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

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

[Register_FluxBB]

  • Bug 1577 fixed : Compatibility with other database systems than MySql like PostgreSql or Sqlite. Using Piwigo's pwg_db_### functions.
  • Property svn:eol-style set to LF
File size: 7.2 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  $query = "
62SELECT conf_value
63FROM ".FluxBB_CONFIG_TABLE."
64WHERE conf_name = 'o_default_user_group'
65;";
66
67  $o_default_user_group = pwg_db_fetch_assoc(pwg_query($query));
68 
69  $query = "
70SELECT conf_value
71FROM ".FluxBB_CONFIG_TABLE."
72WHERE conf_name = 'o_server_timezone'
73;";
74
75  $o_server_timezone = pwg_db_fetch_assoc(pwg_query($query));
76 
77  $query = "
78SELECT conf_value
79FROM ".FluxBB_CONFIG_TABLE."
80WHERE conf_name = 'o_default_lang'
81;";
82
83  $o_default_lang = pwg_db_fetch_assoc(pwg_query($query));
84 
85  $query = "
86SELECT conf_value
87FROM ".FluxBB_CONFIG_TABLE."
88WHERE conf_name = 'o_default_style'
89;";
90
91  $o_default_style = pwg_db_fetch_assoc(pwg_query($query));
92 
93  $query = '
94INSERT 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  )
106VALUES(
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
129function FluxBB_Searchuser($id_user_pwg)
130{
131  $query = "
132SELECT id_user_FluxBB, id_user_pwg FROM ".Register_FluxBB_ID_TABLE."
133WHERE id_user_pwg = ".$id_user_pwg."
134LIMIT 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
147function 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 = "
154SELECT username, id FROM ".FluxBB_USERS_TABLE."
155WHERE id = ".$id_user_FluxBB."
156LIMIT 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 = "
166DELETE FROM ".FluxBB_POSTS_TABLE."
167WHERE poster_id = ".$id_user_FluxBB."
168;";
169
170    $subresult = pwg_query($subquery);
171
172    // Suppression des topics de cet utilisateur
173    $subquery = "
174DELETE FROM ".FluxBB_TOPICS_TABLE."
175WHERE 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 = "
183DELETE FROM ".FluxBB_SUBSCRIPTIONS_TABLE."
184WHERE user_id = ".$id_user_FluxBB."
185;";
186
187  $subresult = pwg_query($subquery);
188 
189  // Suppression du compte utilisateur
190  $subquery = "
191DELETE FROM ".FluxBB_USERS_TABLE."
192WHERE id = ".$id_user_FluxBB."
193;";
194
195  $subresult = pwg_query($subquery);
196
197  FluxBB_Unlinkuser($id_user_FluxBB);
198}
199
200
201
202function FluxBB_Updateuser($pwg_id, $username, $password, $adresse_mail)
203{
204  include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
205
206  $query = "
207SELECT id_user_FluxBB as FluxBB_id
208FROM ".Register_FluxBB_ID_TABLE."
209WHERE id_user_pwg = ".$pwg_id."
210;";
211
212  $row = pwg_db_fetch_assoc(pwg_query($query));
213
214  if (!empty($row))
215  {
216    $query = "
217UPDATE ".FluxBB_USERS_TABLE."
218SET username = '".pwg_db_real_escape_string($username)."', email = '".$adresse_mail."', password = '".$password."'
219WHERE 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 = "
229SELECT id as FluxBB_id
230FROM ".FluxBB_USERS_TABLE."
231WHERE 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 = "
239UPDATE ".FluxBB_USERS_TABLE."
240SET username = '".pwg_db_real_escape_string($username)."', email = '".$adresse_mail."', password = '".$password."'
241WHERE 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
252function 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
296function 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?>
Note: See TracBrowser for help on using the repository browser.