CoreFiles by mySites.guru
File.php118 lines, 2,905 bytes, from Joomla_1.5.0-Stable-Full_Package.zip
Raw History Compare with 1.0.15
md5
8861618629bc49823ef1f966f110c968
sha1
08f9a818711b974d55809c274cd614d9a21270c2
sha256
14f5854fab9b91614c1f51ae486cca0f95019c94fb4e3c5e93e9729203733c83
<?PHP
/**
 * patTemplate Template cache that stores data on filesystem
 *
 * $Id: File.php 8287 2007-08-01 08:38:59Z eddieajau $
 *
 * @package		patTemplate
 * @subpackage	Caches
 * @author		Stephan Schmidt <[email protected]>
 */

// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();

/**
 * patTemplate Template cache that stores data on filesystem
 *
 * $Id: File.php 8287 2007-08-01 08:38:59Z eddieajau $
 *
 * Possible parameters for the cache are:
 * - cacheFolder : set the folder from which to load the cache
 * - lifetime : seconds for which the cache is valid, if set to auto, it will check
 *   whether the cache is older than the original file (if the reader supports this)
 * - prefix for the filenames
 *
 * @package		patTemplate
 * @subpackage	Caches
 * @author		Stephan Schmidt <[email protected]>
 */
class patTemplate_TemplateCache_File extends patTemplate_TemplateCache
{
	/**
	* parameters of the cache
	*
	* @access	private
	* @var		array
	*/
	var $_params = array(
						 'cacheFolder' => './cache',
						 'lifetime'	   => 'auto',
						 'prefix'	   => '',
						 'filemode'	=> null
						);


	/**
	* load template from cache
	*
	* @access	public
	* @param	string			cache key
	* @param	integer			modification time of original template
	* @return	array|boolean	either an array containing the templates or false cache could not be loaded
	*/
	function load($key, $modTime = -1)
	{
		$filename = $this->_getCachefileName( $key );
		if (!file_exists($filename) || !is_readable($filename)) {
			return false;
		}

		$generatedOn = filemtime( $filename );
		$ttl		 = $this->getParam('lifetime');
		if ($ttl == 'auto') {
			if ($modTime < 1) {
				return false;
			}
			if ($modTime > $generatedOn) {
				return false;
			}
			return unserialize(file_get_contents($filename));
		} elseif(is_int( $ttl)) {
			if ($generatedOn + $ttl < time()) {
				return false;
			}
			return unserialize( file_get_contents( $filename ) );
		}

		return false;
	}

	/**
	* write template to cache
	*
	* @access	public
	* @param	string		cache key
	* @param	array		templates to store
	* @return	boolean		true on success
	*/
	function write( $key, $templates )
	{
		$cacheFile = $this->_getCachefileName($key);
		$fp = @fopen($cacheFile, 'w');
		if (!$fp) {
			return false;
		}
		flock( $fp, LOCK_EX );
		fputs( $fp, serialize($templates));
		flock( $fp, LOCK_UN );
		$filemode = $this->getParam('filemode');
		if ($filemode !== null) {
			chmod($cacheFile, $filemode);
		}
		return true;
	}

	/**
	* get the cache filename
	*
	* @access	private
	* @param	string		cache key
	* @return	string		cache file name
	*/
	function _getCachefileName( $key )
	{
		return $this->getParam( 'cacheFolder' ) . '/' . $this->getParam( 'prefix' ).$key . '.cache';
	}
}
?>

The same content is in 4 releases, Joomla 1.5.0 to 1.5.3. See them all, or every version of this file.