1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @title User Core Model Class |
4
|
|
|
* |
5
|
|
|
* @author Pierre-Henry Soria <[email protected]> |
6
|
|
|
* @copyright (c) 2012-2017, Pierre-Henry Soria. All Rights Reserved. |
7
|
|
|
* @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
8
|
|
|
* @package PH7 / App / System / Core / Model |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace PH7; |
12
|
|
|
|
13
|
|
|
use PH7\Framework\Mvc\Model\Engine\Model; |
14
|
|
|
use PH7\Framework\Mvc\Model\Engine\Db; |
|
|
|
|
15
|
|
|
use PH7\Framework\Mvc\Model\DbConfig; |
16
|
|
|
use PH7\Framework\Mvc\Model\Engine\Util\Various; |
17
|
|
|
use PH7\Framework\Str\Str; |
18
|
|
|
use PH7\Framework\Date\CDateTime; |
19
|
|
|
use PH7\Framework\Session\Session; |
20
|
|
|
use PH7\Framework\Security\Security; |
|
|
|
|
21
|
|
|
use PH7\Framework\CArray\ObjArr; |
22
|
|
|
use PH7\Framework\Ip\Ip; |
23
|
|
|
use stdClass; |
24
|
|
|
|
25
|
|
|
// Abstract Class |
26
|
|
|
class UserCoreModel extends Model |
27
|
|
|
{ |
28
|
|
|
const CACHE_GROUP = 'db/sys/mod/user', CACHE_TIME = 604800; |
29
|
|
|
|
30
|
|
|
/** @var string */ |
31
|
|
|
protected $sCurrentDate; |
32
|
|
|
|
33
|
|
|
/** @var string */ |
34
|
|
|
protected $iProfileId; |
35
|
|
|
|
36
|
|
|
/** @var boolean */ |
37
|
|
|
private $bOnlyAvatarsSet; |
38
|
|
|
|
39
|
|
|
public function __construct() |
40
|
|
|
{ |
41
|
|
|
parent::__construct(); |
42
|
|
|
|
43
|
|
|
$this->sCurrentDate = (new CDateTime)->get()->dateTime('Y-m-d H:i:s'); |
44
|
|
|
$this->iProfileId = (new Session)->get('member_id'); |
45
|
|
|
$this->bOnlyAvatarsSet = (bool) DbConfig::getSetting('profileWithAvatarSet'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public static function checkGroup() |
49
|
|
|
{ |
50
|
|
|
$oSession = new Session; |
51
|
|
|
|
52
|
|
|
if (!$oSession->exists('member_group_id')) { |
53
|
|
|
$oSession->regenerateId(); |
54
|
|
|
$oSession->set('member_group_id', PermissionCore::VISITOR_GROUP_ID); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT permissions FROM' . Db::prefix('Memberships') . 'WHERE groupId = :groupId LIMIT 1'); |
58
|
|
|
$rStmt->bindValue(':groupId', $oSession->get('member_group_id'), \PDO::PARAM_INT); |
59
|
|
|
$rStmt->execute(); |
60
|
|
|
$oFetch = $rStmt->fetch(\PDO::FETCH_OBJ); |
61
|
|
|
Db::free($rStmt); |
62
|
|
|
unset($oSession); |
63
|
|
|
|
64
|
|
|
return ObjArr::toObject(unserialize($oFetch->permissions)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Login method for Members and Affiliate, but not for Admins since it has another method PH7\AdminModel::adminLogin() even more secure. |
69
|
|
|
* |
70
|
|
|
* @param string $sEmail Not case sensitive since on lot of mobile devices (such as iPhone), the first letter is uppercase. |
71
|
|
|
* @param string $sPassword |
72
|
|
|
* @param string $sTable Default 'Members' |
73
|
|
|
* |
74
|
|
|
* @return mixed (boolean "true" or string "message") |
75
|
|
|
*/ |
76
|
|
|
public function login($sEmail, $sPassword, $sTable = 'Members') |
77
|
|
|
{ |
78
|
|
|
Various::checkModelTable($sTable); |
79
|
|
|
|
80
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT email, password FROM' . Db::prefix($sTable) . 'WHERE email = :email LIMIT 1'); |
81
|
|
|
$rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR); |
82
|
|
|
$rStmt->execute(); |
83
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
84
|
|
|
Db::free($rStmt); |
85
|
|
|
|
86
|
|
|
$sDbEmail = (!empty($oRow->email)) ? $oRow->email : ''; |
87
|
|
|
$sDbPassword = (!empty($oRow->password)) ? $oRow->password : ''; |
88
|
|
|
|
89
|
|
|
if (strtolower($sEmail) !== strtolower($sDbEmail)) { |
90
|
|
|
return 'email_does_not_exist'; |
91
|
|
|
} |
92
|
|
|
if (!Security::checkPwd($sPassword, $sDbPassword)) { |
93
|
|
|
return 'password_does_not_exist'; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return true; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Set Log Session. |
101
|
|
|
* |
102
|
|
|
* @param string $sEmail |
103
|
|
|
* @param string $sUsername |
104
|
|
|
* @param string $sFirstName |
105
|
|
|
* @param string $sTable |
106
|
|
|
* @param string $sTable Default 'Members' |
107
|
|
|
* |
108
|
|
|
* @return void |
109
|
|
|
*/ |
110
|
|
|
public function sessionLog($sEmail, $sUsername, $sFirstName, $sTable = 'Members') |
111
|
|
|
{ |
112
|
|
|
Various::checkModelTable($sTable); |
113
|
|
|
|
114
|
|
|
$rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix($sTable.'LogSess') . '(email, username, firstName, ip) |
115
|
|
|
VALUES (:email, :username, :firstName, :ip)'); |
116
|
|
|
$rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR); |
117
|
|
|
$rStmt->bindValue(':username', $sUsername, \PDO::PARAM_STR); |
118
|
|
|
$rStmt->bindValue(':firstName', $sFirstName, \PDO::PARAM_STR); |
119
|
|
|
$rStmt->bindValue(':ip', Ip::get(), \PDO::PARAM_STR); |
120
|
|
|
$rStmt->execute(); |
121
|
|
|
Db::free($rStmt); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Read Profile Data. |
126
|
|
|
* |
127
|
|
|
* @param integer $iProfileId The user ID |
128
|
|
|
* @param string $sTable Default 'Members' |
129
|
|
|
* |
130
|
|
|
* @return stdClass The data of a member |
131
|
|
|
*/ |
132
|
|
|
public function readProfile($iProfileId, $sTable = 'Members') |
133
|
|
|
{ |
134
|
|
|
$this->cache->start(self::CACHE_GROUP, 'readProfile' . $iProfileId . $sTable, static::CACHE_TIME); |
135
|
|
|
|
136
|
|
|
if (!$oData = $this->cache->get()) { |
137
|
|
|
Various::checkModelTable($sTable); |
138
|
|
|
|
139
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1'); |
140
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
141
|
|
|
$rStmt->execute(); |
142
|
|
|
$oData = $rStmt->fetch(\PDO::FETCH_OBJ); |
143
|
|
|
Db::free($rStmt); |
144
|
|
|
$this->cache->put($oData); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return $oData; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Get the total number of members. |
152
|
|
|
* |
153
|
|
|
* @param string $sTable Default 'Members' |
154
|
|
|
* @param integer $iDay Default '0' |
155
|
|
|
* @param string $sGenger Values available 'all', 'male', 'female'. 'couple' is only available to Members. Default 'all' |
156
|
|
|
* |
157
|
|
|
* @return integer Total Users |
158
|
|
|
*/ |
159
|
|
|
public function total($sTable = 'Members', $iDay = 0, $sGenger = 'all') |
160
|
|
|
{ |
161
|
|
|
Various::checkModelTable($sTable); |
162
|
|
|
$iDay = (int) $iDay; |
163
|
|
|
|
164
|
|
|
$bIsDay = ($iDay > 0); |
165
|
|
|
$bIsGenger = ($sTable === 'Members' ? ($sGenger === 'male' || $sGenger === 'female' || $sGenger === 'couple') : ($sGenger === 'male' || $sGenger === 'female')); |
166
|
|
|
|
167
|
|
|
$sSqlDay = $bIsDay ? ' AND (joinDate + INTERVAL :day DAY) > NOW()' : ''; |
168
|
|
|
$sSqlGender = $bIsGenger ? ' AND sex = :gender' : ''; |
169
|
|
|
|
170
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT COUNT(profileId) AS totalUsers FROM' . Db::prefix($sTable) . 'WHERE username <> \'' . PH7_GHOST_USERNAME . '\'' . $sSqlDay . $sSqlGender); |
171
|
|
|
if ($bIsDay) $rStmt->bindValue(':day', $iDay, \PDO::PARAM_INT); |
172
|
|
|
if ($bIsGenger) $rStmt->bindValue(':gender', $sGenger, \PDO::PARAM_STR); |
173
|
|
|
$rStmt->execute(); |
174
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
175
|
|
|
Db::free($rStmt); |
176
|
|
|
return (int) $oRow->totalUsers; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Update profile data. |
181
|
|
|
* |
182
|
|
|
* @param string $sSection |
183
|
|
|
* @param string $sValue |
184
|
|
|
* @param integer $iProfileId Profile ID |
185
|
|
|
* @param string $sTable Default 'Members' |
186
|
|
|
* |
187
|
|
|
* @return void |
188
|
|
|
*/ |
189
|
|
|
public function updateProfile($sSection, $sValue, $iProfileId, $sTable ='Members') |
190
|
|
|
{ |
191
|
|
|
Various::checkModelTable($sTable); |
192
|
|
|
|
193
|
|
|
$this->orm->update($sTable, $sSection, $sValue, 'profileId', $iProfileId); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Update Privacy setting data. |
198
|
|
|
* |
199
|
|
|
* @param string $sSection |
200
|
|
|
* @param string $sValue |
201
|
|
|
* @param integer $iProfileId Profile ID |
202
|
|
|
* |
203
|
|
|
* @return void |
204
|
|
|
*/ |
205
|
|
|
public function updatePrivacySetting($sSection, $sValue, $iProfileId) |
206
|
|
|
{ |
207
|
|
|
$this->orm->update('MembersPrivacy', $sSection, $sValue, 'profileId', $iProfileId); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Change password of a member. |
212
|
|
|
* |
213
|
|
|
* @param string $sEmail |
214
|
|
|
* @param string $sNewPassword |
215
|
|
|
* @param string $sTable |
216
|
|
|
* |
217
|
|
|
* @return boolean |
218
|
|
|
*/ |
219
|
|
|
public function changePassword($sEmail, $sNewPassword, $sTable) |
220
|
|
|
{ |
221
|
|
|
Various::checkModelTable($sTable); |
222
|
|
|
|
223
|
|
|
$rStmt = Db::getInstance()->prepare('UPDATE' . Db::prefix($sTable) . 'SET password = :newPassword WHERE email = :email LIMIT 1'); |
224
|
|
|
$rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR); |
225
|
|
|
$rStmt->bindValue(':newPassword', Security::hashPwd($sNewPassword), \PDO::PARAM_STR); |
226
|
|
|
|
227
|
|
|
return $rStmt->execute(); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Set a new hash validation. |
232
|
|
|
* |
233
|
|
|
* @param integer $iProfileId |
234
|
|
|
* @param string $sHash |
235
|
|
|
* @param string $sTable |
236
|
|
|
* |
237
|
|
|
* @return boolean |
238
|
|
|
*/ |
239
|
|
|
public function setNewHashValidation($iProfileId, $sHash, $sTable) |
240
|
|
|
{ |
241
|
|
|
Various::checkModelTable($sTable); |
242
|
|
|
|
243
|
|
|
$rStmt = Db::getInstance()->prepare('UPDATE' . Db::prefix($sTable) . 'SET hashValidation = :hash WHERE profileId = :profileId LIMIT 1'); |
244
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
245
|
|
|
$rStmt->bindParam(':hash', $sHash, \PDO::PARAM_STR, 40); |
246
|
|
|
|
247
|
|
|
return $rStmt->execute(); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Check the hash validation. |
252
|
|
|
* |
253
|
|
|
* @param string $sEmail |
254
|
|
|
* @param string $sHash |
255
|
|
|
* @param string $sTable |
256
|
|
|
* |
257
|
|
|
* @return boolean |
258
|
|
|
*/ |
259
|
|
|
public function checkHashValidation($sEmail, $sHash, $sTable) |
260
|
|
|
{ |
261
|
|
|
Various::checkModelTable($sTable); |
262
|
|
|
|
263
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT COUNT(profileId) FROM' . Db::prefix($sTable) . 'WHERE email = :email AND hashValidation = :hash LIMIT 1'); |
264
|
|
|
$rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR); |
265
|
|
|
$rStmt->bindParam(':hash', $sHash, \PDO::PARAM_STR, 40); |
266
|
|
|
$rStmt->execute(); |
267
|
|
|
|
268
|
|
|
return $rStmt->fetchColumn() == 1; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Search users. |
273
|
|
|
* |
274
|
|
|
* @param array $aParams |
275
|
|
|
* @param boolean $bCount |
276
|
|
|
* @param integer $iOffset |
277
|
|
|
* @param integer $iLimit |
278
|
|
|
* |
279
|
|
|
* @return stdClass|integer Object for the users list returned or Integer for the total number users returned. |
280
|
|
|
*/ |
281
|
|
|
public function search(array $aParams, $bCount, $iOffset, $iLimit) |
282
|
|
|
{ |
283
|
|
|
$bCount = (bool) $bCount; |
284
|
|
|
$iOffset = (int) $iOffset; |
285
|
|
|
$iLimit = (int) $iLimit; |
286
|
|
|
|
287
|
|
|
$bIsFirstName = !empty($aParams[SearchQueryCore::FIRST_NAME]) && Str::noSpaces($aParams[SearchQueryCore::FIRST_NAME]); |
288
|
|
|
$bIsMiddleName = !empty($aParams[SearchQueryCore::MIDDLE_NAME]) && Str::noSpaces($aParams[SearchQueryCore::MIDDLE_NAME]); |
289
|
|
|
$bIsLastName = !empty($aParams[SearchQueryCore::LAST_NAME]) && Str::noSpaces($aParams[SearchQueryCore::LAST_NAME]); |
290
|
|
|
$bIsSingleAge = !empty($aParams[SearchQueryCore::AGE]); |
291
|
|
|
$bIsAge = empty($aParams[SearchQueryCore::AGE]) && !empty($aParams[SearchQueryCore::MIN_AGE]) && !empty($aParams[SearchQueryCore::MAX_AGE]); |
292
|
|
|
$bIsHeight = !empty($aParams[SearchQueryCore::HEIGHT]); |
293
|
|
|
$bIsWeight = !empty($aParams[SearchQueryCore::WEIGHT]); |
294
|
|
|
$bIsCountry = !empty($aParams[SearchQueryCore::COUNTRY]) && Str::noSpaces($aParams[SearchQueryCore::COUNTRY]); |
295
|
|
|
$bIsCity = !empty($aParams[SearchQueryCore::CITY]) && Str::noSpaces($aParams[SearchQueryCore::CITY]); |
296
|
|
|
$bIsState = !empty($aParams[SearchQueryCore::STATE]) && Str::noSpaces($aParams[SearchQueryCore::STATE]); |
297
|
|
|
$bIsZipCode = !empty($aParams[SearchQueryCore::ZIP_CODE]) && Str::noSpaces($aParams[SearchQueryCore::ZIP_CODE]); |
298
|
|
|
$bIsMail = !empty($aParams[SearchQueryCore::EMAIL]) && Str::noSpaces($aParams[SearchQueryCore::EMAIL]); |
299
|
|
|
$bIsSex = !empty($aParams[SearchQueryCore::SEX]); |
300
|
|
|
$bHideUserLogged = !empty($this->iProfileId); |
301
|
|
|
$bIsMatchSex = !empty($aParams[SearchQueryCore::MATCH_SEX]); |
302
|
|
|
|
303
|
|
|
$sSqlLimit = !$bCount ? 'LIMIT :offset, :limit' : ''; |
304
|
|
|
$sSqlSelect = !$bCount ? '*' : 'COUNT(m.profileId) AS totalUsers'; |
305
|
|
|
$sSqlFirstName = $bIsFirstName ? ' AND firstName = :firstName' : ''; |
306
|
|
|
$sSqlMiddleName = $bIsMiddleName ? ' AND middleName = :middleName' : ''; |
307
|
|
|
$sSqlLastName = $bIsLastName ? ' AND lastName = :lastName' : ''; |
308
|
|
|
$sSqlSingleAge = $bIsSingleAge ? ' AND birthDate LIKE :birthDate ' : ''; |
309
|
|
|
$sSqlAge = $bIsAge ? ' AND birthDate BETWEEN DATE_SUB(\'' . $this->sCurrentDate . '\', INTERVAL :age2 YEAR) AND DATE_SUB(\'' . $this->sCurrentDate . '\', INTERVAL :age1 YEAR) ' : ''; |
310
|
|
|
$sSqlHeight = $bIsHeight ? ' AND height = :height ' : ''; |
311
|
|
|
$sSqlWeight = $bIsWeight ? ' AND weight = :weight ' : ''; |
312
|
|
|
$sSqlCountry = $bIsCountry ? ' AND country = :country ' : ''; |
313
|
|
|
$sSqlCity = $bIsCity ? ' AND city LIKE :city ' : ''; |
314
|
|
|
$sSqlState = $bIsState ? ' AND state LIKE :state ' : ''; |
315
|
|
|
$sSqlZipCode = $bIsZipCode ? ' AND zipCode LIKE :zipCode ' : ''; |
316
|
|
|
$sSqlEmail = $bIsMail ? ' AND email LIKE :email ' : ''; |
317
|
|
|
$sSqlOnline = !empty($aParams[SearchQueryCore::ONLINE]) ? ' AND userStatus = 1 AND lastActivity > DATE_SUB(\'' . $this->sCurrentDate . '\', INTERVAL ' . DbConfig::getSetting('userTimeout') . ' MINUTE) ' : ''; |
318
|
|
|
$sSqlAvatar = !empty($aParams[SearchQueryCore::AVATAR]) ? ' AND avatar IS NOT NULL AND approvedAvatar = 1 ' : ''; |
319
|
|
|
$sSqlHideLoggedProfile = $bHideUserLogged ? ' AND (m.profileId <> :profileId)' : ''; |
320
|
|
|
|
321
|
|
|
if (empty($aParams[SearchQueryCore::ORDER])) { |
322
|
|
|
$aParams[SearchQueryCore::ORDER] = SearchCoreModel::LATEST; // Default is "ORDER BY joinDate" |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
if (empty($aParams[SearchQueryCore::SORT])) { |
326
|
|
|
$aParams[SearchQueryCore::SORT] = SearchCoreModel::ASC; // Default is "ascending" |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
$sSqlOrder = SearchCoreModel::order($aParams[SearchQueryCore::ORDER], $aParams[SearchQueryCore::SORT]); |
330
|
|
|
|
331
|
|
|
$sSqlMatchSex = $bIsMatchSex ? ' AND matchSex LIKE :matchSex ' : ''; |
332
|
|
|
|
333
|
|
|
if ($bIsSex) { |
334
|
|
|
$sGender = ''; |
335
|
|
|
$aSex = $aParams[SearchQueryCore::SEX]; |
336
|
|
|
foreach ($aSex as $sSex) { |
337
|
|
|
if ($sSex === 'male') { |
338
|
|
|
$sGender .= '\'male\','; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
if ($sSex === 'female') { |
342
|
|
|
$sGender .= '\'female\','; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
if ($sSex === 'couple') { |
346
|
|
|
$sGender .= '\'couple\','; |
347
|
|
|
} |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
$sSqlSex = ' AND sex IN (' . rtrim($sGender, ',') . ') '; |
351
|
|
|
} else { |
352
|
|
|
$sSqlSex = ''; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
$rStmt = Db::getInstance()->prepare( |
356
|
|
|
'SELECT ' . $sSqlSelect . ' FROM' . Db::prefix('Members') . 'AS m LEFT JOIN' . Db::prefix('MembersPrivacy') . 'AS p USING(profileId) |
357
|
|
|
LEFT JOIN' . Db::prefix('MembersInfo') . 'AS i USING(profileId) WHERE username <> \'' . PH7_GHOST_USERNAME . '\' AND searchProfile = \'yes\' |
358
|
|
|
AND (groupId <> 1) AND (groupId <> 9) AND (ban = 0)' . $sSqlHideLoggedProfile . $sSqlFirstName . $sSqlMiddleName . $sSqlLastName . $sSqlMatchSex . $sSqlSex . $sSqlSingleAge . $sSqlAge . $sSqlCountry . $sSqlCity . $sSqlState . |
359
|
|
|
$sSqlZipCode . $sSqlHeight . $sSqlWeight . $sSqlEmail . $sSqlOnline . $sSqlAvatar . $sSqlOrder . $sSqlLimit |
360
|
|
|
); |
361
|
|
|
|
362
|
|
|
if ($bIsMatchSex) $rStmt->bindValue(':matchSex', '%' . $aParams[SearchQueryCore::MATCH_SEX] . '%', \PDO::PARAM_STR); |
363
|
|
|
if ($bIsFirstName) $rStmt->bindValue(':firstName', $aParams[SearchQueryCore::FIRST_NAME], \PDO::PARAM_STR); |
364
|
|
|
if ($bIsMiddleName) $rStmt->bindValue(':middleName', $aParams[SearchQueryCore::MIDDLE_NAME], \PDO::PARAM_STR); |
365
|
|
|
if ($bIsLastName) $rStmt->bindValue(':lastName', $aParams[SearchQueryCore::LAST_NAME], \PDO::PARAM_STR); |
366
|
|
|
if ($bIsSingleAge) $rStmt->bindValue(':birthDate', '%' . $aParams[SearchQueryCore::AGE] . '%', \PDO::PARAM_STR); |
367
|
|
|
if ($bIsAge) $rStmt->bindValue(':age1', $aParams[SearchQueryCore::MIN_AGE], \PDO::PARAM_INT); |
368
|
|
|
if ($bIsAge) $rStmt->bindValue(':age2', $aParams[SearchQueryCore::MAX_AGE], \PDO::PARAM_INT); |
369
|
|
|
if ($bIsHeight) $rStmt->bindValue(':height', $aParams[SearchQueryCore::HEIGHT], \PDO::PARAM_INT); |
370
|
|
|
if ($bIsWeight) $rStmt->bindValue(':weight', $aParams[SearchQueryCore::WEIGHT], \PDO::PARAM_INT); |
371
|
|
|
if ($bIsCountry) $rStmt->bindParam(':country', $aParams[SearchQueryCore::COUNTRY], \PDO::PARAM_STR, 2); |
372
|
|
|
if ($bIsCity) $rStmt->bindValue(':city', '%' . str_replace('-', ' ', $aParams[SearchQueryCore::CITY]) . '%', \PDO::PARAM_STR); |
373
|
|
|
if ($bIsState) $rStmt->bindValue(':state', '%' . str_replace('-', ' ', $aParams[SearchQueryCore::STATE]) . '%', \PDO::PARAM_STR); |
374
|
|
|
if ($bIsZipCode) $rStmt->bindValue(':zipCode', '%' . $aParams[SearchQueryCore::ZIP_CODE] . '%', \PDO::PARAM_STR); |
375
|
|
|
if ($bIsMail) $rStmt->bindValue(':email', '%' . $aParams[SearchQueryCore::EMAIL] . '%', \PDO::PARAM_STR); |
376
|
|
|
if ($bHideUserLogged) $rStmt->bindValue(':profileId', $this->iProfileId, \PDO::PARAM_INT); |
377
|
|
|
|
378
|
|
|
if (!$bCount) { |
379
|
|
|
$rStmt->bindParam(':offset', $iOffset, \PDO::PARAM_INT); |
380
|
|
|
$rStmt->bindParam(':limit', $iLimit, \PDO::PARAM_INT); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
$rStmt->execute(); |
384
|
|
|
|
385
|
|
|
if (!$bCount) { |
386
|
|
|
$oRow = $rStmt->fetchAll(\PDO::FETCH_OBJ); |
387
|
|
|
Db::free($rStmt); |
388
|
|
|
return $oRow; |
389
|
|
|
} else { |
390
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
391
|
|
|
Db::free($rStmt); |
392
|
|
|
return (int) $oRow->totalUsers; |
393
|
|
|
} |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* Check online status. |
398
|
|
|
* |
399
|
|
|
* @param integer $iProfileId |
400
|
|
|
* @param integer $iTime Number of minutes that a member becomes inactive (offline). Default 1 minute |
401
|
|
|
* |
402
|
|
|
* @return boolean |
403
|
|
|
*/ |
404
|
|
|
public function isOnline($iProfileId, $iTime = 1) |
405
|
|
|
{ |
406
|
|
|
$iProfileId = (int) $iProfileId; |
407
|
|
|
$iTime = (int) $iTime; |
408
|
|
|
|
409
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT profileId FROM' . Db::prefix('Members') . 'WHERE profileId = :profileId |
410
|
|
|
AND userStatus = 1 AND lastActivity >= DATE_SUB(:currentTime, INTERVAL :time MINUTE) LIMIT 1'); |
411
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
412
|
|
|
$rStmt->bindValue(':time', $iTime, \PDO::PARAM_INT); |
413
|
|
|
$rStmt->bindValue(':currentTime', $this->sCurrentDate, \PDO::PARAM_STR); |
414
|
|
|
$rStmt->execute(); |
415
|
|
|
return $rStmt->rowCount() === 1; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* Set the user status. |
420
|
|
|
* |
421
|
|
|
* @param integer iProfileId |
422
|
|
|
* @param integer $iStatus Values: 0 = Offline, 1 = Online, 2 = Busy, 3 = Away |
423
|
|
|
* |
424
|
|
|
* @return void |
425
|
|
|
*/ |
426
|
|
|
public function setUserStatus($iProfileId, $iStatus) |
427
|
|
|
{ |
428
|
|
|
$this->orm->update('Members', 'userStatus', $iStatus, 'profileId', $iProfileId); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Get the user status. |
433
|
|
|
* |
434
|
|
|
* @param integer $iProfileId |
435
|
|
|
* |
436
|
|
|
* @return integer The user status. 0 = Offline, 1 = Online, 2 = Busy, 3 = Away |
437
|
|
|
*/ |
438
|
|
|
public function getUserStatus($iProfileId) |
439
|
|
|
{ |
440
|
|
|
$this->cache->start(self::CACHE_GROUP, 'userStatus' . $iProfileId, static::CACHE_TIME); |
441
|
|
|
|
442
|
|
|
if (!$iData = $this->cache->get()) |
443
|
|
|
{ |
444
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT userStatus FROM' . Db::prefix('Members') . 'WHERE profileId = :profileId LIMIT 1'); |
445
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
446
|
|
|
$rStmt->execute(); |
447
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
448
|
|
|
Db::free($rStmt); |
449
|
|
|
$iData = (int) $oRow->userStatus; |
450
|
|
|
unset($oRow); |
451
|
|
|
$this->cache->put($iData); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
return $iData; |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* Update the notifications. |
459
|
|
|
* |
460
|
|
|
* @param string $sSection |
461
|
|
|
* @param string $sValue |
462
|
|
|
* @param integer $iProfileId Profile ID |
463
|
|
|
* |
464
|
|
|
* @return void |
465
|
|
|
*/ |
466
|
|
|
public function setNotification($sSection, $sValue, $iProfileId) |
467
|
|
|
{ |
468
|
|
|
$this->orm->update('MembersNotifications', $sSection, $sValue, 'profileId', $iProfileId); |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* Get the user notifications. |
473
|
|
|
* |
474
|
|
|
* @param integer $iProfileId |
475
|
|
|
* |
476
|
|
|
* @return stdClass |
477
|
|
|
*/ |
478
|
|
|
public function getNotification($iProfileId) |
479
|
|
|
{ |
480
|
|
|
$this->cache->start(self::CACHE_GROUP, 'notification' . $iProfileId, static::CACHE_TIME); |
481
|
|
|
|
482
|
|
|
if (!$oData = $this->cache->get()) |
483
|
|
|
{ |
484
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix('MembersNotifications') . 'WHERE profileId = :profileId LIMIT 1'); |
485
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
486
|
|
|
$rStmt->execute(); |
487
|
|
|
$oData = $rStmt->fetch(\PDO::FETCH_OBJ); |
488
|
|
|
Db::free($rStmt); |
489
|
|
|
$this->cache->put($oData); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
return $oData; |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
/** |
496
|
|
|
* Check notifications. |
497
|
|
|
* |
498
|
|
|
* @param integer $iProfileId |
499
|
|
|
* @param string $sNotiName Notification name. |
500
|
|
|
* |
501
|
|
|
* @return boolean |
502
|
|
|
*/ |
503
|
|
|
public function isNotification($iProfileId, $sNotiName) |
504
|
|
|
{ |
505
|
|
|
$this->cache->start(self::CACHE_GROUP, 'isNotification' . $iProfileId, static::CACHE_TIME); |
506
|
|
|
|
507
|
|
|
if (!$bData = $this->cache->get()) { |
508
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT ' . $sNotiName . ' FROM' . Db::prefix('MembersNotifications') . 'WHERE profileId = :profileId AND ' . $sNotiName . ' = 1 LIMIT 1'); |
509
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
510
|
|
|
$rStmt->execute(); |
511
|
|
|
$bData = ($rStmt->rowCount() === 1); |
512
|
|
|
Db::free($rStmt); |
513
|
|
|
$this->cache->put($bData); |
|
|
|
|
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
return $bData; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Set the last activity of a user. |
521
|
|
|
* |
522
|
|
|
* @param integer $iProfileId |
523
|
|
|
* @param string $sTable Default 'Members' |
524
|
|
|
* |
525
|
|
|
* @return void |
526
|
|
|
*/ |
527
|
|
|
public function setLastActivity($iProfileId, $sTable = 'Members') |
528
|
|
|
{ |
529
|
|
|
Various::checkModelTable($sTable); |
530
|
|
|
|
531
|
|
|
$this->orm->update($sTable, 'lastActivity', $this->sCurrentDate, 'profileId', $iProfileId); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* Set the last edit account of a user. |
536
|
|
|
* |
537
|
|
|
* @param integer $iProfileId |
538
|
|
|
* @param string $sTable Default 'Members' |
539
|
|
|
* |
540
|
|
|
* @return void |
541
|
|
|
*/ |
542
|
|
|
public function setLastEdit($iProfileId, $sTable = 'Members') |
543
|
|
|
{ |
544
|
|
|
Various::checkModelTable($sTable); |
545
|
|
|
|
546
|
|
|
$this->orm->update($sTable, 'lastEdit', $this->sCurrentDate, 'profileId', $iProfileId); |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* Approve a profile. |
551
|
|
|
* |
552
|
|
|
* @param integer $iProfileId |
553
|
|
|
* @param integer $iStatus 1 = apprved | 0 = not approved |
554
|
|
|
* @param string $sTable Default 'Members' |
555
|
|
|
* |
556
|
|
|
* @return void |
557
|
|
|
*/ |
558
|
|
|
public function approve($iProfileId, $iStatus, $sTable = 'Members') |
559
|
|
|
{ |
560
|
|
|
Various::checkModelTable($sTable); |
561
|
|
|
|
562
|
|
|
$this->orm->update($sTable, 'active', $iStatus, 'profileId', $iProfileId); |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
/** |
566
|
|
|
* Get member data. The hash of course but also some useful data for sending the activation email. (hash, email, username, firstName). |
567
|
|
|
* |
568
|
|
|
* @param string $sEmail User's email address. |
569
|
|
|
* @param string $sTable Default 'Members' |
570
|
|
|
* |
571
|
|
|
* @return stdClass|boolean Returns the data member (email, username, firstName, hashValidation) on success, otherwise returns false if there is an error. |
572
|
|
|
*/ |
573
|
|
|
public function getHashValidation($sEmail, $sTable = 'Members') |
574
|
|
|
{ |
575
|
|
|
Various::checkModelTable($sTable); |
576
|
|
|
|
577
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT email, username, firstName, hashValidation FROM' . Db::prefix($sTable) . 'WHERE email = :email AND active = 2'); |
578
|
|
|
$rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR); |
579
|
|
|
$rStmt->execute(); |
580
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
581
|
|
|
Db::free($rStmt); |
582
|
|
|
|
583
|
|
|
return $oRow; |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* Valid on behalf of a user with the hash. |
588
|
|
|
* |
589
|
|
|
* @param string $sEmail |
590
|
|
|
* @param string $sHash |
591
|
|
|
* @param string $sTable Default 'Members' |
592
|
|
|
* |
593
|
|
|
* @return boolean |
594
|
|
|
*/ |
595
|
|
|
public function validateAccount($sEmail, $sHash, $sTable = 'Members') |
596
|
|
|
{ |
597
|
|
|
Various::checkModelTable($sTable); |
598
|
|
|
|
599
|
|
|
$rStmt = Db::getInstance()->prepare('UPDATE' . Db::prefix($sTable) . 'SET active = 1 WHERE email = :email AND hashValidation = :hash AND active = 2'); |
600
|
|
|
$rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR); |
601
|
|
|
$rStmt->bindParam(':hash', $sHash, \PDO::PARAM_STR, 40); |
602
|
|
|
return $rStmt->execute(); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* Adding a User. |
607
|
|
|
* |
608
|
|
|
* @param array $aData |
609
|
|
|
* |
610
|
|
|
* @return integer The ID of the User. |
611
|
|
|
*/ |
612
|
|
|
public function add(array $aData) |
613
|
|
|
{ |
614
|
|
|
$sHashValidation = (!empty($aData['hash_validation']) ? $aData['hash_validation'] : null); |
615
|
|
|
|
616
|
|
|
$rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('Members') . '(email, username, password, firstName, lastName, sex, matchSex, birthDate, active, ip, hashValidation, joinDate, lastActivity) |
617
|
|
|
VALUES (:email, :username, :password, :firstName, :lastName, :sex, :matchSex, :birthDate, :active, :ip, :hashValidation, :joinDate, :lastActivity)'); |
618
|
|
|
$rStmt->bindValue(':email', trim($aData['email']), \PDO::PARAM_STR); |
619
|
|
|
$rStmt->bindValue(':username', trim($aData['username']), \PDO::PARAM_STR); |
620
|
|
|
$rStmt->bindValue(':password', Security::hashPwd($aData['password']), \PDO::PARAM_STR); |
621
|
|
|
$rStmt->bindValue(':firstName', $aData['first_name'], \PDO::PARAM_STR); |
622
|
|
|
$rStmt->bindValue(':lastName', $aData['last_name'], \PDO::PARAM_STR); |
623
|
|
|
$rStmt->bindValue(':sex', $aData['sex'], \PDO::PARAM_STR); |
624
|
|
|
$rStmt->bindValue(':matchSex', Form::setVal($aData['match_sex']), \PDO::PARAM_STR); |
625
|
|
|
$rStmt->bindValue(':birthDate', $aData['birth_date'], \PDO::PARAM_STR); |
626
|
|
|
$rStmt->bindValue(':active', (!empty($aData['is_active']) ? $aData['is_active'] : 1), \PDO::PARAM_INT); |
627
|
|
|
$rStmt->bindValue(':ip', $aData['ip'], \PDO::PARAM_STR); |
628
|
|
|
$rStmt->bindParam(':hashValidation', $sHashValidation, \PDO::PARAM_STR, 40); |
629
|
|
|
$rStmt->bindValue(':joinDate', $this->sCurrentDate, \PDO::PARAM_STR); |
630
|
|
|
$rStmt->bindValue(':lastActivity', $this->sCurrentDate, \PDO::PARAM_STR); |
631
|
|
|
$rStmt->execute(); |
632
|
|
|
$this->setKeyId( Db::getInstance()->lastInsertId() ); // Set the user's ID |
633
|
|
|
Db::free($rStmt); |
634
|
|
|
$this->setInfoFields($aData); |
635
|
|
|
$this->setDefaultPrivacySetting(); |
636
|
|
|
$this->setDefaultNotification(); |
637
|
|
|
|
638
|
|
|
// Last one, update the membership with the correct details |
639
|
|
|
$this->updateMembership( |
640
|
|
|
(int)DbConfig::getSetting('defaultMembershipGroupId'), |
641
|
|
|
$this->getKeyId(), |
642
|
|
|
$this->sCurrentDate |
643
|
|
|
); |
644
|
|
|
|
645
|
|
|
return $this->getKeyId(); |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* @param array $aData |
650
|
|
|
* |
651
|
|
|
* @return boolean |
652
|
|
|
*/ |
653
|
|
|
public function setInfoFields(array $aData) |
654
|
|
|
{ |
655
|
|
|
$rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('MembersInfo') . '(profileId, middleName, country, city, state, zipCode, description, website, socialNetworkSite) |
656
|
|
|
VALUES (:profileId, :middleName, :country, :city, :state, :zipCode, :description, :website, :socialNetworkSite)'); |
657
|
|
|
$rStmt->bindValue(':profileId', $this->getKeyId(), \PDO::PARAM_INT); |
658
|
|
|
$rStmt->bindValue(':middleName', (!empty($aData['middle_name']) ? $aData['middle_name'] : ''), \PDO::PARAM_STR); |
659
|
|
|
$rStmt->bindValue(':country', (!empty($aData['country']) ? $aData['country'] : ''), \PDO::PARAM_STR); |
660
|
|
|
$rStmt->bindValue(':city', (!empty($aData['city']) ? $aData['city'] : ''), \PDO::PARAM_STR); |
661
|
|
|
$rStmt->bindValue(':state', (!empty($aData['state']) ? $aData['state'] : ''), \PDO::PARAM_STR); |
662
|
|
|
$rStmt->bindValue(':zipCode', (!empty($aData['zip_code']) ? $aData['zip_code'] : ''), \PDO::PARAM_STR); |
663
|
|
|
$rStmt->bindValue(':description', (!empty($aData['description']) ? $aData['description'] : ''), \PDO::PARAM_STR); |
664
|
|
|
$rStmt->bindValue(':website', (!empty($aData['website']) ? trim($aData['website']) : ''), \PDO::PARAM_STR); |
665
|
|
|
$rStmt->bindValue(':socialNetworkSite', (!empty($aData['social_network_site']) ? trim($aData['social_network_site']) : ''), \PDO::PARAM_STR); |
666
|
|
|
|
667
|
|
|
return $rStmt->execute(); |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* Set the default privacy settings. |
672
|
|
|
* |
673
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure. |
674
|
|
|
*/ |
675
|
|
|
public function setDefaultPrivacySetting() |
676
|
|
|
{ |
677
|
|
|
$rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('MembersPrivacy') . |
678
|
|
|
'(profileId, privacyProfile, searchProfile, userSaveViews) |
679
|
|
|
VALUES (:profileId, \'all\', \'yes\', \'yes\')'); |
680
|
|
|
$rStmt->bindValue(':profileId', $this->getKeyId(), \PDO::PARAM_INT); |
681
|
|
|
return $rStmt->execute(); |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
/** |
685
|
|
|
* Set the default notifications. |
686
|
|
|
* |
687
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure. |
688
|
|
|
*/ |
689
|
|
|
public function setDefaultNotification() |
690
|
|
|
{ |
691
|
|
|
$rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('MembersNotifications') . |
692
|
|
|
'(profileId, enableNewsletters, newMsg, friendRequest) |
693
|
|
|
VALUES (:profileId, 0, 1, 1)'); |
694
|
|
|
$rStmt->bindValue(':profileId', $this->getKeyId(), \PDO::PARAM_INT); |
695
|
|
|
return $rStmt->execute(); |
696
|
|
|
} |
697
|
|
|
|
698
|
|
|
/** |
699
|
|
|
* To avoid flooding! |
700
|
|
|
* Waiting time before a new registration with the same IP address. |
701
|
|
|
* |
702
|
|
|
* @param string $sIp |
703
|
|
|
* @param integer $iWaitTime In minutes! |
704
|
|
|
* @param string $sCurrentTime In date format: 0000-00-00 00:00:00 |
705
|
|
|
* @param string $sTable Default 'Members' |
706
|
|
|
* |
707
|
|
|
* @return boolean Return TRUE if the weather was fine, FALSE otherwise. |
708
|
|
|
*/ |
709
|
|
|
public function checkWaitJoin($sIp, $iWaitTime, $sCurrentTime, $sTable = 'Members') |
710
|
|
|
{ |
711
|
|
|
Various::checkModelTable($sTable); |
712
|
|
|
|
713
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT profileId FROM' . Db::prefix($sTable) . |
714
|
|
|
'WHERE ip = :ip AND DATE_ADD(joinDate, INTERVAL :waitTime MINUTE) > :currentTime LIMIT 1'); |
715
|
|
|
$rStmt->bindValue(':ip', $sIp, \PDO::PARAM_STR); |
716
|
|
|
$rStmt->bindValue(':waitTime', $iWaitTime, \PDO::PARAM_INT); |
717
|
|
|
$rStmt->bindValue(':currentTime', $sCurrentTime, \PDO::PARAM_STR); |
718
|
|
|
$rStmt->execute(); |
719
|
|
|
|
720
|
|
|
return $rStmt->rowCount() === 0; |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
|
724
|
|
|
/********** AVATAR **********/ |
725
|
|
|
|
726
|
|
|
/** |
727
|
|
|
* Update or add a new avatar. |
728
|
|
|
* |
729
|
|
|
* @param integer $iProfileId |
730
|
|
|
* @param string $sAvatar |
731
|
|
|
* @param integer $iApproved |
732
|
|
|
* |
733
|
|
|
* @return boolean |
734
|
|
|
*/ |
735
|
|
|
public function setAvatar($iProfileId, $sAvatar, $iApproved) |
736
|
|
|
{ |
737
|
|
|
$rStmt = Db::getInstance()->prepare('UPDATE' . Db::prefix('Members') . 'SET avatar = :avatar, approvedAvatar = :approved WHERE profileId = :profileId'); |
738
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
739
|
|
|
$rStmt->bindValue(':avatar', $sAvatar, \PDO::PARAM_STR); |
740
|
|
|
$rStmt->bindValue(':approved', $iApproved, \PDO::PARAM_INT); |
741
|
|
|
|
742
|
|
|
return $rStmt->execute(); |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
/** |
746
|
|
|
* Get avatar. |
747
|
|
|
* |
748
|
|
|
* @param integer $iProfileId |
749
|
|
|
* @param integer $iApproved (1 = approved | 0 = pending | NULL = approved and pending) |
750
|
|
|
* |
751
|
|
|
* @return stdClass The Avatar (SQL alias is pic), profileId and approvedAvatar |
752
|
|
|
*/ |
753
|
|
|
public function getAvatar($iProfileId, $iApproved = null) |
754
|
|
|
{ |
755
|
|
|
$this->cache->start(self::CACHE_GROUP, 'avatar' . $iProfileId, static::CACHE_TIME); |
756
|
|
|
|
757
|
|
|
if (!$oData = $this->cache->get()) { |
758
|
|
|
$sSqlApproved = (isset($iApproved)) ? ' AND approvedAvatar = :approved ' : ' '; |
759
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT profileId, avatar AS pic, approvedAvatar FROM' . Db::prefix('Members') . 'WHERE profileId = :profileId' . $sSqlApproved . 'LIMIT 1'); |
760
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
761
|
|
|
if (isset($iApproved)) $rStmt->bindValue(':approved', $iApproved, \PDO::PARAM_INT); |
762
|
|
|
$rStmt->execute(); |
763
|
|
|
$oData = $rStmt->fetch(\PDO::FETCH_OBJ); |
764
|
|
|
Db::free($rStmt); |
765
|
|
|
$this->cache->put($oData); |
766
|
|
|
} |
767
|
|
|
|
768
|
|
|
return $oData; |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* Delete an avatar in the database. |
773
|
|
|
* |
774
|
|
|
* @param integer $iProfileId |
775
|
|
|
* |
776
|
|
|
* @return boolean |
777
|
|
|
*/ |
778
|
|
|
public function deleteAvatar($iProfileId) |
779
|
|
|
{ |
780
|
|
|
return $this->setAvatar($iProfileId, null, 1); |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
|
784
|
|
|
/********** BACKGROUND **********/ |
785
|
|
|
|
786
|
|
|
/** |
787
|
|
|
* Get file of a user background. |
788
|
|
|
* |
789
|
|
|
* @param integer $iProfileId |
790
|
|
|
* @param integer $iApproved (1 = approved | 0 = pending | NULL = approved and pending) Default NULL |
791
|
|
|
* |
792
|
|
|
* @return string |
793
|
|
|
*/ |
794
|
|
|
public function getBackground($iProfileId, $iApproved = null) |
795
|
|
|
{ |
796
|
|
|
$this->cache->start(self::CACHE_GROUP, 'background' . $iProfileId, static::CACHE_TIME); |
797
|
|
|
|
798
|
|
|
if (!$sData = $this->cache->get()) { |
799
|
|
|
$sSqlApproved = (isset($iApproved)) ? ' AND approved = :approved ' : ' '; |
800
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT file FROM' . Db::prefix('MembersBackground') . 'WHERE profileId = :profileId' . $sSqlApproved . 'LIMIT 1'); |
801
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
802
|
|
|
if (isset($iApproved)) $rStmt->bindValue(':approved', $iApproved, \PDO::PARAM_INT); |
803
|
|
|
$rStmt->execute(); |
804
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
805
|
|
|
Db::free($rStmt); |
806
|
|
|
$sData = @$oRow->file; |
807
|
|
|
unset($oRow); |
808
|
|
|
$this->cache->put($sData); |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
return $sData; |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
/** |
815
|
|
|
* Add profile background. |
816
|
|
|
* |
817
|
|
|
* @param integer $iProfileId |
818
|
|
|
* @param string $sFile |
819
|
|
|
* @param integer $iApproved |
820
|
|
|
* |
821
|
|
|
* @return boolean |
822
|
|
|
*/ |
823
|
|
|
public function addBackground($iProfileId, $sFile, $iApproved = 1) |
824
|
|
|
{ |
825
|
|
|
$rStmt = Db::getInstance()->prepare('INSERT INTO' . Db::prefix('MembersBackground') . '(profileId, file, approved) VALUES (:profileId, :file, :approved)'); |
826
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
827
|
|
|
$rStmt->bindValue(':file', $sFile, \PDO::PARAM_STR); |
828
|
|
|
$rStmt->bindValue(':approved', $iApproved, \PDO::PARAM_INT); |
829
|
|
|
|
830
|
|
|
return $rStmt->execute(); |
831
|
|
|
} |
832
|
|
|
|
833
|
|
|
/** |
834
|
|
|
* Delete profile background. |
835
|
|
|
* |
836
|
|
|
* @param integer $iProfileId |
837
|
|
|
* |
838
|
|
|
* @return boolean |
839
|
|
|
*/ |
840
|
|
|
public function deleteBackground($iProfileId) |
841
|
|
|
{ |
842
|
|
|
$rStmt = Db::getInstance()->prepare('DELETE FROM' . Db::prefix('MembersBackground') . 'WHERE profileId = :profileId'); |
843
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
844
|
|
|
return $rStmt->execute(); |
845
|
|
|
} |
846
|
|
|
|
847
|
|
|
/** |
848
|
|
|
* Delete User. |
849
|
|
|
* |
850
|
|
|
* @param integer $iProfileId |
851
|
|
|
* @param string $sUsername |
852
|
|
|
* |
853
|
|
|
* @return void |
854
|
|
|
*/ |
855
|
|
|
public function delete($iProfileId, $sUsername) |
856
|
|
|
{ |
857
|
|
|
$sUsername = (string) $sUsername; |
858
|
|
|
$iProfileId = (int) $iProfileId; |
859
|
|
|
|
860
|
|
|
if ($sUsername === PH7_GHOST_USERNAME) { |
861
|
|
|
exit('You cannot delete this profile!'); |
|
|
|
|
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
$oDb = Db::getInstance(); |
865
|
|
|
|
866
|
|
|
// DELETE MESSAGES |
867
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('Messages') . 'WHERE sender = ' . $iProfileId); |
868
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('Messages') . 'WHERE recipient = ' . $iProfileId); |
869
|
|
|
|
870
|
|
|
// DELETE MESSAGES OF MESSENGER |
871
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('Messenger') . 'WHERE fromUser = ' . Db::getInstance()->quote($sUsername)); |
872
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('Messenger') . 'WHERE toUser = ' . Db::getInstance()->quote($sUsername)); |
873
|
|
|
|
874
|
|
|
// DELETE PROFILE COMMENTS |
875
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('CommentsProfile') . 'WHERE sender = ' . $iProfileId); |
876
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('CommentsProfile') . 'WHERE recipient = ' . $iProfileId); |
877
|
|
|
|
878
|
|
|
// DELETE PICTURE COMMENTS |
879
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('CommentsPicture') . 'WHERE sender = ' . $iProfileId); |
880
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('CommentsPicture') . 'WHERE recipient = ' . $iProfileId); |
881
|
|
|
|
882
|
|
|
// DELETE VIDEO COMMENTS |
883
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('CommentsVideo') . 'WHERE sender = ' . $iProfileId); |
884
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('CommentsVideo') . 'WHERE recipient = ' . $iProfileId); |
885
|
|
|
|
886
|
|
|
// DELETE NOTE COMMENTS |
887
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('CommentsNote') . 'WHERE sender = ' . $iProfileId); |
888
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('CommentsNote') . 'WHERE recipient = ' . $iProfileId); |
889
|
|
|
|
890
|
|
|
// DELETE BLOG COMMENTS |
891
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('CommentsBlog') . 'WHERE sender = ' . $iProfileId); |
892
|
|
|
|
893
|
|
|
// DELETE GAME COMMENTS |
894
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('CommentsGame') . 'WHERE sender = ' . $iProfileId); |
895
|
|
|
|
896
|
|
|
// DELETE PICTURES ALBUMS AND PICTURES |
897
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('Pictures') . 'WHERE profileId = ' . $iProfileId); |
898
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('AlbumsPictures') . 'WHERE profileId = ' . $iProfileId); |
899
|
|
|
|
900
|
|
|
// DELETE VIDEOS ALBUMS AND VIDEOS |
901
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('Videos') . 'WHERE profileId = ' . $iProfileId); |
902
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('AlbumsVideos') . 'WHERE profileId = ' . $iProfileId); |
903
|
|
|
|
904
|
|
|
// DELETE FRIENDS |
905
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('MembersFriends') . 'WHERE profileId = ' . $iProfileId); |
906
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('MembersFriends') . 'WHERE friendId = ' . $iProfileId); |
907
|
|
|
|
908
|
|
|
// DELETE WALL |
909
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('MembersWall') . 'WHERE profileId = ' . $iProfileId); |
910
|
|
|
|
911
|
|
|
// DELETE BACKGROUND |
912
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('MembersBackground') . 'WHERE profileId = ' . $iProfileId); |
913
|
|
|
|
914
|
|
|
// DELETE NOTES |
915
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('NotesCategories') . 'WHERE profileId = ' . $iProfileId); |
916
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('Notes') . 'WHERE profileId = ' . $iProfileId); |
917
|
|
|
|
918
|
|
|
// DELETE LIKE |
919
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('Likes') . 'WHERE keyId LIKE ' . Db::getInstance()->quote('%' . $sUsername . '.html')); |
920
|
|
|
|
921
|
|
|
// DELETE PROFILE VISITS |
922
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('MembersWhoViews') . 'WHERE profileId = ' . $iProfileId); |
923
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('MembersWhoViews') . 'WHERE visitorId = ' . $iProfileId); |
924
|
|
|
|
925
|
|
|
// DELETE REPORT |
926
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('Report') . 'WHERE spammerId = ' . $iProfileId); |
927
|
|
|
|
928
|
|
|
// DELETE TOPICS of FORUMS |
929
|
|
|
/* |
930
|
|
|
No! Ghost Profile is ultimately the best solution! |
931
|
|
|
WARNING: Do not change this part of code without asking permission from Pierre-Henry Soria |
932
|
|
|
*/ |
933
|
|
|
//$oDb->exec('DELETE FROM' . Db::prefix('ForumsMessages') . 'WHERE profileId = ' . $iProfileId); |
|
|
|
|
934
|
|
|
//$oDb->exec('DELETE FROM' . Db::prefix('ForumsTopics') . 'WHERE profileId = ' . $iProfileId); |
|
|
|
|
935
|
|
|
|
936
|
|
|
// DELETE NOTIFICATIONS |
937
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('MembersNotifications') . 'WHERE profileId = ' . $iProfileId . ' LIMIT 1'); |
938
|
|
|
|
939
|
|
|
// DELETE PRIVACY SETTINGS |
940
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('MembersPrivacy') . 'WHERE profileId = ' . $iProfileId . ' LIMIT 1'); |
941
|
|
|
|
942
|
|
|
// DELETE INFO FIELDS |
943
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('MembersInfo') . 'WHERE profileId = ' . $iProfileId . ' LIMIT 1'); |
944
|
|
|
|
945
|
|
|
// DELETE USER |
946
|
|
|
$oDb->exec('DELETE FROM' . Db::prefix('Members') . 'WHERE profileId = ' . $iProfileId . ' LIMIT 1'); |
947
|
|
|
|
948
|
|
|
unset($oDb); // Destruction of the object |
949
|
|
|
} |
950
|
|
|
|
951
|
|
|
/** |
952
|
|
|
* @param string $sUsernameSearch |
953
|
|
|
* @param string $sTable Default 'Members' |
954
|
|
|
* |
955
|
|
|
* @return stdClass data of users (profileId, username, sex) |
956
|
|
|
*/ |
957
|
|
|
public function getUsernameList($sUsernameSearch, $sTable = 'Members') |
958
|
|
|
{ |
959
|
|
|
Various::checkModelTable($sTable); |
960
|
|
|
|
961
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT profileId, username, sex FROM' . Db::prefix($sTable) . 'WHERE username <> \'' . PH7_GHOST_USERNAME . '\' AND username LIKE :username'); |
962
|
|
|
$rStmt->bindValue(':username', '%'.$sUsernameSearch.'%', \PDO::PARAM_STR); |
963
|
|
|
$rStmt->execute(); |
964
|
|
|
$oRow = $rStmt->fetchAll(\PDO::FETCH_OBJ); |
965
|
|
|
Db::free($rStmt); |
966
|
|
|
return $oRow; |
967
|
|
|
} |
968
|
|
|
|
969
|
|
|
/** |
970
|
|
|
* Get profiles data. |
971
|
|
|
* |
972
|
|
|
* @param string $sOrder |
973
|
|
|
* @param integer $iOffset |
974
|
|
|
* @param integer $iLimit |
975
|
|
|
* |
976
|
|
|
* @return stdClass Data of users |
977
|
|
|
*/ |
978
|
|
|
public function getProfiles($sOrder = SearchCoreModel::LAST_ACTIVITY, $iOffset = null, $iLimit = null) |
979
|
|
|
{ |
980
|
|
|
$bIsLimit = $iOffset !== null && $iLimit !== null; |
981
|
|
|
$bHideUserLogged = !empty($this->iProfileId); |
982
|
|
|
|
983
|
|
|
$iOffset = (int) $iOffset; |
984
|
|
|
$iLimit = (int) $iLimit; |
985
|
|
|
|
986
|
|
|
$sOrder = SearchCoreModel::order($sOrder, SearchCoreModel::DESC); |
987
|
|
|
|
988
|
|
|
$sSqlLimit = $bIsLimit ? 'LIMIT :offset, :limit' : ''; |
989
|
|
|
$sSqlHideLoggedProfile = $bHideUserLogged ? ' AND (m.profileId <> :profileId)' : ''; |
990
|
|
|
$sSqlShowOnlyWithAvatars = $this->bOnlyAvatarsSet ? ' AND avatar IS NOT NULL AND approvedAvatar = 1' : ''; |
991
|
|
|
|
992
|
|
|
$rStmt = Db::getInstance()->prepare( |
993
|
|
|
'SELECT * FROM' . Db::prefix('Members') . 'AS m LEFT JOIN' . Db::prefix('MembersPrivacy') . 'AS p USING(profileId) |
994
|
|
|
LEFT JOIN' . Db::prefix('MembersInfo') . 'AS i USING(profileId) WHERE (username <> \'' . PH7_GHOST_USERNAME . '\') AND (searchProfile = \'yes\') |
995
|
|
|
AND (username IS NOT NULL) AND (firstName IS NOT NULL) AND (sex IS NOT NULL) AND (matchSex IS NOT NULL) AND (country IS NOT NULL) |
996
|
|
|
AND (city IS NOT NULL) AND (groupId <> 1) AND (groupId <> 9) AND (ban = 0)' . |
997
|
|
|
$sSqlHideLoggedProfile . $sSqlShowOnlyWithAvatars . $sOrder . $sSqlLimit |
998
|
|
|
); |
999
|
|
|
|
1000
|
|
|
if ($bHideUserLogged) { |
1001
|
|
|
$rStmt->bindValue(':profileId', $this->iProfileId, \PDO::PARAM_INT); |
1002
|
|
|
} |
1003
|
|
|
|
1004
|
|
|
if ($bIsLimit) { |
1005
|
|
|
$rStmt->bindParam(':offset', $iOffset, \PDO::PARAM_INT); |
1006
|
|
|
$rStmt->bindParam(':limit', $iLimit, \PDO::PARAM_INT); |
1007
|
|
|
} |
1008
|
|
|
|
1009
|
|
|
$rStmt->execute(); |
1010
|
|
|
$oRow = $rStmt->fetchAll(\PDO::FETCH_OBJ); |
1011
|
|
|
Db::free($rStmt); |
1012
|
|
|
|
1013
|
|
|
return $oRow; |
1014
|
|
|
} |
1015
|
|
|
|
1016
|
|
|
/** |
1017
|
|
|
* Get the users from the location data. |
1018
|
|
|
* |
1019
|
|
|
* @param string $sCountry |
1020
|
|
|
* @param string $sCity |
1021
|
|
|
* @param boolean $bCount |
1022
|
|
|
* @param string $sOrder |
1023
|
|
|
* @param integer $iOffset |
1024
|
|
|
* @param integer $iLimit |
1025
|
|
|
* |
1026
|
|
|
* @return stdClass|integer Object with the users list returned or integer for the total number users returned. |
1027
|
|
|
*/ |
1028
|
|
|
public function getGeoProfiles($sCountry, $sCity, $bCount, $sOrder, $iOffset, $iLimit) |
1029
|
|
|
{ |
1030
|
|
|
$bCount = (bool) $bCount; |
1031
|
|
|
$iOffset = (int) $iOffset; |
1032
|
|
|
$iLimit = (int) $iLimit; |
1033
|
|
|
|
1034
|
|
|
$sOrder = !$bCount ? SearchCoreModel::order($sOrder, SearchCoreModel::DESC) : ''; |
1035
|
|
|
|
1036
|
|
|
$sSqlLimit = !$bCount ? 'LIMIT :offset, :limit' : ''; |
1037
|
|
|
$sSqlSelect = !$bCount ? '*' : 'COUNT(m.profileId) AS totalUsers'; |
1038
|
|
|
|
1039
|
|
|
$sSqlCity = !empty($sCity) ? 'AND (city LIKE :city)' : ''; |
1040
|
|
|
|
1041
|
|
|
$rStmt = Db::getInstance()->prepare( |
1042
|
|
|
'SELECT ' . $sSqlSelect . ' FROM' . Db::prefix('Members') . 'AS m LEFT JOIN' . Db::prefix('MembersInfo') . 'AS i USING(profileId) |
1043
|
|
|
WHERE (username <> \'' . PH7_GHOST_USERNAME . '\') AND (country = :country) ' . $sSqlCity . ' AND (username IS NOT NULL) |
1044
|
|
|
AND (firstName IS NOT NULL) AND (sex IS NOT NULL) AND (matchSex IS NOT NULL) AND (country IS NOT NULL) |
1045
|
|
|
AND (city IS NOT NULL) AND (groupId <> 1) AND (groupId <> 9) AND (ban = 0)' . $sOrder . $sSqlLimit |
1046
|
|
|
); |
1047
|
|
|
$rStmt->bindParam(':country', $sCountry, \PDO::PARAM_STR, 2); |
1048
|
|
|
|
1049
|
|
|
if (!empty($sCity)) { |
1050
|
|
|
$rStmt->bindValue(':city', '%' . $sCity . '%', \PDO::PARAM_STR); |
1051
|
|
|
} |
1052
|
|
|
|
1053
|
|
|
if (!$bCount) { |
1054
|
|
|
$rStmt->bindParam(':offset', $iOffset, \PDO::PARAM_INT); |
1055
|
|
|
$rStmt->bindParam(':limit', $iLimit, \PDO::PARAM_INT); |
1056
|
|
|
} |
1057
|
|
|
|
1058
|
|
|
$rStmt->execute(); |
1059
|
|
|
|
1060
|
|
|
if (!$bCount) { |
1061
|
|
|
$oRow = $rStmt->fetchAll(\PDO::FETCH_OBJ); |
1062
|
|
|
Db::free($rStmt); |
1063
|
|
|
return $oRow; |
1064
|
|
|
} else { |
1065
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
1066
|
|
|
Db::free($rStmt); |
1067
|
|
|
return (int) $oRow->totalUsers; |
1068
|
|
|
} |
1069
|
|
|
|
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
|
/** |
1073
|
|
|
* Updating the privacy settings. |
1074
|
|
|
* |
1075
|
|
|
* @param integer $iProfileId |
1076
|
|
|
* |
1077
|
|
|
* @return stdClass |
1078
|
|
|
*/ |
1079
|
|
|
public function getPrivacySetting($iProfileId) |
1080
|
|
|
{ |
1081
|
|
|
$this->cache->start(self::CACHE_GROUP, 'privacySetting' . $iProfileId, static::CACHE_TIME); |
1082
|
|
|
|
1083
|
|
|
if (!$oData = $this->cache->get()) |
1084
|
|
|
{ |
1085
|
|
|
$iProfileId = (int) $iProfileId; |
1086
|
|
|
|
1087
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix('MembersPrivacy') . 'WHERE profileId = :profileId LIMIT 1'); |
1088
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1089
|
|
|
$rStmt->execute(); |
1090
|
|
|
$oData = $rStmt->fetch(\PDO::FETCH_OBJ); |
1091
|
|
|
Db::free($rStmt); |
1092
|
|
|
$this->cache->put($oData); |
1093
|
|
|
} |
1094
|
|
|
|
1095
|
|
|
return $oData; |
1096
|
|
|
} |
1097
|
|
|
|
1098
|
|
|
/** |
1099
|
|
|
* Get the Profile ID of a user. |
1100
|
|
|
* |
1101
|
|
|
* @param string $sEmail Default NULL |
1102
|
|
|
* @param string $sUsername Default NULL |
1103
|
|
|
* @param string $sTable Default 'Members' |
1104
|
|
|
* |
1105
|
|
|
* @return integer|boolean The Member ID if it is found or FALSE if not found. |
1106
|
|
|
*/ |
1107
|
|
|
public function getId($sEmail = null, $sUsername = null, $sTable = 'Members') |
1108
|
|
|
{ |
1109
|
|
|
$this->cache->start(self::CACHE_GROUP, 'id' . $sEmail . $sUsername . $sTable, static::CACHE_TIME); |
1110
|
|
|
|
1111
|
|
|
if (!$iData = $this->cache->get()) { |
1112
|
|
|
Various::checkModelTable($sTable); |
1113
|
|
|
|
1114
|
|
|
if (!empty($sEmail)) { |
1115
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT profileId FROM' . Db::prefix($sTable) . 'WHERE email = :email LIMIT 1'); |
1116
|
|
|
$rStmt->bindValue(':email', $sEmail, \PDO::PARAM_STR); |
1117
|
|
|
} else { |
1118
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT profileId FROM' . Db::prefix($sTable) . 'WHERE username = :username LIMIT 1'); |
1119
|
|
|
$rStmt->bindValue(':username', $sUsername, \PDO::PARAM_STR); |
1120
|
|
|
} |
1121
|
|
|
$rStmt->execute(); |
1122
|
|
|
|
1123
|
|
|
if ($rStmt->rowCount() === 0) { |
1124
|
|
|
return false; |
1125
|
|
|
} else { |
1126
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
1127
|
|
|
Db::free($rStmt); |
1128
|
|
|
$iData = (int) $oRow->profileId; |
1129
|
|
|
unset($oRow); |
1130
|
|
|
$this->cache->put($iData); |
1131
|
|
|
} |
1132
|
|
|
} |
1133
|
|
|
|
1134
|
|
|
return $iData; |
1135
|
|
|
} |
1136
|
|
|
|
1137
|
|
|
/** |
1138
|
|
|
* @param integer $iProfileId |
1139
|
|
|
* @param string $sTable Default 'Members' |
1140
|
|
|
* |
1141
|
|
|
* @return string The email address of a member |
1142
|
|
|
*/ |
1143
|
|
|
public function getEmail($iProfileId, $sTable = 'Members') |
1144
|
|
|
{ |
1145
|
|
|
$this->cache->start(self::CACHE_GROUP, 'email' . $iProfileId . $sTable, static::CACHE_TIME); |
1146
|
|
|
|
1147
|
|
|
if (!$sData = $this->cache->get()) { |
1148
|
|
|
Various::checkModelTable($sTable); |
1149
|
|
|
|
1150
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT email FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1'); |
1151
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1152
|
|
|
$rStmt->execute(); |
1153
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
1154
|
|
|
Db::free($rStmt); |
1155
|
|
|
$sData = @$oRow->email; |
1156
|
|
|
unset($oRow); |
1157
|
|
|
$this->cache->put($sData); |
1158
|
|
|
} |
1159
|
|
|
|
1160
|
|
|
return $sData; |
1161
|
|
|
} |
1162
|
|
|
|
1163
|
|
|
/** |
1164
|
|
|
* Retrieves the username from the user ID. |
1165
|
|
|
* |
1166
|
|
|
* @param integer $iProfileId |
1167
|
|
|
* @param string $sTable Default 'Members' |
1168
|
|
|
* |
1169
|
|
|
* @return string The Username of member |
1170
|
|
|
*/ |
1171
|
|
|
public function getUsername($iProfileId, $sTable = 'Members') |
1172
|
|
|
{ |
1173
|
|
|
if ($iProfileId === PH7_ADMIN_ID) { |
1174
|
|
|
return t('Administration of %site_name%'); |
1175
|
|
|
} |
1176
|
|
|
|
1177
|
|
|
$this->cache->start(self::CACHE_GROUP, 'username' . $iProfileId . $sTable, static::CACHE_TIME); |
1178
|
|
|
|
1179
|
|
|
if (!$sData = $this->cache->get()) { |
1180
|
|
|
Various::checkModelTable($sTable); |
1181
|
|
|
|
1182
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT username FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1'); |
1183
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1184
|
|
|
$rStmt->execute(); |
1185
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
1186
|
|
|
Db::free($rStmt); |
1187
|
|
|
$sData = @$oRow->username; |
1188
|
|
|
unset($oRow); |
1189
|
|
|
$this->cache->put($sData); |
1190
|
|
|
} |
1191
|
|
|
|
1192
|
|
|
return $sData; |
1193
|
|
|
} |
1194
|
|
|
|
1195
|
|
|
/** |
1196
|
|
|
* Retrieves the first name from the user ID. |
1197
|
|
|
* |
1198
|
|
|
* @param integer $iProfileId |
1199
|
|
|
* @param string $sTable Default 'Members' |
1200
|
|
|
* |
1201
|
|
|
* @return string The first name of member |
1202
|
|
|
*/ |
1203
|
|
|
public function getFirstName($iProfileId, $sTable = 'Members') |
1204
|
|
|
{ |
1205
|
|
|
$this->cache->start(self::CACHE_GROUP, 'firstName' . $iProfileId . $sTable, static::CACHE_TIME); |
1206
|
|
|
|
1207
|
|
|
if (!$sData = $this->cache->get()) { |
1208
|
|
|
Various::checkModelTable($sTable); |
1209
|
|
|
|
1210
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT firstName FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1'); |
1211
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1212
|
|
|
$rStmt->execute(); |
1213
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
1214
|
|
|
Db::free($rStmt); |
1215
|
|
|
$sData = @$oRow->firstName; |
1216
|
|
|
unset($oRow); |
1217
|
|
|
$this->cache->put($sData); |
1218
|
|
|
} |
1219
|
|
|
|
1220
|
|
|
return $sData; |
1221
|
|
|
} |
1222
|
|
|
|
1223
|
|
|
/** |
1224
|
|
|
* Get Gender (sex) of a user. |
1225
|
|
|
* |
1226
|
|
|
* @param integer $iProfileId Default NULL |
1227
|
|
|
* @param string $sUsername Default NULL |
1228
|
|
|
* @param string $sTable Default 'Members' |
1229
|
|
|
* |
1230
|
|
|
* @return string The sex of a member |
1231
|
|
|
*/ |
1232
|
|
|
public function getSex($iProfileId = null, $sUsername = null, $sTable = 'Members') |
1233
|
|
|
{ |
1234
|
|
|
$this->cache->start(self::CACHE_GROUP, 'sex' . $iProfileId . $sUsername . $sTable, static::CACHE_TIME); |
1235
|
|
|
|
1236
|
|
|
if (!$sData = $this->cache->get()) { |
1237
|
|
|
Various::checkModelTable($sTable); |
1238
|
|
|
|
1239
|
|
|
if (!empty($iProfileId)) { |
1240
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT sex FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1'); |
1241
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1242
|
|
|
} else { |
1243
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT sex FROM' . Db::prefix($sTable) . 'WHERE username=:username LIMIT 1'); |
1244
|
|
|
$rStmt->bindValue(':username', $sUsername, \PDO::PARAM_STR); |
1245
|
|
|
} |
1246
|
|
|
|
1247
|
|
|
$rStmt->execute(); |
1248
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
1249
|
|
|
Db::free($rStmt); |
1250
|
|
|
$sData = @$oRow->sex; |
1251
|
|
|
unset($oRow); |
1252
|
|
|
$this->cache->put($sData); |
1253
|
|
|
} |
1254
|
|
|
|
1255
|
|
|
return $sData; |
1256
|
|
|
} |
1257
|
|
|
|
1258
|
|
|
/** |
1259
|
|
|
* Get Match sex for a member (so only from the Members table, because Affiliates and Admins don't have match sex). |
1260
|
|
|
* |
1261
|
|
|
* @param integer $iProfileId |
1262
|
|
|
* |
1263
|
|
|
* @return string The User's birthdate. |
1264
|
|
|
*/ |
1265
|
|
|
public function getMatchSex($iProfileId) |
1266
|
|
|
{ |
1267
|
|
|
$this->cache->start(self::CACHE_GROUP, 'matchsex' . $iProfileId, static::CACHE_TIME); |
1268
|
|
|
|
1269
|
|
|
if (!$sData = $this->cache->get()) |
1270
|
|
|
{ |
1271
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT matchSex FROM' . Db::prefix('Members') . 'WHERE profileId = :profileId LIMIT 1'); |
1272
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1273
|
|
|
$rStmt->execute(); |
1274
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
1275
|
|
|
Db::free($rStmt); |
1276
|
|
|
$sData = $oRow->matchSex; |
1277
|
|
|
unset($oRow); |
1278
|
|
|
$this->cache->put($sData); |
1279
|
|
|
} |
1280
|
|
|
|
1281
|
|
|
return $sData; |
1282
|
|
|
} |
1283
|
|
|
|
1284
|
|
|
/** |
1285
|
|
|
* Get Birth Date of a user. |
1286
|
|
|
* |
1287
|
|
|
* @param integer $iProfileId |
1288
|
|
|
* @param string $sTable Default 'Members' |
1289
|
|
|
* |
1290
|
|
|
* @return string The User's birthdate. |
1291
|
|
|
*/ |
1292
|
|
|
public function getBirthDate($iProfileId, $sTable = 'Members') |
1293
|
|
|
{ |
1294
|
|
|
$this->cache->start(self::CACHE_GROUP, 'birthdate' . $iProfileId . $sTable, static::CACHE_TIME); |
1295
|
|
|
|
1296
|
|
|
if (!$sData = $this->cache->get()) |
1297
|
|
|
{ |
1298
|
|
|
Various::checkModelTable($sTable); |
1299
|
|
|
|
1300
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT birthDate FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1'); |
1301
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1302
|
|
|
$rStmt->execute(); |
1303
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
1304
|
|
|
Db::free($rStmt); |
1305
|
|
|
$sData = $oRow->birthDate; |
1306
|
|
|
unset($oRow); |
1307
|
|
|
$this->cache->put($sData); |
1308
|
|
|
} |
1309
|
|
|
|
1310
|
|
|
return $sData; |
1311
|
|
|
} |
1312
|
|
|
|
1313
|
|
|
/** |
1314
|
|
|
* Get user's group. |
1315
|
|
|
* |
1316
|
|
|
* @param integer $iProfileId |
1317
|
|
|
* @param string sTable Default 'Members' |
1318
|
|
|
* |
1319
|
|
|
* @return integer The Group ID of a member |
1320
|
|
|
*/ |
1321
|
|
|
public function getGroupId($iProfileId, $sTable = 'Members') |
1322
|
|
|
{ |
1323
|
|
|
$this->cache->start(self::CACHE_GROUP, 'groupId' . $iProfileId . $sTable, static::CACHE_TIME); |
1324
|
|
|
|
1325
|
|
|
if (!$sData = $this->cache->get()) |
1326
|
|
|
{ |
1327
|
|
|
Various::checkModelTable($sTable); |
1328
|
|
|
|
1329
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT groupId FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1'); |
1330
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1331
|
|
|
$rStmt->execute(); |
1332
|
|
|
$oRow = $rStmt->fetch(\PDO::FETCH_OBJ); |
1333
|
|
|
Db::free($rStmt); |
1334
|
|
|
$sData = (int) $oRow->groupId; |
1335
|
|
|
unset($oRow); |
1336
|
|
|
$this->cache->put($sData); |
1337
|
|
|
} |
1338
|
|
|
|
1339
|
|
|
return $sData; |
1340
|
|
|
} |
1341
|
|
|
|
1342
|
|
|
/** |
1343
|
|
|
* Get the membership(s) data. |
1344
|
|
|
* |
1345
|
|
|
* @param integer $iGroupId Group ID. Select only the specific membership from a group ID. |
1346
|
|
|
* |
1347
|
|
|
* @return stdClass The membership(s) data. |
1348
|
|
|
*/ |
1349
|
|
|
public function getMemberships($iGroupId = null) |
1350
|
|
|
{ |
1351
|
|
|
$this->cache->start(self::CACHE_GROUP, 'memberships' . $iGroupId, static::CACHE_TIME); |
1352
|
|
|
|
1353
|
|
|
if (!$mData = $this->cache->get()) |
1354
|
|
|
{ |
1355
|
|
|
$bIsGroupId = !empty($iGroupId); |
1356
|
|
|
$sSqlGroup = ($bIsGroupId) ? ' WHERE groupId = :groupId ' : ' '; |
1357
|
|
|
|
1358
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix('Memberships') . $sSqlGroup . 'ORDER BY enable DESC, name ASC'); |
1359
|
|
|
if (!empty($iGroupId)) $rStmt->bindValue(':groupId', $iGroupId, \PDO::PARAM_INT); |
1360
|
|
|
$rStmt->execute(); |
1361
|
|
|
$mData = ($bIsGroupId) ? $rStmt->fetch(\PDO::FETCH_OBJ) : $rStmt->fetchAll(\PDO::FETCH_OBJ); |
1362
|
|
|
Db::free($rStmt); |
1363
|
|
|
$this->cache->put($mData); |
1364
|
|
|
} |
1365
|
|
|
|
1366
|
|
|
return $mData; |
1367
|
|
|
} |
1368
|
|
|
|
1369
|
|
|
/** |
1370
|
|
|
* Get the membership details of a user. |
1371
|
|
|
* |
1372
|
|
|
* @param integer $iProfileId |
1373
|
|
|
* |
1374
|
|
|
* @return stdClass The membership detais. |
1375
|
|
|
*/ |
1376
|
|
|
public function getMembershipDetails($iProfileId) |
1377
|
|
|
{ |
1378
|
|
|
$this->cache->start(self::CACHE_GROUP, 'membershipdetails' . $iProfileId, static::CACHE_TIME); |
1379
|
|
|
|
1380
|
|
|
if (!$oData = $this->cache->get()) { |
1381
|
|
|
$sSql = 'SELECT m.*, g.expirationDays, g.name AS membershipName FROM' . Db::prefix('Members'). 'AS m INNER JOIN ' . Db::prefix('Memberships') . |
1382
|
|
|
'AS g USING(groupId) WHERE profileId = :profileId LIMIT 1'; |
1383
|
|
|
|
1384
|
|
|
$rStmt = Db::getInstance()->prepare($sSql); |
1385
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1386
|
|
|
$rStmt->execute(); |
1387
|
|
|
$oData = $rStmt->fetch(\PDO::FETCH_OBJ); |
1388
|
|
|
Db::free($rStmt); |
1389
|
|
|
$this->cache->put($oData); |
1390
|
|
|
} |
1391
|
|
|
|
1392
|
|
|
return $oData; |
1393
|
|
|
} |
1394
|
|
|
|
1395
|
|
|
/** |
1396
|
|
|
* Check if membership is expired. |
1397
|
|
|
* |
1398
|
|
|
* @param integer $iProfileId |
1399
|
|
|
* @param string $sCurrentTime In date format: 0000-00-00 00:00:00 |
1400
|
|
|
* |
1401
|
|
|
* @return boolean |
1402
|
|
|
*/ |
1403
|
|
|
public function checkMembershipExpiration($iProfileId, $sCurrentTime) |
1404
|
|
|
{ |
1405
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT m.profileId FROM' . Db::prefix('Members') . 'AS m INNER JOIN' . Db::prefix('Memberships') . |
1406
|
|
|
'AS pay USING(groupId) WHERE (pay.expirationDays = 0 OR DATE_ADD(m.membershipDate, INTERVAL pay.expirationDays DAY) >= :currentTime) |
1407
|
|
|
AND (m.profileId = :profileId) LIMIT 1'); |
1408
|
|
|
|
1409
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1410
|
|
|
$rStmt->bindValue(':currentTime', $sCurrentTime, \PDO::PARAM_INT); |
1411
|
|
|
$rStmt->execute(); |
1412
|
|
|
return ($rStmt->rowCount() === 1); |
1413
|
|
|
} |
1414
|
|
|
|
1415
|
|
|
/** |
1416
|
|
|
* Update the membership group of a user. |
1417
|
|
|
* |
1418
|
|
|
* @param integer $iNewGroupId The new ID of membership group. |
1419
|
|
|
* @param integer $iProfileId The user ID. |
1420
|
|
|
* @param string $sDateTime In date format: 0000-00-00 00:00:00 |
1421
|
|
|
* |
1422
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure. |
1423
|
|
|
*/ |
1424
|
|
|
public function updateMembership($iNewGroupId, $iProfileId, $sDateTime = null) |
1425
|
|
|
{ |
1426
|
|
|
$bIsTime = !empty($sDateTime); |
1427
|
|
|
|
1428
|
|
|
$sSqlTime = ($bIsTime) ? ',membershipDate = :dateTime ' : ' '; |
1429
|
|
|
$sSqlQuery = 'UPDATE' . Db::prefix('Members') . 'SET groupId = :groupId' . |
1430
|
|
|
$sSqlTime . 'WHERE profileId = :profileId LIMIT 1'; |
1431
|
|
|
|
1432
|
|
|
$rStmt = Db::getInstance()->prepare($sSqlQuery); |
1433
|
|
|
$rStmt->bindValue(':groupId', $iNewGroupId, \PDO::PARAM_INT); |
1434
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1435
|
|
|
if ($bIsTime) $rStmt->bindValue(':dateTime', $sDateTime, \PDO::PARAM_STR); |
1436
|
|
|
return $rStmt->execute(); |
1437
|
|
|
} |
1438
|
|
|
|
1439
|
|
|
/** |
1440
|
|
|
* Get Info Fields from profile ID. |
1441
|
|
|
* |
1442
|
|
|
* @param integer $iProfileId |
1443
|
|
|
* @param string $sTable Default 'MembersInfo' |
1444
|
|
|
* |
1445
|
|
|
* @return stdClass |
1446
|
|
|
*/ |
1447
|
|
|
public function getInfoFields($iProfileId, $sTable = 'MembersInfo') |
1448
|
|
|
{ |
1449
|
|
|
$this->cache->start(self::CACHE_GROUP, 'infoFields' . $iProfileId . $sTable, static::CACHE_TIME); |
1450
|
|
|
|
1451
|
|
|
if (!$oData = $this->cache->get()) { |
1452
|
|
|
Various::checkModelTable($sTable); |
1453
|
|
|
|
1454
|
|
|
$rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix($sTable) . 'WHERE profileId = :profileId LIMIT 1'); |
1455
|
|
|
$rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT); |
1456
|
|
|
$rStmt->execute(); |
1457
|
|
|
$oColumns = $rStmt->fetch(\PDO::FETCH_OBJ); |
1458
|
|
|
Db::free($rStmt); |
1459
|
|
|
|
1460
|
|
|
$oData = new stdClass; |
1461
|
|
|
foreach ($oColumns as $sColumn => $sValue) |
1462
|
|
|
{ |
1463
|
|
|
if ($sColumn != 'profileId') |
1464
|
|
|
$oData->$sColumn = $sValue; |
1465
|
|
|
} |
1466
|
|
|
$this->cache->put($oData); |
|
|
|
|
1467
|
|
|
} |
1468
|
|
|
|
1469
|
|
|
return $oData; |
1470
|
|
|
} |
1471
|
|
|
|
1472
|
|
|
/** |
1473
|
|
|
* Clone is set to private to stop cloning. |
1474
|
|
|
*/ |
1475
|
|
|
private function __clone() {} |
1476
|
|
|
} |
1477
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: