[2286] | 1 | <?php |
---|
[2161] | 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3049] | 5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[3369] | 23 | if (!defined('LANGUAGE_SWITCH_PATH')) |
---|
| 24 | define('LANGUAGE_SWITCH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
[2161] | 25 | function language_switch() |
---|
| 26 | { |
---|
[2162] | 27 | global $user, $template, $conf, $lang; |
---|
| 28 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
[2164] | 29 | $same = $user['language']; |
---|
[2162] | 30 | if ( isset( $_GET['lang']) ) |
---|
[2161] | 31 | { |
---|
[2286] | 32 | if ( !empty($_GET['lang'] ) and |
---|
[2162] | 33 | file_exists( PHPWG_ROOT_PATH.'language/' |
---|
| 34 | . $_GET['lang'].'/common.lang.php') ) |
---|
[2161] | 35 | { |
---|
[2162] | 36 | if (is_a_guest() or is_generic()) |
---|
| 37 | { |
---|
[2286] | 38 | setcookie( 'pwg_lang_switch', $_GET['lang'], |
---|
[2162] | 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']; |
---|
[2161] | 50 | } |
---|
| 51 | } |
---|
| 52 | // Users have $user['language'] |
---|
| 53 | // Guest or generic members will use their cookied language ! |
---|
[2162] | 54 | if ((is_a_guest() or is_generic()) |
---|
| 55 | and isset( $_COOKIE['pwg_lang_switch'] ) ) |
---|
[2286] | 56 | { |
---|
| 57 | $user['language'] = $_COOKIE['pwg_lang_switch']; |
---|
[2162] | 58 | } |
---|
[2164] | 59 | // Reload language only if it isn't the same one |
---|
[2286] | 60 | if ( $same !== $user['language']) |
---|
[2162] | 61 | { |
---|
[2479] | 62 | load_language('common.lang', '', array('language'=>$user['language']) ); |
---|
| 63 | load_language('local.lang', '', array('language'=>$user['language'], 'no_fallback'=>true) ); |
---|
[2164] | 64 | if (defined('IN_ADMIN') and IN_ADMIN) |
---|
| 65 | { |
---|
[2479] | 66 | load_language('admin.lang', '', array('language'=>$user['language']) ); |
---|
[2164] | 67 | } |
---|
[2162] | 68 | } |
---|
[2161] | 69 | } |
---|
| 70 | //if ( isset( $_GET['lang']) ) { redirect( make_index_url() ); } |
---|
[2286] | 71 | function Lang_flags() |
---|
[2161] | 72 | { |
---|
[2162] | 73 | global $user, $template; |
---|
| 74 | $available_lang = get_languages(); |
---|
[3369] | 75 | $lsw = array(); |
---|
[2162] | 76 | foreach ( $available_lang as $code => $displayname ) |
---|
| 77 | { |
---|
| 78 | $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) ); |
---|
| 79 | $qlc_alt = ucwords( $displayname ); |
---|
[3369] | 80 | $qlc_img = 'plugins/language_switch/icons/' |
---|
| 81 | . $code . '.jpg'; |
---|
| 82 | if ( $code !== $user['language'] and file_exists(PHPWG_ROOT_PATH.$qlc_img) ) |
---|
| 83 | { |
---|
| 84 | $lsw['flags'][$code] = Array( |
---|
| 85 | 'url' => $qlc_url, |
---|
| 86 | 'alt' => $qlc_alt, |
---|
| 87 | 'img' => $qlc_img, |
---|
| 88 | ) ; |
---|
| 89 | } else { |
---|
| 90 | $lsw['Active'] = Array( |
---|
| 91 | 'url' => $qlc_url, |
---|
| 92 | 'alt' => $qlc_alt, |
---|
| 93 | 'img' => $qlc_img, |
---|
| 94 | ); |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl'); |
---|
| 98 | $lsw['side'] = ceil(sqrt(count($available_lang))); |
---|
| 99 | $template->assign(array( |
---|
| 100 | 'lang_switch'=> $lsw, |
---|
| 101 | 'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH, |
---|
| 102 | )); |
---|
| 103 | $flags = $template->parse('language_flags',true); |
---|
| 104 | $template->clear_assign('lang_switch'); |
---|
| 105 | $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags); |
---|
| 106 | // In state of making a $flags each time TODO Caching $flags[$user['language']] |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | if (!function_exists('Componant_exists')) { |
---|
| 110 | function Componant_exists($path, $file) |
---|
| 111 | { |
---|
| 112 | return file_exists( $path . $file); |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | // Should be deleted later |
---|
| 117 | function Lang_flags_previous_function() |
---|
| 118 | { |
---|
| 119 | global $user, $template; |
---|
| 120 | $available_lang = get_languages(); |
---|
| 121 | foreach ( $available_lang as $code => $displayname ) |
---|
| 122 | { |
---|
| 123 | $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) ); |
---|
| 124 | $qlc_alt = ucwords( $displayname ); |
---|
[2162] | 125 | $qlc_title = $qlc_alt; |
---|
[2286] | 126 | $qlc_img = 'plugins/language_switch/icons/' |
---|
[2161] | 127 | . $code . '.gif'; |
---|
[2286] | 128 | |
---|
| 129 | if ( $code !== $user['language'] and file_exists(PHPWG_ROOT_PATH.$qlc_img) ) |
---|
[2162] | 130 | { |
---|
[2286] | 131 | $template->concat( 'PLUGIN_INDEX_ACTIONS', |
---|
| 132 | '<li><a href="' . $qlc_url . '" ><img src="' . get_root_url().$qlc_img . '" alt="' |
---|
[2162] | 133 | . $qlc_alt . '" title="' |
---|
[2286] | 134 | . $qlc_title . '" style="border: 1px solid #000000; ' |
---|
[2162] | 135 | . ' margin: 0px 2px;" /></a></li>'); |
---|
| 136 | } |
---|
[2161] | 137 | } |
---|
| 138 | } |
---|
| 139 | ?> |
---|