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

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 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// +-----------------------------------------------------------------------+
23// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
26// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
27// +-----------------------------------------------------------------------+
28// | file          : $Id: language_switch.inc.php 2297 2008-04-04 22:57:23Z plg $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Revision: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47function language_switch()
48{
49  global $user, $template, $conf, $lang;
50  if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
51  $same = $user['language'];
52  if ( isset( $_GET['lang']) )
53  {
54    if ( !empty($_GET['lang'] ) and
55      file_exists( PHPWG_ROOT_PATH.'language/'
56      . $_GET['lang'].'/common.lang.php') )
57    {
58      if (is_a_guest() or is_generic())
59      {
60        setcookie( 'pwg_lang_switch', $_GET['lang'],
61          time()+60*60*24*30, cookie_path() );
62      }
63      else
64      {
65        $query = 'UPDATE '.USER_INFOS_TABLE.'
66        SET language = \''.$_GET['lang'].'\'
67        WHERE user_id = '.$user['id'].'
68        ;';
69        pwg_query($query);
70      }
71      $user['language'] = $_GET['lang'];
72    }
73  }
74// Users have $user['language']
75// Guest or generic members will use their cookied language !
76  if ((is_a_guest() or is_generic())
77    and isset( $_COOKIE['pwg_lang_switch'] ) )
78  {
79    $user['language'] = $_COOKIE['pwg_lang_switch'];
80  }
81// Reload language only if it isn't the same one
82  if ( $same !== $user['language'])
83  {
84    load_language('common.lang', '', $user['language']);
85    load_language('local.lang', '', $user['language']);
86    if (defined('IN_ADMIN') and IN_ADMIN)
87    {
88      load_language('admin.lang', '', $user['language']);
89    }
90  }
91}
92//if ( isset( $_GET['lang']) ) { redirect( make_index_url() ); }
93
94function Lang_flags()
95{
96  global $user, $template;
97  $available_lang = get_languages();
98  foreach ( $available_lang as $code => $displayname )
99  {
100    $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) );
101    $qlc_alt = ucwords( $displayname );
102    $qlc_title =  $qlc_alt;
103    $qlc_img =  'plugins/language_switch/icons/'
104       . $code . '.gif';
105
106    if ( $code !== $user['language'] and file_exists(PHPWG_ROOT_PATH.$qlc_img) )
107    {
108      $template->concat( 'PLUGIN_INDEX_ACTIONS',
109        '<li><a href="' . $qlc_url . '" ><img src="' . get_root_url().$qlc_img . '" alt="'
110        . $qlc_alt . '" title="'
111        . $qlc_title . '" style="border: 1px solid #000000; '
112        . ' margin: 0px 2px;" /></a></li>');
113    }
114  }
115}
116?>
Note: See TracBrowser for help on using the repository browser.