[geeklog-cvs] Geeklog-1.x/public_html switchlang.php,1.3,1.4

Dirk Haun dhaun at qs1489.pair.com
Sun Sep 14 05:17:45 EDT 2008


Update of /cvsroot/geeklog/Geeklog-1.x/public_html
In directory qs1489.pair.com:/tmp/cvs-serv44576/public_html

Modified Files:
	switchlang.php 
Log Message:
Fixed failure to switch language with new query highlighting URLs (bug #0000733)


Index: switchlang.php
===================================================================
RCS file: /cvsroot/geeklog/Geeklog-1.x/public_html/switchlang.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** switchlang.php	3 Oct 2006 09:19:45 -0000	1.3
--- switchlang.php	14 Sep 2008 09:17:41 -0000	1.4
***************
*** 3,7 ****
  /* Reminder: always indent with 4 spaces (no tabs). */
  // +---------------------------------------------------------------------------+
! // | Geeklog 1.4                                                               |
  // +---------------------------------------------------------------------------+
  // | switchlang.php                                                            |
--- 3,7 ----
  /* Reminder: always indent with 4 spaces (no tabs). */
  // +---------------------------------------------------------------------------+
! // | Geeklog 1.5                                                               |
  // +---------------------------------------------------------------------------+
  // | switchlang.php                                                            |
***************
*** 9,13 ****
  // | Switch the user's language                                                |
  // +---------------------------------------------------------------------------+
! // | Copyright (C) 2006 by the following authors:                              |
  // |                                                                           |
  // | Authors: Dirk Haun         - dirk AT haun-online DOT de                   |
--- 9,13 ----
  // | Switch the user's language                                                |
  // +---------------------------------------------------------------------------+
! // | Copyright (C) 2006-2008 by the following authors:                         |
  // |                                                                           |
  // | Authors: Dirk Haun         - dirk AT haun-online DOT de                   |
***************
*** 33,37 ****
  // $Id$
  
! require_once ('lib-common.php');
  
  /**
--- 33,37 ----
  // $Id$
  
! require_once 'lib-common.php';
  
  /**
***************
*** 44,48 ****
  *
  */
! function switch_language ($url, $newlang, $oldlang)
  {
      global $_CONF;
--- 44,48 ----
  *
  */
! function switch_language($url, $newlang, $oldlang)
  {
      global $_CONF;
***************
*** 50,72 ****
      $retval = '';
  
!     if (empty ($newlang) || empty ($oldlang) ||
!             (strlen ($newlang) != strlen ($oldlang))) {
          return $url;
      }
  
!     $lang_len = strlen ($oldlang);
!     if ((strpos ($url, '&') === false) && (strpos ($url, '?') === false) &&
!             $_CONF['url_rewrite']) {
          // for "rewritten" URLs we assume that the first parameter after
          // the script name is the ID, e.g. /article.php/story-id-here_en
          $changed = false;
!         $p = explode ('/', $url);
!         for ($i = 0; $i < count ($p); $i++) {
!             if (substr ($p[$i], -4) == '.php') {
                  // found the script name - assume next parameter is the ID
!                 if (isset ($p[$i + 1])) {
!                     if (substr ($p[$i + 1], -($lang_len + 1)) == '_' . $oldlang) {
!                         $p[$i + 1] = substr_replace ($p[$i + 1], $newlang,
!                                                      -$lang_len);
                          $changed = true;
                      }
--- 50,91 ----
      $retval = '';
  
!     if (empty($newlang) || empty($oldlang) ||
!             (strlen($newlang) != strlen($oldlang))) {
          return $url;
      }
  
!     $lang_len = strlen($oldlang);
!     $url_rewrite = false;
!     $q = false;
! 
!     if ($_CONF['url_rewrite']) {
!         // check for "rewritten" URLs with a '?', e.g. search query highlighting
!         $q = strpos($url, '?');
!         if ($q === false) {
!             $url_rewrite = true;
!         } elseif (substr($url, $q - 4, 4) != '.php') {
!             $url_rewrite = true;
!         }
!     }
! 
!     if ($url_rewrite) {
!         if ($q === false) {
!             $the_url = $url;
!         } else {
!             $the_url = substr($url, 0, $q);
!         }
! 
          // for "rewritten" URLs we assume that the first parameter after
          // the script name is the ID, e.g. /article.php/story-id-here_en
          $changed = false;
!         $p = explode('/', $the_url);
!         $parts = count($p);
!         for ($i = 0; $i < $parts; $i++) {
!             if (substr($p[$i], -4) == '.php') {
                  // found the script name - assume next parameter is the ID
!                 if (isset($p[$i + 1])) {
!                     if (substr($p[$i + 1], -($lang_len + 1)) == '_' . $oldlang) {
!                         $p[$i + 1] = substr_replace($p[$i + 1], $newlang,
!                                                     -$lang_len);
                          $changed = true;
                      }
***************
*** 75,96 ****
              }
          }
          if ($changed) {
              // merge the pieces back together
!             $url = implode ('/', $p);
          }
  
          $retval = $url;
      } else { // URL contains '?' or '&'
!         $url = explode ('&', $url);
          $urlpart = $url[0];
!         if (count ($url) > 1) {
!             array_shift ($url);
!             $extra_vars = '&' . implode ('&', $url);
          } else {
              $extra_vars = '';
          }
  
!         if (substr ($urlpart, -($lang_len + 1)) == '_' . $oldlang) {
!             $urlpart = substr_replace ($urlpart, $newlang, -$lang_len);
          }
  
--- 94,120 ----
              }
          }
+ 
          if ($changed) {
              // merge the pieces back together
!             if ($q === false) {
!                 $url = implode('/', $p);
!             } else {
!                 $url = implode('/', $p) . substr($url, $q);
!             }
          }
  
          $retval = $url;
      } else { // URL contains '?' or '&'
!         $url = explode('&', $url);
          $urlpart = $url[0];
!         if (count($url) > 1) {
!             array_shift($url);
!             $extra_vars = '&' . implode('&', $url);
          } else {
              $extra_vars = '';
          }
  
!         if (substr($urlpart, -($lang_len + 1)) == '_' . $oldlang) {
!             $urlpart = substr_replace($urlpart, $newlang, -$lang_len);
          }
  
***************
*** 104,109 ****
  // MAIN
  $ret_url = '';
! if (isset ($_SERVER['HTTP_REFERER'])) {
!     if (strpos ($_SERVER['HTTP_REFERER'], $_CONF['site_url']) !== false) {
          $ret_url = $_SERVER['HTTP_REFERER'];
      }
--- 128,133 ----
  // MAIN
  $ret_url = '';
! if (isset($_SERVER['HTTP_REFERER'])) {
!     if (strpos($_SERVER['HTTP_REFERER'], $_CONF['site_url']) !== false) {
          $ret_url = $_SERVER['HTTP_REFERER'];
      }
***************
*** 113,139 ****
  if ($_CONF['allow_user_language'] == 1) {
  
!     COM_setArgNames (array ('lang'));
  
!     $lang = strtolower (COM_applyFilter (COM_getArgument ('lang')));
!     $lang = preg_replace( '/[^a-z0-9\-_]/', '', $lang );
!     $oldlang = COM_getLanguageId ();
  
      // do we really have a new language to switch to?
!     if (!empty ($lang) && array_key_exists ($lang, $_CONF['language_files'])) {
  
          // does such a language file exist?
          $langfile = $_CONF['language_files'][$lang];
!         if (is_file ($_CONF['path_language'] . $langfile . '.php')) {
  
              // Set the language cookie.
!             // Mainly used for the anonymous user so the rest of this session
!             // will remain in their selected language
!             setcookie ($_CONF['cookie_language'], $langfile, time() + 31536000,
!                        $_CONF['cookie_path'], $_CONF['cookiedomain'],
!                        $_CONF['cookiesecure']);
  
              // if user is not anonymous, store the preference in the database
!             if (isset ($_USER['uid']) && ($_USER['uid'] > 1)) {
!                 DB_query ("UPDATE {$_TABLES['users']} SET language = '{$langfile}' WHERE uid = {$_USER['uid']}");
              }
          }
--- 137,163 ----
  if ($_CONF['allow_user_language'] == 1) {
  
!     COM_setArgNames(array('lang'));
  
!     $lang = strtolower(COM_applyFilter(COM_getArgument('lang')));
!     $lang = preg_replace('/[^a-z0-9\-_]/', '', $lang);
!     $oldlang = COM_getLanguageId();
  
      // do we really have a new language to switch to?
!     if (!empty($lang) && array_key_exists($lang, $_CONF['language_files'])) {
  
          // does such a language file exist?
          $langfile = $_CONF['language_files'][$lang];
!         if (is_file($_CONF['path_language'] . $langfile . '.php')) {
  
              // Set the language cookie.
!             // Mainly used for anonymous users so the rest of their session
!             // will remain in the selected language
!             setcookie($_CONF['cookie_language'], $langfile, time() + 31536000,
!                       $_CONF['cookie_path'], $_CONF['cookiedomain'],
!                       $_CONF['cookiesecure']);
  
              // if user is not anonymous, store the preference in the database
!             if (!COM_isAnonUser()) {
!                 DB_query("UPDATE {$_TABLES['users']} SET language = '{$langfile}' WHERE uid = {$_USER['uid']}");
              }
          }
***************
*** 141,155 ****
  
      // Change the language ID if needed
!     if (!empty ($ret_url) && !empty ($lang) && !empty ($oldlang)) {
!         $ret_url = switch_language ($ret_url, $lang, $oldlang);
      }
  }
  
  // if the user didn't come from our site, send them to our index page
! if (empty ($ret_url)) {
      $ret_url = $_CONF['site_url'] . '/';
  }
  
! header ("Location: $ret_url");
  
  ?>
--- 165,179 ----
  
      // Change the language ID if needed
!     if (!empty($ret_url) && !empty($lang) && !empty($oldlang)) {
!         $ret_url = switch_language($ret_url, $lang, $oldlang);
      }
  }
  
  // if the user didn't come from our site, send them to our index page
! if (empty($ret_url)) {
      $ret_url = $_CONF['site_url'] . '/';
  }
  
! header("Location: $ret_url");
  
  ?>




More information about the geeklog-cvs mailing list