📄 simplepostnukeuserdataprovider.class.php
字号:
if( $status != USER_STATUS_ALL ) $where = "status = '".Db::qstr($status)."'"; if( $searchTerms != "" ) { if( $where != "" ) $where .= " AND "; $where = $this->getSearchConditions( $searchTerms ); } if( $where != "" ) $where = "WHERE $where"; $query = "SELECT * FROM ".$this->getPrefix()."users $where ORDER BY id ASC"; $result = $this->Execute( $query, $page, $itemsPerPage ); $users = Array(); if( !$result ) return $users; while ($row = $result->FetchRow()) { $user = $this->mapRow( $row ); $users[] = $user; // cache the data for later use $this->_cache->setData( $user->getId(), CACHE_USERINFO, $user ); $this->_cache->setData( $user->getUsername(), CACHE_USERIDBYNAME, $user ); } $result->Close(); return $users; } /** * @see Model::buildSearchCondition */ function buildSearchCondition( $searchTerms ) { $searchTerms = trim( $searchTerms ); $searchCond = "(user LIKE '%".Db::qstr($searchTerms)."%' OR full_name LIKE '%".Db::qstr($searchTerms)."%' OR email LIKE '%".Db::qstr($searchTerms)."%')"; return( $searchCond ); } /** * Updates the information related to a user * * @param userInfo An UserInfo object containing the <b>already udpated</b> information of the * user we would like to update. * @return Returns true if ok or false otherwise. */ function updateUser( $user ) { $result = $this->update( $user ); if( $result ) { // remove the old data $this->_cache->removeData( $user->getId(), CACHE_USERINFO ); $this->_cache->removeData( $user->getUsername(), CACHE_USERIDBYNAME ); } BaseUserDataProvider::updateUser( $user ); return $result; } /** * Adds a user to the database. * * @param user An UserInfo object with the necessary information * @return Returns the identifier assigned to the user, or false if there was any error. It will also modify the * UserInfo object passed by parameter and set its database id. */ function addUser( &$user ) { $userId = $this->add( $user ); if( $userId ) { // 1. We need to set the password again in this initial UserInfo object, because // current password is plain password. Through setPassword() we can encrpyt the password // and make the UserInfo object right, then we can cache it. Or user can not login even // we addUser() successfully. // 2. Another easy way to solve this is remove the cache code below, don't cache the UserInfo // Object in the first time. Let it cache later. $user->setMD5Password( $user->getPassword() ); $this->_cache->setData( $user->getId(), CACHE_USERINFO, $user ); $this->_cache->setData( $user->getUsername(), CACHE_USERIDBYNAME, $user ); } return( $userId ); } /** * Returns an array with all the users that belong to the given * blog. * * @param blogId The blog identifier. * @param includeOwner Wether to include the owner of the blog or not. * @param status * @param searchTerms * @return An array with the information about the users who belong in * one way or another to that blog. */ function getBlogUsers( $blogId, $includeOwner = true, $status = USER_STATUS_ALL, $searchTerms = "" ) { $users = Array(); $prefix = $this->getPrefix(); // get the information about the owner, if requested so if( $includeOwner ) { $query = "SELECT {$prefix}users.* FROM {$prefix}users, {$prefix}blogs WHERE {$prefix}users.id = {$prefix}blogs.owner_id AND {$prefix}blogs.id = '".Db::qstr($blogId)."';"; $result = $this->Execute( $query ); if( !$result ) return false; $row = $result->FetchRow(); $result->Close(); array_push( $users, $this->mapRow( $row )); } // now get the other users who have permission for that blog. $query2 = "SELECT {$prefix}users.* FROM {$prefix}users, {$prefix}users_permissions WHERE {$prefix}users.id = {$prefix}users_permissions.user_id AND {$prefix}users_permissions.blog_id = '".Db::qstr($blogId)."';"; $result2 = $this->Execute( $query2 ); if( !$result2 ) // if error, return what we have so far... return $users; while( $row = $result2->FetchRow()) { array_push( $users, $this->mapRow($row)); } $result2->Close(); return $users; } /** * Removes users from the database * * @param userId The identifier of the user we are trying to remove */ function deleteUser( $userId ) { // first, delete all of his/her permissions if( $this->delete( $userId )) { lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" ); $perms = new UserPermissions(); $perms->revokeUserPermissions( $userId ); $this->_cache->removeData( $userId, CACHE_USERINFO ); } else return( false ); } /** * returns the total number of users * * @return total number of users */ function getNumUsers( $status = USER_STATUS_ALL, $searchTerms = "" ) { $table = $this->getPrefix()."users"; if( $status != USER_STATUS_ALL ) $where = "status = '".Db::qstr($status)."'"; $where = ""; if( $searchTerms != "" ) { if( $where != "" ) $where .= " AND "; $where = $this->getSearchConditions( $searchTerms ); } return( $this->getNumItems( $table, $where )); } /** * check if the email account has been registered * @return true if the email account has been registered */ function emailExists($email) { $query = "SELECT email FROM ".$this->getPrefix()."users WHERE email = '".Db::qstr($email)."'"; $result = $this->Execute($query); if(!$result) return false; $count = $result->RecordCount(); $result->Close(); return ($count >= 1); } /** * @see Model::getSearchConditions */ function getSearchConditions( $searchTerms ) { lt_include( PLOG_CLASS_PATH."class/dao/searchengine.class.php" ); // prepare the query string $searchTerms = SearchEngine::adaptSearchString( $searchTerms ); return( "(user LIKE '%".$searchTerms."%' OR full_name LIKE '%".$searchTerms."%')"); } }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -