1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | Plugin Name: Event Cats |
---|
5 | Version: auto |
---|
6 | Description: A single URL can be enough to be identified, and a user can duplicate his account to create a new one getting immediately the same properties. / On peut être identifié grâce à un simple URL, et on peut dupliquer son compte pour créer un nouveau compte ayant immédiatement les mêmes propriétés. |
---|
7 | Plugin URI: http://piwigo.org/ext/extension_svn.php?eid=326 |
---|
8 | Author: LucMorizur |
---|
9 | Author URI: http://lucmorizur.free.fr |
---|
10 | */ |
---|
11 | |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | Piwigo - a PHP based picture gallery | |
---|
14 | // +-----------------------------------------------------------------------+ |
---|
15 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
16 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
17 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
18 | // +-----------------------------------------------------------------------+ |
---|
19 | // | This program is free software; you can redistribute it and/or modify | |
---|
20 | // | it under the terms of the GNU General Public License as published by | |
---|
21 | // | the Free Software Foundation | |
---|
22 | // | | |
---|
23 | // | This program is distributed in the hope that it will be useful, but | |
---|
24 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
25 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
26 | // | General Public License for more details. | |
---|
27 | // | | |
---|
28 | // | You should have received a copy of the GNU General Public License | |
---|
29 | // | along with this program; if not, write to the Free Software | |
---|
30 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
31 | // | USA. | |
---|
32 | // +-----------------------------------------------------------------------+ |
---|
33 | |
---|
34 | // Keeps file coded in UTF-8 without BOM : é |
---|
35 | |
---|
36 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
37 | |
---|
38 | // pour faciliter le debug - make debug easier :o) |
---|
39 | //ini_set('error_reporting', E_ALL); |
---|
40 | //ini_set('display_errors', true); |
---|
41 | |
---|
42 | global $conf, $prefixeTable, $ec_lists; |
---|
43 | |
---|
44 | define( // ------------------------------------------------------------------- |
---|
45 | 'EVNTCATS_INFO_VERSION', // VERSION HISTORY : |
---|
46 | '1.2.0' // Add feature 1335, Possibility to display the 'Connection' |
---|
47 | // link in identification block menu for generic users ; |
---|
48 | // finish (yes !) english translation |
---|
49 | // '1.1.5' // Fix bugs 1324 and 1325 |
---|
50 | // '1.1.4' // Improve help banner |
---|
51 | // '1.1.3' // Better help banner management ; finalize banner texts |
---|
52 | // '1.1.2' // Better help banner example : some examples |
---|
53 | // '1.1.1' // Better help banner example ; but still no text in it |
---|
54 | // '1.1.0' // First bugs (1305 and 1306) corrected ; |
---|
55 | // add newly created user/group association with cat/AP (was |
---|
56 | // forgotten) ; begin help banner |
---|
57 | // '1.0.0' // Conception version |
---|
58 | ); // ------------------------------------------------------------------------ |
---|
59 | define( |
---|
60 | 'EVNTCATS_PATH', |
---|
61 | PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/' |
---|
62 | ); |
---|
63 | define( |
---|
64 | 'EVNTCATS_TABLE', |
---|
65 | $prefixeTable.'event_cats' |
---|
66 | ); |
---|
67 | define( |
---|
68 | 'ROOT_URL', |
---|
69 | get_absolute_root_url() |
---|
70 | ); |
---|
71 | |
---|
72 | include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php'); |
---|
73 | |
---|
74 | class event_cats { |
---|
75 | // Sets the administration panel of the plugin |
---|
76 | function plugin_admin_menu($menu) { |
---|
77 | array_push($menu, |
---|
78 | array( |
---|
79 | 'NAME' => 'Event Cats', |
---|
80 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__). |
---|
81 | '/admin/evntcats_admin.php') |
---|
82 | ) |
---|
83 | ); |
---|
84 | return $menu; |
---|
85 | } |
---|
86 | } // End class |
---|
87 | |
---|
88 | $obj = new event_cats(); |
---|
89 | |
---|
90 | // Adds the translation of "duplicate" link |
---|
91 | load_language('duplic.lang', EVNTCATS_PATH); |
---|
92 | |
---|
93 | // Admin help management |
---|
94 | add_event_handler('get_popup_help_content', 'ec_popup_help_content', |
---|
95 | EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
96 | |
---|
97 | function ec_popup_help_content($popup_help_content, $page) { |
---|
98 | return ( |
---|
99 | $help_content = (is_admin() and $page = 'help') ? |
---|
100 | load_language($page.'.html', EVNTCATS_PATH, array('return' => true)) : false |
---|
101 | ) ? $popup_help_content.$help_content : $popup_help_content; |
---|
102 | } |
---|
103 | |
---|
104 | //---------------------------------- |
---|
105 | |
---|
106 | /** |
---|
107 | * |
---|
108 | * auto_log_user() |
---|
109 | * the function uses the value of the argument "autolog" of the posted URL, as a code |
---|
110 | * to know which username has to be logged in. |
---|
111 | * |
---|
112 | * @param no parameter |
---|
113 | * @return no return value |
---|
114 | */ |
---|
115 | |
---|
116 | add_event_handler('init', 'auto_log_user'); |
---|
117 | |
---|
118 | function auto_log_user() { |
---|
119 | global $ec_lists; |
---|
120 | |
---|
121 | $ec_ap = NULL; |
---|
122 | $ec_cat = NULL; |
---|
123 | $ec_img = NULL; |
---|
124 | |
---|
125 | if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) { |
---|
126 | if (!is_a_guest()) { |
---|
127 | $url = ''; |
---|
128 | foreach ($_GET as $item => $value) { |
---|
129 | $url.= '&'.$item.'='.$value; |
---|
130 | } |
---|
131 | logout_user(); |
---|
132 | redirect(make_index_url().$url); |
---|
133 | } |
---|
134 | build_ec_lists(); |
---|
135 | foreach ($ec_lists['ec_table'] as $ec_entry) { |
---|
136 | if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break; |
---|
137 | } |
---|
138 | if ($code_exists) { |
---|
139 | if (is_in($ec_entry['action'], 'ec_ok')) { |
---|
140 | log_user($ec_entry['user_id'], false); |
---|
141 | if (isset($_GET['ap'])) $ec_ap = $_GET['ap']; |
---|
142 | if (isset($_GET['cat'])) $ec_cat = $_GET['cat']; |
---|
143 | if (isset($_GET['img'])) $ec_img = $_GET['img']; |
---|
144 | if ($ec_entry['forced'] == 'true') { |
---|
145 | if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) { |
---|
146 | $ec_ap = $ec_entry['arg2']; |
---|
147 | } |
---|
148 | elseif (!empty($ec_entry['arg1'])) { |
---|
149 | $ec_cat = $ec_entry['arg1']; |
---|
150 | if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2']; |
---|
151 | } |
---|
152 | } |
---|
153 | if (isset($ec_ap)) { |
---|
154 | if (array_key_exists($ec_ap,$ec_lists['add_pages'])) { |
---|
155 | redirect( |
---|
156 | PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap); |
---|
157 | } |
---|
158 | } |
---|
159 | elseif (isset($ec_cat)) { |
---|
160 | if (array_key_exists($ec_cat, $ec_lists['categories'])) { |
---|
161 | if (isset($ec_img)) { |
---|
162 | if (ec_image_exists($ec_cat, $ec_img)) { |
---|
163 | redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat); |
---|
164 | } |
---|
165 | } |
---|
166 | redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat); |
---|
167 | } |
---|
168 | } |
---|
169 | redirect(make_index_url()); |
---|
170 | } |
---|
171 | else { |
---|
172 | if ( |
---|
173 | $ec_entry['action'] == 'ec_nok' or |
---|
174 | $ec_entry['action'] == 'ec_nok_ap_pb' |
---|
175 | ) { |
---|
176 | if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied(); |
---|
177 | $ec_ap = $ec_entry['arg2']; |
---|
178 | if (array_key_exists($ec_ap, $ec_lists['add_pages'])) { |
---|
179 | redirect( |
---|
180 | PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap); |
---|
181 | } |
---|
182 | access_denied(); |
---|
183 | } |
---|
184 | else { |
---|
185 | redirect(make_index_url()); |
---|
186 | } |
---|
187 | } |
---|
188 | } |
---|
189 | else { |
---|
190 | if ( |
---|
191 | read_ec_conf('unknown_code') == '2' and |
---|
192 | array_key_exists( |
---|
193 | read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages'] |
---|
194 | ) |
---|
195 | ) { |
---|
196 | redirect( |
---|
197 | PHPWG_ROOT_PATH. |
---|
198 | 'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id') |
---|
199 | ); |
---|
200 | } |
---|
201 | elseif (read_ec_conf('unknown_code') == '1' or |
---|
202 | read_ec_conf('unknown_code') == '2') { |
---|
203 | access_denied(); |
---|
204 | } |
---|
205 | else { |
---|
206 | redirect(make_index_url()); |
---|
207 | } |
---|
208 | } |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | /** |
---|
213 | * |
---|
214 | * assign_perm_for_new_user() |
---|
215 | * copies/paste groups+access+properties associations of previously connected |
---|
216 | * username, to newly created username. |
---|
217 | * |
---|
218 | * @param no parameter |
---|
219 | * @return no return value |
---|
220 | */ |
---|
221 | |
---|
222 | add_event_handler('register_user', 'assign_perm_for_new_user'); |
---|
223 | |
---|
224 | function assign_perm_for_new_user($new_user) { |
---|
225 | global $user; |
---|
226 | |
---|
227 | if (!is_a_guest() and !is_admin()) if ( |
---|
228 | read_ec_conf('dup_allow') == '1' or ( |
---|
229 | read_ec_conf('dup_allow') == '2' and |
---|
230 | dup_allowed($user['id']) |
---|
231 | ) |
---|
232 | ) { |
---|
233 | // User access |
---|
234 | $result = pwg_query(" |
---|
235 | SELECT `cat_id` |
---|
236 | FROM `".USER_ACCESS_TABLE."` |
---|
237 | WHERE `user_id` = ".$user['id']."; |
---|
238 | "); |
---|
239 | $insert = array(); |
---|
240 | while ($row = mysql_fetch_assoc($result)) |
---|
241 | $insert[] = "(".$new_user['id'].",".$row['cat_id'].")"; |
---|
242 | if (!empty($insert)) pwg_query(" |
---|
243 | INSERT INTO `".USER_ACCESS_TABLE."` |
---|
244 | VALUES ".implode(',', $insert)."; |
---|
245 | "); |
---|
246 | |
---|
247 | // User groups |
---|
248 | $result = pwg_query(" |
---|
249 | SELECT `group_id` |
---|
250 | FROM `".USER_GROUP_TABLE."` |
---|
251 | WHERE `user_id` = ".$user['id']."; |
---|
252 | "); |
---|
253 | $insert = array(); |
---|
254 | while ($row = mysql_fetch_assoc($result)) |
---|
255 | $insert[] = "(".$new_user['id'].",".$row['group_id'].")"; |
---|
256 | if (!empty($insert)) pwg_query(" |
---|
257 | INSERT INTO `".USER_GROUP_TABLE."` |
---|
258 | VALUES ".implode(',', $insert)."; |
---|
259 | "); |
---|
260 | |
---|
261 | // User infos |
---|
262 | $result = pwg_query(" |
---|
263 | SELECT `level` |
---|
264 | FROM `".USER_INFOS_TABLE."` |
---|
265 | WHERE `user_id` = ".$user['id']."; |
---|
266 | "); |
---|
267 | $insert = array(); |
---|
268 | while ($row = mysql_fetch_assoc($result)) |
---|
269 | $insert[] = "(".$new_user['id'].",".$row['level'].")"; |
---|
270 | if (!empty($insert)) pwg_query(" |
---|
271 | UPDATE `".USER_INFOS_TABLE."` |
---|
272 | SET `level` = ".$user['level']." |
---|
273 | WHERE `user_id` = ".$new_user['id']."; |
---|
274 | "); |
---|
275 | } |
---|
276 | } |
---|
277 | |
---|
278 | /** |
---|
279 | * |
---|
280 | * duplicate_account_url() |
---|
281 | * adds a link for duplicating the currently identified user in |
---|
282 | * Identification block menu, in case the identifed user is granted to |
---|
283 | * duplication. Displays also the connection link for generic users, if |
---|
284 | * required in the configuration. |
---|
285 | * |
---|
286 | * @param no parameter |
---|
287 | * @return no return value |
---|
288 | */ |
---|
289 | |
---|
290 | add_event_handler('blockmanager_apply', 'duplicate_account_url'); |
---|
291 | |
---|
292 | function duplicate_account_url() { |
---|
293 | global $lang, $template, $user; |
---|
294 | |
---|
295 | // Adds duplication link, if needed |
---|
296 | if (!is_admin() and !is_a_guest()) if ( |
---|
297 | read_ec_conf('dup_allow') == '1' or ( |
---|
298 | read_ec_conf('dup_allow') == '2' and |
---|
299 | dup_allowed($user['id']) |
---|
300 | ) |
---|
301 | ) { |
---|
302 | $template->assign('U_REGISTER', get_root_url().'register.php'); |
---|
303 | if ( |
---|
304 | read_ec_conf('duplic_display') == '1' or ( |
---|
305 | read_ec_conf('duplic_display') == '2' and |
---|
306 | !is_generic() |
---|
307 | ) |
---|
308 | ) { |
---|
309 | $lang['Register'] = $lang['Duplicate']; |
---|
310 | $lang['Create a new account'] = |
---|
311 | $lang['Create a new account with same properties']; |
---|
312 | } |
---|
313 | } |
---|
314 | |
---|
315 | // Adds connection link, if needed |
---|
316 | if (read_ec_conf('display_connection') == '1' and is_generic()) { |
---|
317 | // Adds connection link |
---|
318 | $template->assign( |
---|
319 | 'U_LOGIN', |
---|
320 | get_root_url().'identification.php?redirect='.$_SERVER['REQUEST_URI'] |
---|
321 | ); |
---|
322 | // Removes "quick connection" fieldset (form) |
---|
323 | $template->set_filenames(array( |
---|
324 | 'ec_no_quick_connect' => |
---|
325 | realpath(EVNTCATS_PATH.'ec_no_quick_connect.tpl') |
---|
326 | )); |
---|
327 | $begin = 'PLUGIN_INDEX_CONTENT_BEFORE'; |
---|
328 | $old_begin = $template->get_template_vars($begin); |
---|
329 | $template->assign_var_from_handle($begin, 'ec_no_quick_connect'); |
---|
330 | $template->concat($begin, $old_begin); |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | add_event_handler( |
---|
335 | 'get_admin_plugin_menu_links', |
---|
336 | array(&$obj, 'plugin_admin_menu') |
---|
337 | ); |
---|
338 | set_plugin_data($plugin['id'], $obj); |
---|
339 | |
---|
340 | ?> |
---|