コード例 #1
0
 /**
  * Build the entire HTML output combining partials, layouts and views.
  *
  * @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)
 {
     // Added by Ivan Tcholakov, 25-OCT-2012.
     // Preliminary caching the variable $this->_ci->load->_ci_cached_vars['template_views'],
     // so the helper function file_partial() gets able to work.
     self::_find_view_folder();
     //
     // 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'] = trim(implode("\n    ", $this->_metadata));
     if ($template['metadata'] != '') {
         $template['metadata'] = "\n    " . $template['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'])) {
             // Modified by Ivan Tcholakov, 28-DEC-2013.
             //$template['partials'][$name] = $this->_find_view($partial['view'], $partial['data']);
             $template['partials'][$name] = $this->_find_view($partial['view'], $partial['data'], $this->_parsers);
             //
         } else {
             // Modified by Ivan Tcholakov, 27-DEC-2013.
             //if ($this->_parser_enabled === true)
             //{
             //    $partial['string'] = $this->_ci->parser->parse_string($partial['string'], $this->_data + $partial['data'], true, true);
             //}
             if (!empty($this->_parsers)) {
                 $data = $this->_data + $partial['data'];
                 foreach ($this->_parsers as $parser => $config) {
                     $this->_ci->load->parser($parser);
                     $partial['string'] = $this->_ci->{$parser}->parse_string($partial['string'], $data, true, $config);
                 }
                 unset($data);
             }
             //
             $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', true);
         $this->_ci->output->set_header('Cache-Control: no-store, no-cache, must-revalidate', true);
         $this->_ci->output->set_header('Cache-Control: post-check=0, pre-check=0, max-age=0', false);
         $this->_ci->output->set_header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT', true);
         $this->_ci->output->set_header('Pragma: no-cache', true);
     }
     // 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
     // Modified by Ivan Tcholakov, 28-DEC-2013.
     //$this->_body = $this->_find_view( $view, array(), $this->_parser_body_enabled );
     $this->_body = $this->_find_view($view, array(), $this->_parsers_body);
     //
     // Want this file wrapped with a layout file?
     if ($this->_layout) {
         // Added to $this->_data['template'] by refference
         $template['body'] = $this->_body;
         // Find the main body and 3rd param means parse if its a theme view (only if parser is enabled)
         // Modified by Ivan Tcholakov, 25-JUN-2014.
         // A very dirty fix for https://github.com/ivantcholakov/starter-public-edition-4/issues/16
         //// Modified by Ivan Tcholakov, 27-DEC-2013.
         ////$this->_body = self::_load_view('layouts/'.$this->_layout, $this->_data, true, self::_find_view_folder());
         //$this->_body = self::_load_view('layouts/'.$this->_layout, $this->_data, $this->_parsers, self::_find_view_folder());
         ////
         if (file_exists(self::_find_view_folder() . 'layouts/' . $this->_layout . self::_ext($this->_layout))) {
             $this->_body = self::_load_view('layouts/' . $this->_layout, $this->_data, $this->_parsers, self::_find_view_folder());
         } elseif (file_exists(self::_find_view_folder(true) . 'layouts/' . $this->_layout . self::_ext($this->_layout))) {
             $this->_body = self::_load_view('layouts/' . $this->_layout, $this->_data, $this->_parsers, self::_find_view_folder(true));
         } else {
             // This probably would fail and show the error message.
             $this->_body = self::_load_view('layouts/' . $this->_layout, $this->_data, $this->_parsers, self::_find_view_folder());
         }
         //
     }
     if ($this->_minify_enabled && function_exists('process_data_jmr1')) {
         $this->_body = process_data_jmr1($this->_body);
     }
     // Want it returned or output to browser?
     if (!$return) {
         $this->_ci->output->set_output($this->_body);
         // Added by Ivan Tcholakov, 29-MAR-2013.
         return;
         //
     }
     return $this->_body;
 }
コード例 #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())
    {
        // Added by Ivan Tcholakov, 20-JAN-2016.
        $this->_parsers = $this->build_parser_options($this->_parsers, $this->_parsers_config);
        $this->_parsers_body = $this->build_parser_options($this->_parsers_body, $this->_parsers_body_config);
        //
        // Added by Ivan Tcholakov, 25-OCT-2012.
        // Preliminary caching the variable $this->_ci->load->_ci_cached_vars['template_views'],
        // so the helper function file_partial() gets able to work.
        $this->_find_view_folder();
        //
        // 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();
        }
        // Assign by reference, as all loaded views will need access to partials
        $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'])) {
                // Modified by Ivan Tcholakov, 28-DEC-2013.
                //$template['partials'][$name] = $this->_find_view($partial['view'], $partial['data']);
                $template['partials'][$name] = $this->_find_view($partial['view'], $partial['data'], $this->_parsers);
                //
            } else {
                // Modified by Ivan Tcholakov, 27-DEC-2013.
                //if ($this->_parser_enabled === true) {
                //    $partial['string'] = $this->_ci->parser->parse_string($partial['string'], $this->_data + $partial['data'], true, true);
                //}
                if (!empty($this->_parsers)) {
                    $data = $this->_data + $partial['data'];
                    foreach ($this->_parsers as $parser => $config) {
                        $this->_ci->load->parser($parser);
                        $partial['string'] = $this->_ci->{$parser}->parse_string($partial['string'], $data, true, $config);
                    }
                    unset($data);
                }
                //
                $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', true);
            $this->_ci->output->set_header('Cache-Control: no-store, no-cache, must-revalidate', true);
            $this->_ci->output->set_header('Cache-Control: post-check=0, pre-check=0, max-age=0', false);
            $this->_ci->output->set_header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT', true);
            $this->_ci->output->set_header('Pragma: no-cache', true);
        }
        // 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.
        $this->_body = $this->template_body_placeholder;
        if ($pre_parsed_view) {
            //$this->_body = $view;
            $template_body = $view;
        } else {
            // Modified by Ivan Tcholakov, 28-DEC-2013.
            //$this->_body = $this->_find_view($view, array(), $this->_parser_body_enabled);
            //$this->_body = $this->_find_view($view, array(), $this->_parsers_body);
            $template_body = $this->_find_view($view, array(), $this->_parsers_body);
            //
        }
        // Want this file wrapped with a layout file?
        if (!$this->_ci->input->get_request_header('X-PJAX') && $this->_layout) {
            // Added to $this->_data['template'] by refference
            $template['body'] = $this->_body;
            // Find the main body and 3rd param means parse if its a theme view (only if parser is enabled)
            // Modified by Ivan Tcholakov, 25-JUN-2014.
            // A very dirty fix for https://github.com/ivantcholakov/starter-public-edition-4/issues/16
            //// Modified by Ivan Tcholakov, 27-DEC-2013.
            ////$this->_body = $this->_load_view('layouts/'.$this->_layout, $this->_data, true, $this->_find_view_folder());
            //$this->_body = $this->_load_view('layouts/'.$this->_layout, $this->_data, $this->_parsers, $this->_find_view_folder());
            //// Modified by Ivan Tcholakov, 16-JAN-2016.
            ////if (file_exists($this->_find_view_folder().'layouts/'.$this->_layout.$this->_ext($this->_layout))) {
            ////    $this->_body = $this->_load_view('layouts/'.$this->_layout, $this->_data, $this->_parsers, $this->_find_view_folder());
            ////} elseif (file_exists($this->_find_view_folder(true).'layouts/'.$this->_layout.$this->_ext($this->_layout))) {
            ////    $this->_body = $this->_load_view('layouts/'.$this->_layout, $this->_data, $this->_parsers, $this->_find_view_folder(true));
            ////} else {
            ////    // This probably would fail and show the error message.
            ////    $this->_body = $this->_load_view('layouts/'.$this->_layout, $this->_data, $this->_parsers, $this->_find_view_folder());
            ////}
            if (($file = $this->_ci->parser->find_file($this->_find_view_folder() . 'layouts/' . $this->_layout)) !== null) {
                $this->_body = $this->_ci->load->_ci_load(array('_ci_path' => $file, '_ci_vars' => $this->_data, '_ci_return' => true, '_ci_parsers' => $this->_parsers));
            } elseif (($file = $this->_ci->parser->find_file($this->_find_view_folder(true) . 'layouts/' . $this->_layout)) !== null) {
                $this->_body = $this->_ci->load->_ci_load(array('_ci_path' => $file, '_ci_vars' => $this->_data, '_ci_return' => true, '_ci_parsers' => $this->_parsers));
            } else {
                show_error('Unable to load the requested layout: ' . $this->_layout);
            }
            //
        } elseif ($this->_ci->input->get_request_header('X-PJAX')) {
            if (strpos($this->_ci->input->get_request_header('Accept'), 'text/html') !== false && $this->_title != '') {
                // Ivan, 15-AUG-2015:
                // This makes not valid HTML, title tag should not exist within the returned
                // HTML fragment, but I can't the make other way to work.
                $this->_body = '
    <title>' . html_escape(strip_tags($this->_title)) . '</title>
' . $this->_body;
            }
        }
        //
        // Added by Ivan Tcholakov, 20-JAN-2016.
        $this->_body = str_replace($this->template_body_placeholder, $template_body, $this->_body);
        //
        if ($this->_minify_enabled && function_exists('process_data_jmr1')) {
            $this->_body = process_data_jmr1($this->_body);
        }
        // Want it returned or output to browser?
        if (!$return) {
            $this->_ci->output->set_output($this->_body);
            // Added by Ivan Tcholakov, 29-MAR-2013.
            return;
            //
        }
        return $this->_body;
    }
コード例 #3
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;
 }
コード例 #4
0
ファイル: Template.php プロジェクト: phonglanpls/jz-proj-2012
 /**
  * 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;
 }
コード例 #5
0
ファイル: Template.php プロジェクト: JamieLomas/pyrocms
	/**
	 * Build the entire HTML output combining partials, layouts and views.
	 *
	 * @access	public
	 * @param	string	$view
	 * @param	array	$data
	 * @param	bool	$return
	 * @return	string
	 */
	public function build($view, $data = array(), $return = FALSE)
	{
		// 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']		= implode("\n\t\t", $this->_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']);
			}

			// Otherwise the partial must be a string
			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->_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;

			// 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);
		}

		// Want it returned or output to browser?
		if ( ! $return)
		{
			$this->_ci->output->set_output($this->_body);
		}

		return $this->_body;
	}