public function parse_string($template, $data = array(), $return = FALSE, $options = array())
 {
     if (!is_array($options)) {
         $options = array();
     }
     $options = array_merge($this->config, $options);
     $options['cumulative_noparse'] = !empty($options['cumulative_noparse']);
     if (is_object($data)) {
         $data = get_object_vars($data);
     }
     if (!is_array($data)) {
         if (empty($data)) {
             $data = array();
         } else {
             $data = (array) $data;
         }
     }
     $ci = $this->ci;
     $is_mx = false;
     if (!$return) {
         list($ci, $is_mx) = $this->detect_mx();
     }
     $parser = new Parser_Lex_Extensions();
     $parser->scopeGlue($options['scope_glue']);
     $parser->cumulativeNoparse($options['cumulative_noparse']);
     $data = array_merge($data, $ci->load->_ci_cached_vars);
     $parser->parser_options = $options;
     $template = $parser->parse($template, $data, array($parser, 'parser_callback'), $options['allow_php']);
     if ($options['cumulative_noparse']) {
         $template = Parser_Lex_Extensions::injectNoparse($template);
     }
     return $this->output($template, $return, $ci, $is_mx);
 }
 public function set_extension_data($content, $attributes)
 {
     $content and $this->parsed_content = $content;
     $parse_content = false;
     switch ($this->extension_class) {
         case 'html':
             $parse_content = true;
             break;
     }
     if ($attributes) {
         $set = false;
         // Check for parsing the tag's content..
         // Parsing is enabled by default, it could be disabled
         // using a special parameter for that.
         foreach (array('parse_content', 'parse-content') as $attr) {
             if (isset($attributes[$attr]) && !$set) {
                 $parse_content = str_to_bool($attributes[$attr]);
                 $set = true;
             }
             if (isset($attributes[$attr])) {
                 unset($attributes[$attr]);
             }
         }
     }
     if (empty($content) || is_scalar($content) && trim($content) == '') {
         $parse_content = true;
     }
     if (!$parse_content) {
         $this->parse_tag_content = false;
     }
     if ($parse_content && is_scalar($this->parsed_content) && $this->parsed_content != '') {
         $parser = new Parser_Lex_Extensions();
         $parser->scopeGlue($this->parser_instance->parser_options['scope_glue']);
         $parser->cumulativeNoparse($this->parser_instance->parser_options['cumulative_noparse']);
         $this->parsed_content = $parser->parse($this->parsed_content, $this->parser_instance->parser_data, array($this->parser_instance, 'parser_callback'), $this->parser_instance->parser_options['allow_php']);
         unset($parser);
     }
     if ($attributes) {
         $parse_params = true;
         $set = false;
         // Check for additional parsing of the parameters.
         // Additional parsing is enabled by default, it could be disabled
         // using a special parameter for that.
         foreach (array('parse_params', 'parse-params') as $attr) {
             if (isset($attributes[$attr]) && !$set) {
                 $parse_params = str_to_bool($attributes[$attr]);
                 $set = true;
             }
             if (isset($attributes[$attr])) {
                 unset($attributes[$attr]);
             }
         }
         $no_value = new Parser_Lex_No_Value();
         foreach ($attributes as $key => $attr) {
             if (is_string($attr)) {
                 if ($this->parser_instance->is_serialized(trim($attr), $value)) {
                     $attributes[$key] = $value;
                 } elseif (preg_match('/^\\s*\\[\\[(.*)\\]\\]\\s*$/ms', $attr, $matches) && ($value = $this->parser_instance->getVariable(trim($matches[1]), $this->parser_instance->parser_data, $no_value)) !== $no_value) {
                     $attributes[$key] = $value;
                 } elseif ($parse_params && strpos($attr, '[[') !== false && strpos($attr, ']]') !== false) {
                     $a = trim(str_replace(array('[[', ']]'), array('{{', '}}'), $attr));
                     $parser = new Parser_Lex_Extensions();
                     $parser->is_attribute_being_parsed = true;
                     $parser->scopeGlue($this->parser_instance->parser_options['scope_glue']);
                     $parser->cumulativeNoparse($this->parser_instance->parser_options['cumulative_noparse']);
                     $value = $parser->parse($a, $this->parser_instance->parser_data, array($this->parser_instance, 'parser_callback'), $this->parser_instance->parser_options['allow_php']);
                     unset($parser);
                     $attributes[$key] = $this->parser_instance->is_serialized(trim($value), $result) ? $result : $value;
                 }
             }
         }
     }
     $this->parsed_attributes = $attributes;
 }
Exemplo n.º 3
0
 /**
  * extend
  *
  * Usage:
  * {{ layout:extend file='layouts/base-layout.html' }}
  *     {{ layout:content name='body' }}
  *         my body
  *     {{ /layout:content }}
  * {{ /layout:extend }}
  *
  * @return string
  */
 public function extend($name = 'extend')
 {
     $base_layout = $this->get_attribute('file', NULL);
     $string = '';
     $path = $this->load->get_var('template_views');
     $path = $path . $base_layout;
     if ($path != '') {
         $string = @(string) file_get_contents($path);
     }
     $content = $this->get_content();
     $content = is_string($content) ? $content : '';
     $parser = new Parser_Lex_Extensions();
     $parser->scopeGlue($this->parser_instance->parser_options['scope_glue']);
     $parser->cumulativeNoparse($this->parser_instance->parser_options['cumulative_noparse']);
     $parser->parser_options = $this->parser_instance->parser_options;
     $parser->parse($content, $this->parser_instance->parser_data, array($this->parser_instance, 'parser_callback'), $this->parser_instance->parser_options['allow_php']);
     $result = $parser->parse($string, $this->parser_instance->parser_data, array($this->parser_instance, 'parser_callback'), $this->parser_instance->parser_options['allow_php']);
     return $result;
 }