source: trunk/plugins/language_switch/language_switch.inc.php @ 3369

Last change on this file since 3369 was 3369, checked in by vdigital, 15 years ago

Merge: 3368
+ Language Switch enhanced design and concepts.

  • Property svn:eol-style set to LF
File size: 5.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23if (!defined('LANGUAGE_SWITCH_PATH'))
24define('LANGUAGE_SWITCH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
25function language_switch()
26{
27  global $user, $template, $conf, $lang;
28  if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
29  $same = $user['language'];
30  if ( isset( $_GET['lang']) )
31  {
32    if ( !empty($_GET['lang'] ) and
33      file_exists( PHPWG_ROOT_PATH.'language/'
34      . $_GET['lang'].'/common.lang.php') )
35    {
36      if (is_a_guest() or is_generic())
37      {
38        setcookie( 'pwg_lang_switch', $_GET['lang'],
39          time()+60*60*24*30, cookie_path() );
40      }
41      else
42      {
43        $query = 'UPDATE '.USER_INFOS_TABLE.'
44        SET language = \''.$_GET['lang'].'\'
45        WHERE user_id = '.$user['id'].'
46        ;';
47        pwg_query($query);
48      }
49      $user['language'] = $_GET['lang'];
50    }
51  }
52// Users have $user['language']
53// Guest or generic members will use their cookied language !
54  if ((is_a_guest() or is_generic())
55    and isset( $_COOKIE['pwg_lang_switch'] ) )
56  {
57    $user['language'] = $_COOKIE['pwg_lang_switch'];
58  }
59// Reload language only if it isn't the same one
60  if ( $same !== $user['language'])
61  {
62    load_language('common.lang', '', array('language'=>$user['language']) );
63    load_language('local.lang', '', array('language'=>$user['language'], 'no_fallback'=>true) );
64    if (defined('IN_ADMIN') and IN_ADMIN)
65    {
66      load_language('admin.lang', '', array('language'=>$user['language']) );
67    }
68  }
69}
70//if ( isset( $_GET['lang']) ) { redirect( make_index_url() ); }
71function Lang_flags()
72{
73  global $user, $template;
74  $available_lang = get_languages();
75        $lsw = array();
76  foreach ( $available_lang as $code => $displayname )
77  {
78    $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) );
79    $qlc_alt = ucwords( $displayname );
80    $qlc_img =  'plugins/language_switch/icons/'
81       . $code . '.jpg';
82    if ( $code !== $user['language'] and file_exists(PHPWG_ROOT_PATH.$qlc_img) )
83    {
84      $lsw['flags'][$code] = Array(
85                                'url' => $qlc_url,
86                                'alt' => $qlc_alt,
87                                'img' => $qlc_img,
88                        ) ;
89    } else {
90                        $lsw['Active'] = Array(
91                                'url' => $qlc_url,
92                                'alt' => $qlc_alt,
93                                'img' => $qlc_img,
94                        );
95                }
96  }
97        $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl');
98        $lsw['side'] = ceil(sqrt(count($available_lang)));
99        $template->assign(array(
100                'lang_switch'=> $lsw,
101                'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH,
102        ));
103        $flags = $template->parse('language_flags',true);
104        $template->clear_assign('lang_switch');
105        $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags);
106        // In state of making a $flags each time TODO Caching $flags[$user['language']]
107}
108
109if (!function_exists('Componant_exists')) {
110        function Componant_exists($path, $file)
111        {
112          return file_exists( $path . $file);
113        }
114}
115
116// Should be deleted later
117function Lang_flags_previous_function()
118{
119  global $user, $template;
120  $available_lang = get_languages();
121  foreach ( $available_lang as $code => $displayname )
122  {
123    $qlc_url = add_url_params( make_index_url(), array( 'lang' => $code ) );
124    $qlc_alt = ucwords( $displayname );
125    $qlc_title =  $qlc_alt;
126    $qlc_img =  'plugins/language_switch/icons/'
127       . $code . '.gif';
128
129    if ( $code !== $user['language'] and file_exists(PHPWG_ROOT_PATH.$qlc_img) )
130    {
131      $template->concat( 'PLUGIN_INDEX_ACTIONS',
132        '<li><a href="' . $qlc_url . '" ><img src="' . get_root_url().$qlc_img . '" alt="'
133        . $qlc_alt . '" title="'
134        . $qlc_title . '" style="border: 1px solid #000000; '
135        . ' margin: 0px 2px;" /></a></li>');
136    }
137  }
138}
139?>
Note: See TracBrowser for help on using the repository browser.