diff --git a/actions/allrss.php b/actions/allrss.php index 4b6df25048..d7f11bb1eb 100644 --- a/actions/allrss.php +++ b/actions/allrss.php @@ -46,7 +46,7 @@ class AllrssAction extends TargetedRss10Action { protected function getNotices() { - $stream = new InboxNoticeStream($this->target); + $stream = new InboxNoticeStream($this->target, $this->scoped); return $stream->getNotices(0, $this->limit)->fetchAll(); } diff --git a/actions/noticesearch.php b/actions/noticesearch.php index fd8fdf68e5..d7cdeaacc6 100644 --- a/actions/noticesearch.php +++ b/actions/noticesearch.php @@ -65,8 +65,7 @@ class NoticesearchAction extends SearchAction if (!empty($this->q)) { - $profile = Profile::current(); - $stream = new SearchNoticeStream($this->q, $profile); + $stream = new SearchNoticeStream($this->q, $this->scoped); $page = $this->trimmed('page'); if (empty($page)) { diff --git a/actions/showgroup.php b/actions/showgroup.php index 46d0a227f5..8770e6cc8b 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -28,12 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once INSTALLDIR.'/lib/noticelist.php'; -require_once INSTALLDIR.'/lib/feedlist.php'; +if (!defined('GNUSOCIAL')) { exit(1); } /** * Group main page @@ -48,7 +43,6 @@ class ShowgroupAction extends GroupAction { /** page we're viewing. */ var $page = null; - var $userProfile = null; var $notice = null; /** @@ -97,14 +91,10 @@ class ShowgroupAction extends GroupAction $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - $this->userProfile = Profile::current(); - - $user = common_current_user(); - - if (!empty($user) && $user->streamModeOnly()) { - $stream = new GroupNoticeStream($this->group, $this->userProfile); + if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) { + $stream = new GroupNoticeStream($this->group, $this->scoped); } else { - $stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile); + $stream = new ThreadingGroupNoticeStream($this->group, $this->scoped); } $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, @@ -146,12 +136,10 @@ class ShowgroupAction extends GroupAction */ function showGroupNotices() { - $user = common_current_user(); - - if (!empty($user) && $user->streamModeOnly()) { + if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) { $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE)); } else { - $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile); + $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped); } $cnt = $nl->show(); diff --git a/classes/File.php b/classes/File.php index ef4b2cfb3c..d6dd78cbef 100644 --- a/classes/File.php +++ b/classes/File.php @@ -579,7 +579,9 @@ class File extends Managed_DataObject function stream($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0) { - $stream = new FileNoticeStream($this); + // FIXME: Try to get the Profile::current() here in some other way to avoid mixing + // the current session user with possibly background/queue processing. + $stream = new FileNoticeStream($this, Profile::current()); return $stream->getNotices($offset, $limit, $since_id, $max_id); } diff --git a/classes/Notice.php b/classes/Notice.php index 2bae300115..6f406472c7 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1280,9 +1280,9 @@ class Notice extends Managed_DataObject return $stream->getNotices($offset, $limit, $since_id, $max_id); } - static function conversationStream($id, $offset=0, $limit=20, $since_id=null, $max_id=null) + static function conversationStream($id, $offset=0, $limit=20, $since_id=null, $max_id=null, Profile $scoped=null) { - $stream = new ConversationNoticeStream($id); + $stream = new ConversationNoticeStream($id, $scoped); return $stream->getNotices($offset, $limit, $since_id, $max_id); } @@ -1300,8 +1300,9 @@ class Notice extends Managed_DataObject return false; } - $stream = new ConversationNoticeStream($this->conversation); - $notice = $stream->getNotices(/*offset*/ 1, /*limit*/ 1); + //FIXME: Get the Profile::current() stuff some other way + // to avoid confusion between queue processing and session. + $notice = self::conversationStream($this->conversation, 1, 1, null, null, Profile::current()); // if our "offset 1, limit 1" query got a result, return true else false return $notice->N > 0; diff --git a/classes/Notice_tag.php b/classes/Notice_tag.php index b864de8009..9d6bec6d2f 100644 --- a/classes/Notice_tag.php +++ b/classes/Notice_tag.php @@ -55,7 +55,9 @@ class Notice_tag extends Managed_DataObject static function getStream($tag, $offset=0, $limit=20, $sinceId=0, $maxId=0) { - $stream = new TagNoticeStream($tag); + // FIXME: Get the Profile::current value some other way + // to avoid confusino between queue processing and session. + $stream = new TagNoticeStream($tag, Profile::current()); return $stream; } diff --git a/classes/Profile.php b/classes/Profile.php index a5e0d092dc..36e91c3ad0 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -266,7 +266,9 @@ class Profile extends Managed_DataObject function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0) { - $stream = new TaggedProfileNoticeStream($this, $tag); + //FIXME: Get Profile::current() some other way to avoid possible + // confusion between current session profile and background processing. + $stream = new TaggedProfileNoticeStream($this, $tag, Profile::current()); return $stream->getNotices($offset, $limit, $since_id, $max_id); } diff --git a/classes/Profile_list.php b/classes/Profile_list.php index 000e10b41f..b60f4afffd 100644 --- a/classes/Profile_list.php +++ b/classes/Profile_list.php @@ -171,7 +171,9 @@ class Profile_list extends Managed_DataObject function getNotices($offset, $limit, $since_id=null, $max_id=null) { - $stream = new PeopletagNoticeStream($this); + // FIXME: Use something else than Profile::current() to avoid + // possible confusion between session user and queue processing. + $stream = new PeopletagNoticeStream($this, Profile::current()); return $stream->getNotices($offset, $limit, $since_id, $max_id); } diff --git a/classes/Reply.php b/classes/Reply.php index d3405e6581..018937ba6c 100644 --- a/classes/Reply.php +++ b/classes/Reply.php @@ -57,7 +57,9 @@ class Reply extends Managed_DataObject static function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0) { - $stream = new ReplyNoticeStream($user_id); + // FIXME: Use some other method to get Profile::current() in order + // to avoid confusion between background processing and session user. + $stream = new ReplyNoticeStream($user_id, Profile::current()); return $stream->getNotices($offset, $limit, $since_id, $max_id); } } diff --git a/classes/User.php b/classes/User.php index 40e1a1b644..12cc170f86 100644 --- a/classes/User.php +++ b/classes/User.php @@ -701,15 +701,18 @@ class User extends Managed_DataObject function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null) { - $stream = new RepeatedByMeNoticeStream($this); + // FIXME: Use another way to get Profile::current() since we + // want to avoid confusion between session user and queue processing. + $stream = new RepeatedByMeNoticeStream($this->getProfile(), Profile::current()); return $stream->getNotices($offset, $limit, $since_id, $max_id); } function repeatsOfMe($offset=0, $limit=20, $since_id=null, $max_id=null) { - $stream = new RepeatsOfMeNoticeStream($this); - + // FIXME: Use another way to get Profile::current() since we + // want to avoid confusion between session user and queue processing. + $stream = new RepeatsOfMeNoticeStream($this->getProfile(), Profile::current()); return $stream->getNotices($offset, $limit, $since_id, $max_id); } diff --git a/classes/User_group.php b/classes/User_group.php index ecec1ee663..8f736de6d0 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -153,7 +153,9 @@ class User_group extends Managed_DataObject function getNotices($offset, $limit, $since_id=null, $max_id=null) { - $stream = new GroupNoticeStream($this); + // FIXME: Get the Profile::current() some other way, to avoid + // possible confusion between current session and queue process. + $stream = new GroupNoticeStream($this, Profile::current()); return $stream->getNotices($offset, $limit, $since_id, $max_id); } diff --git a/lib/conversationnoticestream.php b/lib/conversationnoticestream.php index 21b2d7f0be..bcb16c2d4b 100644 --- a/lib/conversationnoticestream.php +++ b/lib/conversationnoticestream.php @@ -42,14 +42,10 @@ if (!defined('GNUSOCIAL')) { exit(1); } */ class ConversationNoticeStream extends ScopingNoticeStream { - function __construct($id, $profile = -1) + function __construct($id, Profile $scoped=null) { - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } - parent::__construct(new RawConversationNoticeStream($id), - $profile); + $scoped); } } diff --git a/lib/filenoticestream.php b/lib/filenoticestream.php index f7bca1ed68..49b93732fb 100644 --- a/lib/filenoticestream.php +++ b/lib/filenoticestream.php @@ -28,22 +28,15 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } class FileNoticeStream extends ScopingNoticeStream { - function __construct($file, $profile = -1) + function __construct($file, Profile $scoped=null) { - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } parent::__construct(new CachingNoticeStream(new RawFileNoticeStream($file), 'file:notice-ids:'.$file->id), - $profile); + $scoped); } } diff --git a/lib/groupnoticestream.php b/lib/groupnoticestream.php index 723f064cb3..2d6e7b37cb 100644 --- a/lib/groupnoticestream.php +++ b/lib/groupnoticestream.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Stream of notices for a group @@ -47,19 +43,14 @@ if (!defined('STATUSNET')) { class GroupNoticeStream extends ScopingNoticeStream { var $group; - var $userProfile; - function __construct($group, $profile = -1) + function __construct($group, Profile $scoped=null) { - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } $this->group = $group; - $this->userProfile = $profile; parent::__construct(new CachingNoticeStream(new RawGroupNoticeStream($group), 'user_group:notice_ids:' . $group->id), - $profile); + $scoped); } function getNoticeIds($offset, $limit, $since_id, $max_id) @@ -83,7 +74,7 @@ class GroupNoticeStream extends ScopingNoticeStream function impossibleStream() { if ($this->group->force_scope && - (empty($this->userProfile) || !$this->userProfile->isMember($this->group))) { + (!$this->scoped instanceof Profile || $this->scoped->isMember($this->group))) { return true; } diff --git a/lib/inboxnoticestream.php b/lib/inboxnoticestream.php index ccf0f460c9..2b19461c57 100644 --- a/lib/inboxnoticestream.php +++ b/lib/inboxnoticestream.php @@ -54,9 +54,6 @@ class InboxNoticeStream extends ScopingNoticeStream */ 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); } diff --git a/lib/inboxtagcloudsection.php b/lib/inboxtagcloudsection.php index d19f76366d..4268ee4854 100644 --- a/lib/inboxtagcloudsection.php +++ b/lib/inboxtagcloudsection.php @@ -27,9 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Personal tag cloud section @@ -60,9 +58,9 @@ class InboxTagCloudSection extends TagCloudSection function getTags() { - $profile = Profile::current(); - - $stream = new InboxNoticeStream($this->target, $profile); + // FIXME: Get the Profile::current() value some other way + // to avoid confusion between background stuff and session. + $stream = new InboxNoticeStream($this->target, Profile::current()); $ids = $stream->getNoticeIds(0, self::MAX_NOTICES, null, null); diff --git a/lib/peopletagnoticestream.php b/lib/peopletagnoticestream.php index 4422261ae9..cc453bf1f8 100644 --- a/lib/peopletagnoticestream.php +++ b/lib/peopletagnoticestream.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Stream of notices for a list @@ -47,14 +43,11 @@ if (!defined('STATUSNET')) { */ class PeopletagNoticeStream extends ScopingNoticeStream { - function __construct($plist, $profile = -1) + function __construct($plist, Profile $scoped=null) { - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } parent::__construct(new CachingNoticeStream(new RawPeopletagNoticeStream($plist), 'profile_list:notice_ids:' . $plist->id), - $profile); + $scoped); } } diff --git a/lib/profilenoticestream.php b/lib/profilenoticestream.php index 7ff4163fcb..bfe49efea5 100644 --- a/lib/profilenoticestream.php +++ b/lib/profilenoticestream.php @@ -43,19 +43,14 @@ if (!defined('GNUSOCIAL')) { exit(1); } class ProfileNoticeStream extends ScopingNoticeStream { - var $streamProfile; - var $userProfile; + protected $target; - function __construct($profile, $userProfile = -1) + function __construct(Profile $target, Profile $scoped=null) { - if (is_int($userProfile) && $userProfile == -1) { - $userProfile = Profile::current(); - } - $this->streamProfile = $profile; - $this->userProfile = $userProfile; - parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($profile), - 'profile:notice_ids:' . $profile->id), - $userProfile); + $this->target = $target; + parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($target), + 'profile:notice_ids:' . $target->getID()), + $scoped); } function getNoticeIds($offset, $limit, $since_id=null, $max_id=null) @@ -70,7 +65,7 @@ class ProfileNoticeStream extends ScopingNoticeStream function getNotices($offset, $limit, $since_id=null, $max_id=null) { if ($this->impossibleStream()) { - throw new PrivateStreamException($this->streamProfile, $this->userProfile); + throw new PrivateStreamException($this->target, $this->scoped); } else { return parent::getNotices($offset, $limit, $since_id, $max_id); } @@ -78,7 +73,7 @@ class ProfileNoticeStream extends ScopingNoticeStream function impossibleStream() { - if (!$this->streamProfile->readableBy($this->userProfile)) { + if (!$this->target->readableBy($this->scoped)) { // cannot read because it's a private stream and either noone's logged in or they are not subscribers return true; } @@ -86,8 +81,13 @@ class ProfileNoticeStream extends ScopingNoticeStream // If it's a spammy stream, and no user or not a moderator if (common_config('notice', 'hidespam')) { - if ($this->streamProfile->hasRole(Profile_role::SILENCED) && - (empty($this->userProfile) || (($this->userProfile->id !== $this->streamProfile->id) && !$this->userProfile->hasRight(Right::REVIEWSPAM)))) { + // if this is a silenced user + if ($this->target->hasRole(Profile_role::SILENCED) + // and we are either not logged in + && (!$this->scoped instanceof Profile + // or if we are, we are not logged in as the target, and we don't have right to review spam + || (!$this->scoped->sameAs($this->target) && !$this->scoped->hasRight(Right::REVIEWSPAM)) + )) { return true; } } @@ -109,20 +109,20 @@ class ProfileNoticeStream extends ScopingNoticeStream class RawProfileNoticeStream extends NoticeStream { - protected $profile; + protected $target; protected $selectVerbs = array(); // select all verbs - function __construct($profile) + function __construct(Profile $target) { parent::__construct(); - $this->profile = $profile; + $this->target = $target; } function getNoticeIds($offset, $limit, $since_id, $max_id) { $notice = new Notice(); - $notice->profile_id = $this->profile->id; + $notice->profile_id = $this->target->getID(); $notice->selectAdd(); $notice->selectAdd('id'); diff --git a/lib/publicnoticestream.php b/lib/publicnoticestream.php index 4a16cbd235..1dd59059fd 100644 --- a/lib/publicnoticestream.php +++ b/lib/publicnoticestream.php @@ -43,11 +43,11 @@ if (!defined('GNUSOCIAL')) { exit(1); } class PublicNoticeStream extends ScopingNoticeStream { - function __construct($profile=null) + function __construct(Profile $scoped=null) { parent::__construct(new CachingNoticeStream(new RawPublicNoticeStream(), 'public'), - $profile); + $scoped); } } diff --git a/lib/replynoticestream.php b/lib/replynoticestream.php index 9eb188d54d..d6b2882193 100644 --- a/lib/replynoticestream.php +++ b/lib/replynoticestream.php @@ -43,14 +43,11 @@ if (!defined('GNUSOCIAL')) { exit(1); } class ReplyNoticeStream extends ScopingNoticeStream { - function __construct($userId, $profile=-1) + function __construct($userId, Profile $scoped=null) { - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } parent::__construct(new CachingNoticeStream(new RawReplyNoticeStream($userId), 'reply:stream:' . $userId), - $profile); + $scoped); } } diff --git a/lib/scopingnoticestream.php b/lib/scopingnoticestream.php index c1651d5a30..84af75948d 100644 --- a/lib/scopingnoticestream.php +++ b/lib/scopingnoticestream.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Class comment @@ -49,16 +45,12 @@ class ScopingNoticeStream extends FilteringNoticeStream { protected $profile; - function __construct($upstream, $profile = -1) + function __construct(NoticeStream $upstream, Profile $scoped=null) { parent::__construct($upstream); - // Invalid but not null - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } - - $this->profile = $profile; + $this->profile = $scoped; // legacy + $this->scoped = $scoped; } /** @@ -71,7 +63,7 @@ class ScopingNoticeStream extends FilteringNoticeStream function filter($notice) { - return $notice->inScope($this->profile); + return $notice->inScope($this->scoped); } function prefill($notices) diff --git a/lib/searchnoticestream.php b/lib/searchnoticestream.php index 6593a4c860..9c31a709c6 100644 --- a/lib/searchnoticestream.php +++ b/lib/searchnoticestream.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Stream of notice search results @@ -47,13 +43,9 @@ if (!defined('STATUSNET')) { class SearchNoticeStream extends ScopingNoticeStream { - function __construct($q, $profile = -1) + function __construct($q, Profile $scoped=null) { - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } - - parent::__construct(new RawSearchNoticeStream($q), $profile); + parent::__construct(new RawSearchNoticeStream($q), $scoped); } } @@ -89,4 +81,4 @@ class RawSearchNoticeStream extends NoticeStream return $ids; } -} \ No newline at end of file +} diff --git a/lib/taggedprofilenoticestream.php b/lib/taggedprofilenoticestream.php index eec20cd8c6..f6fb476ff1 100644 --- a/lib/taggedprofilenoticestream.php +++ b/lib/taggedprofilenoticestream.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Stream of notices with a given profile and tag @@ -47,14 +43,11 @@ if (!defined('STATUSNET')) { class TaggedProfileNoticeStream extends ScopingNoticeStream { - function __construct($profile, $tag, $userProfile=-1) + function __construct($profile, $tag, Profile $scoped=null) { - 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); + $scoped); } } diff --git a/lib/tagnoticestream.php b/lib/tagnoticestream.php index 28f5d0e824..5a99a1aa68 100644 --- a/lib/tagnoticestream.php +++ b/lib/tagnoticestream.php @@ -43,13 +43,11 @@ if (!defined('GNUSOCIAL')) { exit(1); } class TagNoticeStream extends ScopingNoticeStream { - function __construct($tag, $profile = -1) + function __construct($tag, Profile $scoped=null) { - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } parent::__construct(new CachingNoticeStream(new RawTagNoticeStream($tag), - 'notice_tag:notice_ids:' . Cache::keyize($tag))); + 'notice_tag:notice_ids:' . Cache::keyize($tag)), + $scoped); } } diff --git a/lib/threadinggroupnoticestream.php b/lib/threadinggroupnoticestream.php index b026ee4714..bc42a6247a 100644 --- a/lib/threadinggroupnoticestream.php +++ b/lib/threadinggroupnoticestream.php @@ -4,8 +4,8 @@ if (!defined('GNUSOCIAL')) { exit(1); } class ThreadingGroupNoticeStream extends ThreadingNoticeStream { - function __construct($group, $profile) + function __construct($group, Profile $scoped=null) { - parent::__construct(new GroupNoticeStream($group, $profile)); + parent::__construct(new GroupNoticeStream($group, $scoped)); } } diff --git a/plugins/ActivitySpam/actions/spam.php b/plugins/ActivitySpam/actions/spam.php index a66b73a829..00a1e0b8a1 100644 --- a/plugins/ActivitySpam/actions/spam.php +++ b/plugins/ActivitySpam/actions/spam.php @@ -74,19 +74,17 @@ class SpamAction extends Action // User must be logged in. - $user = common_current_user(); - - if (empty($user)) { + if (!$this->scoped instanceof Profile) { throw new ClientException(_("You must be logged in to review."), 403); } // User must have the right to review spam - if (!$user->hasRight(ActivitySpamPlugin::REVIEWSPAM)) { + if (!$this->scoped->hasRight(ActivitySpamPlugin::REVIEWSPAM)) { throw new ClientException(_('You cannot review spam on this site.'), 403); } - $stream = new SpamNoticeStream($user->getProfile()); + $stream = new SpamNoticeStream($this->scoped); $this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); diff --git a/plugins/ActivitySpam/lib/spamnoticestream.php b/plugins/ActivitySpam/lib/spamnoticestream.php index ffb8d08025..d19814509c 100644 --- a/plugins/ActivitySpam/lib/spamnoticestream.php +++ b/plugins/ActivitySpam/lib/spamnoticestream.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Spam notice stream @@ -47,13 +43,10 @@ if (!defined('STATUSNET')) { class SpamNoticeStream extends ScopingNoticeStream { - function __construct($tag, $profile = -1) + function __construct(Profile $scoped=null) { - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } - parent::__construct(new CachingNoticeStream(new RawSpamNoticeStream(), - 'spam_score:notice_ids')); + parent::__construct(new CachingNoticeStream(new RawSpamNoticeStream(), 'spam_score:notice_ids'), + $scoped); } } diff --git a/plugins/Bookmark/lib/bookmarksnoticestream.php b/plugins/Bookmark/lib/bookmarksnoticestream.php index a3ac0359d7..f5d384c2e5 100644 --- a/plugins/Bookmark/lib/bookmarksnoticestream.php +++ b/plugins/Bookmark/lib/bookmarksnoticestream.php @@ -1,5 +1,7 @@ getProfile(); - - if (empty($profile)) { + try { + $profile = $user->getProfile(); + } catch (UserNoProfileException $e) { common_log(LOG_WARNING, sprintf('Not sending email summary for user %s; no profile.', $user_id)); return true; } // An InboxNoticeStream for a certain user, scoped to its own view - $stream = new InboxNoticeStream($profile); + $stream = new InboxNoticeStream($profile, $profile); $notice = $stream->getNotices(0, self::MAX_NOTICES, $since_id); diff --git a/plugins/Event/lib/eventsnoticestream.php b/plugins/Event/lib/eventsnoticestream.php index c0d91060be..3dd1a81bd1 100644 --- a/plugins/Event/lib/eventsnoticestream.php +++ b/plugins/Event/lib/eventsnoticestream.php @@ -1,5 +1,7 @@ scoped); $notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE+1); $nl = new NoticeList($notice, $this); diff --git a/plugins/Favorite/actions/showfavorites.php b/plugins/Favorite/actions/showfavorites.php index cba29063c2..ea1169957c 100644 --- a/plugins/Favorite/actions/showfavorites.php +++ b/plugins/Favorite/actions/showfavorites.php @@ -57,8 +57,7 @@ class ShowfavoritesAction extends ShowstreamAction public function getStream() { - $own = $this->scoped instanceof Profile ? $this->scoped->sameAs($this->getTarget()) : false; - return new FaveNoticeStream($this->getTarget()->getID(), $own); + return new FaveNoticeStream($this->getTarget(), $this->scoped); } function getFeeds() diff --git a/plugins/Favorite/classes/Fave.php b/plugins/Favorite/classes/Fave.php index 826d34a36c..864a0fc37b 100644 --- a/plugins/Favorite/classes/Fave.php +++ b/plugins/Favorite/classes/Fave.php @@ -152,16 +152,22 @@ class Fave extends Managed_DataObject return $result; } + // FIXME: Instead of $own, send the scoped Profile so we can pass it along directly to FaveNoticeStream + // and preferrably we should get a Profile instead of $user_id static function stream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $own=false, $since_id=0, $max_id=0) { - $stream = new FaveNoticeStream($user_id, $own); + $target = Profile::getByID($user_id); + $stream = new FaveNoticeStream($target, ($own ? $target : null)); return $stream->getNotices($offset, $limit, $since_id, $max_id); } + // FIXME: Instead of $own, send the scoped Profile so we can pass it along directly to FaveNoticeStream + // and preferrably we should get a Profile instead of $user_id function idStream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $own=false, $since_id=0, $max_id=0) { - $stream = new FaveNoticeStream($user_id, $own); + $target = Profile::getByID($user_id); + $stream = new FaveNoticeStream($target, ($own ? $target : null)); return $stream->getNoticeIds($offset, $limit, $since_id, $max_id); } diff --git a/plugins/Favorite/lib/favenoticestream.php b/plugins/Favorite/lib/favenoticestream.php index d10272ac91..10a3ec83bd 100644 --- a/plugins/Favorite/lib/favenoticestream.php +++ b/plugins/Favorite/lib/favenoticestream.php @@ -42,19 +42,15 @@ if (!defined('GNUSOCIAL')) { exit(1); } */ class FaveNoticeStream extends ScopingNoticeStream { - function __construct($user_id, $own, $profile = -1) + function __construct(Profile $target, Profile $scoped=null) { - $stream = new RawFaveNoticeStream($user_id, $own); - if ($own) { + $stream = new RawFaveNoticeStream($target, $scoped); + if ($target->sameAs($scoped)) { $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); + parent::__construct(new CachingNoticeStream($stream, $key), $scoped); } } @@ -75,12 +71,12 @@ class RawFaveNoticeStream extends NoticeStream protected $selectVerbs = array(); - function __construct($user_id, $own) + function __construct(Profile $target, Profile $scoped=null) { parent::__construct(); - $this->user_id = $user_id; - $this->own = $own; + $this->user_id = $target->getID(); + $this->own = $target->sameAs($scoped); } /** diff --git a/plugins/Favorite/lib/popularnoticestream.php b/plugins/Favorite/lib/popularnoticestream.php index eeba541238..6ef564d32f 100644 --- a/plugins/Favorite/lib/popularnoticestream.php +++ b/plugins/Favorite/lib/popularnoticestream.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Stream of notices sorted by popularity @@ -47,12 +43,12 @@ if (!defined('STATUSNET')) { class PopularNoticeStream extends ScopingNoticeStream { - function __construct($profile=null) + function __construct(Profile $scoped=null) { parent::__construct(new CachingNoticeStream(new RawPopularNoticeStream(), 'popular', false), - $profile); + $scoped); } } diff --git a/plugins/Mapstraction/actions/allmap.php b/plugins/Mapstraction/actions/allmap.php index 21bdf62eaa..77e722e3ef 100644 --- a/plugins/Mapstraction/actions/allmap.php +++ b/plugins/Mapstraction/actions/allmap.php @@ -27,9 +27,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Show a map of user's notices diff --git a/plugins/Share/lib/repeatedbymenoticestream.php b/plugins/Share/lib/repeatedbymenoticestream.php index 4e3e34162b..ecbbefb1cc 100644 --- a/plugins/Share/lib/repeatedbymenoticestream.php +++ b/plugins/Share/lib/repeatedbymenoticestream.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Stream of notices repeated by me @@ -47,14 +43,11 @@ if (!defined('STATUSNET')) { class RepeatedByMeNoticeStream extends ScopingNoticeStream { - function __construct($user, $profile = -1) + function __construct(Profile $target, Profile $scoped=null) { - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } - parent::__construct(new CachingNoticeStream(new RawRepeatedByMeNoticeStream($user), - 'user:repeated_by_me:'.$user->id), - $profile); + parent::__construct(new CachingNoticeStream(new RawRepeatedByMeNoticeStream($target), + 'user:repeated_by_me:'.$target->getID()), + $scoped); } } @@ -71,11 +64,11 @@ class RepeatedByMeNoticeStream extends ScopingNoticeStream class RawRepeatedByMeNoticeStream extends NoticeStream { - protected $user; + protected $target; - function __construct($user) + function __construct(Profile $target) { - $this->user = $user; + $this->target = $target; } function getNoticeIds($offset, $limit, $since_id, $max_id) @@ -85,7 +78,7 @@ class RawRepeatedByMeNoticeStream extends NoticeStream $notice->selectAdd(); // clears it $notice->selectAdd('id'); - $notice->profile_id = $this->user->id; + $notice->profile_id = $this->target->getID(); $notice->whereAdd('repeat_of IS NOT NULL'); $notice->orderBy('created DESC, id DESC'); @@ -110,4 +103,4 @@ class RawRepeatedByMeNoticeStream extends NoticeStream return $ids; } -} \ No newline at end of file +} diff --git a/plugins/Share/lib/repeatsofmenoticestream.php b/plugins/Share/lib/repeatsofmenoticestream.php index ec80d84314..672e3dd973 100644 --- a/plugins/Share/lib/repeatsofmenoticestream.php +++ b/plugins/Share/lib/repeatsofmenoticestream.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Stream of notices that are repeats of mine @@ -47,14 +43,11 @@ if (!defined('STATUSNET')) { class RepeatsOfMeNoticeStream extends ScopingNoticeStream { - function __construct($user, $profile=-1) + function __construct(Profile $target, Profile $scoped=null) { - if (is_int($profile) && $profile == -1) { - $profile = Profile::current(); - } - parent::__construct(new CachingNoticeStream(new RawRepeatsOfMeNoticeStream($user), - 'user:repeats_of_me:'.$user->id), - $profile); + parent::__construct(new CachingNoticeStream(new RawRepeatsOfMeNoticeStream($target), + 'user:repeats_of_me:'.$target->getID()), + $scoped); } } @@ -70,11 +63,11 @@ class RepeatsOfMeNoticeStream extends ScopingNoticeStream */ class RawRepeatsOfMeNoticeStream extends NoticeStream { - protected $user; + protected $target; - function __construct($user) + function __construct(Profile $target) { - $this->user = $user; + $this->target = $target; } function getNoticeIds($offset, $limit, $since_id, $max_id) @@ -82,7 +75,7 @@ class RawRepeatsOfMeNoticeStream extends NoticeStream $qry = 'SELECT DISTINCT original.id AS id ' . 'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' . - 'WHERE original.profile_id = ' . $this->user->id . ' '; + 'WHERE original.profile_id = ' . $this->target->getID() . ' '; $since = Notice::whereSinceId($since_id, 'original.id', 'original.created'); if ($since) {