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

Last change on this file since 2162 was 2162, checked in by vdigital, 16 years ago

Minor code review

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