Files
@ c7d7e38b2269
Branch filter:
Location: hot67beta/libraries/joomla/cache/handler/view.php
c7d7e38b2269
4.3 KiB
text/x-php
Initial import of the site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | <?php
/**
* @version $Id: view.php 10707 2008-08-21 09:52:47Z eddieajau $
* @package Joomla.Framework
* @subpackage Cache
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();
/**
* Joomla! Cache view type object
*
* @package Joomla.Framework
* @subpackage Cache
* @since 1.5
*/
class JCacheView extends JCache
{
/**
* Get the cached view data
*
* @access public
* @param object $view The view object to cache output for
* @param string $method The method name of the view method to cache output for
* @param string $group The cache data group
* @param string $id The cache data id
* @return boolean True if the cache is hit (false else)
* @since 1.5
*/
function get( &$view, $method, $id=false )
{
global $mainframe;
// Initialize variables
$data = false;
// If an id is not given generate it from the request
if ($id == false) {
$id = $this->_makeId($view, $method);
}
$data = parent::get($id);
if ($data !== false) {
$data = unserialize($data);
$document = &JFactory::getDocument();
// Get the document head out of the cache.
$document->setHeadData((isset($data['head'])) ? $data['head'] : array());
// If the pathway buffer is set in the cache data, get it.
if (isset($data['pathway']) && is_array($data['pathway']))
{
// Push the pathway data into the pathway object.
$pathway = &$mainframe->getPathWay();
$pathway->setPathway($data['pathway']);
}
// If a module buffer is set in the cache data, get it.
if (isset($data['module']) && is_array($data['module']))
{
// Iterate through the module positions and push them into the document buffer.
foreach ($data['module'] as $name => $contents) {
$document->setBuffer($contents, 'module', $name);
}
}
// Get the document body out of the cache.
echo (isset($data['body'])) ? $data['body'] : null;
return true;
}
/*
* No hit so we have to execute the view
*/
if (method_exists($view, $method))
{
$document = &JFactory::getDocument();
// Get the modules buffer before component execution.
$buffer1 = $document->getBuffer();
// Make sure the module buffer is an array.
if (!isset($buffer1['module']) || !is_array($buffer1['module'])) {
$buffer1['module'] = array();
}
// Capture and echo output
ob_start();
ob_implicit_flush( false );
$view->$method();
$data = ob_get_contents();
ob_end_clean();
echo $data;
/*
* For a view we have a special case. We need to cache not only the output from the view, but the state
* of the document head after the view has been rendered. This will allow us to properly cache any attached
* scripts or stylesheets or links or any other modifications that the view has made to the document object
*/
$cached = array();
// View body data
$cached['body'] = $data;
// Document head data
$cached['head'] = $document->getHeadData();
// Pathway data
$pathway = &$mainframe->getPathWay();
$cached['pathway'] = $pathway->getPathway();
// Get the module buffer after component execution.
$buffer2 = $document->getBuffer();
// Make sure the module buffer is an array.
if (!isset($buffer2['module']) || !is_array($buffer2['module'])) {
$buffer2['module'] = array();
}
// Compare the second module buffer against the first buffer.
$cached['module'] = array_diff_assoc($buffer2['module'], $buffer1['module']);
// Store the cache data
$this->store(serialize($cached), $id);
}
return false;
}
/**
* Generate a view cache id
*
* @access private
* @param object $view The view object to cache output for
* @param string $method The method name to cache for the view object
* @return string MD5 Hash : view cache id
* @since 1.5
*/
function _makeId(&$view, $method)
{
return md5(serialize(array(JRequest::getURI(), get_class($view), $method)));
}
}
|