/** * @see \wcf\system\user\activity\event\IUserActivityEvent::prepare() */ public function prepare(array $events) { if (!WCF::getSession()->getPermission('user.profile.canViewUserProfile')) { return; } $responses = $responseIDs = array(); foreach ($events as $event) { $responseIDs[] = $event->objectID; } // fetch responses $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($responseIDs)); $responseList->readObjects(); $responses = $responseList->getObjects(); // fetch comments $commentIDs = $comments = array(); foreach ($responses as $response) { $commentIDs[] = $response->commentID; } if (!empty($commentIDs)) { $commentList = new CommentList(); $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs)); $commentList->readObjects(); $comments = $commentList->getObjects(); } // fetch users $userIDs = $users = array(); foreach ($comments as $comment) { $userIDs[] = $comment->objectID; $userIDs[] = $comment->userID; } if (!empty($userIDs)) { $userList = new UserProfileList(); $userList->getConditionBuilder()->add("user_table.userID IN (?)", array($userIDs)); $userList->readObjects(); $users = $userList->getObjects(); } // set message foreach ($events as $event) { if (isset($responses[$event->objectID])) { $response = $responses[$event->objectID]; $comment = $comments[$response->commentID]; if (isset($users[$comment->objectID]) && isset($users[$comment->userID])) { if (!$users[$comment->objectID]->isProtected()) { $event->setIsAccessible(); // title $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.profileCommentResponse', array('commentAuthor' => $users[$comment->userID], 'user' => $users[$comment->objectID])); $event->setTitle($text); // description $event->setDescription($response->getExcerpt()); } continue; } } $event->setIsOrphaned(); } }
/** * @see \wcf\data\ISearchAction::getSearchResultList() */ public function getSearchResultList() { $searchString = $this->parameters['data']['searchString']; $excludedSearchValues = array(); if (isset($this->parameters['data']['excludedSearchValues'])) { $excludedSearchValues = $this->parameters['data']['excludedSearchValues']; } $list = array(); if ($this->parameters['data']['includeUserGroups']) { $accessibleGroups = UserGroup::getAccessibleGroups(); foreach ($accessibleGroups as $group) { $groupName = $group->getName(); if (!in_array($groupName, $excludedSearchValues)) { $pos = mb_strripos($groupName, $searchString); if ($pos !== false && $pos == 0) { $list[] = array('label' => $groupName, 'objectID' => $group->groupID, 'type' => 'group'); } } } } // find users $userProfileList = new UserProfileList(); $userProfileList->getConditionBuilder()->add("username LIKE ?", array($searchString . '%')); if (!empty($excludedSearchValues)) { $userProfileList->getConditionBuilder()->add("username NOT IN (?)", array($excludedSearchValues)); } $userProfileList->sqlLimit = 10; $userProfileList->readObjects(); foreach ($userProfileList as $userProfile) { $list[] = array('icon' => $userProfile->getAvatar()->getImageTag(16), 'label' => $userProfile->username, 'objectID' => $userProfile->userID, 'type' => 'user'); } return $list; }
/** * init one user by condition * * @param Mixed $var * @param Array $mbqOpt * $mbqOpt['case'] = 'oUserProfile' means init user by oUserProfile.$var is oUserProfile. * $mbqOpt['case'] = 'byUserId' means init user by user id.$var is user id. * $mbqOpt['case'] = 'byLoginName' means init user by login name.$var is login name. * @return Mixed */ public function initOMbqEtUser($var = null, $mbqOpt = array()) { if ($mbqOpt['case'] == 'oUserProfile') { $oMbqEtUser = MbqMain::$oClk->newObj('MbqEtUser'); $oUser = $var->getDecoratedObject(); $oMbqEtUser->userId->setOriValue($oUser->userID); $oMbqEtUser->loginName->setOriValue($oUser->username); $oMbqEtUser->userName->setOriValue($oUser->username); $oMbqEtUser->userEmail->setOriValue($oUser->email); $oMbqEtUser->userGroupIds->setOriValue($oUser->getGroupIDs()); $oMbqEtUser->iconUrl->setOriValue($var->getAvatar()->getURL()); $oMbqEtUser->postCount->setOriValue($oUser->wbbPosts); $oMbqEtUser->canSearch->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.canSearch.range.yes')); $oMbqEtUser->canWhosonline->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.canWhosonline.range.yes')); $oMbqEtUser->regTime->setOriValue($oUser->registrationDate); $oMbqEtUser->lastActivityTime->setOriValue($oUser->lastActivityTime); if ($var->isOnline()) { $oMbqEtUser->isOnline->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.isOnline.range.yes')); } else { $oMbqEtUser->isOnline->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.isOnline.range.no')); } if (MODULE_CONVERSATION && $var->getPermission('user.conversation.canUseConversation')) { $oMbqEtUser->canPm->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.canPm.range.yes')); $oMbqEtUser->acceptPm->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.acceptPm.range.yes')); $oMbqEtUser->canSendPm->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.canSendPm.range.yes')); } $oMbqEtUser->maxAttachment->setOriValue(10); //todo,hard code $oMbqEtUser->maxPngSize->setOriValue(1024 * 1024); //todo,hard code $oMbqEtUser->maxJpgSize->setOriValue(1024 * 1024); //todo,hard code $group = UserGroup::getGroupByID($oUser->groupID); if ($oUser->banned) { $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.banned')); } else { if (empty($oUser->groupID) || empty($group)) { if (REGISTER_ACTIVATION_METHOD == 1) { $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.inactive')); } else { $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.unapproved')); } } else { if ($group->isAdminGroup()) { $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.admin')); } else { if (method_exists($group, 'isModGroup') && $group->isModGroup()) { $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.mod')); } else { $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.normal')); } } } } $oMbqEtUser->mbqBind['oUser'] = $oUser; $oMbqEtUser->mbqBind['oUserProfile'] = $var; return $oMbqEtUser; } elseif ($mbqOpt['case'] == 'byUserId') { $userIds = array($var); $objsMbqEtUser = $this->getObjsMbqEtUser($userIds, array('case' => 'byUserIds')); if (is_array($objsMbqEtUser) && count($objsMbqEtUser) == 1) { return $objsMbqEtUser[0]; } return; } elseif ($mbqOpt['case'] == 'byLoginName') { $oUserProfile = UserProfile::getUserProfileByUsername($var); if ($oUserProfile) { return $this->initOMbqEtUser($oUserProfile, array('case' => 'oUserProfile')); } return; } elseif ($mbqOpt['case'] == 'byEmail') { $userList = new UserProfileList(); $userList->getConditionBuilder()->add("user_table.email IN (?)", array(array($var))); $userList->readObjects(); $oUserProfile = current($userList->objects); if ($oUserProfile) { return $this->initOMbqEtUser($oUserProfile, array('case' => 'oUserProfile')); } return; } MbqError::alert('', __METHOD__ . ',line:' . __LINE__ . '.' . MBQ_ERR_INFO_UNKNOWN_CASE); }
/** * Returns user profile preview. * * @return array */ public function getUserProfile() { $userID = reset($this->objectIDs); if ($userID) { $userProfileList = new UserProfileList(); $userProfileList->getConditionBuilder()->add("user_table.userID = ?", array($userID)); $userProfileList->readObjects(); $userProfiles = $userProfileList->getObjects(); if (empty($userProfiles)) { WCF::getTPL()->assign('unknownUser', true); } else { WCF::getTPL()->assign('user', reset($userProfiles)); } } else { WCF::getTPL()->assign('unknownUser', true); } return array('template' => WCF::getTPL()->fetch('userProfilePreview'), 'userID' => $userID); }
/** * Returns the user profiles of the users with the given names. * * @param array<string> $usernames * @return array<\wcf\data\user\UserProfile> */ public static function getUserProfilesByUsername(array $usernames) { $users = array(); // save case sensitive usernames $caseSensitiveUsernames = array(); foreach ($usernames as &$username) { $tmp = mb_strtolower($username); $caseSensitiveUsernames[$tmp] = $username; $username = $tmp; } unset($username); // check cache foreach ($usernames as $index => $username) { foreach (self::$userProfiles as $user) { if (mb_strtolower($user->username) === $username) { $users[$username] = $user; unset($usernames[$index]); } } } if (!empty($usernames)) { $userList = new UserProfileList(); $userList->getConditionBuilder()->add("user_table.username IN (?)", array($usernames)); $userList->readObjects(); foreach ($userList as $user) { $users[mb_strtolower($user->username)] = $user; self::$userProfiles[$user->userID] = $user; } foreach ($usernames as $username) { if (!isset($users[$username])) { $users[$username] = null; } } } // revert usernames to original case foreach ($users as $username => $user) { unset($users[$username]); if (isset($caseSensitiveUsernames[$username])) { $users[$caseSensitiveUsernames[$username]] = $user; } } return $users; }