diff options
author | plegall <plg@piwigo.org> | 2011-05-30 22:58:12 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2011-05-30 22:58:12 +0000 |
commit | 04a4a062b2098b42fe0622b36b2b48ba5881c1b2 (patch) | |
tree | 48e9f7c0d382ce5acd4cc9f5aa72c3dfea125a7e /plugins/language_switch/language_switch.inc.php | |
parent | f650346a8def3fb9bd75ef103841c700215d6580 (diff) |
refactor language switch PHP code to make it readable
git-svn-id: http://piwigo.org/svn/trunk@11123 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | plugins/language_switch/language_switch.inc.php | 124 |
1 files changed, 87 insertions, 37 deletions
diff --git a/plugins/language_switch/language_switch.inc.php b/plugins/language_switch/language_switch.inc.php index c24fcd1a8..a1d85a4ca 100644 --- a/plugins/language_switch/language_switch.inc.php +++ b/plugins/language_switch/language_switch.inc.php @@ -20,58 +20,98 @@ // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | // | USA. | // +-----------------------------------------------------------------------+ + if (!defined('LANGUAGE_SWITCH_PATH')) -define('LANGUAGE_SWITCH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); -class language_controler { +{ + define('LANGUAGE_SWITCH_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); +} + +class language_controler +{ static public function _switch() { global $user; - if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } + + if (!defined('PHPWG_ROOT_PATH')) + { + die('Hacking attempt!'); + } + $same = $user['language']; - if ( isset( $_GET['lang']) ) { - if ( !empty($_GET['lang'] ) and file_exists( PHPWG_ROOT_PATH.'language/' - . $_GET['lang'].'/common.lang.php') ) { - if (is_a_guest() or is_generic()) { - pwg_set_session_var( 'lang_switch', $_GET['lang'] ); - } else { - $query = 'UPDATE '.USER_INFOS_TABLE.' - SET language = \''.$_GET['lang'].'\' - WHERE user_id = '.$user['id'].' - ;'; + + if (isset($_GET['lang'])) + { + if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php')) + { + if (is_a_guest() or is_generic()) + { + pwg_set_session_var('lang_switch', $_GET['lang']); + } + else + { + $query = ' +UPDATE '.USER_INFOS_TABLE.' + SET language = \''.$_GET['lang'].'\' + WHERE user_id = '.$user['id'].' +;'; pwg_query($query); } + $user['language'] = $_GET['lang']; } } - elseif ((is_a_guest() or is_generic())) { - $user['language'] = pwg_get_session_var( 'lang_switch', $user['language'] ); + elseif ((is_a_guest() or is_generic())) + { + $user['language'] = pwg_get_session_var('lang_switch', $user['language']); } - // Reload language only if it isn't the same one - if ( $same !== $user['language']) { - load_language('common.lang', '', array('language'=>$user['language']) ); - load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR, - array('language'=>$user['language'], 'no_fallback'=>true, 'local'=>true) - ); - if (defined('IN_ADMIN') and IN_ADMIN) { // Never currently - load_language('admin.lang', '', array('language'=>$user['language']) ); + + // Reload language only if it isn't the same one + if ( $same !== $user['language']) + { + load_language('common.lang', '', array('language'=>$user['language'])); + + load_language( + 'lang', + PHPWG_ROOT_PATH.PWG_LOCAL_DIR, + array( + 'language' => $user['language'], + 'no_fallback' => true, + 'local' => true + ) + ); + + if (defined('IN_ADMIN') and IN_ADMIN) + { + // Never currently + load_language('admin.lang', '', array('language'=>$user['language'])); } } } + static public function _flags() { global $user, $template, $conf; + $available_lang = get_languages(); - if ( isset($conf['no_flag_languages']) ) - $available_lang = - array_diff_key($available_lang, array_flip($conf['no_flag_languages'])); + + if (isset($conf['no_flag_languages'])) + { + $available_lang = array_diff_key($available_lang, array_flip($conf['no_flag_languages'])); + } + $url_starting = get_query_string_diff(array('lang')); - foreach ( $available_lang as $code => $displayname ) { + + foreach ($available_lang as $code => $displayname) + { $qlc = array ( - 'url' => str_replace(array('=&','?&'),array('&','?'), - add_url_params( $url_starting, array('lang'=> $code) )), - 'alt' => ucwords( $displayname ), + 'url' => str_replace( + array('=&','?&'), + array('&','?'), + add_url_params($url_starting, array('lang'=> $code)) + ), + 'alt' => ucwords($displayname), 'title' => substr($displayname, 0, -4), // remove [FR] or [RU] - 'img' => get_root_url().'language/' . $code . '/' . $code . '.jpg', + 'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg', ); $lsw['flags'][$code] = $qlc ; @@ -81,22 +121,32 @@ class language_controler { $lsw['Active'] = $qlc; } } + $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl'); + $lsw['side'] = ceil(sqrt(count($available_lang))); - $template->assign(array( - 'lang_switch'=> $lsw, - 'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH, - )); + + $template->assign( + array( + 'lang_switch'=> $lsw, + 'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH, + ) + ); + $flags = $template->parse('language_flags',true); $template->clear_assign('lang_switch'); $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags); } } + /* {html_head} usage function */ /* See flags.tpl for example (due no catenation available) */ -if (!function_exists('Componant_exists')) { +if (!function_exists('Componant_exists')) +{ function Componant_exists($path, $file) - { return file_exists( $path . $file); } + { + return file_exists( $path . $file); + } } ?>
\ No newline at end of file |