Esempio n. 1
0
 function should_include_dynamic_filenames_in_include_tag()
 {
     $opt = array('searchpath' => dirname(__FILE__) . DS . 'templates');
     $h2o = h2o('dynamic_include.tpl', $opt);
     expects($h2o->render())->should_match('/DYNAMIC TEMPLATE #1/');
     expects($h2o->render())->should_match('/DYNAMIC TEMPLATE #2/');
 }
Esempio n. 2
0
 public function should_escape_output_by_default()
 {
     $a = '<script>danger</script>';
     $b = '<h1>Welcome</h1>';
     $c = create_context(compact('a', 'b'));
     expects(h2o('{{ a }}')->render($c))->should_be('&lt;script&gt;danger&lt;/script&gt;');
     expects(h2o('{{ b|safe }}')->render($c))->should_be('<h1>Welcome</h1>');
     # disable autoescape as option
     expects(h2o('{{ a }}', array('autoescape' => false))->render(compact('a', 'b')))->should_be($a);
     # disable autoescape on context object
     $c->autoescape = false;
     expects(h2o('{{ a }}')->render($c))->should_be($a);
 }
Esempio n. 3
0
 public function should_invalidate_cache_if_any_subtemplates_has_updated()
 {
     $opt = array('searchpath' => dirname(__FILE__) . DS . 'templates');
     # Load template twice to make sure its cached
     $h2o = h2o('emails/campaign1.html', $opt);
     $h2o->loadTemplate('emails/campaign1.html');
     expects($h2o->loader->cached)->should_be(true);
     # Touch parent template
     sleep(1);
     touch(dirname(__FILE__) . DS . 'templates/emails/base.html');
     $h2o->loadTemplate('emails/campaign1.html');
     expects($h2o->loader->cached)->should_be(false);
     $h2o->loader->flush_cache();
 }
Esempio n. 4
0
 function should_provide_variable_loop_in_for_block()
 {
     $context = array('items' => array(1, 2, 3, 4, 5));
     $rs = h2o('{% for e in items %}{{ loop.counter }}{%endfor%}')->render($context);
     expects($rs)->should_be('12345');
     $rs = h2o('{% for e in items %}{{ loop.counter0 }}{%endfor%}')->render($context);
     expects($rs)->should_be('01234');
     $rs = h2o('{% for e in items %}{{ loop.revcounter }}{%endfor%}')->render($context);
     expects($rs)->should_be('54321');
     $rs = h2o('{% for e in items %}{{ loop.revcounter0 }}{%endfor%}')->render($context);
     expects($rs)->should_be('43210');
     $rs = h2o('{% for e in items %}{% if loop.first %}first{% else %}{{ e }}{% endif %}{%endfor%}')->render($context);
     expects($rs)->should_be('first2345');
     $rs = h2o('{% for e in items %}{% if loop.last %}last{% else %}{{ e }}{% endif %}{%endfor%}')->render($context);
     expects($rs)->should_be('1234last');
     $rs = h2o('{% for e in items %}{% if loop.even%}even{% else %}{{ e }}{% endif %}{%endfor%}')->render($context);
     expects($rs)->should_be('1even3even5');
     $rs = h2o('{% for e in items %}{% if loop.odd%}odd{% else %}{{ e }}{% endif %}{%endfor%}')->render($context);
     expects($rs)->should_be('odd2odd4odd');
 }
Esempio n. 5
0
 function should_correctly_parse_expressions()
 {
     $pi = 3;
     $result = h2o('{{ (pi+1)/2+10 }}')->render(compact('pi'));
     expects($result)->should_be('12');
     $except = false;
     try {
         $res = h2o('{{ ()pi+1)/2+10 }}')->render(compact('pi'));
     } catch (Exception $e) {
         $except = true;
     }
     expects($except)->should_be(true);
     $except = false;
     try {
         $res = h2o('{{ +1 }}')->render(compact('pi'));
     } catch (Exception $e) {
         $except = true;
     }
     expects($except)->should_be(true);
 }
Esempio n. 6
0
 function getcomments($id)
 {
     Configure::write('debug', '0');
     //turn debugging off; debugging breaks ajax
     $this->layout = 'ajax';
     $comments = Set::extract($this->Comment->getComments($this->Event, $id), '{n}.Comment');
     $event = $this->Event->findById($id);
     $params = array();
     $params['summary'] = $event['Event']['summary'];
     $params['start_time'] = $event['Event']['start_time'];
     $params['end_time'] = $event['Event']['end_time'];
     App::import("Model", 'Template');
     $template = new Template();
     $res = $template->findByName('timelineevent-details');
     $tpl = $res['Template']['temp'];
     App::import('Vendor', 'h2o/h2o');
     App::import('Vendor', 'filters');
     $details = h2o($tpl, array('autoescape' => false))->render($params);
     $this->set('json', array('success' => TRUE, 'comments' => $comments, 'details' => $details, 'created' => $event['Event']['created']));
 }
Esempio n. 7
0
 public function render()
 {
     //On a la liste des modules... On récupère les tableaux de bord...
     $this->dashboards = array();
     foreach ($this->dashboard_modules as $module_name) {
         $dashboard_classname = "dashboard_module_" . $module_name;
         $this->dashboards[] = new $dashboard_classname();
     }
     //les différents tableaux
     $this->dasboard_to_print = $context = array();
     foreach ($this->dashboards as $dashboard) {
         if ($dashboard->module == "dashboard") {
             $context['quick_actions'] = $dashboard->get_quick_params_form();
         }
         $this->dasboard_to_print = array_merge($this->dasboard_to_print, $dashboard->render_infos());
     }
     //on charge le layout !
     $template = $this->load_layout();
     $context['dashboards'] = $this->dasboard_to_print;
     return h2o($template)->render($context);
 }
Esempio n. 8
0
 function should_apply_filter_if_available()
 {
     $name = 'taylor luk';
     $result = h2o('{{ name|capitalize }}')->render(compact('name'));
     expects($result)->should_be('Taylor Luk');
 }
Esempio n. 9
0
 public function should_return_nested_items()
 {
     $context = array('granfather' => array('father' => array('child' => 'mike')));
     $rs = h2o('{% with granfather.father.child as child %}{{ child }}{% endwith %}')->render($context);
     expects($rs)->should_be('mike');
 }
Esempio n. 10
0
 public function should_be_able_to_register_a_filter_collection()
 {
     h2o::addFilter('SampleFilters');
     $result = h2o('{{ person | hello }}')->render(array('person' => 'peter'));
     expects($result)->should_be('says hello to peter');
 }
Esempio n. 11
0
 function prepareevent($event, $short = false)
 {
     $parameters = $event['param'];
     // Only if parameters are not void or null
     if ($parameters && $parameters != null) {
         // Decode parameters from json into an array
         $eventparam = json_decode($parameters, TRUE);
     } else {
         $eventparam = array();
     }
     if ($event['user_id'] != null) {
         if ($event['gender'] == 1) {
             $adjective = 'his';
         } else {
             if ($event['gender'] == 2) {
                 $adjective = 'her';
             } else {
                 $adjective = 'her/his';
             }
         }
         $event['adj'] = $adjective;
         if (!array_key_exists('user', $eventparam)) {
             $eventparam['user'] = array();
         }
         $keys = array('id' => 'user_id', 'name' => 'name', 'surname' => 'surname', 'login' => 'login', 'adj' => 'adj', 'commenter_id' => 'commenter_id', 'deleted' => 'deleted');
         foreach ($keys as $k => $key) {
             if (isset($event[$key])) {
                 $eventparam['user'][$k] = $event[$key];
             }
         }
     }
     if (array_key_exists('timelineid', $event)) {
         $eventparam['timelineid'] = $event['timelineid'];
     } else {
         $eventparam['timelineid'] = $event['id'];
     }
     $eventparam['sitename'] = $this->Conf->get('Site.name');
     $eventparam['short_version'] = $short;
     return h2o($event['temp'], array('autoescape' => false))->render($eventparam);
 }
Esempio n. 12
0
 public function render_infos($template = "")
 {
     $template = $this->load_template($template);
     if (!count($this->infos)) {
         $this->get_infos();
     }
     if (count($this->infos)) {
         $rendered = array(array('name' => $this->module_name, 'alert_url' => $this->alert_url, 'module' => $this->module, 'id' => "dashboard_" . $this->module . "_0", 'html' => h2o($template)->render($this->infos)));
     } else {
         $rendered = array();
     }
     return $rendered;
 }
Esempio n. 13
0
function spp($term = "", $template = 'default.html', $hack = "")
{
    global $spp_settings;
    $result = h2o(SPP_PATH . "/templates/{$template}", array('safeClass' => array('SimpleXMLElement', 'stdClass')));
    return $result->render(array('term' => $term, 'hack' => $hack, 'settings' => $spp_settings, 'get' => $_GET));
}
Esempio n. 14
0
 function getcomments($id)
 {
     Configure::write('debug', '0');
     //turn debugging off; debugging breaks ajax
     $this->layout = 'ajax';
     $comments = Set::extract($this->Comment->getComments($this->Photo, $id), '{n}.Comment');
     $photo = $this->Photo->findById($id);
     $params = array();
     $params['id'] = $photo['Photo']['id'];
     $params['name'] = $photo['Photo']['name'];
     $params['filename'] = substr_replace($photo['Photo']['filename'], '.jpg', strrpos($photo['Photo']['filename'], '.'));
     $params['img_path'] = $this->Conf->get('Images.people_web_path');
     App::import("Model", 'Template');
     $template = new Template();
     $res = $template->findByName('photo-details');
     $tpl = $res['Template']['temp'];
     App::import('Vendor', 'h2o/h2o');
     App::import('Vendor', 'filters');
     $details = h2o($tpl, array('autoescape' => false))->render($params);
     $this->set('json', array('success' => TRUE, 'comments' => $comments, 'details' => $details, 'created' => $photo['Photo']['created']));
 }