/** * Validates the 'unignore' action. */ public function validateUnignore() { $this->readInteger('ignoreUserID', false, 'data'); $userProfile = UserProfile::getUserProfile($this->parameters['data']['ignoreUserID']); if ($userProfile === null) { throw new IllegalLinkException(); } }
/** * @see wcf\page\IPage::readParameters() */ public function readParameters() { parent::readParameters(); if (isset($_REQUEST['id']) && !isset($_POST['username'])) { $this->userID = intval($_REQUEST['id']); $this->user[] = UserProfile::getUserProfile($this->userID); } }
/** * @see \wcf\page\IPage::assignVariables() */ public function assignVariables() { parent::assignVariables(); $reportUser = UserProfile::getUserProfile($this->queue->userID); if ($reportUser === null) { $reportUser = new UserProfile(new User(null, array())); } WCF::getTPL()->assign(array('reportedContent' => ModerationQueueReportManager::getInstance()->getReportedContent($this->queue), 'queueManager' => ModerationQueueReportManager::getInstance(), 'reportUser' => $reportUser)); }
/** * @see \wcf\data\IGroupedUserListAction::validateGetGroupedUserList() */ public function validateGetGroupedUserList() { $this->readInteger('pageNo'); $this->readInteger('userID'); $this->userProfile = UserProfile::getUserProfile($this->parameters['userID']); if ($this->userProfile->isProtected()) { throw new PermissionDeniedException(); } }
/** * Returns the user-object which received this statement. * @return wcf\data\user\UserProfile */ public function getUser() { if ($this->user === null) { if ($this->userID) { $this->user = UserProfile::getUserProfile($this->userID); } else { $this->user = new UserProfile(new User(null, array())); } } return $this->user; }
/** * Returns a structured response. * * @param integer $responseID * @return \wcf\data\comment\response\StructuredCommentResponse */ public static function getResponse($responseID) { $response = new CommentResponse($responseID); if (!$response->responseID) { return null; } // prepare structured response $response = new StructuredCommentResponse($response); // add user profile $userProfile = UserProfile::getUserProfile($response->userID); $response->setUserProfile($userProfile); return $response; }
/** * @see \cms\system\content\type\IContentType::getOutput() */ public function getOutput(Content $content) { if ($content->userID) { $user = UserProfile::getUserProfile($content->userID); } else { if ($content->name) { $user = UserProfile::getUserProfileByUsername($content->name); } else { throw new SystemException('Neither user id nor username provided'); } } WCF::getTPL()->assign(array('user' => $user)); return parent::getOutput($content); }
/** * @see \wcf\page\IPage::readParameters() */ public function readParameters() { parent::readParameters(); if (isset($_REQUEST['id'])) { $this->userID = intval($_REQUEST['id']); } $this->user = UserProfile::getUserProfile($this->userID); if ($this->user === null) { throw new IllegalLinkException(); } // validate ignore status if (WCF::getUser()->userID && $this->user->isIgnoredUser(WCF::getUser()->userID)) { throw new PermissionDeniedException(); } $this->canonicalURL = LinkHandler::getInstance()->getLink('Mail', array('object' => $this->user->getDecoratedObject())); }
/** * @see \wcf\system\comment\manager\ICommentManager::isAccessible() */ public function isAccessible($objectID, $validateWritePermission = false) { // check object id $userProfile = UserProfile::getUserProfile($objectID); if ($userProfile === null) { return false; } // check visibility if ($userProfile->isProtected()) { return false; } // check target user settings if ($validateWritePermission) { if (!$userProfile->isAccessible('canWriteProfileComments') && $userProfile->userID != WCF::getUser()->userID) { return false; } if ($userProfile->isIgnoredUser(WCF::getUser()->userID)) { return false; } } return true; }
/** * Validates parameters to begin profile inline editing. */ public function validateBeginEdit() { if (!empty($this->objectIDs) && count($this->objectIDs) == 1) { $userID = reset($this->objectIDs); $this->userProfile = UserProfile::getUserProfile($userID); } if ($this->userProfile === null || !$this->userProfile->userID) { throw new UserInputException('objectIDs'); } if ($this->userProfile->userID != WCF::getUser()->userID) { if (!$this->userProfile->canEdit()) { throw new PermissionDeniedException(); } } else { if (!$this->userProfile->canEditOwnProfile()) { throw new PermissionDeniedException(); } } }
/** * Triggers a notification event. * * @param string $eventName * @param string $objectType * @param \wcf\system\user\notification\object\IUserNotificationObject $notificationObject * @param array<integer> $recipientIDs * @param array<mixed> $additionalData * @param integer $baseObjectID */ public function fireEvent($eventName, $objectType, IUserNotificationObject $notificationObject, array $recipientIDs, array $additionalData = array(), $baseObjectID = 0) { // check given object type and event name if (!isset($this->availableEvents[$objectType][$eventName])) { throw new SystemException("Unknown event " . $objectType . "-" . $eventName . " given"); } // get objects $objectTypeObject = $this->availableObjectTypes[$objectType]; $event = $this->availableEvents[$objectType][$eventName]; // get author's profile $userProfile = null; if ($notificationObject->getAuthorID()) { if ($notificationObject->getAuthorID() == WCF::getUser()->userID) { $userProfile = new UserProfile(WCF::getUser()); } else { $userProfile = UserProfile::getUserProfile($notificationObject->getAuthorID()); } } if ($userProfile === null) { $userProfile = new UserProfile(new User(null, array())); } // set object data $event->setObject(new UserNotification(null, array()), $notificationObject, $userProfile, $additionalData); $parameters = array('eventName' => $eventName, 'objectType' => $objectType, 'notificationObject' => $notificationObject, 'recipientIDs' => $recipientIDs, 'additionalData' => $additionalData, 'baseObjectID' => $baseObjectID, 'objectTypeObject' => $objectTypeObject, 'userProfile' => $userProfile, 'event' => $event); EventHandler::getInstance()->fireAction($this, 'fireEvent', $parameters); // find existing notifications $conditions = new PreparedStatementConditionBuilder(); $conditions->add("userID IN (?)", array($recipientIDs)); $conditions->add("eventID = ?", array($event->eventID)); $conditions->add("eventHash = ?", array($event->getEventHash())); $conditions->add("confirmTime = ?", array(0)); $sql = "SELECT\tnotificationID, userID\n\t\t\tFROM\twcf" . WCF_N . "_user_notification\n\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $notifications = array(); while ($row = $statement->fetchArray()) { $notifications[$row['userID']] = $row['notificationID']; } // check if event supports stacking and author should be added if (!empty($notifications) && $event->isStackable()) { $conditions = new PreparedStatementConditionBuilder(); $conditions->add("notificationID IN (?)", array(array_values($notifications))); if ($notificationObject->getAuthorID()) { $conditions->add("authorID = ?", array($notificationObject->getAuthorID())); } else { $conditions->add("authorID IS NULL"); } $sql = "SELECT\tnotificationID\n\t\t\t\tFROM\twcf" . WCF_N . "_user_notification_author\n\t\t\t\t" . $conditions; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $notificationIDs = array(); while ($row = $statement->fetchArray()) { $notificationIDs[] = $row['notificationID']; } // filter array of existing notifications and remove values which // do not have a notification from this author yet (inverse logic!) foreach ($notifications as $userID => $notificationID) { if (!in_array($notificationID, $notificationIDs)) { unset($notifications[$userID]); } } if (!empty($notificationIDs)) { // update trigger count $sql = "UPDATE\twcf" . WCF_N . "_user_notification\n\t\t\t\t\tSET\ttimesTriggered = timesTriggered + ?,\n\t\t\t\t\t\tguestTimesTriggered = guestTimesTriggered + ?\n\t\t\t\t\tWHERE\tnotificationID = ?"; $statement = WCF::getDB()->prepareStatement($sql); WCF::getDB()->beginTransaction(); foreach ($notificationIDs as $notificationID) { $statement->execute(array(1, $notificationObject->getAuthorID() ? 0 : 1, $notificationID)); } WCF::getDB()->commitTransaction(); } } $recipientIDs = array_diff($recipientIDs, array_keys($notifications)); if (empty($recipientIDs)) { return; } // get recipients $recipientList = new UserNotificationEventRecipientList(); $recipientList->getConditionBuilder()->add('event_to_user.eventID = ?', array($event->eventID)); $recipientList->getConditionBuilder()->add('event_to_user.userID IN (?)', array($recipientIDs)); $recipientList->readObjects(); $recipients = $recipientList->getObjects(); if (!empty($recipients)) { $data = array('authorID' => $event->getAuthorID() ?: null, 'data' => array('eventID' => $event->eventID, 'authorID' => $event->getAuthorID() ?: null, 'objectID' => $notificationObject->getObjectID(), 'baseObjectID' => $baseObjectID, 'eventHash' => $event->getEventHash(), 'packageID' => $objectTypeObject->packageID, 'mailNotified' => $event->supportsEmailNotification() ? 0 : 1, 'time' => TIME_NOW, 'additionalData' => serialize($additionalData)), 'recipients' => $recipients); if ($event->isStackable()) { $data['notifications'] = $notifications; $action = new UserNotificationAction(array(), 'createStackable', $data); } else { $data['data']['timesTriggered'] = 1; $action = new UserNotificationAction(array(), 'createDefault', $data); } $result = $action->executeAction(); $notifications = $result['returnValues']; // send notifications if ($event->supportsEmailNotification()) { foreach ($recipients as $recipient) { if ($recipient->mailNotificationType == 'instant') { if (isset($notifications[$recipient->userID]) && $notifications[$recipient->userID]['isNew']) { $this->sendInstantMailNotification($notifications[$recipient->userID]['object'], $recipient, $event); } } } } // reset notification count UserStorageHandler::getInstance()->reset(array_keys($recipients), 'userNotificationCount'); } }
/** * Returns associated user profile object. * * @return \wcf\data\user\UserProfile */ public function getUserProfile() { if ($this->affectedObject !== null && $this->userProfile === null) { if ($this->affectedObject->getUserID()) { $this->userProfile = UserProfile::getUserProfile($this->affectedObject->getUserID()); } else { $this->userProfile = new UserProfile(new User(null, array())); } } return $this->userProfile; }
/** * Validates the 'cropAvatar' action. */ public function validateCropAvatar() { $this->avatar = $this->getSingleObject(); // check if user can edit the given avatar if ($this->avatar->userID != WCF::getUser()->userID && !WCF::getSession()->getPermission('admin.user.canEditUser')) { throw new PermissionDeniedException(); } if (!WCF::getSession()->getPermission('user.profile.avatar.canUploadAvatar') || UserProfile::getUserProfile($this->avatar->userID)->disableAvatar) { throw new PermissionDeniedException(); } // check parameters $this->readInteger('cropX', true); $this->readInteger('cropY', true); if ($this->parameters['cropX'] < 0 || $this->parameters['cropX'] > $this->avatar->width - UserAvatar::$maxThumbnailSize) { throw new UserInputException('cropX'); } if ($this->parameters['cropY'] < 0 || $this->parameters['cropY'] > $this->avatar->height - UserAvatar::$maxThumbnailSize) { throw new UserInputException('cropY'); } }
/** * @see \wcf\page\IPage::readParameters() */ public function readParameters() { parent::readParameters(); if (!WCF::getUser()->userID) { return; } // check max pc permission if (ConversationHandler::getInstance()->getConversationCount() >= WCF::getSession()->getPermission('user.conversation.maxConversations')) { throw new NamedUserException(WCF::getLanguage()->get('wcf.conversation.error.mailboxIsFull')); } if (isset($_REQUEST['userID'])) { $userID = intval($_REQUEST['userID']); $user = UserProfile::getUserProfile($userID); if ($user === null || $user->userID == WCF::getUser()->userID) { throw new IllegalLinkException(); } // validate user try { Conversation::validateParticipant($user); } catch (UserInputException $e) { throw new NamedUserException(WCF::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.' . $e->getType(), array('errorData' => array('username' => $user->username)))); } $this->participants = $user->username; } // get max text length $this->maxTextLength = WCF::getSession()->getPermission('user.conversation.maxLength'); // quotes MessageQuoteManager::getInstance()->readParameters(); }
/** * Returns a user profile by id, fetches user profiles on first call. * * @param integer $userID * @return \wcf\data\user\UserProfile */ public function getUser($userID) { if (!empty($this->userIDs)) { UserProfile::getUserProfiles($this->userIDs); $this->userIDs = array(); } return UserProfile::getUserProfile($userID); }
/** * @see \wcf\page\IPage::readParameters() */ public function readParameters() { parent::readParameters(); if (isset($_REQUEST['id'])) { $this->userID = intval($_REQUEST['id']); } $this->user = UserProfile::getUserProfile($this->userID); if ($this->user === null) { throw new IllegalLinkException(); } if ($this->user->userID != WCF::getUser()->userID && !WCF::getSession()->getPermission('user.profile.canViewUserProfile')) { throw new PermissionDeniedException(); } if (isset($_REQUEST['editOnInit'])) { $this->editOnInit = true; } $this->canonicalURL = LinkHandler::getInstance()->getLink('User', array('object' => $this->user)); }
/** * Renders a response. * * @param \wcf\data\comment\response\CommentResponse $response * @return string */ protected function renderResponse(CommentResponse $response) { $response = new StructuredCommentResponse($response); $response->setIsDeletable($this->commentProcessor->canDeleteResponse($response->getDecoratedObject())); $response->setIsEditable($this->commentProcessor->canEditResponse($response->getDecoratedObject())); // set user profile if ($response->userID) { $userProfile = UserProfile::getUserProfile($response->userID); $response->setUserProfile($userProfile); } // render response WCF::getTPL()->assign(array('responseList' => array($response), 'commentManager' => $this->commentProcessor)); return WCF::getTPL()->fetch('commentResponseList'); }