1 | <?php |
---|
2 | |
---|
3 | include_once (PHPWG_ROOT_PATH.'/include/constants.php'); |
---|
4 | include_once (REGFLUXBB_PATH.'include/constants.php'); |
---|
5 | |
---|
6 | function FluxBB_Linkuser($pwg_id, $bb_id) |
---|
7 | { |
---|
8 | $query = " |
---|
9 | SELECT pwg.id as pwg_id, bb.id as bb_id |
---|
10 | FROM ".USERS_TABLE." pwg, ".FluxBB_USERS_TABLE." bb |
---|
11 | WHERE pwg.id = ".$pwg_id." |
---|
12 | AND bb.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_FluxBB_ID_TABLE." |
---|
22 | WHERE id_user_pwg = '".$pwg_id."' |
---|
23 | OR id_user_FluxBB = '".$bb_id."' |
---|
24 | ;"; |
---|
25 | |
---|
26 | $subresult = pwg_query($subquery); |
---|
27 | |
---|
28 | $subquery = " |
---|
29 | INSERT INTO ".Register_FluxBB_ID_TABLE." |
---|
30 | (id_user_pwg, id_user_FluxBB) |
---|
31 | VALUES (".$pwg_id.", ".$bb_id.") |
---|
32 | ;"; |
---|
33 | |
---|
34 | $subresult = pwg_query($subquery); |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | function FluxBB_Unlinkuser($bb_id) |
---|
41 | { |
---|
42 | $query = " |
---|
43 | DELETE FROM ".Register_FluxBB_ID_TABLE." |
---|
44 | WHERE id_user_FluxBB = ".$bb_id." |
---|
45 | ;"; |
---|
46 | |
---|
47 | $result = pwg_query($query); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | function FluxBB_Adduser($pwg_id, $login, $password, $adresse_mail) |
---|
53 | { |
---|
54 | global $conf; |
---|
55 | |
---|
56 | $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array(); |
---|
57 | |
---|
58 | $registred = time(); |
---|
59 | $registred_ip = $_SERVER['REMOTE_ADDR']; |
---|
60 | |
---|
61 | $query = " |
---|
62 | SELECT conf_value |
---|
63 | FROM ".FluxBB_CONFIG_TABLE." |
---|
64 | WHERE conf_name = 'o_default_user_group' |
---|
65 | ;"; |
---|
66 | |
---|
67 | $o_default_user_group = pwg_db_fetch_assoc(pwg_query($query)); |
---|
68 | |
---|
69 | $query = " |
---|
70 | SELECT conf_value |
---|
71 | FROM ".FluxBB_CONFIG_TABLE." |
---|
72 | WHERE conf_name = 'o_server_timezone' |
---|
73 | ;"; |
---|
74 | |
---|
75 | $o_server_timezone = pwg_db_fetch_assoc(pwg_query($query)); |
---|
76 | |
---|
77 | $query = " |
---|
78 | SELECT conf_value |
---|
79 | FROM ".FluxBB_CONFIG_TABLE." |
---|
80 | WHERE conf_name = 'o_default_lang' |
---|
81 | ;"; |
---|
82 | |
---|
83 | $o_default_lang = pwg_db_fetch_assoc(pwg_query($query)); |
---|
84 | |
---|
85 | $query = " |
---|
86 | SELECT conf_value |
---|
87 | FROM ".FluxBB_CONFIG_TABLE." |
---|
88 | WHERE conf_name = 'o_default_style' |
---|
89 | ;"; |
---|
90 | |
---|
91 | $o_default_style = pwg_db_fetch_assoc(pwg_query($query)); |
---|
92 | |
---|
93 | $query = ' |
---|
94 | INSERT INTO '.FluxBB_USERS_TABLE." ( |
---|
95 | username, |
---|
96 | ". ( isset($o_default_user_group['conf_value']) ? 'group_id' : '' ) .", |
---|
97 | password, |
---|
98 | email, |
---|
99 | ". ( isset($o_server_timezone['conf_value']) ? 'timezone' : '' ) .", |
---|
100 | ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .", |
---|
101 | ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .", |
---|
102 | registered, |
---|
103 | registration_ip, |
---|
104 | last_visit |
---|
105 | ) |
---|
106 | VALUES( |
---|
107 | '".pwg_db_real_escape_string($login)."', |
---|
108 | ". ( isset($o_default_user_group['conf_value']) ? "'".$o_default_user_group['conf_value']."'" : '' ) .", |
---|
109 | '".$password."', |
---|
110 | '".$adresse_mail."', |
---|
111 | ". ( isset($o_server_timezone['conf_value']) ? "'".$o_server_timezone['conf_value']."'" : '' ) .", |
---|
112 | ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .", |
---|
113 | ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .", |
---|
114 | '".$registred."', |
---|
115 | '".$registred_ip."', |
---|
116 | '".$registred."' |
---|
117 | ) |
---|
118 | ;"; |
---|
119 | |
---|
120 | $result = pwg_query($query); |
---|
121 | |
---|
122 | $bb_id = pwg_db_insert_id(); |
---|
123 | |
---|
124 | FluxBB_Linkuser($pwg_id, $bb_id); |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | function FluxBB_Searchuser($id_user_pwg) |
---|
130 | { |
---|
131 | $query = " |
---|
132 | SELECT id_user_FluxBB, id_user_pwg FROM ".Register_FluxBB_ID_TABLE." |
---|
133 | WHERE id_user_pwg = ".$id_user_pwg." |
---|
134 | LIMIT 1 |
---|
135 | ;"; |
---|
136 | |
---|
137 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
138 | |
---|
139 | if (!empty($data)) |
---|
140 | return $data['id_user_FluxBB']; |
---|
141 | else |
---|
142 | return '0'; |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | function FluxBB_Deluser($id_user_FluxBB, $SuppTopicsPosts) |
---|
148 | { |
---|
149 | global $conf; |
---|
150 | |
---|
151 | $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array(); |
---|
152 | |
---|
153 | $query0 = " |
---|
154 | SELECT username, id FROM ".FluxBB_USERS_TABLE." |
---|
155 | WHERE id = ".$id_user_FluxBB." |
---|
156 | LIMIT 1 |
---|
157 | ;"; |
---|
158 | |
---|
159 | $data0 = pwg_db_fetch_assoc(pwg_query($query0)); |
---|
160 | |
---|
161 | // Si égale à VRAI, suppression de tous les posts et topics |
---|
162 | if ($SuppTopicsPosts and $conf_Register_FluxBB[3]) |
---|
163 | { |
---|
164 | // Suppression des posts de cet utilisateur |
---|
165 | $subquery = " |
---|
166 | DELETE FROM ".FluxBB_POSTS_TABLE." |
---|
167 | WHERE poster_id = ".$id_user_FluxBB." |
---|
168 | ;"; |
---|
169 | |
---|
170 | $subresult = pwg_query($subquery); |
---|
171 | |
---|
172 | // Suppression des topics de cet utilisateur |
---|
173 | $subquery = " |
---|
174 | DELETE FROM ".FluxBB_TOPICS_TABLE." |
---|
175 | WHERE BINARY poster = BINARY '".pwg_db_real_escape_string($data0['username'])."' |
---|
176 | ;"; |
---|
177 | |
---|
178 | $subresult = pwg_query($subquery); |
---|
179 | } |
---|
180 | |
---|
181 | // Suppression des abonnements de l'utilisateur |
---|
182 | $subquery = " |
---|
183 | DELETE FROM ".FluxBB_SUBSCRIPTIONS_TABLE." |
---|
184 | WHERE user_id = ".$id_user_FluxBB." |
---|
185 | ;"; |
---|
186 | |
---|
187 | $subresult = pwg_query($subquery); |
---|
188 | |
---|
189 | // Suppression du compte utilisateur |
---|
190 | $subquery = " |
---|
191 | DELETE FROM ".FluxBB_USERS_TABLE." |
---|
192 | WHERE id = ".$id_user_FluxBB." |
---|
193 | ;"; |
---|
194 | |
---|
195 | $subresult = pwg_query($subquery); |
---|
196 | |
---|
197 | FluxBB_Unlinkuser($id_user_FluxBB); |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | function FluxBB_Updateuser($pwg_id, $username, $password, $adresse_mail) |
---|
203 | { |
---|
204 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
205 | |
---|
206 | $query = " |
---|
207 | SELECT id_user_FluxBB as FluxBB_id |
---|
208 | FROM ".Register_FluxBB_ID_TABLE." |
---|
209 | WHERE id_user_pwg = ".$pwg_id." |
---|
210 | ;"; |
---|
211 | |
---|
212 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
213 | |
---|
214 | if (!empty($row)) |
---|
215 | { |
---|
216 | $query = " |
---|
217 | UPDATE ".FluxBB_USERS_TABLE." |
---|
218 | SET username = '".pwg_db_real_escape_string($username)."', email = '".$adresse_mail."', password = '".$password."' |
---|
219 | WHERE id = ".$row['FluxBB_id']." |
---|
220 | ;"; |
---|
221 | |
---|
222 | $result = pwg_query($query); |
---|
223 | |
---|
224 | FluxBB_Linkuser($pwg_id, $row['FluxBB_id']); |
---|
225 | } |
---|
226 | else |
---|
227 | { |
---|
228 | $query = " |
---|
229 | SELECT id as FluxBB_id |
---|
230 | FROM ".FluxBB_USERS_TABLE." |
---|
231 | WHERE BINARY username = BINARY '".pwg_db_real_escape_string($username)."' |
---|
232 | ;"; |
---|
233 | |
---|
234 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
235 | |
---|
236 | if (!empty($row)) |
---|
237 | { |
---|
238 | $query = " |
---|
239 | UPDATE ".FluxBB_USERS_TABLE." |
---|
240 | SET username = '".pwg_db_real_escape_string($username)."', email = '".$adresse_mail."', password = '".$password."' |
---|
241 | WHERE id = ".$row['FluxBB_id']." |
---|
242 | ;"; |
---|
243 | |
---|
244 | $result = pwg_query($query); |
---|
245 | |
---|
246 | FluxBB_Linkuser($pwg_id, $row['FluxBB_id']); |
---|
247 | } |
---|
248 | } |
---|
249 | } |
---|
250 | |
---|
251 | |
---|
252 | function RegFluxBB_Infos($dir) |
---|
253 | { |
---|
254 | $path = $dir; |
---|
255 | |
---|
256 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
257 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
258 | { |
---|
259 | $plugin['name'] = trim( $val[1] ); |
---|
260 | } |
---|
261 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
262 | { |
---|
263 | $plugin['version'] = trim($val[1]); |
---|
264 | } |
---|
265 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
266 | { |
---|
267 | $plugin['uri'] = trim($val[1]); |
---|
268 | } |
---|
269 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
270 | { |
---|
271 | $plugin['description'] = trim($desc); |
---|
272 | } |
---|
273 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
274 | { |
---|
275 | $plugin['description'] = trim($val[1]); |
---|
276 | } |
---|
277 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
278 | { |
---|
279 | $plugin['author'] = trim($val[1]); |
---|
280 | } |
---|
281 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
282 | { |
---|
283 | $plugin['author uri'] = trim($val[1]); |
---|
284 | } |
---|
285 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
286 | { |
---|
287 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
288 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
289 | } |
---|
290 | // IMPORTANT SECURITY ! |
---|
291 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
292 | |
---|
293 | return $plugin ; |
---|
294 | } |
---|
295 | |
---|
296 | function regfluxbb_obsolete_files() |
---|
297 | { |
---|
298 | if (file_exists(REGFLUXBB_PATH.'obsolete.list') |
---|
299 | and $old_files = file(REGFLUXBB_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
300 | and !empty($old_files)) |
---|
301 | { |
---|
302 | array_push($old_files, 'obsolete.list'); |
---|
303 | foreach($old_files as $old_file) |
---|
304 | { |
---|
305 | $path = REGFLUXBB_PATH.$old_file; |
---|
306 | if (is_file($path)) |
---|
307 | { |
---|
308 | @unlink($path); |
---|
309 | } |
---|
310 | } |
---|
311 | } |
---|
312 | } |
---|
313 | ?> |
---|