mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +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,72 +1,69 @@
|
||||
<?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 eAccelerator Based Caching
|
||||
* ACM Memcache 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 ($this->vars = eaccelerator_get('global'))
|
||||
$temp = eaccelerator_get('global');
|
||||
|
||||
if ($temp !== null)
|
||||
{
|
||||
return true;
|
||||
$this->vars = $temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
@@ -81,7 +78,7 @@ class acm
|
||||
/**
|
||||
* Tidy cache
|
||||
*/
|
||||
public function tidy()
|
||||
function tidy()
|
||||
{
|
||||
eaccelerator_gc();
|
||||
|
||||
@@ -91,9 +88,9 @@ class acm
|
||||
/**
|
||||
* Get saved cache object
|
||||
*/
|
||||
public function get($var_name)
|
||||
function get($var_name)
|
||||
{
|
||||
if ($var_name[0] === '_')
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
$temp = eaccelerator_get($var_name);
|
||||
|
||||
@@ -119,9 +116,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] == '_')
|
||||
{
|
||||
eaccelerator_put($var_name, $var, $ttl);
|
||||
}
|
||||
@@ -135,7 +132,7 @@ class acm
|
||||
/**
|
||||
* Purge cache data
|
||||
*/
|
||||
public function purge()
|
||||
function purge()
|
||||
{
|
||||
// Purge all phpbb cache files
|
||||
$dir = @opendir($this->cache_dir);
|
||||
@@ -163,10 +160,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;
|
||||
}
|
||||
@@ -174,9 +168,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))
|
||||
{
|
||||
@@ -209,7 +203,7 @@ class acm
|
||||
return;
|
||||
}
|
||||
|
||||
if ($var_name[0] === '_')
|
||||
if ($var_name[0] == '_')
|
||||
{
|
||||
eaccelerator_rm($var_name);
|
||||
}
|
||||
@@ -226,7 +220,7 @@ 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);
|
||||
@@ -241,31 +235,23 @@ class acm
|
||||
|
||||
$this->sql_rowset[$query_id] = $temp;
|
||||
|
||||
$this->sql_row_pointer[$query_id] = 0;
|
||||
|
||||
return $query_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
@@ -278,13 +264,14 @@ class acm
|
||||
{
|
||||
$temp = array();
|
||||
}
|
||||
$temp[$query_hash] = true;
|
||||
$temp[md5($query)] = true;
|
||||
eaccelerator_put('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))
|
||||
{
|
||||
@@ -292,35 +279,63 @@ class acm
|
||||
}
|
||||
$db->sql_freeresult($query_result);
|
||||
|
||||
eaccelerator_put('sql_' . $query_hash, $this->sql_rowset[$query_id], $ttl);
|
||||
eaccelerator_put('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]))
|
||||
{
|
||||
@@ -328,6 +343,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