PageRenderTime 245ms CodeModel.GetById 131ms app.highlight 14ms RepoModel.GetById 96ms app.codeStats 1ms

/users/default_config.php

http://showslow.googlecode.com/
PHP | 331 lines | 222 code | 58 blank | 51 comment | 3 complexity | 1c2d8efd62a04b0d94ae8bf3368db5aa MD5 | raw file
  1<?php
  2require_once(dirname(__FILE__).'/Plan.php');
  3require_once(dirname(__FILE__).'/Cohort.php');
  4require_once(dirname(__FILE__).'/Feature.php');
  5require_once(dirname(__FILE__).'/modules.php');
  6require_once(dirname(__FILE__).'/tools.php');
  7
  8class UserConfig
  9{
 10	// list of all available modules
 11	public static $all_modules = array();
 12
 13	// multiple email modules can be assigned for the same instance
 14	public static $authentication_modules = array();
 15
 16	// Only one email module can exist
 17	public static $email_module;
 18
 19	// Debugger enabled/disabled
 20	public static $DEBUG = false;
 21
 22	// paths
 23	public static $ROOTPATH;
 24	public static $USERSROOTURL;
 25	public static $USERSROOTFULLURL;
 26	public static $SITEROOTURL;
 27	public static $SITEROOTFULLURL;
 28	public static $DEFAULTLOGINRETURN;
 29	public static $DEFAULTLOGOUTRETURN;
 30	public static $DEFAULTREGISTERRETURN;
 31	public static $DEFAULTUPDATEPASSWORDRETURN;
 32
 33	// session secret - must be unique for each installation
 34	public static $SESSION_SECRET;
 35	public static $csrf_nonce_key = 'users-csrf-nonce';
 36
 37	// Administrator users
 38	public static $admins = array();
 39
 40	// key used in session storage to store user's ID
 41	public static $session_userid_key = 'users-userid';
 42	public static $session_return_key = 'users-return-to';
 43	public static $impersonation_userid_key = 'users-userid-impr';
 44
 45	public static $mysql_host = 'localhost';
 46	public static $mysql_port = 3306;
 47	public static $mysql_db;
 48	public static $mysql_user;
 49	public static $mysql_password;
 50	public static $mysql_prefix= 'u_';
 51
 52	private static $db = null;
 53
 54	public static $header;
 55	public static $footer;
 56	public static $maillist;
 57
 58	public static $admin_header;
 59	public static $admin_footer;
 60
 61	// a list of activities
 62	public static $activities = array();
 63
 64	// a list of cohort providers for cohort analysis
 65	public static $cohort_providers = array();
 66
 67	/* A list of features in the system.
 68	   Key must be integer.
 69	   Values of the array are:
 70		- name of the feature (string)
 71		- if it is enabled or disabled globally (boolean)
 72		- if it is enabled for everybody, overriding account settings (boolean)
 73	*/
 74	public static $features = array();
 75
 76	// returning user activity configs
 77	public static $last_login_key = 'users-last-login';
 78	public static $last_login_session_length = 30; // 30 minutes away considered returning user
 79
 80	// tracking referrals
 81	public static $entry_referer_key = 'users-ref';
 82
 83	// campaign tracking variables with Google Analytics defaults
 84	public static $entry_cmp_key = 'users-cmp';
 85	public static $campaign_variables = array(
 86		'cmp_source' => array('utm_source'),
 87		'cmp_medium' => array('utm_medium'),
 88		'cmp_keywords' => array('utm_term'),
 89		'cmp_content' => array('utm_content'),
 90		'cmp_name' => array('utm_campaign')
 91	);
 92
 93	// Facebook session storage key prefix
 94	public static $facebook_storage_key_prefix = 'users-fb';
 95
 96	// don't display activity for some admin users
 97	public static $dont_display_activity_for = array();
 98
 99	// functionality switches
100	public static $enableRegistration = true;
101	public static $registrationDisabledMessage = 'Registration is disabled.';
102
103	public static $enableInvitations = false;
104	public static $invitationRequiredMessage = 'Please enter your invitation code';
105
106	// Support emails configuration
107	public static $supportEmailFrom = 'User Support <support@example.com>';
108	public static $supportEmailReplyTo = 'support@example.com';
109	public static $supportEmailXMailer;
110
111	// Password recovery email configuration
112	public static $passwordRecoveryEmailSubject = 'Your Password';
113
114	// TODO move all module-specific remember me configurations to module classes
115	// Allow remembering user for longer then a session
116	public static $allowRememberMe = true;
117	// Automatically remember user for longer then a session when they register
118	public static $rememberUserOnRegistration = true;
119	// Time for long sessions - defaults to 10 years
120	// can be set to relatively short, e.g. 2 weeks if needed
121	public static $rememberMeTime = 315360000;
122	// To check or not "remember me" box by default
123	public static $rememberMeDefault = false;
124
125	// use accounts or just users only
126	public static $useAccounts = true;
127
128	// account switch destination (curret page will be used if null)
129	public static $accountSwitchDestination = null;
130
131	// OAuth application name (not sent if null)
132	public static $OAuthAppName = null;
133
134	// key for storing OAuth User ID during the OAuth workflow
135	public static $oauth_user_id_key = 'users-oauth-user-id';
136
137	/*
138	 * Admin insterface settings
139	 */
140	public static $adminActiveOnlyWithPoints = false;
141
142	/*
143	 * hooks
144	 */
145
146	// Invitation page action renderers
147	public static $onRenderUserInvitationAction = 'UserConfig::renderUserInvitationAction';
148	public static $onRenderUserInvitationFollowUpAction = 'UserConfig::renderUserInvitationFollowUpAction';
149	// formatter for password recovery email
150	public static $onRenderTemporaryPasswordEmail = 'UserConfig::renderTemporaryPasswordEmail';
151	// handler to be called when new user is created
152	public static $onCreate = null;
153	// create extra links on login strip
154	public static $onLoginStripLinks = null;
155			
156	public static function getDB()
157	{
158		if (is_null(self::$db))
159		{
160			self::$db = new mysqli(self::$mysql_host, self::$mysql_user, self::$mysql_password, self::$mysql_db, self::$mysql_port);
161			if (!self::$db->set_charset('utf8')) {
162				error_log("[UserBase] Warning: Can't set utf8 charset for DB connection");
163			}
164		}
165
166		return self::$db;
167	}
168
169	public static function setDB($db)
170	{
171		self::$db = $db;
172	}
173
174	public static function renderUserInvitationAction($code)
175	{
176		?><a href="mailto:?Subject=Invitation&Body=<?php echo UserConfig::$SITEROOTFULLURL?>users/register.php?invite=<?php echo urlencode($code)?>">Invite</a><?php
177	}
178
179	public static function renderUserInvitationFollowUpAction($code)
180	{
181		?><a href="mailto:?Subject=Re:%20Invitation&Body=<?php echo UserConfig::$SITEROOTFULLURL?>users/register.php?invite=<?php echo urlencode($code)?>">Follow Up</a><?php
182	}
183
184	public static function renderTemporaryPasswordEmail($baseurl, $username, $temppass )
185	{
186		$message = <<<EOD
187You're receieving this email because somebody requested to reset password for your user account
188
189If it wasn't you, then just ignore this email - your current password will keep working fine.
190
191Otherwise, just go and log in using your temporary password:
192
193Login Page: $baseurl
194Username: $username
195Temporary Password: $temppass
196
197You will be asked to enter your new password before you will be able to continue.
198
199Temporary passwords only work for one day and will become invalid once you set your new password.
200
201
202--
203User Support
204EOD;
205		return $message;
206	}
207
208	public static function loadModule($modulename) {
209		require_once(dirname(__FILE__).'/modules/'.$modulename.'/index.php');
210	}
211
212	public static function init()
213	{
214		UserConfig::$ROOTPATH = dirname(__FILE__);
215
216		// Chopping of trailing slash which is not supposed to be there in Apache config
217		// See: http://httpd.apache.org/docs/2.0/mod/core.html#documentroot
218		$docroot = $_SERVER['DOCUMENT_ROOT'];
219		if (substr($docroot, -1) == DIRECTORY_SEPARATOR) {
220			$docroot = substr($docroot, 0, -1);
221		}
222		$docrootlength = strlen($docroot);
223		UserConfig::$USERSROOTURL = substr(UserConfig::$ROOTPATH, $docrootlength);
224
225		// we assume that package is extracted into the root of the site
226		UserConfig::$SITEROOTURL = substr(dirname(UserConfig::$ROOTPATH), $docrootlength).'/';
227		UserConfig::$DEFAULTLOGINRETURN = UserConfig::$SITEROOTURL;
228		UserConfig::$DEFAULTLOGOUTRETURN = UserConfig::$SITEROOTURL;
229		UserConfig::$DEFAULTREGISTERRETURN = UserConfig::$SITEROOTURL;
230		UserConfig::$DEFAULTUPDATEPASSWORDRETURN = UserConfig::$SITEROOTURL;
231
232		if (array_key_exists('HTTP_HOST', $_SERVER))
233		{
234			$host = $_SERVER['HTTP_HOST'];
235		}
236		else
237		{
238			$host = php_uname('n');
239			if (php_sapi_name() !== 'cli') {
240				error_log("[UserBase config] Warning: Can't determine site's host name, using $host");
241			}
242 
243		}
244
245		UserConfig::$SITEROOTFULLURL = 'http://'.$host.UserConfig::$SITEROOTURL;
246		UserConfig::$USERSROOTFULLURL = 'http://'.$host.substr(UserConfig::$ROOTPATH, $docrootlength);
247
248		UserConfig::$supportEmailXMailer = 'UserBase (PHP/'.phpversion();
249
250		UserConfig::$header = dirname(__FILE__).'/header.php';
251		UserConfig::$footer = dirname(__FILE__).'/footer.php';
252
253		UserConfig::$admin_header = dirname(__FILE__).'/header.php';
254		UserConfig::$admin_footer = dirname(__FILE__).'/footer.php';
255
256		// Built in activities 
257		define('USERBASE_ACTIVITY_LOGIN_UPASS',		1000);
258		define('USERBASE_ACTIVITY_LOGIN_FB',		1001);
259		define('USERBASE_ACTIVITY_LOGIN_GFC',		1002);
260
261		define('USERBASE_ACTIVITY_ADDED_UPASS',		1003);
262		define('USERBASE_ACTIVITY_ADDED_FB',		1004);
263		define('USERBASE_ACTIVITY_ADDED_GFC',		1005);
264
265		define('USERBASE_ACTIVITY_REMOVED_FB',		1006);
266		define('USERBASE_ACTIVITY_REMOVED_GFC',		1007);
267
268		define('USERBASE_ACTIVITY_LOGOUT',		1008);
269
270		define('USERBASE_ACTIVITY_REGISTER_UPASS',	1009);
271		define('USERBASE_ACTIVITY_REGISTER_FB',		1010);
272		define('USERBASE_ACTIVITY_REGISTER_GFC',	1011);
273
274		define('USERBASE_ACTIVITY_UPDATEUSERINFO',	1012);
275
276		define('USERBASE_ACTIVITY_UPDATEPASS',		1013);
277		define('USERBASE_ACTIVITY_RESETPASS',		1014);
278
279		define('USERBASE_ACTIVITY_RETURN_DAILY',	1015);
280		define('USERBASE_ACTIVITY_RETURN_WEEKLY',	1016);
281		define('USERBASE_ACTIVITY_RETURN_MONTHLY',	1017);
282
283		define('USERBASE_ACTIVITY_LOGIN_EMAIL',		1018);
284		define('USERBASE_ACTIVITY_REGISTER_EMAIL',	1019);
285
286		// Array of activities in the system.
287		// Key must be integer (best if specified using a constant).
288		// The values are an array with label and "points" value of activity.
289		UserConfig::$activities = array(
290			USERBASE_ACTIVITY_LOGIN_UPASS => array('Logged in using username and password',	1),
291			USERBASE_ACTIVITY_LOGIN_FB => array('Logged in using Facebook',			1),
292			USERBASE_ACTIVITY_LOGIN_GFC => array('Logged in using Google Friend Connect',	1),
293
294			USERBASE_ACTIVITY_ADDED_UPASS => array('Added username and password',		1),
295			USERBASE_ACTIVITY_ADDED_FB => array('Added Facebook credential',		1),
296			USERBASE_ACTIVITY_ADDED_GFC => array('Added Google Friend Connect credential',	1),
297
298			USERBASE_ACTIVITY_REMOVED_FB => array('Removed Facebook Connect',		0),
299			USERBASE_ACTIVITY_REMOVED_GFC => array('Removed Google Friend Connect credential',0),
300
301			USERBASE_ACTIVITY_LOGOUT => array('Logged out',					0),
302
303			USERBASE_ACTIVITY_REGISTER_UPASS => array('Registered using a form',		1),
304			USERBASE_ACTIVITY_REGISTER_FB => array('Registered using Facebook',		1),
305			USERBASE_ACTIVITY_REGISTER_GFC => array('Registered using Google Friend Connect', 1),
306
307			USERBASE_ACTIVITY_UPDATEUSERINFO => array('Updated user info',			0),
308
309			USERBASE_ACTIVITY_UPDATEPASS => array('Updated their password',			0),
310			USERBASE_ACTIVITY_RESETPASS => array('Reset forgotten password',		0),
311
312			USERBASE_ACTIVITY_RETURN_DAILY => array('Returned to the site within a day',	3),
313			USERBASE_ACTIVITY_RETURN_WEEKLY => array('Returned to the site within a week',	2),
314			USERBASE_ACTIVITY_RETURN_MONTHLY => array('Returned to the site within a month', 1),
315
316			USERBASE_ACTIVITY_LOGIN_EMAIL => array('Logged in using email link',		1),
317			USERBASE_ACTIVITY_REGISTER_EMAIL => array('Registered using email',		1)
318		);
319
320		UserConfig::$cohort_providers[] = new GenerationCohorts(GenerationCohorts::MONTH);
321		UserConfig::$cohort_providers[] = new GenerationCohorts(GenerationCohorts::WEEK);
322		UserConfig::$cohort_providers[] = new GenerationCohorts(GenerationCohorts::YEAR);
323		UserConfig::$cohort_providers[] = new RegMethodCohorts();
324	}
325
326	// Couldn't reuse it, but keeping it here because it might be still populated in user configs
327	// Use UserConfig::$all_modules array instead of needed
328	/* !!! DEPRECATED !!! */ public static $modules = array();
329}
330
331UserConfig::init();