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

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

Language Switch:

  • display language name next to flag (and enlarge the flag box to ~400px)
  • force the links color inside the language box because the background color is

forced : on a theme like "grum dark II", the result is really awful, impossible
to read.

  • the current language is not removed from the list, this ways the list is not

reorganized depending on the current language

  • Property svn:eol-style set to LF
File size: 4.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2011 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// +-----------------------------------------------------------------------+
23if (!defined('LANGUAGE_SWITCH_PATH'))
24define('LANGUAGE_SWITCH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
25class language_controler {
26  static public function _switch()
27  {
28    global $user;
29    if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
30    $same = $user['language'];
31    if ( isset( $_GET['lang']) ) {
32      if ( !empty($_GET['lang'] ) and file_exists( PHPWG_ROOT_PATH.'language/'
33        . $_GET['lang'].'/common.lang.php') ) {
34        if (is_a_guest() or is_generic()) {
35          pwg_set_session_var( 'lang_switch', $_GET['lang'] );
36        } else {
37          $query = 'UPDATE '.USER_INFOS_TABLE.'
38          SET language = \''.$_GET['lang'].'\'
39          WHERE user_id = '.$user['id'].'
40          ;';
41          pwg_query($query);
42        }
43        $user['language'] = $_GET['lang'];
44      }
45    }
46    elseif ((is_a_guest() or is_generic())) {
47      $user['language'] = pwg_get_session_var( 'lang_switch', $user['language'] );
48    }
49  // Reload language only if it isn't the same one
50    if ( $same !== $user['language']) {
51      load_language('common.lang', '', array('language'=>$user['language']) );
52      load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR,
53        array('language'=>$user['language'], 'no_fallback'=>true, 'local'=>true)
54      );
55      if (defined('IN_ADMIN') and IN_ADMIN) { // Never currently
56        load_language('admin.lang', '', array('language'=>$user['language']) );
57      }
58    }
59  }
60  static public function _flags()
61  {
62    global $user, $template, $conf;
63    $available_lang = get_languages();
64    if ( isset($conf['no_flag_languages']) ) 
65      $available_lang = 
66        array_diff_key($available_lang, array_flip($conf['no_flag_languages']));
67    $url_starting = get_query_string_diff(array('lang'));
68    foreach ( $available_lang as $code => $displayname ) {
69      $qlc = array ( 
70        'url' => str_replace(array('=&amp;','?&amp;'),array('&amp;','?'),
71                 add_url_params( $url_starting, array('lang'=> $code) )),
72        'alt' => ucwords( $displayname ),
73        'title' => substr($displayname, 0, -4), // remove [FR] or [RU]
74        'img' => get_root_url().'language/' . $code . '/' . $code . '.jpg',
75        );
76     
77      $lsw['flags'][$code] = $qlc ;
78     
79      if ($code == $user['language'])
80      {
81        $lsw['Active'] = $qlc;
82      }
83    }
84    $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl');
85    $lsw['side'] = ceil(sqrt(count($available_lang)));
86    $template->assign(array(
87      'lang_switch'=> $lsw,
88      'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH,
89    ));
90    $flags = $template->parse('language_flags',true);
91    $template->clear_assign('lang_switch');
92    $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags);
93  }
94}
95  /* {html_head} usage function */
96  /* See flags.tpl for example (due no catenation available) */
97if (!function_exists('Componant_exists')) {
98  function Componant_exists($path, $file)
99    { return file_exists( $path . $file); }
100}
101
102?>
Note: See TracBrowser for help on using the repository browser.