source: trunk/plugins/language_switch/language_switch.inc.php @ 15917

Last change on this file since 15917 was 13956, checked in by plg, 12 years ago

merge r13955 from branch 2.3 to trunk

bug 2610 fixed: make sure the $_GETlang or $_GETlanguage is in the
list of available languages.

  • Property svn:eol-style set to LF
File size: 4.9 KB
RevLine 
[2286]1<?php
[2161]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[12922]5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[11123]23
[3369]24if (!defined('LANGUAGE_SWITCH_PATH'))
[11123]25{
26  define('LANGUAGE_SWITCH_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
27}
28
29class language_controler
30{
[3376]31  static public function _switch()
[2161]32  {
[3376]33    global $user;
[11123]34   
35    if (!defined('PHPWG_ROOT_PATH'))
36    {
37      die('Hacking attempt!');
38    }
39   
[3376]40    $same = $user['language'];
[11123]41   
42    if (isset($_GET['lang']))
43    {
[13956]44      include_once(PHPWG_ROOT_PATH . 'admin/include/languages.class.php');
45      $languages = new languages();
46      if (!in_array($_GET['lang'], array_keys($languages->fs_languages)))
47      {
48        $_GET['lang'] = PHPWG_DEFAULT_LANGUAGE;
49      }
50
[11123]51      if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php'))
52      {
53        if (is_a_guest() or is_generic())
54        {
55          pwg_set_session_var('lang_switch', $_GET['lang']);
56        }
57        else
58        {
59          $query = '
60UPDATE '.USER_INFOS_TABLE.'
61  SET language = \''.$_GET['lang'].'\'
62  WHERE user_id = '.$user['id'].'
63;';
[3376]64          pwg_query($query);
65        }
[11123]66       
[3376]67        $user['language'] = $_GET['lang'];
[2162]68      }
[3376]69    }
[11123]70    elseif ((is_a_guest() or is_generic()))
71    {
72      $user['language'] = pwg_get_session_var('lang_switch', $user['language']);
[3376]73    }
[11123]74   
75    // Reload language only if it isn't the same one
76    if ( $same !== $user['language'])
77    {
78      load_language('common.lang', '', array('language'=>$user['language']));
79     
80      load_language(
81        'lang',
82        PHPWG_ROOT_PATH.PWG_LOCAL_DIR,
83        array(
84          'language' => $user['language'],
85          'no_fallback' => true,
86          'local' => true
87          )
88        );
89     
90      if (defined('IN_ADMIN') and IN_ADMIN)
91      {
92        // Never currently
93        load_language('admin.lang', '', array('language'=>$user['language']));
[2162]94      }
[2161]95    }
96  }
[11123]97 
[3376]98  static public function _flags()
[2286]99  {
[3376]100    global $user, $template, $conf;
[11123]101   
[3376]102    $available_lang = get_languages();
[11123]103   
104    if (isset($conf['no_flag_languages']))
105    {
106      $available_lang = array_diff_key($available_lang, array_flip($conf['no_flag_languages']));
107    }
108   
[3479]109    $url_starting = get_query_string_diff(array('lang'));
[12342]110
[11123]111    foreach ($available_lang as $code => $displayname)
112    {
[12342]113      $qlc = array (
114        'url' => add_url_params(duplicate_index_url(), array('lang'=> $code)),
[11123]115        'alt' => ucwords($displayname),
[9906]116        'title' => substr($displayname, 0, -4), // remove [FR] or [RU]
[11123]117        'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg',
[3376]118        );
[9906]119     
120      $lsw['flags'][$code] = $qlc ;
121     
122      if ($code == $user['language'])
123      {
124        $lsw['Active'] = $qlc;
125      }
[3376]126    }
[11123]127   
[3376]128    $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl');
[11123]129   
[3376]130    $lsw['side'] = ceil(sqrt(count($available_lang)));
[11123]131   
132    $template->assign(
133      array(
134        'lang_switch'=> $lsw,
135        'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH,
136        )
137      );
138   
[3376]139    $flags = $template->parse('language_flags',true);
140    $template->clear_assign('lang_switch');
141    $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags);
[2162]142  }
[2161]143}
[11123]144
[3376]145  /* {html_head} usage function */
146  /* See flags.tpl for example (due no catenation available) */
[11123]147if (!function_exists('Componant_exists'))
148{
[3376]149  function Componant_exists($path, $file)
[11123]150  {
151    return file_exists( $path . $file);
152  }
[3369]153}
154
[12342]155?>
Note: See TracBrowser for help on using the repository browser.