1 | <?php |
---|
2 | |
---|
3 | include_once (PHPWG_ROOT_PATH.'/include/constants.php'); |
---|
4 | include_once (REGFLUXBB_PATH.'include/constants.php'); |
---|
5 | |
---|
6 | |
---|
7 | function Register_FluxBB_admin_menu($menu) |
---|
8 | { |
---|
9 | array_push($menu, array( |
---|
10 | 'NAME' => 'Register FluxBB', |
---|
11 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(REGFLUXBB_PATH) |
---|
12 | ) |
---|
13 | ); |
---|
14 | return $menu; |
---|
15 | } |
---|
16 | |
---|
17 | |
---|
18 | function Register_FluxBB_Adduser($register_user) |
---|
19 | { |
---|
20 | global $errors, $conf; |
---|
21 | |
---|
22 | // Exclusion of Adult_Content users |
---|
23 | if ($register_user['username'] != "16" and $register_user['username'] != "18") |
---|
24 | { |
---|
25 | // Warning : FluxBB uses Sha1 hash instead of md5 for Piwigo! |
---|
26 | FluxBB_Adduser($register_user['id'], $register_user['username'], sha1($_POST['password']), $register_user['email']); |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | |
---|
31 | function Register_FluxBB_Deluser($user_id) |
---|
32 | { |
---|
33 | FluxBB_Deluser(FluxBB_Searchuser($user_id), true); |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | function Register_FluxBB_InitPage() |
---|
38 | { |
---|
39 | global $conf, $user; |
---|
40 | |
---|
41 | if (isset($_POST['validate']) and !is_admin()) |
---|
42 | { |
---|
43 | if (!empty($_POST['use_new_pwd'])) |
---|
44 | { |
---|
45 | $query = ' |
---|
46 | SELECT '.$conf['user_fields']['username'].' AS username |
---|
47 | FROM '.USERS_TABLE.' |
---|
48 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
49 | ;'; |
---|
50 | |
---|
51 | list($username) = pwg_db_fetch_row(pwg_query($query)); |
---|
52 | |
---|
53 | FluxBB_Updateuser($user['id'], stripslashes($username), sha1($_POST['use_new_pwd']), $_POST['mail_address']); |
---|
54 | } |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | function UAM_Bridge() |
---|
60 | { |
---|
61 | global $conf, $user; |
---|
62 | |
---|
63 | $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array(); |
---|
64 | |
---|
65 | // Check if UAM is installed and if bridge is set - Exception for admins and webmasters |
---|
66 | $query =' |
---|
67 | SELECT user_id, status |
---|
68 | FROM '.USER_INFOS_TABLE.' |
---|
69 | WHERE user_id = '.$user['id'].' |
---|
70 | ;'; |
---|
71 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
72 | |
---|
73 | if ($data['status'] <> "admin" and $data['status'] <> "webmaster") |
---|
74 | { |
---|
75 | if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB[6]) and $conf_Register_FluxBB[6] == 'true') |
---|
76 | { |
---|
77 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
78 | |
---|
79 | // Getting unvalidated users group else Piwigo's default group |
---|
80 | if (isset($conf_UAM[2]) and $conf_UAM[2] != '-1') |
---|
81 | { |
---|
82 | $Waitingroup = $conf_UAM[2]; |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | $query = ' |
---|
87 | SELECT id |
---|
88 | FROM '.GROUPS_TABLE.' |
---|
89 | WHERE is_default = "true" |
---|
90 | LIMIT 1 |
---|
91 | ;'; |
---|
92 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
93 | $Waitingroup = $data['id']; |
---|
94 | } |
---|
95 | |
---|
96 | // check if logged in user is in a Piwigo's validated or unvalidated users group |
---|
97 | $query = ' |
---|
98 | SELECT * |
---|
99 | FROM '.USER_GROUP_TABLE.' |
---|
100 | WHERE user_id = '.$user['id'].' |
---|
101 | AND group_id = '.$Waitingroup.' |
---|
102 | ;'; |
---|
103 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
104 | |
---|
105 | // Check if logged in user is in a FluxBB's unvalidated group |
---|
106 | $query = " |
---|
107 | SELECT group_id |
---|
108 | FROM ".FluxBB_USERS_TABLE." |
---|
109 | WHERE id = ".FluxBB_Searchuser($user['id'])." |
---|
110 | ;"; |
---|
111 | |
---|
112 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
113 | |
---|
114 | // Logged in user switch to the default FluxBB's group if he'is validated |
---|
115 | if ($count == 0 and $data['group_id'] = $conf_Register_FluxBB[7]) |
---|
116 | { |
---|
117 | $query = " |
---|
118 | SELECT conf_value |
---|
119 | FROM ".FluxBB_CONFIG_TABLE." |
---|
120 | WHERE conf_name = 'o_default_user_group' |
---|
121 | ;"; |
---|
122 | |
---|
123 | $o_user_group = pwg_db_fetch_assoc(pwg_query($query)); |
---|
124 | |
---|
125 | $query = " |
---|
126 | UPDATE ".FluxBB_USERS_TABLE." |
---|
127 | SET group_id = ".$o_user_group['conf_value']." |
---|
128 | WHERE id = ".FluxBB_Searchuser($user['id'])." |
---|
129 | ;"; |
---|
130 | pwg_query($query); |
---|
131 | } |
---|
132 | } |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | function Register_FluxBB_RegistrationCheck($errors, $user) |
---|
138 | { |
---|
139 | global $conf; |
---|
140 | |
---|
141 | //Because FluxBB is case insensitive on login name, we have to check if a similar login already exists in FluxBB's user table |
---|
142 | // If "test" user already exists, "TEST" or "Test" (and so on...) can't register |
---|
143 | $query = " |
---|
144 | SELECT username |
---|
145 | FROM ".FluxBB_USERS_TABLE." |
---|
146 | WHERE LOWER(".stripslashes('username').") = '".strtolower($user['username'])."' |
---|
147 | ;"; |
---|
148 | |
---|
149 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
150 | |
---|
151 | if ($count > 0) |
---|
152 | { |
---|
153 | array_push($errors, l10n('this login is already used')); |
---|
154 | } |
---|
155 | return $errors; |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | function FluxBB_Linkuser($pwg_id, $bb_id) |
---|
160 | { |
---|
161 | $query = " |
---|
162 | SELECT pwg.id as pwg_id, bb.id as bb_id |
---|
163 | FROM ".USERS_TABLE." pwg, ".FluxBB_USERS_TABLE." bb |
---|
164 | WHERE pwg.id = ".$pwg_id." |
---|
165 | AND bb.id = ".$bb_id." |
---|
166 | AND pwg.username = bb.username |
---|
167 | ;"; |
---|
168 | |
---|
169 | $data = pwg_db_fetch_row(pwg_query($query)); |
---|
170 | |
---|
171 | if (!empty($data)) |
---|
172 | { |
---|
173 | $subquery = " |
---|
174 | DELETE FROM ".Register_FluxBB_ID_TABLE." |
---|
175 | WHERE id_user_pwg = '".$pwg_id."' |
---|
176 | OR id_user_FluxBB = '".$bb_id."' |
---|
177 | ;"; |
---|
178 | |
---|
179 | $subresult = pwg_query($subquery); |
---|
180 | |
---|
181 | $subquery = " |
---|
182 | INSERT INTO ".Register_FluxBB_ID_TABLE." |
---|
183 | (id_user_pwg, id_user_FluxBB) |
---|
184 | VALUES (".$pwg_id.", ".$bb_id.") |
---|
185 | ;"; |
---|
186 | |
---|
187 | $subresult = pwg_query($subquery); |
---|
188 | } |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | function FluxBB_Unlinkuser($bb_id) |
---|
194 | { |
---|
195 | $query = " |
---|
196 | DELETE FROM ".Register_FluxBB_ID_TABLE." |
---|
197 | WHERE id_user_FluxBB = ".$bb_id." |
---|
198 | ;"; |
---|
199 | |
---|
200 | $result = pwg_query($query); |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | |
---|
205 | function FluxBB_Adduser($pwg_id, $login, $password, $adresse_mail) |
---|
206 | { |
---|
207 | global $errors, $conf; |
---|
208 | |
---|
209 | $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array(); |
---|
210 | |
---|
211 | $registred = time(); |
---|
212 | $registred_ip = $_SERVER['REMOTE_ADDR']; |
---|
213 | |
---|
214 | // Check if UAM is installed and if bridge is set - Exception for admins and webmasters |
---|
215 | if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB[6]) and $conf_Register_FluxBB[6] == 'true') |
---|
216 | { |
---|
217 | $o_default_user_group = $conf_Register_FluxBB[7]; |
---|
218 | } |
---|
219 | else |
---|
220 | { |
---|
221 | $query = " |
---|
222 | SELECT conf_value |
---|
223 | FROM ".FluxBB_CONFIG_TABLE." |
---|
224 | WHERE conf_name = 'o_default_user_group' |
---|
225 | ;"; |
---|
226 | |
---|
227 | $o_default_user_group = pwg_db_fetch_assoc(pwg_query($query)); |
---|
228 | } |
---|
229 | |
---|
230 | // Check for FluxBB version 1.4.x and get the correct value |
---|
231 | $query1 = " |
---|
232 | SELECT conf_value |
---|
233 | FROM ".FluxBB_CONFIG_TABLE." |
---|
234 | WHERE conf_name = 'o_default_timezone' |
---|
235 | ;"; |
---|
236 | |
---|
237 | $count1 = pwg_db_num_rows(pwg_query($query1)); |
---|
238 | |
---|
239 | // Check for FluxBB version 1.2.x and get the correct value |
---|
240 | $query2 = " |
---|
241 | SELECT conf_value |
---|
242 | FROM ".FluxBB_CONFIG_TABLE." |
---|
243 | WHERE conf_name = 'o_server_timezone' |
---|
244 | ;"; |
---|
245 | |
---|
246 | $count2 = pwg_db_num_rows(pwg_query($query2)); |
---|
247 | |
---|
248 | if ($count1 == 1 and $count2 == 0) |
---|
249 | { |
---|
250 | $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query1)); |
---|
251 | } |
---|
252 | else if ($count1 == 0 and $count2 == 1) |
---|
253 | { |
---|
254 | $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query2)); |
---|
255 | } |
---|
256 | |
---|
257 | |
---|
258 | $query = " |
---|
259 | SELECT conf_value |
---|
260 | FROM ".FluxBB_CONFIG_TABLE." |
---|
261 | WHERE conf_name = 'o_default_lang' |
---|
262 | ;"; |
---|
263 | |
---|
264 | $o_default_lang = pwg_db_fetch_assoc(pwg_query($query)); |
---|
265 | |
---|
266 | $query = " |
---|
267 | SELECT conf_value |
---|
268 | FROM ".FluxBB_CONFIG_TABLE." |
---|
269 | WHERE conf_name = 'o_default_style' |
---|
270 | ;"; |
---|
271 | |
---|
272 | $o_default_style = pwg_db_fetch_assoc(pwg_query($query)); |
---|
273 | |
---|
274 | $query = " |
---|
275 | INSERT INTO ".FluxBB_USERS_TABLE." ( |
---|
276 | username, |
---|
277 | ". ( isset($o_default_user_group['conf_value']) ? 'group_id' : '' ) .", |
---|
278 | password, |
---|
279 | email, |
---|
280 | ". ( isset($o_default_timezone['conf_value']) ? 'timezone' : '' ) .", |
---|
281 | ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .", |
---|
282 | ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .", |
---|
283 | registered, |
---|
284 | registration_ip, |
---|
285 | last_visit |
---|
286 | ) |
---|
287 | VALUES( |
---|
288 | '".pwg_db_real_escape_string($login)."', |
---|
289 | ". ( isset($o_default_user_group['conf_value']) ? "'".$o_default_user_group['conf_value']."'" : '' ) .", |
---|
290 | '".$password."', |
---|
291 | '".$adresse_mail."', |
---|
292 | ". ( isset($o_default_timezone['conf_value']) ? "'".$o_default_timezone['conf_value']."'" : '' ) .", |
---|
293 | ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .", |
---|
294 | ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .", |
---|
295 | '".$registred."', |
---|
296 | '".$registred_ip."', |
---|
297 | '".$registred."' |
---|
298 | ) |
---|
299 | ;"; |
---|
300 | |
---|
301 | $result = pwg_query($query); |
---|
302 | |
---|
303 | $bb_id = pwg_db_insert_id(); |
---|
304 | |
---|
305 | FluxBB_Linkuser($pwg_id, $bb_id); |
---|
306 | } |
---|
307 | |
---|
308 | |
---|
309 | |
---|
310 | function FluxBB_Searchuser($id_user_pwg) |
---|
311 | { |
---|
312 | $query = " |
---|
313 | SELECT id_user_FluxBB, id_user_pwg |
---|
314 | FROM ".Register_FluxBB_ID_TABLE." |
---|
315 | WHERE id_user_pwg = ".$id_user_pwg." |
---|
316 | LIMIT 1 |
---|
317 | ;"; |
---|
318 | |
---|
319 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
320 | |
---|
321 | if (!empty($data)) |
---|
322 | return $data['id_user_FluxBB']; |
---|
323 | else |
---|
324 | return '0'; |
---|
325 | } |
---|
326 | |
---|
327 | |
---|
328 | |
---|
329 | function FluxBB_Deluser($id_user_FluxBB, $SuppTopicsPosts) |
---|
330 | { |
---|
331 | global $conf; |
---|
332 | |
---|
333 | $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array(); |
---|
334 | |
---|
335 | $query0 = " |
---|
336 | SELECT username, id FROM ".FluxBB_USERS_TABLE." |
---|
337 | WHERE id = ".$id_user_FluxBB." |
---|
338 | LIMIT 1 |
---|
339 | ;"; |
---|
340 | |
---|
341 | $data0 = pwg_db_fetch_assoc(pwg_query($query0)); |
---|
342 | |
---|
343 | // If True, delete related topics and posts |
---|
344 | if ($SuppTopicsPosts and $conf_Register_FluxBB[3]) |
---|
345 | { |
---|
346 | // Delete posts and topics of this user |
---|
347 | $subquery = " |
---|
348 | DELETE FROM ".FluxBB_POSTS_TABLE." |
---|
349 | WHERE poster_id = ".$id_user_FluxBB." |
---|
350 | ;"; |
---|
351 | |
---|
352 | $subresult = pwg_query($subquery); |
---|
353 | |
---|
354 | // Delete topics of this user |
---|
355 | $subquery = " |
---|
356 | DELETE FROM ".FluxBB_TOPICS_TABLE." |
---|
357 | WHERE BINARY poster = BINARY '".pwg_db_real_escape_string($data0['username'])."' |
---|
358 | ;"; |
---|
359 | |
---|
360 | $subresult = pwg_query($subquery); |
---|
361 | } |
---|
362 | |
---|
363 | // Delete user's subscriptions |
---|
364 | $subquery = " |
---|
365 | DELETE FROM ".FluxBB_SUBSCRIPTIONS_TABLE." |
---|
366 | WHERE user_id = ".$id_user_FluxBB." |
---|
367 | ;"; |
---|
368 | |
---|
369 | $subresult = pwg_query($subquery); |
---|
370 | |
---|
371 | // Delete user's account |
---|
372 | $subquery = " |
---|
373 | DELETE FROM ".FluxBB_USERS_TABLE." |
---|
374 | WHERE id = ".$id_user_FluxBB." |
---|
375 | ;"; |
---|
376 | |
---|
377 | $subresult = pwg_query($subquery); |
---|
378 | |
---|
379 | FluxBB_Unlinkuser($id_user_FluxBB); |
---|
380 | } |
---|
381 | |
---|
382 | |
---|
383 | |
---|
384 | function FluxBB_Updateuser($pwg_id, $username, $password, $adresse_mail) |
---|
385 | { |
---|
386 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
387 | |
---|
388 | $query = " |
---|
389 | SELECT id_user_FluxBB as FluxBB_id |
---|
390 | FROM ".Register_FluxBB_ID_TABLE." |
---|
391 | WHERE id_user_pwg = ".$pwg_id." |
---|
392 | ;"; |
---|
393 | |
---|
394 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
395 | |
---|
396 | if (!empty($row)) |
---|
397 | { |
---|
398 | $query = " |
---|
399 | UPDATE ".FluxBB_USERS_TABLE." |
---|
400 | SET username = '".pwg_db_real_escape_string($username)."', email = '".$adresse_mail."', password = '".$password."' |
---|
401 | WHERE id = ".$row['FluxBB_id']." |
---|
402 | ;"; |
---|
403 | |
---|
404 | $result = pwg_query($query); |
---|
405 | |
---|
406 | FluxBB_Linkuser($pwg_id, $row['FluxBB_id']); |
---|
407 | } |
---|
408 | else |
---|
409 | { |
---|
410 | $query = " |
---|
411 | SELECT id as FluxBB_id |
---|
412 | FROM ".FluxBB_USERS_TABLE." |
---|
413 | WHERE BINARY username = BINARY '".pwg_db_real_escape_string($username)."' |
---|
414 | ;"; |
---|
415 | |
---|
416 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
417 | |
---|
418 | if (!empty($row)) |
---|
419 | { |
---|
420 | $query = " |
---|
421 | UPDATE ".FluxBB_USERS_TABLE." |
---|
422 | SET username = '".pwg_db_real_escape_string($username)."', email = '".$adresse_mail."', password = '".$password."' |
---|
423 | WHERE id = ".$row['FluxBB_id']." |
---|
424 | ;"; |
---|
425 | |
---|
426 | $result = pwg_query($query); |
---|
427 | |
---|
428 | FluxBB_Linkuser($pwg_id, $row['FluxBB_id']); |
---|
429 | } |
---|
430 | } |
---|
431 | } |
---|
432 | |
---|
433 | |
---|
434 | function RegFluxBB_Infos($dir) |
---|
435 | { |
---|
436 | $path = $dir; |
---|
437 | |
---|
438 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
439 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
440 | { |
---|
441 | $plugin['name'] = trim( $val[1] ); |
---|
442 | } |
---|
443 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
444 | { |
---|
445 | $plugin['version'] = trim($val[1]); |
---|
446 | } |
---|
447 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
448 | { |
---|
449 | $plugin['uri'] = trim($val[1]); |
---|
450 | } |
---|
451 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
452 | { |
---|
453 | $plugin['description'] = trim($desc); |
---|
454 | } |
---|
455 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
456 | { |
---|
457 | $plugin['description'] = trim($val[1]); |
---|
458 | } |
---|
459 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
460 | { |
---|
461 | $plugin['author'] = trim($val[1]); |
---|
462 | } |
---|
463 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
464 | { |
---|
465 | $plugin['author uri'] = trim($val[1]); |
---|
466 | } |
---|
467 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
468 | { |
---|
469 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
470 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
471 | } |
---|
472 | // IMPORTANT SECURITY ! |
---|
473 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
474 | |
---|
475 | return $plugin ; |
---|
476 | } |
---|
477 | |
---|
478 | function regfluxbb_obsolete_files() |
---|
479 | { |
---|
480 | if (file_exists(REGFLUXBB_PATH.'obsolete.list') |
---|
481 | and $old_files = file(REGFLUXBB_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
482 | and !empty($old_files)) |
---|
483 | { |
---|
484 | array_push($old_files, 'obsolete.list'); |
---|
485 | foreach($old_files as $old_file) |
---|
486 | { |
---|
487 | $path = REGFLUXBB_PATH.$old_file; |
---|
488 | if (is_file($path)) |
---|
489 | { |
---|
490 | @unlink($path); |
---|
491 | } |
---|
492 | } |
---|
493 | } |
---|
494 | } |
---|
495 | ?> |
---|