1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-13 12:35:06 +01:00

Re-jiggle where acl_option caching is done, move to common in-keeping with config

git-svn-id: file:///svn/phpbb/trunk@3341 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-01-21 14:33:07 +00:00
parent 8c31649706
commit 5bea3ea3b4
2 changed files with 48 additions and 125 deletions

View File

@ -19,7 +19,7 @@
*
***************************************************************************/
if ( !defined('IN_PHPBB') )
if (!defined('IN_PHPBB'))
{
die('Hacking attempt');
}
@ -29,7 +29,7 @@ error_reporting(E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitia
set_magic_quotes_runtime(0);
// If magic quotes is off, addslashes
if ( !get_magic_quotes_gpc() )
if (!get_magic_quotes_gpc())
{
$_GET = slash_input_data($_GET);
$_POST = slash_input_data($_POST);
@ -37,9 +37,8 @@ if ( !get_magic_quotes_gpc() )
}
require($phpbb_root_path . 'config.'.$phpEx);
//require($phpbb_root_path . 'config_cache.'.$phpEx);
if ( !defined('PHPBB_INSTALLED') )
if (!defined('PHPBB_INSTALLED'))
{
header('Location: install/install.'.$phpEx);
exit;
@ -47,10 +46,10 @@ if ( !defined('PHPBB_INSTALLED') )
// Include files
require($phpbb_root_path . 'includes/acm/cache_' . $acm_type . '.'.$phpEx);
require($phpbb_root_path . 'db/' . $dbms . '.'.$phpEx);
require($phpbb_root_path . 'includes/template.'.$phpEx);
require($phpbb_root_path . 'includes/session.'.$phpEx);
require($phpbb_root_path . 'includes/functions.'.$phpEx);
require($phpbb_root_path . 'db/' . $dbms . '.'.$phpEx);
// User related
define('ANONYMOUS', 0);
@ -90,10 +89,6 @@ define('POST_ANNOUNCE', 2);
define('LASTREAD_NORMAL', 0); // not used at the moment
define('LASTREAD_POSTED', 1);
// Error codes
define('MESSAGE', 200);
define('ERROR', 201);
// Private messaging
define('PRIVMSGS_READ_MAIL', 0);
define('PRIVMSGS_NEW_MAIL', 1);
@ -140,7 +135,7 @@ define('USERS_TABLE', $table_prefix.'users');
define('WORDS_TABLE', $table_prefix.'words');
define('POLL_OPTIONS_TABLE', $table_prefix.'poll_results');
define('POLL_VOTES_TABLE', $table_prefix.'poll_voters');
// Unnecessary
define('VOTE_DESC_TABLE', $table_prefix.'vote_desc');
define('VOTE_RESULTS_TABLE', $table_prefix.'vote_results');
define('VOTE_USERS_TABLE', $table_prefix.'vote_voters');
@ -148,64 +143,61 @@ define('VOTE_USERS_TABLE', $table_prefix.'vote_voters');
// Set PHP error handler to ours
set_error_handler('msg_handler');
// Experimental cache manager
$cache = new acm();
// Instantiate some basic classes
$user = new user();
$auth = new auth();
// Need these here so instantiate them now
$cache = new acm();// Experimental cache manager
$template = new Template();
$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false);
/*
// Obtain boardwide default config (rebuilding cache if reqd)
if ( empty($config) )
{
require_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
$config = config_config();
}
$sql = "SELECT *
FROM " . CONFIG_TABLE . "
WHERE is_dynamic = 1";
$result = $db->sql_query($sql, false);
while ( $row = $db->sql_fetchrow($result) )
{
$config[$row['config_name']] = $row['config_value'];
}
// Re-cache acl options if reqd
if ( empty($acl_options) )
{
require_once($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
$auth_admin = new auth_admin();
$acl_options = $auth_admin->acl_cache_options();
}
*/
if (!$config = $cache->get('config'))
// Grab global variables, re-cache if necessary
if (!($config = $cache->get('config')))
{
$config = array();
$sql = 'SELECT * FROM ' . CONFIG_TABLE;
/*
WHERE is_dynamic = 1';
*/
$sql = 'SELECT *
FROM ' . CONFIG_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$config[$row['config_name']] = $row['config_value'];
}
$db->sql_freeresult($result);
$cache->put('config', $config);
}
if ($cache->exists('acl_options'))
if (!($acl_options = $cache->get('acl_options')))
{
$acl_options = $cache->get('acl_options');
}
else
{
require_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
$auth_admin = new auth_admin();
$acl_options = $auth_admin->acl_cache_options();
$acl_options = array();
$sql = "SELECT auth_value, is_global, is_local
FROM " . ACL_OPTIONS_TABLE . "
ORDER BY auth_option_id";
$result = $db->sql_query($sql);
$global = $local = 0;
while ($row = $db->sql_fetchrow($result))
{
if (!empty($row['is_global']))
{
$acl_options['global'][$row['auth_value']] = $global++;
}
if (!empty($row['is_local']))
{
$acl_options['local'][$row['auth_value']] = $local++;
}
}
$db->sql_freeresult($result);
$cache->put('acl_options', $acl_options);
$auth->acl_clear_prefetch();
}
/*
@ -215,28 +207,24 @@ if (time() - $config['cache_interval'] >= $config['cache_last_gc'])
}
*/
// Instantiate some basic classes
$user = new user();
$auth = new auth();
// Show 'Board is disabled' message
if ( $config['board_disable'] && !defined('IN_ADMIN') && !defined('IN_LOGIN') )
if ($config['board_disable'] && !defined('IN_ADMIN') && !defined('IN_LOGIN'))
{
$message = ( !empty($config['board_disable_msg']) ) ? $config['board_disable_msg'] : 'Board_disable';
$message = (!empty($config['board_disable_msg'])) ? $config['board_disable_msg'] : 'Board_disable';
trigger_error($message);
}
// addslashes to vars if magic_quotes_gpc is off
function slash_input_data(&$data)
{
if ( is_array($data) )
if (is_array($data))
{
foreach ( $data as $k => $v )
foreach ($data as $k => $v)
{
$data[$k] = ( is_array($v) ) ? slash_input_data($v) : addslashes($v);
$data[$k] = (is_array($v)) ? slash_input_data($v) : addslashes($v);
}
}
return $data;
}
?>
?>

View File

@ -688,20 +688,6 @@ class auth_admin extends auth
$this->acl_clear_prefetch();
}
function acl_clear_prefetch($user_id = false)
{
global $db;
$where_sql = ($user_id) ? "WHERE user_id = $user_id" : '';
$sql = "UPDATE " . USERS_TABLE . "
SET user_permissions = ''
$where_sql";
$db->sql_query($sql);
return;
}
// Add a new option to the list ... $options is a hash of form ->
// $options = array(
// 'local' => array('option1', 'option2', ...),
@ -802,58 +788,7 @@ class auth_admin extends auth
$result = $db->sql_query($sql);
}
$this->acl_cache_options($options);
}
function acl_cache_options($options = false)
{
global $db, $cache;
$options = array();
if (!$options)
{
$sql = "SELECT auth_value, is_global, is_local
FROM " . ACL_OPTIONS_TABLE . "
ORDER BY is_global, is_local, auth_value";
$result = $db->sql_query($sql);
$global = $local = 0;
while ($row = $db->sql_fetchrow($result))
{
if (!empty($row['is_global']))
{
$options['global'][$row['auth_value']] = $global++;
}
if (!empty($row['is_local']))
{
$options['local'][$row['auth_value']] = $local++;
}
}
$db->sql_freeresult($result);
}
/*
// Re-cache options
$cache_str = "\$acl_options = array(\n";
foreach ($options as $type => $options_ary)
{
$cache_str .= "\t'$type' => array(\n";
foreach ($options_ary as $option_value => $option_id)
{
$cache_str .= "\t\t'$option_value' => " . $option_id . ",\n";
}
$cache_str .= "\t),\n";
}
$cache_str .= ");";
config_cache_write('\$acl_options = array\(.*?\);', $cache_str);
$this->acl_clear_prefetch();
*/
$cache->put('acl_options', $options);
$this->acl_clear_prefetch();
return $options;
$cache->destroy('acl_options');
}
}