Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
erAck committed Sep 21, 2017
2 parents 20f1ee4 + 440b189 commit e2a35c3
Show file tree
Hide file tree
Showing 1,136 changed files with 44,686 additions and 17,640 deletions.
5 changes: 2 additions & 3 deletions README.markdown
@@ -1,4 +1,3 @@
# Serendipity - a PHP Weblog/Blog software

[Serendipity](http://s9y.org) is a PHP-powered weblog application which gives the user an easy way to maintain an online diary, weblog or even a complete homepage. While the default package is designed for the casual blogger, Serendipity offers a flexible, expandable and easy-to-use framework with the power for professional applications.
# Serendipity - A reliable, secure & extensible PHP blog

[Serendipity](https://s9y.org) is a PHP-powered weblog engine which gives the user an easy way to maintain a blog. While the default package is designed for the casual blogger, Serendipity offers an expandable framework with the power for professional applications.
87 changes: 69 additions & 18 deletions bundled-libs/Cache/Lite.php
Expand Up @@ -19,8 +19,8 @@
*
* @package Cache_Lite
* @category Caching
* @version $Id: Lite.php,v 1.54 2009/07/07 05:34:37 tacker Exp $
* @author Fabien MARTY <fab@php.net>
* @author Markus Tacker <tacker@php.net>
*/

define('CACHE_LITE_ERROR_RETURN', 1);
Expand Down Expand Up @@ -247,6 +247,12 @@ class Cache_Lite
* @var boolean
*/
var $_errorHandlingAPIBreak = false;

var $_hashedDirectoryGroup = NULL;

var $_cacheFileMode = NULL;

var $_cacheFileGroup = NULL;

// --- Public methods ---

Expand All @@ -272,16 +278,30 @@ class Cache_Lite
* 'hashedDirectoryLevel' => level of the hashed directory system (int),
* 'hashedDirectoryUmask' => umask for hashed directory structure (int),
* 'errorHandlingAPIBreak' => API break for better error handling ? (boolean)
* 'hashedDirectoryGroup' => group of hashed directory structure (int | string) (see function chgrp)
* 'cacheFileMode' => filesystem mode of newly created cache files (int)
* 'cacheFileGroup' => group of newly created cache files (int | string) (see function chgrp)
* );
*
* If sys_get_temp_dir() is available and the
* 'cacheDir' option is not provided in the
* constructor options array its output is used
* to determine the suitable temporary directory.
*
* @see http://de.php.net/sys_get_temp_dir
* @see http://pear.php.net/bugs/bug.php?id=18328
*
* @param array $options options
* @access public
*/
function Cache_Lite($options = array(NULL))
function __construct($options = array(NULL))
{
foreach($options as $key => $value) {
$this->setOption($key, $value);
}
if (!isset($options['cacheDir']) && function_exists('sys_get_temp_dir')) {
$this->setOption('cacheDir', sys_get_temp_dir() . DIRECTORY_SEPARATOR);
}
}

/**
Expand All @@ -295,7 +315,7 @@ function Cache_Lite($options = array(NULL))
*/
function setOption($name, $value)
{
$availableOptions = array('errorHandlingAPIBreak', 'hashedDirectoryUmask', 'hashedDirectoryLevel', 'automaticCleaningFactor', 'automaticSerialization', 'fileNameProtection', 'memoryCaching', 'onlyMemoryCaching', 'memoryCachingLimit', 'cacheDir', 'caching', 'lifeTime', 'fileLocking', 'writeControl', 'readControl', 'readControlType', 'pearErrorMode');
$availableOptions = array('errorHandlingAPIBreak', 'hashedDirectoryUmask', 'hashedDirectoryLevel', 'automaticCleaningFactor', 'automaticSerialization', 'fileNameProtection', 'memoryCaching', 'onlyMemoryCaching', 'memoryCachingLimit', 'cacheDir', 'caching', 'lifeTime', 'fileLocking', 'writeControl', 'readControl', 'readControlType', 'pearErrorMode', 'hashedDirectoryGroup', 'cacheFileMode', 'cacheFileGroup');
if (in_array($name, $availableOptions)) {
$property = '_'.$name;
$this->$property = $value;
Expand Down Expand Up @@ -329,7 +349,7 @@ function get($id, $group = 'default', $doNotTestCacheValidity = false)
}
if ($this->_onlyMemoryCaching) {
return false;
}
}
}
if (($doNotTestCacheValidity) || (is_null($this->_refreshTime))) {
if (file_exists($this->_file)) {
Expand Down Expand Up @@ -376,8 +396,8 @@ function save($data, $id = NULL, $group = 'default')
}
}
if ($this->_automaticCleaningFactor>0 && ($this->_automaticCleaningFactor==1 || mt_rand(1, $this->_automaticCleaningFactor)==1)) {
$this->clean(false, 'old');
}
$this->clean(false, 'old');
}
if ($this->_writeControl) {
$res = $this->_writeAndControl($data);
if (is_bool($res)) {
Expand All @@ -387,7 +407,7 @@ function save($data, $id = NULL, $group = 'default')
// if $res if false, we need to invalidate the cache
@touch($this->_file, time() - 2*abs($this->_lifeTime));
return false;
}
}
} else {
$res = $this->_write($data);
}
Expand Down Expand Up @@ -534,7 +554,7 @@ function lastModified()
*/
function raiseError($msg, $code)
{
include_once dirname(__FILE__) . '/../PEAR.php';
include_once('PEAR.php');
return PEAR::raiseError($msg, $code, $this->_pearErrorMode);
}

Expand Down Expand Up @@ -599,7 +619,7 @@ function _cleanDir($dir, $group = false, $mode = 'ingroup')
$motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
}
if ($this->_memoryCaching) {
foreach($this->_memoryCachingArray as $key => $v) {
foreach($this->_memoryCachingArray as $key => $v) {
if (strpos($key, $motif) !== false) {
unset($this->_memoryCachingArray[$key]);
$this->_memoryCachingCounter = $this->_memoryCachingCounter - 1;
Expand All @@ -613,7 +633,7 @@ function _cleanDir($dir, $group = false, $mode = 'ingroup')
return $this->raiseError('Cache_Lite : Unable to open cache directory !', -4);
}
$result = true;
while ($file = readdir($dh)) {
while (($file = readdir($dh)) !== false) {
if (($file != '.') && ($file != '..')) {
if (substr($file, 0, 6)=='cache_') {
$file2 = $dir . $file;
Expand Down Expand Up @@ -654,7 +674,19 @@ function _cleanDir($dir, $group = false, $mode = 'ingroup')
}
return $result;
}


/**
* Touch the cache file while are recreating it to avoid
* launch this task more then once when necessary
* When the cache recreated and Added in Cache Memory
* @return void
* @access private
*/
function _touchCacheFile(){
if (file_exists($this->_file)) {
@touch($this->_file);
}
}
/**
* Add some date in the memory caching array
*
Expand All @@ -663,6 +695,7 @@ function _cleanDir($dir, $group = false, $mode = 'ingroup')
*/
function _memoryCacheAdd($data)
{
$this->_touchCacheFile();
$this->_memoryCachingArray[$this->_file] = $data;
if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) {
list($key, ) = each($this->_memoryCachingArray);
Expand Down Expand Up @@ -707,8 +740,8 @@ function _setFileName($id, $group)
function _read()
{
$fp = @fopen($this->_file, "rb");
if ($this->_fileLocking) @flock($fp, LOCK_SH);
if ($fp) {
if ($this->_fileLocking) @flock($fp, LOCK_SH);
clearstatcache();
$length = @filesize($this->_file);
$mqr = get_magic_quotes_runtime();
Expand All @@ -718,9 +751,13 @@ function _read()
if ($this->_readControl) {
$hashControl = @fread($fp, 32);
$length = $length - 32;
}
}

if ($length) {
$data = @fread($fp, $length);
$data = '';
// See https://bugs.php.net/bug.php?id=30936
// The 8192 magic number is the chunk size used internally by PHP.
while(!feof($fp)) $data .= fread($fp, 8192);
} else {
$data = '';
}
Expand Down Expand Up @@ -760,13 +797,29 @@ function _write($data)
for ($i=0 ; $i<$this->_hashedDirectoryLevel ; $i++) {
$root = $root . 'cache_' . substr($hash, 0, $i + 1) . '/';
if (!(@is_dir($root))) {
@mkdir($root, $this->_hashedDirectoryUmask);
if (@mkdir($root))
{
@chmod($root, $this->_hashedDirectoryUmask);
if (! is_null($this->_hashedDirectoryGroup))
@chgrp($root, $this->_hashedDirectoryGroup);
}
}
}
}
// if both _cacheFileMode and _cacheFileGroup is null, then we don't need to call
// file_exists (see below: if ($is_newfile) ...)
$is_newfile = (! is_null($this->_cacheFileMode) || !is_null($this->_cacheFileGroup))
&& ! @file_exists($this->_file);
$fp = @fopen($this->_file, "wb");
if ($fp) {
if ($this->_fileLocking) @flock($fp, LOCK_EX);
if ($is_newfile)
{
if (! is_null($this->_cacheFileMode))
@chmod($this->_file, $this->_cacheFileMode);
if (! is_null($this->_cacheFileGroup))
@chgrp($this->_file, $this->_cacheFileGroup);
}
if ($this->_readControl) {
@fwrite($fp, $this->_hash($data, $this->_readControlType), 32);
}
Expand All @@ -781,7 +834,7 @@ function _write($data)
if ($this->_fileLocking) @flock($fp, LOCK_UN);
@fclose($fp);
return true;
}
}
return $this->raiseError('Cache_Lite : Unable to write cache file : '.$this->_file, -1);
}

Expand Down Expand Up @@ -831,5 +884,3 @@ function _hash($data, $controlType)
}

}

?>
90 changes: 90 additions & 0 deletions bundled-libs/Cache/Lite/File.php
@@ -0,0 +1,90 @@
<?php

/**
* This class extends Cache_Lite and offers a cache system driven by a master file
*
* With this class, cache validity is only dependent of a given file. Cache files
* are valid only if they are older than the master file. It's a perfect way for
* caching templates results (if the template file is newer than the cache, cache
* must be rebuild...) or for config classes...
* There are some examples in the 'docs/examples' file
* Technical choices are described in the 'docs/technical' file
*
* @package Cache_Lite
* @author Fabien MARTY <fab@php.net>
*/

require_once('Cache/Lite.php');

class Cache_Lite_File extends Cache_Lite
{

// --- Private properties ---

/**
* Complete path of the file used for controlling the cache lifetime
*
* @var string $_masterFile
*/
var $_masterFile = '';

/**
* Masterfile mtime
*
* @var int $_masterFile_mtime
*/
var $_masterFile_mtime = 0;

// --- Public methods ----

/**
* Constructor
*
* $options is an assoc. To have a look at availables options,
* see the constructor of the Cache_Lite class in 'Cache_Lite.php'
*
* Comparing to Cache_Lite constructor, there is another option :
* $options = array(
* (...) see Cache_Lite constructor
* 'masterFile' => complete path of the file used for controlling the cache lifetime(string)
* );
*
* @param array $options options
* @access public
*/
function __construct($options = array(NULL))
{
$options['lifetime'] = 0;
parent::__construct($options);
if (isset($options['masterFile'])) {
$this->_masterFile = $options['masterFile'];
} else {
return $this->raiseError('Cache_Lite_File : masterFile option must be set !');
}
if (!($this->_masterFile_mtime = @filemtime($this->_masterFile))) {
return $this->raiseError('Cache_Lite_File : Unable to read masterFile : '.$this->_masterFile, -3);
}
}

/**
* Test if a cache is available and (if yes) return it
*
* @param string $id cache id
* @param string $group name of the cache group
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
* @return string data of the cache (else : false)
* @access public
*/
function get($id, $group = 'default', $doNotTestCacheValidity = false)
{
if ($data = parent::get($id, $group, true)) {
if ($filemtime = $this->lastModified()) {
if ($filemtime > $this->_masterFile_mtime) {
return $data;
}
}
}
return false;
}

}
9 changes: 3 additions & 6 deletions bundled-libs/Cache/Lite/Function.php
Expand Up @@ -11,12 +11,11 @@
* Technical choices are described in the 'docs/technical' file
*
* @package Cache_Lite
* @version $Id: Function.php,v 1.11 2006/12/14 12:59:43 cweiske Exp $
* @author Sebastian BERGMANN <sb@sebastian-bergmann.de>
* @author Fabien MARTY <fab@php.net>
*/

require_once dirname(__FILE__) . '/../Lite.php';
require_once('Cache/Lite.php');

class Cache_Lite_Function extends Cache_Lite
{
Expand Down Expand Up @@ -82,7 +81,7 @@ class Cache_Lite_Function extends Cache_Lite
* @param array $options options
* @access public
*/
function Cache_Lite_Function($options = array(NULL))
function __construct($options = array(NULL))
{
$availableOptions = array('debugCacheLiteFunction', 'defaultGroup', 'dontCacheWhenTheOutputContainsNOCACHE', 'dontCacheWhenTheResultIsFalse', 'dontCacheWhenTheResultIsNull');
while (list($name, $value) = each($options)) {
Expand All @@ -92,7 +91,7 @@ function Cache_Lite_Function($options = array(NULL))
}
}
reset($options);
$this->Cache_Lite($options);
parent::__construct($options);
}

/**
Expand Down Expand Up @@ -207,5 +206,3 @@ function _makeId($arguments)
}

}

?>

0 comments on commit e2a35c3

Please sign in to comment.