mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-11 03:04:09 +02:00
remove global and change $user-> to phpbb::$user->
git-svn-id: file:///svn/phpbb/trunk@9334 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -1,45 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
/**
|
||||
*
|
||||
* @package acm
|
||||
* @version $Id$
|
||||
* @copyright (c) 2005 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
* @copyright (c) 2005 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* ACM XCache Based Caching
|
||||
* @package acm
|
||||
*/
|
||||
class acm
|
||||
{
|
||||
private $vars = array();
|
||||
private $is_modified = false;
|
||||
var $vars = array();
|
||||
var $is_modified = false;
|
||||
|
||||
public $sql_rowset = array();
|
||||
public $cache_dir = '';
|
||||
var $sql_rowset = array();
|
||||
var $sql_row_pointer = array();
|
||||
var $cache_dir = '';
|
||||
|
||||
/**
|
||||
* Set cache path
|
||||
*/
|
||||
function __construct()
|
||||
function acm()
|
||||
{
|
||||
$this->cache_dir = PHPBB_ROOT_PATH . 'cache/';
|
||||
$this->cache_dir = $phpbb_root_path . 'cache/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Load global cache
|
||||
*/
|
||||
private function load()
|
||||
function load()
|
||||
{
|
||||
// grab the global cache
|
||||
if (xcache_isset('global'))
|
||||
@@ -54,20 +47,18 @@ class acm
|
||||
/**
|
||||
* Unload cache object
|
||||
*/
|
||||
public function unload()
|
||||
function unload()
|
||||
{
|
||||
$this->save();
|
||||
unset($this->vars);
|
||||
unset($this->sql_rowset);
|
||||
|
||||
$this->vars = array();
|
||||
$this->sql_rowset = array();
|
||||
unset($this->sql_row_pointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save modified objects
|
||||
*/
|
||||
private function save()
|
||||
function save()
|
||||
{
|
||||
if (!$this->is_modified)
|
||||
{
|
||||
@@ -82,7 +73,7 @@ class acm
|
||||
/**
|
||||
* Tidy cache
|
||||
*/
|
||||
public function tidy()
|
||||
function tidy()
|
||||
{
|
||||
// cache has auto GC, no need to have any code here :)
|
||||
|
||||
@@ -92,9 +83,9 @@ class acm
|
||||
/**
|
||||
* Get saved cache object
|
||||
*/
|
||||
public function get($var_name)
|
||||
function get($var_name)
|
||||
{
|
||||
if ($var_name[0] === '_')
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
return (xcache_isset($var_name)) ? xcache_get($var_name) : false;
|
||||
}
|
||||
@@ -111,9 +102,9 @@ class acm
|
||||
/**
|
||||
* Put data into cache
|
||||
*/
|
||||
public function put($var_name, $var, $ttl = 31536000)
|
||||
function put($var_name, $var, $ttl = 31536000)
|
||||
{
|
||||
if ($var_name[0] === '_')
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
xcache_set($var_name, $var, $ttl);
|
||||
}
|
||||
@@ -127,7 +118,7 @@ class acm
|
||||
/**
|
||||
* Purge cache data
|
||||
*/
|
||||
public function purge()
|
||||
function purge()
|
||||
{
|
||||
// Purge all phpbb cache files
|
||||
$dir = @opendir($this->cache_dir);
|
||||
@@ -156,10 +147,7 @@ class acm
|
||||
|
||||
unset($this->vars);
|
||||
unset($this->sql_rowset);
|
||||
|
||||
$this->vars = array();
|
||||
$this->var_expires = array();
|
||||
$this->sql_rowset = array();
|
||||
unset($this->sql_row_pointer);
|
||||
|
||||
$this->is_modified = false;
|
||||
}
|
||||
@@ -167,9 +155,9 @@ class acm
|
||||
/**
|
||||
* Destroy cache data
|
||||
*/
|
||||
public function destroy($var_name, $table = '')
|
||||
function destroy($var_name, $table = '')
|
||||
{
|
||||
if ($var_name === 'sql' && !empty($table))
|
||||
if ($var_name == 'sql' && !empty($table))
|
||||
{
|
||||
if (!is_array($table))
|
||||
{
|
||||
@@ -198,7 +186,7 @@ class acm
|
||||
return;
|
||||
}
|
||||
|
||||
if ($var_name[0] === '_')
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
xcache_unset($var_name);
|
||||
}
|
||||
@@ -215,21 +203,20 @@ class acm
|
||||
/**
|
||||
* Load cached sql query
|
||||
*/
|
||||
public function sql_load($query)
|
||||
function sql_load($query)
|
||||
{
|
||||
// Remove extra spaces and tabs
|
||||
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
||||
$query_id = sizeof($this->sql_rowset);
|
||||
|
||||
$query_hash = md5($query);
|
||||
|
||||
if (!xcache_isset('sql_' . $query_hash))
|
||||
if (!xcache_isset('sql_' . md5($query)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->sql_rowset[$query_id] = xcache_get('sql_' . $query_hash);
|
||||
$this->sql_rowset[$query_id] = xcache_get('sql_' . md5($query));
|
||||
|
||||
$this->sql_row_pointer[$query_id] = 0;
|
||||
|
||||
return $query_id;
|
||||
}
|
||||
@@ -237,25 +224,15 @@ class acm
|
||||
/**
|
||||
* Save sql query
|
||||
*/
|
||||
public function sql_save($query, &$query_result, $ttl)
|
||||
function sql_save($query, &$query_result, $ttl)
|
||||
{
|
||||
global $db;
|
||||
|
||||
// Remove extra spaces and tabs
|
||||
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
||||
|
||||
// determine which tables this query belongs to:
|
||||
|
||||
// grab all the FROM tables, avoid getting a LEFT JOIN
|
||||
preg_match('/FROM \(?(\w+(?: (?!LEFT JOIN)\w+)?(?:, ?\w+(?: (?!LEFT JOIN)\w+)?)*)\)?/', $query, $regs);
|
||||
// determine which tables this query belongs to
|
||||
preg_match('/FROM \\(?(\\w+(?: \\w+)?(?:, ?\\w+(?: \\w+)?)*)\\)?/', $query, $regs);
|
||||
$tables = array_map('trim', explode(',', $regs[1]));
|
||||
|
||||
// now get the LEFT JOIN
|
||||
preg_match_all('/LEFT JOIN\s+(\w+)(?: \w+)?/', $query, $result, PREG_PATTERN_ORDER);
|
||||
$tables = array_merge($tables, $result[1]);
|
||||
|
||||
$query_hash = md5($query);
|
||||
|
||||
foreach ($tables as $table_name)
|
||||
{
|
||||
if (($pos = strpos($table_name, ' ')) !== false)
|
||||
@@ -271,13 +248,14 @@ class acm
|
||||
{
|
||||
$temp = array();
|
||||
}
|
||||
$temp[$query_hash] = true;
|
||||
$temp[md5($query)] = true;
|
||||
xcache_set('sql_' . $table_name, $temp, $ttl);
|
||||
}
|
||||
|
||||
// store them in the right place
|
||||
$query_id = sizeof($this->sql_rowset);
|
||||
$this->sql_rowset[$query_id] = array();
|
||||
$this->sql_row_pointer[$query_id] = 0;
|
||||
|
||||
while ($row = $db->sql_fetchrow($query_result))
|
||||
{
|
||||
@@ -285,35 +263,63 @@ class acm
|
||||
}
|
||||
$db->sql_freeresult($query_result);
|
||||
|
||||
xcache_set('sql_' . $query_hash, $this->sql_rowset[$query_id], $ttl);
|
||||
xcache_set('sql_' . md5($query), $this->sql_rowset[$query_id], $ttl);
|
||||
|
||||
$query_result = $query_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ceck if a given sql query exist in cache
|
||||
*/
|
||||
function sql_exists($query_id)
|
||||
{
|
||||
return isset($this->sql_rowset[$query_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch row from cache (database)
|
||||
*/
|
||||
public function sql_fetchrow($query_id)
|
||||
function sql_fetchrow($query_id)
|
||||
{
|
||||
list(, $row) = each($this->sql_rowset[$query_id]);
|
||||
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
|
||||
{
|
||||
return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
|
||||
}
|
||||
|
||||
return ($row !== NULL) ? $row : false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a field from the current row of a cached database result (database)
|
||||
*/
|
||||
public function sql_fetchfield($query_id, $field)
|
||||
function sql_fetchfield($query_id, $field)
|
||||
{
|
||||
$row = current($this->sql_rowset[$query_id]);
|
||||
if ($this->sql_row_pointer[$query_id] < sizeof($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 ($row !== false && isset($row[$field])) ? $row[$field] : false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seek a specific row in an a cached database result (database)
|
||||
*/
|
||||
function sql_rowseek($rownum, $query_id)
|
||||
{
|
||||
if ($rownum >= sizeof($this->sql_rowset[$query_id]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->sql_row_pointer[$query_id] = $rownum;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free memory used for a cached database result (database)
|
||||
*/
|
||||
public function sql_freeresult($query_id)
|
||||
function sql_freeresult($query_id)
|
||||
{
|
||||
if (!isset($this->sql_rowset[$query_id]))
|
||||
{
|
||||
@@ -321,6 +327,7 @@ class acm
|
||||
}
|
||||
|
||||
unset($this->sql_rowset[$query_id]);
|
||||
unset($this->sql_row_pointer[$query_id]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user