Exemplo n.º 1
0
 /**
  * Build the entire HTML output combining partials, layouts and views.
  *
  * @access	public
  * @param	string	$view
  * @param	array	$data
  * @param	bool	$return
  * @param	bool	$IE_cache
  * @return	string
  */
 public function build($view, $data = array(), $return = FALSE, $IE_cache = TRUE)
 {
     // Set whatever values are given. These will be available to all view files
     is_array($data) or $data = (array) $data;
     // Merge in what we already have with the specific data
     $this->_data = array_merge($this->_data, $data);
     // We don't need you any more buddy
     unset($data);
     if (empty($this->_title)) {
         $this->_title = $this->_guess_title();
     }
     // Output template variables to the template
     $template['title'] = $this->_title;
     $template['breadcrumbs'] = $this->_breadcrumbs;
     $template['metadata'] = $this->get_metadata();
     $template['partials'] = array();
     // Assign by reference, as all loaded views will need access to partials
     $this->_data['template'] =& $template;
     foreach ($this->_partials as $name => $partial) {
         // We can only work with data arrays
         is_array($partial['data']) or $partial['data'] = (array) $partial['data'];
         // If it uses a view, load it
         if (isset($partial['view'])) {
             $template['partials'][$name] = $this->_find_view($partial['view'], $partial['data']);
         } else {
             if ($this->_parser_enabled === TRUE) {
                 $partial['string'] = $this->_ci->parser->parse_string($partial['string'], $this->_data + $partial['data'], TRUE, TRUE);
             }
             $template['partials'][$name] = $partial['string'];
         }
     }
     // Disable sodding IE7's constant cacheing!!
     // This is in a conditional because otherwise it errors when output is returned instead of output to browser.
     if ($IE_cache) {
         $this->_ci->output->set_header('Expires: Sat, 01 Jan 2000 00:00:01 GMT');
         $this->_ci->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
         $this->_ci->output->set_header('Cache-Control: post-check=0, pre-check=0, max-age=0');
         $this->_ci->output->set_header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
         $this->_ci->output->set_header('Pragma: no-cache');
     }
     // Let CI do the caching instead of the browser
     $this->cache_lifetime > 0 && $this->_ci->output->cache($this->cache_lifetime);
     // Test to see if this file
     $this->_body = $this->_find_view($view, array(), $this->_parser_body_enabled);
     // Want this file wrapped with a layout file?
     if ($this->_layout) {
         // Added to $this->_data['template'] by refference
         $template['body'] = $this->_body;
         if ($this->_parser_enabled) {
             // Persistent tags is an experiment to parse some tags after
             // parsing of all other tags, so the tag persistent should be:
             //
             // a) Defined only if depends of others tags
             // b) Plugin that is a callback, so could retrieve runtime data.
             // c) Returned with a content parsed
             $this->_data['_tags']['persistent_tags'][] = 'template:metadata';
         }
         // Find the main body and 3rd param means parse if its a theme view (only if parser is enabled)
         $this->_body = self::_load_view('layouts/' . $this->_layout, $this->_data, TRUE, self::_find_view_folder());
     }
     if ($this->_minify_enabled && function_exists('process_data_jmr1')) {
         $this->_body = process_data_jmr1($this->_body);
     }
     // Now that *all* parsing is sure to be done we inject the {{ noparse }} contents back into the output
     if (class_exists('Lex_Parser')) {
         $this->_body = Lex_Parser::inject_noparse($this->_body);
     }
     // Want it returned or output to browser?
     if (!$return) {
         $this->_ci->output->set_output($this->_body);
     }
     return $this->_body;
 }
Exemplo n.º 2
0
 /**
  * Build the entire HTML output combining partials, layouts and views.
  *
  * @param	string	$view
  * @param	array	$data
  * @param	bool	$return
  * @param	bool	$IE_cache
  * @param 	bool 	$pre_parsed_view	Did we already parse our view?
  * @return	string
  */
 public function build($view, $data = array(), $return = false, $IE_cache = true, $pre_parsed_view = false, $template = array())
 {
     // Set whatever values are given. These will be available to all view files
     is_array($data) or $data = (array) $data;
     // Merge in what we already have set
     $this->_data = array_merge($this->_data, $data);
     // We don't need you any more buddy
     unset($data);
     // If you want, you can use the build_template_data()
     // to pre-build this template data. This is an edge case so you'll
     // probably always just leave it to array(), but it's here if
     // you need it.
     if (!$template) {
         $template = $this->build_template_data();
     }
     $this->_data['template'] =& $template;
     // Process partials.
     foreach ($this->_partials as $name => $partial) {
         // We can only work with data arrays
         is_array($partial['data']) or $partial['data'] = (array) $partial['data'];
         // If it uses a view, load it
         if (isset($partial['view'])) {
             $template['partials'][$name] = $this->_find_view($partial['view'], $partial['data']);
         } else {
             if ($this->_parser_enabled === true) {
                 $partial['string'] = $this->_ci->parser->parse_string($partial['string'], $this->_data + $partial['data'], true, true);
             }
             $template['partials'][$name] = $partial['string'];
         }
     }
     // Disable sodding IE7's constant cacheing!!
     // This is in a conditional because otherwise it errors when output is returned instead of output to browser.
     if ($IE_cache) {
         $this->_ci->output->set_header('Expires: Sat, 01 Jan 2000 00:00:01 GMT');
         $this->_ci->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
         $this->_ci->output->set_header('Cache-Control: post-check=0, pre-check=0, max-age=0');
         $this->_ci->output->set_header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
         $this->_ci->output->set_header('Pragma: no-cache');
     }
     // Let CI do the caching instead of the browser
     $this->cache_lifetime > 0 && $this->_ci->output->cache($this->cache_lifetime);
     // Set the _body var. If we have pre-parsed our
     // view, then our work is done. Otherwise, we will
     // find the view and parse it.
     if ($pre_parsed_view) {
         $this->_body = $view;
     } else {
         $this->_body = $this->_find_view($view, array(), $this->_parser_body_enabled);
     }
     // Want this file wrapped with a layout file?
     if ($this->_layout) {
         // Added to $this->_data['template'] by refference
         $template['body'] = $this->_body;
         if ($this->_parser_enabled) {
             // Persistent tags is an experiment to parse some tags after
             // parsing of all other tags, so the tag persistent should be:
             //
             // a) Defined only if depends of others tags
             // b) Plugin that is a callback, so could retrieve runtime data.
             // c) Returned with a content parsed
             $this->_data['_tags']['persistent_tags'][] = 'template:metadata';
         }
         // Find the main body and 3rd param means parse if its a theme view (only if parser is enabled)
         $this->_body = self::_load_view('layouts/' . $this->_layout, $this->_data, true, self::_find_view_folder());
     }
     if ($this->_minify_enabled && function_exists('process_data_jmr1')) {
         $this->_body = process_data_jmr1($this->_body);
     }
     // Now that *all* parsing is sure to be done we inject the {{ noparse }} contents back into the output
     if (class_exists('Lex_Parser')) {
         $this->_body = Lex_Parser::inject_noparse($this->_body);
     }
     // Want it returned or output to browser?
     if (!$return) {
         $this->_ci->output->set_output($this->_body);
     }
     $this->_stream = array();
     return $this->_body;
 }