Documentation, format class, no modification. (#7629)

This commit is contained in:
frytimo
2025-11-19 12:48:36 -04:00
committed by GitHub
parent 0ea256fce8
commit 34821bed7e
36 changed files with 12982 additions and 11551 deletions

View File

@@ -25,67 +25,91 @@
*/
//define the template class
class template {
class template {
public $engine;
public $template_dir;
public $cache_dir;
private $object;
private $var_array;
public $engine;
public $template_dir;
public $cache_dir;
private $object;
private $var_array;
public function __construct(){
}
public function __construct() {
}
public function init() {
if ($this->engine === 'smarty') {
require_once "resources/templates/engine/smarty/Smarty.class.php";
$this->object = new Smarty();
$this->object->setTemplateDir($this->template_dir);
$this->object->setCompileDir($this->cache_dir);
$this->object->setCacheDir($this->cache_dir);
$this->object->registerPlugin("modifier","in_array", "in_array");
}
if ($this->engine === 'raintpl') {
require_once "resources/templates/engine/raintpl/rain.tpl.class.php";
$this->object = new RainTPL();
RainTPL::configure('tpl_dir', realpath($this->template_dir)."/");
RainTPL::configure('cache_dir', realpath($this->cache_dir)."/");
}
if ($this->engine === 'twig') {
require_once "resources/templates/engine/Twig/Autoloader.php";
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem($this->template_dir);
$this->object = new Twig_Environment($loader);
$lexer = new Twig_Lexer($this->object, array(
'tag_comment' => array('{*', '*}'),
'tag_block' => array('{', '}'),
'tag_variable' => array('{$', '}'),
));
$this->object->setLexer($lexer);
}
}
public function assign($key, $value) {
if ($this->engine === 'smarty') {
$this->object->assign($key, $value);
}
if ($this->engine === 'raintpl') {
$this->object->assign($key, $value);
}
if ($this->engine === 'twig') {
$this->var_array[$key] = $value;
}
}
public function render($name) {
if ($this->engine === 'smarty') {
return $this->object->fetch($name);
}
if ($this->engine === 'raintpl') {
return $this->object-> draw($name, 'return_string=true');
}
if ($this->engine === 'twig') {
return $this->object->render($name,$this->var_array);
}
}
/**
* Initializes the template engine based on the selected engine.
*
* @access public
*/
public function init() {
if ($this->engine === 'smarty') {
require_once "resources/templates/engine/smarty/Smarty.class.php";
$this->object = new Smarty();
$this->object->setTemplateDir($this->template_dir);
$this->object->setCompileDir($this->cache_dir);
$this->object->setCacheDir($this->cache_dir);
$this->object->registerPlugin("modifier", "in_array", "in_array");
}
if ($this->engine === 'raintpl') {
require_once "resources/templates/engine/raintpl/rain.tpl.class.php";
$this->object = new RainTPL();
RainTPL::configure('tpl_dir', realpath($this->template_dir) . "/");
RainTPL::configure('cache_dir', realpath($this->cache_dir) . "/");
}
if ($this->engine === 'twig') {
require_once "resources/templates/engine/Twig/Autoloader.php";
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem($this->template_dir);
$this->object = new Twig_Environment($loader);
$lexer = new Twig_Lexer($this->object, [
'tag_comment' => ['{*', '*}'],
'tag_block' => ['{', '}'],
'tag_variable' => ['{$', '}'],
]);
$this->object->setLexer($lexer);
}
}
/**
* Assigns a value to the template engine based on the selected engine.
*
* @param string $key The key for the assigned value.
* @param mixed $value The value to be assigned.
*
* @access public
*
* @return void
*/
public function assign($key, $value) {
if ($this->engine === 'smarty') {
$this->object->assign($key, $value);
}
if ($this->engine === 'raintpl') {
$this->object->assign($key, $value);
}
if ($this->engine === 'twig') {
$this->var_array[$key] = $value;
}
}
/**
* Renders the given template using the configured engine.
*
* @param string $name Name of the template to render. Values can be 'smarty', 'raintpl' or 'twig' (case sensitive)
*
* @return mixed The rendered template output, depending on the used engine
*
* @access public
*/
public function render($name) {
if ($this->engine === 'smarty') {
return $this->object->fetch($name);
}
if ($this->engine === 'raintpl') {
return $this->object->draw($name, 'return_string=true');
}
if ($this->engine === 'twig') {
return $this->object->render($name, $this->var_array);
}
}
}