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

Last change on this file since 8044 was 8044, 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($errors, $user)
136{
137  global $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($user['username'])."'
145;";
146
147  $count = pwg_db_num_rows(pwg_query($query));
148
149  if ($count > 0)
150  {
151    array_push($errors, l10n('this login is already used'));
152  }
153  return $errors; 
154}
155
156
157function FluxBB_Linkuser($pwg_id, $bb_id)
158{
159  $query = "
160SELECT pwg.id as pwg_id, bb.id as bb_id
161FROM ".USERS_TABLE." pwg, ".FluxBB_USERS_TABLE." bb
162WHERE pwg.id = ".$pwg_id."
163AND bb.id = ".$bb_id."
164AND pwg.username = bb.username
165;";
166 
167  $data = pwg_db_fetch_row(pwg_query($query));
168 
169  if (!empty($data))
170  {
171    $subquery = "
172DELETE FROM ".Register_FluxBB_ID_TABLE."
173WHERE id_user_pwg = '".$pwg_id."'
174OR id_user_FluxBB = '".$bb_id."'
175;";
176
177    $subresult = pwg_query($subquery);
178
179    $subquery = "
180INSERT INTO ".Register_FluxBB_ID_TABLE."
181  (id_user_pwg, id_user_FluxBB)
182VALUES (".$pwg_id.", ".$bb_id.")
183;";
184
185    $subresult = pwg_query($subquery);
186  }
187}
188
189
190
191function FluxBB_Unlinkuser($bb_id)
192{
193  $query = "
194DELETE FROM ".Register_FluxBB_ID_TABLE."
195WHERE id_user_FluxBB = ".$bb_id."
196;";
197
198  $result = pwg_query($query);
199}
200
201
202
203function FluxBB_Adduser($pwg_id, $login, $password, $adresse_mail)
204{
205  global $errors, $conf;
206
207  $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array();
208
209  $registred = time();
210  $registred_ip = $_SERVER['REMOTE_ADDR'];
211 
212  // Check if UAM is installed and if bridge is set - Exception for admins and webmasters
213  if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB[6]) and $conf_Register_FluxBB[6] == 'true')
214  {
215    $o_default_user_group = $conf_Register_FluxBB[7];
216  }
217  else
218  {
219    $query = "
220SELECT conf_value
221FROM ".FluxBB_CONFIG_TABLE."
222WHERE conf_name = 'o_default_user_group'
223;";
224
225    $o_default_user_group = pwg_db_fetch_assoc(pwg_query($query));
226  }
227
228// Check for FluxBB version 1.4.x and get the correct value
229  $query1 = "
230SELECT conf_value
231FROM ".FluxBB_CONFIG_TABLE."
232WHERE conf_name = 'o_default_timezone'
233;";
234
235  $count1 = pwg_db_num_rows(pwg_query($query1));
236
237// Check for FluxBB version 1.2.x and get the correct value
238  $query2 = "
239SELECT conf_value
240FROM ".FluxBB_CONFIG_TABLE."
241WHERE conf_name = 'o_server_timezone'
242;";
243
244  $count2 = pwg_db_num_rows(pwg_query($query2));
245 
246  if ($count1 == 1 and $count2 == 0)
247  {
248    $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query1));
249  }
250  else if ($count1 == 0 and $count2 == 1)
251  {
252    $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query2));
253  }
254 
255 
256  $query = "
257SELECT conf_value
258FROM ".FluxBB_CONFIG_TABLE."
259WHERE conf_name = 'o_default_lang'
260;";
261
262  $o_default_lang = pwg_db_fetch_assoc(pwg_query($query));
263 
264  $query = "
265SELECT conf_value
266FROM ".FluxBB_CONFIG_TABLE."
267WHERE conf_name = 'o_default_style'
268;";
269
270  $o_default_style = pwg_db_fetch_assoc(pwg_query($query));
271
272  $query = "
273INSERT INTO ".FluxBB_USERS_TABLE." (
274  username,
275  ". ( isset($o_default_user_group['conf_value']) ? 'group_id' : '' ) .",
276  password,
277  email,
278  ". ( isset($o_default_timezone['conf_value']) ? 'timezone' : '' ) .",
279  ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .",
280  ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .",
281  registered,
282  registration_ip,
283  last_visit
284  )
285VALUES(
286  '".pwg_db_real_escape_string($login)."',
287  ". ( isset($o_default_user_group['conf_value']) ? "'".$o_default_user_group['conf_value']."'" : '' ) .",
288  '".$password."',
289        '".$adresse_mail."',
290  ". ( isset($o_default_timezone['conf_value']) ? "'".$o_default_timezone['conf_value']."'" : '' ) .",
291  ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .",
292  ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .",
293  '".$registred."',
294  '".$registred_ip."',
295  '".$registred."'
296  )
297;";
298
299  $result = pwg_query($query);
300
301  $bb_id = pwg_db_insert_id();
302 
303  FluxBB_Linkuser($pwg_id, $bb_id);
304}
305
306
307
308function FluxBB_Searchuser($id_user_pwg)
309{
310  $query = "
311SELECT id_user_FluxBB, id_user_pwg FROM ".Register_FluxBB_ID_TABLE."
312WHERE id_user_pwg = ".$id_user_pwg."
313LIMIT 1
314;";
315
316  $data = pwg_db_fetch_assoc(pwg_query($query));
317 
318  if (!empty($data))
319    return $data['id_user_FluxBB'];
320  else
321    return '0'; 
322}
323
324
325
326function FluxBB_Deluser($id_user_FluxBB, $SuppTopicsPosts)
327{
328  global $conf;
329
330  $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array();
331
332  $query0 = "
333SELECT username, id FROM ".FluxBB_USERS_TABLE."
334WHERE id = ".$id_user_FluxBB."
335LIMIT 1
336;";
337
338  $data0 = pwg_db_fetch_assoc(pwg_query($query0));
339
340  // If True, delete related topics and posts
341  if ($SuppTopicsPosts and $conf_Register_FluxBB[3])
342  {
343    // Delete posts and topics of this user
344    $subquery = "
345DELETE FROM ".FluxBB_POSTS_TABLE."
346WHERE poster_id = ".$id_user_FluxBB."
347;";
348
349    $subresult = pwg_query($subquery);
350
351    // Delete topics of this user
352    $subquery = "
353DELETE FROM ".FluxBB_TOPICS_TABLE."
354WHERE BINARY poster = BINARY '".pwg_db_real_escape_string($data0['username'])."'
355;";
356
357    $subresult = pwg_query($subquery);
358  }
359
360  // Delete user's subscriptions
361  $subquery = "
362DELETE FROM ".FluxBB_SUBSCRIPTIONS_TABLE."
363WHERE user_id = ".$id_user_FluxBB."
364;";
365
366  $subresult = pwg_query($subquery);
367 
368  // Delete user's account
369  $subquery = "
370DELETE FROM ".FluxBB_USERS_TABLE."
371WHERE id = ".$id_user_FluxBB."
372;";
373
374  $subresult = pwg_query($subquery);
375
376  FluxBB_Unlinkuser($id_user_FluxBB);
377}
378
379
380
381function FluxBB_Updateuser($pwg_id, $username, $password, $adresse_mail)
382{
383  include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
384
385  $query = "
386SELECT id_user_FluxBB as FluxBB_id
387FROM ".Register_FluxBB_ID_TABLE."
388WHERE id_user_pwg = ".$pwg_id."
389;";
390
391  $row = pwg_db_fetch_assoc(pwg_query($query));
392
393  if (!empty($row))
394  {
395    $query = "
396UPDATE ".FluxBB_USERS_TABLE."
397SET username = '".pwg_db_real_escape_string($username)."', email = '".$adresse_mail."', password = '".$password."'
398WHERE id = ".$row['FluxBB_id']."
399;";
400   
401    $result = pwg_query($query);
402     
403    FluxBB_Linkuser($pwg_id, $row['FluxBB_id']);
404  }
405  else
406  {
407    $query = "
408SELECT id as FluxBB_id
409FROM ".FluxBB_USERS_TABLE."
410WHERE BINARY username = BINARY '".pwg_db_real_escape_string($username)."'
411;";
412
413    $row = pwg_db_fetch_assoc(pwg_query($query));
414 
415    if (!empty($row))
416    {
417      $query = "
418UPDATE ".FluxBB_USERS_TABLE."
419SET username = '".pwg_db_real_escape_string($username)."', email = '".$adresse_mail."', password = '".$password."'
420WHERE id = ".$row['FluxBB_id']."
421;";
422     
423      $result = pwg_query($query);
424     
425      FluxBB_Linkuser($pwg_id, $row['FluxBB_id']);
426    }
427  }
428}
429
430
431function RegFluxBB_Infos($dir)
432{
433  $path = $dir;
434
435  $plg_data = implode( '', file($path.'main.inc.php') );
436  if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
437  {
438    $plugin['name'] = trim( $val[1] );
439  }
440  if (preg_match("|Version: (.*)|", $plg_data, $val))
441  {
442    $plugin['version'] = trim($val[1]);
443  }
444  if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
445  {
446    $plugin['uri'] = trim($val[1]);
447  }
448  if ($desc = load_language('description.txt', $path.'/', array('return' => true)))
449  {
450    $plugin['description'] = trim($desc);
451  }
452  elseif ( preg_match("|Description: (.*)|", $plg_data, $val) )
453  {
454    $plugin['description'] = trim($val[1]);
455  }
456  if ( preg_match("|Author: (.*)|", $plg_data, $val) )
457  {
458    $plugin['author'] = trim($val[1]);
459  }
460  if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
461  {
462    $plugin['author uri'] = trim($val[1]);
463  }
464  if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid='))
465  {
466    list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']);
467    if (is_numeric($extension)) $plugin['extension'] = $extension;
468  }
469// IMPORTANT SECURITY !
470  $plugin = array_map('htmlspecialchars', $plugin);
471
472  return $plugin ;
473}
474
475function regfluxbb_obsolete_files()
476{
477  if (file_exists(REGFLUXBB_PATH.'obsolete.list')
478    and $old_files = file(REGFLUXBB_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES)
479    and !empty($old_files))
480  {
481    array_push($old_files, 'obsolete.list');
482    foreach($old_files as $old_file)
483    {
484      $path = REGFLUXBB_PATH.$old_file;
485      if (is_file($path))
486      {
487        @unlink($path);
488      }
489    }
490  }
491}
492?>
Note: See TracBrowser for help on using the repository browser.