3 * Container for user properties.
5 * Copyright 2003 Mark O'Sullivan
6 * This file is part of Lussumo's Software Library.
7 * Lussumo's Software Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
8 * Lussumo's Software Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
10 * The latest source code is available at www.lussumo.com
11 * Contact Mark O'Sullivan at mark [at] lussumo [dot] com
13 * @author Mark O'Sullivan
14 * @copyright 2003 Mark O'Sullivan
15 * @license http://lussumo.com/community/gpl.txt GPL 2
22 * Container for user properties.
26 // Basic User Properties
50 var $CountDiscussions;
55 var $BlocksCategories;
56 var $DefaultFormatType;
58 var $DisplayIcon; // The icon to display for the user. Normally the user-defined icon, but if the user has a role icon it will appear here instead
60 // Spam blocking variables
61 var $LastDiscussionPost;
62 var $DiscussionSpamCheck;
64 var $CommentSpamCheck;
66 // Access Abilities (relating to the user role)
67 var $PERMISSION_SIGN_IN;
68 var $PERMISSION_HTML_ALLOWED;
69 var $PERMISSION_RECEIVE_APPLICATION_NOTIFICATION;
70 var $Permissions; // An array of permissions (similar to the Preferences Property but applicable to all people in a particular role).
72 // Password Manipulation Properties
78 // An associative array of user-defined settings
79 var $SendNewApplicantNotifications;
89 $this->RoleDescription
= '';
92 $this->CustomStyle
= '';
94 $this->FirstName
= '';
99 $this->ConfirmPassword
= '';
100 $this->NewPassword
= '';
101 $this->VerificationKey
= '';
102 $this->OldPassword
= '';
104 $this->UtilizeEmail
= 0;
107 $this->Attributes
= array();
108 $this->DateFirstVisit
= '';
109 $this->DateLastActive
= '';
110 $this->CountVisit
= 0;
111 $this->CountDiscussions
= 0;
112 $this->CountComments
= 0;
113 $this->RemoteIp
= '';
114 $this->AgreeToTerms
= 0;
115 $this->ReadTerms
= 0;
116 $this->BlocksCategories
= 0;
117 if ($this->Context
) {
118 $this->DefaultFormatType
= $this->Context
->Configuration
['DEFAULT_FORMAT_TYPE'];
119 $this->StyleUrl
= $this->Context
->Configuration
['DEFAULT_STYLE'];
121 global $Configuration;
122 $this->DefaultFormatType
= $Configuration['DEFAULT_FORMAT_TYPE'];
123 $this->StyleUrl
= $Configuration['DEFAULT_STYLE'];
125 $this->Discovery
= '';
126 $this->DisplayIcon
= '';
127 $this->SendNewApplicantNotifications
= 0;
129 $this->Preferences
= array();
131 $this->PERMISSION_SIGN_IN
= 1;
132 $this->PERMISSION_HTML_ALLOWED
= 0;
133 $this->PERMISSION_RECEIVE_APPLICATION_NOTIFICATION
= 0;
134 $this->Permissions
= array();
137 // Customizations are strings stored in the Preferences array
138 function Customization($CustomizationName) {
139 $CustomizationName = str_replace('CUSTOMIZATION_', '', $CustomizationName);
140 if (array_key_exists($CustomizationName, $this->Preferences
)) {
141 return $this->Preferences
[$CustomizationName];
143 return ForceString(@$this->Context
->Configuration
['CUSTOMIZATION_'.$CustomizationName], '');
147 function FormatPropertiesForDatabaseInput() {
148 $this->CustomStyle
= FormatStringForDatabaseInput($this->CustomStyle
, 1);
149 $this->Name
= FormatStringForDatabaseInput($this->Name
, 1);
150 $this->FirstName
= FormatStringForDatabaseInput($this->FirstName
, 1);
151 $this->LastName
= FormatStringForDatabaseInput($this->LastName
, 1);
152 $this->Email
= FormatStringForDatabaseInput($this->Email
, 1);
153 $this->Icon
= FormatStringForDatabaseInput($this->Icon
, 1);
154 $this->Picture
= FormatStringForDatabaseInput($this->Picture
, 1);
155 $this->Password
= FormatStringForDatabaseInput($this->Password
, 1);
156 $this->OldPassword
= FormatStringForDatabaseInput($this->OldPassword
, 1);
157 $this->NewPassword
= FormatStringForDatabaseInput($this->NewPassword
, 1);
158 $this->ConfirmPassword
= FormatStringForDatabaseInput($this->ConfirmPassword
, 1);
159 $this->VerificationKey
= FormatStringForDatabaseInput($this->VerificationKey
);
160 $this->Attributes
= SerializeArray($this->Attributes
);
161 $this->Discovery
= FormatStringForDatabaseInput($this->Discovery
, 1);
164 function FormatPropertiesForDisplay() {
165 $this->Name
= FormatStringForDisplay($this->Name
, 1);
166 $this->FirstName
= FormatStringForDisplay($this->FirstName
, 1);
167 $this->LastName
= FormatStringForDisplay($this->LastName
, 1);
168 $this->FullName
= FormatStringForDisplay($this->FullName
, 1);
169 $this->Email
= FormatStringForDisplay($this->Email
, 1);
170 $this->Password
= '';
171 $this->ConfirmPassword
= '';
172 $this->NewPassword
= '';
173 $this->OldPassword
= '';
174 $this->VerificationKey
= '';
175 $this->Picture
= FormatStringForDisplay($this->Picture
, 1, 0);
176 $this->Icon
= FormatStringForDisplay($this->Icon
, 1, 0);
177 $this->DisplayIcon
= FormatStringForDisplay($this->DisplayIcon
, 1, 0);
178 $this->Style
= FormatStringForDisplay($this->Style
, 0);
179 $this->Discovery
= FormatHtmlStringForNonDisplay($this->Discovery
);
182 function GetPropertiesFromDataSet($DataSet) {
183 $this->UserID
= ForceInt(@$DataSet['UserID'],0);
184 $this->RoleID
= ForceInt(@$DataSet['RoleID'],0);
185 $this->Role
= ForceString(@$DataSet['Role'],'');
186 if ($this->RoleID
== 0 && $this->Context
) $this->Role
= $this->Context
->GetDefinition('Applicant');
187 $this->RoleIcon
= ForceString(@$DataSet['RoleIcon'],'');
188 $this->RoleDescription
= ForceString(@$DataSet['RoleDescription'],'');
189 $this->StyleID
= ForceInt(@$DataSet['StyleID'], 0);
190 $this->Style
= ForceString(@$DataSet['Style'], '');
191 $this->StyleUrl
= ForceString(@$DataSet['StyleUrl'], '');
192 $this->CustomStyle
= ForceString(@$DataSet['CustomStyle'], '');
193 $this->Name
= ForceString(@$DataSet['Name'],'');
194 $this->FirstName
= ForceString(@$DataSet['FirstName'], '');
195 $this->LastName
= ForceString(@$DataSet['LastName'], '');
196 $this->FullName
= trim($this->FirstName
. ' ' . $this->LastName
);
197 $this->ShowName
= ForceBool(@$DataSet['ShowName'], 0);
198 $this->Email
= ForceString(@$DataSet['Email'],'');
199 $this->UtilizeEmail
= ForceBool(@$DataSet['UtilizeEmail'], 0);
200 $this->Icon
= ForceString(@$DataSet['Icon'], '');
201 $this->Picture
= ForceString(@$DataSet['Picture'],'');
202 $this->Discovery
= ForceString(@$DataSet['Discovery'], '');
203 $this->Attributes
= '';
204 $this->Attributes
= ForceString(@$DataSet['Attributes'],'');
205 $this->Attributes
= UnserializeArray($this->Attributes
);
206 $this->SendNewApplicantNotifications
= ForceBool(@$DataSet['SendNewApplicantNotifications'], 0);
208 if ($this->RoleIcon
!= '') {
209 $this->DisplayIcon
= $this->RoleIcon
;
211 $this->DisplayIcon
= $this->Icon
;
214 $this->Preferences
= '';
215 $this->Preferences
= ForceString(@$DataSet['Preferences'],'');
216 $this->Preferences
= UnserializeAssociativeArray($this->Preferences
);
217 $this->DateFirstVisit
= UnixTimestamp(@$DataSet['DateFirstVisit']);
218 $this->DateLastActive
= UnixTimestamp(@$DataSet['DateLastActive']);
219 $this->CountVisit
= ForceInt(@$DataSet['CountVisit'],0);
220 $this->CountDiscussions
= ForceInt(@$DataSet['CountDiscussions'],0);
221 $this->CountComments
= ForceInt(@$DataSet['CountComments'],0);
222 $this->RemoteIp
= ForceString(@$DataSet['RemoteIp'],'');
223 $this->BlocksCategories
= ForceBool(@$DataSet['UserBlocksCategories'], 0);
224 $this->DefaultFormatType
= ForceString(@$DataSet['DefaultFormatType'], $this->Context
->Configuration
['DEFAULT_FORMAT_TYPE']);
226 // User Role Permissions
227 $this->PERMISSION_SIGN_IN
= ForceBool(@$DataSet['PERMISSION_SIGN_IN'], $this->Context
->Configuration
['PERMISSION_SIGN_IN']);
228 $this->PERMISSION_HTML_ALLOWED
= ForceBool(@$DataSet['PERMISSION_HTML_ALLOWED'], $this->Context
->Configuration
['PERMISSION_HTML_ALLOWED']);
229 $this->PERMISSION_RECEIVE_APPLICATION_NOTIFICATION
= ForceBool(@$DataSet['PERMISSION_RECEIVE_APPLICATION_NOTIFICATION'], $this->Context
->Configuration
['PERMISSION_RECEIVE_APPLICATION_NOTIFICATION']);
230 $this->Permissions
= '';
231 $this->Permissions
= ForceString(@$DataSet['Permissions'],'');
232 $this->Permissions
= UnserializeAssociativeArray($this->Permissions
);
233 $this->Permissions
['PERMISSION_SIGN_IN'] = $this->PERMISSION_SIGN_IN
;
234 $this->Permissions
['PERMISSION_HTML_ALLOWED'] = $this->PERMISSION_HTML_ALLOWED
;
235 $this->Permissions
['PERMISSION_RECEIVE_APPLICATION_NOTIFICATION'] = $this->PERMISSION_RECEIVE_APPLICATION_NOTIFICATION
;
237 // If this user doesn't have permission to do things, force their preferences to abide.
238 if (!$this->Permission('PERMISSION_VIEW_HIDDEN_DISCUSSIONS')) $this->Setting
['ShowDeletedDiscussions'] = 0;
239 if (!$this->Permission('PERMISSION_VIEW_HIDDEN_COMMENTS')) $this->Setting
['ShowDeletedComments'] = 0;
240 if (!$this->PERMISSION_RECEIVE_APPLICATION_NOTIFICATION
) $this->SendNewApplicantNotifications
= 0;
242 // change the user's style if they've selected no style
243 if ($this->StyleID
== 0) {
244 $this->Style
= 'Custom';
245 $this->StyleUrl
= ForceString($this->CustomStyle
, $this->Context
->Configuration
['DEFAULT_STYLE']);
248 $this->Password
= ForceString(@$DataSet['Password'], '*');
249 $this->VerificationKey
= ForceString(@$DataSet['VerificationKey'], '');
252 function GetPropertiesFromForm() {
253 $this->UserID
= ForceIncomingInt('u', 0);
254 $this->RoleID
= ForceIncomingInt('RoleID', 0);
255 $this->StyleID
= ForceIncomingInt('StyleID', 0);
256 $this->CustomStyle
= ForceIncomingString('CustomStyle', '');
257 $this->Name
= ForceIncomingString('Name', '');
258 $this->FirstName
= ForceIncomingString('FirstName', '');
259 $this->LastName
= ForceIncomingString('LastName', '');
260 $this->ShowName
= ForceIncomingBool('ShowName', 0);
261 $this->Email
= ForceIncomingString('Email', '');
262 $this->UtilizeEmail
= ForceIncomingBool('UtilizeEmail',0);
263 $this->Password
= ForceIncomingString('Password', '');
264 $this->Icon
= PrependString(array('http://', 'https://'), ForceIncomingString('Icon',''));
265 $this->Picture
= PrependString(array('http://', 'https://'), ForceIncomingString('Picture',''));
266 $this->AgreeToTerms
= ForceIncomingBool('AgreeToTerms', 0);
267 $this->ReadTerms
= ForceIncomingBool('ReadTerms', 0);
268 $this->Discovery
= ForceIncomingString('Discovery', '');
270 $this->OldPassword
= ForceIncomingString('OldPassword', '');
271 $this->NewPassword
= ForceIncomingString('NewPassword', '');
272 $this->ConfirmPassword
= ForceIncomingString('ConfirmPassword', '');
274 // Retrieve attributes from the form
275 $AttributeCount = ForceIncomingInt('LabelValuePairCount', 0);
278 for ($i = 0; $i < $AttributeCount; $i++
) {
279 $Label = ForceIncomingString('Label'.($i+
1), '');
280 $Label = strip_tags($Label);
281 $Label = str_replace("\\\"", "", $Label);
282 $Value = ForceIncomingString("Value".($i+
1), "");
283 $Value = strip_tags($Value);
284 $Value = str_replace("\\\"", "", $Value);
285 if ($Label != '' && $Value != '') $this->Attributes
[] = array('Label' => $Label, 'Value' => $Value);
289 // Call this method to retrieve a setting (boolean) value rather than accessing the settings array directly and catching an error if the particular setting is not defined
290 function Preference($PreferenceName) {
291 if (array_key_exists($PreferenceName, $this->Preferences
)) {
292 return ForceBool($this->Preferences
[$PreferenceName], 0);
294 return ForceBool(@$this->Context
->Configuration
['PREFERENCE_'.$PreferenceName], 0);
298 function Permission($PermissionName) {
300 if (is_array($this->Context
->Configuration
)
301 && array_key_exists($PermissionName, $this->Context
->Configuration
)) {
302 $Default = $this->Context
->Configuration
[$PermissionName];
304 if (array_key_exists($PermissionName, $this->Permissions
)) {
305 return ForceBool($this->Permissions
[$PermissionName], $Default);
311 function User(&$Context) {
312 $this->Context
= &$Context;