Example #1
0
 public static function output($vars = '')
 {
     // variables
     $template = new Template($vars);
     $cache = null;
     $id = "{$_SERVER['HTTP_HOST']}/html/" . $template->hash;
     // get available cache (if applicable)
     if ($template->canCache()) {
         // first thing, check if there's a cached version of the template
         $cache = self::getCache($id);
     }
     //$cache = false;
     if (!empty($cache) && !DEBUG) {
         echo $cache;
         return;
     }
     // continue processing
     $template->setupClient();
     //
     $GLOBALS['body'] = $template->vars["body"];
     $GLOBALS['head'] = $template->get("head");
     $GLOBALS['foot'] = $template->get("foot");
     // compile the page with the existing data
     $output = $template->do_fetch($template->file, $template->vars);
     // post-process (in debug with limited features)
     $output = $template->process($output);
     // output the final markup - clear whitespace (if not in debug mode)
     echo $output;
     // set the cache for later use
     self::setCache($id, $output);
 }
Example #2
0
 /**
  * Returns the processed template from a template instance.
  * @param $template Template The template instance.
  * @return string
  */
 public function process(Template $template, Layout $layout = null)
 {
     $content = $template->process($this->rules, $this->data);
     if (!is_null($layout)) {
         $this->data[] = $content;
         $content = $layout->process($this->rules, $this->data);
     }
     return $content;
 }
Example #3
0
 public function call()
 {
     $survey_code = strtoupper($this->getArgument('uid'));
     //check access
     if (!session_id()) {
         session_start();
     }
     if (!array_key_exists('survey_results', $_SESSION) || !array_key_exists($survey_code, $_SESSION['survey_results']) || !$_SESSION['survey_results'][$survey_code]) {
         return new Redirect('internal', MAIN_SCRIPT . '?action=dashboardlogin');
     }
     $tpl = new Template('dashboard_flex_body.php');
     return new Answer('ok', $tpl->process(array('session' => session_id(), 'survey_code' => $survey_code)), 'html');
 }
Example #4
0
 public function process(array $custom_rules, array $data)
 {
     $custom_rules[] = new Rule('yield', 'yield', '<?php $end = end($this->data); echo $end; ?>');
     return parent::process($custom_rules, $data);
 }
Example #5
0
 /**
  * Imports a file in the form of a new Template.
  * @var $file string The filename of the imported Template.
  * @returns string
  */
 private function importFile($file)
 {
     $template = new Template($this->include_path . $file);
     return $template->process($this->rules, $this->data);
 }
Example #6
0
 private function do_render($options = array())
 {
     $template = new Template($this, $options, $this->properties);
     try {
         echo $template->process();
     } catch (TemplateMissingException $e) {
         $this->echo_friendly_error('Template Missing', 'Template <tt>\'' . htmlentities($e->getMessage()) . '\'</tt> not found.');
         return false;
     }
     $this->clear_flash();
 }
Example #7
0
 function render($options)
 {
     $template = new Template($this->controller, $options, $this->properties);
     return $template->process();
 }
Example #8
0
 public function call()
 {
     try {
         $device = $this->getArgument('device');
         if ($device == 'phone') {
             $survey_tpl = new Template('phone/main.php');
             return new Answer('ok', $survey_tpl->process(array('device' => $device)), 'html');
         } else {
             $survey_tpl = new Template('survey_code_body.php');
             return new Answer('ok', $survey_tpl->process(array()), 'html');
         }
     } catch (Exception $e) {
         return new Answer('error', $e->getMessage(), 'html');
     }
 }
Example #9
0
    $example->save();
    return Example::first()->name == 'hello';
}, 'Model updates rows', 'Model');
Test::add(function () {
    $example = new Example(array('id' => 2));
    $example->delete();
    return Example::count() == 1;
}, 'Model deletes rows', 'Model');
/////////////// Templates test
$template = new Template(array("implementation" => new Template\Implementation\Standard()));
Test::add(function () use($template) {
    return $template instanceof Template;
}, "Template instantiates", "Template");
Test::add(function () use($template) {
    $template->parse("{echo 'hello world'}");
    $processed = $template->process();
    return $processed == "hello world";
}, "Template parses echo tag", "Template");
Test::add(function () use($template) {
    $template->parse("{script \$_text[] = 'foo bar' }");
    $processed = $template->process();
    return $processed == "foo bar";
}, "Template parses script tag", "Template");
Test::add(function () use($template) {
    $template->parse("\n            {foreach \$number in \$numbers}{echo \$number_i},{echo \$number},{/foreach}");
    $processed = $template->process(array("numbers" => array(1, 2, 3)));
    return trim($processed) == "0,1,1,2,2,3,";
}, "Template parses foreach tag", "Template");
Test::add(function () use($template) {
    $template->parse("\n            {for \$number in \$numbers}{echo \$number_i},{echo \$number},{/for}\n        ");
    $processed = $template->process(array("numbers" => array(1, 2, 3)));