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

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

update css overload

  • Property svn:eol-style set to LF
File size: 4.7 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    $qlc = array (
113      'url' => add_url_params($base_url, array('lang'=> $code)),
114      'alt' => ucwords($displayname),
115      'title' => substr($displayname, 0, -4), // remove [FR] or [RU]
116      'code' => $code,
117      );
118   
119    $lsw['flags'][$code] = $qlc;
120   
121    if ($code == $user['language'])
122    {
123      $lsw['Active'] = $qlc;
124    }
125  }
126 
127  $safe_themes = array('clear','dark','elegant','Sylvia','simple-grey','simple-black','simple-white','kardon','luciano','montblancxl'); // stripped (2.6)
128 
129  $template->assign(array(
130      'lang_switch'=> $lsw,
131      'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH,
132      'LANGUAGE_SWITCH_LOAD_STYLE' => !in_array($user['theme'], $safe_themes),
133      ));
134 
135  $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl');
136  $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('language_flags', true) );
137  $template->clear_assign('lang_switch');
138}
139
140?>
Note: See TracBrowser for help on using the repository browser.