2008-03-20 01:35:36 +01:00
|
|
|
<?php
|
2007-11-18 20:59:33 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2008-04-05 00:57:23 +02:00
|
|
|
// | Piwigo - a PHP based picture gallery |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2009-01-05 00:28:36 +01:00
|
|
|
// | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org |
|
2008-04-05 00:57:23 +02:00
|
|
|
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
|
|
|
|
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | This program is free software; you can redistribute it and/or modify |
|
|
|
|
// | it under the terms of the GNU General Public License as published by |
|
2007-11-18 20:59:33 +01:00
|
|
|
// | the Free Software Foundation |
|
|
|
|
// | |
|
|
|
|
// | This program is distributed in the hope that it will be useful, but |
|
|
|
|
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
|
// | General Public License for more details. |
|
|
|
|
// | |
|
|
|
|
// | You should have received a copy of the GNU General Public License |
|
|
|
|
// | along with this program; if not, write to the Free Software |
|
|
|
|
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
|
|
|
// | USA. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
function language_switch()
|
|
|
|
{
|
2007-11-19 20:51:54 +01:00
|
|
|
global $user, $template, $conf, $lang;
|
|
|
|
if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
|
2007-11-20 22:37:05 +01:00
|
|
|
$same = $user['language'];
|
2007-11-19 20:51:54 +01:00
|
|
|
if ( isset( $_GET['lang']) )
|
2007-11-18 20:59:33 +01:00
|
|
|
{
|
2008-03-20 01:35:36 +01:00
|
|
|
if ( !empty($_GET['lang'] ) and
|
2007-11-19 20:51:54 +01:00
|
|
|
file_exists( PHPWG_ROOT_PATH.'language/'
|
|
|
|
. $_GET['lang'].'/common.lang.php') )
|
2007-11-18 20:59:33 +01:00
|
|
|
{
|
2007-11-19 20:51:54 +01:00
|
|
|
if (is_a_guest() or is_generic())
|
|
|
|
{
|
2008-03-20 01:35:36 +01:00
|
|
|
setcookie( 'pwg_lang_switch', $_GET['lang'],
|
2007-11-19 20:51:54 +01:00
|
|
|
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'];
|
2007-11-18 20:59:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Users have $user['language']
|
|
|
|
// Guest or generic members will use their cookied language !
|
2007-11-19 20:51:54 +01:00
|
|
|
if ((is_a_guest() or is_generic())
|
|
|
|
and isset( $_COOKIE['pwg_lang_switch'] ) )
|
2008-03-20 01:35:36 +01:00
|
|
|
{
|
|
|
|
$user['language'] = $_COOKIE['pwg_lang_switch'];
|
2007-11-19 20:51:54 +01:00
|
|
|
}
|
2007-11-20 22:37:05 +01:00
|
|
|
// Reload language only if it isn't the same one
|
2008-03-20 01:35:36 +01:00
|
|
|
if ( $same !== $user['language'])
|
2007-11-19 20:51:54 +01:00
|
|
|
{
|
2008-08-20 02:35:22 +02:00
|
|
|
load_language('common.lang', '', array('language'=>$user['language']) );
|
|
|
|
load_language('local.lang', '', array('language'=>$user['language'], 'no_fallback'=>true) );
|
2007-11-20 22:37:05 +01:00
|
|
|
if (defined('IN_ADMIN') and IN_ADMIN)
|
|
|
|
{
|
2008-08-20 02:35:22 +02:00
|
|
|
load_language('admin.lang', '', array('language'=>$user['language']) );
|
2007-11-20 22:37:05 +01:00
|
|
|
}
|
2007-11-19 20:51:54 +01:00
|
|
|
}
|
2007-11-18 20:59:33 +01:00
|
|
|
}
|
|
|
|
//if ( isset( $_GET['lang']) ) { redirect( make_index_url() ); }
|
|
|
|
|
2008-03-20 01:35:36 +01:00
|
|
|
function Lang_flags()
|
2007-11-18 20:59:33 +01:00
|
|
|
{
|
2007-11-19 20:51:54 +01:00
|
|
|
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;
|
2008-03-20 01:35:36 +01:00
|
|
|
$qlc_img = 'plugins/language_switch/icons/'
|
2007-11-18 20:59:33 +01:00
|
|
|
. $code . '.gif';
|
2008-03-20 01:35:36 +01:00
|
|
|
|
|
|
|
if ( $code !== $user['language'] and file_exists(PHPWG_ROOT_PATH.$qlc_img) )
|
2007-11-19 20:51:54 +01:00
|
|
|
{
|
2008-03-20 01:35:36 +01:00
|
|
|
$template->concat( 'PLUGIN_INDEX_ACTIONS',
|
|
|
|
'<li><a href="' . $qlc_url . '" ><img src="' . get_root_url().$qlc_img . '" alt="'
|
2007-11-19 20:51:54 +01:00
|
|
|
. $qlc_alt . '" title="'
|
2008-03-20 01:35:36 +01:00
|
|
|
. $qlc_title . '" style="border: 1px solid #000000; '
|
2007-11-19 20:51:54 +01:00
|
|
|
. ' margin: 0px 2px;" /></a></li>');
|
|
|
|
}
|
2007-11-18 20:59:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|