Ejemplo n.º 1
0
 public function resolve(OOTemplate_Context $context)
 {
     $resolved = $this->_variable->resolve($context);
     foreach (explode('|', $this->_filters) as $filter) {
         $filter = trim($filter);
         if (!empty($filter)) {
             @(list($filter_name, $str_args) = explode(':', $filter, 2));
             try {
                 $args = array();
                 foreach (explode(',', $str_args) as $arg) {
                     switch (strpos($arg, "'") || strpos($arg, '"')) {
                         case true:
                             $args[] = trim($arg, '\'" ');
                             break;
                         case false:
                             $args[] = new OOTemplate_Variable($arg);
                             break;
                     }
                 }
                 $resolved = OOTemplate_Libs::filter($filter_name, $resolved, $args)->resolve($context);
             } catch (OOTemplate_Exception $e) {
                 OOTemplate_Debug::show($e->getMessage());
             }
         }
     }
     return $resolved;
 }
Ejemplo n.º 2
0
 public function resolve(OOTemplate_Context $context)
 {
     $resolved = clone $context;
     try {
         foreach (explode('.', $this->_variable) as $bit) {
             if (!$resolved instanceof OOTemplate_Context) {
                 throw new OOTemplate_Exception(sprintf("Variable is invalid : %s", $this->_variable));
             }
             $resolved = $resolved->get($bit, OOTemplate_Setting::$string_ifnot_defined);
         }
     } catch (OOTemplate_Exception $e) {
         OOTemplate_Debug::show($e->getMessage());
     }
     if (OOTemplate_Setting::$autoescape) {
         $resolved = $this->escape($resolved);
     }
     return $resolved;
 }
Ejemplo n.º 3
0
 public function render(OOTemplate_Context $context)
 {
     try {
         list(, $arg) = $this->_token->split();
         if (strpos($arg, "'") === false && strpos($arg, '"') === false) {
             $o = new OOTemplate_Variable($arg);
             $file = $o->resolve($context);
         } else {
             $file = trim($arg, '\'" ');
         }
         $result = @file_get_contents(OOTemplate_Setting::generate_inc_path($file));
         if ($result === false) {
             throw new OOTemplate_Exception(vsprintf('failed to open stream: %s, check OOTemplate_Setting::$dir_include', $file));
         }
     } catch (OOTemplate_Exception $e) {
         OOTemplate_Debug::show($e->getMessage());
     }
     return $result;
 }
Ejemplo n.º 4
0
 public function render(OOTemplate_Context $context)
 {
     $result = "";
     list(, $o, , $var) = $this->_token->split();
     try {
         if (is_null($o) || is_null($var)) {
             throw new OOTemplate_Exception(sprintf("'for' statements should use the format : 'for x in y' : %s", $this->_token->contents()));
         }
         if (!$context->has_key($var)) {
             throw new OOTemplate_Exception(sprintf("'for' tag received an invalid argument : %s", $this->_token->contents()));
         }
         $current = clone $context;
         foreach ($context->get($var) as $each) {
             $current->set($o, $each->getDicts());
             foreach ($this->_nodes as $node) {
                 $result .= $node->render($current);
             }
         }
     } catch (OOTemplate_Exception $e) {
         OOTemplate_Debug::show($e->getMessage());
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Execute and return the template result
  *
  * @param string $template_file, the template file or null if alredy defined
  * @return string an evaluate contents of template
  */
 public function render($template_file = null)
 {
     try {
         if (!is_null($template_file)) {
             $this->_document->setFile($template_file);
         }
         return $this->_document->render($this->_context);
     } catch (OOTemplate_Exception $e) {
         OOTemplate_Debug::show($e->getMessage());
     }
 }