source: extensions/Register_FluxBB/branches/2.3/include/functions.inc.php @ 7983

Last change on this file since 7983 was 7983, checked in by Eric, 13 years ago

Merge from trunk to branch 2.3

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