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 | /* |
---|
25 | Plugin Name: Language Switch Menubar |
---|
26 | Version: auto |
---|
27 | Description: Switch to another language from flags on your menubar gallery. |
---|
28 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=601 |
---|
29 | Author: ddtddt |
---|
30 | Author URI: http://piwigo.org |
---|
31 | */ |
---|
32 | |
---|
33 | if (!defined('PHPWG_ROOT_PATH')) |
---|
34 | { |
---|
35 | die('Hacking attempt!'); |
---|
36 | } |
---|
37 | |
---|
38 | define('LSM_DIR' , basename(dirname(__FILE__))); |
---|
39 | define('LSM_PATH' , PHPWG_PLUGINS_PATH . LSM_DIR . '/'); |
---|
40 | |
---|
41 | add_event_handler('blockmanager_register_blocks', 'register_lsm_menubar_blocks'); |
---|
42 | add_event_handler('blockmanager_apply', 'lsm_apply'); |
---|
43 | add_event_handler('loading_lang', 'reloadlang'); |
---|
44 | |
---|
45 | function register_lsm_menubar_blocks( $menu_ref_arr ) |
---|
46 | { |
---|
47 | $menu = & $menu_ref_arr[0]; |
---|
48 | if ($menu->get_id() != 'menubar') |
---|
49 | return; |
---|
50 | $menu->register_block( new RegisteredBlock( 'mbLSM', 'lsm', 'LSM')); |
---|
51 | } |
---|
52 | |
---|
53 | function lsm_apply($menu_ref_arr) |
---|
54 | { |
---|
55 | global $template, $user, $template, $conf, $page; |
---|
56 | |
---|
57 | $menu = & $menu_ref_arr[0]; |
---|
58 | |
---|
59 | load_language('plugin.lang', LSM_PATH); |
---|
60 | $template->assign( |
---|
61 | array ( |
---|
62 | 'LSMTITLE' => l10n('Language'), |
---|
63 | ) |
---|
64 | ); |
---|
65 | |
---|
66 | if (($block = $menu->get_block( 'mbLSM' )) != null) |
---|
67 | { |
---|
68 | $template->set_template_dir(LSM_PATH.'template/'); |
---|
69 | $block->template = 'flags.tpl'; |
---|
70 | } |
---|
71 | |
---|
72 | if (isset($page['section']) and $page['section'] == 'additional_page' and isset($page['additional_page'])) |
---|
73 | { |
---|
74 | $base_url = make_index_url(array('section'=>'page')).'/'.(isset($page['additional_page']['permalink']) ? $page['additional_page']['permalink'] : $page['additional_page']['id']); |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | $base_url = duplicate_index_url(); |
---|
79 | } |
---|
80 | |
---|
81 | $available_lang = get_languages(); |
---|
82 | foreach ($available_lang as $code => $displayname) |
---|
83 | { |
---|
84 | $qlc = array ( |
---|
85 | 'url' => add_url_params($base_url, array('lang'=> $code)), |
---|
86 | 'alt' => ucwords($displayname), |
---|
87 | 'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg', |
---|
88 | ); |
---|
89 | |
---|
90 | $lsw['flags'][$code] = $qlc ; |
---|
91 | |
---|
92 | if ($code == $user['language']) |
---|
93 | { |
---|
94 | $lsw['Active'] = $qlc; |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | $lsw['side'] = ceil(sqrt(count($available_lang))); |
---|
99 | $template->clear_assign('lang_switch'); |
---|
100 | $template->assign( |
---|
101 | array( |
---|
102 | 'lang_switch'=> $lsw, |
---|
103 | 'LSM_PATH' => LSM_PATH, |
---|
104 | ) |
---|
105 | ); |
---|
106 | } |
---|
107 | |
---|
108 | function reloadlang() |
---|
109 | { |
---|
110 | global $user; |
---|
111 | $same = $user['language']; |
---|
112 | |
---|
113 | if (isset($_GET['lang'])) |
---|
114 | { |
---|
115 | if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php')) |
---|
116 | { |
---|
117 | if (is_a_guest() or is_generic()) |
---|
118 | { |
---|
119 | pwg_set_session_var('lang_switch', $_GET['lang']); |
---|
120 | } |
---|
121 | else |
---|
122 | { |
---|
123 | $query = ' |
---|
124 | UPDATE '.USER_INFOS_TABLE.' |
---|
125 | SET language = \''.$_GET['lang'].'\' |
---|
126 | WHERE user_id = '.$user['id'].' |
---|
127 | ;'; |
---|
128 | pwg_query($query); |
---|
129 | } |
---|
130 | $user['language'] = $_GET['lang']; |
---|
131 | } |
---|
132 | } |
---|
133 | elseif ((is_a_guest() or is_generic())) |
---|
134 | { |
---|
135 | $user['language'] = pwg_get_session_var('lang_switch', $user['language']); |
---|
136 | } |
---|
137 | |
---|
138 | if ( $same !== $user['language']) |
---|
139 | { |
---|
140 | load_language('common.lang', '', array('language'=>$user['language'])); |
---|
141 | |
---|
142 | load_language( |
---|
143 | 'lang', |
---|
144 | PHPWG_ROOT_PATH.PWG_LOCAL_DIR, |
---|
145 | array( |
---|
146 | 'language' => $user['language'], |
---|
147 | 'no_fallback' => true, |
---|
148 | 'local' => true |
---|
149 | ) |
---|
150 | ); |
---|
151 | } |
---|
152 | |
---|
153 | if (defined('IN_ADMIN') and IN_ADMIN) |
---|
154 | { |
---|
155 | load_language('admin.lang', '', array('language'=>$user['language'])); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | ?> |
---|