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

Last change on this file since 2479 was 2479, checked in by rvelices, 16 years ago
  • local.lang is loaded without fallback on default language or PHPWG_DEFAULT_LANGUAGE (needed to change the signature of load_language which became a little too big)
  • move a function from functions.inc.php to functions_picture.inc.php (included only when necessary)
  • removed some css (not as much as I wanted)
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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// +-----------------------------------------------------------------------+
23function language_switch()
24{
25  global $user, $template, $conf, $lang;
26  if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
27  $same = $user['language'];
28  if ( isset( $_GET['lang']) )
29  {
30    if ( !empty($_GET['lang'] ) and
31      file_exists( PHPWG_ROOT_PATH.'language/'
32      . $_GET['lang'].'/common.lang.php') )
33    {
34      if (is_a_guest() or is_generic())
35      {
36        setcookie( 'pwg_lang_switch', $_GET['lang'],
37          time()+60*60*24*30, cookie_path() );
38      }
39      else
40      {
41        $query = 'UPDATE '.USER_INFOS_TABLE.'
42        SET language = \''.$_GET['lang'].'\'
43        WHERE user_id = '.$user['id'].'
44        ;';
45        pwg_query($query);
46      }
47      $user['language'] = $_GET['lang'];
48    }
49  }
50// Users have $user['language']
51// Guest or generic members will use their cookied language !
52  if ((is_a_guest() or is_generic())
53    and isset( $_COOKIE['pwg_lang_switch'] ) )
54  {
55    $user['language'] = $_COOKIE['pwg_lang_switch'];
56  }
57// Reload language only if it isn't the same one
58  if ( $same !== $user['language'])
59  {
60    load_language('common.lang', '', array('language'=>$user['language']) );
61    load_language('local.lang', '', array('language'=>$user['language'], 'no_fallback'=>true) );
62    if (defined('IN_ADMIN') and IN_ADMIN)
63    {
64      load_language('admin.lang', '', array('language'=>$user['language']) );
65    }
66  }
67}
68//if ( isset( $_GET['lang']) ) { redirect( make_index_url() ); }
69
70function Lang_flags()
71{
72  global $user, $template;
73  $available_lang = get_languages();
74  foreach ( $available_lang as $code => $displayname )
75  {
76    $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) );
77    $qlc_alt = ucwords( $displayname );
78    $qlc_title =  $qlc_alt;
79    $qlc_img =  'plugins/language_switch/icons/'
80       . $code . '.gif';
81
82    if ( $code !== $user['language'] and file_exists(PHPWG_ROOT_PATH.$qlc_img) )
83    {
84      $template->concat( 'PLUGIN_INDEX_ACTIONS',
85        '<li><a href="' . $qlc_url . '" ><img src="' . get_root_url().$qlc_img . '" alt="'
86        . $qlc_alt . '" title="'
87        . $qlc_title . '" style="border: 1px solid #000000; '
88        . ' margin: 0px 2px;" /></a></li>');
89    }
90  }
91}
92?>
Note: See TracBrowser for help on using the repository browser.