/** * @see EventListener::execute() */ public function execute($eventObj, $className, $eventName) { if (!USERGUESTBOOK_SHOWINSIDEBAR) { return; } if (!WCF::getUser()->getPermission('user.guestbook.canRead')) { return; } if (empty($eventObj->postList->posts)) { return; } $seen = $ret = array(); $ret = WCF::getTPL()->get('additionalSidebarUserContacts'); $link = '<a href="index.php?page=UserGuestbook&userID=%1$d' . SID_ARG_2ND . '"><img src="' . RELATIVE_WCF_DIR . 'icon/guestbookS.png" alt="" title="%2$s" /></a>'; $curUserID = WCF::getUser()->userID; $curUserCanUse = WCF::getUser()->getPermission('user.guestbook.canUseOwn'); $gbEnableOption = 'userOption' . User::getUserOptionID('userGuestbook_enable'); require_once WCF_DIR . 'lib/data/user/UserProfile.class.php'; foreach ($eventObj->postList->posts as $post) { if ($post->userID) { if ($curUserID == $post->userID && !$curUserCanUse) { continue; } else { if (!$post->{$gbEnableOption}) { continue; } else { if (array_key_exists($post->userID, $seen)) { if (!empty($seen[$post->userID])) { if (isset($ret[$post->postID])) { $ret[$post->postID] .= ' ' . $seen[$post->userID]; } else { $ret[$post->postID] = $seen[$post->userID]; } } } else { $add = ''; $user = new UserProfile($post->userID, null, null, null); if ($user->getPermission('user.guestbook.canUseOwn')) { $username = StringUtil::encodeHTML($user->username); $title = WCF::getLanguage()->get('wcf.user.guestbook.title', array('$user->username' => $username)); $add = sprintf($link, $post->userID, $title); if (isset($ret[$post->postID])) { $ret[$post->postID] .= ' ' . $add; } else { $ret[$post->postID] = $add; } } $seen[$post->userID] = $add; } } } } } if (count($ret)) { WCF::getTPL()->assign('additionalSidebarUserContacts', $ret); } }
/** * Checks the given recipients. */ protected function validateRecipients($recipients, $field = 'recipients') { // explode multiple recipients to an array $recipientArray = explode(',', $recipients); $result = array(); $error = array(); // loop through recipients and check their settings foreach ($recipientArray as $recipient) { $recipient = StringUtil::trim($recipient); if (empty($recipient)) { continue; } try { // get recipient's profile $user = new UserProfile(null, null, $recipient); if (!$user->userID) { throw new UserInputException('recipient', 'notFound'); } $reply = $this->pm && $this->reply && $this->pm->userID == $user->userID && !$this->pm->isReplied; // check recipient's settings and permissions // can use pm if (!$user->getPermission('user.pm.canUsePm')) { throw new UserInputException('recipient', 'canNotUsePm'); } if (!$reply) { // accepts messages if (!$user->acceptPm) { throw new UserInputException('recipient', 'doesNotAcceptPm'); } // recipient only accept private messages from buddies if ($user->onlyBuddyCanPm && !$user->buddy && $user->userID != WCF::getUser()->userID && !WCF::getUser()->getPermission('user.profile.blacklist.canNotBeIgnored')) { throw new UserInputException('recipient', 'onlyAcceptsPmFromBuddies'); } } // active user is ignored by recipient if ($user->ignoredUser) { throw new UserInputException('recipient', 'ignoresYou'); } // check recipient's mailbox quota if ($user->pmTotalCount >= $user->getPermission('user.pm.maxPm') && !WCF::getUser()->getPermission('user.profile.blacklist.canNotBeIgnored')) { throw new UserInputException('recipient', 'recipientsMailboxIsFull'); } // no error $result[] = array('userID' => $user->userID, 'username' => $user->username); if ($user->emailOnPm) { $this->notificationRecipients[$user->userID] = $user; } } catch (UserInputException $e) { $error[] = array('type' => $e->getType(), 'username' => $recipient); } } if (count($error)) { throw new UserInputException($field, $error); } return $result; }
/** * @see EventListener::execute() */ public function execute($eventObj, $className, $eventName) { if (!USERWANTEDPOSTER_SHOWINSIDEBAR) { return; } if (!WCF::getUser()->getPermission('user.wantedPoster.canViewWantedPoster')) { return; } if (empty($eventObj->postList->posts)) { return; } $seen = $wpUserIDs = $postUserIDs = array(); $uwpIDinStr = ''; $ret = WCF::getTPL()->get('additionalSidebarUserContacts'); $link = '<a href="index.php?page=UserWantedPoster&userID=%1$d"><img src="' . RELATIVE_WCF_DIR . 'icon/userWantedPosterS.png" alt="" title="%2$s" /></a>'; $curUserID = WCF::getUser()->userID; $curUserCanUse = WCF::getUser()->getPermission('user.wantedPoster.canUseWantedPoster'); require_once WCF_DIR . 'lib/data/user/UserProfile.class.php'; foreach ($eventObj->postList->posts as $post) { if ($post->userID && !in_array($post->userID, $postUserIDs)) { $postUserIDs[] = $post->userID; } } $uwpIDinStr = implode(',', $postUserIDs); if (empty($uwpIDinStr) || $uwpIDinStr == ',') { return; } $sql = "SELECT userID" . "\n FROM wcf" . WCF_N . "_user_wanted_poster" . "\n WHERE userID IN (" . $uwpIDinStr . ")"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $wpUserIDs[] = $row['userID']; } if (!count($wpUserIDs)) { return; } foreach ($eventObj->postList->posts as $post) { if ($post->userID) { if ($curUserID == $post->userID && !$curUserCanUse) { continue; } else { if (!in_array($post->userID, $wpUserIDs, true)) { continue; } else { if (array_key_exists($post->userID, $seen)) { if (!empty($seen[$post->userID])) { if (isset($ret[$post->postID])) { $ret[$post->postID] .= ' ' . $seen[$post->userID]; } else { $ret[$post->postID] = $seen[$post->userID]; } } } else { $add = ''; $user = new UserProfile($post->userID, null, null, null); if ($user->getPermission('user.wantedPoster.canUseWantedPoster')) { $username = StringUtil::encodeHTML($user->username); $title = WCF::getLanguage()->get('wcf.user.wantedPoster.title', array('$user->username' => $username)); $add = sprintf($link, $post->userID, $title); if (isset($ret[$post->postID])) { $ret[$post->postID] .= ' ' . $add; } else { $ret[$post->postID] = $add; } } $seen[$post->userID] = $add; } } } } } if (count($ret)) { WCF::getTPL()->assign('additionalSidebarUserContacts', $ret); } }