diff options
author | vdigital <vdigital@piwigo.org> | 2007-11-19 19:51:54 +0000 |
---|---|---|
committer | vdigital <vdigital@piwigo.org> | 2007-11-19 19:51:54 +0000 |
commit | 4601ff1c36bd076cc2867c33e470c62c9d728c8a (patch) | |
tree | 55ff7c9fc3c5a988e9535c505e5e5bfedcb22c43 /plugins/language_switch | |
parent | 51e3d211c85f413fbce8d78cbe172bf1e7f1829f (diff) |
Minor code review
git-svn-id: http://piwigo.org/svn/trunk@2162 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | plugins/language_switch/language_switch.inc.php | 109 | ||||
-rw-r--r-- | plugins/language_switch/main.inc.php | 4 |
2 files changed, 49 insertions, 64 deletions
diff --git a/plugins/language_switch/language_switch.inc.php b/plugins/language_switch/language_switch.inc.php index 5ae57956f..2a5c37dbc 100644 --- a/plugins/language_switch/language_switch.inc.php +++ b/plugins/language_switch/language_switch.inc.php @@ -1,11 +1,4 @@ -<?php /* -Plugin Name: Language Switch -Version: 1.0 -Description: Give you an advice on the administration page. -Plugin URI: http://www.phpwebgallery.net -Author: PhpWebGallery team -Author URI: http://www.phpwebgallery.net -*/ +<?php // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | @@ -32,75 +25,67 @@ Author URI: http://www.phpwebgallery.net // +-----------------------------------------------------------------------+ function language_switch() { -global $user, $template, $conf, $lang; - -if (!isset($user['status'])) -{ die('You are not authorized to access this page'); }; - -if ( isset( $_GET['lang']) ) -{ - if ( !empty($_GET['lang'] ) and - file_exists( PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php') ) + global $user, $template, $conf, $lang; + if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } + if ( isset( $_GET['lang']) ) { - if ($user['is_the_guest'] or $user['status'] == 'generic') + if ( !empty($_GET['lang'] ) and + file_exists( PHPWG_ROOT_PATH.'language/' + . $_GET['lang'].'/common.lang.php') ) { - setcookie( 'pwg_lang_switch', $_GET['lang'], - time()+60*60*24*30, cookie_path() ); + if (is_a_guest() or is_generic()) + { + setcookie( 'pwg_lang_switch', $_GET['lang'], + time()+60*60*24*30, cookie_path() ); + } + else + { + $query = 'UPDATE '.USER_INFOS_TABLE.' + SET language = \''.$_GET['lang'].'\' + WHERE user_id = '.$user['id'].' + ;'; + pwg_query($query); + } + $user['language'] = $_GET['lang']; } - else - { - $query = ' - UPDATE '.USER_INFOS_TABLE.' - SET language = \''.$_GET['lang'].'\' - WHERE user_id = '.$user['id'].' - ;'; - pwg_query($query); - } - $user['language'] = $_GET['lang']; } -} // Users have $user['language'] // Guest or generic members will use their cookied language ! + if ((is_a_guest() or is_generic()) + and isset( $_COOKIE['pwg_lang_switch'] ) ) + { + $user['language'] = $_COOKIE['pwg_lang_switch']; + } -if ((is_a_guest() or is_generic()) - and isset( $_COOKIE['pwg_lang_switch'] ) ) -{ $user['language'] = $_COOKIE['pwg_lang_switch']; } - -load_language('common.lang', '', $user['language']); -load_language('local.lang', '', $user['language']); -if (defined('IN_ADMIN') and IN_ADMIN) -{ - load_language('admin.lang', '', $user['language']); -} + load_language('common.lang', '', $user['language']); + load_language('local.lang', '', $user['language']); + if (defined('IN_ADMIN') and IN_ADMIN) + { + load_language('admin.lang', '', $user['language']); + } } //if ( isset( $_GET['lang']) ) { redirect( make_index_url() ); } - - - - function Lang_flags() { -global $user, $template; -$available_lang = get_languages(); -foreach ( $available_lang as $code => $displayname ) -{ - $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) ); - $qlc_alt = ucwords( $displayname ); - $qlc_title = $qlc_alt; - $qlc_img = PHPWG_PLUGINS_PATH.'language_switch/icons/' + global $user, $template; + $available_lang = get_languages(); + foreach ( $available_lang as $code => $displayname ) + { + $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) ); + $qlc_alt = ucwords( $displayname ); + $qlc_title = $qlc_alt; + $qlc_img = PHPWG_PLUGINS_PATH.'language_switch/icons/' . $code . '.gif'; - // echo $code . ' '. $qlc_url .' // <br />'; - // echo $user['language'] . ' '. $qlc_img .' /// <br />'; if ( $code !== $user['language'] and file_exists($qlc_img) ) - { - $template -> concat_var( 'PLUGIN_INDEX_ACTIONS', - '<li><a href="' . $qlc_url . '" ><img src="' . $qlc_img . '" alt="' - . $qlc_alt . '" title="' - . $qlc_title . '" style="border: 1px solid #000000; ' - . ' margin: 0px 2px;" /></a></li>'); + { + $template -> concat_var( 'PLUGIN_INDEX_ACTIONS', + '<li><a href="' . $qlc_url . '" ><img src="' . $qlc_img . '" alt="' + . $qlc_alt . '" title="' + . $qlc_title . '" style="border: 1px solid #000000; ' + . ' margin: 0px 2px;" /></a></li>'); + } } } -} ?>
\ No newline at end of file diff --git a/plugins/language_switch/main.inc.php b/plugins/language_switch/main.inc.php index 8be206563..82eb5dc2e 100644 --- a/plugins/language_switch/main.inc.php +++ b/plugins/language_switch/main.inc.php @@ -1,7 +1,7 @@ <?php /* Plugin Name: Language Switch Version: 1.0 -Description: Give you an advice on the administration page. +Description: Switch to another language from flags on your gallery home page. Plugin URI: http://www.phpwebgallery.net Author: PhpWebGallery team Author URI: http://www.phpwebgallery.net @@ -30,7 +30,7 @@ Author URI: http://www.phpwebgallery.net // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | // | USA. | // +-----------------------------------------------------------------------+ -add_event_handler('loading_lang', 'language_switch' ); include_once(PHPWG_PLUGINS_PATH.'language_switch/language_switch.inc.php'); +add_event_handler('loading_lang', 'language_switch' ); add_event_handler('loc_end_index', 'Lang_flags' ); ?>
\ No newline at end of file |