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; |
---|
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 | if (($block = $menu->get_block( 'mbLSM' )) != null) { |
---|
66 | $template->set_template_dir(LSM_PATH.'template/'); |
---|
67 | $block->template = 'flags.tpl'; |
---|
68 | } |
---|
69 | |
---|
70 | $available_lang = get_languages(); |
---|
71 | foreach ($available_lang as $code => $displayname) |
---|
72 | { |
---|
73 | $qlc = array ( |
---|
74 | 'url' => add_url_params(duplicate_index_url(), array('lang'=> $code)), |
---|
75 | 'alt' => ucwords($displayname), |
---|
76 | 'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg', |
---|
77 | ); |
---|
78 | |
---|
79 | $lsw['flags'][$code] = $qlc ; |
---|
80 | |
---|
81 | if ($code == $user['language']) |
---|
82 | { |
---|
83 | $lsw['Active'] = $qlc; |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | $lsw['side'] = ceil(sqrt(count($available_lang))); |
---|
88 | $template->clear_assign('lang_switch'); |
---|
89 | $template->assign( |
---|
90 | array( |
---|
91 | 'lang_switch'=> $lsw, |
---|
92 | 'LSM_PATH' => LSM_PATH, |
---|
93 | ) |
---|
94 | ); |
---|
95 | } |
---|
96 | |
---|
97 | function reloadlang() |
---|
98 | { |
---|
99 | global $user; |
---|
100 | $same = $user['language']; |
---|
101 | |
---|
102 | if (isset($_GET['lang'])) |
---|
103 | { |
---|
104 | if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php')) |
---|
105 | { |
---|
106 | if (is_a_guest() or is_generic()) |
---|
107 | { |
---|
108 | pwg_set_session_var('lang_switch', $_GET['lang']); |
---|
109 | } |
---|
110 | else |
---|
111 | { |
---|
112 | $query = ' |
---|
113 | UPDATE '.USER_INFOS_TABLE.' |
---|
114 | SET language = \''.$_GET['lang'].'\' |
---|
115 | WHERE user_id = '.$user['id'].' |
---|
116 | ;'; |
---|
117 | pwg_query($query); |
---|
118 | } |
---|
119 | $user['language'] = $_GET['lang']; |
---|
120 | } |
---|
121 | } |
---|
122 | elseif ((is_a_guest() or is_generic())) |
---|
123 | { |
---|
124 | $user['language'] = pwg_get_session_var('lang_switch', $user['language']); |
---|
125 | } |
---|
126 | |
---|
127 | if ( $same !== $user['language']) |
---|
128 | { |
---|
129 | load_language('common.lang', '', array('language'=>$user['language'])); |
---|
130 | |
---|
131 | load_language( |
---|
132 | 'lang', |
---|
133 | PHPWG_ROOT_PATH.PWG_LOCAL_DIR, |
---|
134 | array( |
---|
135 | 'language' => $user['language'], |
---|
136 | 'no_fallback' => true, |
---|
137 | 'local' => true |
---|
138 | ) |
---|
139 | );} |
---|
140 | |
---|
141 | if (defined('IN_ADMIN') and IN_ADMIN) |
---|
142 | { |
---|
143 | load_language('admin.lang', '', array('language'=>$user['language'])); |
---|
144 | } |
---|
145 | |
---|
146 | } |
---|
147 | |
---|
148 | ?> |
---|