|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @package acm
|
|
|
4c79b5 |
* @version $Id: acm_file.php 9076 2008-11-22 19:06:42Z acydburn $
|
|
|
4c79b5 |
* @copyright (c) 2005 phpBB Group
|
|
|
4c79b5 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* @ignore
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
if (!defined('IN_PHPBB'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* ACM File Based Caching
|
|
|
4c79b5 |
* @package acm
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
class acm
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var $vars = array();
|
|
|
4c79b5 |
var $var_expires = array();
|
|
|
4c79b5 |
var $is_modified = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
var $sql_rowset = array();
|
|
|
4c79b5 |
var $sql_row_pointer = array();
|
|
|
4c79b5 |
var $cache_dir = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Set cache path
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function acm()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path;
|
|
|
4c79b5 |
$this->cache_dir = $phpbb_root_path . 'cache/';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Load global cache
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function load()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpEx;
|
|
|
4c79b5 |
if (file_exists($this->cache_dir . 'data_global.' . $phpEx))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@include($this->cache_dir . 'data_global.' . $phpEx);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Unload cache object
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function unload()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->save();
|
|
|
4c79b5 |
unset($this->vars);
|
|
|
4c79b5 |
unset($this->var_expires);
|
|
|
4c79b5 |
unset($this->sql_rowset);
|
|
|
4c79b5 |
unset($this->sql_row_pointer);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->vars = array();
|
|
|
4c79b5 |
$this->var_expires = array();
|
|
|
4c79b5 |
$this->sql_rowset = array();
|
|
|
4c79b5 |
$this->sql_row_pointer = array();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Save modified objects
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function save()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$this->is_modified)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
global $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($fp = @fopen($this->cache_dir . 'data_global.' . $phpEx, 'wb'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@flock($fp, LOCK_EX);
|
|
|
4c79b5 |
fwrite($fp, "vars = " . var_export($this->vars, true) . ";\n\n\$this->var_expires = " . var_export($this->var_expires, true) . "\n?>");
|
|
|
4c79b5 |
@flock($fp, LOCK_UN);
|
|
|
4c79b5 |
fclose($fp);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!function_exists('phpbb_chmod'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path;
|
|
|
4c79b5 |
include($phpbb_root_path . 'includes/functions.' . $phpEx);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
phpbb_chmod($this->cache_dir . 'data_global.' . $phpEx, CHMOD_WRITE);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Now, this occurred how often? ... phew, just tell the user then...
|
|
|
4c79b5 |
if (!@is_writable($this->cache_dir))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($this->cache_dir . ' is NOT writable.', E_USER_ERROR);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
trigger_error('Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx, E_USER_ERROR);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->is_modified = false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Tidy cache
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function tidy()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$dir = @opendir($this->cache_dir);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$dir)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while (($entry = readdir($dir)) !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!preg_match('/^(sql_|data_(?!global))/', $entry))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$expired = true;
|
|
|
4c79b5 |
@include($this->cache_dir . $entry);
|
|
|
4c79b5 |
if ($expired)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->remove_file($this->cache_dir . $entry);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
closedir($dir);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (file_exists($this->cache_dir . 'data_global.' . $phpEx))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!sizeof($this->vars))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->load();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($this->var_expires as $var_name => $expires)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (time() > $expires)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->destroy($var_name);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
set_config('cache_last_gc', time(), true);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Get saved cache object
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get($var_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($var_name[0] == '_')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$this->_exists($var_name))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
@include($this->cache_dir . "data{$var_name}.$phpEx");
|
|
|
4c79b5 |
return (isset($data)) ? $data : false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Put data into cache
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function put($var_name, $var, $ttl = 31536000)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($var_name[0] == '_')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($fp = @fopen($this->cache_dir . "data{$var_name}.$phpEx", 'wb'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@flock($fp, LOCK_EX);
|
|
|
4c79b5 |
fwrite($fp, " " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\n\$data = " . (sizeof($var) ? "unserialize(" . var_export(serialize($var), true) . ");" : 'array();') . "\n\n?>");
|
|
|
4c79b5 |
@flock($fp, LOCK_UN);
|
|
|
4c79b5 |
fclose($fp);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!function_exists('phpbb_chmod'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path;
|
|
|
4c79b5 |
include($phpbb_root_path . 'includes/functions.' . $phpEx);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
phpbb_chmod($this->cache_dir . "data{$var_name}.$phpEx", CHMOD_WRITE);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->vars[$var_name] = $var;
|
|
|
4c79b5 |
$this->var_expires[$var_name] = time() + $ttl;
|
|
|
4c79b5 |
$this->is_modified = true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Purge cache data
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function purge()
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Purge all phpbb cache files
|
|
|
4c79b5 |
$dir = @opendir($this->cache_dir);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$dir)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while (($entry = readdir($dir)) !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->remove_file($this->cache_dir . $entry);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
closedir($dir);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
unset($this->vars);
|
|
|
4c79b5 |
unset($this->var_expires);
|
|
|
4c79b5 |
unset($this->sql_rowset);
|
|
|
4c79b5 |
unset($this->sql_row_pointer);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->vars = array();
|
|
|
4c79b5 |
$this->var_expires = array();
|
|
|
4c79b5 |
$this->sql_rowset = array();
|
|
|
4c79b5 |
$this->sql_row_pointer = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->is_modified = false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Destroy cache data
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function destroy($var_name, $table = '')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($var_name == 'sql' && !empty($table))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!is_array($table))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$table = array($table);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$dir = @opendir($this->cache_dir);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$dir)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while (($entry = readdir($dir)) !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (strpos($entry, 'sql_') !== 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// The following method is more failproof than simply assuming the query is on line 3 (which it should be)
|
|
|
4c79b5 |
$check_line = @file_get_contents($this->cache_dir . $entry);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (empty($check_line))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Now get the contents between /* and */
|
|
|
4c79b5 |
$check_line = substr($check_line, strpos($check_line, '/* ') + 3, strpos($check_line, ' */') - strpos($check_line, '/* ') - 3);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$found = false;
|
|
|
4c79b5 |
foreach ($table as $check_table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Better catch partial table names than no table names. ;)
|
|
|
4c79b5 |
if (strpos($check_line, $check_table) !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$found = true;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($found)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->remove_file($this->cache_dir . $entry);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
closedir($dir);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$this->_exists($var_name))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($var_name[0] == '_')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->remove_file($this->cache_dir . 'data' . $var_name . ".$phpEx", true);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (isset($this->vars[$var_name]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->is_modified = true;
|
|
|
4c79b5 |
unset($this->vars[$var_name]);
|
|
|
4c79b5 |
unset($this->var_expires[$var_name]);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// We save here to let the following cache hits succeed
|
|
|
4c79b5 |
$this->save();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Check if a given cache entry exist
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _exists($var_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($var_name[0] == '_')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpEx;
|
|
|
4c79b5 |
return file_exists($this->cache_dir . 'data' . $var_name . ".$phpEx");
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!sizeof($this->vars))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->load();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!isset($this->var_expires[$var_name]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return (time() > $this->var_expires[$var_name]) ? false : isset($this->vars[$var_name]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Load cached sql query
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_load($query)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Remove extra spaces and tabs
|
|
|
4c79b5 |
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
|
|
4c79b5 |
$query_id = sizeof($this->sql_rowset);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!file_exists($this->cache_dir . 'sql_' . md5($query) . ".$phpEx"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
@include($this->cache_dir . 'sql_' . md5($query) . ".$phpEx");
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!isset($expired))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($expired)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->remove_file($this->cache_dir . 'sql_' . md5($query) . ".$phpEx", true);
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->sql_row_pointer[$query_id] = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $query_id;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Save sql query
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_save($query, &$query_result, $ttl)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Remove extra spaces and tabs
|
|
|
4c79b5 |
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
|
|
|
4c79b5 |
$filename = $this->cache_dir . 'sql_' . md5($query) . '.' . $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($fp = @fopen($filename, 'wb'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@flock($fp, LOCK_EX);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$query_id = sizeof($this->sql_rowset);
|
|
|
4c79b5 |
$this->sql_rowset[$query_id] = array();
|
|
|
4c79b5 |
$this->sql_row_pointer[$query_id] = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($query_result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->sql_rowset[$query_id][] = $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($query_result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$file = "
|
|
|
4c79b5 |
$file .= "\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
fwrite($fp, $file . "\n\$this->sql_rowset[\$query_id] = " . (sizeof($this->sql_rowset[$query_id]) ? "unserialize(" . var_export(serialize($this->sql_rowset[$query_id]), true) . ");" : 'array();') . "\n\n?>");
|
|
|
4c79b5 |
@flock($fp, LOCK_UN);
|
|
|
4c79b5 |
fclose($fp);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!function_exists('phpbb_chmod'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path;
|
|
|
4c79b5 |
include($phpbb_root_path . 'includes/functions.' . $phpEx);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
phpbb_chmod($filename, CHMOD_WRITE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$query_result = $query_id;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Ceck if a given sql query exist in cache
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_exists($query_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return isset($this->sql_rowset[$query_id]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Fetch row from cache (database)
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_fetchrow($query_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Fetch a field from the current row of a cached database result (database)
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_fetchfield($query_id, $field)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
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;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Seek a specific row in an a cached database result (database)
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_rowseek($rownum, $query_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($rownum >= sizeof($this->sql_rowset[$query_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->sql_row_pointer[$query_id] = $rownum;
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Free memory used for a cached database result (database)
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_freeresult($query_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!isset($this->sql_rowset[$query_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
unset($this->sql_rowset[$query_id]);
|
|
|
4c79b5 |
unset($this->sql_row_pointer[$query_id]);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Removes/unlinks file
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function remove_file($filename, $check = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($check && !@is_writable($this->cache_dir))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// E_USER_ERROR - not using language entry - intended.
|
|
|
4c79b5 |
trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return @unlink($filename);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|