You've already forked joomla_test
first commit
This commit is contained in:
205
libraries/joomla/cache/controller/callback.php
vendored
Normal file
205
libraries/joomla/cache/controller/callback.php
vendored
Normal file
@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Cache
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Joomla! Cache callback type object
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Cache
|
||||
* @since 11.1
|
||||
*/
|
||||
class JCacheControllerCallback extends JCacheController
|
||||
{
|
||||
/**
|
||||
* Executes a cacheable callback if not found in cache else returns cached output and result
|
||||
*
|
||||
* Since arguments to this function are read with func_get_args you can pass any number of
|
||||
* arguments to this method
|
||||
* as long as the first argument passed is the callback definition.
|
||||
*
|
||||
* The callback definition can be in several forms:
|
||||
* - Standard PHP Callback array see <http://php.net/callback> [recommended]
|
||||
* - Function name as a string eg. 'foo' for function foo()
|
||||
* - Static method name as a string eg. 'MyClass::myMethod' for method myMethod() of class MyClass
|
||||
*
|
||||
* @return mixed Result of the callback
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function call()
|
||||
{
|
||||
// Get callback and arguments
|
||||
$args = func_get_args();
|
||||
$callback = array_shift($args);
|
||||
|
||||
return $this->get($callback, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a cacheable callback if not found in cache else returns cached output and result
|
||||
*
|
||||
* @param mixed $callback Callback or string shorthand for a callback
|
||||
* @param array $args Callback arguments
|
||||
* @param string $id Cache id
|
||||
* @param boolean $wrkarounds True to use wrkarounds
|
||||
* @param array $woptions Workaround options
|
||||
*
|
||||
* @return mixed Result of the callback
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function get($callback, $args = array(), $id = false, $wrkarounds = false, $woptions = array())
|
||||
{
|
||||
|
||||
// Normalize callback
|
||||
if (is_array($callback))
|
||||
{
|
||||
// We have a standard php callback array -- do nothing
|
||||
}
|
||||
elseif (strstr($callback, '::'))
|
||||
{
|
||||
// This is shorthand for a static method callback classname::methodname
|
||||
list ($class, $method) = explode('::', $callback);
|
||||
$callback = array(trim($class), trim($method));
|
||||
}
|
||||
elseif (strstr($callback, '->'))
|
||||
{
|
||||
/*
|
||||
* This is a really not so smart way of doing this... we provide this for backward compatability but this
|
||||
* WILL! disappear in a future version. If you are using this syntax change your code to use the standard
|
||||
* PHP callback array syntax: <http://php.net/callback>
|
||||
*
|
||||
* We have to use some silly global notation to pull it off and this is very unreliable
|
||||
*/
|
||||
list ($object_123456789, $method) = explode('->', $callback);
|
||||
global $$object_123456789;
|
||||
$callback = array($$object_123456789, $method);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have just a standard function -- do nothing
|
||||
}
|
||||
|
||||
if (!$id)
|
||||
{
|
||||
// Generate an ID
|
||||
$id = $this->_makeId($callback, $args);
|
||||
}
|
||||
|
||||
$data = $this->cache->get($id);
|
||||
|
||||
$locktest = new stdClass;
|
||||
$locktest->locked = null;
|
||||
$locktest->locklooped = null;
|
||||
|
||||
if ($data === false)
|
||||
{
|
||||
$locktest = $this->cache->lock($id);
|
||||
if ($locktest->locked == true && $locktest->locklooped == true)
|
||||
{
|
||||
$data = $this->cache->get($id);
|
||||
}
|
||||
}
|
||||
|
||||
$coptions = array();
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
|
||||
$cached = unserialize(trim($data));
|
||||
$coptions['mergehead'] = isset($woptions['mergehead']) ? $woptions['mergehead'] : 0;
|
||||
$output = ($wrkarounds == false) ? $cached['output'] : JCache::getWorkarounds($cached['output'], $coptions);
|
||||
$result = $cached['result'];
|
||||
if ($locktest->locked == true)
|
||||
{
|
||||
$this->cache->unlock($id);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (!is_array($args))
|
||||
{
|
||||
$Args = !empty($args) ? array(&$args) : array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$Args = &$args;
|
||||
}
|
||||
|
||||
if ($locktest->locked == false)
|
||||
{
|
||||
$locktest = $this->cache->lock($id);
|
||||
}
|
||||
|
||||
if (isset($woptions['modulemode']) && $woptions['modulemode'] == 1)
|
||||
{
|
||||
$document = JFactory::getDocument();
|
||||
$coptions['modulemode'] = 1;
|
||||
$coptions['headerbefore'] = $document->getHeadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
$coptions['modulemode'] = 0;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
ob_implicit_flush(false);
|
||||
|
||||
$result = call_user_func_array($callback, $Args);
|
||||
$output = ob_get_contents();
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
$cached = array();
|
||||
|
||||
$coptions['nopathway'] = isset($woptions['nopathway']) ? $woptions['nopathway'] : 1;
|
||||
$coptions['nohead'] = isset($woptions['nohead']) ? $woptions['nohead'] : 1;
|
||||
$coptions['nomodules'] = isset($woptions['nomodules']) ? $woptions['nomodules'] : 1;
|
||||
|
||||
$cached['output'] = ($wrkarounds == false) ? $output : JCache::setWorkarounds($output, $coptions);
|
||||
$cached['result'] = $result;
|
||||
|
||||
// Store the cache data
|
||||
$this->cache->store(serialize($cached), $id);
|
||||
if ($locktest->locked == true)
|
||||
{
|
||||
$this->cache->unlock($id);
|
||||
}
|
||||
}
|
||||
|
||||
echo $output;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a callback cache id
|
||||
*
|
||||
* @param callback $callback Callback to cache
|
||||
* @param array $args Arguments to the callback method to cache
|
||||
*
|
||||
* @return string MD5 Hash : function cache id
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
protected function _makeId($callback, $args)
|
||||
{
|
||||
if (is_array($callback) && is_object($callback[0]))
|
||||
{
|
||||
$vars = get_object_vars($callback[0]);
|
||||
$vars[] = strtolower(get_class($callback[0]));
|
||||
$callback[0] = $vars;
|
||||
}
|
||||
|
||||
return md5(serialize(array($callback, $args)));
|
||||
}
|
||||
}
|
1
libraries/joomla/cache/controller/index.html
vendored
Normal file
1
libraries/joomla/cache/controller/index.html
vendored
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
122
libraries/joomla/cache/controller/output.php
vendored
Normal file
122
libraries/joomla/cache/controller/output.php
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Cache
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Joomla Cache output type object
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Cache
|
||||
* @since 11.1
|
||||
*/
|
||||
class JCacheControllerOutput extends JCacheController
|
||||
{
|
||||
/**
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $_group;
|
||||
|
||||
/**
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $_locktest = null;
|
||||
|
||||
/**
|
||||
* Start the cache
|
||||
*
|
||||
* @param string $id The cache data id
|
||||
* @param string $group The cache data group
|
||||
*
|
||||
* @return boolean True if the cache is hit (false else)
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function start($id, $group = null)
|
||||
{
|
||||
// If we have data in cache use that.
|
||||
$data = $this->cache->get($id, $group);
|
||||
|
||||
$this->_locktest = new stdClass;
|
||||
$this->_locktest->locked = null;
|
||||
$this->_locktest->locklooped = null;
|
||||
|
||||
if ($data === false)
|
||||
{
|
||||
$this->_locktest = $this->cache->lock($id, $group);
|
||||
if ($this->_locktest->locked == true && $this->_locktest->locklooped == true)
|
||||
{
|
||||
$data = $this->cache->get($id, $group);
|
||||
}
|
||||
}
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
$data = unserialize(trim($data));
|
||||
echo $data;
|
||||
if ($this->_locktest->locked == true)
|
||||
{
|
||||
$this->cache->unlock($id, $group);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nothing in cache... let's start the output buffer and start collecting data for next time.
|
||||
if ($this->_locktest->locked == false)
|
||||
{
|
||||
$this->_locktest = $this->cache->lock($id, $group);
|
||||
}
|
||||
ob_start();
|
||||
ob_implicit_flush(false);
|
||||
|
||||
// Set id and group placeholders
|
||||
$this->_id = $id;
|
||||
$this->_group = $group;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the cache buffer and store the cached data
|
||||
*
|
||||
* @return boolean True if cache stored
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function end()
|
||||
{
|
||||
// Get data from output buffer and echo it
|
||||
$data = ob_get_contents();
|
||||
ob_end_clean();
|
||||
echo $data;
|
||||
|
||||
// Get id and group and reset them placeholders
|
||||
$id = $this->_id;
|
||||
$group = $this->_group;
|
||||
$this->_id = null;
|
||||
$this->_group = null;
|
||||
|
||||
// Get the storage handler and store the cached data
|
||||
$ret = $this->cache->store(serialize($data), $id, $group);
|
||||
|
||||
if ($this->_locktest->locked == true)
|
||||
{
|
||||
$this->cache->unlock($id, $group);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
211
libraries/joomla/cache/controller/page.php
vendored
Normal file
211
libraries/joomla/cache/controller/page.php
vendored
Normal file
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Cache
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Joomla! Cache page type object
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Cache
|
||||
* @since 11.1
|
||||
*/
|
||||
class JCacheControllerPage extends JCacheController
|
||||
{
|
||||
/**
|
||||
* @var integer ID property for the cache page object.
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $_id;
|
||||
|
||||
/**
|
||||
* @var string Cache group
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $_group;
|
||||
|
||||
/**
|
||||
* @var object Cache lock test
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $_locktest = null;
|
||||
|
||||
/**
|
||||
* Get the cached page data
|
||||
*
|
||||
* @param string $id The cache data id
|
||||
* @param string $group The cache data group
|
||||
*
|
||||
* @return boolean True if the cache is hit (false else)
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function get($id = false, $group = 'page')
|
||||
{
|
||||
// If an id is not given, generate it from the request
|
||||
if ($id == false)
|
||||
{
|
||||
$id = $this->_makeId();
|
||||
}
|
||||
|
||||
// If the etag matches the page id ... set a no change header and exit : utilize browser cache
|
||||
if (!headers_sent() && isset($_SERVER['HTTP_IF_NONE_MATCH']))
|
||||
{
|
||||
$etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
|
||||
if ($etag == $id)
|
||||
{
|
||||
$browserCache = isset($this->options['browsercache']) ? $this->options['browsercache'] : false;
|
||||
if ($browserCache)
|
||||
{
|
||||
$this->_noChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We got a cache hit... set the etag header and echo the page data
|
||||
$data = $this->cache->get($id, $group);
|
||||
|
||||
$this->_locktest = new stdClass;
|
||||
$this->_locktest->locked = null;
|
||||
$this->_locktest->locklooped = null;
|
||||
|
||||
if ($data === false)
|
||||
{
|
||||
$this->_locktest = $this->cache->lock($id, $group);
|
||||
if ($this->_locktest->locked == true && $this->_locktest->locklooped == true)
|
||||
{
|
||||
$data = $this->cache->get($id, $group);
|
||||
}
|
||||
}
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
$data = unserialize(trim($data));
|
||||
|
||||
$data = JCache::getWorkarounds($data);
|
||||
|
||||
$this->_setEtag($id);
|
||||
if ($this->_locktest->locked == true)
|
||||
{
|
||||
$this->cache->unlock($id, $group);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Set id and group placeholders
|
||||
$this->_id = $id;
|
||||
$this->_group = $group;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the cache buffer and store the cached data
|
||||
*
|
||||
* @param mixed $data The data to store
|
||||
* @param string $id The cache data id
|
||||
* @param string $group The cache data group
|
||||
* @param boolean $wrkarounds True to use wrkarounds
|
||||
*
|
||||
* @return boolean True if cache stored
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function store($data, $id, $group = null, $wrkarounds = true)
|
||||
{
|
||||
// Get page data from JResponse
|
||||
if (empty($data))
|
||||
{
|
||||
$data = JResponse::getBody();
|
||||
}
|
||||
|
||||
// Get id and group and reset the placeholders
|
||||
if (empty($id))
|
||||
{
|
||||
$id = $this->_id;
|
||||
}
|
||||
if (empty($group))
|
||||
{
|
||||
$group = $this->_group;
|
||||
}
|
||||
|
||||
// Only attempt to store if page data exists
|
||||
if ($data)
|
||||
{
|
||||
if ($wrkarounds) {
|
||||
$data = JCache::setWorkarounds($data, array(
|
||||
'nopathway' => 1,
|
||||
'nohead' => 1,
|
||||
'nomodules' => 1,
|
||||
'headers' => true
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->_locktest->locked == false)
|
||||
{
|
||||
$this->_locktest = $this->cache->lock($id, $group);
|
||||
}
|
||||
|
||||
$sucess = $this->cache->store(serialize($data), $id, $group);
|
||||
|
||||
if ($this->_locktest->locked == true)
|
||||
{
|
||||
$this->cache->unlock($id, $group);
|
||||
}
|
||||
|
||||
return $sucess;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a page cache id
|
||||
*
|
||||
* @return string MD5 Hash : page cache id
|
||||
*
|
||||
* @since 11.1
|
||||
* @todo Discuss whether this should be coupled to a data hash or a request
|
||||
* hash ... perhaps hashed with a serialized request
|
||||
*/
|
||||
protected function _makeId()
|
||||
{
|
||||
return JCache::makeId();
|
||||
}
|
||||
|
||||
/**
|
||||
* There is no change in page data so send an
|
||||
* unmodified header and die gracefully
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
protected function _noChange()
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
|
||||
// Send not modified header and exit gracefully
|
||||
header('HTTP/1.x 304 Not Modified', true);
|
||||
$app->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ETag header in the response
|
||||
*
|
||||
* @param string $etag The entity tag (etag) to set
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
protected function _setEtag($etag)
|
||||
{
|
||||
JResponse::setHeader('ETag', $etag, true);
|
||||
}
|
||||
}
|
135
libraries/joomla/cache/controller/view.php
vendored
Normal file
135
libraries/joomla/cache/controller/view.php
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Cache
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Joomla! Cache view type object
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Cache
|
||||
* @since 11.1
|
||||
*/
|
||||
class JCacheControllerView extends JCacheController
|
||||
{
|
||||
/**
|
||||
* Get the cached view data
|
||||
*
|
||||
* @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 $id The cache data id
|
||||
* @param boolean $wrkarounds True to enable workarounds.
|
||||
*
|
||||
* @return boolean True if the cache is hit (false else)
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function get( $view, $method = 'display' , $id = false, $wrkarounds = true )
|
||||
{
|
||||
// If an id is not given generate it from the request
|
||||
if ($id == false)
|
||||
{
|
||||
$id = $this->_makeId($view, $method);
|
||||
}
|
||||
|
||||
$data = $this->cache->get($id);
|
||||
|
||||
$locktest = new stdClass;
|
||||
$locktest->locked = null;
|
||||
$locktest->locklooped = null;
|
||||
|
||||
if ($data === false)
|
||||
{
|
||||
$locktest = $this->cache->lock($id, null);
|
||||
|
||||
// If the loop is completed and returned true it means the lock has been set.
|
||||
// If looped is true try to get the cached data again; it could exist now.
|
||||
if ($locktest->locked == true && $locktest->locklooped == true)
|
||||
{
|
||||
$data = $this->cache->get($id);
|
||||
}
|
||||
|
||||
// False means that locking is either turned off or maxtime has been exceeded.
|
||||
// Execute the view.
|
||||
}
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
$data = unserialize(trim($data));
|
||||
|
||||
if ($wrkarounds === true)
|
||||
{
|
||||
echo JCache::getWorkarounds($data);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No workarounds, so all data is stored in one piece
|
||||
echo (isset($data)) ? $data : null;
|
||||
}
|
||||
|
||||
if ($locktest->locked == true)
|
||||
{
|
||||
$this->cache->unlock($id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* No hit so we have to execute the view
|
||||
*/
|
||||
if (method_exists($view, $method))
|
||||
{
|
||||
// If previous lock failed try again
|
||||
if ($locktest->locked == false)
|
||||
{
|
||||
$locktest = $this->cache->lock($id);
|
||||
}
|
||||
|
||||
// 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 = $wrkarounds == true ? JCache::setWorkarounds($data) : $data;
|
||||
|
||||
// Store the cache data
|
||||
$this->cache->store(serialize($cached), $id);
|
||||
|
||||
if ($locktest->locked == true)
|
||||
{
|
||||
$this->cache->unlock($id);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a view cache id.
|
||||
*
|
||||
* @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 11.1
|
||||
*/
|
||||
protected function _makeId(&$view, $method)
|
||||
{
|
||||
return md5(serialize(array(JCache::makeId(), get_class($view), $method)));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user