[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/users/model/ -> _usersettings.class.php (source)

   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-2007 by Francois PLANQUE - {@link http://fplanque.net/}

   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,v 1.2 2007/06/30 22:10:32 fplanque Exp $

  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');
  41  
  42  /**

  43   * Class to handle the settings for users

  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' => 'default',    // selected view in blog (user/group) perms
  71  
  72          'login_multiple_sessions' => 1,     // allow multiple concurrent sessions? (PARAMOUNT ON DEMO SERVER)
  73  
  74          'results_per_page' => 20,
  75      );
  76  
  77  
  78      /**

  79       * Constructor

  80       */
  81  	function UserSettings()
  82      { // constructor
  83          parent::AbstractSettings( 'T_usersettings', array( 'uset_user_ID', 'uset_name' ), 'uset_value', 1 );
  84      }
  85  
  86  
  87      /**

  88       * Get a setting from the DB user settings table

  89       *

  90       * @param string name of setting

  91       * @param integer User ID (by default $current_User->ID will be used)

  92       */
  93  	function get( $setting, $user_ID = NULL )
  94      {
  95          if( ! isset($user_ID) )
  96          {
  97              global $current_User;
  98  
  99              if( ! isset($current_User) )
 100              { // no current/logged in user:
 101                  return $this->get_default($setting);
 102              }
 103  
 104              $user_ID = $current_User->ID;
 105          }
 106  
 107          return parent::get( $user_ID, $setting );
 108      }
 109  
 110  
 111      /**

 112       * Temporarily sets a user setting ({@link dbupdate()} writes it to DB)

 113       *

 114       * @param string name of setting

 115       * @param mixed new value

 116       * @param integer User ID (by default $current_User->ID will be used)

 117       */
 118  	function set( $setting, $value, $user_ID = NULL )
 119      {
 120          if( ! isset($user_ID) )
 121          {
 122              global $current_User;
 123  
 124              if( ! isset($current_User) )
 125              { // no current/logged in user:
 126                  return false;
 127              }
 128  
 129              $user_ID = $current_User->ID;
 130          }
 131  
 132          return parent::set( $user_ID, $setting, $value );
 133      }
 134  
 135  
 136      /**

 137       * Mark a setting for deletion ({@link dbupdate()} writes it to DB).

 138       *

 139       * @param string name of setting

 140       * @param integer User ID (by default $current_User->ID will be used)

 141       */
 142  	function delete( $setting, $user_ID = NULL )
 143      {
 144          if( ! isset($user_ID) )
 145          {
 146              global $current_User;
 147  
 148              if( ! isset($current_User) )
 149              { // no current/logged in user:
 150                  return false;
 151              }
 152  
 153              $user_ID = $current_User->ID;
 154          }
 155  
 156          return parent::delete( $user_ID, $setting );
 157      }
 158  
 159  
 160      /**

 161       * Get a param from Request and save it to UserSettings, or default to previously saved user setting.

 162       *

 163       * If the user setting was not set before (and there's no default given that gets returned), $default gets used.

 164       *

 165       * @todo Move this to _abstractsettings.class.php - the other Settings object can also make use of it!

 166       *

 167       * @param string Request param name

 168       * @param string User setting name. Make sure this is unique!

 169       * @param string Force value type to one of:

 170       * - integer

 171       * - float

 172       * - string (strips (HTML-)Tags, trims whitespace)

 173       * - array

 174       * - object

 175       * - null

 176       * - html (does nothing)

 177       * - '' (does nothing)

 178       * - '/^...$/' check regexp pattern match (string)

 179       * - 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).

 180       * Value type will be forced only if resulting value (probably from default then) is !== NULL

 181       * @param mixed Default value or TRUE if user input required

 182       * @param boolean Do we need to memorize this to regenerate the URL for this page?

 183       * @param boolean Override if variable already set

 184       * @return NULL|mixed NULL, if neither a param was given nor {@link $UserSettings} knows about it.

 185       */
 186  	function param_Request( $param_name, $uset_name, $type = '', $default = '', $memorize = false, $override = false ) // we do not force setting it..
 187      {
 188          $value = param( $param_name, $type, NULL, $memorize, $override, false ); // we pass NULL here, to see if it got set at all

 189  
 190          if( $value !== false )
 191          { // we got a value
 192              $this->set( $uset_name, $value );
 193              $this->dbupdate();
 194          }
 195          else
 196          { // get the value from user settings
 197              $value = $this->get($uset_name);
 198  
 199              if( is_null($value) )
 200              { // it's not saved yet and there's not default defined ($_defaults)
 201                  $value = $default;
 202              }
 203          }
 204  
 205          set_param( $param_name, $value );
 206          return get_param($param_name);
 207      }
 208  }
 209  
 210  
 211  /*

 212   * $Log: _usersettings.class.php,v $

 213   * Revision 1.2  2007/06/30 22:10:32  fplanque

 214   * changed default

 215   *

 216   * Revision 1.1  2007/06/25 11:01:48  fplanque

 217   * MODULES (refactored MVC)

 218   *

 219   * Revision 1.32  2007/05/26 22:21:32  blueyed

 220   * Made $limit for Results configurable per user

 221   *

 222   * Revision 1.31  2007/05/13 18:49:55  fplanque

 223   * made autoselect_blog() more robust under PHP4

 224   *

 225   * Revision 1.30  2007/04/26 00:11:11  fplanque

 226   * (c) 2007

 227   *

 228   * Revision 1.29  2007/02/25 01:39:06  fplanque

 229   * wording

 230   *

 231   * Revision 1.28  2007/02/21 22:21:30  blueyed

 232   * "Multiple sessions" user setting

 233   *

 234   * Revision 1.27  2007/01/25 03:17:00  fplanque

 235   * visual cleanup for average users

 236   * geeky stuff preserved as options

 237   *

 238   * Revision 1.26  2007/01/24 01:57:07  fplanque

 239   * minor

 240   *

 241   * Revision 1.25  2007/01/23 05:00:25  fplanque

 242   * better user defaults

 243   *

 244   * Revision 1.24  2006/12/18 03:20:22  fplanque

 245   * _header will always try to set $Blog.

 246   * controllers can use valid_blog_requested() to make sure we have one

 247   * controllers should call set_working_blog() to change $blog, so that it gets memorized in the user settings

 248   *

 249   * Revision 1.23  2006/12/18 01:43:26  fplanque

 250   * minor bugfix

 251   *

 252   * Revision 1.22  2006/11/24 18:27:25  blueyed

 253   * Fixed link to b2evo CVS browsing interface in file docblocks

 254   *

 255   * Revision 1.21  2006/11/12 17:37:41  fplanque

 256   * code for "simple" is "default"

 257   *

 258   * Revision 1.20  2006/11/04 17:43:14  blueyed

 259   * Blog perm layout views: fixed non-JS links (ctrl param) and store selected one in UserSettings (TODO for switching by JS)

 260   */
 261  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics