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

Last change on this file since 7154 was 6815, checked in by Eric, 14 years ago

bug 1434 fixed : Bridge between Register_FluxBB and UAM for users registration control

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