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

Last change on this file since 19989 was 19703, checked in by plg, 12 years ago

update Piwigo headers to 2013 (the end of the world didn't occur as expected on r12922)

  • 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-2013 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('PHPWG_ROOT_PATH')) die('Hacking attempt!');
25
26function language_controler_switch()
27{
28  global $user;
29   
30  $same = $user['language'];
31 
32  if (isset($_GET['lang']))
33  {
34    include_once(PHPWG_ROOT_PATH . 'admin/include/languages.class.php');
35    $languages = new languages();
36    if ( !in_array($_GET['lang'], array_keys($languages->fs_languages)) )
37    {
38      $_GET['lang'] = PHPWG_DEFAULT_LANGUAGE;
39    }
40
41    if ( !empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php') )
42    {
43      if ( is_a_guest() or is_generic() )
44      {
45        pwg_set_session_var('lang_switch', $_GET['lang']);
46      }
47      else
48      {
49        $query = '
50UPDATE '.USER_INFOS_TABLE.'
51  SET language = \''.$_GET['lang'].'\'
52  WHERE user_id = '.$user['id'].'
53;';
54        pwg_query($query);
55      }
56     
57      $user['language'] = $_GET['lang'];
58    }
59  }
60  elseif ( (is_a_guest() or is_generic()) )
61  {
62    $user['language'] = pwg_get_session_var('lang_switch', $user['language']);
63  }
64 
65  // Reload language only if it isn't the same one
66  if ( $same !== $user['language'] )
67  {
68    load_language('common.lang', '', array('language'=>$user['language']));
69   
70    load_language(
71      'lang',
72      PHPWG_ROOT_PATH.PWG_LOCAL_DIR,
73      array(
74        'language' => $user['language'],
75        'no_fallback' => true,
76        'local' => true
77        )
78      );
79   
80    if ( defined('IN_ADMIN') and IN_ADMIN )
81    {
82      // Never currently
83      load_language('admin.lang', '', array('language'=>$user['language']));
84    }
85  }
86}
87
88function language_controler_flags()
89{
90  global $user, $template, $conf, $page;
91 
92  $available_lang = get_languages();
93 
94  if (isset($conf['no_flag_languages']))
95  {
96    $available_lang = array_diff_key($available_lang, array_flip($conf['no_flag_languages']));
97  }
98 
99  $url_starting = get_query_string_diff(array('lang'));
100 
101  if (isset($page['section']) and $page['section'] == 'additional_page' and isset($page['additional_page']))
102  {
103    $base_url = make_index_url(array('section'=>'page')).'/'.(isset($page['additional_page']['permalink']) ? $page['additional_page']['permalink'] : $page['additional_page']['id']);
104  }
105  else
106  {
107    $base_url = duplicate_index_url();
108  }
109 
110  foreach ($available_lang as $code => $displayname)
111  {
112   
113    $qlc = array (
114      'url' => add_url_params($base_url, array('lang'=> $code)),
115      'alt' => ucwords($displayname),
116      'title' => substr($displayname, 0, -4), // remove [FR] or [RU]
117      'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg',
118      );
119   
120    $lsw['flags'][$code] = $qlc;
121   
122    if ($code == $user['language'])
123    {
124      $lsw['Active'] = $qlc;
125    }
126  }
127 
128  $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl');
129 
130  $template->assign(
131    array(
132      'lang_switch'=> $lsw,
133      'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH,
134      )
135    );
136 
137  $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('language_flags', true) );
138  $template->clear_assign('lang_switch');
139}
140
141?>
Note: See TracBrowser for help on using the repository browser.