diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2008-12-28 13:27:58 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2008-12-28 13:27:58 +0000 |
commit | 889fa871402814874d5d4f01b2f1c829d8206eb9 (patch) | |
tree | ce3d6b9c23a6df118c1458cc7adeafa10ffde5a8 /phpBB/includes | |
parent | fbaf2baa8d683a2afdd3cf98ea1e7c035369f1a3 (diff) | |
download | forums-889fa871402814874d5d4f01b2f1c829d8206eb9.tar forums-889fa871402814874d5d4f01b2f1c829d8206eb9.tar.gz forums-889fa871402814874d5d4f01b2f1c829d8206eb9.tar.bz2 forums-889fa871402814874d5d4f01b2f1c829d8206eb9.tar.xz forums-889fa871402814874d5d4f01b2f1c829d8206eb9.zip |
implement new phpbb::$acm object, replacing $cache global
git-svn-id: file:///svn/phpbb/trunk@9240 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/acm/acm_file.php | 493 | ||||
-rw-r--r-- | phpBB/includes/classes/acl.php | 309 | ||||
-rw-r--r-- | phpBB/includes/classes/template.php | 58 | ||||
-rw-r--r-- | phpBB/includes/classes/template_compile.php | 24 | ||||
-rw-r--r-- | phpBB/includes/classes/user.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_admin.php | 4 | ||||
-rw-r--r-- | phpBB/includes/functions_content.php | 5 | ||||
-rw-r--r-- | phpBB/includes/functions_display.php | 1 | ||||
-rw-r--r-- | phpBB/includes/functions_module.php | 6 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 6 | ||||
-rw-r--r-- | phpBB/includes/functions_user.php | 22 | ||||
-rw-r--r-- | phpBB/includes/search/search.php | 16 |
12 files changed, 358 insertions, 588 deletions
diff --git a/phpBB/includes/acm/acm_file.php b/phpBB/includes/acm/acm_file.php index 23183d1865..e05977d158 100644 --- a/phpBB/includes/acm/acm_file.php +++ b/phpBB/includes/acm/acm_file.php @@ -17,67 +17,155 @@ if (!defined('IN_PHPBB')) } /** -* ACM File Based Caching +* Define file-based cache. * @package acm */ -class acm +class phpbb_acm_file extends phpbb_acm_abstract { - private $vars = array(); - private $var_expires = array(); - private $is_modified = false; - - public $sql_rowset = array(); + /** + * @var string The cache directory to use + */ public $cache_dir = ''; /** - * Set cache path + * @var array|bool The cache types this class supports. True indicates support for all types. + */ + public $supported = true; + + /** + * Set cache directory + * + * @param string $cache_prefix The cache prefix the instance is responsible for + * @access public */ - function __construct() + public function __construct($cache_prefix) { $this->cache_dir = PHPBB_ROOT_PATH . 'cache/'; + $this->cache_prefix = $cache_prefix; } /** - * Load global cache + * {@link phpbb_acm_abstract::get() get()} */ - private function load() + public function get($var_name) { - // grab the global cache - if (file_exists($this->cache_dir . 'data_global.' . PHP_EXT)) + if ($var_name[0] === '#') { - @include($this->cache_dir . 'data_global.' . PHP_EXT); - return true; + $var_name = substr($var_name, 1); + return $this->get_global($var_name); } - return false; + if (!$this->exists($var_name)) + { + return false; + } + + @include($this->cache_dir . $this->cache_prefix . '_' . $var_name . '.' . PHP_EXT); + + // If no data there, then the file expired... + if ($expired) + { + // Destroy + $this->destroy($var_name); + return false; + } + + return $data; } /** - * Unload cache object + * {@link phpbb_acm_abstract::put() put()} */ - public function unload() + public function put($var_name, $data, $ttl = 31536000) + { + if ($var_name[0] === '#') + { + $var_name = substr($var_name, 1); + return $this->put_global($var_name, $data, $ttl); + } + + $filename = $this->cache_dir . $this->cache_prefix . '_' . $var_name . '.' . PHP_EXT; + + if ($fp = @fopen($filename, 'wb')) + { + @flock($fp, LOCK_EX); + fwrite($fp, "<?php\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\$data = " . (sizeof($data) ? "unserialize(" . var_export(serialize($data), true) . ");" : 'array();')); + @flock($fp, LOCK_UN); + fclose($fp); + + if (!function_exists('phpbb_chmod')) + { + include(PHPBB_ROOT_PATH . 'includes/functions.' . PHP_EXT); + } + + phpbb_chmod($filename, phpbb::CHMOD_WRITE); + } + + return $data; + } + + + /** + * {@link phpbb_acm_abstract::exists() exists()} + */ + public function exists($var_name) + { + if ($var_name[0] === '#') + { + $var_name = substr($var_name, 1); + return $this->exists_global($var_name); + } + + return file_exists($this->cache_dir . $this->cache_prefix . '_' . $var_name . '.' . PHP_EXT); + } + + /** + * {@link phpbb_acm_abstract::destroy() destroy()} + */ + public function destroy($var_name) + { + if ($var_name[0] === '#') + { + $var_name = substr($var_name, 1); + $this->destroy_global($var_name); + } + + if (!$this->exists($var_name)) + { + return false; + } + + $this->remove_file($this->cache_dir . $this->cache_prefix . '_' . $var_name . '.' . PHP_EXT, true); + } + + /** + * {@link phpbb_acm_abstract::load() load()} + */ + public function load() { - $this->save(); - unset($this->vars); - unset($this->var_expires); - unset($this->sql_rowset); - - $this->vars = array(); - $this->var_expires = array(); - $this->sql_rowset = array(); + // grab the global cache + if (file_exists($this->cache_dir . $this->cache_prefix . '_global.' . PHP_EXT)) + { + @include($this->cache_dir . $this->cache_prefix . '_global.' . PHP_EXT); + return true; + } + + return false; } /** - * Save modified objects + * {@link phpbb_acm_abstract::unload() unload()} */ - private function save() + public function unload() { if (!$this->is_modified) { return; } - if ($fp = @fopen($this->cache_dir . 'data_global.' . PHP_EXT, 'wb')) + $filename = $this->cache_dir . $this->cache_prefix . '_global.' . PHP_EXT; + + if ($fp = @fopen($filename, 'wb')) { @flock($fp, LOCK_EX); fwrite($fp, "<?php\n\$this->vars = unserialize(" . var_export(serialize($this->vars), true) . ");\n\$this->var_expires = unserialize(" . var_export(serialize($this->var_expires), true) . ");"); @@ -89,7 +177,7 @@ class acm include(PHPBB_ROOT_PATH . 'includes/functions.' . PHP_EXT); } - phpbb_chmod($this->cache_dir . 'data_global.' . PHP_EXT, phpbb::CHMOD_WRITE); + phpbb_chmod($filename, phpbb::CHMOD_WRITE); } else { @@ -99,16 +187,20 @@ class acm trigger_error($this->cache_dir . ' is NOT writable.', E_USER_ERROR); } - trigger_error('Not able to open ' . $this->cache_dir . 'data_global.' . PHP_EXT, E_USER_ERROR); + trigger_error('Not able to open ' . $filename, E_USER_ERROR); } $this->is_modified = false; + + // To reset the global vars + $this->vars = $this->var_expires = array(); } /** - * Tidy cache + * Tidy local cache data. Also see {@link phpbb_acm_abstract::tidy() tidy()} + * @access protected */ - public function tidy() + protected function tidy_local() { $dir = @opendir($this->cache_dir); @@ -119,96 +211,28 @@ class acm while (($entry = readdir($dir)) !== false) { - if (!preg_match('/^(sql_|data_(?!global))/', $entry)) + if (strpos($entry, $this->cache_prefix . '_') !== 0 || strpos($entry, $this->cache_prefix . '_global') === 0) { continue; } $expired = true; @include($this->cache_dir . $entry); + if ($expired) { $this->remove_file($this->cache_dir . $entry); } } closedir($dir); - - if (file_exists($this->cache_dir . 'data_global.' . PHP_EXT)) - { - if (!sizeof($this->vars)) - { - $this->load(); - } - - foreach ($this->var_expires as $var_name => $expires) - { - if (time() > $expires) - { - $this->destroy($var_name); - } - } - } - - set_config('cache_last_gc', time(), true); - } - - /** - * Get saved cache object - */ - public function get($var_name) - { - if ($var_name[0] === '_') - { - if (!$this->_exists($var_name)) - { - return false; - } - - @include($this->cache_dir . "data{$var_name}." . PHP_EXT); - return (isset($data)) ? $data : false; - } - else - { - return ($this->_exists($var_name)) ? $this->vars[$var_name] : false; - } } /** - * Put data into cache + * Purge local cache data. Also see {@link phpbb_acm_abstract::purge() purge()} + * @access protected */ - function put($var_name, $var, $ttl = 31536000) + protected function purge_local() { - if ($var_name[0] === '_') - { - if ($fp = @fopen($this->cache_dir . "data{$var_name}." . PHP_EXT, 'wb')) - { - @flock($fp, LOCK_EX); - fwrite($fp, "<?php\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\$data = " . (sizeof($var) ? "unserialize(" . var_export(serialize($var), true) . ");" : 'array();')); - @flock($fp, LOCK_UN); - fclose($fp); - - if (!function_exists('phpbb_chmod')) - { - include(PHPBB_ROOT_PATH . 'includes/functions.' . PHP_EXT); - } - - phpbb_chmod($this->cache_dir . "data{$var_name}." . PHP_EXT, phpbb::CHMOD_WRITE); - } - } - else - { - $this->vars[$var_name] = $var; - $this->var_expires[$var_name] = time() + $ttl; - $this->is_modified = true; - } - } - - /** - * Purge cache data - */ - public function purge() - { - // Purge all phpbb cache files $dir = @opendir($this->cache_dir); if (!$dir) @@ -218,7 +242,7 @@ class acm while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0) + if (strpos($entry, $this->cache_prefix . '_') !== 0 || strpos($entry, $this->cache_prefix . '_global') === 0) { continue; } @@ -226,240 +250,101 @@ class acm $this->remove_file($this->cache_dir . $entry); } closedir($dir); - - unset($this->vars); - unset($this->var_expires); - unset($this->sql_rowset); - - $this->vars = array(); - $this->var_expires = array(); - $this->sql_rowset = array(); - - $this->is_modified = false; } /** - * Destroy cache data + * Get modified date for cache entry + * + * @param string $var_name The cache variable name + * @access public */ - public function destroy($var_name, $table = '') + public function get_modified_date($var_name) { - 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; - } - - // The following method is more failproof than simply assuming the query is on line 3 (which it should be) - $check_line = @file_get_contents($this->cache_dir . $entry); - - if (empty($check_line)) - { - continue; - } - - // Now get the contents between /* and */ - $check_line = substr($check_line, strpos($check_line, '/* ') + 3, strpos($check_line, ' */') - strpos($check_line, '/* ') - 3); - - $found = false; - foreach ($table as $check_table) - { - // Better catch partial table names than no table names. ;) - if (strpos($check_line, $check_table) !== false) - { - $found = true; - break; - } - } - - if ($found) - { - $this->remove_file($this->cache_dir . $entry); - } - } - closedir($dir); - - return; - } - - if (!$this->_exists($var_name)) - { - return; - } - - if ($var_name[0] === '_') - { - $this->remove_file($this->cache_dir . 'data' . $var_name . '.' . PHP_EXT, 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(); - } + return @filemtime($this->cache_dir . $this->cache_prefix . '_' . $var_name . '.' . PHP_EXT); } /** - * Check if a given cache entry exist + * Removes/unlinks file + * + * @param string $filename The filename to remove + * @param bool $check If true the cache directory is checked for correct directory permissions. + * @access protected */ - private function _exists($var_name) + protected function remove_file($filename, $check = false) { - if ($var_name[0] === '_') + if ($check && !@is_writable($this->cache_dir)) { - return file_exists($this->cache_dir . 'data' . $var_name . '.' . PHP_EXT); + // 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); } - else - { - if (!sizeof($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]); - } + return @unlink($filename); } +} +/** +* Special implementation for cache type 'sql' +* @package acm +*/ +class phpbb_acm_file_sql extends phpbb_acm_file +{ /** - * Load cached sql query + * {@link phpbb_acm_abstract::destroy() destroy()} */ - public function sql_load($query) + public function destroy($var_name) { - // Remove extra spaces and tabs - $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); - $query_id = sizeof($this->sql_rowset); - - if (!file_exists($this->cache_dir . 'sql_' . md5($query) . '.' . PHP_EXT)) + if ($var_name[0] === '#') { - return false; + $var_name = substr($var_name, 1); + $this->destroy_global($var_name); } - @include($this->cache_dir . 'sql_' . md5($query) . '.' . PHP_EXT); + $table = (!is_array($var_name)) ? array($var_name) : $var_name; + $dir = @opendir($this->cache_dir); - if (!isset($expired)) - { - return false; - } - else if ($expired) + if (!$dir) { - $this->remove_file($this->cache_dir . 'sql_' . md5($query) . '.' . PHP_EXT, true); - return false; + return; } - - return $query_id; - } - - /** - * Save sql query - */ - public function sql_save($query, &$query_result, $ttl) - { - global $db; - - // Remove extra spaces and tabs - $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); - $filename = $this->cache_dir . 'sql_' . md5($query) . '.' . PHP_EXT; - - if ($fp = @fopen($filename, 'wb')) + while (($entry = readdir($dir)) !== false) { - @flock($fp, LOCK_EX); - - $query_id = sizeof($this->sql_rowset); - $this->sql_rowset[$query_id] = array(); - - while ($row = $db->sql_fetchrow($query_result)) + if (strpos($entry, $this->cache_prefix . '_') !== 0) { - $this->sql_rowset[$query_id][] = $row; + continue; } - $db->sql_freeresult($query_result); - $file = "<?php\n/* " . str_replace('*/', '*\/', $query) . " */"; - $file .= "\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n"; - - fwrite($fp, $file . "\$this->sql_rowset[\$query_id] = " . (sizeof($this->sql_rowset[$query_id]) ? "unserialize(" . var_export(serialize($this->sql_rowset[$query_id]), true) . ");" : 'array();')); - @flock($fp, LOCK_UN); - fclose($fp); + // The following method is more failproof than simply assuming the query is on line 3 (which it should be) + @include($this->cache_dir . $entry); - if (!function_exists('phpbb_chmod')) + if (empty($data)) { - include(PHPBB_ROOT_PATH . 'includes/functions.' . PHP_EXT); + $this->remove_file($this->cache_dir . $entry); + continue; } - phpbb_chmod($filename, phpbb::CHMOD_WRITE); - - $query_result = $query_id; - } - } - - /** - * Fetch row from cache (database) - */ - public function sql_fetchrow($query_id) - { - list(, $row) = each($this->sql_rowset[$query_id]); - - return ($row !== NULL) ? $row : false; - } - - /** - * Fetch a field from the current row of a cached database result (database) - */ - public function sql_fetchfield($query_id, $field) - { - $row = current($this->sql_rowset[$query_id]); - - return ($row !== false && isset($row[$field])) ? $row[$field] : false; - } - - /** - * Free memory used for a cached database result (database) - */ - public function sql_freeresult($query_id) - { - if (!isset($this->sql_rowset[$query_id])) - { - return false; - } + // Get the query + $data = $data['query']; - unset($this->sql_rowset[$query_id]); - - return true; - } + $found = false; + foreach ($table as $check_table) + { + // Better catch partial table names than no table names. ;) + if (strpos($data, $check_table) !== false) + { + $found = true; + break; + } + } - /** - * Removes/unlinks file - */ - private function remove_file($filename, $check = false) - { - if ($check && !@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); + if ($found) + { + $this->remove_file($this->cache_dir . $entry); + } } + closedir($dir); - return @unlink($filename); + return; } } diff --git a/phpBB/includes/classes/acl.php b/phpBB/includes/classes/acl.php index 226bb8be23..97a7b02d41 100644 --- a/phpBB/includes/classes/acl.php +++ b/phpBB/includes/classes/acl.php @@ -17,36 +17,38 @@ if (!defined('IN_PHPBB')) } /** -* Permission/Auth class +* Permission/ACL class * @package phpBB3 */ -class auth +class phpbb_acl { + public $phpbb_required = array('acm', 'db'); + public $phpbb_optional = array(); + + public $acl_raw; + private $acl = array(); private $cache = array(); public $acl_options = array(); - private $acl_forum_ids = false; + private $acl_element_ids = false; + private $recache = false; - /** - * Init permissions - */ - function acl(array &$userdata) + public function __construct() { - global $db, $cache; - $this->acl = $this->cache = $this->acl_options = array(); - $this->acl_forum_ids = false; + $this->acl_element_ids = false; - if (($this->acl_options = $cache->get('_acl_options')) === false) + if (($this->acl_options = phpbb::$acm->get('acl_options')) === false) { $sql = 'SELECT auth_option_id, auth_option, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . ' ORDER BY auth_option_id'; - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); $global = $local = 0; $this->acl_options = array(); - while ($row = $db->sql_fetchrow($result)) + + while ($row = phpbb::$db->sql_fetchrow($result)) { if ($row['is_global']) { @@ -61,12 +63,22 @@ class auth $this->acl_options['id'][$row['auth_option']] = (int) $row['auth_option_id']; $this->acl_options['option'][(int) $row['auth_option_id']] = $row['auth_option']; } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); - $cache->put('_acl_options', $this->acl_options); - $this->acl_cache($userdata); + phpbb::$acm->put('acl_options', $this->acl_options); + $this->recache = true; } - else if (!trim($userdata['user_permissions'])) + + // Add raw data acl class + $this->acl_raw = new phpbb_acl_raw_data(); + } + + /** + * Init permissions + */ + public function init(array &$userdata) + { + if (!trim($userdata['user_permissions']) || $this->recache) { $this->acl_cache($userdata); } @@ -150,7 +162,6 @@ class auth $opt = substr($opt, 1); } - // @todo: use the ref technique to reduce opcode generation if (!isset($this->cache[$f][$opt])) { // We combine the global/local option with an OR because some options are global and local. @@ -203,23 +214,21 @@ class auth { if ($this->acl_forum_ids === false) { - global $db; - $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE; if (sizeof($this->acl)) { - $sql .= ' WHERE ' . $db->sql_in_set('forum_id', array_keys($this->acl), true); + $sql .= ' WHERE ' . phpbb::$db->sql_in_set('forum_id', array_keys($this->acl), true); } - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); $this->acl_forum_ids = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { $this->acl_forum_ids[] = $row['forum_id']; } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); } } @@ -342,11 +351,11 @@ class auth { if ($user_id !== false && !is_array($user_id) && $opts === false && $forum_id === false) { - $hold_ary = array($user_id => $this->acl_raw_data_single_user($user_id)); + $hold_ary = array($user_id => $this->acl_raw->single_user($user_id)); } else { - $hold_ary = $this->acl_raw_data($user_id, $opts, $forum_id); + $hold_ary = $this->acl_raw->data($user_id, $opts, $forum_id); } $auth_ary = array(); @@ -372,17 +381,15 @@ class auth */ public function acl_cache(array &$userdata) { - global $db; - // Empty user_permissions $userdata['user_permissions'] = ''; - $hold_ary = $this->acl_raw_data_single_user($userdata['user_id']); + $hold_ary = $this->acl_raw->single_user($userdata['user_id']); // Key 0 in $hold_ary are global options, all others are forum_ids // If this user is founder we're going to force fill the admin options ... - if ($userdata['user_type'] == phpbb::USER_FOUNDER) + if ($userdata['user_type'] == USER_FOUNDER) { foreach ($this->acl_options['global'] as $opt => $id) { @@ -400,10 +407,10 @@ class auth $userdata['user_permissions'] = $hold_str; $sql = 'UPDATE ' . USERS_TABLE . " - SET user_permissions = '" . $db->sql_escape($userdata['user_permissions']) . "', + SET user_permissions = '" . phpbb::$db->sql_escape($userdata['user_permissions']) . "', user_perm_from = 0 WHERE user_id = " . $userdata['user_id']; - $db->sql_query($sql); + phpbb::$db->sql_query($sql); } return; @@ -475,29 +482,27 @@ class auth */ public function acl_clear_prefetch($user_id = false) { - global $db, $cache; - // Rebuild options cache - $cache->destroy('_role_cache'); + phpbb::$acm->destroy('role_cache'); $sql = 'SELECT * FROM ' . ACL_ROLES_DATA_TABLE . ' ORDER BY role_id ASC'; - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); $this->role_cache = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting']; } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); foreach ($this->role_cache as $role_id => $role_options) { $this->role_cache[$role_id] = serialize($role_options); } - $cache->put('_role_cache', $this->role_cache); + phpbb::$acm->put('role_cache', $this->role_cache); // Now empty user permissions $where_sql = ''; @@ -505,62 +510,72 @@ class auth if ($user_id !== false) { $user_id = (!is_array($user_id)) ? $user_id = array((int) $user_id) : array_map('intval', $user_id); - $where_sql = ' WHERE ' . $db->sql_in_set('user_id', $user_id); + $where_sql = ' WHERE ' . phpbb::$db->sql_in_set('user_id', $user_id); } $sql = 'UPDATE ' . USERS_TABLE . " SET user_permissions = '', user_perm_from = 0 $where_sql"; - $db->sql_query($sql); + phpbb::$db->sql_query($sql); return; } +/** +} + + * Role-specific methods/definitionis used by phpbb_acl +class phpbb_acl_role +{ + */ + /** * Get assigned roles * @todo: protected or public? */ public function acl_role_data($user_type, $role_type, $ug_id = false, $forum_id = false) { - global $db; - $roles = array(); $sql_id = ($user_type == 'user') ? 'user_id' : 'group_id'; - $sql_ug = ($ug_id !== false) ? ((!is_array($ug_id)) ? "AND a.$sql_id = $ug_id" : 'AND ' . $db->sql_in_set("a.$sql_id", $ug_id)) : ''; - $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? "AND a.forum_id = $forum_id" : 'AND ' . $db->sql_in_set('a.forum_id', $forum_id)) : ''; + $sql_ug = ($ug_id !== false) ? ((!is_array($ug_id)) ? "AND a.$sql_id = $ug_id" : 'AND ' . phpbb::$db->sql_in_set("a.$sql_id", $ug_id)) : ''; + $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? "AND a.forum_id = $forum_id" : 'AND ' . phpbb::$db->sql_in_set('a.forum_id', $forum_id)) : ''; // Grab assigned roles... $sql = 'SELECT a.auth_role_id, a.' . $sql_id . ', a.forum_id FROM ' . (($user_type == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE) . ' a, ' . ACL_ROLES_TABLE . " r WHERE a.auth_role_id = r.role_id - AND r.role_type = '" . $db->sql_escape($role_type) . "' + AND r.role_type = '" . phpbb::$db->sql_escape($role_type) . "' $sql_ug $sql_forum ORDER BY r.role_order ASC"; - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { $roles[$row[$sql_id]][$row['forum_id']] = $row['auth_role_id']; } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); return $roles; } +} +/** +* data-specific methods/definitionis used by phpbb_acl +*/ +class phpbb_acl_raw_data +{ /** * Get raw acl data based on user/option/forum * @todo: protected or public? */ - public function acl_raw_data($user_id = false, $opts = false, $forum_id = false) + public function data($user_id = false, $opts = false, $forum_id = false) { - global $db; - - $sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : $db->sql_in_set('user_id', array_map('intval', $user_id))) : ''; - $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : ''; + $sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : phpbb::$db->sql_in_set('user_id', array_map('intval', $user_id))) : ''; + $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . phpbb::$db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : ''; $sql_opts = $sql_opts_select = $sql_opts_from = ''; $hold_ary = array(); @@ -594,14 +609,14 @@ class auth foreach ($sql_ary as $sql) { - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { $option = ($sql_opts_select) ? $row['auth_option'] : $this->acl_options['option'][$row['auth_option_id']]; $hold_ary[$row['user_id']][$row['forum_id']][$option] = $row['auth_setting']; } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); } $sql_ary = array(); @@ -630,9 +645,9 @@ class auth foreach ($sql_ary as $sql) { - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { $option = ($sql_opts_select) ? $row['auth_option'] : $this->acl_options['option'][$row['auth_option_id']]; @@ -641,7 +656,7 @@ class auth { $hold_ary[$row['user_id']][$row['forum_id']][$option] = $row['auth_setting']; - // If we detect ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again) + // If we detect phpbb::ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again) if ($row['auth_setting'] == phpbb::ACL_NEVER) { $flag = substr($option, 0, strpos($option, '_') + 1); @@ -659,7 +674,7 @@ class auth } } } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); } return $hold_ary; @@ -668,12 +683,10 @@ class auth /** * Get raw user based permission settings */ - public function acl_user_raw_data($user_id = false, $opts = false, $forum_id = false) + public function user($user_id = false, $opts = false, $forum_id = false) { - global $db; - - $sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : $db->sql_in_set('user_id', array_map('intval', $user_id))) : ''; - $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : ''; + $sql_user = ($user_id !== false) ? ((!is_array($user_id)) ? 'user_id = ' . (int) $user_id : phpbb::$db->sql_in_set('user_id', array_map('intval', $user_id))) : ''; + $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . phpbb::$db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : ''; $sql_opts = ''; $hold_ary = $sql_ary = array(); @@ -705,13 +718,13 @@ class auth foreach ($sql_ary as $sql) { - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { $hold_ary[$row['user_id']][$row['forum_id']][$row['auth_option']] = $row['auth_setting']; } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); } return $hold_ary; @@ -720,12 +733,10 @@ class auth /** * Get raw group based permission settings */ - public function acl_group_raw_data($group_id = false, $opts = false, $forum_id = false) + public function group($group_id = false, $opts = false, $forum_id = false) { - global $db; - - $sql_group = ($group_id !== false) ? ((!is_array($group_id)) ? 'group_id = ' . (int) $group_id : $db->sql_in_set('group_id', array_map('intval', $group_id))) : ''; - $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . $db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : ''; + $sql_group = ($group_id !== false) ? ((!is_array($group_id)) ? 'group_id = ' . (int) $group_id : phpbb::$db->sql_in_set('group_id', array_map('intval', $group_id))) : ''; + $sql_forum = ($forum_id !== false) ? ((!is_array($forum_id)) ? 'AND a.forum_id = ' . (int) $forum_id : 'AND ' . phpbb::$db->sql_in_set('a.forum_id', array_map('intval', $forum_id))) : ''; $sql_opts = ''; $hold_ary = $sql_ary = array(); @@ -757,13 +768,13 @@ class auth foreach ($sql_ary as $sql) { - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { $hold_ary[$row['group_id']][$row['forum_id']][$row['auth_option']] = $row['auth_setting']; } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); } return $hold_ary; @@ -771,14 +782,12 @@ class auth /** * Get raw acl data based on user for caching user_permissions - * This function returns the same data as acl_raw_data(), but without the user id as the first key within the array. + * This function returns the same data as data(), but without the user id as the first key within the array. */ - public function acl_raw_data_single_user($user_id) + public function single_user($user_id) { - global $db, $cache; - // Check if the role-cache is there - if (($this->role_cache = $cache->get('_role_cache')) === false) + if (($this->role_cache = phpbb::$acm->get('role_cache')) === false) { $this->role_cache = array(); @@ -786,20 +795,20 @@ class auth $sql = 'SELECT * FROM ' . ACL_ROLES_DATA_TABLE . ' ORDER BY role_id ASC'; - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { $this->role_cache[$row['role_id']][$row['auth_option_id']] = (int) $row['auth_setting']; } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); foreach ($this->role_cache as $role_id => $role_options) { $this->role_cache[$role_id] = serialize($role_options); } - $cache->put('_role_cache', $this->role_cache); + phpbb::$acm->put('role_cache', $this->role_cache); } $hold_ary = array(); @@ -808,9 +817,9 @@ class auth $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting FROM ' . ACL_USERS_TABLE . ' WHERE user_id = ' . $user_id; - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { // If a role is assigned, assign all options included within this role. Else, only set this one option. if ($row['auth_role_id']) @@ -822,7 +831,7 @@ class auth $hold_ary[$row['forum_id']][$row['auth_option_id']] = $row['auth_setting']; } } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); // Now grab group-specific permission settings $sql = 'SELECT a.forum_id, a.auth_option_id, a.auth_role_id, a.auth_setting @@ -830,9 +839,9 @@ class auth WHERE a.group_id = ug.group_id AND ug.user_pending = 0 AND ug.user_id = ' . $user_id; - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { if (!$row['auth_role_id']) { @@ -846,7 +855,7 @@ class auth } } } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); return $hold_ary; } @@ -860,7 +869,7 @@ class auth { $hold_ary[$option_id] = $setting; - // If we detect ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again) + // If we detect phpbb::ACL_NEVER, we will unset the flag option (within building the bitstring it is correctly set again) if ($setting == phpbb::ACL_NEVER) { $flag = substr($this->acl_options['option'][$option_id], 0, strpos($this->acl_options['option'][$option_id], '_') + 1); @@ -881,123 +890,19 @@ class auth } /** - * Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him. - */ - public function login($username, $password, $autologin = false, $viewonline = 1, $admin = 0) - { - global $config, $db, $user; - - $method = trim(basename($config['auth_method'])); - include_once(PHPBB_ROOT_PATH . 'includes/auth/auth_' . $method . '.' . PHP_EXT); - - $method = 'login_' . $method; - if (function_exists($method)) - { - $login = $method($username, $password); - - // If the auth module wants us to create an empty profile do so and then treat the status as LOGIN_SUCCESS - if ($login['status'] == LOGIN_SUCCESS_CREATE_PROFILE) - { - // we are going to use the user_add function so include functions_user.php if it wasn't defined yet - if (!function_exists('user_add')) - { - include(PHPBB_ROOT_PATH . 'includes/functions_user.' . PHP_EXT); - } - - user_add($login['user_row'], (isset($login['cp_data'])) ? $login['cp_data'] : false); - - $sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type - FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) - { - return array( - 'status' => LOGIN_ERROR_EXTERNAL_AUTH, - 'error_msg' => 'AUTH_NO_PROFILE_CREATED', - 'user_row' => array('user_id' => ANONYMOUS), - ); - } - - $login = array( - 'status' => LOGIN_SUCCESS, - 'error_msg' => false, - 'user_row' => $row, - ); - } - - // If login succeeded, we will log the user in... else we pass the login array through... - if ($login['status'] == LOGIN_SUCCESS) - { - $old_session_id = $user->session_id; - - if ($admin) - { - global $SID, $_SID; - - $cookie_expire = time() - 31536000; - $user->set_cookie('u', '', $cookie_expire); - $user->set_cookie('sid', '', $cookie_expire); - unset($cookie_expire); - - $SID = '?sid='; - $user->session_id = $_SID = ''; - } - - $result = $user->session_create($login['user_row']['user_id'], $admin, $autologin, $viewonline); - - // Successful session creation - if ($result === true) - { - // If admin re-authentication we remove the old session entry because a new one has been created... - if ($admin) - { - // the login array is used because the user ids do not differ for re-authentication - $sql = 'DELETE FROM ' . SESSIONS_TABLE . " - WHERE session_id = '" . $db->sql_escape($old_session_id) . "' - AND session_user_id = {$login['user_row']['user_id']}"; - $db->sql_query($sql); - } - - return array( - 'status' => LOGIN_SUCCESS, - 'error_msg' => false, - 'user_row' => $login['user_row'], - ); - } - - return array( - 'status' => LOGIN_BREAK, - 'error_msg' => $result, - 'user_row' => $login['user_row'], - ); - } - - return $login; - } - - trigger_error('Authentication method not found', E_USER_ERROR); - } - - /** * Fill auth_option statement for later querying based on the supplied options */ private function build_auth_option_statement($key, $auth_options, &$sql_opts) { - global $db; - if (!is_array($auth_options)) { if (strpos($auth_options, '%') !== false) { - $sql_opts = "AND $key " . $db->sql_like_expression(str_replace('%', $db->any_char, $auth_options)); + $sql_opts = "AND $key " . phpbb::$db->sql_like_expression(str_replace('%', phpbb::$db->any_char, $auth_options)); } else { - $sql_opts = "AND $key = '" . $db->sql_escape($auth_options) . "'"; + $sql_opts = "AND $key = '" . phpbb::$db->sql_escape($auth_options) . "'"; } } else @@ -1014,7 +919,7 @@ class auth if (!$is_like_expression) { - $sql_opts = 'AND ' . $db->sql_in_set($key, $auth_options); + $sql_opts = 'AND ' . phpbb::$db->sql_in_set($key, $auth_options); } else { @@ -1024,11 +929,11 @@ class auth { if (strpos($option, '%') !== false) { - $sql[] = $key . ' ' . $db->sql_like_expression(str_replace('%', $db->any_char, $option)); + $sql[] = $key . ' ' . phpbb::$db->sql_like_expression(str_replace('%', phpbb::$db->any_char, $option)); } else { - $sql[] = $key . " = '" . $db->sql_escape($option) . "'"; + $sql[] = $key . " = '" . phpbb::$db->sql_escape($option) . "'"; } } diff --git a/phpBB/includes/classes/template.php b/phpBB/includes/classes/template.php index a49fd75eb3..167f33f3e8 100644 --- a/phpBB/includes/classes/template.php +++ b/phpBB/includes/classes/template.php @@ -20,9 +20,12 @@ if (!defined('IN_PHPBB')) * Base Template class. * @package phpBB3 */ -class template +class phpbb_template { - /** + public $phpbb_required = array('user', 'config'); + public $phpbb_optional = array(); + + /** * variable that holds all the data we'll be substituting into * the compiled templates. Takes form: * --> $this->_tpldata[block][iteration#][child][iteration#][child2][iteration#][variablename] == value @@ -63,16 +66,14 @@ class template */ public function set_template() { - global $user; - - if (file_exists(PHPBB_ROOT_PATH . 'styles/' . $user->theme['template_path'] . '/template')) + if (file_exists(PHPBB_ROOT_PATH . 'styles/' . phpbb::$user->theme['template_path'] . '/template')) { - $this->root = PHPBB_ROOT_PATH . 'styles/' . $user->theme['template_path'] . '/template'; - $this->cachepath = PHPBB_ROOT_PATH . 'cache/tpl_' . $user->theme['template_path'] . '_'; + $this->root = PHPBB_ROOT_PATH . 'styles/' . phpbb::$user->theme['template_path'] . '/template'; + $this->cachepath = PHPBB_ROOT_PATH . 'cache/tpl_' . phpbb::$user->theme['template_path'] . '_'; } else { - trigger_error('Template path could not be found: styles/' . $user->theme['template_path'] . '/template', E_USER_ERROR); + trigger_error('Template path could not be found: styles/' . phpbb::$user->theme['template_path'] . '/template', E_USER_ERROR); } $this->_rootref = &$this->_tpldata['.'][0]; @@ -158,8 +159,7 @@ class template */ public function display($handle, $include_once = true) { - global $user, $phpbb_hook; - +/* if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, __FUNCTION__), $handle, $include_once)) { if ($phpbb_hook->hook_return(array(__CLASS__, __FUNCTION__))) @@ -167,7 +167,7 @@ class template return $phpbb_hook->hook_return_result(array(__CLASS__, __FUNCTION__)); } } - +*/ /* if (defined('IN_ERROR_HANDLER')) { if ((E_NOTICE & error_reporting()) == E_NOTICE) @@ -178,7 +178,7 @@ class template $_tpldata = &$this->_tpldata; $_rootref = &$this->_rootref; - $_lang = &$user->lang; + $_lang = &phpbb::$user->lang; // These _are_ used the included files. $_tpldata; $_rootref; $_lang; @@ -235,21 +235,19 @@ class template */ private function _tpl_load($handle) { - global $config; - $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . PHP_EXT; - $recompile = (!file_exists($filename) || @filesize($filename) === 0 || ($config['load_tplcompile'] && @filemtime($filename) < filemtime($this->files[$handle]))) ? true : false; + $recompile = (!file_exists($filename) || @filesize($filename) === 0 || (phpbb::$config['load_tplcompile'] && @filemtime($filename) < filemtime($this->files[$handle]))) ? true : false; + + if (defined('DEBUG_EXTRA')) + { + $recompile = true; + } // Recompile page if the original template is newer, otherwise load the compiled version if ($recompile) { - if (!class_exists('template_compile')) - { - include(PHPBB_ROOT_PATH . 'includes/functions_template.' . PHP_EXT); - } - - $compile = new template_compile($this); + $compile = new phpbb_template_compile($this); // If we don't have a file assigned to this handle, die. if (!isset($this->files[$handle])) @@ -275,12 +273,7 @@ class template */ private function _tpl_eval($handle) { - if (!class_exists('template_compile')) - { - include(PHPBB_ROOT_PATH . 'includes/functions_template.' . PHP_EXT); - } - - $compile = new template_compile($this); + $compile = new phpbb_template_compile($this); // If we don't have a file assigned to this handle, die. if (!isset($this->files[$handle])) @@ -500,11 +493,9 @@ class template if ($include) { - global $user; - $_tpldata = &$this->_tpldata; $_rootref = &$this->_rootref; - $_lang = &$user->lang; + $_lang = &phpbb::$user->lang; // These _are_ used the included files. $_tpldata; $_rootref; $_lang; @@ -516,12 +507,7 @@ class template } else { - if (!class_exists('template_compile')) - { - include(PHPBB_ROOT_PATH . 'includes/functions_template.' . PHP_EXT); - } - - $compile = new template_compile($this); + $compile = new phpbb_template_compile($this); if (($code = $compile->_tpl_gen_src($handle)) !== false) { diff --git a/phpBB/includes/classes/template_compile.php b/phpBB/includes/classes/template_compile.php index 0ad6021e44..b8fc662208 100644 --- a/phpBB/includes/classes/template_compile.php +++ b/phpBB/includes/classes/template_compile.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) * @package phpBB3 * */ -class template_filter extends php_user_filter +class phpbb_template_filter extends php_user_filter { /** * @var string Replaceable tokens regex @@ -93,8 +93,6 @@ class template_filter extends php_user_filter private function replace($matches) { - global $config; - if (isset($matches[3])) { return $this->compile_var_tags($matches[0]); @@ -146,15 +144,15 @@ class template_filter extends php_user_filter break; case 'INCLUDEPHP': - return ($config['tpl_allow_php']) ? '<?php ' . $this->compile_tag_include_php($matches[2]) . ' ?>' : ''; + return (phpbb::$config['tpl_allow_php']) ? '<?php ' . $this->compile_tag_include_php($matches[2]) . ' ?>' : ''; break; case 'PHP': - return ($config['tpl_allow_php']) ? '<?php ' : '<!-- '; + return (phpbb::$config['tpl_allow_php']) ? '<?php ' : '<!-- '; break; case 'ENDPHP': - return ($config['tpl_allow_php']) ? ' ?>' : ' -->'; + return (phpbb::$config['tpl_allow_php']) ? ' ?>' : ' -->'; break; default: @@ -437,7 +435,7 @@ class template_filter extends php_user_filter $namespace = substr($varrefs[1], 0, -1); $namespace = (strpos($namespace, '.') === false) ? $namespace : strrchr($namespace, '.'); - // S_ROW_COUNT is deceptive, it returns the current row number not the number of rows + // S_ROW_COUNT is deceptive, it returns the current row number now the number of rows // hence S_ROW_COUNT is deprecated in favour of S_ROW_NUM switch ($varrefs[3]) { @@ -643,7 +641,7 @@ class template_filter extends php_user_filter $expr = true; - // S_ROW_COUNT is deceptive, it returns the current row number not the number of rows + // S_ROW_COUNT is deceptive, it returns the current row number now the number of rows // hence S_ROW_COUNT is deprecated in favour of S_ROW_NUM switch ($varname) { @@ -731,7 +729,7 @@ class template_filter extends php_user_filter } } -stream_filter_register('template', 'template_filter'); +stream_filter_register('phpbb_template', 'phpbb_template_filter'); /** * Extension of template class - Functions needed for compiling templates only. @@ -753,7 +751,7 @@ stream_filter_register('template', 'template_filter'); * @package phpBB3 * @uses template_filter As a PHP stream filter to perform compilation of templates */ -class template_compile +class phpbb_template_compile { /** * @var template Reference to the {@link template template} object performing compilation @@ -764,7 +762,7 @@ class template_compile * Constructor * @param template $template {@link template Template} object performing compilation */ - function __construct(template $template) + function __construct(phpbb_template $template) { $this->template = $template; } @@ -826,7 +824,7 @@ class template_compile @flock($destination_handle, LOCK_EX); - stream_filter_append($source_handle, 'template'); + stream_filter_append($source_handle, 'phpbb_template'); stream_copy_to_stream($source_handle, $destination_handle); @fclose($source_handle); @@ -856,7 +854,7 @@ class template_compile return false; } - stream_filter_append($source_handle, 'template'); + stream_filter_append($source_handle, 'phpbb_template'); stream_copy_to_stream($source_handle, $destination_handle); @fclose($source_handle); diff --git a/phpBB/includes/classes/user.php b/phpBB/includes/classes/user.php index 85a2ee012f..d86eb3d886 100644 --- a/phpBB/includes/classes/user.php +++ b/phpBB/includes/classes/user.php @@ -412,7 +412,7 @@ class phpbb_user extends phpbb_session { phpbb::$db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); phpbb::$db->sql_transaction('commit'); - phpbb::$acm->destroy('sql', STYLES_IMAGESET_DATA_TABLE); + phpbb::$acm->destroy_sql(STYLES_IMAGESET_DATA_TABLE); add_log('admin', 'LOG_IMAGESET_LANG_REFRESHED', $this->theme['imageset_name'], $this->img_lang); } diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 89c6a21468..f9fde6fcd0 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2118,10 +2118,10 @@ function remove_comments(&$output) */ function cache_moderators() { - global $db, $cache, $auth; + global $db, $auth; // Remove cached sql results - $cache->destroy('sql', MODERATOR_CACHE_TABLE); + phpbb::$acm->destroy_sql(MODERATOR_CACHE_TABLE); // Clear table if ($db->truncate) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index e497a61920..7f8ee5d4c0 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -673,7 +673,7 @@ function censor_text($text) // We moved the word censor checks in here because we call this function quite often - and then only need to do the check once if (!isset($censors) || !is_array($censors)) { - global $config, $user, $auth, $cache; + global $config, $user, $auth; // We check here if the user is having viewing censors disabled (and also allowed to do so). if (!$user->optionget('viewcensors') && $config['allow_nocensors'] && $auth->acl_get('u_chgcensors')) @@ -738,7 +738,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count, return; } - global $template, $cache, $user; + global $template, $user; global $extensions, $config; // @@ -1068,7 +1068,6 @@ function extension_allowed($forum_id, $extension, &$extensions) { if (empty($extensions)) { - global $cache; $extensions = phpbb_cache::obtain_extensions_forum($forum_id); } diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 0936279fde..18788f1204 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1155,7 +1155,6 @@ function get_user_rank($user_id, $user_rank, $user_posts, &$rank_title, &$rank_i if (empty($ranks)) { - global $cache; $ranks = phpbb_cache::obtain_ranks(); } diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 2899848009..6a7301c798 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -78,13 +78,13 @@ class p_master */ function list_modules($p_class) { - global $auth, $db, $user, $cache, $config; + global $auth, $db, $user, $config; // Sanitise for future path use, it's escaped as appropriate for queries $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); // Get cached modules - if (($this->module_cache = $cache->get('_modules_' . $this->p_class)) === false) + if (($this->module_cache = phpbb::$acm->get('modules_' . $this->p_class)) === false) { // Get modules $sql = 'SELECT * @@ -108,7 +108,7 @@ class p_master } unset($rows); - $cache->put('_modules_' . $this->p_class, $this->module_cache); + phpbb::$acm->put('modules_' . $this->p_class, $this->module_cache); } if (empty($this->module_cache)) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 40d075a52c..e30e088132 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -245,7 +245,7 @@ function update_post_information($type, $ids, $return_update_sql = false) */ function posting_gen_topic_icons($mode, $icon_id) { - global $config, $template, $cache; + global $config, $template; // Grab icons $icons = phpbb_cache::obtain_icons(); @@ -347,7 +347,7 @@ function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL) */ function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false) { - global $auth, $user, $config, $db, $cache; + global $auth, $user, $config, $db; $filedata = array( 'error' => array() @@ -932,7 +932,7 @@ function load_drafts($topic_id = 0, $forum_id = 0, $id = 0) */ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id = 0, $show_quote_button = true) { - global $user, $auth, $db, $template, $bbcode, $cache, $config; + global $user, $auth, $db, $template, $bbcode, $config; // Go ahead and pull all data for this topic $sql = 'SELECT p.post_id diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index c9eafc3d90..f6223b93aa 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -113,7 +113,7 @@ function update_last_username() */ function user_update_name($old_name, $new_name) { - global $config, $db, $cache; + global $config, $db; $update_ary = array( FORUMS_TABLE => array('forum_last_poster_name'), @@ -139,7 +139,7 @@ function user_update_name($old_name, $new_name) } // Because some tables/caches use username-specific data we need to purge this here. - $cache->destroy('sql', MODERATOR_CACHE_TABLE); + phpbb::$acm->destroy_sql(MODERATOR_CACHE_TABLE); } /** @@ -300,7 +300,7 @@ function user_add($user_row, $cp_data = false) */ function user_delete($mode, $user_id, $post_username = false) { - global $cache, $config, $db, $user, $auth; + global $config, $db, $user, $auth; $sql = 'SELECT * FROM ' . USERS_TABLE . ' @@ -498,7 +498,7 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_query($sql); } - $cache->destroy('sql', MODERATOR_CACHE_TABLE); + phpbb::$acm->destroy_sql(MODERATOR_CACHE_TABLE); // Remove any undelivered mails... $sql = 'SELECT msg_id, user_id @@ -674,7 +674,7 @@ function user_active_flip($mode, $user_id_ary, $reason = INACTIVE_MANUAL) */ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason = '') { - global $db, $user, $auth, $cache; + global $db, $user, $auth; // Delete stale bans $sql = 'DELETE FROM ' . BANLIST_TABLE . ' @@ -1053,13 +1053,13 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas add_log('admin', $log_entry . strtoupper($mode), $ban_reason, $ban_list_log); add_log('mod', 0, 0, $log_entry . strtoupper($mode), $ban_reason, $ban_list_log); - $cache->destroy('sql', BANLIST_TABLE); + phpbb::$acm->destroy_sql(BANLIST_TABLE); return true; } // There was nothing to ban/exclude. But destroying the cache because of the removal of stale bans. - $cache->destroy('sql', BANLIST_TABLE); + phpbb::$acm->destroy_sql(BANLIST_TABLE); return false; } @@ -1069,7 +1069,7 @@ function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reas */ function user_unban($mode, $ban) { - global $db, $user, $auth, $cache; + global $db, $user, $auth; // Delete stale bans $sql = 'DELETE FROM ' . BANLIST_TABLE . ' @@ -1126,7 +1126,7 @@ function user_unban($mode, $ban) add_log('mod', 0, 0, 'LOG_UNBAN_' . strtoupper($mode), $l_unban_list); } - $cache->destroy('sql', BANLIST_TABLE); + phpbb::$acm->destroy_sql(BANLIST_TABLE); return false; } @@ -1344,7 +1344,7 @@ function validate_match($string, $optional = false, $match = '') */ function validate_username($username, $allowed_username = false) { - global $config, $db, $user, $cache; + global $config, $db, $user; $clean_username = utf8_clean_string($username); $allowed_username = ($allowed_username === false) ? $user->data['username_clean'] : utf8_clean_string($allowed_username); @@ -1947,7 +1947,7 @@ function get_avatar_filename($avatar_entry) */ function avatar_gallery($category, $avatar_select, $items_per_column, $block_var = 'avatar_row') { - global $user, $cache, $template, $config; + global $user, $template, $config; $avatar_list = array(); diff --git a/phpBB/includes/search/search.php b/phpBB/includes/search/search.php index a6986dfa2a..f3a5cc363f 100644 --- a/phpBB/includes/search/search.php +++ b/phpBB/includes/search/search.php @@ -94,9 +94,7 @@ class search_backend */ protected function obtain_ids($search_key, &$result_count, &$id_ary, $start, $per_page, $sort_dir) { - global $cache; - - if (!($stored_ids = $cache->get('_search_results_' . $search_key))) + if (!($stored_ids = phpbb::$acm->get('search_results_' . $search_key))) { // no search results cached for this search_key return self::SEARCH_RESULT_NOT_IN_CACHE; @@ -154,7 +152,7 @@ class search_backend */ protected function save_ids($search_key, $keywords, $author_ary, $result_count, &$id_ary, $start, $sort_dir) { - global $cache, $config, $db, $user; + global $config, $db, $user; $length = min(sizeof($id_ary), $config['search_block_size']); @@ -168,7 +166,7 @@ class search_backend // create a new resultset if there is none for this search_key yet // or add the ids to the existing resultset - if (!($store = $cache->get('_search_results_' . $search_key))) + if (!($store = phpbb::$acm->get('search_results_' . $search_key))) { // add the current keywords to the recent searches in the cache which are listed on the search page if (!empty($keywords) || sizeof($author_ary)) @@ -245,7 +243,7 @@ class search_backend } } } - $cache->put('_search_results_' . $search_key, $store, $config['search_store_results']); + phpbb::$acm->put('search_results_' . $search_key, $store, $config['search_store_results']); $sql = 'UPDATE ' . SEARCH_RESULTS_TABLE . ' SET search_time = ' . time() . ' @@ -263,7 +261,7 @@ class search_backend */ public function destroy_cache($words, $authors = false) { - global $db, $cache, $config; + global $db, $config; // clear all searches that searched for the specified words if (sizeof($words)) @@ -281,7 +279,7 @@ class search_backend while ($row = $db->sql_fetchrow($result)) { - $cache->destroy('_search_results_' . $row['search_key']); + phpbb::$acm->destroy('search_results_' . $row['search_key']); } $db->sql_freeresult($result); } @@ -302,7 +300,7 @@ class search_backend while ($row = $db->sql_fetchrow($result)) { - $cache->destroy('_search_results_' . $row['search_key']); + phpbb::$acm->destroy('search_results_' . $row['search_key']); } $db->sql_freeresult($result); } |