source: extensions/Register_FluxBB/tags/2.1.3/include/functions_Register_FluxBB.inc.php @ 4289

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

[Register_FluxBB] Merged from branch to tags/2.1.3 - Building release 2.1.3

  • Using sha1 hash instead of md5 for password hashing in FluxBB because FluxBB uses prior sha1 hash and md5 only in last sentence.
  • Escaping all characters in login names and be able to retreive them without slashes - FluxBB does not allow this so Piwigo's user names with escaped characters will not been escaped in FluxBB (ie : "it's" in Piwigo will be "It\'s" in FluxBB)
  • Code refactoring
  • Full HTML 4.0 for tpl
  • Property svn:eol-style set to LF
File size: 6.2 KB
Line 
1<?php
2
3function FluxBB_Linkuser($pwg_id, $bb_id)
4{
5  include_once (PHPWG_ROOT_PATH.'/include/constants.php');
6  include_once (Register_FluxBB_PATH.'include/constants.php');
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 = mysql_fetch_array(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  include_once (PHPWG_ROOT_PATH.'/include/constants.php');
43  include_once (Register_FluxBB_PATH.'include/constants.php');
44
45  $query = "
46DELETE FROM ".Register_FluxBB_ID_TABLE."
47WHERE id_user_FluxBB = ".$bb_id."
48;";
49
50  $result = pwg_query($query);
51}
52
53
54
55function FluxBB_Adduser($pwg_id, $login, $password, $adresse_mail)
56{
57  include_once (PHPWG_ROOT_PATH.'/include/constants.php');
58  include_once (Register_FluxBB_PATH.'include/constants.php');
59
60  global $conf;
61
62  $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array();
63
64  $registred = time();
65  $registred_ip = $_SERVER['REMOTE_ADDR'];
66
67  $query = "
68SELECT conf_value
69FROM ".FluxBB_CONFIG_TABLE."
70WHERE conf_name = 'o_default_user_group'
71;";
72
73  $o_default_user_group = mysql_fetch_array(pwg_query($query));
74 
75  $query = "
76SELECT conf_value
77FROM ".FluxBB_CONFIG_TABLE."
78WHERE conf_name = 'o_server_timezone'
79;";
80
81  $o_server_timezone = mysql_fetch_array(pwg_query($query));
82 
83  $query = "
84SELECT conf_value
85FROM ".FluxBB_CONFIG_TABLE."
86WHERE conf_name = 'o_default_lang'
87;";
88
89  $o_default_lang = mysql_fetch_array(pwg_query($query));
90 
91  $query = "
92SELECT conf_value
93FROM ".FluxBB_CONFIG_TABLE."
94WHERE conf_name = 'o_default_style'
95;";
96
97  $o_default_style = mysql_fetch_array(pwg_query($query));
98 
99  $query = '
100INSERT INTO '.FluxBB_USERS_TABLE." (
101  username,
102  ". ( isset($o_default_user_group['conf_value']) ? 'group_id' : '' ) .",
103  password,
104  email,
105  ". ( isset($o_server_timezone['conf_value']) ? 'timezone' : '' ) .",
106  ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .",
107  ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .",
108  registered,
109  registration_ip,
110  last_visit
111  )
112VALUES(
113  '".mysql_real_escape_string($login)."',
114  ". ( isset($o_default_user_group['conf_value']) ? "'".$o_default_user_group['conf_value']."'" : '' ) .",
115  '".$password."',
116        '".$adresse_mail."',
117  ". ( isset($o_server_timezone['conf_value']) ? "'".$o_server_timezone['conf_value']."'" : '' ) .",
118  ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .",
119  ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .",
120  '".$registred."',
121  '".$registred_ip."',
122  '".$registred."'
123  )
124;";
125
126  $result = pwg_query($query);
127
128  $bb_id = mysql_insert_id();
129 
130  FluxBB_Linkuser($pwg_id, $bb_id);
131}
132
133
134
135function FluxBB_Searchuser($id_user_pwg)
136{
137  include_once (PHPWG_ROOT_PATH.'/include/constants.php');
138  include_once (Register_FluxBB_PATH.'include/constants.php');
139
140  $query = "
141SELECT id_user_FluxBB, id_user_pwg FROM ".Register_FluxBB_ID_TABLE."
142WHERE id_user_pwg = ".$id_user_pwg."
143LIMIT 1
144;";
145
146  $data = mysql_fetch_array(pwg_query($query));
147 
148  if (!empty($data))
149    return $data['id_user_FluxBB'];
150  else
151    return '0'; 
152}
153
154
155
156function FluxBB_Deluser($id_user_FluxBB, $SuppTopicsPosts)
157{
158  include_once (PHPWG_ROOT_PATH.'/include/constants.php');
159  include_once (Register_FluxBB_PATH.'include/constants.php');
160
161  global $conf;
162
163  $conf_Register_FluxBB = isset($conf['Register_FluxBB']) ? explode(";" , $conf['Register_FluxBB']) : array();
164
165  $query0 = "
166SELECT username, id FROM ".FluxBB_USERS_TABLE."
167WHERE id = ".$id_user_FluxBB."
168LIMIT 1
169;";
170
171  $data0 = mysql_fetch_array(pwg_query($query0));
172
173  // Si égale à VRAI, suppression de tous les posts et topics
174  if ($SuppTopicsPosts and $conf_Register_FluxBB[3])
175  {
176    // Suppression des posts de cet utilisateur
177    $subquery = "
178DELETE FROM ".FluxBB_POSTS_TABLE."
179WHERE poster_id = ".$id_user_FluxBB."
180;";
181
182    $subresult = pwg_query($subquery);
183
184    // Suppression des topics de cet utilisateur
185    $subquery = "
186DELETE FROM ".FluxBB_TOPICS_TABLE."
187WHERE BINARY poster = BINARY '".mysql_real_escape_string($data0['username'])."'
188;";
189
190    $subresult = pwg_query($subquery);
191  }
192
193  // Suppression des abonnements de l'utilisateur
194  $subquery = "
195DELETE FROM ".FluxBB_SUBSCRIPTIONS_TABLE."
196WHERE user_id = ".$id_user_FluxBB."
197;";
198
199  $subresult = pwg_query($subquery);
200 
201  // Suppression du compte utilisateur
202  $subquery = "
203DELETE FROM ".FluxBB_USERS_TABLE."
204WHERE id = ".$id_user_FluxBB."
205;";
206
207  $subresult = pwg_query($subquery);
208
209  FluxBB_Unlinkuser($id_user_FluxBB);
210}
211
212
213
214function FluxBB_Updateuser($pwg_id, $username, $password, $adresse_mail)
215{
216  include_once (PHPWG_ROOT_PATH.'/include/constants.php');
217  include_once (Register_FluxBB_PATH.'include/constants.php');
218  include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
219
220  $query = "
221SELECT id_user_FluxBB as FluxBB_id
222FROM ".Register_FluxBB_ID_TABLE."
223WHERE id_user_pwg = ".$pwg_id."
224;";
225
226  $row = mysql_fetch_array(pwg_query($query));
227
228  if (!empty($row))
229  {
230    $query = "
231UPDATE ".FluxBB_USERS_TABLE."
232SET username = '".mysql_real_escape_string($username)."', email = '".$adresse_mail."', password = '".$password."'
233WHERE id = ".$row['FluxBB_id']."
234;";
235   
236    $result = pwg_query($query);
237     
238    FluxBB_Linkuser($pwg_id, $row['FluxBB_id']);
239  }
240  else
241  {
242    $query = "
243SELECT id as FluxBB_id
244FROM ".FluxBB_USERS_TABLE."
245WHERE BINARY username = BINARY '".mysql_real_escape_string($username)."'
246;";
247
248    $row = mysql_fetch_array(pwg_query($query));
249 
250    if (!empty($row))
251    {
252      $query = "
253UPDATE ".FluxBB_USERS_TABLE."
254SET username = '".mysql_real_escape_string($username)."', email = '".$adresse_mail."', password = '".$password."'
255WHERE id = ".$row['FluxBB_id']."
256;";
257     
258      $result = pwg_query($query);
259     
260      FluxBB_Linkuser($pwg_id, $row['FluxBB_id']);
261    }
262  }
263}
264?>
Note: See TracBrowser for help on using the repository browser.