Unreported: Now caches portal config

This commit is contained in:
Ice
2008-02-02 13:21:16 +00:00
parent 7cc218e8bf
commit 5d8e911233
3 changed files with 52 additions and 55 deletions

View File

@@ -9,35 +9,6 @@
* *
*/ */
/**
* Set config value. Creates missing config entry.
*/
function set_portal_config($config_name, $config_value, $is_dynamic = false)
{
global $db, $cache, $config;
$sql = 'UPDATE ' . PORTAL_CONFIG_TABLE . "
SET config_value = '" . $db->sql_escape($config_value) . "'
WHERE config_name = '" . $db->sql_escape($config_name) . "'";
$db->sql_query($sql);
if (!$db->sql_affectedrows() && !isset($config[$config_name]))
{
$sql = 'INSERT INTO ' . PORTAL_CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array(
'config_name' => $config_name,
'config_value' => $config_value,
'is_dynamic' => ($is_dynamic) ? 1 : 0));
$db->sql_query($sql);
}
$config[$config_name] = $config_value;
if (!$is_dynamic)
{
$cache->destroy('config');
}
}
class acp_portal class acp_portal
{ {
var $u_action; var $u_action;
@@ -48,17 +19,11 @@ class acp_portal
global $db, $user, $template; global $db, $user, $template;
global $config, $portal_config, $phpbb_root_path, $phpbb_admin_path, $phpEx; global $config, $portal_config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
// Get portal config $phpEx = (empty($phpEx)) ? substr(strrchr(__FILE__, '.'), 1) : $phpEx;
$sql = 'SELECT *
FROM ' . PORTAL_CONFIG_TABLE;
$result = $db->sql_query($sql);
while( $row = $db->sql_fetchrow($result) ) require '../portal/includes/functions.'.$phpEx;
{
$config_name = $row['config_name']; $portal_config = obtain_portal_config();
$config_value = $row['config_value'];
$config[$config_name] = $config_value;
}
$user->add_lang('mods/lang_portal_acp'); $user->add_lang('mods/lang_portal_acp');
@@ -262,7 +227,7 @@ class acp_portal
$user->add_lang($display_vars['lang']); $user->add_lang($display_vars['lang']);
} }
$this->new_config = $config; $this->new_config = $portal_config;
$cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config; $cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config;
$error = array(); $error = array();
@@ -285,13 +250,6 @@ class acp_portal
$this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
if ($config_name == 'email_function_name')
{
$this->new_config['email_function_name'] = trim(str_replace(array('(', ')'), array('', ''), $this->new_config['email_function_name']));
$this->new_config['email_function_name'] = (empty($this->new_config['email_function_name']) || !function_exists($this->new_config['email_function_name'])) ? 'mail' : $this->new_config['email_function_name'];
$config_value = $this->new_config['email_function_name'];
}
if ($submit) if ($submit)
{ {
set_portal_config($config_name, $config_value); set_portal_config($config_name, $config_value);

View File

@@ -19,6 +19,8 @@ $phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx); include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'portal/includes/functions.'.$phpEx); include($phpbb_root_path . 'portal/includes/functions.'.$phpEx);
$portal_config = obtain_portal_config();
// Start session management // Start session management
$user->session_begin(); $user->session_begin();
$auth->acl($user->data); $auth->acl($user->data);

View File

@@ -16,15 +16,52 @@ if (!defined('IN_PHPBB'))
} }
// Get portal config // Get portal config
$sql = 'SELECT * function obtain_portal_config()
FROM ' . PORTAL_CONFIG_TABLE;
$result = $db->sql_query($sql);
while( $row = $db->sql_fetchrow($result) )
{ {
$portal_config_name = $row['config_name']; global $db, $cache;
$portal_config_value = $row['config_value'];
$portal_config[$portal_config_name] = $portal_config_value; if (($portal_config = $cache->get('portal_config')) !== true)
{
$portal_config = $cached_portal_config = array();
$sql = 'SELECT config_name, config_value
FROM ' . PORTAL_CONFIG_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$cached_portal_config[$row['config_name']] = $row['config_value'];
$portal_config[$row['config_name']] = $row['config_value'];
}
$db->sql_freeresult($result);
$cache->put('portal_config', $cached_portal_config);
}
return $portal_config;
}
/**
* Set config value. Creates missing config entry.
*/
function set_portal_config($config_name, $config_value)
{
global $db, $cache, $portal_config;
$sql = 'UPDATE ' . PORTAL_CONFIG_TABLE . "
SET config_value = '" . $db->sql_escape($config_value) . "'
WHERE config_name = '" . $db->sql_escape($config_name) . "'";
$db->sql_query($sql);
if (!$db->sql_affectedrows() && !isset($portal_config[$config_name]))
{
$sql = 'INSERT INTO ' . PORTAL_CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array(
'config_name' => $config_name,
'config_value' => $config_value));
$db->sql_query($sql);
}
$portal_config[$config_name] = $config_value;
} }
// //