/** * Handle the request * * Check the format and show the user info * * @return void */ protected function handle() { parent::handle(); if (empty($this->profile_a) || empty($this->profile_b)) { $this->clientError(_('Two valid IDs or nick names must be supplied.'), 400); } $result = Subscription::exists($this->profile_a, $this->profile_b); switch ($this->format) { case 'xml': $this->initDocument('xml'); $this->element('friends', null, $result); $this->endDocument('xml'); break; case 'json': $this->initDocument('json'); print json_encode($result); $this->endDocument('json'); break; default: break; } }
public function onEndUnsubscribe($subscriber, $other) { if (!Subscription::exists($subscriber, $other)) { $notif = new QvitterNotification(); $notif->to_profile_id = $other->id; $notif->from_profile_id = $subscriber->id; $notif->ntype = 'follow'; $notif->delete(); } return true; }
function do_main() { $iSubscriptionType = SubscriptionEvent::subTypes('Folder'); if (!Subscription::exists($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType)) { $_SESSION['KTErrorMessage'][] = _kt("You were not subscribed to that folder"); } else { $oSubscription =& Subscription::getByIDs($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType); $res = $oSubscription->delete(); if ($res) { $_SESSION['KTInfoMessage'][] = _kt("You have been unsubscribed from this folder"); } else { $_SESSION['KTErrorMessage'][] = _kt("There was a problem unsubscribing you from this folder"); } } controllerRedirect('browse', 'fFolderId=' . $this->oFolder->getId()); exit(0); }
protected function _inScope($profile) { $scope = is_null($this->scope) ? self::defaultScope() : $this->getScope(); if ($scope === 0 && !$this->getProfile()->isPrivateStream()) { // Not scoping, so it is public. return !$this->isHiddenSpam($profile); } // If there's scope, anon cannot be in scope if (empty($profile)) { return false; } // Author is always in scope if ($this->profile_id == $profile->id) { return true; } // Only for users on this site if ($scope & Notice::SITE_SCOPE && !$profile->isLocal()) { return false; } // Only for users mentioned in the notice if ($scope & Notice::ADDRESSEE_SCOPE) { $reply = Reply::pkeyGet(array('notice_id' => $this->id, 'profile_id' => $profile->id)); if (!$reply instanceof Reply) { return false; } } // Only for members of the given group if ($scope & Notice::GROUP_SCOPE) { // XXX: just query for the single membership $groups = $this->getGroups(); $foundOne = false; foreach ($groups as $group) { if ($profile->isMember($group)) { $foundOne = true; break; } } if (!$foundOne) { return false; } } if ($scope & Notice::FOLLOWER_SCOPE || $this->getProfile()->isPrivateStream()) { if (!Subscription::exists($profile, $this->getProfile())) { return false; } } return !$this->isHiddenSpam($profile); }
/** * Checks if the user is subscribed to the document * * @author KnowledgeTree Team * @access public * @return bool $result TRUE if subscribed | FALSE if not */ public function isSubscribed() { $subscriptionType = SubscriptionEvent::subTypes('Document'); $user = $this->ktapi->get_user(); $document = $this->document; $result = Subscription::exists($user->getId(), $document->getId(), $subscriptionType); return $result; }
function block($other) { // Add a new block record // no blocking (and thus unsubbing from) yourself if ($this->id == $other->id) { common_log(LOG_WARNING, sprintf("Profile ID %d (%s) tried to block themself.", $this->id, $this->nickname)); return false; } $block = new Profile_block(); // Begin a transaction $block->query('BEGIN'); $block->blocker = $this->id; $block->blocked = $other->id; $result = $block->insert(); if (!$result) { common_log_db_error($block, 'INSERT', __FILE__); return false; } $self = $this->getProfile(); if (Subscription::exists($other, $self)) { Subscription::cancel($other, $self); } if (Subscription::exists($self, $other)) { Subscription::cancel($self, $other); } $block->query('COMMIT'); return true; }
/** * Is this profile subscribed to another profile? * * @param Profile $other * @return boolean */ function isSubscribed($other) { return Subscription::exists($this, $other); }
function canRead(Notice $notice) { if ($notice->scope & Notice::SITE_SCOPE) { $user = $this->getUser(); if (empty($user)) { return false; } } if ($notice->scope & Notice::ADDRESSEE_SCOPE) { $replies = $notice->getReplies(); if (!in_array($this->id, $replies)) { $groups = $notice->getGroups(); $foundOne = false; foreach ($groups as $group) { if ($this->isMember($group)) { $foundOne = true; break; } } if (!$foundOne) { return false; } } } if ($notice->scope & Notice::FOLLOWER_SCOPE) { $author = $notice->getProfile(); if (!Subscription::exists($this, $author)) { return false; } } return true; }
protected function _inScope($profile) { if (!is_null($this->scope)) { $scope = $this->scope; } else { $scope = self::defaultScope(); } // If there's no scope, anyone (even anon) is in scope. if ($scope == 0) { // Not private return !$this->isHiddenSpam($profile); } else { // Private, somehow // If there's scope, anon cannot be in scope if (empty($profile)) { return false; } // Author is always in scope if ($this->profile_id == $profile->id) { return true; } // Only for users on this site if ($scope & Notice::SITE_SCOPE) { $user = $profile->getUser(); if (empty($user)) { return false; } } // Only for users mentioned in the notice if ($scope & Notice::ADDRESSEE_SCOPE) { $repl = Reply::pkeyGet(array('notice_id' => $this->id, 'profile_id' => $profile->id)); if (empty($repl)) { return false; } } // Only for members of the given group if ($scope & Notice::GROUP_SCOPE) { // XXX: just query for the single membership $groups = $this->getGroups(); $foundOne = false; foreach ($groups as $group) { if ($profile->isMember($group)) { $foundOne = true; break; } } if (!$foundOne) { return false; } } // Only for followers of the author $author = null; if ($scope & Notice::FOLLOWER_SCOPE) { try { $author = $this->getProfile(); } catch (Exception $e) { return false; } if (!Subscription::exists($profile, $author)) { return false; } } return !$this->isHiddenSpam($profile); } }
/** * Determines whether the currently logged on user is subscribed * * @author KnowledgeTree Team * @access public * @return boolean */ public function isSubscribed() { $subscriptionType = SubscriptionEvent::subTypes('Folder'); $user = $this->ktapi->get_user(); $folder = $this->folder; $result = Subscription::exists($user->getId(), $folder->getId(), $subscriptionType); return $result; }
protected function _inScope($profile) { // If there's no scope, anyone (even anon) is in scope. if ($this->scope == 0) { return true; } // If there's scope, anon cannot be in scope if (empty($profile)) { return false; } // Author is always in scope if ($this->profile_id == $profile->id) { return true; } // Only for users on this site if ($this->scope & Notice::SITE_SCOPE) { $user = $profile->getUser(); if (empty($user)) { return false; } } // Only for users mentioned in the notice if ($this->scope & Notice::ADDRESSEE_SCOPE) { // XXX: just query for the single reply $replies = $this->getReplies(); if (!in_array($profile->id, $replies)) { return false; } } // Only for members of the given group if ($this->scope & Notice::GROUP_SCOPE) { // XXX: just query for the single membership $groups = $this->getGroups(); $foundOne = false; foreach ($groups as $group) { if ($profile->isMember($group)) { $foundOne = true; break; } } if (!$foundOne) { return false; } } // Only for followers of the author if ($this->scope & Notice::FOLLOWER_SCOPE) { $author = $this->getProfile(); if (!Subscription::exists($profile, $author)) { return false; } } return true; }