source: extensions/Register_FluxBB/trunk/include/functions.inc.php @ 9885

Last change on this file since 9885 was 9885, checked in by Eric, 10 years ago

Piwigo 2.2 compliance (nicer URL for admin panel)

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