[2286] | 1 | <?php |
---|
[2161] | 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[2161] | 23 | function language_switch() |
---|
| 24 | { |
---|
[2162] | 25 | global $user, $template, $conf, $lang; |
---|
| 26 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
[2164] | 27 | $same = $user['language']; |
---|
[2162] | 28 | if ( isset( $_GET['lang']) ) |
---|
[2161] | 29 | { |
---|
[2286] | 30 | if ( !empty($_GET['lang'] ) and |
---|
[2162] | 31 | file_exists( PHPWG_ROOT_PATH.'language/' |
---|
| 32 | . $_GET['lang'].'/common.lang.php') ) |
---|
[2161] | 33 | { |
---|
[2162] | 34 | if (is_a_guest() or is_generic()) |
---|
| 35 | { |
---|
[2286] | 36 | setcookie( 'pwg_lang_switch', $_GET['lang'], |
---|
[2162] | 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']; |
---|
[2161] | 48 | } |
---|
| 49 | } |
---|
| 50 | // Users have $user['language'] |
---|
| 51 | // Guest or generic members will use their cookied language ! |
---|
[2162] | 52 | if ((is_a_guest() or is_generic()) |
---|
| 53 | and isset( $_COOKIE['pwg_lang_switch'] ) ) |
---|
[2286] | 54 | { |
---|
| 55 | $user['language'] = $_COOKIE['pwg_lang_switch']; |
---|
[2162] | 56 | } |
---|
[2164] | 57 | // Reload language only if it isn't the same one |
---|
[2286] | 58 | if ( $same !== $user['language']) |
---|
[2162] | 59 | { |
---|
[2479] | 60 | load_language('common.lang', '', array('language'=>$user['language']) ); |
---|
| 61 | load_language('local.lang', '', array('language'=>$user['language'], 'no_fallback'=>true) ); |
---|
[2164] | 62 | if (defined('IN_ADMIN') and IN_ADMIN) |
---|
| 63 | { |
---|
[2479] | 64 | load_language('admin.lang', '', array('language'=>$user['language']) ); |
---|
[2164] | 65 | } |
---|
[2162] | 66 | } |
---|
[2161] | 67 | } |
---|
| 68 | //if ( isset( $_GET['lang']) ) { redirect( make_index_url() ); } |
---|
| 69 | |
---|
[2286] | 70 | function Lang_flags() |
---|
[2161] | 71 | { |
---|
[2162] | 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; |
---|
[2286] | 79 | $qlc_img = 'plugins/language_switch/icons/' |
---|
[2161] | 80 | . $code . '.gif'; |
---|
[2286] | 81 | |
---|
| 82 | if ( $code !== $user['language'] and file_exists(PHPWG_ROOT_PATH.$qlc_img) ) |
---|
[2162] | 83 | { |
---|
[2286] | 84 | $template->concat( 'PLUGIN_INDEX_ACTIONS', |
---|
| 85 | '<li><a href="' . $qlc_url . '" ><img src="' . get_root_url().$qlc_img . '" alt="' |
---|
[2162] | 86 | . $qlc_alt . '" title="' |
---|
[2286] | 87 | . $qlc_title . '" style="border: 1px solid #000000; ' |
---|
[2162] | 88 | . ' margin: 0px 2px;" /></a></li>'); |
---|
| 89 | } |
---|
[2161] | 90 | } |
---|
| 91 | } |
---|
| 92 | ?> |
---|