b2evolution PHP Cross Reference Blogging Systems

Source: /inc/users/model/_usersettings.class.php - 305 lines - 11105 bytes - Summary - Text - Print

Description: This file implements the UserSettings class which handles user_ID/name/value triplets. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the UserSettings class which handles user_ID/name/value triplets.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
  10   *
  11   * {@internal License choice
  12   * - If you have received this file as part of a package, please find the license.txt file in
  13   *   the same folder or the closest folder above for complete license terms.
  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15   *   then you must choose one of the following licenses before using the file:
  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18   * }}
  19   *
  20   * {@internal Open Source relicensing agreement:
  21   * Daniel HAHLER grants Francois PLANQUE the right to license
  22   * Daniel HAHLER's contributions to this file and the b2evolution project
  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  24   * }}
  25   *
  26   * @package evocore
  27   *
  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  29   * @author fplanque: Francois PLANQUE
  30   * @author blueyed: Daniel HAHLER
  31   *
  32   * @version $Id: _usersettings.class.php 6136 2014-03-08 07:59:48Z manuel $
  33   *
  34   */
  35  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  36  
  37  /**
  38   * Includes
  39   */
  40  load_class( 'settings/model/_abstractsettings.class.php', 'AbstractSettings' );
  41  
  42  /**
  43   * Class to handle the settings for users, and any user name-value pair which is not frequently used 
  44   *
  45   * @package evocore
  46   */
  47  class UserSettings extends AbstractSettings
  48  {
  49      /**
  50       * The default settings to use, when a setting is not given
  51       * in the database.
  52       *
  53       * @todo Allow overriding from /conf/_config_TEST.php?
  54       * @access protected
  55       * @var array
  56       */
  57      var $_defaults = array(
  58          'action_icon_threshold' => 3,
  59          'action_word_threshold' => 3,
  60          'display_icon_legend' => 0,
  61          'control_form_abortions' => 1,
  62          'focus_on_first_input' => 0,            // TODO: fix sideeffect when pressing F5
  63          'pref_browse_tab' => 'full',
  64          'pref_edit_tab' => 'simple',
  65  
  66          'fm_imglistpreview' => 1,
  67          'fm_showdate'       => 'compact',
  68          'fm_allowfiltering' => 'simple',
  69  
  70          'blogperms_layout' => 'wide',    // selected view in blog (user/group) perms
  71  
  72          'login_multiple_sessions' => 0,     // disallow multiple concurrent sessions by default
  73          'timeout_sessions' => NULL,            // user session timeout (NULL means application default)
  74  
  75          'results_per_page' => 20,
  76  
  77          'show_evobar' => 1,
  78          'show_breadcrumbs' => 1,
  79          'show_menu' => 1,
  80  
  81          'last_activation_email' => NULL, // It should be the date of the last account activation email. If it is not set, and users is not activated means activation email wasn't sent.
  82          'last_unread_messages_reminder' => NULL, // It will be the date when the last unread message reminder email was sent
  83          'last_notification_email' => NULL, // It must have a 'timestamp_number' format, where the timestamp ( servertime ) is the last notification email ts, and the number is how many notification email was sent on that day
  84          'last_newsletter' => NULL, // It must have a 'timestamp_number' format, where the timestamp ( servertime ) is the last newsletter ts, and the number is how many newsletter was sent on that day
  85          'last_activation_reminder_key' => NULL, // It will be set at the first time when activation reminder email will be sent
  86          'activation_reminder_count' => 0, // How many activation reminder was sent since the user is not activated
  87          'send_activation_reminder' => 1, // Send reminder to activate my account if it is not activated
  88          'welcome_message_sent' => 0, // Used to know if user already received a welcome message after email activation
  89  
  90          // admin user notifications
  91          'send_cmt_moderation_reminder' => 1, // Send reminders about comments awaiting moderation
  92          'notify_new_user_registration' => 1, // Notify admin user when a new user has registered
  93          'notify_activated_account' => 1, // Notify admin user when an account has been activated by email
  94          'notify_closed_account' => 1, // Notify admin user when an account has been closed by the account owner
  95          'notify_reported_account' => 1, // Notify admin user when an account has been reported by another user
  96          'notify_cronjob_error' => 1, // Notify admin user when a scheduled task ends with an error or timeout
  97  
  98          'account_close_ts' => NULL, // It will be the date when the account was closed. Until the account is not closed this will be NULL.
  99          'account_close_reason' => NULL, // It will be the reason why the account was closed. Until the account is not closed this will be NULL.
 100  
 101          'last_new_thread' => NULL, // It is the date when the user has created the last new thread, NULL if User has never create a new thread
 102          'new_thread_count' => 0, // How many new thread was created by this user TODAY!
 103  
 104          'show_online' => 1,     // Show if user is online or not
 105          'user_domain' => NULL,  // User domain
 106          'user_browser' => NULL, // User browser
 107  
 108          'email_format' => 'auto', // Email format: auto | html | text
 109  
 110          'admin_skin' => 'chicago',  // User default admin skin
 111      );
 112  
 113      /**
 114       * The configurable default settings.
 115       * Add those settings below, which default value is saved in GeneralSettings.
 116       * For these option we didn't add a default value here intentionally, this way it will get the default value from general settings!
 117       * All of this options must have a pair with a 'def_' prefix in GeneralSettings class.
 118       * We use this array when we are reseting the default settings.
 119       *
 120       * @access protected
 121       * @var array
 122       */
 123      var $_configurable_defaults = array(
 124          'notify_messages' => 1,     // Notify user when receives a private message
 125          'notify_unread_messages' => 1, // Notify user when he has unread messages more then 24 hour, and he was not notified in the last 3 days
 126          'notify_published_comments' => 1, // Notify user when a comment is published in an own post
 127          'notify_comment_moderation' => 1, // Notify when a comment is awaiting moderation and the user has right to moderate that comment
 128          'notify_post_moderation' => 1, // Notify when a post is awaiting moderation and the user has right to moderate that post
 129  
 130          'enable_PM' => 1,
 131          'enable_email' => 1,
 132  
 133          'newsletter_news' => 1, // Send news
 134          'newsletter_ads'  => 0, // Send ADs
 135  
 136          'notification_email_limit' => 3, // How many notification email is allowed per day for this user
 137          'newsletter_limit' => 1, // How many newsletter email is allowed per day for this user
 138      );
 139  
 140  
 141      /**
 142       * Constructor
 143       */
 144  	function UserSettings()
 145      { // constructor
 146          parent::AbstractSettings( 'T_users__usersettings', array( 'uset_user_ID', 'uset_name' ), 'uset_value', 1 );
 147      }
 148  
 149  
 150      /**
 151       * Get a setting from the DB user settings table
 152       *
 153       * @param string name of setting
 154       * @param integer User ID (by default $current_User->ID will be used)
 155       */
 156  	function get( $setting, $user_ID = NULL )
 157      {
 158          global $Settings;
 159  
 160          if( ! isset($user_ID) )
 161          {
 162              global $current_User;
 163  
 164              if( ! isset($current_User) )
 165              { // no current/logged in user:
 166                  $result = $this->get_default($setting);
 167                  if( $result == NULL )
 168                  {
 169                      $result = $Settings->get( 'def_'.$setting );
 170                  }
 171                  return $result;
 172              }
 173  
 174              $user_ID = $current_User->ID;
 175          }
 176  
 177          $result = parent::get( $user_ID, $setting );
 178          if( $result == NULL )
 179          {
 180              $result = $Settings->get( 'def_'.$setting );
 181          }
 182          return $result;
 183      }
 184  
 185  
 186      /**
 187       * Temporarily sets a user setting ({@link dbupdate()} writes it to DB)
 188       *
 189       * @param string name of setting
 190       * @param mixed new value
 191       * @param integer User ID (by default $current_User->ID will be used)
 192       */
 193  	function set( $setting, $value, $user_ID = NULL )
 194      {
 195          if( ! isset($user_ID) )
 196          {
 197              global $current_User;
 198  
 199              if( ! isset($current_User) )
 200              { // no current/logged in user:
 201                  return false;
 202              }
 203  
 204              $user_ID = $current_User->ID;
 205          }
 206  
 207          return parent::set( $user_ID, $setting, $value );
 208      }
 209  
 210  
 211      /**
 212       * Mark a setting for deletion ({@link dbupdate()} writes it to DB).
 213       *
 214       * @param string name of setting
 215       * @param integer User ID (by default $current_User->ID will be used)
 216       */
 217  	function delete( $setting, $user_ID = NULL )
 218      {
 219          if( ! isset($user_ID) )
 220          {
 221              global $current_User;
 222  
 223              if( ! isset($current_User) )
 224              { // no current/logged in user:
 225                  return false;
 226              }
 227  
 228              $user_ID = $current_User->ID;
 229          }
 230  
 231          return parent::delete( $user_ID, $setting );
 232      }
 233  
 234  
 235      /**
 236       * Get a param from Request and save it to UserSettings, or default to previously saved user setting.
 237       *
 238       * If the user setting was not set before (and there's no default given that gets returned), $default gets used.
 239       *
 240       * @todo Move this to _abstractsettings.class.php - the other Settings object can also make use of it!
 241       *
 242       * @param string Request param name
 243       * @param string User setting name. Make sure this is unique!
 244       * @param string Force value type to one of:
 245       * - integer
 246       * - float
 247       * - string (strips (HTML-)Tags, trims whitespace)
 248       * - array
 249       * - object
 250       * - null
 251       * - html (does nothing)
 252       * - '' (does nothing)
 253       * - '/^...$/' check regexp pattern match (string)
 254       * - boolean (will force type to boolean, but you can't use 'true' as a default since it has special meaning. There is no real reason to pass booleans on a URL though. Passing 0 and 1 as integers seems to be best practice).
 255       * Value type will be forced only if resulting value (probably from default then) is !== NULL
 256       * @param mixed Default value or TRUE if user input required
 257       * @param boolean Do we need to memorize this to regenerate the URL for this page?
 258       * @param boolean Override if variable already set
 259       * @return NULL|mixed NULL, if neither a param was given nor {@link $UserSettings} knows about it.
 260       */
 261  	function param_Request( $param_name, $uset_name, $type = '', $default = '', $memorize = false, $override = false ) // we do not force setting it..
 262      {
 263          $value = param( $param_name, $type, NULL, $memorize, $override, false ); // we pass NULL here, to see if it got set at all
 264  
 265          if( $value !== false )
 266          { // we got a value
 267              $this->set( $uset_name, $value );
 268              $this->dbupdate();
 269          }
 270          else
 271          { // get the value from user settings
 272              $value = $this->get($uset_name);
 273  
 274              if( is_null($value) )
 275              { // it's not saved yet and there's not default defined ($_defaults)
 276                  $value = $default;
 277              }
 278          }
 279  
 280          set_param( $param_name, $value );
 281          return get_param($param_name);
 282      }
 283  
 284  
 285      /**
 286       * Reset a user settings to the default values
 287       * 
 288       * @param integer user ID
 289       * @param boolean set to true to save modifications
 290       */
 291  	function reset_to_defaults( $user_ID, $db_save = true )
 292      {
 293          // Remove all UserSettings where a default or configurable default exists:
 294          foreach( $this->_defaults as $k => $v )
 295          {
 296              $this->delete( $k, $user_ID );
 297          }
 298          foreach( $this->_configurable_defaults as $k => $v )
 299          {
 300              $this->delete( $k, $user_ID );
 301          }
 302      }
 303  }
 304  
 305  ?>

title

Description

title

Description

title

Description

title

title

Body