Changeset 29840 for trunk/include


Ignore:
Timestamp:
Sep 30, 2014, 10:23:34 AM (10 years ago)
Author:
plg
Message:

bug 3111: cleaner code for get_browser_language (no more reference as parameter)

Location:
trunk/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_user.inc.php

    r29839 r29840  
    220220    }
    221221
    222     $override = null;
    223     if ($notify_admin and $conf['browser_language'])
    224     {
    225       // if function get_browser_language finds a language in the browser
    226       // which matches a language activated in Piwigo, then it sets
    227       // $override['language'] to 'ru' (for example) and returns
    228       // true. $override won't stay null
    229       if (!get_browser_language($override['language']))
    230       {
    231         $override=null;
    232       }
    233     }
     222    $override = array();
     223    if ($language = get_browser_language())
     224    {
     225      $override['language'] = $language;
     226    }
     227   
    234228    create_user_infos($user_id, $override);
    235229
     
    814808 * @todo : try to match 'fr_CA' before 'fr'
    815809 *
    816  * @param string &$lang
    817  * @return bool
    818  */
    819 function get_browser_language(&$lang)
     810 * @return string
     811 */
     812function get_browser_language()
    820813{
    821814  $browser_language = substr(@$_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2);
     
    824817    if (substr($language_code, 0, 2) == $browser_language)
    825818    {
    826       $lang = $language_code;
    827       return true;
     819      return $language_code;
    828820    }
    829821  }
  • trunk/include/user.inc.php

    r28587 r29840  
    6969          ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ?
    7070         );
    71 if ($conf['browser_language'] and (is_a_guest() or is_generic()) )
     71if ($conf['browser_language'] and (is_a_guest() or is_generic()) and $language = get_browser_language())
    7272{
    73   get_browser_language($user['language']);
     73  $user['language'] = $language;
    7474}
    7575trigger_notify('user_init', $user);
Note: See TracChangeset for help on using the changeset viewer.