[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the UserCache class. 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: _usercache.class.php,v 1.1 2007/06/25 11:01:47 fplanque Exp $ 33 */ 34 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 35 36 load_class('_core/model/dataobjects/_dataobjectcache.class.php'); 37 38 /** 39 * Blog Cache Class 40 * 41 * @package evocore 42 */ 43 class UserCache extends DataObjectCache 44 { 45 /** 46 * Cache for login -> User object reference. "login" is transformed to lowercase. 47 * @access private 48 * @var array 49 */ 50 var $cache_login = array(); 51 52 53 /** 54 * Remember special cache loads. 55 * @access protected 56 */ 57 var $alreadyCached = array(); 58 59 60 /** 61 * Constructor 62 */ 63 function UserCache() 64 { 65 parent::DataObjectCache( 'User', false, 'T_users', 'user_', 'user_ID', NULL, '', 66 /* TRANS: "None" select option */ T_('No user') ); 67 } 68 69 /* this is for debugging only: 70 function & get_by_ID( $req_ID, $halt_on_error = true ) 71 { 72 $obj = parent::get_by_ID( $req_ID, $halt_on_error ); 73 pre_dump($obj); 74 return $obj; 75 } 76 */ 77 78 79 /** 80 * Get a user object by login. 81 * 82 * Does not halt on error. 83 * 84 * @return false|User Reference to the user object or false if not found 85 */ 86 function & get_by_login( $login ) 87 { 88 // Make sure we have a lowercase login: 89 // We want all logins to be lowercase to guarantee uniqueness regardless of the database case handling for UNIQUE indexes. 90 $login = strtolower( $login ); 91 92 if( !isset( $this->cache_login[$login] ) ) 93 { 94 global $DB; 95 96 if( $row = $DB->get_row( " 97 SELECT * 98 FROM T_users 99 WHERE user_login = '".$DB->escape($login)."'", 0, 0, 'Get User login' ) ) 100 { 101 $this->add( new User( $row ) ); 102 } 103 else 104 { 105 $this->cache_login[$login] = false; 106 } 107 } 108 109 return $this->cache_login[$login]; 110 } 111 112 113 /** 114 * Get a user object by login, only if password matches. 115 * 116 * @param string Login 117 * @param string Password 118 * @param boolean Password is MD5()'ed 119 * @return false|User 120 */ 121 function & get_by_loginAndPwd( $login, $pass, $pass_is_md5 = true ) 122 { 123 if( !($User =& $this->get_by_login( $login )) ) 124 { 125 return false; 126 } 127 128 if( !$pass_is_md5 ) 129 { 130 $pass = md5($pass); 131 } 132 133 if( $User->pass != $pass ) 134 { 135 return false; 136 } 137 138 return $User; 139 } 140 141 142 /** 143 * Overload parent's function to also maintain the login cache. 144 * 145 * @param User 146 * @return boolean 147 */ 148 function add( & $Obj ) 149 { 150 if( parent::add( $Obj ) ) 151 { 152 $this->cache_login[ strtolower($Obj->login) ] = & $Obj; 153 154 return true; 155 } 156 157 return false; 158 } 159 160 161 /** 162 * Load members of a given blog 163 * 164 * @todo make a UNION query when we upgrade to MySQL 4 165 * @param integer blog ID to load members for 166 */ 167 function load_blogmembers( $blog_ID ) 168 { 169 global $DB, $Debuglog; 170 171 if( isset( $this->alreadyCached['blogmembers'] ) && isset( $this->alreadyCached['blogmembers'][$blog_ID] ) ) 172 { 173 $Debuglog->add( "Already loaded <strong>$this->objtype(Blog #$blog_ID members)</strong> into cache", 'dataobjects' ); 174 return false; 175 } 176 177 // Remember this special load: 178 $this->alreadyCached['blogmembers'][$blog_ID] = true; 179 180 $Debuglog->add( "Loading <strong>$this->objtype(Blog #$blog_ID members)</strong> into cache", 'dataobjects' ); 181 182 // User perms: 183 $sql = 'SELECT T_users.* 184 FROM T_users INNER JOIN T_coll_user_perms ON user_ID = bloguser_user_ID 185 WHERE bloguser_blog_ID = '.$blog_ID.' 186 AND bloguser_ismember <> 0'; 187 foreach( $DB->get_results( $sql ) as $row ) 188 { 189 if( !isset($this->cache[$row->user_ID]) ) 190 { // Save reinstatiating User if it's already been added 191 $this->add( new User( $row ) ); 192 } 193 } 194 195 // Group perms: 196 $sql = 'SELECT T_users.* 197 FROM T_users LEFT JOIN T_coll_group_perms ON user_grp_ID = bloggroup_group_ID 198 WHERE bloggroup_blog_ID = '.$blog_ID.' 199 AND bloggroup_ismember <> 0'; 200 foreach( $DB->get_results( $sql ) as $row ) 201 { 202 if( !isset($this->cache[$row->user_ID]) ) 203 { // Save reinstatiating User if it's already been added 204 $this->add( new User( $row ) ); 205 } 206 } 207 208 return true; 209 } 210 211 212 /** 213 * Loads cache with blog memeber, then display form option list with cache contents 214 * 215 * Optionally, also adds default choice to the cache. 216 * 217 * @param integer blog ID 218 * @param integer selected ID 219 * @param boolean provide a choice for "none" with ID 0 220 */ 221 function get_blog_member_option_list( $blog_ID, $default = 0, $allow_none = false, $always_load_default = false ) 222 { 223 if( $blog_ID ) 224 { // Load requested blog members: 225 $this->load_blogmembers( $blog_ID ); 226 227 // Make sure current user is in list: 228 if( $default && $always_load_default ) 229 { 230 // echo '<option>getting default'; 231 $this->get_by_ID( $default ); 232 } 233 } 234 else 235 { // No blog specified: load ALL members: 236 $this->load_all(); 237 } 238 239 return parent::get_option_list( $default, $allow_none, 'get_preferred_name' ); 240 } 241 242 243 /** 244 * Clear our caches. 245 */ 246 function clear( $keep_shadow = false ) 247 { 248 $this->alreadyCached = array(); 249 $this->cache_login = array(); 250 251 return parent::clear($keep_shadow); 252 } 253 254 /** 255 * Handle our login cache. 256 */ 257 function remove_by_ID( $reg_ID ) 258 { 259 if( isset($this->cache[$req_ID]) ) 260 { 261 unset( $this->cache_login[ $this->cache[$req_ID] ] ); 262 } 263 parent::remove_by_ID($req_ID); 264 } 265 } 266 267 268 /* 269 * $Log: _usercache.class.php,v $ 270 * Revision 1.1 2007/06/25 11:01:47 fplanque 271 * MODULES (refactored MVC) 272 * 273 * Revision 1.10 2007/04/26 00:11:11 fplanque 274 * (c) 2007 275 * 276 * Revision 1.9 2007/02/08 03:48:22 waltercruz 277 * Changing double quotes to single quotes 278 * 279 * Revision 1.8 2006/12/05 01:35:27 blueyed 280 * Hooray for less complexity and the 8th param for DataObjectCache() 281 * 282 * Revision 1.7 2006/12/05 00:34:39 blueyed 283 * Implemented custom "None" option text in DataObjectCache; Added for $ItemStatusCache, $GroupCache, UserCache and BlogCache; Added custom text for Item::priority_options() 284 * 285 * Revision 1.6 2006/11/24 18:27:25 blueyed 286 * Fixed link to b2evo CVS browsing interface in file docblocks 287 * 288 * Revision 1.5 2006/10/13 10:01:07 blueyed 289 * Fixed clear() and remove_by_ID() for UserCache and its own caches + test 290 */ 291 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |