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 | /** |
---|
19 | * Change user's password in FluxBB user table if a new password is set in Piwigo |
---|
20 | * or an account synchronization was set |
---|
21 | */ |
---|
22 | function Register_FluxBB_InitProfile() |
---|
23 | { |
---|
24 | global $template, $conf, $user; |
---|
25 | |
---|
26 | if (Reg_FluxBB_PwdSynch($user['id'])) |
---|
27 | { |
---|
28 | $template->append('errors', l10n('RegFluxBB_Password_Reset_Msg')); |
---|
29 | } |
---|
30 | |
---|
31 | if (isset($_POST['validate'])) |
---|
32 | { |
---|
33 | if (!empty($_POST['use_new_pwd'])) |
---|
34 | { |
---|
35 | $query = ' |
---|
36 | SELECT '.$conf['user_fields']['username'].' AS username |
---|
37 | FROM '.USERS_TABLE.' |
---|
38 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
39 | AND '.$conf['user_fields']['username'].' NOT IN ("18","16") |
---|
40 | ;'; |
---|
41 | |
---|
42 | list($username) = pwg_db_fetch_row(pwg_query($query)); |
---|
43 | FluxBB_Updateuser($user['id'], stripslashes($username), sha1($_POST['use_new_pwd']), $_POST['mail_address']); |
---|
44 | } |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | /** |
---|
50 | * Triggered on login_success |
---|
51 | * |
---|
52 | * Redirect user to profile page and displays a message to make him change his password for synch with FluxBB |
---|
53 | * |
---|
54 | */ |
---|
55 | function Register_FluxBB_Login() |
---|
56 | { |
---|
57 | global $conf, $user; |
---|
58 | |
---|
59 | if (Reg_FluxBB_PwdSynch($user['id'])) |
---|
60 | { |
---|
61 | redirect(PHPWG_ROOT_PATH.'profile.php'); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | /** |
---|
67 | * Checks special users exclusion befaore add new registered user in FluxBB user table |
---|
68 | */ |
---|
69 | function Register_FluxBB_Adduser($register_user) |
---|
70 | { |
---|
71 | global $errors, $conf; |
---|
72 | |
---|
73 | // Exclusion of Adult_Content users |
---|
74 | if ($register_user['username'] != "16" and $register_user['username'] != "18") |
---|
75 | { |
---|
76 | FluxBB_Adduser($register_user['id'], $register_user['username'], sha1($_POST['password']), $register_user['email']); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * Delete registered user in FluxBB user table |
---|
82 | */ |
---|
83 | function Register_FluxBB_Deluser($user_id) |
---|
84 | { |
---|
85 | FluxBB_Deluser(FluxBB_Searchuser($user_id), true); |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | /** |
---|
90 | * Update FluxBB password if user uses "lost password" |
---|
91 | */ |
---|
92 | function Register_FluxBB_PasswReset() |
---|
93 | { |
---|
94 | global $page, $user, $conf; |
---|
95 | |
---|
96 | if (isset($_POST['submit'])) |
---|
97 | { |
---|
98 | if ('reset' == $_GET['action']) |
---|
99 | { |
---|
100 | $user_id = check_password_reset_key($_GET['key']); |
---|
101 | |
---|
102 | $query = ' |
---|
103 | SELECT '.$conf['user_fields']['username'].' AS username, mail_address |
---|
104 | FROM '.USERS_TABLE.' |
---|
105 | WHERE '.$conf['user_fields']['id'].' = \''.$user_id.'\' |
---|
106 | AND '.$conf['user_fields']['username'].' NOT IN ("18","16") |
---|
107 | ;'; |
---|
108 | |
---|
109 | list($username,$mail_address) = pwg_db_fetch_row(pwg_query($query)); |
---|
110 | FluxBB_Updateuser($user_id, stripslashes($username), sha1($_POST['use_new_pwd']), $mail_address); |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * Bridge with UAM confirmation option |
---|
117 | */ |
---|
118 | function UAM_Bridge() |
---|
119 | { |
---|
120 | global $conf, $user; |
---|
121 | |
---|
122 | $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']); |
---|
123 | |
---|
124 | // Check if UAM is installed and if bridge is set - Exception for admins and webmasters |
---|
125 | $query =' |
---|
126 | SELECT user_id, status |
---|
127 | FROM '.USER_INFOS_TABLE.' |
---|
128 | WHERE user_id = '.$user['id'].' |
---|
129 | ;'; |
---|
130 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
131 | |
---|
132 | if ($data['status'] <> "admin" and $data['status'] <> "webmaster") |
---|
133 | { |
---|
134 | if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true') |
---|
135 | { |
---|
136 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
137 | |
---|
138 | // Getting unvalidated users group else Piwigo's default group |
---|
139 | if (isset($conf_UAM['NO_CONFIRM_GROUP']) and $conf_UAM['NO_CONFIRM_GROUP'] != '-1') |
---|
140 | { |
---|
141 | $Waitingroup = $conf_UAM['NO_CONFIRM_GROUP']; |
---|
142 | } |
---|
143 | else |
---|
144 | { |
---|
145 | $query = ' |
---|
146 | SELECT id |
---|
147 | FROM '.GROUPS_TABLE.' |
---|
148 | WHERE is_default = "true" |
---|
149 | LIMIT 1 |
---|
150 | ;'; |
---|
151 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
152 | $Waitingroup = $data['id']; |
---|
153 | } |
---|
154 | |
---|
155 | // check if logged in user is in a Piwigo's validated or unvalidated users group |
---|
156 | $query = ' |
---|
157 | SELECT * |
---|
158 | FROM '.USER_GROUP_TABLE.' |
---|
159 | WHERE user_id = '.$user['id'].' |
---|
160 | AND group_id = '.$Waitingroup.' |
---|
161 | ;'; |
---|
162 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
163 | |
---|
164 | // Check if logged in user is in a FluxBB's unvalidated group |
---|
165 | $query = ' |
---|
166 | SELECT group_id |
---|
167 | FROM '.FluxBB_USERS_TABLE.' |
---|
168 | WHERE id = '.FluxBB_Searchuser($user['id']).' |
---|
169 | ;'; |
---|
170 | |
---|
171 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
172 | |
---|
173 | // Logged in user switch to the default FluxBB's group if he is validated |
---|
174 | if ($count == 0 and $data['group_id'] = $conf_Register_FluxBB['FLUXBB_GROUP']) |
---|
175 | { |
---|
176 | $query = ' |
---|
177 | SELECT conf_value |
---|
178 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
179 | WHERE conf_name = "o_default_user_group" |
---|
180 | ;'; |
---|
181 | |
---|
182 | $o_user_group = pwg_db_fetch_assoc(pwg_query($query)); |
---|
183 | |
---|
184 | $query = ' |
---|
185 | UPDATE '.FluxBB_USERS_TABLE.' |
---|
186 | SET group_id = '.$o_user_group['conf_value'].' |
---|
187 | WHERE id = '.FluxBB_Searchuser($user['id']).' |
---|
188 | ;'; |
---|
189 | pwg_query($query); |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | * Check the username accuracy in FluxBB users table |
---|
197 | */ |
---|
198 | function Register_FluxBB_RegistrationCheck($errors, $user) |
---|
199 | { |
---|
200 | global $conf; |
---|
201 | |
---|
202 | // Because FluxBB is case insensitive on login name, we have to check if a similar login already exists in FluxBB's user table |
---|
203 | // If "test" user already exists, "TEST" or "Test" (and so on...) can't register |
---|
204 | $query = ' |
---|
205 | SELECT username |
---|
206 | FROM '.FluxBB_USERS_TABLE.' |
---|
207 | WHERE LOWER('.stripslashes('username').') = "'.strtolower($user['username']).'" |
---|
208 | ;'; |
---|
209 | |
---|
210 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
211 | |
---|
212 | if ($count > 0) |
---|
213 | { |
---|
214 | array_push($errors, l10n('this login is already used')); |
---|
215 | } |
---|
216 | return $errors; |
---|
217 | } |
---|
218 | |
---|
219 | |
---|
220 | /** |
---|
221 | * Users linking in a dedicated links table |
---|
222 | */ |
---|
223 | function FluxBB_Linkuser($pwg_id, $bb_id, $PwdSync) |
---|
224 | { |
---|
225 | global $conf; |
---|
226 | |
---|
227 | $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']); |
---|
228 | |
---|
229 | $query = ' |
---|
230 | SELECT pwg.id as pwg_id, bb.id as bb_id |
---|
231 | FROM '.USERS_TABLE.' pwg, '.FluxBB_USERS_TABLE.' bb |
---|
232 | WHERE pwg.id = '.$pwg_id.' |
---|
233 | AND bb.id = '.$bb_id.' |
---|
234 | AND pwg.username = bb.username |
---|
235 | AND pwg.username NOT IN ("18","16") |
---|
236 | ;'; |
---|
237 | |
---|
238 | $data = pwg_db_fetch_row(pwg_query($query)); |
---|
239 | |
---|
240 | if (!empty($data) and !is_null($PwdSync)) |
---|
241 | { |
---|
242 | $subquery = ' |
---|
243 | DELETE FROM '.Register_FluxBB_ID_TABLE.' |
---|
244 | WHERE id_user_pwg = "'.$pwg_id.'" |
---|
245 | OR id_user_FluxBB = "'.$bb_id.'" |
---|
246 | ;'; |
---|
247 | |
---|
248 | pwg_query($subquery); |
---|
249 | |
---|
250 | $subquery = ' |
---|
251 | INSERT INTO '.Register_FluxBB_ID_TABLE.' |
---|
252 | (id_user_pwg, id_user_FluxBB, PwdSynch) |
---|
253 | VALUES ('.$pwg_id.', '.$bb_id.', "'.$PwdSync.'") |
---|
254 | ;'; |
---|
255 | |
---|
256 | pwg_query($subquery); |
---|
257 | } |
---|
258 | else |
---|
259 | { |
---|
260 | $PwdSync = NULL; |
---|
261 | $subquery = ' |
---|
262 | DELETE FROM '.Register_FluxBB_ID_TABLE.' |
---|
263 | WHERE id_user_pwg = "'.$pwg_id.'" |
---|
264 | OR id_user_FluxBB = "'.$bb_id.'" |
---|
265 | ;'; |
---|
266 | |
---|
267 | pwg_query($subquery); |
---|
268 | |
---|
269 | $subquery = ' |
---|
270 | INSERT INTO '.Register_FluxBB_ID_TABLE.' |
---|
271 | (id_user_pwg, id_user_FluxBB, PwdSynch) |
---|
272 | VALUES ('.$pwg_id.', '.$bb_id.', "'.$PwdSync.'") |
---|
273 | ;'; |
---|
274 | |
---|
275 | pwg_query($subquery); |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | |
---|
280 | /** |
---|
281 | * Users unlinking in a dedicated links table (on user deletion) |
---|
282 | */ |
---|
283 | function FluxBB_Unlinkuser($bb_id) |
---|
284 | { |
---|
285 | $query = ' |
---|
286 | DELETE FROM '.Register_FluxBB_ID_TABLE.' |
---|
287 | WHERE id_user_FluxBB = '.$bb_id.' |
---|
288 | ;'; |
---|
289 | |
---|
290 | pwg_query($query); |
---|
291 | } |
---|
292 | |
---|
293 | |
---|
294 | /** |
---|
295 | * Add new registered user in fluxBB users table |
---|
296 | * Called from Register_FluxBB_Adduser() |
---|
297 | */ |
---|
298 | function FluxBB_Adduser($pwg_id, $login, $password, $adresse_mail) |
---|
299 | { |
---|
300 | global $errors, $conf; |
---|
301 | |
---|
302 | $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']); |
---|
303 | |
---|
304 | $registred = time(); |
---|
305 | $registred_ip = $_SERVER['REMOTE_ADDR']; |
---|
306 | |
---|
307 | // Set default FluxBB group - Check if UAM is installed and if bridge is set |
---|
308 | if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true') |
---|
309 | { |
---|
310 | $o_default_user_group1 = $conf_Register_FluxBB['FLUXBB_GROUP']; |
---|
311 | } |
---|
312 | else |
---|
313 | { |
---|
314 | $query = ' |
---|
315 | SELECT conf_value |
---|
316 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
317 | WHERE conf_name = "o_default_user_group" |
---|
318 | ;'; |
---|
319 | |
---|
320 | $o_default_user_group = pwg_db_fetch_assoc(pwg_query($query)); |
---|
321 | } |
---|
322 | |
---|
323 | // Check for timezone settings in FluxBB version 1.4.x or higher |
---|
324 | $query1 = ' |
---|
325 | SELECT conf_value |
---|
326 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
327 | WHERE conf_name = "o_default_timezone" |
---|
328 | ;'; |
---|
329 | |
---|
330 | $count1 = pwg_db_num_rows(pwg_query($query1)); |
---|
331 | |
---|
332 | // Check for timezone settings in FluxBB version 1.2.x |
---|
333 | $query2 = ' |
---|
334 | SELECT conf_value |
---|
335 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
336 | WHERE conf_name = "o_server_timezone" |
---|
337 | ;'; |
---|
338 | |
---|
339 | $count2 = pwg_db_num_rows(pwg_query($query2)); |
---|
340 | |
---|
341 | // Set timezone var according of FluxBB version |
---|
342 | if ($count1 == 1 and $count2 == 0) |
---|
343 | { |
---|
344 | $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query1)); |
---|
345 | } |
---|
346 | else if ($count1 == 0 and $count2 == 1) |
---|
347 | { |
---|
348 | $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query2)); |
---|
349 | } |
---|
350 | |
---|
351 | // Get FluxBB default language |
---|
352 | $query = ' |
---|
353 | SELECT conf_value |
---|
354 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
355 | WHERE conf_name = "o_default_lang" |
---|
356 | ;'; |
---|
357 | |
---|
358 | $o_default_lang = pwg_db_fetch_assoc(pwg_query($query)); |
---|
359 | |
---|
360 | // Get FluxBB default style |
---|
361 | $query = ' |
---|
362 | SELECT conf_value |
---|
363 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
364 | WHERE conf_name = "o_default_style" |
---|
365 | ;'; |
---|
366 | |
---|
367 | $o_default_style = pwg_db_fetch_assoc(pwg_query($query)); |
---|
368 | |
---|
369 | // Add user - Check if UAM is installed and if bridge is set |
---|
370 | if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true') |
---|
371 | { |
---|
372 | $query = " |
---|
373 | INSERT INTO ".FluxBB_USERS_TABLE." ( |
---|
374 | username, |
---|
375 | ". ( isset($o_default_user_group1) ? 'group_id' : '' ) .", |
---|
376 | password, |
---|
377 | email, |
---|
378 | ". ( isset($o_default_timezone['conf_value']) ? 'timezone' : '' ) .", |
---|
379 | ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .", |
---|
380 | ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .", |
---|
381 | registered, |
---|
382 | registration_ip, |
---|
383 | last_visit |
---|
384 | ) |
---|
385 | VALUES( |
---|
386 | '".pwg_db_real_escape_string($login)."', |
---|
387 | ". ( isset($o_default_user_group1) ? "'".$o_default_user_group1."'" : '' ) .", |
---|
388 | '".$password."', |
---|
389 | '".$adresse_mail."', |
---|
390 | ". ( isset($o_default_timezone['conf_value']) ? "'".$o_default_timezone['conf_value']."'" : '' ) .", |
---|
391 | ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .", |
---|
392 | ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .", |
---|
393 | '".$registred."', |
---|
394 | '".$registred_ip."', |
---|
395 | '".$registred."' |
---|
396 | );"; |
---|
397 | |
---|
398 | pwg_query($query); |
---|
399 | } |
---|
400 | else |
---|
401 | { |
---|
402 | $query = " |
---|
403 | INSERT INTO ".FluxBB_USERS_TABLE." ( |
---|
404 | username, |
---|
405 | ". ( isset($o_default_user_group['conf_value']) ? 'group_id' : '' ) .", |
---|
406 | password, |
---|
407 | email, |
---|
408 | ". ( isset($o_default_timezone['conf_value']) ? 'timezone' : '' ) .", |
---|
409 | ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .", |
---|
410 | ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .", |
---|
411 | registered, |
---|
412 | registration_ip, |
---|
413 | last_visit |
---|
414 | ) |
---|
415 | VALUES( |
---|
416 | '".pwg_db_real_escape_string($login)."', |
---|
417 | ". ( isset($o_default_user_group['conf_value']) ? "'".$o_default_user_group['conf_value']."'" : '' ) .", |
---|
418 | '".$password."', |
---|
419 | '".$adresse_mail."', |
---|
420 | ". ( isset($o_default_timezone['conf_value']) ? "'".$o_default_timezone['conf_value']."'" : '' ) .", |
---|
421 | ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .", |
---|
422 | ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .", |
---|
423 | '".$registred."', |
---|
424 | '".$registred_ip."', |
---|
425 | '".$registred."' |
---|
426 | ) |
---|
427 | ;"; |
---|
428 | pwg_query($query); |
---|
429 | } |
---|
430 | |
---|
431 | $bb_id = pwg_db_insert_id(); |
---|
432 | |
---|
433 | FluxBB_Linkuser($pwg_id, $bb_id, "OK"); |
---|
434 | } |
---|
435 | |
---|
436 | |
---|
437 | /** |
---|
438 | * Update user information in FluxBB users table |
---|
439 | */ |
---|
440 | function FluxBB_Updateuser($pwg_id, $username, $password, $adresse_mail) |
---|
441 | { |
---|
442 | global $conf; |
---|
443 | |
---|
444 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
445 | $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']); |
---|
446 | |
---|
447 | // Select users to update in ID link table |
---|
448 | $query = ' |
---|
449 | SELECT id_user_FluxBB as FluxBB_id |
---|
450 | FROM '.Register_FluxBB_ID_TABLE.' |
---|
451 | WHERE id_user_pwg = '.$pwg_id.' |
---|
452 | ;'; |
---|
453 | |
---|
454 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
455 | |
---|
456 | if (!empty($row)) |
---|
457 | { |
---|
458 | $query = ' |
---|
459 | UPDATE '.FluxBB_USERS_TABLE.' |
---|
460 | SET username = "'.pwg_db_real_escape_string($username).'", email = "'.$adresse_mail.'", password = "'.$password.'" |
---|
461 | WHERE id = '.$row['FluxBB_id'].' |
---|
462 | AND "'.pwg_db_real_escape_string($username).'" NOT IN ("18","16") |
---|
463 | ;'; |
---|
464 | |
---|
465 | pwg_query($query); |
---|
466 | |
---|
467 | FluxBB_Linkuser($pwg_id, $row['FluxBB_id'], "OK"); |
---|
468 | } |
---|
469 | else |
---|
470 | { |
---|
471 | $query = ' |
---|
472 | SELECT id as FluxBB_id |
---|
473 | FROM '.FluxBB_USERS_TABLE.' |
---|
474 | WHERE BINARY username = BINARY "'.pwg_db_real_escape_string($username).'" |
---|
475 | ;'; |
---|
476 | |
---|
477 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
478 | |
---|
479 | if (!empty($row)) |
---|
480 | { |
---|
481 | $query = ' |
---|
482 | UPDATE '.FluxBB_USERS_TABLE.' |
---|
483 | SET username = "'.pwg_db_real_escape_string($username).'", email = "'.$adresse_mail.'", password = "'.$password.'" |
---|
484 | WHERE id = '.$row['FluxBB_id'].' |
---|
485 | AND "'.pwg_db_real_escape_string($username).'" NOT IN ("18","16") |
---|
486 | ;'; |
---|
487 | |
---|
488 | pwg_query($query); |
---|
489 | |
---|
490 | FluxBB_Linkuser($pwg_id, $row['FluxBB_id'], "OK"); |
---|
491 | } |
---|
492 | } |
---|
493 | } |
---|
494 | |
---|
495 | |
---|
496 | /** |
---|
497 | * Add new registered user in fluxBB users table from audit/synch action |
---|
498 | * Standard FluxBB_Adduser() function is not used because of existing password mismatch |
---|
499 | * To solve password synch problem, passwords are reset to NULL to force users to get a new password on their profile page |
---|
500 | */ |
---|
501 | function Synch_FluxBB_Adduser($pwg_id, $login, $adresse_mail) |
---|
502 | { |
---|
503 | global $errors, $conf; |
---|
504 | |
---|
505 | $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']); |
---|
506 | |
---|
507 | $registred = time(); |
---|
508 | $registred_ip = $_SERVER['REMOTE_ADDR']; |
---|
509 | $password = NULL; |
---|
510 | |
---|
511 | // Set default FluxBB group - Check if UAM is installed and if bridge is set |
---|
512 | if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true') |
---|
513 | { |
---|
514 | $o_default_user_group1 = $conf_Register_FluxBB['FLUXBB_GROUP']; |
---|
515 | } |
---|
516 | else |
---|
517 | { |
---|
518 | $query = ' |
---|
519 | SELECT conf_value |
---|
520 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
521 | WHERE conf_name = "o_default_user_group" |
---|
522 | ;'; |
---|
523 | |
---|
524 | $o_default_user_group = pwg_db_fetch_assoc(pwg_query($query)); |
---|
525 | } |
---|
526 | |
---|
527 | // Check for timezone settings in FluxBB version 1.4.x or higher |
---|
528 | $query1 = ' |
---|
529 | SELECT conf_value |
---|
530 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
531 | WHERE conf_name = "o_default_timezone" |
---|
532 | ;'; |
---|
533 | |
---|
534 | $count1 = pwg_db_num_rows(pwg_query($query1)); |
---|
535 | |
---|
536 | // Check for timezone settings in FluxBB version 1.2.x |
---|
537 | $query2 = ' |
---|
538 | SELECT conf_value |
---|
539 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
540 | WHERE conf_name = "o_server_timezone" |
---|
541 | ;'; |
---|
542 | |
---|
543 | $count2 = pwg_db_num_rows(pwg_query($query2)); |
---|
544 | |
---|
545 | // Set timezone var according of FluxBB version |
---|
546 | if ($count1 == 1 and $count2 == 0) |
---|
547 | { |
---|
548 | $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query1)); |
---|
549 | } |
---|
550 | else if ($count1 == 0 and $count2 == 1) |
---|
551 | { |
---|
552 | $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query2)); |
---|
553 | } |
---|
554 | |
---|
555 | // Get FluxBB default language |
---|
556 | $query = ' |
---|
557 | SELECT conf_value |
---|
558 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
559 | WHERE conf_name = "o_default_lang" |
---|
560 | ;'; |
---|
561 | |
---|
562 | $o_default_lang = pwg_db_fetch_assoc(pwg_query($query)); |
---|
563 | |
---|
564 | // Get FluxBB default style |
---|
565 | $query = ' |
---|
566 | SELECT conf_value |
---|
567 | FROM '.FluxBB_CONFIG_TABLE.' |
---|
568 | WHERE conf_name = "o_default_style" |
---|
569 | ;'; |
---|
570 | |
---|
571 | $o_default_style = pwg_db_fetch_assoc(pwg_query($query)); |
---|
572 | |
---|
573 | // Add user - Check if UAM is installed and if bridge is set |
---|
574 | if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true') |
---|
575 | { |
---|
576 | $query = " |
---|
577 | INSERT INTO ".FluxBB_USERS_TABLE." ( |
---|
578 | username, |
---|
579 | ". ( isset($o_default_user_group1) ? 'group_id' : '' ) .", |
---|
580 | password, |
---|
581 | email, |
---|
582 | ". ( isset($o_default_timezone['conf_value']) ? 'timezone' : '' ) .", |
---|
583 | ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .", |
---|
584 | ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .", |
---|
585 | registered, |
---|
586 | registration_ip, |
---|
587 | last_visit |
---|
588 | ) |
---|
589 | VALUES( |
---|
590 | '".pwg_db_real_escape_string($login)."', |
---|
591 | ". ( isset($o_default_user_group1) ? "'".$o_default_user_group1."'" : '' ) .", |
---|
592 | '".$password."', |
---|
593 | '".$adresse_mail."', |
---|
594 | ". ( isset($o_default_timezone['conf_value']) ? "'".$o_default_timezone['conf_value']."'" : '' ) .", |
---|
595 | ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .", |
---|
596 | ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .", |
---|
597 | '".$registred."', |
---|
598 | '".$registred_ip."', |
---|
599 | '".$registred."' |
---|
600 | );"; |
---|
601 | |
---|
602 | pwg_query($query); |
---|
603 | } |
---|
604 | else |
---|
605 | { |
---|
606 | $query = " |
---|
607 | INSERT INTO ".FluxBB_USERS_TABLE." ( |
---|
608 | username, |
---|
609 | ". ( isset($o_default_user_group['conf_value']) ? 'group_id' : '' ) .", |
---|
610 | password, |
---|
611 | email, |
---|
612 | ". ( isset($o_default_timezone['conf_value']) ? 'timezone' : '' ) .", |
---|
613 | ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .", |
---|
614 | ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .", |
---|
615 | registered, |
---|
616 | registration_ip, |
---|
617 | last_visit |
---|
618 | ) |
---|
619 | VALUES( |
---|
620 | '".pwg_db_real_escape_string($login)."', |
---|
621 | ". ( isset($o_default_user_group['conf_value']) ? "'".$o_default_user_group['conf_value']."'" : '' ) .", |
---|
622 | '".$password."', |
---|
623 | '".$adresse_mail."', |
---|
624 | ". ( isset($o_default_timezone['conf_value']) ? "'".$o_default_timezone['conf_value']."'" : '' ) .", |
---|
625 | ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .", |
---|
626 | ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .", |
---|
627 | '".$registred."', |
---|
628 | '".$registred_ip."', |
---|
629 | '".$registred."' |
---|
630 | ) |
---|
631 | ;"; |
---|
632 | pwg_query($query); |
---|
633 | } |
---|
634 | |
---|
635 | $bb_id = pwg_db_insert_id(); |
---|
636 | |
---|
637 | FluxBB_Linkuser($pwg_id, $bb_id, "NOK"); |
---|
638 | } |
---|
639 | |
---|
640 | |
---|
641 | /** |
---|
642 | * Search linked users |
---|
643 | */ |
---|
644 | function FluxBB_Searchuser($id_user_pwg) |
---|
645 | { |
---|
646 | $query = ' |
---|
647 | SELECT id_user_FluxBB, id_user_pwg |
---|
648 | FROM '.Register_FluxBB_ID_TABLE.' |
---|
649 | WHERE id_user_pwg = '.$id_user_pwg.' |
---|
650 | LIMIT 1 |
---|
651 | ;'; |
---|
652 | |
---|
653 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
654 | |
---|
655 | if (!empty($data)) |
---|
656 | return $data['id_user_FluxBB']; |
---|
657 | else |
---|
658 | return '0'; |
---|
659 | } |
---|
660 | |
---|
661 | |
---|
662 | /** |
---|
663 | * Delete user from FluxBB users table |
---|
664 | * Called from Register_FluxBB_Deluser() |
---|
665 | */ |
---|
666 | function FluxBB_Deluser($id_user_FluxBB, $SuppTopicsPosts) |
---|
667 | { |
---|
668 | global $conf; |
---|
669 | |
---|
670 | $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']); |
---|
671 | |
---|
672 | $query0 = ' |
---|
673 | SELECT username, id |
---|
674 | FROM '.FluxBB_USERS_TABLE.' |
---|
675 | WHERE id = '.$id_user_FluxBB.' |
---|
676 | LIMIT 1 |
---|
677 | ;'; |
---|
678 | |
---|
679 | $data0 = pwg_db_fetch_assoc(pwg_query($query0)); |
---|
680 | |
---|
681 | // If True, delete related topics and posts |
---|
682 | if ($SuppTopicsPosts and $conf_Register_FluxBB['FLUXBB_DEL_PT']) |
---|
683 | { |
---|
684 | // Delete posts and topics of this user |
---|
685 | $subquery = ' |
---|
686 | DELETE FROM '.FluxBB_POSTS_TABLE.' |
---|
687 | WHERE poster_id = '.$id_user_FluxBB.' |
---|
688 | ;'; |
---|
689 | |
---|
690 | $subresult = pwg_query($subquery); |
---|
691 | |
---|
692 | // Delete topics of this user |
---|
693 | $subquery = ' |
---|
694 | DELETE FROM '.FluxBB_TOPICS_TABLE.' |
---|
695 | WHERE BINARY poster = BINARY "'.pwg_db_real_escape_string($data0['username']).'" |
---|
696 | ;'; |
---|
697 | |
---|
698 | $subresult = pwg_query($subquery); |
---|
699 | } |
---|
700 | |
---|
701 | // Delete user's subscriptions |
---|
702 | $subquery = ' |
---|
703 | DELETE FROM '.FluxBB_SUBSCRIPTIONS_TABLE.' |
---|
704 | WHERE user_id = '.$id_user_FluxBB.' |
---|
705 | ;'; |
---|
706 | |
---|
707 | $subresult = pwg_query($subquery); |
---|
708 | |
---|
709 | // Delete user's account |
---|
710 | $subquery = ' |
---|
711 | DELETE FROM '.FluxBB_USERS_TABLE.' |
---|
712 | WHERE id = '.$id_user_FluxBB.' |
---|
713 | ;'; |
---|
714 | |
---|
715 | $subresult = pwg_query($subquery); |
---|
716 | |
---|
717 | FluxBB_Unlinkuser($id_user_FluxBB); |
---|
718 | } |
---|
719 | |
---|
720 | |
---|
721 | /** |
---|
722 | * Get plugin information |
---|
723 | */ |
---|
724 | function RegFluxBB_Infos($dir) |
---|
725 | { |
---|
726 | $path = $dir; |
---|
727 | |
---|
728 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
729 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
730 | { |
---|
731 | $plugin['name'] = trim( $val[1] ); |
---|
732 | } |
---|
733 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
734 | { |
---|
735 | $plugin['version'] = trim($val[1]); |
---|
736 | } |
---|
737 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
738 | { |
---|
739 | $plugin['uri'] = trim($val[1]); |
---|
740 | } |
---|
741 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
742 | { |
---|
743 | $plugin['description'] = trim($desc); |
---|
744 | } |
---|
745 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
746 | { |
---|
747 | $plugin['description'] = trim($val[1]); |
---|
748 | } |
---|
749 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
750 | { |
---|
751 | $plugin['author'] = trim($val[1]); |
---|
752 | } |
---|
753 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
754 | { |
---|
755 | $plugin['author uri'] = trim($val[1]); |
---|
756 | } |
---|
757 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
758 | { |
---|
759 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
760 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
761 | } |
---|
762 | // IMPORTANT SECURITY ! |
---|
763 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
764 | |
---|
765 | return $plugin ; |
---|
766 | } |
---|
767 | |
---|
768 | |
---|
769 | /** |
---|
770 | * Delete obsolete files at plugin update |
---|
771 | */ |
---|
772 | function regfluxbb_obsolete_files() |
---|
773 | { |
---|
774 | if (file_exists(REGFLUXBB_PATH.'obsolete.list') |
---|
775 | and $old_files = file(REGFLUXBB_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
776 | and !empty($old_files)) |
---|
777 | { |
---|
778 | array_push($old_files, 'obsolete.list'); |
---|
779 | foreach($old_files as $old_file) |
---|
780 | { |
---|
781 | $path = REGFLUXBB_PATH.$old_file; |
---|
782 | if (is_file($path)) |
---|
783 | { |
---|
784 | @unlink($path); |
---|
785 | } |
---|
786 | } |
---|
787 | } |
---|
788 | } |
---|
789 | |
---|
790 | |
---|
791 | /** |
---|
792 | * Function to update plugin version number in config table |
---|
793 | * Used everytime a new version is updated even if no database |
---|
794 | * upgrade is needed |
---|
795 | */ |
---|
796 | function RegFluxBB_version_update() |
---|
797 | { |
---|
798 | global $conf; |
---|
799 | |
---|
800 | // Get current plugin version |
---|
801 | // -------------------------- |
---|
802 | $plugin = RegFluxBB_Infos(REGFLUXBB_PATH); |
---|
803 | $version = $plugin['version']; |
---|
804 | |
---|
805 | // Upgrading options |
---|
806 | // ----------------- |
---|
807 | $query = ' |
---|
808 | SELECT value |
---|
809 | FROM '.CONFIG_TABLE.' |
---|
810 | WHERE param = "Register_FluxBB" |
---|
811 | ;'; |
---|
812 | |
---|
813 | $result = pwg_query($query); |
---|
814 | $Conf_RegFluxBB = pwg_db_fetch_assoc($result); |
---|
815 | |
---|
816 | $Newconf_RegFluxBB = unserialize($Conf_RegFluxBB['value']); |
---|
817 | |
---|
818 | $Newconf_RegFluxBB['REGFLUXBB_VERSION'] = $version; |
---|
819 | |
---|
820 | $update_conf = serialize($Newconf_RegFluxBB); |
---|
821 | |
---|
822 | conf_update_param('Register_FluxBB', pwg_db_real_escape_string($update_conf)); |
---|
823 | |
---|
824 | |
---|
825 | // Check #_plugin table consistency |
---|
826 | // Only useful if a previous version upgrade has not worked correctly (rare case) |
---|
827 | // ------------------------------------------------------------------------------ |
---|
828 | $query = ' |
---|
829 | SELECT version |
---|
830 | FROM '.PLUGINS_TABLE.' |
---|
831 | WHERE id = "Register_FluxBB" |
---|
832 | ;'; |
---|
833 | |
---|
834 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
835 | |
---|
836 | if (empty($data['version']) or $data['version'] <> $version) |
---|
837 | { |
---|
838 | $query = ' |
---|
839 | UPDATE '.PLUGINS_TABLE.' |
---|
840 | SET version="'.$version.'" |
---|
841 | WHERE id = "Register_FluxBB" |
---|
842 | LIMIT 1 |
---|
843 | ;'; |
---|
844 | |
---|
845 | pwg_query($query); |
---|
846 | } |
---|
847 | } |
---|
848 | |
---|
849 | |
---|
850 | /** |
---|
851 | * Useful for debugging - 4 vars can be set |
---|
852 | * Output result to log.txt file |
---|
853 | * |
---|
854 | */ |
---|
855 | function RegFluxBBLog($var1, $var2, $var3, $var4) |
---|
856 | { |
---|
857 | $fo=fopen (REGFLUXBB_PATH.'log.txt','a') ; |
---|
858 | fwrite($fo,"======================\n") ; |
---|
859 | fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n"); |
---|
860 | fwrite($fo,$var1 ."\r\n") ; |
---|
861 | fwrite($fo,$var2 ."\r\n") ; |
---|
862 | fwrite($fo,$var3 ."\r\n") ; |
---|
863 | fwrite($fo,$var4 ."\r\n") ; |
---|
864 | fclose($fo) ; |
---|
865 | } |
---|
866 | ?> |
---|