diff --git a/che_close/c_tournament.php b/che_close/c_tournament.php index 875c85d3..157dc74a 100644 --- a/che_close/c_tournament.php +++ b/che_close/c_tournament.php @@ -182,7 +182,7 @@ if($btn == "자동개최설정" && $me[userlevel] >= 5) { } elseif($btn == "예선전부" && $me[userlevel] >= 5) { qualifyAll($connect, $admin[tnmt_type], $admin[tournament], $admin[phase]); } elseif($btn == "추첨" && $me[userlevel] >= 5) { selection($connect, $admin[tnmt_type], $admin[tournament], $admin[phase]); } elseif($btn == "추첨전부" && $me[userlevel] >= 5) { selectionAll($connect, $admin[tnmt_type], $admin[tournament], $admin[phase]); -} elseif($btn == "본선" && $me[userlevel] >= 5) { finally($connect, $admin[tnmt_type], $admin[tournament], $admin[phase]); +} elseif($btn == "본선" && $me[userlevel] >= 5) { finallySingle($connect, $admin[tnmt_type], $admin[tournament], $admin[phase]); } elseif($btn == "본선전부" && $me[userlevel] >= 5) { finallyAll($connect, $admin[tnmt_type], $admin[tournament], $admin[phase]); } elseif($btn == "배정" && $me[userlevel] >= 5) { final16set($connect); } elseif($btn == "베팅마감" && $me[userlevel] >= 5) { diff --git a/che_close/func_tournament.php b/che_close/func_tournament.php index 97fe7a50..89809095 100644 --- a/che_close/func_tournament.php +++ b/che_close/func_tournament.php @@ -42,7 +42,7 @@ function processTournament($connect) { if($phase >= 32) { $tnmt = 4; $phase = 0; } break; case 4: //본선중 - finally($connect, $type, $tnmt, $phase); $phase++; + finallySingle($connect, $type, $tnmt, $phase); $phase++; if($phase >= 6) { $tnmt = 5; $phase = 0; } break; case 5: //배정중 @@ -454,7 +454,7 @@ function selectionAll($connect, $tnmt_type, $tnmt, $phase) { } } -function finally($connect, $tnmt_type, $tnmt, $phase) { +function finallySingle($connect, $tnmt_type, $tnmt, $phase) { $cand = getTwo($tnmt, $phase); //각 그룹 페이즈 실행 @@ -484,7 +484,7 @@ function finallyAll($connect, $tnmt_type, $tnmt, $phase) { $start = $phase; $end = $phase - ($phase % 2) + 2; for($i=$start; $i < $end; $i++) { - finally($connect, $tnmt_type, $tnmt, $i); + finallySingle($connect, $tnmt_type, $tnmt, $i); } } diff --git a/e_lib/plates/Engine.php b/e_lib/plates/Engine.php new file mode 100644 index 00000000..6c89642b --- /dev/null +++ b/e_lib/plates/Engine.php @@ -0,0 +1,279 @@ +directory = new Directory($directory); + $this->fileExtension = new FileExtension($fileExtension); + $this->folders = new Folders(); + $this->functions = new Functions(); + $this->data = new Data(); + } + + /** + * Set path to templates directory. + * @param string|null $directory Pass null to disable the default directory. + * @return Engine + */ + public function setDirectory($directory) + { + $this->directory->set($directory); + + return $this; + } + + /** + * Get path to templates directory. + * @return string + */ + public function getDirectory() + { + return $this->directory->get(); + } + + /** + * Set the template file extension. + * @param string|null $fileExtension Pass null to manually set it. + * @return Engine + */ + public function setFileExtension($fileExtension) + { + $this->fileExtension->set($fileExtension); + + return $this; + } + + /** + * Get the template file extension. + * @return string + */ + public function getFileExtension() + { + return $this->fileExtension->get(); + } + + /** + * Add a new template folder for grouping templates under different namespaces. + * @param string $name + * @param string $directory + * @param boolean $fallback + * @return Engine + */ + public function addFolder($name, $directory, $fallback = false) + { + $this->folders->add($name, $directory, $fallback); + + return $this; + } + + /** + * Remove a template folder. + * @param string $name + * @return Engine + */ + public function removeFolder($name) + { + $this->folders->remove($name); + + return $this; + } + + /** + * Get collection of all template folders. + * @return Folders + */ + public function getFolders() + { + return $this->folders; + } + + /** + * Add preassigned template data. + * @param array $data; + * @param null|string|array $templates; + * @return Engine + */ + public function addData(array $data, $templates = null) + { + $this->data->add($data, $templates); + + return $this; + } + + /** + * Get all preassigned template data. + * @param null|string $template; + * @return array + */ + public function getData($template = null) + { + return $this->data->get($template); + } + + /** + * Register a new template function. + * @param string $name; + * @param callback $callback; + * @return Engine + */ + public function registerFunction($name, $callback) + { + $this->functions->add($name, $callback); + + return $this; + } + + /** + * Remove a template function. + * @param string $name; + * @return Engine + */ + public function dropFunction($name) + { + $this->functions->remove($name); + + return $this; + } + + /** + * Get a template function. + * @param string $name + * @return Func + */ + public function getFunction($name) + { + return $this->functions->get($name); + } + + /** + * Check if a template function exists. + * @param string $name + * @return boolean + */ + public function doesFunctionExist($name) + { + return $this->functions->exists($name); + } + + /** + * Load an extension. + * @param ExtensionInterface $extension + * @return Engine + */ + public function loadExtension(ExtensionInterface $extension) + { + $extension->register($this); + + return $this; + } + + /** + * Load multiple extensions. + * @param array $extensions + * @return Engine + */ + public function loadExtensions(array $extensions = array()) + { + foreach ($extensions as $extension) { + $this->loadExtension($extension); + } + + return $this; + } + + /** + * Get a template path. + * @param string $name + * @return string + */ + public function path($name) + { + $name = new Name($this, $name); + + return $name->getPath(); + } + + /** + * Check if a template exists. + * @param string $name + * @return boolean + */ + public function exists($name) + { + $name = new Name($this, $name); + + return $name->doesPathExist(); + } + + /** + * Create a new template. + * @param string $name + * @return Template + */ + public function make($name) + { + return new Template($this, $name); + } + + /** + * Create a new template and render it. + * @param string $name + * @param array $data + * @return string + */ + public function render($name, array $data = array()) + { + return $this->make($name)->render($data); + } +} diff --git a/e_lib/plates/Extension/Asset.php b/e_lib/plates/Extension/Asset.php new file mode 100644 index 00000000..91d39f66 --- /dev/null +++ b/e_lib/plates/Extension/Asset.php @@ -0,0 +1,85 @@ +path = rtrim($path, '/'); + $this->filenameMethod = $filenameMethod; + } + + /** + * Register extension function. + * @param Engine $engine + * @return null + */ + public function register(Engine $engine) + { + $engine->registerFunction('asset', array($this, 'cachedAssetUrl')); + } + + /** + * Create "cache busted" asset URL. + * @param string $url + * @return string + */ + public function cachedAssetUrl($url) + { + $filePath = $this->path . '/' . ltrim($url, '/'); + + if (!file_exists($filePath)) { + throw new LogicException( + 'Unable to locate the asset "' . $url . '" in the "' . $this->path . '" directory.' + ); + } + + $lastUpdated = filemtime($filePath); + $pathInfo = pathinfo($url); + + if ($pathInfo['dirname'] === '.') { + $directory = ''; + } elseif ($pathInfo['dirname'] === '/') { + $directory = '/'; + } else { + $directory = $pathInfo['dirname'] . '/'; + } + + if ($this->filenameMethod) { + return $directory . $pathInfo['filename'] . '.' . $lastUpdated . '.' . $pathInfo['extension']; + } + + return $directory . $pathInfo['filename'] . '.' . $pathInfo['extension'] . '?v=' . $lastUpdated; + } +} diff --git a/e_lib/plates/Extension/ExtensionInterface.php b/e_lib/plates/Extension/ExtensionInterface.php new file mode 100644 index 00000000..0164d1ea --- /dev/null +++ b/e_lib/plates/Extension/ExtensionInterface.php @@ -0,0 +1,13 @@ +uri = $uri; + $this->parts = explode('/', $this->uri); + } + + /** + * Register extension functions. + * @param Engine $engine + * @return null + */ + public function register(Engine $engine) + { + $engine->registerFunction('uri', array($this, 'runUri')); + } + + /** + * Perform URI check. + * @param null|integer|string $var1 + * @param mixed $var2 + * @param mixed $var3 + * @param mixed $var4 + * @return mixed + */ + public function runUri($var1 = null, $var2 = null, $var3 = null, $var4 = null) + { + if (is_null($var1)) { + return $this->uri; + } + + if (is_numeric($var1) and is_null($var2)) { + return array_key_exists($var1, $this->parts) ? $this->parts[$var1] : null; + } + + if (is_numeric($var1) and is_string($var2)) { + return $this->checkUriSegmentMatch($var1, $var2, $var3, $var4); + } + + if (is_string($var1)) { + return $this->checkUriRegexMatch($var1, $var2, $var3); + } + + throw new LogicException('Invalid use of the uri function.'); + } + + /** + * Perform a URI segment match. + * @param integer $key + * @param string $string + * @param mixed $returnOnTrue + * @param mixed $returnOnFalse + * @return mixed + */ + protected function checkUriSegmentMatch($key, $string, $returnOnTrue = null, $returnOnFalse = null) + { + if (array_key_exists($key, $this->parts) && $this->parts[$key] === $string) { + return is_null($returnOnTrue) ? true : $returnOnTrue; + } + + return is_null($returnOnFalse) ? false : $returnOnFalse; + } + + /** + * Perform a regular express match. + * @param string $regex + * @param mixed $returnOnTrue + * @param mixed $returnOnFalse + * @return mixed + */ + protected function checkUriRegexMatch($regex, $returnOnTrue = null, $returnOnFalse = null) + { + if (preg_match('#^' . $regex . '$#', $this->uri) === 1) { + return is_null($returnOnTrue) ? true : $returnOnTrue; + } + + return is_null($returnOnFalse) ? false : $returnOnFalse; + } +} diff --git a/e_lib/plates/Template/Data.php b/e_lib/plates/Template/Data.php new file mode 100644 index 00000000..aa4d1e1e --- /dev/null +++ b/e_lib/plates/Template/Data.php @@ -0,0 +1,93 @@ +shareWithAll($data); + } + + if (is_array($templates)) { + return $this->shareWithSome($data, $templates); + } + + if (is_string($templates)) { + return $this->shareWithSome($data, array($templates)); + } + + throw new LogicException( + 'The templates variable must be null, an array or a string, ' . gettype($templates) . ' given.' + ); + } + + /** + * Add data shared with all templates. + * @param array $data; + * @return Data + */ + public function shareWithAll($data) + { + $this->sharedVariables = array_merge($this->sharedVariables, $data); + + return $this; + } + + /** + * Add data shared with some templates. + * @param array $data; + * @param array $templates; + * @return Data + */ + public function shareWithSome($data, array $templates) + { + foreach ($templates as $template) { + if (isset($this->templateVariables[$template])) { + $this->templateVariables[$template] = array_merge($this->templateVariables[$template], $data); + } else { + $this->templateVariables[$template] = $data; + } + } + + return $this; + } + + /** + * Get template data. + * @param null|string $template; + * @return array + */ + public function get($template = null) + { + if (isset($template, $this->templateVariables[$template])) { + return array_merge($this->sharedVariables, $this->templateVariables[$template]); + } + + return $this->sharedVariables; + } +} diff --git a/e_lib/plates/Template/Directory.php b/e_lib/plates/Template/Directory.php new file mode 100644 index 00000000..f5de5374 --- /dev/null +++ b/e_lib/plates/Template/Directory.php @@ -0,0 +1,53 @@ +set($path); + } + + /** + * Set path to templates directory. + * @param string|null $path Pass null to disable the default directory. + * @return Directory + */ + public function set($path) + { + if (!is_null($path) and !is_dir($path)) { + throw new LogicException( + 'The specified path "' . $path . '" does not exist.' + ); + } + + $this->path = $path; + + return $this; + } + + /** + * Get path to templates directory. + * @return string + */ + public function get() + { + return $this->path; + } +} diff --git a/e_lib/plates/Template/FileExtension.php b/e_lib/plates/Template/FileExtension.php new file mode 100644 index 00000000..57646bdd --- /dev/null +++ b/e_lib/plates/Template/FileExtension.php @@ -0,0 +1,45 @@ +set($fileExtension); + } + + /** + * Set the template file extension. + * @param null|string $fileExtension + * @return FileExtension + */ + public function set($fileExtension) + { + $this->fileExtension = $fileExtension; + + return $this; + } + + /** + * Get the template file extension. + * @return string + */ + public function get() + { + return $this->fileExtension; + } +} diff --git a/e_lib/plates/Template/Folder.php b/e_lib/plates/Template/Folder.php new file mode 100644 index 00000000..01fcbdd2 --- /dev/null +++ b/e_lib/plates/Template/Folder.php @@ -0,0 +1,109 @@ +setName($name); + $this->setPath($path); + $this->setFallback($fallback); + } + + /** + * Set the folder name. + * @param string $name + * @return Folder + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get the folder name. + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set the folder path. + * @param string $path + * @return Folder + */ + public function setPath($path) + { + if (!is_dir($path)) { + throw new LogicException('The specified directory path "' . $path . '" does not exist.'); + } + + $this->path = $path; + + return $this; + } + + /** + * Get the folder path. + * @return string + */ + public function getPath() + { + return $this->path; + } + + /** + * Set the folder fallback status. + * @param boolean $fallback + * @return Folder + */ + public function setFallback($fallback) + { + $this->fallback = $fallback; + + return $this; + } + + /** + * Get the folder fallback status. + * @return boolean + */ + public function getFallback() + { + return $this->fallback; + } +} diff --git a/e_lib/plates/Template/Folders.php b/e_lib/plates/Template/Folders.php new file mode 100644 index 00000000..9bf266a7 --- /dev/null +++ b/e_lib/plates/Template/Folders.php @@ -0,0 +1,75 @@ +exists($name)) { + throw new LogicException('The template folder "' . $name . '" is already being used.'); + } + + $this->folders[$name] = new Folder($name, $path, $fallback); + + return $this; + } + + /** + * Remove a template folder. + * @param string $name + * @return Folders + */ + public function remove($name) + { + if (!$this->exists($name)) { + throw new LogicException('The template folder "' . $name . '" was not found.'); + } + + unset($this->folders[$name]); + + return $this; + } + + /** + * Get a template folder. + * @param string $name + * @return Folder + */ + public function get($name) + { + if (!$this->exists($name)) { + throw new LogicException('The template folder "' . $name . '" was not found.'); + } + + return $this->folders[$name]; + } + + /** + * Check if a template folder exists. + * @param string $name + * @return boolean + */ + public function exists($name) + { + return isset($this->folders[$name]); + } +} diff --git a/e_lib/plates/Template/Func.php b/e_lib/plates/Template/Func.php new file mode 100644 index 00000000..79141f46 --- /dev/null +++ b/e_lib/plates/Template/Func.php @@ -0,0 +1,107 @@ +setName($name); + $this->setCallback($callback); + } + + /** + * Set the function name. + * @param string $name + * @return Func + */ + public function setName($name) + { + if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $name) !== 1) { + throw new LogicException( + 'Not a valid function name.' + ); + } + + $this->name = $name; + + return $this; + } + + /** + * Get the function name. + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set the function callback + * @param callable $callback + * @return Func + */ + public function setCallback($callback) + { + if (!is_callable($callback, true)) { + throw new LogicException( + 'Not a valid function callback.' + ); + } + + $this->callback = $callback; + + return $this; + } + + /** + * Get the function callback. + * @return callable + */ + public function getCallback() + { + return $this->callback; + } + + /** + * Call the function. + * @param Template $template + * @param array $arguments + * @return mixed + */ + public function call(Template $template = null, $arguments = array()) + { + if (is_array($this->callback) and + isset($this->callback[0]) and + $this->callback[0] instanceof ExtensionInterface + ) { + $this->callback[0]->template = $template; + } + + return call_user_func_array($this->callback, $arguments); + } +} diff --git a/e_lib/plates/Template/Functions.php b/e_lib/plates/Template/Functions.php new file mode 100644 index 00000000..e0e4c2c1 --- /dev/null +++ b/e_lib/plates/Template/Functions.php @@ -0,0 +1,78 @@ +exists($name)) { + throw new LogicException( + 'The template function name "' . $name . '" is already registered.' + ); + } + + $this->functions[$name] = new Func($name, $callback); + + return $this; + } + + /** + * Remove a template function. + * @param string $name; + * @return Functions + */ + public function remove($name) + { + if (!$this->exists($name)) { + throw new LogicException( + 'The template function "' . $name . '" was not found.' + ); + } + + unset($this->functions[$name]); + + return $this; + } + + /** + * Get a template function. + * @param string $name + * @return Func + */ + public function get($name) + { + if (!$this->exists($name)) { + throw new LogicException('The template function "' . $name . '" was not found.'); + } + + return $this->functions[$name]; + } + + /** + * Check if a template function exists. + * @param string $name + * @return boolean + */ + public function exists($name) + { + return isset($this->functions[$name]); + } +} diff --git a/e_lib/plates/Template/Name.php b/e_lib/plates/Template/Name.php new file mode 100644 index 00000000..a999d74d --- /dev/null +++ b/e_lib/plates/Template/Name.php @@ -0,0 +1,202 @@ +setEngine($engine); + $this->setName($name); + } + + /** + * Set the engine. + * @param Engine $engine + * @return Name + */ + public function setEngine(Engine $engine) + { + $this->engine = $engine; + + return $this; + } + + /** + * Get the engine. + * @return Engine + */ + public function getEngine() + { + return $this->engine; + } + + /** + * Set the original name and parse it. + * @param string $name + * @return Name + */ + public function setName($name) + { + $this->name = $name; + + $parts = explode('::', $this->name); + + if (count($parts) === 1) { + $this->setFile($parts[0]); + } elseif (count($parts) === 2) { + $this->setFolder($parts[0]); + $this->setFile($parts[1]); + } else { + throw new LogicException( + 'The template name "' . $this->name . '" is not valid. ' . + 'Do not use the folder namespace separator "::" more than once.' + ); + } + + return $this; + } + + /** + * Get the original name. + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set the parsed template folder. + * @param string $folder + * @return Name + */ + public function setFolder($folder) + { + $this->folder = $this->engine->getFolders()->get($folder); + + return $this; + } + + /** + * Get the parsed template folder. + * @return string + */ + public function getFolder() + { + return $this->folder; + } + + /** + * Set the parsed template file. + * @param string $file + * @return Name + */ + public function setFile($file) + { + if ($file === '') { + throw new LogicException( + 'The template name "' . $this->name . '" is not valid. ' . + 'The template name cannot be empty.' + ); + } + + $this->file = $file; + + if (!is_null($this->engine->getFileExtension())) { + $this->file .= '.' . $this->engine->getFileExtension(); + } + + return $this; + } + + /** + * Get the parsed template file. + * @return string + */ + public function getFile() + { + return $this->file; + } + + /** + * Resolve template path. + * @return string + */ + public function getPath() + { + if (is_null($this->folder)) { + return $this->getDefaultDirectory() . DIRECTORY_SEPARATOR . $this->file; + } + + $path = $this->folder->getPath() . DIRECTORY_SEPARATOR . $this->file; + + if (!is_file($path) and $this->folder->getFallback() and is_file($this->getDefaultDirectory() . DIRECTORY_SEPARATOR . $this->file)) { + $path = $this->getDefaultDirectory() . DIRECTORY_SEPARATOR . $this->file; + } + + return $path; + } + + /** + * Check if template path exists. + * @return boolean + */ + public function doesPathExist() + { + return is_file($this->getPath()); + } + + /** + * Get the default templates directory. + * @return string + */ + protected function getDefaultDirectory() + { + $directory = $this->engine->getDirectory(); + + if (is_null($directory)) { + throw new LogicException( + 'The template name "' . $this->name . '" is not valid. '. + 'The default directory has not been defined.' + ); + } + + return $directory; + } +} diff --git a/e_lib/plates/Template/Template.php b/e_lib/plates/Template/Template.php new file mode 100644 index 00000000..0a88c8cf --- /dev/null +++ b/e_lib/plates/Template/Template.php @@ -0,0 +1,346 @@ +engine = $engine; + $this->name = new Name($engine, $name); + + $this->data($this->engine->getData($name)); + } + + /** + * Magic method used to call extension functions. + * @param string $name + * @param array $arguments + * @return mixed + */ + public function __call($name, $arguments) + { + return $this->engine->getFunction($name)->call($this, $arguments); + } + + /** + * Alias for render() method. + * @throws \Throwable + * @throws \Exception + * @return string + */ + public function __toString() + { + return $this->render(); + } + + /** + * Assign or get template data. + * @param array $data + * @return mixed + */ + public function data(array $data = null) + { + if (is_null($data)) { + return $this->data; + } + + $this->data = array_merge($this->data, $data); + } + + /** + * Check if the template exists. + * @return boolean + */ + public function exists() + { + return $this->name->doesPathExist(); + } + + /** + * Get the template path. + * @return string + */ + public function path() + { + return $this->name->getPath(); + } + + /** + * Render the template and layout. + * @param array $data + * @throws \Throwable + * @throws \Exception + * @return string + */ + public function render(array $data = array()) + { + $this->data($data); + unset($data); + extract($this->data); + + if (!$this->exists()) { + throw new LogicException( + 'The template "' . $this->name->getName() . '" could not be found at "' . $this->path() . '".' + ); + } + + try { + $level = ob_get_level(); + ob_start(); + + include $this->path(); + + $content = ob_get_clean(); + + if (isset($this->layoutName)) { + $layout = $this->engine->make($this->layoutName); + $layout->sections = array_merge($this->sections, array('content' => $content)); + $content = $layout->render($this->layoutData); + } + + return $content; + } catch (Throwable $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + + throw $e; + } catch (Exception $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + + throw $e; + } + } + + /** + * Set the template's layout. + * @param string $name + * @param array $data + * @return null + */ + public function layout($name, array $data = array()) + { + $this->layoutName = $name; + $this->layoutData = $data; + } + + /** + * Start a new section block. + * @param string $name + * @return null + */ + public function start($name) + { + if ($name === 'content') { + throw new LogicException( + 'The section name "content" is reserved.' + ); + } + + if ($this->sectionName) { + throw new LogicException('You cannot nest sections within other sections.'); + } + + $this->sectionName = $name; + + ob_start(); + } + + /** + * Start a new append section block. + * @param string $name + * @return null + */ + public function push($name) + { + $this->appendSection = true; + + $this->start($name); + } + + /** + * Stop the current section block. + * @return null + */ + public function stop() + { + if (is_null($this->sectionName)) { + throw new LogicException( + 'You must start a section before you can stop it.' + ); + } + + if (!isset($this->sections[$this->sectionName])) { + $this->sections[$this->sectionName] = ''; + } + + $this->sections[$this->sectionName] = $this->appendSection ? $this->sections[$this->sectionName] . ob_get_clean() : ob_get_clean(); + $this->sectionName = null; + $this->appendSection = false; + } + + /** + * Alias of stop(). + * @return null + */ + public function end() + { + $this->stop(); + } + + /** + * Returns the content for a section block. + * @param string $name Section name + * @param string $default Default section content + * @return string|null + */ + public function section($name, $default = null) + { + if (!isset($this->sections[$name])) { + return $default; + } + + return $this->sections[$name]; + } + + /** + * Fetch a rendered template. + * @param string $name + * @param array $data + * @return string + */ + public function fetch($name, array $data = array()) + { + return $this->engine->render($name, $data); + } + + /** + * Output a rendered template. + * @param string $name + * @param array $data + * @return null + */ + public function insert($name, array $data = array()) + { + echo $this->engine->render($name, $data); + } + + /** + * Apply multiple functions to variable. + * @param mixed $var + * @param string $functions + * @return mixed + */ + public function batch($var, $functions) + { + foreach (explode('|', $functions) as $function) { + if ($this->engine->doesFunctionExist($function)) { + $var = call_user_func(array($this, $function), $var); + } elseif (is_callable($function)) { + $var = call_user_func($function, $var); + } else { + throw new LogicException( + 'The batch function could not find the "' . $function . '" function.' + ); + } + } + + return $var; + } + + /** + * Escape string. + * @param string $string + * @param null|string $functions + * @return string + */ + public function escape($string, $functions = null) + { + static $flags; + + if (!isset($flags)) { + $flags = ENT_QUOTES | (defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0); + } + + if ($functions) { + $string = $this->batch($string, $functions); + } + + return htmlspecialchars($string, $flags, 'UTF-8'); + } + + /** + * Alias to escape function. + * @param string $string + * @param null|string $functions + * @return string + */ + public function e($string, $functions = null) + { + return $this->escape($string, $functions); + } +} diff --git a/e_lib/plates/example.php b/e_lib/plates/example.php new file mode 100644 index 00000000..7e30a6a1 --- /dev/null +++ b/e_lib/plates/example.php @@ -0,0 +1,20 @@ +addData(['company' => 'The Company Name'], 'layout'); + +// Render a template +echo $templates->render('profile', ['name' => 'Jonathan']); diff --git a/e_lib/plates/plates.php b/e_lib/plates/plates.php new file mode 100644 index 00000000..8000a7ce --- /dev/null +++ b/e_lib/plates/plates.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/e_lib/plates/templates/layout.php b/e_lib/plates/templates/layout.php new file mode 100644 index 00000000..5b5847cf --- /dev/null +++ b/e_lib/plates/templates/layout.php @@ -0,0 +1,12 @@ + +
+Hello, =$this->e($name)?>!
+ +insert('sidebar') ?> + +push('scripts') ?> + +end() ?> \ No newline at end of file diff --git a/e_lib/plates/templates/sidebar.php b/e_lib/plates/templates/sidebar.php new file mode 100644 index 00000000..13d9ea83 --- /dev/null +++ b/e_lib/plates/templates/sidebar.php @@ -0,0 +1,6 @@ + \ No newline at end of file