PDF rausgenommen
This commit is contained in:
70
msd2/phpBB3/phpbb/cache/driver/apc.php
vendored
Normal file
70
msd2/phpBB3/phpbb/cache/driver/apc.php
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
/**
|
||||
* ACM for APC
|
||||
*/
|
||||
class apc extends \phpbb\cache\driver\memory
|
||||
{
|
||||
var $extension = 'apc';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function purge()
|
||||
{
|
||||
apc_clear_cache('user');
|
||||
|
||||
parent::purge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
{
|
||||
return apc_fetch($this->key_prefix . $var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
{
|
||||
return apc_store($this->key_prefix . $var, $data, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
{
|
||||
return apc_delete($this->key_prefix . $var);
|
||||
}
|
||||
}
|
74
msd2/phpBB3/phpbb/cache/driver/apcu.php
vendored
Normal file
74
msd2/phpBB3/phpbb/cache/driver/apcu.php
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
/**
|
||||
* ACM for APCU
|
||||
*/
|
||||
class apcu extends \phpbb\cache\driver\memory
|
||||
{
|
||||
var $extension = 'apcu';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function purge()
|
||||
{
|
||||
/*
|
||||
* Use an iterator to selectively delete our cache entries without disturbing
|
||||
* any other cache users (e.g. other phpBB boards hosted on this server)
|
||||
*/
|
||||
apcu_delete(new \APCUIterator('#^' . $this->key_prefix . '#'));
|
||||
|
||||
parent::purge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
{
|
||||
return apcu_fetch($this->key_prefix . $var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
{
|
||||
return apcu_store($this->key_prefix . $var, $data, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
{
|
||||
return apcu_delete($this->key_prefix . $var);
|
||||
}
|
||||
}
|
234
msd2/phpBB3/phpbb/cache/driver/base.php
vendored
Normal file
234
msd2/phpBB3/phpbb/cache/driver/base.php
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
abstract class base implements \phpbb\cache\driver\driver_interface
|
||||
{
|
||||
var $vars = array();
|
||||
var $is_modified = false;
|
||||
|
||||
var $sql_rowset = array();
|
||||
var $sql_row_pointer = array();
|
||||
var $cache_dir = '';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function purge()
|
||||
{
|
||||
// Purge all phpbb cache files
|
||||
try
|
||||
{
|
||||
$iterator = new \DirectoryIterator($this->cache_dir);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($iterator as $fileInfo)
|
||||
{
|
||||
if ($fileInfo->isDot())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$filename = $fileInfo->getFilename();
|
||||
if ($fileInfo->isDir())
|
||||
{
|
||||
$this->remove_dir($fileInfo->getPathname());
|
||||
}
|
||||
else if (strpos($filename, 'container_') === 0 ||
|
||||
strpos($filename, 'autoload_') === 0 ||
|
||||
strpos($filename, 'url_matcher') === 0 ||
|
||||
strpos($filename, 'url_generator') === 0 ||
|
||||
strpos($filename, 'sql_') === 0 ||
|
||||
strpos($filename, 'data_') === 0)
|
||||
{
|
||||
$this->remove_file($fileInfo->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
unset($this->vars);
|
||||
unset($this->sql_rowset);
|
||||
unset($this->sql_row_pointer);
|
||||
|
||||
if (function_exists('opcache_reset'))
|
||||
{
|
||||
@opcache_reset();
|
||||
}
|
||||
|
||||
$this->vars = array();
|
||||
$this->sql_rowset = array();
|
||||
$this->sql_row_pointer = array();
|
||||
|
||||
$this->is_modified = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function unload()
|
||||
{
|
||||
$this->save();
|
||||
unset($this->vars);
|
||||
unset($this->sql_rowset);
|
||||
unset($this->sql_row_pointer);
|
||||
|
||||
$this->vars = array();
|
||||
$this->sql_rowset = array();
|
||||
$this->sql_row_pointer = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_load($query)
|
||||
{
|
||||
// Remove extra spaces and tabs
|
||||
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
||||
$query_id = md5($query);
|
||||
|
||||
if (($result = $this->_read('sql_' . $query_id)) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->sql_rowset[$query_id] = $result;
|
||||
$this->sql_row_pointer[$query_id] = 0;
|
||||
|
||||
return $query_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_exists($query_id)
|
||||
{
|
||||
return isset($this->sql_rowset[$query_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_fetchrow($query_id)
|
||||
{
|
||||
if ($this->sql_row_pointer[$query_id] < count($this->sql_rowset[$query_id]))
|
||||
{
|
||||
return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_fetchfield($query_id, $field)
|
||||
{
|
||||
if ($this->sql_row_pointer[$query_id] < count($this->sql_rowset[$query_id]))
|
||||
{
|
||||
return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++][$field] : false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_rowseek($rownum, $query_id)
|
||||
{
|
||||
if ($rownum >= count($this->sql_rowset[$query_id]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->sql_row_pointer[$query_id] = $rownum;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_freeresult($query_id)
|
||||
{
|
||||
if (!isset($this->sql_rowset[$query_id]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
unset($this->sql_rowset[$query_id]);
|
||||
unset($this->sql_row_pointer[$query_id]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes/unlinks file
|
||||
*
|
||||
* @param string $filename Filename to remove
|
||||
* @param bool $check Check file permissions
|
||||
* @return bool True if the file was successfully removed, otherwise false
|
||||
*/
|
||||
function remove_file($filename, $check = false)
|
||||
{
|
||||
global $phpbb_filesystem;
|
||||
|
||||
if ($check && !$phpbb_filesystem->is_writable($this->cache_dir))
|
||||
{
|
||||
// E_USER_ERROR - not using language entry - intended.
|
||||
trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR);
|
||||
}
|
||||
|
||||
return @unlink($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove directory
|
||||
*
|
||||
* @param string $dir Directory to remove
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function remove_dir($dir)
|
||||
{
|
||||
try
|
||||
{
|
||||
$iterator = new \DirectoryIterator($dir);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($iterator as $fileInfo)
|
||||
{
|
||||
if ($fileInfo->isDot())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($fileInfo->isDir())
|
||||
{
|
||||
$this->remove_dir($fileInfo->getPathname());
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->remove_file($fileInfo->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
@rmdir($dir);
|
||||
}
|
||||
}
|
167
msd2/phpBB3/phpbb/cache/driver/driver_interface.php
vendored
Normal file
167
msd2/phpBB3/phpbb/cache/driver/driver_interface.php
vendored
Normal file
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
/**
|
||||
* An interface that all cache drivers must implement
|
||||
*/
|
||||
interface driver_interface
|
||||
{
|
||||
/**
|
||||
* Load global cache
|
||||
*
|
||||
* @return mixed False if an error was encountered, otherwise the data type of the cached data
|
||||
*/
|
||||
public function load();
|
||||
|
||||
/**
|
||||
* Unload cache object
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function unload();
|
||||
|
||||
/**
|
||||
* Save modified objects
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function save();
|
||||
|
||||
/**
|
||||
* Tidy cache
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function tidy();
|
||||
|
||||
/**
|
||||
* Get saved cache object
|
||||
*
|
||||
* @param string $var_name Cache key
|
||||
* @return mixed False if an error was encountered, otherwise the saved cached object
|
||||
*/
|
||||
public function get($var_name);
|
||||
|
||||
/**
|
||||
* Put data into cache
|
||||
*
|
||||
* @param string $var_name Cache key
|
||||
* @param mixed $var Cached data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return null
|
||||
*/
|
||||
public function put($var_name, $var, $ttl = 0);
|
||||
|
||||
/**
|
||||
* Purge cache data
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function purge();
|
||||
|
||||
/**
|
||||
* Destroy cache data
|
||||
*
|
||||
* @param string $var_name Cache key
|
||||
* @param string $table Table name
|
||||
* @return null
|
||||
*/
|
||||
public function destroy($var_name, $table = '');
|
||||
|
||||
/**
|
||||
* Check if a given cache entry exists
|
||||
*
|
||||
* @param string $var_name Cache key
|
||||
*
|
||||
* @return bool True if cache file exists and has not expired.
|
||||
* False otherwise.
|
||||
*/
|
||||
public function _exists($var_name);
|
||||
|
||||
/**
|
||||
* Load result of an SQL query from cache.
|
||||
*
|
||||
* @param string $query SQL query
|
||||
*
|
||||
* @return int|bool Query ID (integer) if cache contains a rowset
|
||||
* for the specified query.
|
||||
* False otherwise.
|
||||
*/
|
||||
public function sql_load($query);
|
||||
|
||||
/**
|
||||
* Save result of an SQL query in cache.
|
||||
*
|
||||
* In persistent cache stores, this function stores the query
|
||||
* result to persistent storage. In other words, there is no need
|
||||
* to call save() afterwards.
|
||||
*
|
||||
* @param \phpbb\db\driver\driver_interface $db Database connection
|
||||
* @param string $query SQL query, should be used for generating storage key
|
||||
* @param mixed $query_result The result from \dbal::sql_query, to be passed to
|
||||
* \dbal::sql_fetchrow to get all rows and store them
|
||||
* in cache.
|
||||
* @param int $ttl Time to live, after this timeout the query should
|
||||
* expire from the cache.
|
||||
* @return int|mixed If storing in cache succeeded, an integer $query_id
|
||||
* representing the query should be returned. Otherwise
|
||||
* the original $query_result should be returned.
|
||||
*/
|
||||
public function sql_save(\phpbb\db\driver\driver_interface $db, $query, $query_result, $ttl);
|
||||
|
||||
/**
|
||||
* Check if result for a given SQL query exists in cache.
|
||||
*
|
||||
* @param int $query_id
|
||||
* @return bool
|
||||
*/
|
||||
public function sql_exists($query_id);
|
||||
|
||||
/**
|
||||
* Fetch row from cache (database)
|
||||
*
|
||||
* @param int $query_id
|
||||
* @return array|bool The query result if found in the cache, otherwise
|
||||
* false.
|
||||
*/
|
||||
public function sql_fetchrow($query_id);
|
||||
|
||||
/**
|
||||
* Fetch a field from the current row of a cached database result (database)
|
||||
*
|
||||
* @param int $query_id
|
||||
* @param string $field The name of the column.
|
||||
* @return string|bool The field of the query result if found in the cache,
|
||||
* otherwise false.
|
||||
*/
|
||||
public function sql_fetchfield($query_id, $field);
|
||||
|
||||
/**
|
||||
* Seek a specific row in an a cached database result (database)
|
||||
*
|
||||
* @param int $rownum Row to seek to.
|
||||
* @param int $query_id
|
||||
* @return bool
|
||||
*/
|
||||
public function sql_rowseek($rownum, $query_id);
|
||||
|
||||
/**
|
||||
* Free memory used for a cached database result (database)
|
||||
*
|
||||
* @param int $query_id
|
||||
* @return bool
|
||||
*/
|
||||
public function sql_freeresult($query_id);
|
||||
}
|
153
msd2/phpBB3/phpbb/cache/driver/dummy.php
vendored
Normal file
153
msd2/phpBB3/phpbb/cache/driver/dummy.php
vendored
Normal file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
/**
|
||||
* ACM dummy Caching
|
||||
*/
|
||||
class dummy extends \phpbb\cache\driver\base
|
||||
{
|
||||
/**
|
||||
* Set cache path
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function load()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function unload()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function save()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function tidy()
|
||||
{
|
||||
global $config;
|
||||
|
||||
// This cache always has a tidy room.
|
||||
$config->set('cache_last_gc', time(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function get($var_name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function put($var_name, $var, $ttl = 0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function purge()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function destroy($var_name, $table = '')
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _exists($var_name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_load($query)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_save(\phpbb\db\driver\driver_interface $db, $query, $query_result, $ttl)
|
||||
{
|
||||
return $query_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_exists($query_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_fetchrow($query_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_fetchfield($query_id, $field)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_rowseek($rownum, $query_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_freeresult($query_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
107
msd2/phpBB3/phpbb/cache/driver/eaccelerator.php
vendored
Normal file
107
msd2/phpBB3/phpbb/cache/driver/eaccelerator.php
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
/**
|
||||
* ACM for eAccelerator
|
||||
* @todo Missing locks from destroy() talk with David
|
||||
*/
|
||||
class eaccelerator extends \phpbb\cache\driver\memory
|
||||
{
|
||||
var $extension = 'eaccelerator';
|
||||
var $function = 'eaccelerator_get';
|
||||
|
||||
var $serialize_header = '#phpbb-serialized#';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function purge()
|
||||
{
|
||||
foreach (eaccelerator_list_keys() as $var)
|
||||
{
|
||||
// @todo Check why the substr()
|
||||
// @todo Only unset vars matching $this->key_prefix
|
||||
eaccelerator_rm(substr($var['name'], 1));
|
||||
}
|
||||
|
||||
parent::purge();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function tidy()
|
||||
{
|
||||
global $config;
|
||||
|
||||
eaccelerator_gc();
|
||||
|
||||
$config->set('cache_last_gc', time(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
{
|
||||
$result = eaccelerator_get($this->key_prefix . $var);
|
||||
|
||||
if ($result === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Handle serialized objects
|
||||
if (is_string($result) && strpos($result, $this->serialize_header . 'O:') === 0)
|
||||
{
|
||||
$result = unserialize(substr($result, strlen($this->serialize_header)));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
{
|
||||
// Serialize objects and make them easy to detect
|
||||
$data = (is_object($data)) ? $this->serialize_header . serialize($data) : $data;
|
||||
|
||||
return eaccelerator_put($this->key_prefix . $var, $data, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
{
|
||||
return eaccelerator_rm($this->key_prefix . $var);
|
||||
}
|
||||
}
|
613
msd2/phpBB3/phpbb/cache/driver/file.php
vendored
Normal file
613
msd2/phpBB3/phpbb/cache/driver/file.php
vendored
Normal file
@ -0,0 +1,613 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
/**
|
||||
* ACM File Based Caching
|
||||
*/
|
||||
class file extends \phpbb\cache\driver\base
|
||||
{
|
||||
var $var_expires = array();
|
||||
|
||||
/**
|
||||
* @var \phpbb\filesystem\filesystem_interface
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* Set cache path
|
||||
*
|
||||
* @param string $cache_dir Define the path to the cache directory (default: $phpbb_root_path . 'cache/')
|
||||
*/
|
||||
function __construct($cache_dir = null)
|
||||
{
|
||||
global $phpbb_container;
|
||||
|
||||
$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir');
|
||||
$this->filesystem = new \phpbb\filesystem\filesystem();
|
||||
|
||||
if (!is_dir($this->cache_dir))
|
||||
{
|
||||
@mkdir($this->cache_dir, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function load()
|
||||
{
|
||||
return $this->_read('data_global');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function unload()
|
||||
{
|
||||
parent::unload();
|
||||
unset($this->var_expires);
|
||||
$this->var_expires = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function save()
|
||||
{
|
||||
if (!$this->is_modified)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
global $phpEx;
|
||||
|
||||
if (!$this->_write('data_global'))
|
||||
{
|
||||
// Now, this occurred how often? ... phew, just tell the user then...
|
||||
if (!$this->filesystem->is_writable($this->cache_dir))
|
||||
{
|
||||
// We need to use die() here, because else we may encounter an infinite loop (the message handler calls $cache->unload())
|
||||
die('Fatal: ' . $this->cache_dir . ' is NOT writable.');
|
||||
exit;
|
||||
}
|
||||
|
||||
die('Fatal: Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->is_modified = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function tidy()
|
||||
{
|
||||
global $config, $phpEx;
|
||||
|
||||
$dir = @opendir($this->cache_dir);
|
||||
|
||||
if (!$dir)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$time = time();
|
||||
|
||||
while (($entry = readdir($dir)) !== false)
|
||||
{
|
||||
if (!preg_match('/^(sql_|data_(?!global))/', $entry))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!($handle = @fopen($this->cache_dir . $entry, 'rb')))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip the PHP header
|
||||
fgets($handle);
|
||||
|
||||
// Skip expiration
|
||||
$expires = (int) fgets($handle);
|
||||
|
||||
fclose($handle);
|
||||
|
||||
if ($time >= $expires)
|
||||
{
|
||||
$this->remove_file($this->cache_dir . $entry);
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
|
||||
if (file_exists($this->cache_dir . 'data_global.' . $phpEx))
|
||||
{
|
||||
if (!count($this->vars))
|
||||
{
|
||||
$this->load();
|
||||
}
|
||||
|
||||
foreach ($this->var_expires as $var_name => $expires)
|
||||
{
|
||||
if ($time >= $expires)
|
||||
{
|
||||
$this->destroy($var_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$config->set('cache_last_gc', time(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function get($var_name)
|
||||
{
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
if (!$this->_exists($var_name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_read('data' . $var_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function put($var_name, $var, $ttl = 31536000)
|
||||
{
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
$this->_write('data' . $var_name, $var, time() + $ttl);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->vars[$var_name] = $var;
|
||||
$this->var_expires[$var_name] = time() + $ttl;
|
||||
$this->is_modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function purge()
|
||||
{
|
||||
parent::purge();
|
||||
$this->var_expires = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function destroy($var_name, $table = '')
|
||||
{
|
||||
global $phpEx;
|
||||
|
||||
if ($var_name == 'sql' && !empty($table))
|
||||
{
|
||||
if (!is_array($table))
|
||||
{
|
||||
$table = array($table);
|
||||
}
|
||||
|
||||
$dir = @opendir($this->cache_dir);
|
||||
|
||||
if (!$dir)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (($entry = readdir($dir)) !== false)
|
||||
{
|
||||
if (strpos($entry, 'sql_') !== 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!($handle = @fopen($this->cache_dir . $entry, 'rb')))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip the PHP header
|
||||
fgets($handle);
|
||||
|
||||
// Skip expiration
|
||||
fgets($handle);
|
||||
|
||||
// Grab the query, remove the LF
|
||||
$query = substr(fgets($handle), 0, -1);
|
||||
|
||||
fclose($handle);
|
||||
|
||||
foreach ($table as $check_table)
|
||||
{
|
||||
// Better catch partial table names than no table names. ;)
|
||||
if (strpos($query, $check_table) !== false)
|
||||
{
|
||||
$this->remove_file($this->cache_dir . $entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->_exists($var_name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
$this->remove_file($this->cache_dir . 'data' . $var_name . ".$phpEx", true);
|
||||
}
|
||||
else if (isset($this->vars[$var_name]))
|
||||
{
|
||||
$this->is_modified = true;
|
||||
unset($this->vars[$var_name]);
|
||||
unset($this->var_expires[$var_name]);
|
||||
|
||||
// We save here to let the following cache hits succeed
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _exists($var_name)
|
||||
{
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
global $phpEx;
|
||||
$var_name = $this->clean_varname($var_name);
|
||||
return file_exists($this->cache_dir . 'data' . $var_name . ".$phpEx");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!count($this->vars))
|
||||
{
|
||||
$this->load();
|
||||
}
|
||||
|
||||
if (!isset($this->var_expires[$var_name]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (time() > $this->var_expires[$var_name]) ? false : isset($this->vars[$var_name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_save(\phpbb\db\driver\driver_interface $db, $query, $query_result, $ttl)
|
||||
{
|
||||
// Remove extra spaces and tabs
|
||||
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
||||
|
||||
$query_id = md5($query);
|
||||
$this->sql_rowset[$query_id] = array();
|
||||
$this->sql_row_pointer[$query_id] = 0;
|
||||
|
||||
while ($row = $db->sql_fetchrow($query_result))
|
||||
{
|
||||
$this->sql_rowset[$query_id][] = $row;
|
||||
}
|
||||
$db->sql_freeresult($query_result);
|
||||
|
||||
if ($this->_write('sql_' . $query_id, $this->sql_rowset[$query_id], $ttl + time(), $query))
|
||||
{
|
||||
return $query_id;
|
||||
}
|
||||
|
||||
return $query_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read cached data from a specified file
|
||||
*
|
||||
* @access private
|
||||
* @param string $filename Filename to write
|
||||
* @return mixed False if an error was encountered, otherwise the data type of the cached data
|
||||
*/
|
||||
function _read($filename)
|
||||
{
|
||||
global $phpEx;
|
||||
|
||||
$filename = $this->clean_varname($filename);
|
||||
$file = "{$this->cache_dir}$filename.$phpEx";
|
||||
|
||||
$type = substr($filename, 0, strpos($filename, '_'));
|
||||
|
||||
if (!file_exists($file))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!($handle = @fopen($file, 'rb')))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip the PHP header
|
||||
fgets($handle);
|
||||
|
||||
if ($filename == 'data_global')
|
||||
{
|
||||
$this->vars = $this->var_expires = array();
|
||||
|
||||
$time = time();
|
||||
|
||||
while (($expires = (int) fgets($handle)) && !feof($handle))
|
||||
{
|
||||
// Number of bytes of data
|
||||
$bytes = substr(fgets($handle), 0, -1);
|
||||
|
||||
if (!is_numeric($bytes) || ($bytes = (int) $bytes) === 0)
|
||||
{
|
||||
// We cannot process the file without a valid number of bytes
|
||||
// so we discard it
|
||||
fclose($handle);
|
||||
|
||||
$this->vars = $this->var_expires = array();
|
||||
$this->is_modified = false;
|
||||
|
||||
$this->remove_file($file);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($time >= $expires)
|
||||
{
|
||||
fseek($handle, $bytes, SEEK_CUR);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$var_name = substr(fgets($handle), 0, -1);
|
||||
|
||||
// Read the length of bytes that consists of data.
|
||||
$data = fread($handle, $bytes - strlen($var_name));
|
||||
$data = @unserialize($data);
|
||||
|
||||
// Don't use the data if it was invalid
|
||||
if ($data !== false)
|
||||
{
|
||||
$this->vars[$var_name] = $data;
|
||||
$this->var_expires[$var_name] = $expires;
|
||||
}
|
||||
|
||||
// Absorb the LF
|
||||
fgets($handle);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$this->is_modified = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = false;
|
||||
$line = 0;
|
||||
|
||||
while (($buffer = fgets($handle)) && !feof($handle))
|
||||
{
|
||||
$buffer = substr($buffer, 0, -1); // Remove the LF
|
||||
|
||||
// $buffer is only used to read integers
|
||||
// if it is non numeric we have an invalid
|
||||
// cache file, which we will now remove.
|
||||
if (!is_numeric($buffer))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if ($line == 0)
|
||||
{
|
||||
$expires = (int) $buffer;
|
||||
|
||||
if (time() >= $expires)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if ($type == 'sql')
|
||||
{
|
||||
// Skip the query
|
||||
fgets($handle);
|
||||
}
|
||||
}
|
||||
else if ($line == 1)
|
||||
{
|
||||
$bytes = (int) $buffer;
|
||||
|
||||
// Never should have 0 bytes
|
||||
if (!$bytes)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Grab the serialized data
|
||||
$data = fread($handle, $bytes);
|
||||
|
||||
// Read 1 byte, to trigger EOF
|
||||
fread($handle, 1);
|
||||
|
||||
if (!feof($handle))
|
||||
{
|
||||
// Somebody tampered with our data
|
||||
$data = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Something went wrong
|
||||
break;
|
||||
}
|
||||
$line++;
|
||||
}
|
||||
fclose($handle);
|
||||
|
||||
// unserialize if we got some data
|
||||
$data = ($data !== false) ? @unserialize($data) : $data;
|
||||
|
||||
if ($data === false)
|
||||
{
|
||||
$this->remove_file($file);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write cache data to a specified file
|
||||
*
|
||||
* 'data_global' is a special case and the generated format is different for this file:
|
||||
* <code>
|
||||
* <?php exit; ?>
|
||||
* (expiration)
|
||||
* (length of var and serialised data)
|
||||
* (var)
|
||||
* (serialised data)
|
||||
* ... (repeat)
|
||||
* </code>
|
||||
*
|
||||
* The other files have a similar format:
|
||||
* <code>
|
||||
* <?php exit; ?>
|
||||
* (expiration)
|
||||
* (query) [SQL files only]
|
||||
* (length of serialised data)
|
||||
* (serialised data)
|
||||
* </code>
|
||||
*
|
||||
* @access private
|
||||
* @param string $filename Filename to write
|
||||
* @param mixed $data Data to store
|
||||
* @param int $expires Timestamp when the data expires
|
||||
* @param string $query Query when caching SQL queries
|
||||
* @return bool True if the file was successfully created, otherwise false
|
||||
*/
|
||||
function _write($filename, $data = null, $expires = 0, $query = '')
|
||||
{
|
||||
global $phpEx;
|
||||
|
||||
$filename = $this->clean_varname($filename);
|
||||
$file = "{$this->cache_dir}$filename.$phpEx";
|
||||
|
||||
$lock = new \phpbb\lock\flock($file);
|
||||
$lock->acquire();
|
||||
|
||||
if ($handle = @fopen($file, 'wb'))
|
||||
{
|
||||
// File header
|
||||
fwrite($handle, '<' . '?php exit; ?' . '>');
|
||||
|
||||
if ($filename == 'data_global')
|
||||
{
|
||||
// Global data is a different format
|
||||
foreach ($this->vars as $var => $data)
|
||||
{
|
||||
if (strpos($var, "\r") !== false || strpos($var, "\n") !== false)
|
||||
{
|
||||
// CR/LF would cause fgets() to read the cache file incorrectly
|
||||
// do not cache test entries, they probably won't be read back
|
||||
// the cache keys should really be alphanumeric with a few symbols.
|
||||
continue;
|
||||
}
|
||||
$data = serialize($data);
|
||||
|
||||
// Write out the expiration time
|
||||
fwrite($handle, "\n" . $this->var_expires[$var] . "\n");
|
||||
|
||||
// Length of the remaining data for this var (ignoring two LF's)
|
||||
fwrite($handle, strlen($data . $var) . "\n");
|
||||
fwrite($handle, $var . "\n");
|
||||
fwrite($handle, $data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite($handle, "\n" . $expires . "\n");
|
||||
|
||||
if (strpos($filename, 'sql_') === 0)
|
||||
{
|
||||
fwrite($handle, $query . "\n");
|
||||
}
|
||||
$data = serialize($data);
|
||||
|
||||
fwrite($handle, strlen($data) . "\n");
|
||||
fwrite($handle, $data);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
if (function_exists('opcache_invalidate'))
|
||||
{
|
||||
@opcache_invalidate($file);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->filesystem->phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);
|
||||
}
|
||||
catch (\phpbb\filesystem\exception\filesystem_exception $e)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
$return_value = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$return_value = false;
|
||||
}
|
||||
|
||||
$lock->release();
|
||||
|
||||
return $return_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace slashes in the file name
|
||||
*
|
||||
* @param string $varname name of a cache variable
|
||||
* @return string $varname name that is safe to use as a filename
|
||||
*/
|
||||
protected function clean_varname($varname)
|
||||
{
|
||||
return str_replace(array('/', '\\'), '-', $varname);
|
||||
}
|
||||
}
|
122
msd2/phpBB3/phpbb/cache/driver/memcache.php
vendored
Normal file
122
msd2/phpBB3/phpbb/cache/driver/memcache.php
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
if (!defined('PHPBB_ACM_MEMCACHE_PORT'))
|
||||
{
|
||||
define('PHPBB_ACM_MEMCACHE_PORT', 11211);
|
||||
}
|
||||
|
||||
if (!defined('PHPBB_ACM_MEMCACHE_COMPRESS'))
|
||||
{
|
||||
define('PHPBB_ACM_MEMCACHE_COMPRESS', false);
|
||||
}
|
||||
|
||||
if (!defined('PHPBB_ACM_MEMCACHE_HOST'))
|
||||
{
|
||||
define('PHPBB_ACM_MEMCACHE_HOST', 'localhost');
|
||||
}
|
||||
|
||||
if (!defined('PHPBB_ACM_MEMCACHE'))
|
||||
{
|
||||
//can define multiple servers with host1/port1,host2/port2 format
|
||||
define('PHPBB_ACM_MEMCACHE', PHPBB_ACM_MEMCACHE_HOST . '/' . PHPBB_ACM_MEMCACHE_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* ACM for Memcached
|
||||
*/
|
||||
class memcache extends \phpbb\cache\driver\memory
|
||||
{
|
||||
var $extension = 'memcache';
|
||||
|
||||
var $memcache;
|
||||
var $flags = 0;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
// Call the parent constructor
|
||||
parent::__construct();
|
||||
|
||||
$this->memcache = new \Memcache;
|
||||
foreach (explode(',', PHPBB_ACM_MEMCACHE) as $u)
|
||||
{
|
||||
preg_match('#(.*)/(\d+)#', $u, $parts);
|
||||
$this->memcache->addServer(trim($parts[1]), (int) trim($parts[2]));
|
||||
}
|
||||
$this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function unload()
|
||||
{
|
||||
parent::unload();
|
||||
|
||||
$this->memcache->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function purge()
|
||||
{
|
||||
$this->memcache->flush();
|
||||
|
||||
parent::purge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
{
|
||||
return $this->memcache->get($this->key_prefix . $var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
{
|
||||
if (!$this->memcache->replace($this->key_prefix . $var, $data, $this->flags, $ttl))
|
||||
{
|
||||
return $this->memcache->set($this->key_prefix . $var, $data, $this->flags, $ttl);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
{
|
||||
return $this->memcache->delete($this->key_prefix . $var);
|
||||
}
|
||||
}
|
134
msd2/phpBB3/phpbb/cache/driver/memcached.php
vendored
Normal file
134
msd2/phpBB3/phpbb/cache/driver/memcached.php
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
if (!defined('PHPBB_ACM_MEMCACHED_PORT'))
|
||||
{
|
||||
define('PHPBB_ACM_MEMCACHED_PORT', 11211);
|
||||
}
|
||||
|
||||
if (!defined('PHPBB_ACM_MEMCACHED_COMPRESS'))
|
||||
{
|
||||
define('PHPBB_ACM_MEMCACHED_COMPRESS', true);
|
||||
}
|
||||
|
||||
if (!defined('PHPBB_ACM_MEMCACHED_HOST'))
|
||||
{
|
||||
define('PHPBB_ACM_MEMCACHED_HOST', 'localhost');
|
||||
}
|
||||
|
||||
if (!defined('PHPBB_ACM_MEMCACHED'))
|
||||
{
|
||||
//can define multiple servers with host1/port1,host2/port2 format
|
||||
define('PHPBB_ACM_MEMCACHED', PHPBB_ACM_MEMCACHED_HOST . '/' . PHPBB_ACM_MEMCACHED_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* ACM for Memcached
|
||||
*/
|
||||
class memcached extends \phpbb\cache\driver\memory
|
||||
{
|
||||
/** @var string Extension to use */
|
||||
protected $extension = 'memcached';
|
||||
|
||||
/** @var \Memcached Memcached class */
|
||||
protected $memcached;
|
||||
|
||||
/** @var int Flags */
|
||||
protected $flags = 0;
|
||||
|
||||
/**
|
||||
* Memcached constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Call the parent constructor
|
||||
parent::__construct();
|
||||
|
||||
$this->memcached = new \Memcached();
|
||||
$this->memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
|
||||
// Memcached defaults to using compression, disable if we don't want
|
||||
// to use it
|
||||
if (!PHPBB_ACM_MEMCACHED_COMPRESS)
|
||||
{
|
||||
$this->memcached->setOption(\Memcached::OPT_COMPRESSION, false);
|
||||
}
|
||||
|
||||
foreach (explode(',', PHPBB_ACM_MEMCACHED) as $u)
|
||||
{
|
||||
preg_match('#(.*)/(\d+)#', $u, $parts);
|
||||
$this->memcached->addServer(trim($parts[1]), (int) trim($parts[2]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function unload()
|
||||
{
|
||||
parent::unload();
|
||||
|
||||
unset($this->memcached);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function purge()
|
||||
{
|
||||
$this->memcached->flush();
|
||||
|
||||
parent::purge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @param string $var Cache key
|
||||
*
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
protected function _read($var)
|
||||
{
|
||||
return $this->memcached->get($this->key_prefix . $var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
protected function _write($var, $data, $ttl = 2592000)
|
||||
{
|
||||
if (!$this->memcached->replace($this->key_prefix . $var, $data, $ttl))
|
||||
{
|
||||
return $this->memcached->set($this->key_prefix . $var, $data, $ttl);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
protected function _delete($var)
|
||||
{
|
||||
return $this->memcached->delete($this->key_prefix . $var);
|
||||
}
|
||||
}
|
282
msd2/phpBB3/phpbb/cache/driver/memory.php
vendored
Normal file
282
msd2/phpBB3/phpbb/cache/driver/memory.php
vendored
Normal file
@ -0,0 +1,282 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
/**
|
||||
* ACM Abstract Memory Class
|
||||
*/
|
||||
abstract class memory extends \phpbb\cache\driver\base
|
||||
{
|
||||
var $key_prefix;
|
||||
|
||||
/**
|
||||
* Set cache path
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
global $phpbb_root_path, $dbname, $table_prefix, $phpbb_container;
|
||||
|
||||
$this->cache_dir = $phpbb_container->getParameter('core.cache_dir');
|
||||
$this->key_prefix = substr(md5($dbname . $table_prefix), 0, 8) . '_';
|
||||
|
||||
if (!isset($this->extension) || !extension_loaded($this->extension))
|
||||
{
|
||||
global $acm_type;
|
||||
|
||||
trigger_error("Could not find required extension [{$this->extension}] for the ACM module $acm_type.", E_USER_ERROR);
|
||||
}
|
||||
|
||||
if (isset($this->function) && !function_exists($this->function))
|
||||
{
|
||||
global $acm_type;
|
||||
|
||||
trigger_error("The required function [{$this->function}] is not available for the ACM module $acm_type.", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function load()
|
||||
{
|
||||
// grab the global cache
|
||||
$data = $this->_read('global');
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
$this->vars = $data;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function save()
|
||||
{
|
||||
if (!$this->is_modified)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_write('global', $this->vars, 2592000);
|
||||
|
||||
$this->is_modified = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function tidy()
|
||||
{
|
||||
global $config;
|
||||
|
||||
// cache has auto GC, no need to have any code here :)
|
||||
$config->set('cache_last_gc', time(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function get($var_name)
|
||||
{
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
if (!$this->_exists($var_name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_read($var_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function put($var_name, $var, $ttl = 2592000)
|
||||
{
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
$this->_write($var_name, $var, $ttl);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->vars[$var_name] = $var;
|
||||
$this->is_modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function destroy($var_name, $table = '')
|
||||
{
|
||||
if ($var_name == 'sql' && !empty($table))
|
||||
{
|
||||
if (!is_array($table))
|
||||
{
|
||||
$table = array($table);
|
||||
}
|
||||
|
||||
foreach ($table as $table_name)
|
||||
{
|
||||
// gives us the md5s that we want
|
||||
$temp = $this->_read('sql_' . $table_name);
|
||||
|
||||
if ($temp === false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// delete each query ref
|
||||
foreach ($temp as $md5_id => $void)
|
||||
{
|
||||
$this->_delete('sql_' . $md5_id);
|
||||
}
|
||||
|
||||
// delete the table ref
|
||||
$this->_delete('sql_' . $table_name);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->_exists($var_name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
$this->_delete($var_name);
|
||||
}
|
||||
else if (isset($this->vars[$var_name]))
|
||||
{
|
||||
$this->is_modified = true;
|
||||
unset($this->vars[$var_name]);
|
||||
|
||||
// We save here to let the following cache hits succeed
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function _exists($var_name)
|
||||
{
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
return $this->_isset($var_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!count($this->vars))
|
||||
{
|
||||
$this->load();
|
||||
}
|
||||
|
||||
return isset($this->vars[$var_name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function sql_save(\phpbb\db\driver\driver_interface $db, $query, $query_result, $ttl)
|
||||
{
|
||||
// Remove extra spaces and tabs
|
||||
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
||||
$query_id = md5($query);
|
||||
|
||||
// determine which tables this query belongs to
|
||||
// Some queries use backticks, namely the get_database_size() query
|
||||
// don't check for conformity, the SQL would error and not reach here.
|
||||
if (!preg_match_all('/(?:FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?)|(?:JOIN (`?\\w+`?(?: \\w+)?))/', $query, $regs, PREG_SET_ORDER))
|
||||
{
|
||||
// Bail out if the match fails.
|
||||
return $query_result;
|
||||
}
|
||||
|
||||
$tables = array();
|
||||
foreach ($regs as $match)
|
||||
{
|
||||
if ($match[0][0] == 'F')
|
||||
{
|
||||
$tables = array_merge($tables, array_map('trim', explode(',', $match[1])));
|
||||
}
|
||||
else
|
||||
{
|
||||
$tables[] = $match[2];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($tables as $table_name)
|
||||
{
|
||||
// Remove backticks
|
||||
$table_name = ($table_name[0] == '`') ? substr($table_name, 1, -1) : $table_name;
|
||||
|
||||
if (($pos = strpos($table_name, ' ')) !== false)
|
||||
{
|
||||
$table_name = substr($table_name, 0, $pos);
|
||||
}
|
||||
|
||||
$temp = $this->_read('sql_' . $table_name);
|
||||
|
||||
if ($temp === false)
|
||||
{
|
||||
$temp = array();
|
||||
}
|
||||
|
||||
$temp[$query_id] = true;
|
||||
|
||||
// This must never expire
|
||||
$this->_write('sql_' . $table_name, $temp, 0);
|
||||
}
|
||||
|
||||
// store them in the right place
|
||||
$this->sql_rowset[$query_id] = array();
|
||||
$this->sql_row_pointer[$query_id] = 0;
|
||||
|
||||
while ($row = $db->sql_fetchrow($query_result))
|
||||
{
|
||||
$this->sql_rowset[$query_id][] = $row;
|
||||
}
|
||||
$db->sql_freeresult($query_result);
|
||||
|
||||
$this->_write('sql_' . $query_id, $this->sql_rowset[$query_id], $ttl);
|
||||
|
||||
return $query_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a cache var exists
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if it exists, otherwise false
|
||||
*/
|
||||
function _isset($var)
|
||||
{
|
||||
// Most caches don't need to check
|
||||
return true;
|
||||
}
|
||||
}
|
162
msd2/phpBB3/phpbb/cache/driver/redis.php
vendored
Normal file
162
msd2/phpBB3/phpbb/cache/driver/redis.php
vendored
Normal file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
if (!defined('PHPBB_ACM_REDIS_PORT'))
|
||||
{
|
||||
define('PHPBB_ACM_REDIS_PORT', 6379);
|
||||
}
|
||||
|
||||
if (!defined('PHPBB_ACM_REDIS_HOST'))
|
||||
{
|
||||
define('PHPBB_ACM_REDIS_HOST', 'localhost');
|
||||
}
|
||||
|
||||
/**
|
||||
* ACM for Redis
|
||||
*
|
||||
* Compatible with the php extension phpredis available
|
||||
* at https://github.com/nicolasff/phpredis
|
||||
*
|
||||
*/
|
||||
class redis extends \phpbb\cache\driver\memory
|
||||
{
|
||||
var $extension = 'redis';
|
||||
|
||||
var $redis;
|
||||
|
||||
/**
|
||||
* Creates a redis cache driver.
|
||||
*
|
||||
* The following global constants affect operation:
|
||||
*
|
||||
* PHPBB_ACM_REDIS_HOST
|
||||
* PHPBB_ACM_REDIS_PORT
|
||||
* PHPBB_ACM_REDIS_PASSWORD
|
||||
* PHPBB_ACM_REDIS_DB
|
||||
*
|
||||
* There are no publicly documented constructor parameters.
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
// Call the parent constructor
|
||||
parent::__construct();
|
||||
|
||||
$this->redis = new \Redis();
|
||||
|
||||
$args = func_get_args();
|
||||
if (!empty($args))
|
||||
{
|
||||
$ok = call_user_func_array(array($this->redis, 'connect'), $args);
|
||||
}
|
||||
else
|
||||
{
|
||||
$ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT);
|
||||
}
|
||||
|
||||
if (!$ok)
|
||||
{
|
||||
trigger_error('Could not connect to redis server');
|
||||
}
|
||||
|
||||
if (defined('PHPBB_ACM_REDIS_PASSWORD'))
|
||||
{
|
||||
if (!$this->redis->auth(PHPBB_ACM_REDIS_PASSWORD))
|
||||
{
|
||||
global $acm_type;
|
||||
|
||||
trigger_error("Incorrect password for the ACM module $acm_type.", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
$this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
|
||||
$this->redis->setOption(\Redis::OPT_PREFIX, $this->key_prefix);
|
||||
|
||||
if (defined('PHPBB_ACM_REDIS_DB'))
|
||||
{
|
||||
if (!$this->redis->select(PHPBB_ACM_REDIS_DB))
|
||||
{
|
||||
global $acm_type;
|
||||
|
||||
trigger_error("Incorrect database for the ACM module $acm_type.", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function unload()
|
||||
{
|
||||
parent::unload();
|
||||
|
||||
$this->redis->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function purge()
|
||||
{
|
||||
$this->redis->flushDB();
|
||||
|
||||
parent::purge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
{
|
||||
return $this->redis->get($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
{
|
||||
if ($ttl == 0)
|
||||
{
|
||||
return $this->redis->set($var, $data);
|
||||
}
|
||||
return $this->redis->setex($var, $ttl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
{
|
||||
if ($this->redis->delete($var) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
73
msd2/phpBB3/phpbb/cache/driver/wincache.php
vendored
Normal file
73
msd2/phpBB3/phpbb/cache/driver/wincache.php
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
/**
|
||||
* ACM for WinCache
|
||||
*/
|
||||
class wincache extends \phpbb\cache\driver\memory
|
||||
{
|
||||
var $extension = 'wincache';
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function purge()
|
||||
{
|
||||
wincache_ucache_clear();
|
||||
|
||||
parent::purge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
{
|
||||
$success = false;
|
||||
$result = wincache_ucache_get($this->key_prefix . $var, $success);
|
||||
|
||||
return ($success) ? $result : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
{
|
||||
return wincache_ucache_set($this->key_prefix . $var, $data, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
{
|
||||
return wincache_ucache_delete($this->key_prefix . $var);
|
||||
}
|
||||
}
|
107
msd2/phpBB3/phpbb/cache/driver/xcache.php
vendored
Normal file
107
msd2/phpBB3/phpbb/cache/driver/xcache.php
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache\driver;
|
||||
|
||||
/**
|
||||
* ACM for XCache
|
||||
*
|
||||
* To use this module you need ini_get() enabled and the following INI settings configured as follows:
|
||||
* - xcache.var_size > 0
|
||||
* - xcache.admin.enable_auth = off (or xcache.admin.user and xcache.admin.password set)
|
||||
*
|
||||
*/
|
||||
class xcache extends \phpbb\cache\driver\memory
|
||||
{
|
||||
var $extension = 'XCache';
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
if (!function_exists('ini_get') || (int) ini_get('xcache.var_size') <= 0)
|
||||
{
|
||||
trigger_error('Increase xcache.var_size setting above 0 or enable ini_get() to use this ACM module.', E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
function purge()
|
||||
{
|
||||
// Run before for XCache, if admin functions are disabled it will terminate execution
|
||||
parent::purge();
|
||||
|
||||
// If the admin authentication is enabled but not set up, this will cause a nasty error.
|
||||
// Not much we can do about it though.
|
||||
$n = xcache_count(XC_TYPE_VAR);
|
||||
|
||||
for ($i = 0; $i < $n; $i++)
|
||||
{
|
||||
xcache_clear_cache(XC_TYPE_VAR, $i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return mixed Cached data
|
||||
*/
|
||||
function _read($var)
|
||||
{
|
||||
$result = xcache_get($this->key_prefix . $var);
|
||||
|
||||
return ($result !== null) ? $result : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data in the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @param mixed $data Data to store
|
||||
* @param int $ttl Time-to-live of cached data
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _write($var, $data, $ttl = 2592000)
|
||||
{
|
||||
return xcache_set($this->key_prefix . $var, $data, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if the operation succeeded
|
||||
*/
|
||||
function _delete($var)
|
||||
{
|
||||
return xcache_unset($this->key_prefix . $var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a cache var exists
|
||||
*
|
||||
* @access protected
|
||||
* @param string $var Cache key
|
||||
* @return bool True if it exists, otherwise false
|
||||
*/
|
||||
function _isset($var)
|
||||
{
|
||||
return xcache_isset($this->key_prefix . $var);
|
||||
}
|
||||
}
|
390
msd2/phpBB3/phpbb/cache/service.php
vendored
Normal file
390
msd2/phpBB3/phpbb/cache/service.php
vendored
Normal file
@ -0,0 +1,390 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\cache;
|
||||
|
||||
/**
|
||||
* Class for grabbing/handling cached entries
|
||||
*/
|
||||
class service
|
||||
{
|
||||
/**
|
||||
* Cache driver.
|
||||
*
|
||||
* @var \phpbb\cache\driver\driver_interface
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* The config.
|
||||
*
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Database connection.
|
||||
*
|
||||
* @var \phpbb\db\driver\driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Root path.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* PHP file extension.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* Creates a cache service around a cache driver
|
||||
*
|
||||
* @param \phpbb\cache\driver\driver_interface $driver The cache driver
|
||||
* @param \phpbb\config\config $config The config
|
||||
* @param \phpbb\db\driver\driver_interface $db Database connection
|
||||
* @param string $phpbb_root_path Root path
|
||||
* @param string $php_ext PHP file extension
|
||||
*/
|
||||
public function __construct(\phpbb\cache\driver\driver_interface $driver, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext)
|
||||
{
|
||||
$this->set_driver($driver);
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cache driver used by this cache service.
|
||||
*
|
||||
* @return \phpbb\cache\driver\driver_interface The cache driver
|
||||
*/
|
||||
public function get_driver()
|
||||
{
|
||||
return $this->driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the cache driver used by this cache service.
|
||||
*
|
||||
* @param \phpbb\cache\driver\driver_interface $driver The cache driver
|
||||
*/
|
||||
public function set_driver(\phpbb\cache\driver\driver_interface $driver)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
}
|
||||
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
return call_user_func_array(array($this->driver, $method), $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain list of naughty words and build preg style replacement arrays for use by the
|
||||
* calling script
|
||||
*/
|
||||
function obtain_word_list()
|
||||
{
|
||||
if (($censors = $this->driver->get('_word_censors')) === false)
|
||||
{
|
||||
$sql = 'SELECT word, replacement
|
||||
FROM ' . WORDS_TABLE;
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$censors = array();
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$censors['match'][] = get_censor_preg_expression($row['word']);
|
||||
$censors['replace'][] = $row['replacement'];
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$this->driver->put('_word_censors', $censors);
|
||||
}
|
||||
|
||||
return $censors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain currently listed icons
|
||||
*/
|
||||
function obtain_icons()
|
||||
{
|
||||
if (($icons = $this->driver->get('_icons')) === false)
|
||||
{
|
||||
// Topic icons
|
||||
$sql = 'SELECT *
|
||||
FROM ' . ICONS_TABLE . '
|
||||
ORDER BY icons_order';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$icons = array();
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$icons[$row['icons_id']]['img'] = $row['icons_url'];
|
||||
$icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
|
||||
$icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
|
||||
$icons[$row['icons_id']]['alt'] = ($row['icons_alt']) ? $row['icons_alt'] : '';
|
||||
$icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$this->driver->put('_icons', $icons);
|
||||
}
|
||||
|
||||
return $icons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain ranks
|
||||
*/
|
||||
function obtain_ranks()
|
||||
{
|
||||
if (($ranks = $this->driver->get('_ranks')) === false)
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM ' . RANKS_TABLE . '
|
||||
ORDER BY rank_min DESC';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$ranks = array();
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
if ($row['rank_special'])
|
||||
{
|
||||
unset($row['rank_min']);
|
||||
$ranks['special'][$row['rank_id']] = $row;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ranks['normal'][$row['rank_id']] = $row;
|
||||
}
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$this->driver->put('_ranks', $ranks);
|
||||
}
|
||||
|
||||
return $ranks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain allowed extensions
|
||||
*
|
||||
* @param mixed $forum_id If false then check for private messaging, if int then check for forum id. If true, then only return extension informations.
|
||||
*
|
||||
* @return array allowed extensions array.
|
||||
*/
|
||||
function obtain_attach_extensions($forum_id)
|
||||
{
|
||||
if (($extensions = $this->driver->get('_extensions')) === false)
|
||||
{
|
||||
$extensions = array(
|
||||
'_allowed_post' => array(),
|
||||
'_allowed_pm' => array(),
|
||||
);
|
||||
|
||||
// The rule is to only allow those extensions defined. ;)
|
||||
$sql = 'SELECT e.extension, g.*
|
||||
FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
|
||||
WHERE e.group_id = g.group_id
|
||||
AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$extension = strtolower(trim($row['extension']));
|
||||
|
||||
$extensions[$extension] = array(
|
||||
'display_cat' => (int) $row['cat_id'],
|
||||
'download_mode' => (int) $row['download_mode'],
|
||||
'upload_icon' => trim($row['upload_icon']),
|
||||
'max_filesize' => (int) $row['max_filesize'],
|
||||
'allow_group' => $row['allow_group'],
|
||||
'allow_in_pm' => $row['allow_in_pm'],
|
||||
'group_name' => $row['group_name'],
|
||||
);
|
||||
|
||||
$allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
|
||||
|
||||
// Store allowed extensions forum wise
|
||||
if ($row['allow_group'])
|
||||
{
|
||||
$extensions['_allowed_post'][$extension] = (!count($allowed_forums)) ? 0 : $allowed_forums;
|
||||
}
|
||||
|
||||
if ($row['allow_in_pm'])
|
||||
{
|
||||
$extensions['_allowed_pm'][$extension] = 0;
|
||||
}
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$this->driver->put('_extensions', $extensions);
|
||||
}
|
||||
|
||||
// Forum post
|
||||
if ($forum_id === false)
|
||||
{
|
||||
// We are checking for private messages, therefore we only need to get the pm extensions...
|
||||
$return = array('_allowed_' => array());
|
||||
|
||||
foreach ($extensions['_allowed_pm'] as $extension => $check)
|
||||
{
|
||||
$return['_allowed_'][$extension] = 0;
|
||||
$return[$extension] = $extensions[$extension];
|
||||
}
|
||||
|
||||
$extensions = $return;
|
||||
}
|
||||
else if ($forum_id === true)
|
||||
{
|
||||
return $extensions;
|
||||
}
|
||||
else
|
||||
{
|
||||
$forum_id = (int) $forum_id;
|
||||
$return = array('_allowed_' => array());
|
||||
|
||||
foreach ($extensions['_allowed_post'] as $extension => $check)
|
||||
{
|
||||
// Check for allowed forums
|
||||
if (is_array($check))
|
||||
{
|
||||
$allowed = (!in_array($forum_id, $check)) ? false : true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$allowed = true;
|
||||
}
|
||||
|
||||
if ($allowed)
|
||||
{
|
||||
$return['_allowed_'][$extension] = 0;
|
||||
$return[$extension] = $extensions[$extension];
|
||||
}
|
||||
}
|
||||
|
||||
$extensions = $return;
|
||||
}
|
||||
|
||||
if (!isset($extensions['_allowed_']))
|
||||
{
|
||||
$extensions['_allowed_'] = array();
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain active bots
|
||||
*/
|
||||
function obtain_bots()
|
||||
{
|
||||
if (($bots = $this->driver->get('_bots')) === false)
|
||||
{
|
||||
switch ($this->db->get_sql_layer())
|
||||
{
|
||||
case 'mssql_odbc':
|
||||
case 'mssqlnative':
|
||||
$sql = 'SELECT user_id, bot_agent, bot_ip
|
||||
FROM ' . BOTS_TABLE . '
|
||||
WHERE bot_active = 1
|
||||
ORDER BY LEN(bot_agent) DESC';
|
||||
break;
|
||||
|
||||
// LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
|
||||
default:
|
||||
$sql = 'SELECT user_id, bot_agent, bot_ip
|
||||
FROM ' . BOTS_TABLE . '
|
||||
WHERE bot_active = 1
|
||||
ORDER BY LENGTH(bot_agent) DESC';
|
||||
break;
|
||||
}
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$bots = array();
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$bots[] = $row;
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$this->driver->put('_bots', $bots);
|
||||
}
|
||||
|
||||
return $bots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain cfg file data
|
||||
*/
|
||||
function obtain_cfg_items($style)
|
||||
{
|
||||
$parsed_array = $this->driver->get('_cfg_' . $style['style_path']);
|
||||
|
||||
if ($parsed_array === false)
|
||||
{
|
||||
$parsed_array = array();
|
||||
}
|
||||
|
||||
$filename = $this->phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg';
|
||||
|
||||
if (!file_exists($filename))
|
||||
{
|
||||
return $parsed_array;
|
||||
}
|
||||
|
||||
if (!isset($parsed_array['filetime']) || (($this->config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
|
||||
{
|
||||
// Re-parse cfg file
|
||||
$parsed_array = parse_cfg_file($filename);
|
||||
$parsed_array['filetime'] = @filemtime($filename);
|
||||
|
||||
$this->driver->put('_cfg_' . $style['style_path'], $parsed_array);
|
||||
}
|
||||
|
||||
return $parsed_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain disallowed usernames
|
||||
*/
|
||||
function obtain_disallowed_usernames()
|
||||
{
|
||||
if (($usernames = $this->driver->get('_disallowed_usernames')) === false)
|
||||
{
|
||||
$sql = 'SELECT disallow_username
|
||||
FROM ' . DISALLOW_TABLE;
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$usernames = array();
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$this->driver->put('_disallowed_usernames', $usernames);
|
||||
}
|
||||
|
||||
return $usernames;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user