Changed session gettext to use a global variable instead for smaller footprints in...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 27 Jan 2012 13:37:50 +0000 (14:37 +0100)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 27 Jan 2012 13:37:50 +0000 (14:37 +0100)
admin/db/users_db.inc
admin/inst_lang.php
includes/lang/gettext.php
includes/lang/language.php
includes/session.inc
install/isession.inc
reporting/includes/class.pdf.inc

index 221bc77c832d2e4399d82d5a3ae081cb856d6190..267029c96f2c2bd685fbbd60f6b5bd5d316c82de 100644 (file)
@@ -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)
index e1fbd0636270513e6011633853efbdb5d64eb535..805969ffa0514dfa35cd892c6c4ed2eed6b06f5f 100644 (file)
@@ -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;
 
index 3023e9363020ebd4d8fdd2558198af73d5513cf1..72f246001c8ac6304f63f191a283d672c9ef8ec7 100644 (file)
@@ -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);
 }
 ?>
index 1d6d7d83fb9a7c66e0d6133fb6981e8fac7a564a..5b0509258b109e3271478b2197c5d929053ffe45 100644 (file)
@@ -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;
index 990a51c01a1403f6d9a333888f2021b1e9078544..7cd9d749fe3dcec85b13a5b0f4d43e62fab8f401 100644 (file)
@@ -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");
index 0f7cae89e9dfc7db17bc374b4d72e56efed5aff8..25a5519c1f5eef284c3bd80d9625a2730c73ded5 100644 (file)
@@ -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");
index 0b15e80f8efae9fac05e5725c8ad12c9e1493958..300cd40194987856fee4080535f9f81ba44f86ff 100644 (file)
@@ -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');