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

Last change on this file since 12342 was 12342, checked in by plg, 13 years ago

bug 2430 fixed: prevents from cross site scripting, the URL is cleanly rewritten

  • Property svn:eol-style set to LF
File size: 4.6 KB
RevLine 
[2286]1<?php
[2161]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[8728]5// | Copyright(C) 2008-2011 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    {
44      if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php'))
45      {
46        if (is_a_guest() or is_generic())
47        {
48          pwg_set_session_var('lang_switch', $_GET['lang']);
49        }
50        else
51        {
52          $query = '
53UPDATE '.USER_INFOS_TABLE.'
54  SET language = \''.$_GET['lang'].'\'
55  WHERE user_id = '.$user['id'].'
56;';
[3376]57          pwg_query($query);
58        }
[11123]59       
[3376]60        $user['language'] = $_GET['lang'];
[2162]61      }
[3376]62    }
[11123]63    elseif ((is_a_guest() or is_generic()))
64    {
65      $user['language'] = pwg_get_session_var('lang_switch', $user['language']);
[3376]66    }
[11123]67   
68    // Reload language only if it isn't the same one
69    if ( $same !== $user['language'])
70    {
71      load_language('common.lang', '', array('language'=>$user['language']));
72     
73      load_language(
74        'lang',
75        PHPWG_ROOT_PATH.PWG_LOCAL_DIR,
76        array(
77          'language' => $user['language'],
78          'no_fallback' => true,
79          'local' => true
80          )
81        );
82     
83      if (defined('IN_ADMIN') and IN_ADMIN)
84      {
85        // Never currently
86        load_language('admin.lang', '', array('language'=>$user['language']));
[2162]87      }
[2161]88    }
89  }
[11123]90 
[3376]91  static public function _flags()
[2286]92  {
[3376]93    global $user, $template, $conf;
[11123]94   
[3376]95    $available_lang = get_languages();
[11123]96   
97    if (isset($conf['no_flag_languages']))
98    {
99      $available_lang = array_diff_key($available_lang, array_flip($conf['no_flag_languages']));
100    }
101   
[3479]102    $url_starting = get_query_string_diff(array('lang'));
[12342]103
[11123]104    foreach ($available_lang as $code => $displayname)
105    {
[12342]106      $qlc = array (
107        'url' => add_url_params(duplicate_index_url(), array('lang'=> $code)),
[11123]108        'alt' => ucwords($displayname),
[9906]109        'title' => substr($displayname, 0, -4), // remove [FR] or [RU]
[11123]110        'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg',
[3376]111        );
[9906]112     
113      $lsw['flags'][$code] = $qlc ;
114     
115      if ($code == $user['language'])
116      {
117        $lsw['Active'] = $qlc;
118      }
[3376]119    }
[11123]120   
[3376]121    $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl');
[11123]122   
[3376]123    $lsw['side'] = ceil(sqrt(count($available_lang)));
[11123]124   
125    $template->assign(
126      array(
127        'lang_switch'=> $lsw,
128        'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH,
129        )
130      );
131   
[3376]132    $flags = $template->parse('language_flags',true);
133    $template->clear_assign('lang_switch');
134    $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags);
[2162]135  }
[2161]136}
[11123]137
[3376]138  /* {html_head} usage function */
139  /* See flags.tpl for example (due no catenation available) */
[11123]140if (!function_exists('Componant_exists'))
141{
[3376]142  function Componant_exists($path, $file)
[11123]143  {
144    return file_exists( $path . $file);
145  }
[3369]146}
147
[12342]148?>
Note: See TracBrowser for help on using the repository browser.