Source for file _usercache.class.php
Documentation is available at _usercache.class.php
* This file implements the UserCache class.
* This file is part of the evoCore framework - {@link http://evocore.net/}
* See also {@link http://sourceforge.net/projects/evocms/}.
* @copyright (c)2003-2008 by Francois PLANQUE - {@link http://fplanque.net/}
* Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
* {@internal License choice
* - If you have received this file as part of a package, please find the license.txt file in
* the same folder or the closest folder above for complete license terms.
* - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
* then you must choose one of the following licenses before using the file:
* - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
* - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
* {@internal Open Source relicensing agreement:
* Daniel HAHLER grants Francois PLANQUE the right to license
* Daniel HAHLER's contributions to this file and the b2evolution project
* under any OSI approved OSS license (http://www.opensource.org/licenses/).
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
* @author fplanque: Francois PLANQUE
* @author blueyed: Daniel HAHLER
* @version $Id: _usercache.class.php,v 1.2 2008/01/21 09:35:36 fplanque Exp $
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
load_class('_core/model/dataobjects/_dataobjectcache.class.php');
* Cache for login -> User object reference. "login" is transformed to lowercase.
var $cache_login =
array();
* Remember special cache loads.
parent::DataObjectCache( 'User', false, 'T_users', 'user_', 'user_ID', NULL, '',
/* TRANS: "None" select option */ T_('No user') );
/* this is for debugging only:
function & get_by_ID( $req_ID, $halt_on_error = true )
$obj = parent::get_by_ID( $req_ID, $halt_on_error );
* Get a user object by login.
* Does not halt on error.
* @return false|UserReference to the user object or false if not found
// Make sure we have a lowercase login:
// We want all logins to be lowercase to guarantee uniqueness regardless of the database case handling for UNIQUE indexes.
if( !isset
( $this->cache_login[$login] ) )
if( $row =
$DB->get_row( "
WHERE user_login = '".
$DB->escape($login).
"'", 0, 0, 'Get User login' ) )
$this->cache_login[$login] =
false;
return $this->cache_login[$login];
* Get a user object by login, only if password matches.
* @param boolean Password is MD5()'ed
if( $User->pass !=
$pass )
* Overload parent's function to also maintain the login cache.
if( parent::add( $Obj ) )
$this->cache_login[ strtolower($Obj->login) ] =
& $Obj;
* Load members of a given blog
* @todo make a UNION query when we upgrade to MySQL 4
* @param integer blog ID to load members for
$Debuglog->add( "Already loaded <strong>$this->objtype(Blog #$blog_ID members)</strong> into cache", 'dataobjects' );
// Remember this special load:
$Debuglog->add( "Loading <strong>$this->objtype(Blog #$blog_ID members)</strong> into cache", 'dataobjects' );
FROM T_users INNER JOIN T_coll_user_perms ON user_ID = bloguser_user_ID
WHERE bloguser_blog_ID = '.
$blog_ID.
'
AND bloguser_ismember <> 0';
foreach( $DB->get_results( $sql ) as $row )
if( !isset
($this->cache[$row->user_ID]) )
{ // Save reinstatiating User if it's already been added
FROM T_users LEFT JOIN T_coll_group_perms ON user_grp_ID = bloggroup_group_ID
WHERE bloggroup_blog_ID = '.
$blog_ID.
'
AND bloggroup_ismember <> 0';
foreach( $DB->get_results( $sql ) as $row )
if( !isset
($this->cache[$row->user_ID]) )
{ // Save reinstatiating User if it's already been added
* Loads cache with blog memeber, then display form option list with cache contents
* Optionally, also adds default choice to the cache.
* @param integer selected ID
* @param boolean provide a choice for "none" with ID 0
{ // Load requested blog members:
// Make sure current user is in list:
if( $default &&
$always_load_default )
// echo '<option>getting default';
{ // No blog specified: load ALL members:
return parent::get_option_list( $default, $allow_none, 'get_preferred_name' );
function clear( $keep_shadow =
false )
$this->cache_login =
array();
return parent::clear($keep_shadow);
* Handle our login cache.
if( isset
($this->cache[$req_ID]) )
unset
( $this->cache_login[ $this->cache[$req_ID] ] );
* $Log: _usercache.class.php,v $
* Revision 1.2 2008/01/21 09:35:36 fplanque
* Revision 1.1 2007/06/25 11:01:47 fplanque
* MODULES (refactored MVC)
* Revision 1.10 2007/04/26 00:11:11 fplanque
* Revision 1.9 2007/02/08 03:48:22 waltercruz
* Changing double quotes to single quotes
* Revision 1.8 2006/12/05 01:35:27 blueyed
* Hooray for less complexity and the 8th param for DataObjectCache()
* Revision 1.7 2006/12/05 00:34:39 blueyed
* Implemented custom "None" option text in DataObjectCache; Added for $ItemStatusCache, $GroupCache, UserCache and BlogCache; Added custom text for Item::priority_options()
* Revision 1.6 2006/11/24 18:27:25 blueyed
* Fixed link to b2evo CVS browsing interface in file docblocks
* Revision 1.5 2006/10/13 10:01:07 blueyed
* Fixed clear() and remove_by_ID() for UserCache and its own caches + test