1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2011 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 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if (!defined('LANGUAGE_SWITCH_PATH')) |
---|
25 | { |
---|
26 | define('LANGUAGE_SWITCH_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
27 | } |
---|
28 | |
---|
29 | class language_controler |
---|
30 | { |
---|
31 | static public function _switch() |
---|
32 | { |
---|
33 | global $user; |
---|
34 | |
---|
35 | if (!defined('PHPWG_ROOT_PATH')) |
---|
36 | { |
---|
37 | die('Hacking attempt!'); |
---|
38 | } |
---|
39 | |
---|
40 | $same = $user['language']; |
---|
41 | |
---|
42 | if (isset($_GET['lang'])) |
---|
43 | { |
---|
44 | if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php')) |
---|
45 | { |
---|
46 | if (is_a_guest() or is_generic()) |
---|
47 | { |
---|
48 | pwg_set_session_var('lang_switch', $_GET['lang']); |
---|
49 | } |
---|
50 | else |
---|
51 | { |
---|
52 | $query = ' |
---|
53 | UPDATE '.USER_INFOS_TABLE.' |
---|
54 | SET language = \''.$_GET['lang'].'\' |
---|
55 | WHERE user_id = '.$user['id'].' |
---|
56 | ;'; |
---|
57 | pwg_query($query); |
---|
58 | } |
---|
59 | |
---|
60 | $user['language'] = $_GET['lang']; |
---|
61 | } |
---|
62 | } |
---|
63 | elseif ((is_a_guest() or is_generic())) |
---|
64 | { |
---|
65 | $user['language'] = pwg_get_session_var('lang_switch', $user['language']); |
---|
66 | } |
---|
67 | |
---|
68 | // Reload language only if it isn't the same one |
---|
69 | if ( $same !== $user['language']) |
---|
70 | { |
---|
71 | load_language('common.lang', '', array('language'=>$user['language'])); |
---|
72 | |
---|
73 | load_language( |
---|
74 | 'lang', |
---|
75 | PHPWG_ROOT_PATH.PWG_LOCAL_DIR, |
---|
76 | array( |
---|
77 | 'language' => $user['language'], |
---|
78 | 'no_fallback' => true, |
---|
79 | 'local' => true |
---|
80 | ) |
---|
81 | ); |
---|
82 | |
---|
83 | if (defined('IN_ADMIN') and IN_ADMIN) |
---|
84 | { |
---|
85 | // Never currently |
---|
86 | load_language('admin.lang', '', array('language'=>$user['language'])); |
---|
87 | } |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | static public function _flags() |
---|
92 | { |
---|
93 | global $user, $template, $conf; |
---|
94 | |
---|
95 | $available_lang = get_languages(); |
---|
96 | |
---|
97 | if (isset($conf['no_flag_languages'])) |
---|
98 | { |
---|
99 | $available_lang = array_diff_key($available_lang, array_flip($conf['no_flag_languages'])); |
---|
100 | } |
---|
101 | |
---|
102 | $url_starting = get_query_string_diff(array('lang')); |
---|
103 | |
---|
104 | foreach ($available_lang as $code => $displayname) |
---|
105 | { |
---|
106 | $qlc = array ( |
---|
107 | 'url' => str_replace( |
---|
108 | array('=&','?&'), |
---|
109 | array('&','?'), |
---|
110 | add_url_params($url_starting, array('lang'=> $code)) |
---|
111 | ), |
---|
112 | 'alt' => ucwords($displayname), |
---|
113 | 'title' => substr($displayname, 0, -4), // remove [FR] or [RU] |
---|
114 | 'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg', |
---|
115 | ); |
---|
116 | |
---|
117 | $lsw['flags'][$code] = $qlc ; |
---|
118 | |
---|
119 | if ($code == $user['language']) |
---|
120 | { |
---|
121 | $lsw['Active'] = $qlc; |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | $template->set_filename('language_flags', dirname(__FILE__) . '/flags.tpl'); |
---|
126 | |
---|
127 | $lsw['side'] = ceil(sqrt(count($available_lang))); |
---|
128 | |
---|
129 | $template->assign( |
---|
130 | array( |
---|
131 | 'lang_switch'=> $lsw, |
---|
132 | 'LANGUAGE_SWITCH_PATH' => LANGUAGE_SWITCH_PATH, |
---|
133 | ) |
---|
134 | ); |
---|
135 | |
---|
136 | $flags = $template->parse('language_flags',true); |
---|
137 | $template->clear_assign('lang_switch'); |
---|
138 | $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags); |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | /* {html_head} usage function */ |
---|
143 | /* See flags.tpl for example (due no catenation available) */ |
---|
144 | if (!function_exists('Componant_exists')) |
---|
145 | { |
---|
146 | function Componant_exists($path, $file) |
---|
147 | { |
---|
148 | return file_exists( $path . $file); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | ?> |
---|