function prepare($args) { Action::prepare($args); // skip the ProfileAction code and replace it... $id = $this->arg('id'); $this->user = false; $this->profile = Profile::staticGet('id', $id); if (!$this->profile) { // TRANS: Error message displayed when referring to a user without a profile. $this->serverError(_m('User has no profile.')); return false; } $user = User::staticGet('id', $this->profile->id); if ($user) { // This is a local user -- send to their regular profile. $url = common_local_url('showstream', array('nickname' => $user->nickname)); common_redirect($url); return false; } $this->tag = $this->trimmed('tag'); $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1; common_set_returnto($this->selfUrl()); $p = Profile::current(); if (empty($this->tag)) { $stream = new ProfileNoticeStream($this->profile, $p); } else { $stream = new TaggedProfileNoticeStream($this->profile, $this->tag, $p); } $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); return true; }
/** * Prepare the object * * Check the input values and initialize the object. * Shows an error page on bad input. * * @param array $args $_REQUEST data * * @return boolean success flag */ function prepare($args) { parent::prepare($args); $nickname = common_canonical_nickname($this->arg('nickname')); $this->user = User::staticGet('nickname', $nickname); if (!$this->user) { // TRANS: Client error displayed when trying to reply to a non-exsting user. $this->clientError(_('No such user.')); return false; } $profile = $this->user->getProfile(); if (!$profile) { // TRANS: Error message displayed when referring to a user without a profile. $this->serverError(_('User has no profile.')); return false; } $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1; common_set_returnto($this->selfUrl()); $stream = new ReplyNoticeStream($this->user->id, Profile::current()); $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); if ($this->page > 1 && $this->notice->N == 0) { // TRANS: Server error when page not found (404) $this->serverError(_('No such page.'), $code = 404); } return true; }
function __construct($q, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } parent::__construct(new RawSearchNoticeStream($q), $profile); }
function __construct($plist, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } parent::__construct(new CachingNoticeStream(new RawPeopletagNoticeStream($plist), 'profile_list:notice_ids:' . $plist->id), $profile); }
function __construct($profile, $tag, $userProfile = -1) { if (is_int($userProfile) && $userProfile == -1) { $userProfile = Profile::current(); } parent::__construct(new CachingNoticeStream(new RawTaggedProfileNoticeStream($profile, $tag), 'profile:notice_ids_tagged:' . $profile->id . ':' . Cache::keyize($tag)), $userProfile); }
function getPeopletags() { $limit = PEOPLETAGS_PER_SECTION + 1; $offset = 0; $ptags = $this->profile->getOtherTags(Profile::current(), $offset, $limit); return $ptags; }
function __construct($tag, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } parent::__construct(new CachingNoticeStream(new RawSpamNoticeStream(), 'spam_score:notice_ids')); }
function __construct($profile, $userProfile = -1) { if (is_int($userProfile) && $userProfile == -1) { $userProfile = Profile::current(); } parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($profile), 'profile:notice_ids:' . $profile->id), $userProfile); }
function __construct($userId, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } parent::__construct(new CachingNoticeStream(new RawReplyNoticeStream($userId), 'reply:stream:' . $userId), $profile); }
function getTags() { $profile = Profile::current(); $keypart = sprintf('Inbox:notice_tag:%d:%d', $this->user->id, $profile->id); $tag = Memcached_DataObject::cacheGet($keypart); if ($tag === false) { $stream = new InboxNoticeStream($this->user, $profile); $ids = $stream->getNoticeIds(0, Inbox::MAX_NOTICES, null, null); if (empty($ids)) { $tag = array(); } else { $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff')); // @fixme should we use the cutoff too? Doesn't help with indexing per-user. $qry = 'SELECT notice_tag.tag, ' . $weightexpr . ' as weight ' . 'FROM notice_tag JOIN notice ' . 'ON notice_tag.notice_id = notice.id ' . 'WHERE notice.id in (' . implode(',', $ids) . ')' . 'GROUP BY notice_tag.tag ' . 'ORDER BY weight DESC '; $limit = TAGS_PER_SECTION; $offset = 0; if (common_config('db', 'type') == 'pgsql') { $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; } else { $qry .= ' LIMIT ' . $offset . ', ' . $limit; } $t = new Notice_tag(); $t->query($qry); $tag = array(); while ($t->fetch()) { $tag[] = clone $t; } } Memcached_DataObject::cacheSet($keypart, $tag, 3600); } return new ArrayWrapper($tag); }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); $convId = $this->trimmed('id'); if (empty($convId)) { // TRANS: Client exception thrown when no conversation ID is given. throw new ClientException(_('No conversation ID.')); } $this->conversation = Conversation::staticGet('id', $convId); if (empty($this->conversation)) { // TRANS: Client exception thrown when referring to a non-existing conversation ID (%d). $this->clientError(_('No conversation ID found'), 404); return false; } $profile = Profile::current(); $stream = new ConversationNoticeStream($convId, $profile); $notice = $stream->getNotices(($this->page - 1) * $this->count, $this->count, $this->since_id, $this->max_id); $this->notices = $notice->fetchAll(); $originalConversation = new Notice(); $originalConversation->whereAdd('conversation=' . $convId); $originalConversation->limit(1); $originalConversation->orderBy('created'); $originalConversation->find(); if ($originalConversation->fetch()) { $this->originalNotice = $originalConversation; } return true; }
function __construct($tag, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } parent::__construct(new CachingNoticeStream(new RawTagNoticeStream($tag), 'notice_tag:notice_ids:' . Cache::keyize($tag))); }
function __construct($user, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } parent::__construct(new CachingNoticeStream(new RawRepeatsOfMeNoticeStream($user), 'user:repeats_of_me:' . $user->id), $profile); }
function __construct($file, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } parent::__construct(new CachingNoticeStream(new RawFileNoticeStream($file), 'file:notice-ids:' . $this->url), $profile); }
function __construct($id, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } parent::__construct(new RawConversationNoticeStream($id), $profile); }
function __construct($group, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } parent::__construct(new CachingNoticeStream(new RawGroupNoticeStream($group), 'user_group:notice_ids:' . $group->id), $profile); }
/** * Constructor * * @param Profile $target Profile to get a stream for * @param Profile $scoped Currently scoped profile (if null, it is fetched) */ function __construct(Profile $target, Profile $scoped = null) { if ($scoped === null) { $scoped = Profile::current(); } // FIXME: we don't use CachingNoticeStream - but maybe we should? parent::__construct(new CachingNoticeStream(new RawInboxNoticeStream($target), 'profileall'), $scoped); }
function __construct(Notice $notice, Action $out = null, $profile = -1) { parent::__construct($notice, $out); if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } $this->userProfile = $profile; }
function __construct($upstream, $profile = -1) { parent::__construct($upstream); // Invalid but not null if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } $this->profile = $profile; }
/** * Constructor * * @param User $user User to get a stream for */ function __construct($user, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } // Note: we don't use CachingNoticeStream since RawInboxNoticeStream // uses Inbox::staticGet(), which is cached. parent::__construct(new RawInboxNoticeStream($user), $profile); }
function prepare($args) { parent::prepare($args); $stream = new ThreadingInboxNoticeStream($this->user, Profile::current()); $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); if ($this->page > 1 && $this->notice->N == 0) { // TRANS: Server error when page not found (404). $this->serverError(_('No such page.'), 404); } return true; }
function prepare($args) { parent::prepare($args); $p = Profile::current(); if (empty($this->tag)) { $stream = new ProfileNoticeStream($this->profile, $p); } else { $stream = new TaggedProfileNoticeStream($this->profile, $this->tag, $p); } $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); return true; }
function __construct($user_id, $own, $profile = -1) { $stream = new RawFaveNoticeStream($user_id, $own); if ($own) { $key = 'fave:ids_by_user_own:' . $user_id; } else { $key = 'fave:ids_by_user:' . $user_id; } if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } parent::__construct(new CachingNoticeStream($stream, $key), $profile); }
function prepare($args) { parent::prepare($args); if (common_config('singleuser', 'enabled')) { $tagger_arg = User::singleUserNickname(); } else { $tagger_arg = $this->arg('tagger'); } $tag_arg = $this->arg('tag'); $tagger = common_canonical_nickname($tagger_arg); $tag = common_canonical_tag($tag_arg); // Permanent redirect on non-canonical nickname if ($tagger_arg != $tagger || $tag_arg != $tag) { $args = array('tagger' => $nickname, 'tag' => $tag); if ($this->page != 1) { $args['page'] = $this->page; } common_redirect(common_local_url('showprofiletag', $args), 301); return false; } if (!$tagger) { // TRANS: Client error displayed when a tagger is expected but not provided. $this->clientError(_('No tagger.'), 404); return false; } $user = User::staticGet('nickname', $tagger); if (!$user) { // TRANS: Client error displayed trying to perform an action related to a non-existing user. $this->clientError(_('No such user.'), 404); return false; } $this->tagger = $user->getProfile(); $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag)); $current = common_current_user(); $can_see = !empty($this->peopletag) && (!$this->peopletag->private || $this->peopletag->private && $this->peopletag->tagger === $current->id); if (!$can_see) { // TRANS: Client error displayed trying to reference a non-existing list. $this->clientError(_('No such list.'), 404); return false; } $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1; $this->userProfile = Profile::current(); $stream = new PeopletagNoticeStream($this->peopletag, $this->userProfile); $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); if ($this->page > 1 && $this->notice->N == 0) { // TRANS: Server error when page not found (404). $this->serverError(_('No such page.'), $code = 404); } return true; }
/** * Take arguments for running, looks for an OAuth request, * and outputs basic auth header if needed * * @param array $args $_REQUEST args * * @return boolean success flag * */ protected function prepare(array $args = array()) { parent::prepare($args); // NOTE: $this->auth_user has to get set in prepare(), not handle(), // because subclasses do stuff with it in their prepares. // qvitterfix, accepts regular login session if (common_logged_in()) { $this->scoped = Profile::current(); $this->auth_user = $this->scoped->getUser(); if (!$this->auth_user->hasRight(Right::API)) { // TRANS: Authorization exception thrown when a user without API access tries to access the API. throw new AuthorizationException(_('Not allowed to use API.')); } $this->access = self::READ_WRITE; Event::handle('EndSetApiUser', array($this->auth_user)); } else { $oauthReq = $this->getOAuthRequest(); if (!$oauthReq) { if ($this->requiresAuth()) { $this->checkBasicAuthUser(true); } else { // Check to see if a basic auth user is there even // if one's not required $this->checkBasicAuthUser(false); } } else { $this->checkOAuthRequest($oauthReq); } } // NOTE: Make sure we're scoped properly based on the auths! if (isset($this->auth_user) && !empty($this->auth_user)) { $this->scoped = $this->auth_user->getProfile(); } else { $this->scoped = null; } // legacy user transferral // TODO: remove when sure no extended classes need it $this->user = $this->auth_user; // Reject API calls with the wrong access level if ($this->isReadOnly($args) == false) { if ($this->access != self::READ_WRITE) { // TRANS: Client error 401. $msg = _('API resource requires read-write access, ' . 'but you only have read access.'); $this->clientError($msg, 401); } } return true; }
function __construct($userId, $profile = -1) { if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } /* parent::__construct(new CachingNoticeStream(new RawReplyNoticeStream($userId), 'reply:stream:' . $userId), $profile);*/ //TODO: add cache parent::__construct(new RawCommentByUserNoticeStream($userId)); /* parent::__construct(new CachingNoticeStream(new RawCommentByUserNoticeStream($senderUserId), 'comment:stream:' . $userId), $profile);*/ }
/** * Take arguments for running, looks for an OAuth request, * and outputs basic auth header if needed * * @param array $args $_REQUEST args * * @return boolean success flag * */ protected function prepare(array $args = array()) { parent::prepare($args); // NOTE: $this->scoped and $this->auth_user has to get set in // prepare(), not handle(), as subclasses use them in prepares. // Allow regular login session if (common_logged_in()) { $this->scoped = Profile::current(); $this->auth_user = $this->scoped->getUser(); if (!$this->auth_user->hasRight(Right::API)) { // TRANS: Authorization exception thrown when a user without API access tries to access the API. throw new AuthorizationException(_('Not allowed to use API.')); } // Let's run this in the same way as if we've just authenticated the user (basic/oauth auth) Event::handle('EndSetApiUser', array($this->auth_user)); $this->access = self::READ_WRITE; } else { $oauthReq = $this->getOAuthRequest(); if ($oauthReq instanceof OAuthRequest) { $this->checkOAuthRequest($oauthReq); } else { // If not using OAuth, check if there is a basic auth // and require it if the current action requires it. $this->checkBasicAuthUser($this->requiresAuth()); } // NOTE: Make sure we're scoped properly based on the auths! if (isset($this->auth_user) && $this->auth_user instanceof User) { $this->scoped = $this->auth_user->getProfile(); } else { $this->scoped = null; } } // legacy user transferral // TODO: remove when sure no extended classes need it $this->user = $this->auth_user; // Reject API calls with the wrong access level if ($this->isReadOnly($args) == false) { if ($this->access != self::READ_WRITE) { // TRANS: Client error 401. $msg = _('API resource requires read-write access, ' . 'but you only have read access.'); $this->clientError($msg, 401); } } return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); $convId = $this->trimmed('id'); if (empty($convId)) { // TRANS: Client exception thrown when no conversation ID is given. throw new ClientException(_('No conversation ID.')); } $this->conversation = Conversation::staticGet('id', $convId); if (empty($this->conversation)) { // TRANS: Client exception thrown when referring to a non-existing conversation ID (%d). throw new ClientException(sprintf(_('No conversation with ID %d.'), $convId), 404); } $profile = Profile::current(); $stream = new ConversationNoticeStream($convId, $profile); $notice = $stream->getNotices(($this->page - 1) * $this->count, $this->count, $this->since_id, $this->max_id); $this->notices = $notice->fetchAll(); return true; }
function showSections() { // Show invite button, as long as site isn't closed, and // we have a logged in user. if (common_config('invite', 'enabled') && !common_config('site', 'closed') && common_logged_in()) { if (!common_config('site', 'private')) { $ibs = new InviteButtonSection($this, _m('BUTTON', 'Send invite')); } else { $ibs = new InviteButtonSection($this); } $ibs->show(); } $p = Profile::current(); if (!common_config('performance', 'high')) { $cloud = new PublicTagCloudSection($this); $cloud->show(); } $feat = new FeaturedUsersSection($this); $feat->show(); }
/** * Get IDs in a range * * @param int $offset Offset from start * @param int $limit Limit of number to get * @param int $since_id Since this notice * @param int $max_id Before this notice * * @return Array IDs found */ function getNotificationIds($offset, $limit, $since_id, $max_id) { $notification = new QvitterNotification(); $notification->selectAdd(); $notification->selectAdd('id'); $notification->whereAdd(sprintf('qvitternotification.to_profile_id = "%s"', $notification->escape($this->target->id))); $notification->whereAdd(sprintf('qvitternotification.created >= "%s"', $notification->escape($this->target->created))); // the user might have opted out from certain notification types $current_profile = Profile::current(); $disable_notify_replies_and_mentions = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_replies_and_mentions'); $disable_notify_favs = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_favs'); $disable_notify_repeats = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_repeats'); $disable_notify_follows = Profile_prefs::getConfigData($current_profile, 'qvitter', 'disable_notify_follows'); if ($disable_notify_replies_and_mentions == '1') { $notification->whereAdd('qvitternotification.ntype != "mention"'); $notification->whereAdd('qvitternotification.ntype != "reply"'); } if ($disable_notify_favs == '1') { $notification->whereAdd('qvitternotification.ntype != "like"'); } if ($disable_notify_repeats == '1') { $notification->whereAdd('qvitternotification.ntype != "repeat"'); } if ($disable_notify_follows == '1') { $notification->whereAdd('qvitternotification.ntype != "follow"'); } $notification->limit($offset, $limit); $notification->orderBy('qvitternotification.created DESC'); if ($since_id) { $notification->whereAdd(sprintf('qvitternotification.id > %d', $notification->escape($since_id))); } if ($max_id) { $notification->whereAdd(sprintf('qvitternotification.id <= %d', $notification->escape($max_id))); } if (!$notification->find()) { return array(); } $ids = $notification->fetchAll('id'); return $ids; }