PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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