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 | $code2=explode("_", $code); |
---|
85 | $qlc = array ( |
---|
86 | 'url' => add_url_params($base_url, array('lang'=> $code)), |
---|
87 | 'alt' => ucwords($displayname), |
---|
88 | 'hreflang' =>$code2[0], |
---|
89 | 'img' => get_root_url().'language/'.$code.'/'.$code.'.jpg', |
---|
90 | ); |
---|
91 | |
---|
92 | $lsw['flags'][$code] = $qlc ; |
---|
93 | |
---|
94 | if ($code == $user['language']) |
---|
95 | { |
---|
96 | $lsw['Active'] = $qlc; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | $lsw['side'] = ceil(sqrt(count($available_lang))); |
---|
101 | $template->clear_assign('lang_switch'); |
---|
102 | $template->assign( |
---|
103 | array( |
---|
104 | 'lang_switch'=> $lsw, |
---|
105 | 'LSM_PATH' => LSM_PATH, |
---|
106 | ) |
---|
107 | ); |
---|
108 | } |
---|
109 | |
---|
110 | function reloadlang() |
---|
111 | { |
---|
112 | global $user; |
---|
113 | $same = $user['language']; |
---|
114 | |
---|
115 | if (isset($_GET['lang'])) |
---|
116 | { |
---|
117 | if (!empty($_GET['lang']) and file_exists(PHPWG_ROOT_PATH.'language/'.$_GET['lang'].'/common.lang.php')) |
---|
118 | { |
---|
119 | if (is_a_guest() or is_generic()) |
---|
120 | { |
---|
121 | pwg_set_session_var('lang_switch', $_GET['lang']); |
---|
122 | } |
---|
123 | else |
---|
124 | { |
---|
125 | $query = ' |
---|
126 | UPDATE '.USER_INFOS_TABLE.' |
---|
127 | SET language = \''.$_GET['lang'].'\' |
---|
128 | WHERE user_id = '.$user['id'].' |
---|
129 | ;'; |
---|
130 | pwg_query($query); |
---|
131 | } |
---|
132 | $user['language'] = $_GET['lang']; |
---|
133 | } |
---|
134 | } |
---|
135 | elseif ((is_a_guest() or is_generic())) |
---|
136 | { |
---|
137 | $user['language'] = pwg_get_session_var('lang_switch', $user['language']); |
---|
138 | } |
---|
139 | |
---|
140 | if ( $same !== $user['language']) |
---|
141 | { |
---|
142 | load_language('common.lang', '', array('language'=>$user['language'])); |
---|
143 | |
---|
144 | load_language( |
---|
145 | 'lang', |
---|
146 | PHPWG_ROOT_PATH.PWG_LOCAL_DIR, |
---|
147 | array( |
---|
148 | 'language' => $user['language'], |
---|
149 | 'no_fallback' => true, |
---|
150 | 'local' => true |
---|
151 | ) |
---|
152 | ); |
---|
153 | } |
---|
154 | |
---|
155 | if (defined('IN_ADMIN') and IN_ADMIN) |
---|
156 | { |
---|
157 | load_language('admin.lang', '', array('language'=>$user['language'])); |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | ?> |
---|