[2286] | 1 | <?php |
---|
[2161] | 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 2286 2008-03-20 00:35:36Z rvelices $ |
---|
| 8 | // | last update : $Date: 2008-03-20 00:35:36 +0000 (Thu, 20 Mar 2008) $ |
---|
| 9 | // | last modifier : $Author: rvelices $ |
---|
| 10 | // | revision : $Revision: 2286 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
| 26 | function language_switch() |
---|
| 27 | { |
---|
[2162] | 28 | global $user, $template, $conf, $lang; |
---|
| 29 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
[2164] | 30 | $same = $user['language']; |
---|
[2162] | 31 | if ( isset( $_GET['lang']) ) |
---|
[2161] | 32 | { |
---|
[2286] | 33 | if ( !empty($_GET['lang'] ) and |
---|
[2162] | 34 | file_exists( PHPWG_ROOT_PATH.'language/' |
---|
| 35 | . $_GET['lang'].'/common.lang.php') ) |
---|
[2161] | 36 | { |
---|
[2162] | 37 | if (is_a_guest() or is_generic()) |
---|
| 38 | { |
---|
[2286] | 39 | setcookie( 'pwg_lang_switch', $_GET['lang'], |
---|
[2162] | 40 | time()+60*60*24*30, cookie_path() ); |
---|
| 41 | } |
---|
| 42 | else |
---|
| 43 | { |
---|
| 44 | $query = 'UPDATE '.USER_INFOS_TABLE.' |
---|
| 45 | SET language = \''.$_GET['lang'].'\' |
---|
| 46 | WHERE user_id = '.$user['id'].' |
---|
| 47 | ;'; |
---|
| 48 | pwg_query($query); |
---|
| 49 | } |
---|
| 50 | $user['language'] = $_GET['lang']; |
---|
[2161] | 51 | } |
---|
| 52 | } |
---|
| 53 | // Users have $user['language'] |
---|
| 54 | // Guest or generic members will use their cookied language ! |
---|
[2162] | 55 | if ((is_a_guest() or is_generic()) |
---|
| 56 | and isset( $_COOKIE['pwg_lang_switch'] ) ) |
---|
[2286] | 57 | { |
---|
| 58 | $user['language'] = $_COOKIE['pwg_lang_switch']; |
---|
[2162] | 59 | } |
---|
[2164] | 60 | // Reload language only if it isn't the same one |
---|
[2286] | 61 | if ( $same !== $user['language']) |
---|
[2162] | 62 | { |
---|
[2164] | 63 | load_language('common.lang', '', $user['language']); |
---|
| 64 | load_language('local.lang', '', $user['language']); |
---|
| 65 | if (defined('IN_ADMIN') and IN_ADMIN) |
---|
| 66 | { |
---|
| 67 | load_language('admin.lang', '', $user['language']); |
---|
| 68 | } |
---|
[2162] | 69 | } |
---|
[2161] | 70 | } |
---|
| 71 | //if ( isset( $_GET['lang']) ) { redirect( make_index_url() ); } |
---|
| 72 | |
---|
[2286] | 73 | function Lang_flags() |
---|
[2161] | 74 | { |
---|
[2162] | 75 | global $user, $template; |
---|
| 76 | $available_lang = get_languages(); |
---|
| 77 | foreach ( $available_lang as $code => $displayname ) |
---|
| 78 | { |
---|
| 79 | $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) ); |
---|
| 80 | $qlc_alt = ucwords( $displayname ); |
---|
| 81 | $qlc_title = $qlc_alt; |
---|
[2286] | 82 | $qlc_img = 'plugins/language_switch/icons/' |
---|
[2161] | 83 | . $code . '.gif'; |
---|
[2286] | 84 | |
---|
| 85 | if ( $code !== $user['language'] and file_exists(PHPWG_ROOT_PATH.$qlc_img) ) |
---|
[2162] | 86 | { |
---|
[2286] | 87 | $template->concat( 'PLUGIN_INDEX_ACTIONS', |
---|
| 88 | '<li><a href="' . $qlc_url . '" ><img src="' . get_root_url().$qlc_img . '" alt="' |
---|
[2162] | 89 | . $qlc_alt . '" title="' |
---|
[2286] | 90 | . $qlc_title . '" style="border: 1px solid #000000; ' |
---|
[2162] | 91 | . ' margin: 0px 2px;" /></a></li>'); |
---|
| 92 | } |
---|
[2161] | 93 | } |
---|
| 94 | } |
---|
| 95 | ?> |
---|