From 70d1cb82db99550984cf43e0d3c6efb0d3318ae2 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Fri, 27 Jan 2012 14:37:50 +0100 Subject: [PATCH] Changed session gettext to use a global variable instead for smaller footprints in session files. --- admin/db/users_db.inc | 4 ++-- admin/inst_lang.php | 4 ++-- includes/lang/gettext.php | 21 ++++++++++----------- includes/lang/language.php | 17 +++++++---------- includes/session.inc | 9 ++------- install/isession.inc | 2 +- reporting/includes/class.pdf.inc | 8 ++++---- 7 files changed, 28 insertions(+), 37 deletions(-) diff --git a/admin/db/users_db.inc b/admin/db/users_db.inc index 221bc77c..267029c9 100644 --- a/admin/db/users_db.inc +++ b/admin/db/users_db.inc @@ -160,10 +160,10 @@ function check_user_activity($id) //----------------------------------------------------------------------------------------------- function show_users_online() { - global $show_users_online, $db; + global $show_users_online, $db, $GetText; if (!isset($show_users_online) || $show_users_online == 0 || !defined('TB_PREF') || - !isset($_SESSION['get_text']) || !isset($db)) + !isset($GetText) || !isset($db)) return ""; $result = db_query("SHOW TABLES LIKE '".TB_PREF."useronline'"); if (db_num_rows($result) == 1) diff --git a/admin/inst_lang.php b/admin/inst_lang.php index e1fbd063..805969ff 100644 --- a/admin/inst_lang.php +++ b/admin/inst_lang.php @@ -30,7 +30,7 @@ simple_page_mode(true); // function display_languages() { - global $table_style, $installed_languages, $dflt_lang; + global $table_style, $installed_languages, $dflt_lang, $GetText; $th = array(_("Language"), _("Name"), _("Encoding"), _("Right To Left"), _("Installed"), _("Available"), _("Default"), "", ""); @@ -75,7 +75,7 @@ function display_languages() else alt_table_row_color($k); - $support = $_SESSION['get_text']->check_support($lang, $charset); + $support = $GetText->check_support($lang, $charset); if (function_exists('gettext') && !$support && !get_post('DisplayAll')) continue; diff --git a/includes/lang/gettext.php b/includes/lang/gettext.php index 3023e936..72f24600 100644 --- a/includes/lang/gettext.php +++ b/includes/lang/gettext.php @@ -26,19 +26,19 @@ define('GETTEXT_NATIVE', 1); define('GETTEXT_PHP', 2); function get_text_init($managerType = GETTEXT_NATIVE) { - - if (!isset($_SESSION['get_text'])) { + global $GetText; + if (!isset($GetText)) { if ($managerType == GETTEXT_NATIVE) { if (function_exists('gettext')) { - $_SESSION['get_text'] = new gettext_native_support(); + $GetText = new gettext_native_support(); return; } } // fail back to php support - $_SESSION['get_text'] = new gettext_php_support(); + $GetText = new gettext_php_support(); } } @@ -190,7 +190,7 @@ class gettext_native_support */ function gettext($key) { - $value = $this->_get_translation($key); + $value = $this->_get_translation($key); if ($value === false) { $str = sprintf('Unable to locate gettext key "%s"', $key); //$err = new GetText_Error($str); @@ -320,7 +320,7 @@ class gettext_php_support extends gettext_native_support $this->_jobs[] = array($domain, $path); return; } - // Don't fill the domains with false data + // Don't fill the domains with false data, it increased the error.log if (strpos($domain, $this->_lang_code) === false) return; @@ -360,7 +360,6 @@ class gettext_php_support extends gettext_native_support $d = new gettext_domain(); $d->name = $domain; $d->path = $path; - if (!file_exists($php_domain) || (filemtime($php_domain) < filemtime($src_domain))) { @@ -553,7 +552,7 @@ class gettext_php_support_compiler Set current gettext domain path */ function set_ext_domain($path='') { - global $path_to_root; + global $path_to_root, $GetText; static $domain_stack = array(''); if ($path) // save path on domain stack @@ -565,9 +564,9 @@ function set_ext_domain($path='') { } $lang_path = $path_to_root . ($path ? '/' : '') .$path.'/lang'; - // ignore change when extension does not provide translation structure and test for valid session. - if (file_exists($lang_path) && isset($_SESSION['get_text'])) - $_SESSION['get_text']->add_domain($_SESSION['language']->code, + // ignore change when extension does not provide translation structure and test for valid gettext. + if (file_exists($lang_path) && isset($GetText)) + $GetText->add_domain($_SESSION['language']->code, $lang_path, $path ? '' : $_SESSION['language']->version); } ?> diff --git a/includes/lang/language.php b/includes/lang/language.php index 1d6d7d83..5b050925 100644 --- a/includes/lang/language.php +++ b/includes/lang/language.php @@ -48,7 +48,7 @@ class language function set_language($code) { - global $path_to_root, $installed_languages; + global $path_to_root, $installed_languages, $GetText; $lang = array_search_value($code, $installed_languages, 'code'); $changed = $this->code != $code || $this->version != @$lang['version']; @@ -67,8 +67,8 @@ class language $this->is_locale_file = file_exists($locale); } - $_SESSION['get_text']->set_language($this->code, $this->encoding); - $_SESSION['get_text']->add_domain($this->code, $path_to_root . "/lang", $this->version); + $GetText->set_language($this->code, $this->encoding); + $GetText->add_domain($this->code, $path_to_root . "/lang", $this->version); // Necessary for ajax calls. Due to bug in php 4.3.10 for this // version set globally in php.ini @@ -79,18 +79,15 @@ class language } } -function _set($key,$value) -{ - $_SESSION['get_text']->set_var($key,$value); -} - if (!function_exists("_")) { function _($text) { - if (!isset($_SESSION['get_text'])) // Don't allow using session if not is net. + global $GetText; + if (!isset($GetText)) // Don't allow using gettext if not is net. return $text; - $retVal = $_SESSION['get_text']->gettext($text); + + $retVal = $GetText->gettext($text); if ($retVal == "") return $text; return $retVal; diff --git a/includes/session.inc b/includes/session.inc index 990a51c0..7cd9d749 100644 --- a/includes/session.inc +++ b/includes/session.inc @@ -75,11 +75,8 @@ class SessionManager $_SESSION['OBSOLETE'] = true; $_SESSION['EXPIRES'] = time() + 10; - // Create new session destroying the old one if posiible - if (phpversion() >= "5.1.0") - session_regenerate_id(true); - else - session_regenerate_id(); + // Create new session without destroying the old one + session_regenerate_id(); // Grab current session ID and close both sessions to allow other scripts to use them $newSession = session_id(); @@ -299,8 +296,6 @@ ini_set('session.gc_maxlifetime', 36000); // 10hrs $Session_manager = new SessionManager(); $Session_manager->sessionStart('FA'.md5(dirname(__FILE__))); -//session_name('FA'.md5(dirname(__FILE__))); -//session_start(); // this is to fix the "back-do-you-want-to-refresh" issue - thanx PHPFreaks header("Cache-control: private"); diff --git a/install/isession.inc b/install/isession.inc index 0f7cae89..25a5519c 100644 --- a/install/isession.inc +++ b/install/isession.inc @@ -107,7 +107,7 @@ if (!isset($installed_languages)) $installed_languages = array(); $_SESSION['language']->set_language($_SESSION['language']->code); -$_SESSION['get_text']->add_domain( $_SESSION['language']->code, $path_to_root."/install/lang"); +$GetText->add_domain( $_SESSION['language']->code, $path_to_root."/install/lang"); include_once($path_to_root . "/version.php"); include_once($path_to_root . "/includes/main.inc"); diff --git a/reporting/includes/class.pdf.inc b/reporting/includes/class.pdf.inc index 0b15e80f..300cd401 100644 --- a/reporting/includes/class.pdf.inc +++ b/reporting/includes/class.pdf.inc @@ -79,21 +79,21 @@ class Cpdf extends FPDI { */ function SetLang($code=null) { - global $installed_languages, $dflt_lang, $path_to_root, $local_path_to_root; + global $installed_languages, $dflt_lang, $path_to_root, $local_path_to_root, $GetText; if (!$code) $code = $dflt_lang; $lang = array_search_value($code, $installed_languages, 'code'); - $_SESSION['get_text']->set_language($lang['code'], strtoupper($lang['encoding'])); + $GetText->set_language($lang['code'], strtoupper($lang['encoding'])); // $local_path_to_root is set inside find_custom_file. // Select extension domain if po file is provided // otherwise use global translation. if (file_exists($local_path_to_root.'/lang/'.$lang['code'].'/LC_MESSAGES/'.$lang['code'].'.po')) - $_SESSION['get_text']->add_domain($lang['code'], $local_path_to_root . "/lang"); + $GetText->add_domain($lang['code'], $local_path_to_root . "/lang"); else - $_SESSION['get_text']->add_domain($lang['code'], $path_to_root . "/lang", @$lang['version']); + $GetText->add_domain($lang['code'], $path_to_root . "/lang", @$lang['version']); // re-read translated sys names. include($path_to_root.'/includes/sysnames.inc'); -- 2.30.2