[2286] | 1 | <?php |
---|
[2161] | 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[5196] | 5 | // | Copyright(C) 2008-2010 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__)) . '/'); |
---|
[3376] | 25 | class language_controler { |
---|
| 26 | static public function _switch() |
---|
[2161] | 27 | { |
---|
[3376] | 28 | global $user; |
---|
| 29 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
| 30 | $same = $user['language']; |
---|
| 31 | if ( isset( $_GET['lang']) ) { |
---|
| 32 | if ( !empty($_GET['lang'] ) and file_exists( PHPWG_ROOT_PATH.'language/' |
---|
| 33 | . $_GET['lang'].'/common.lang.php') ) { |
---|
| 34 | if (is_a_guest() or is_generic()) { |
---|
| 35 | pwg_set_session_var( 'lang_switch', $_GET['lang'] ); |
---|
| 36 | } else { |
---|
| 37 | $query = 'UPDATE '.USER_INFOS_TABLE.' |
---|
| 38 | SET language = \''.$_GET['lang'].'\' |
---|
| 39 | WHERE user_id = '.$user['id'].' |
---|
| 40 | ;'; |
---|
| 41 | pwg_query($query); |
---|
| 42 | } |
---|
| 43 | $user['language'] = $_GET['lang']; |
---|
[2162] | 44 | } |
---|
[3376] | 45 | } |
---|
| 46 | elseif ((is_a_guest() or is_generic())) { |
---|
| 47 | $user['language'] = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
| 48 | } |
---|
| 49 | // Reload language only if it isn't the same one |
---|
| 50 | if ( $same !== $user['language']) { |
---|
| 51 | load_language('common.lang', '', array('language'=>$user['language']) ); |
---|
[5208] | 52 | load_language('lang', PHPWG_ROOT_PATH.'local/', |
---|
| 53 | array('language'=>$user['language'], 'no_fallback'=>true, 'local'=>true) |
---|
| 54 | ); |
---|
[3376] | 55 | if (defined('IN_ADMIN') and IN_ADMIN) { // Never currently |
---|
| 56 | load_language('admin.lang', '', array('language'=>$user['language']) ); |
---|
[2162] | 57 | } |
---|
[2161] | 58 | } |
---|
| 59 | } |
---|
[3376] | 60 | static public function _flags() |
---|
[2286] | 61 | { |
---|
[3376] | 62 | global $user, $template, $conf; |
---|
| 63 | $available_lang = get_languages(); |
---|
| 64 | if ( isset($conf['no_flag_languages']) ) |
---|
[3479] | 65 | $available_lang = |
---|
| 66 | array_diff_key($available_lang, array_flip($conf['no_flag_languages'])); |
---|
| 67 | $url_starting = get_query_string_diff(array('lang')); |
---|
[3376] | 68 | foreach ( $available_lang as $code => $displayname ) { |
---|
| 69 | $qlc = array ( |
---|
[3479] | 70 | 'url' => str_replace(array('=&','?&'),array('&','?'), |
---|
| 71 | add_url_params( $url_starting, array('lang'=> $code) )), |
---|
[3376] | 72 | 'alt' => ucwords( $displayname ), |
---|
[5845] | 73 | 'img' => get_root_url().'language/' . $code . '/' . $code . '.jpg', |
---|
[3376] | 74 | ); |
---|
[5845] | 75 | if ( $code !== $user['language'] ) |
---|
[3376] | 76 | $lsw['flags'][$code] = $qlc ; |
---|
| 77 | else $lsw['Active'] = $qlc; |
---|
| 78 | } |
---|
| 79 | $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl'); |
---|
| 80 | $lsw['side'] = ceil(sqrt(count($available_lang))); |
---|
| 81 | $template->assign(array( |
---|
| 82 | 'lang_switch'=> $lsw, |
---|
| 83 | 'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH, |
---|
| 84 | )); |
---|
| 85 | $flags = $template->parse('language_flags',true); |
---|
| 86 | $template->clear_assign('lang_switch'); |
---|
| 87 | $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags); |
---|
[2162] | 88 | } |
---|
[2161] | 89 | } |
---|
[3376] | 90 | /* {html_head} usage function */ |
---|
| 91 | /* See flags.tpl for example (due no catenation available) */ |
---|
[3369] | 92 | if (!function_exists('Componant_exists')) { |
---|
[3376] | 93 | function Componant_exists($path, $file) |
---|
| 94 | { return file_exists( $path . $file); } |
---|
[3369] | 95 | } |
---|
| 96 | |
---|
[2161] | 97 | ?> |
---|