1 | <?php |
---|
2 | |
---|
3 | include_once (PHPWG_ROOT_PATH.'/include/constants.php'); |
---|
4 | include_once (REGPHPBB_PATH.'include/constants.php'); |
---|
5 | |
---|
6 | function PhpBB_Linkuser($pwg_id, $bb_id) |
---|
7 | { |
---|
8 | $query = " |
---|
9 | SELECT pwg.id as pwg_id, bb.user_id as bb_id |
---|
10 | FROM ".USERS_TABLE." pwg, ".PhpBB_USERS_TABLE." bb |
---|
11 | WHERE pwg.id = ".$pwg_id." |
---|
12 | AND bb.user_id = ".$bb_id." |
---|
13 | AND pwg.username = bb.username |
---|
14 | ;"; |
---|
15 | |
---|
16 | $data = pwg_db_fetch_row(pwg_query($query)); |
---|
17 | |
---|
18 | if (!empty($data)) |
---|
19 | { |
---|
20 | $subquery = " |
---|
21 | DELETE FROM ".Register_PhpBB_ID_TABLE." |
---|
22 | WHERE id_user_pwg = '".$pwg_id."' |
---|
23 | OR id_user_PhpBB = '".$bb_id."' |
---|
24 | ;"; |
---|
25 | |
---|
26 | $subresult = pwg_query($subquery); |
---|
27 | |
---|
28 | $subquery = " |
---|
29 | INSERT INTO ".Register_PhpBB_ID_TABLE." |
---|
30 | (id_user_pwg, id_user_PhpBB) |
---|
31 | VALUES (".$pwg_id.", ".$bb_id.") |
---|
32 | ;"; |
---|
33 | |
---|
34 | $subresult = pwg_query($subquery); |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | function PhpBB_Unlinkuser($bb_id) |
---|
41 | { |
---|
42 | $query = " |
---|
43 | DELETE FROM ".Register_PhpBB_ID_TABLE." |
---|
44 | WHERE id_user_PhpBB = ".$bb_id." |
---|
45 | ;"; |
---|
46 | |
---|
47 | $result = pwg_query($query); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | function PhpBB_Adduser($pwg_id, $login, $password, $adresse_mail) |
---|
53 | { |
---|
54 | global $conf; |
---|
55 | |
---|
56 | $conf_Register_PhpBB = isset($conf['Register_PhpBB']) ? explode(";" , $conf['Register_PhpBB']) : array(); |
---|
57 | |
---|
58 | $registred = time(); |
---|
59 | $registred_ip = $_SERVER['REMOTE_ADDR']; |
---|
60 | |
---|
61 | // Check if UAM is installed and if bridge is set - Exception for admins and webmasters |
---|
62 | if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_PhpBB[5]) and $conf_Register_PhpBB[5] == 'true') |
---|
63 | { |
---|
64 | $default_user_group = '7'; |
---|
65 | } |
---|
66 | else |
---|
67 | { |
---|
68 | $query = " |
---|
69 | SELECT group_id |
---|
70 | FROM ".PhpBB_GROUPS_TABLE." |
---|
71 | WHERE group_name = 'REGISTERED' |
---|
72 | ;"; |
---|
73 | |
---|
74 | $default_user_group = pwg_db_fetch_assoc(pwg_query($query)); |
---|
75 | } |
---|
76 | |
---|
77 | $query = " |
---|
78 | UPDATE ".PhpBB_CONFIG_TABLE." |
---|
79 | SET config_value = config_value+1 |
---|
80 | WHERE config_name = 'num_users' |
---|
81 | ;"; |
---|
82 | |
---|
83 | $result = pwg_query($query); |
---|
84 | |
---|
85 | $query = " |
---|
86 | UPDATE ".PhpBB_CONFIG_TABLE." |
---|
87 | SET config_value = '".pwg_db_real_escape_string($login)."' |
---|
88 | WHERE config_name = 'newest_username' |
---|
89 | ;"; |
---|
90 | $result = pwg_query($query); |
---|
91 | |
---|
92 | $query = " |
---|
93 | SELECT config_value |
---|
94 | FROM ".PhpBB_CONFIG_TABLE." |
---|
95 | WHERE config_name = 'board_timezone' |
---|
96 | ;"; |
---|
97 | |
---|
98 | $board_timezone = pwg_db_fetch_assoc(pwg_query($query)); |
---|
99 | |
---|
100 | $query = " |
---|
101 | SELECT config_value |
---|
102 | FROM ".PhpBB_CONFIG_TABLE." |
---|
103 | WHERE config_name = 'default_dateformat' |
---|
104 | ;"; |
---|
105 | |
---|
106 | $default_dateformat = pwg_db_fetch_assoc(pwg_query($query)); |
---|
107 | |
---|
108 | $query = " |
---|
109 | SELECT config_value |
---|
110 | FROM ".PhpBB_CONFIG_TABLE." |
---|
111 | WHERE config_name = 'default_lang' |
---|
112 | ;"; |
---|
113 | |
---|
114 | $default_lang = pwg_db_fetch_assoc(pwg_query($query)); |
---|
115 | |
---|
116 | $query = " |
---|
117 | SELECT config_value |
---|
118 | FROM ".PhpBB_CONFIG_TABLE." |
---|
119 | WHERE config_name = 'default_style' |
---|
120 | ;"; |
---|
121 | |
---|
122 | $default_style = pwg_db_fetch_assoc(pwg_query($query)); |
---|
123 | |
---|
124 | $query = " |
---|
125 | SELECT group_colour |
---|
126 | FROM ".PhpBB_GROUPS_TABLE." |
---|
127 | WHERE group_id = '".$default_user_group."' |
---|
128 | ;"; |
---|
129 | $default_colour = pwg_db_fetch_assoc(pwg_query($query)); |
---|
130 | |
---|
131 | $query = ' |
---|
132 | INSERT INTO '.PhpBB_USERS_TABLE." ( |
---|
133 | username, |
---|
134 | username_clean, |
---|
135 | ". ( isset($default_user_group['group_id']) ? 'group_id' : '' ) .", |
---|
136 | user_password, |
---|
137 | user_email, |
---|
138 | ". ( isset($board_timezone['config_value']) ? 'user_timezone' : '' ) .", |
---|
139 | ". ( isset($default_lang['config_value']) ? 'user_lang' : '' ) .", |
---|
140 | ". ( isset($default_dateformat['config_value']) ? 'user_dateformat' : '' ) .", |
---|
141 | ". ( isset($default_style['config_value']) ? 'user_style' : '' ) .", |
---|
142 | user_colour, |
---|
143 | user_regdate, |
---|
144 | user_ip, |
---|
145 | user_lastvisit, |
---|
146 | user_new |
---|
147 | ) |
---|
148 | VALUES( |
---|
149 | '".pwg_db_real_escape_string($login)."', |
---|
150 | '".strtolower(pwg_db_real_escape_string($login))."', |
---|
151 | ". ( isset($default_user_group['group_id']) ? "'".$default_user_group['group_id']."'" : '' ) .", |
---|
152 | '".$password."', |
---|
153 | '".$adresse_mail."', |
---|
154 | ". ( isset($board_timezone['config_value']) ? "'".$board_timezone['config_value']."'" : '' ) .", |
---|
155 | ". ( isset($default_lang['config_value']) ? "'".$default_lang['config_value']."'" : '' ) .", |
---|
156 | ". ( isset($default_dateformat['config_value']) ? "'".$default_dateformat['config_value']."'" : '' ) .", |
---|
157 | ". ( isset($default_style['config_value']) ? "'".$default_style['config_value']."'" : '' ) .", |
---|
158 | '".$default_colour['group_colour']."', |
---|
159 | '".$registred."', |
---|
160 | '".$registred_ip."', |
---|
161 | '".$registred."', |
---|
162 | '0' |
---|
163 | ) |
---|
164 | ;"; |
---|
165 | |
---|
166 | $result = pwg_query($query); |
---|
167 | |
---|
168 | $bb_id = pwg_db_insert_id(); |
---|
169 | |
---|
170 | PhpBB_Linkuser($pwg_id, $bb_id); |
---|
171 | |
---|
172 | $query = " |
---|
173 | SELECT user_id |
---|
174 | FROM ".PhpBB_USERS_TABLE." |
---|
175 | WHERE username = '".pwg_db_real_escape_string($login)."' |
---|
176 | ;"; |
---|
177 | |
---|
178 | $userid = pwg_db_fetch_assoc(pwg_query($query)); |
---|
179 | |
---|
180 | $query = " |
---|
181 | UPDATE ".PhpBB_CONFIG_TABLE." |
---|
182 | SET config_value = '".$userid."' |
---|
183 | WHERE config_name = 'newest_user_id' |
---|
184 | ;"; |
---|
185 | $result = pwg_query($query); |
---|
186 | |
---|
187 | $query = ' |
---|
188 | INSERT INTO '.PhpBB_USERGROUP_TABLE." ( |
---|
189 | ". ( isset($default_user_group['group_id']) ? 'group_id' : '' ) .", |
---|
190 | user_id, |
---|
191 | group_leader, |
---|
192 | user_pending |
---|
193 | ) |
---|
194 | VALUES( |
---|
195 | ". ( isset($default_user_group['group_id']) ? "'".$default_user_group['group_id']."'" : '' ) .", |
---|
196 | ". ( isset($userid['user_id']) ? "'".$userid['user_id']."'" : '' ) .", |
---|
197 | '0', |
---|
198 | '0' |
---|
199 | ) |
---|
200 | ;"; |
---|
201 | |
---|
202 | $result = pwg_query($query); |
---|
203 | |
---|
204 | $query = " |
---|
205 | UPDATE ".PhpBB_CONFIG_TABLE." |
---|
206 | SET config_value = '".$default_colour."' |
---|
207 | WHERE config_name = 'newest_user_colour' |
---|
208 | ;"; |
---|
209 | $result = pwg_query($query); |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | function PhpBB_Searchuser($id_user_pwg) |
---|
215 | { |
---|
216 | $query = " |
---|
217 | SELECT id_user_PhpBB, id_user_pwg FROM ".Register_PhpBB_ID_TABLE." |
---|
218 | WHERE id_user_pwg = ".$id_user_pwg." |
---|
219 | LIMIT 1 |
---|
220 | ;"; |
---|
221 | |
---|
222 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
223 | |
---|
224 | if (!empty($data)) |
---|
225 | return $data['id_user_PhpBB']; |
---|
226 | else |
---|
227 | return '0'; |
---|
228 | } |
---|
229 | |
---|
230 | |
---|
231 | |
---|
232 | function PhpBB_Deluser($id_user_PhpBB, $SuppTopicsPosts) |
---|
233 | { |
---|
234 | global $conf; |
---|
235 | |
---|
236 | $conf_Register_PhpBB = isset($conf['Register_PhpBB']) ? explode(";" , $conf['Register_PhpBB']) : array(); |
---|
237 | |
---|
238 | $query0 = " |
---|
239 | SELECT username, user_id FROM ".PhpBB_USERS_TABLE." |
---|
240 | WHERE user_id = ".$id_user_PhpBB." |
---|
241 | LIMIT 1 |
---|
242 | ;"; |
---|
243 | |
---|
244 | $data0 = pwg_db_fetch_assoc(pwg_query($query0)); |
---|
245 | |
---|
246 | |
---|
247 | $subquery = " |
---|
248 | UPDATE ".PhpBB_POSTS_TABLE." |
---|
249 | SET post_username = '".pwg_db_real_escape_string($data0['username'])."', poster_id = '1' |
---|
250 | WHERE poster_id = ".$id_user_PhpBB." |
---|
251 | ;"; |
---|
252 | |
---|
253 | $subresult = pwg_query($subquery); |
---|
254 | |
---|
255 | $subquery = " |
---|
256 | UPDATE ".PhpBB_TOPICS_TABLE." |
---|
257 | SET topic_poster = '1' |
---|
258 | WHERE BINARY topic_poster = ".$id_user_PhpBB." |
---|
259 | ;"; |
---|
260 | |
---|
261 | $subresult = pwg_query($subquery); |
---|
262 | |
---|
263 | $subquery = " |
---|
264 | UPDATE ".PhpBB_TOPICS_TABLE." |
---|
265 | SET topic_last_poster_id = '1' |
---|
266 | WHERE topic_last_poster_id = ".$id_user_PhpBB." |
---|
267 | ;"; |
---|
268 | $subresult = pwg_query($subquery); |
---|
269 | |
---|
270 | $subquery = " |
---|
271 | UPDATE ".PhpBB_FORUMS_TABLE." |
---|
272 | SET forum_last_poster_id = '1' |
---|
273 | WHERE forum_last_poster_id = ".$id_user_PhpBB." |
---|
274 | ;"; |
---|
275 | $subresult = pwg_query($subquery); |
---|
276 | |
---|
277 | |
---|
278 | $subquery = " |
---|
279 | DELETE FROM ".PhpBB_TOPICSPOSTED_TABLE." |
---|
280 | WHERE user_id = ".$id_user_PhpBB." |
---|
281 | ;"; |
---|
282 | |
---|
283 | $subresult = pwg_query($subquery); |
---|
284 | |
---|
285 | $subquery = " |
---|
286 | DELETE FROM ".PhpBB_FORUMSTRACK_TABLE." |
---|
287 | WHERE user_id = ".$id_user_PhpBB." |
---|
288 | ;"; |
---|
289 | |
---|
290 | $subresult = pwg_query($subquery); |
---|
291 | |
---|
292 | // Suppression des abonnements aux topics de l'utilisateur |
---|
293 | $subquery = " |
---|
294 | DELETE FROM ".PhpBB_SUBSCRIPTIONS_TABLE." |
---|
295 | WHERE user_id = ".$id_user_PhpBB." |
---|
296 | ;"; |
---|
297 | |
---|
298 | $subresult = pwg_query($subquery); |
---|
299 | |
---|
300 | //Suppression des abonnements aux forums de l'utilisateur |
---|
301 | $subquery = " |
---|
302 | DELETE FROM ".PhpBB_SUBFORUMS_TABLE." |
---|
303 | WHERE user_id = ".$id_user_PhpBB." |
---|
304 | ;"; |
---|
305 | |
---|
306 | $subresult = pwg_query($subquery); |
---|
307 | |
---|
308 | $subquery = " |
---|
309 | UPDATE ".PhpBB_CONFIG_TABLE." |
---|
310 | SET config_value = config_value-1 |
---|
311 | WHERE config_name = 'num_users' |
---|
312 | ;"; |
---|
313 | |
---|
314 | $subresult = pwg_query($subquery); |
---|
315 | |
---|
316 | // Suppression du compte utilisateur |
---|
317 | $subquery = " |
---|
318 | DELETE FROM ".PhpBB_USERS_TABLE." |
---|
319 | WHERE user_id = ".$id_user_PhpBB." |
---|
320 | ;"; |
---|
321 | |
---|
322 | $subresult = pwg_query($subquery); |
---|
323 | |
---|
324 | $subquery = " |
---|
325 | DELETE FROM ".PhpBB_USERGROUP_TABLE." |
---|
326 | WHERE user_id = ".$id_user_PhpBB." |
---|
327 | ;"; |
---|
328 | |
---|
329 | $subresult = pwg_query($subquery); |
---|
330 | |
---|
331 | $subquery = " |
---|
332 | UPDATE ".PhpBB_CONFIG_TABLE." |
---|
333 | SET config_value = (SELECT username FROM ".PhpBB_USERS_TABLE." WHERE user_regdate = (SELECT MAX(user_regdate) FROM ".PhpBB_USERS_TABLE." WHERE ((group_id <> 6) AND (username <> 'Anonymous')) |
---|
334 | LIMIT 1) LIMIT 1) |
---|
335 | WHERE config_name = 'newest_username' |
---|
336 | ;"; |
---|
337 | |
---|
338 | $subresult = pwg_query($subquery); |
---|
339 | |
---|
340 | $subquery = " |
---|
341 | UPDATE ".PhpBB_CONFIG_TABLE." |
---|
342 | SET config_value = (SELECT user_id FROM ".PhpBB_USERS_TABLE." WHERE user_regdate = (SELECT MAX(user_regdate) FROM ".PhpBB_USERS_TABLE." WHERE ((group_id <> 6) AND (username <> 'Anonymous')) |
---|
343 | LIMIT 1) LIMIT 1) |
---|
344 | WHERE config_name = 'newest_user_id' |
---|
345 | ;"; |
---|
346 | |
---|
347 | $subresult = pwg_query($subquery); |
---|
348 | |
---|
349 | PhpBB_Unlinkuser($id_user_PhpBB); |
---|
350 | } |
---|
351 | |
---|
352 | |
---|
353 | |
---|
354 | function PhpBB_Updateuser($pwg_id, $username, $password, $adresse_mail) |
---|
355 | { |
---|
356 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
357 | |
---|
358 | $query = " |
---|
359 | SELECT id_user_PhpBB as PhpBB_id |
---|
360 | FROM ".Register_PhpBB_ID_TABLE." |
---|
361 | WHERE id_user_pwg = ".$pwg_id." |
---|
362 | ;"; |
---|
363 | |
---|
364 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
365 | |
---|
366 | if (!empty($row)) |
---|
367 | { |
---|
368 | $query = " |
---|
369 | UPDATE ".PhpBB_USERS_TABLE." |
---|
370 | SET username = '".pwg_db_real_escape_string($username)."', username_clean = '".strtolower(pwg_db_real_escape_string($username))."', user_email = '".$adresse_mail."', user_password = '".$password."' |
---|
371 | WHERE user_id = ".$row['PhpBB_id']." |
---|
372 | ;"; |
---|
373 | |
---|
374 | $result = pwg_query($query); |
---|
375 | |
---|
376 | PhpBB_Linkuser($pwg_id, $row['PhpBB_id']); |
---|
377 | } |
---|
378 | else |
---|
379 | { |
---|
380 | $query = " |
---|
381 | SELECT user_id as PhpBB_id |
---|
382 | FROM ".PhpBB_USERS_TABLE." |
---|
383 | WHERE BINARY username = BINARY '".pwg_db_real_escape_string($username)."' |
---|
384 | ;"; |
---|
385 | |
---|
386 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
387 | |
---|
388 | if (!empty($row)) |
---|
389 | { |
---|
390 | $query = " |
---|
391 | UPDATE ".PhpBB_USERS_TABLE." |
---|
392 | SET username = '".pwg_db_real_escape_string($username)."', username_clean = '".strtolower(pwg_db_real_escape_string($username))."', user_email = '".$adresse_mail."', user_password = '".$password."' |
---|
393 | WHERE user_id = ".$row['PhpBB_id']." |
---|
394 | ;"; |
---|
395 | |
---|
396 | $result = pwg_query($query); |
---|
397 | |
---|
398 | PhpBB_Linkuser($pwg_id, $row['PhpBB_id']); |
---|
399 | } |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | |
---|
404 | function RegPhpBB_Infos($dir) |
---|
405 | { |
---|
406 | $path = $dir; |
---|
407 | |
---|
408 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
409 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
410 | { |
---|
411 | $plugin['name'] = trim( $val[1] ); |
---|
412 | } |
---|
413 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
414 | { |
---|
415 | $plugin['version'] = trim($val[1]); |
---|
416 | } |
---|
417 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
418 | { |
---|
419 | $plugin['uri'] = trim($val[1]); |
---|
420 | } |
---|
421 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
422 | { |
---|
423 | $plugin['description'] = trim($desc); |
---|
424 | } |
---|
425 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
426 | { |
---|
427 | $plugin['description'] = trim($val[1]); |
---|
428 | } |
---|
429 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
430 | { |
---|
431 | $plugin['author'] = trim($val[1]); |
---|
432 | } |
---|
433 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
434 | { |
---|
435 | $plugin['author uri'] = trim($val[1]); |
---|
436 | } |
---|
437 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
438 | { |
---|
439 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
440 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
441 | } |
---|
442 | // IMPORTANT SECURITY ! |
---|
443 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
444 | |
---|
445 | return $plugin ; |
---|
446 | } |
---|
447 | |
---|
448 | function regphpbb_obsolete_files() |
---|
449 | { |
---|
450 | if (file_exists(REGPHPBB_PATH.'obsolete.list') |
---|
451 | and $old_files = file(REGPHPBB_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
452 | and !empty($old_files)) |
---|
453 | { |
---|
454 | array_push($old_files, 'obsolete.list'); |
---|
455 | foreach($old_files as $old_file) |
---|
456 | { |
---|
457 | $path = REGPHPBB_PATH.$old_file; |
---|
458 | if (is_file($path)) |
---|
459 | { |
---|
460 | @unlink($path); |
---|
461 | } |
---|
462 | } |
---|
463 | } |
---|
464 | } |
---|
465 | ?> |
---|