From 5d8e911233c95e70550da1e1d1a062b845fb1162 Mon Sep 17 00:00:00 2001 From: Ice Date: Sat, 2 Feb 2008 13:21:16 +0000 Subject: [PATCH] Unreported: Now caches portal config --- root/includes/acp/acp_portal.php | 52 +++-------------------------- root/portal.php | 2 ++ root/portal/includes/functions.php | 53 +++++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 55 deletions(-) diff --git a/root/includes/acp/acp_portal.php b/root/includes/acp/acp_portal.php index e0a69e38..b9f902d3 100644 --- a/root/includes/acp/acp_portal.php +++ b/root/includes/acp/acp_portal.php @@ -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 { var $u_action; @@ -48,17 +19,11 @@ class acp_portal global $db, $user, $template; global $config, $portal_config, $phpbb_root_path, $phpbb_admin_path, $phpEx; - // Get portal config - $sql = 'SELECT * - FROM ' . PORTAL_CONFIG_TABLE; - $result = $db->sql_query($sql); + $phpEx = (empty($phpEx)) ? substr(strrchr(__FILE__, '.'), 1) : $phpEx; + + require '../portal/includes/functions.'.$phpEx; - while( $row = $db->sql_fetchrow($result) ) - { - $config_name = $row['config_name']; - $config_value = $row['config_value']; - $config[$config_name] = $config_value; - } + $portal_config = obtain_portal_config(); $user->add_lang('mods/lang_portal_acp'); @@ -262,7 +227,7 @@ class acp_portal $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; $error = array(); @@ -285,13 +250,6 @@ class acp_portal $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) { set_portal_config($config_name, $config_value); diff --git a/root/portal.php b/root/portal.php index cccdeba8..f32a3ee7 100644 --- a/root/portal.php +++ b/root/portal.php @@ -19,6 +19,8 @@ $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); include($phpbb_root_path . 'portal/includes/functions.'.$phpEx); +$portal_config = obtain_portal_config(); + // Start session management $user->session_begin(); $auth->acl($user->data); diff --git a/root/portal/includes/functions.php b/root/portal/includes/functions.php index b0dc7b92..8ae68f2a 100644 --- a/root/portal/includes/functions.php +++ b/root/portal/includes/functions.php @@ -16,15 +16,52 @@ if (!defined('IN_PHPBB')) } // Get portal config -$sql = 'SELECT * - FROM ' . PORTAL_CONFIG_TABLE; -$result = $db->sql_query($sql); - -while( $row = $db->sql_fetchrow($result) ) +function obtain_portal_config() { - $portal_config_name = $row['config_name']; - $portal_config_value = $row['config_value']; - $portal_config[$portal_config_name] = $portal_config_value; + global $db, $cache; + + 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; } //