[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__)) . '/'); |
---|
[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']) ); |
---|
| 52 | load_language('local.lang', '', array('language'=>$user['language'], 'no_fallback'=>true) ); |
---|
| 53 | if (defined('IN_ADMIN') and IN_ADMIN) { // Never currently |
---|
| 54 | load_language('admin.lang', '', array('language'=>$user['language']) ); |
---|
[2162] | 55 | } |
---|
[2161] | 56 | } |
---|
| 57 | } |
---|
[3376] | 58 | static public function _flags() |
---|
[2286] | 59 | { |
---|
[3376] | 60 | global $user, $template, $conf; |
---|
| 61 | $available_lang = get_languages(); |
---|
| 62 | if ( isset($conf['no_flag_languages']) ) |
---|
| 63 | $available_lang = array_diff_key($available_lang, array_flip($conf['no_flag_languages'])); |
---|
| 64 | $url_starting = $_SERVER['REQUEST_URI']; |
---|
| 65 | if ( isset( $_GET['lang']) ) { |
---|
| 66 | $pos = stripos ( $url_starting , '&lang=' ); |
---|
| 67 | if (is_numeric($pos) and $pos > 0) $url_starting = substr($url_starting, 0, $pos); |
---|
[2164] | 68 | } |
---|
[3376] | 69 | $pos = stripos($url_starting, script_basename()); |
---|
| 70 | if (is_numeric($pos)) $url_starting = substr($url_starting, $pos); |
---|
| 71 | foreach ( $available_lang as $code => $displayname ) { |
---|
| 72 | $qlc = array ( |
---|
| 73 | 'url' => add_url_params( $url_starting, array('lang'=> $code) ), |
---|
| 74 | 'alt' => ucwords( $displayname ), |
---|
| 75 | 'img' => 'plugins/language_switch/icons/' . $code . '.jpg', |
---|
| 76 | ); |
---|
| 77 | if ( $code !== $user['language'] and file_exists(PHPWG_ROOT_PATH.$qlc['img']) ) |
---|
| 78 | $lsw['flags'][$code] = $qlc ; |
---|
| 79 | else $lsw['Active'] = $qlc; |
---|
| 80 | } |
---|
| 81 | $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl'); |
---|
| 82 | $lsw['side'] = ceil(sqrt(count($available_lang))); |
---|
| 83 | $template->assign(array( |
---|
| 84 | 'lang_switch'=> $lsw, |
---|
| 85 | 'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH, |
---|
| 86 | )); |
---|
| 87 | $flags = $template->parse('language_flags',true); |
---|
| 88 | $template->clear_assign('lang_switch'); |
---|
| 89 | $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags); |
---|
| 90 | // TODO : Try to cache $flags and $user['language'] in $_SESSION for performance |
---|
[2162] | 91 | } |
---|
[2161] | 92 | } |
---|
[3376] | 93 | /* {html_head} usage function */ |
---|
| 94 | /* See flags.tpl for example (due no catenation available) */ |
---|
[3369] | 95 | if (!function_exists('Componant_exists')) { |
---|
[3376] | 96 | function Componant_exists($path, $file) |
---|
| 97 | { return file_exists( $path . $file); } |
---|
[3369] | 98 | } |
---|
| 99 | |
---|
[2161] | 100 | ?> |
---|