Example #1
0
 function __construct($tpl)
 {
     $this->tpl = $tpl;
     $config = array("tpl_dir" => "view/", "cache_dir" => "template_cache/");
     //add url tag
     parent::registerTag("({@.*?@})", "{@(.*?)(?:\\|(.*?))@}", function ($params) {
         // function called by the tag
         $tag = $params[1][0];
         $arg = $params[2][0];
         return Yeast::generateURI($tag, $arg);
     });
     parent::configure($config);
 }
Example #2
0
 protected function tpl()
 {
     $config = array('tpl_dir' => APP_PATH . 'widgets/' . $this->name . '/', 'cache_dir' => CACHE_PATH, 'tpl_ext' => 'tpl', 'auto_escape' => false);
     $view = new Tpl();
     $view->objectConfigure($config);
     $view->assign('c', $this);
     return $view;
 }
Example #3
0
<?php

// namespace
use Rain\Tpl;
// include
include "library/Rain/Tpl.php";
// configure
$config = array("base_url" => null, "tpl_dir" => "templates/", "cache_dir" => "cache/", "debug" => true, "auto_escape" => true);
Tpl::configure($config);
// set variables
$var = array("variable" => "Hello World!", "version" => "3.0 Alpha", "menu" => array(array("name" => "Home", "link" => "index.php", "selected" => true), array("name" => "FAQ", "link" => "index.php/FAQ/", "selected" => null), array("name" => "Documentation", "link" => "index.php/doc/", "selected" => null)), "week" => array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), "user" => (object) array("name" => "Rain", "citizen" => "Earth", "race" => "Human"), "numbers" => array(3, 2, 1), "bad_text" => 'Hey this is a malicious XSS <script>alert(1);</script>', "table" => array(array("Apple", "1996"), array("PC", "1997")), "title" => "Rain TPL 3 - Easy and Fast template engine", "copyright" => "Copyright 2006 - 2012 Rain TPL<br>Project By Rain Team");
// add a function
Tpl::register_tag("({@.*?@})", "{@(.*?)@}", function ($params) {
    // function called by the tag
    $value = $params[0];
    return "Translate: <b>{$value}</b>";
});
// draw
$tpl = new Tpl();
$tpl->assign($var);
echo $tpl->draw("bootstrap/hero");
Example #4
0
// include
include "library/Rain/Tpl.php";
// config
$config = array("base_url" => null, "tpl_dir" => "templates/test/", "cache_dir" => "cache/", "debug" => true, "auto_escape" => true);
Tpl::configure($config);
// set variables
$var = array("variable" => "Hello World!", "version" => "3.0 Alpha", "menu" => array(array("name" => "Home", "link" => "index.php", "selected" => true), array("name" => "FAQ", "link" => "index.php/FAQ/", "selected" => null), array("name" => "Documentation", "link" => "index.php/doc/", "selected" => null)), "week" => array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), "user" => (object) array("name" => "Rain", "citizen" => "Earth", "race" => "Human"), "numbers" => array(3, 2, 1), "bad_text" => 'Hey this is a malicious XSS <script>alert(1);</script>', "table" => array(array("Apple", "1996"), array("PC", "1997")), "title" => "Rain TPL 3 - Easy and Fast template engine", "copyright" => "Copyright 2006 - 2012 Rain TPL<br>Project By Rain Team");
// add a tag
Tpl::register_tag("({@.*?@})", "{@(.*?)@}", function ($params) {
    // function called by the tag
    $value = $params[1][0];
    return "Translate: <b>{$value}</b>";
});
// add a tag
Tpl::register_tag("({%.*?%})", "{%(.*?)(?:\\|(.*?))%}", function ($params) {
    // function called by the tag
    $value = $params[1][0];
    $value2 = $params[2][0];
    return "Translate: <b>{$value}</b> in <b>{$value2}</b>";
});
class Test
{
    public static function method($variable)
    {
        echo "Hi I am a static method, and this is the parameter passed to me: {$variable}!";
    }
}
// draw
$tpl = new Tpl();
$tpl->assign($var);
echo $tpl->draw("test");
<?php

// include
require "library/Rain/autoload.php";
// namespace
use Rain\Tpl;
// config
$config = array("tpl_dir" => array("templates/multiple-template-directories/newimplement/", "templates/multiple-template-directories/base/"), "cache_dir" => "cache/", "debug" => true);
Tpl::configure($config);
// Add PathReplace plugin (necessary to load the CSS with path replace)
Tpl::registerPlugin(new Tpl\Plugin\PathReplace());
// create the Tpl object
$tpl = new Tpl();
$tpl->draw("subfolder/index");
<?php

// include
require "library/Rain/autoload.php";
// namespace
use Rain\Tpl;
// config
$config = array("tpl_dir" => "templates/simple/", "cache_dir" => "cache/", "debug" => true);
Tpl::configure($config);
// Add PathReplace plugin (necessary to load the CSS with path replace)
Tpl::registerPlugin(new Tpl\Plugin\PathReplace());
// create the Tpl object
$tpl = new Tpl();
// assign a variable
$tpl->assign("name", "Obi Wan Kenoby");
// assign an array
$tpl->assign("week", array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"));
// draw the template
$tpl->draw("simple_template");
<?php

// include
require "library/Rain/autoload.php";
// namespace
use Rain\Tpl;
// conf
$config = array("base_url" => null, "tpl_dir" => "templates/raintpl2/", "cache_dir" => "cache/", "debug" => true);
Tpl::configure($config);
// Add PathReplace plugin
Tpl::registerPlugin(new Tpl\Plugin\PathReplace());
global $global_variable;
$global_variable = "I'm Global";
// set variables
$var = array("variable" => "Hello", "version" => "3.0 Alpha", "menu" => array(array("name" => "Home", "link" => "index.php", "selected" => true), array("name" => "FAQ", "link" => "index.php/FAQ/", "selected" => null), array("name" => "Documentation", "link" => "index.php/doc/", "selected" => null)), "week" => array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), "title" => "Rain TPL 3 - Easy and Fast template engine", "user" => array(array("name" => "Fede", "color" => "blue"), array("name" => "Sheska", "color" => "red"), array("name" => "Who", "color" => "yellow")), "empty_array" => array(), "copyright" => "Copyright 2006 - 2012 Rain TPL<br>Project By Rain Team");
function test($params)
{
    $value = $params[0];
    return "Translate: <b>{$value}</b>";
}
// add a function
Tpl::registerTag("({@.*?@})", "{@(.*?)@}", "test");
// draw
$tpl = new Tpl();
$tpl->assign($var);
echo $tpl->draw("page");
Example #8
0
use Rain\Tpl;
// Detect if Mobile or Computer is used
$detect = new Mobile_Detect();
$mobile = $detect->isMobile() || isset($_GET['mobile']) && $_GET['mobile'] == 1;
// Use template ?
if ($config["useTemplate"]) {
    // Templace RainTPL
    if (!is_dir('cache')) {
        mkdir('cache', 0705);
        chmod('cache', 0705);
    }
    Tpl::configure(array("tpl_dir" => array($config["template"]["tpl_dir"], $config["template"]["tpl_dir"]), "cache_dir" => "cache/", "debug" => false));
    // Add PathReplace plugin (necessary to load the CSS with path replace)
    Tpl::registerPlugin(new Tpl\Plugin\PathReplace());
    // create the Tpl object
    $tpl = new Tpl();
    header("Vary: User-Agent");
    if ($mobile) {
        $tpl->draw($config["template"]["mobile"]);
    } else {
        $tpl->draw($config["template"]["desktop"]);
    }
} else {
    header("Vary: User-Agent");
    if ($mobile) {
        //readfile("tpl/teleinfo.tabs.mobile.html");
        readfile($config["notemplate"]["mobile"]);
        // FIXME: Security hole
    } else {
        //readfile("tpl/teleinfo.tabs.html");
        readfile($config["notemplate"]["desktop"]);
Tpl::registerTag("({%.*?%})", "{%(.*?)(?:\\|(.*?))%}", function ($params) {
    // function called by the tag
    $value = $params[1][0];
    $value2 = $params[2][0];
    return "Translate: <b>{$value}</b> in <b>{$value2}</b>";
});
$string = file_get_contents("templates/test/test.html");
class Test
{
    public static function method($variable)
    {
        echo "Hi I am a static method, and this is the parameter passed to me: {$variable}!";
    }
}
// draw
$tpl = new Tpl();
$tpl->assign($var);
echo $tpl->drawString($string);
// -- end
//-------------------------------------------------------------
//
//	BENCHMARK/DEBUG FUNCTIONS
//
//-------------------------------------------------------------
echo "<br>---------<br>";
echo memoryUsage();
echo "<br>";
echo timer();
/**
 * Useful for debug, print the variable $mixed and die
 */
Example #10
0
 protected function initTemplateEngine($params)
 {
     $defaults = array('tpl_dir' => "{$this->params['templates_dir']}/", 'cache_dir' => sys_get_temp_dir() . '/');
     $params = array_merge($defaults, $params);
     // init template engine
     $tpl = new Tpl();
     $tpl->configure($params);
     return $tpl;
 }
Example #11
0
 /**
  * Mostramos todas las plantillas cargadas
  * @param boolean $return Indica si retornar o no el HTML generado
  * @return nothing
  */
 public static function show()
 {
     if (count(self::$templates) >= 1) {
         $dir_theme = 'views' . DS . 'html' . DS;
         $dir_base = explode('/', $_SERVER['REQUEST_URI']);
         array_shift($dir_base);
         array_pop($dir_base);
         $dir_base = '/' . implode('/', $dir_base) . '/';
         self::add_key('site', get_config('site'));
         self::add_key('core_files', self::$files);
         self::add_key('core_paths', array('theme' => $dir_theme, 'base' => $dir_base));
         self::add_key('site', get_config('site'));
         // Instanciamos RainTPL
         $rain = new RainTpl();
         // Configuramos Rain para trabajar
         RainTpl::configure('base_url', $_SERVER['SERVER_NAME'] . $dir_base);
         RainTpl::configure('tpl_dir', 'views' . DS . 'html' . DS);
         RainTpl::configure('cache_dir', CACHE_DIR . 'html' . DS);
         $rain->assign('lang', self::load_language(self::$configuration['lang']));
         $rain->assign(self::$variables);
         if (self::$configuration['start_with'] !== null) {
             $rain->draw(self::$configuration['start_with'], false);
         }
         // Recorremos el arreglo de plantillas y las vamos mostrando
         foreach (self::$templates as $template) {
             $rain->draw($template, false);
         }
         if (self::$configuration['end_with'] !== null) {
             $rain->draw(self::$configuration['end_with'], false);
         }
     } else {
         //TODO: Considerar idiomas
         if (count(self::$variables) >= 1) {
             echo json_encode(self::$variables);
         }
     }
 }
<?php

ini_set("display_errors", true);
// include
require "library/Rain/autoload.php";
// namespace
use Rain\Tpl;
// conf
$config = array("base_url" => null, "tpl_dir" => "templates/compress/", "cache_dir" => "cache/", "debug" => true);
Tpl::configure($config);
Tpl::registerPlugin(new Tpl\Plugin\PathReplace());
$compress = new Tpl\Plugin\Compress();
$compress->configure('css', array('status' => true));
$compress->configure('html', array('status' => true));
$compress->configure('javascript', array('status' => true, 'position' => 'bottom'));
Tpl::registerPlugin($compress);
global $global_variable;
$global_variable = "I'm Global";
// set variables
$var = array("variable" => "Hello", "version" => "3.0 Alpha", "menu" => array(array("name" => "Home", "link" => "index.php", "selected" => true), array("name" => "FAQ", "link" => "index.php/FAQ/", "selected" => null), array("name" => "Documentation", "link" => "index.php/doc/", "selected" => null)), "week" => array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), "title" => "Rain TPL 3 - Easy and Fast template engine", "user" => array(array("name" => "Fede", "color" => "blue"), array("name" => "Sheska", "color" => "red"), array("name" => "Who", "color" => "yellow")), "empty_array" => array(), "copyright" => "Copyright 2006 - 2012 Rain TPL<br>Project By Rain Team");
// draw
$tpl = new Tpl();
$tpl->assign($var);
$tpl->draw("test_compress");
<?php

// include
require "library/Rain/autoload.php";
// namespace
use Rain\Tpl;
// config
$config = array("base_url" => null, "tpl_dir" => "templates/nested_loop/", "cache_dir" => "cache/", "debug" => true);
Tpl::configure($config);
// Add PathReplace plugin
Tpl::registerPlugin(new Tpl\Plugin\PathReplace());
$user = array(array('name' => 'Jupiter', 'color' => 'yellow', 'orders' => array(array('order_id' => '123', 'order_name' => 'o1d'), array('order_id' => '1sn24', 'order_name' => 'o2d'))), array('name' => 'Mars', 'color' => 'red', 'orders' => array(array('order_id' => '3rf22', 'order_name' => '¶©µ¥Aj'))), array('name' => 'Empty', 'color' => 'blue', 'orders' => array()), array('name' => 'Earth', 'color' => 'blue', 'orders' => array(array('order_id' => '2315', 'order_name' => '¶©µ¥15'), array('order_id' => 'rf2123', 'order_name' => '¶©µ¥215'), array('order_id' => '0231', 'order_name' => '¶©µ¥315'), array('order_id' => 'sn09-0fsd', 'order_name' => '¶©µ¥45415'))));
// draw
$tpl = new Tpl();
$tpl->assign("user", $user);
echo $tpl->draw("test");
class Test
{
    public static function method($variable)
    {
        echo "Hi I am a static method, and this is the parameter passed to me: {$variable}!";
    }
}
// end