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

Last change on this file since 12922 was 12922, checked in by mistic100, 12 years ago

update Piwigo headers to 2012, last change before the expected (or not) apocalypse

  • Property svn:eol-style set to LF
File size: 4.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23
24if (!defined('LANGUAGE_SWITCH_PATH'))
25{
26  define('LANGUAGE_SWITCH_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
27}
28
29class language_controler
30{
31  static public function _switch()
32  {
33    global $user;
34   
35    if (!defined('PHPWG_ROOT_PATH'))
36    {
37      die('Hacking attempt!');
38    }
39   
40    $same = $user['language'];
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;';
57          pwg_query($query);
58        }
59       
60        $user['language'] = $_GET['lang'];
61      }
62    }
63    elseif ((is_a_guest() or is_generic()))
64    {
65      $user['language'] = pwg_get_session_var('lang_switch', $user['language']);
66    }
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']));
87      }
88    }
89  }
90 
91  static public function _flags()
92  {
93    global $user, $template, $conf;
94   
95    $available_lang = get_languages();
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   
102    $url_starting = get_query_string_diff(array('lang'));
103
104    foreach ($available_lang as $code => $displayname)
105    {
106      $qlc = array (
107        'url' => add_url_params(duplicate_index_url(), array('lang'=> $code)),
108        'alt' => ucwords($displayname),
109        'title' => substr($displayname, 0, -4), // remove [FR] or [RU]
110        'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg',
111        );
112     
113      $lsw['flags'][$code] = $qlc ;
114     
115      if ($code == $user['language'])
116      {
117        $lsw['Active'] = $qlc;
118      }
119    }
120   
121    $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl');
122   
123    $lsw['side'] = ceil(sqrt(count($available_lang)));
124   
125    $template->assign(
126      array(
127        'lang_switch'=> $lsw,
128        'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH,
129        )
130      );
131   
132    $flags = $template->parse('language_flags',true);
133    $template->clear_assign('lang_switch');
134    $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags);
135  }
136}
137
138  /* {html_head} usage function */
139  /* See flags.tpl for example (due no catenation available) */
140if (!function_exists('Componant_exists'))
141{
142  function Componant_exists($path, $file)
143  {
144    return file_exists( $path . $file);
145  }
146}
147
148?>
Note: See TracBrowser for help on using the repository browser.