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