From a5d27d9ce700d24d8fd2493a4b988cfe22d247e6 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 28 Jan 2015 20:25:39 +0100 Subject: [PATCH] /main/all will give a network-wide public stream Qvitter had implemented this as a "PublicAndExternal" stream, but I figured we might as well put it into the GNU social core. --- actions/networkpublic.php | 66 ++++++++++++++++++++++ actions/public.php | 42 ++------------ classes/Notice.php | 10 ++-- lib/networkpublicnoticestream.php | 66 ++++++++++++++++++++++ lib/publicnoticestream.php | 9 +-- lib/router.php | 6 +- lib/threadingnetworkpublicnoticestream.php | 11 ++++ lib/threadingpublicnoticestream.php | 11 ++++ 8 files changed, 169 insertions(+), 52 deletions(-) create mode 100644 actions/networkpublic.php create mode 100644 lib/networkpublicnoticestream.php create mode 100644 lib/threadingnetworkpublicnoticestream.php create mode 100644 lib/threadingpublicnoticestream.php diff --git a/actions/networkpublic.php b/actions/networkpublic.php new file mode 100644 index 0000000000..4bba2f7f47 --- /dev/null +++ b/actions/networkpublic.php @@ -0,0 +1,66 @@ +scoped instanceof Profile && common_config('public', 'localonly')) { + $this->serverError(_('Network wide public feed is not permitted without authorization'), 403); + } + if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) { + $this->stream = new NetworkPublicNoticeStream($this->scoped); + } else { + $this->stream = new ThreadingNetworkPublicNoticeStream($this->scoped); + } + } + + function title() + { + if ($this->page > 1) { + // TRANS: Title for all public timeline pages but the first. + // TRANS: %d is the page number. + return sprintf(_('Network public timeline, page %d'), $this->page); + } else { + // TRANS: Title for the first public timeline page. + return _('Network public timeline'); + } + } + + function extraHead() + { + // the PublicAction has some XRDS stuff that might be unique to the non-network public feed + // FIXME: Solve this with a call that doesn't rely on parent:: and is unique for each class. + ManagedAction::extraHead(); + } + + 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, + // TRANS: Button text for inviting more users to the StatusNet instance. + // TRANS: Less business/enterprise-oriented language for public sites. + _m('BUTTON', 'Send invite') + ); + } else { + $ibs = new InviteButtonSection($this); + } + $ibs->show(); + } + + // Network public tag cloud? + } + + /** + * FIXME: Network public feed! Get a template from PublicAction + */ + function getFeeds() + { + return array(); + } +} diff --git a/actions/public.php b/actions/public.php index 52bab072ae..4f91b77e1e 100644 --- a/actions/public.php +++ b/actions/public.php @@ -45,7 +45,7 @@ define('MAX_PUBLIC_PAGE', 100); * @see PublicrssAction * @see PublicxrdsAction */ -class PublicAction extends Action +class PublicAction extends ManagedAction { /** * page of the stream we're on; default = 1 @@ -61,16 +61,8 @@ class PublicAction extends Action return true; } - /** - * Read and validate arguments - * - * @param array $args URL parameters - * - * @return boolean success value - */ - protected function prepare(array $args=array()) + protected function doPreparation() { - parent::prepare($args); $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; if ($this->page > MAX_PUBLIC_PAGE) { @@ -108,22 +100,6 @@ class PublicAction extends Action } } - /** - * handle request - * - * Show the public stream, using recipe method showPage() - * - * @param array $args arguments, mostly unused - * - * @return void - */ - protected function handle() - { - parent::handle(); - - $this->showPage(); - } - /** * Title of the page * @@ -219,9 +195,7 @@ class PublicAction extends Action */ function showContent() { - $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->scoped); @@ -234,7 +208,7 @@ class PublicAction extends Action } $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, - $this->page, 'public'); + $this->page, $this->action); } function showSections() @@ -285,11 +259,3 @@ class PublicAction extends Action $this->elementEnd('div'); } } - -class ThreadingPublicNoticeStream extends ThreadingNoticeStream -{ - function __construct($profile) - { - parent::__construct(new PublicNoticeStream($profile)); - } -} diff --git a/classes/Notice.php b/classes/Notice.php index 641b129552..6760eb7278 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -997,6 +997,7 @@ class Notice extends Managed_DataObject if ($this->isPublic()) { $this->blowStream('public'); + $this->blowStream('networkpublic'); } self::blow('notice:list-ids:conversation:%s', $this->conversation); @@ -1041,6 +1042,7 @@ class Notice extends Managed_DataObject if ($this->isPublic()) { self::blow('public;last'); + self::blow('networkpublic;last'); } self::blow('fave:by_notice', $this->id); @@ -2636,12 +2638,8 @@ class Notice extends Managed_DataObject function isPublic() { - if (common_config('public', 'localonly')) { - return ($this->is_local == Notice::LOCAL_PUBLIC); - } else { - return (($this->is_local != Notice::LOCAL_NONPUBLIC) && - ($this->is_local != Notice::GATEWAY)); - } + return (($this->is_local != Notice::LOCAL_NONPUBLIC) && + ($this->is_local != Notice::GATEWAY)); } /** diff --git a/lib/networkpublicnoticestream.php b/lib/networkpublicnoticestream.php new file mode 100644 index 0000000000..3320b7cd5a --- /dev/null +++ b/lib/networkpublicnoticestream.php @@ -0,0 +1,66 @@ + + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +class RawNetworkPublicNoticeStream extends NoticeStream +{ + function getNoticeIds($offset, $limit, $since_id, $max_id) + { + $notice = new Notice(); + + $notice->selectAdd(); // clears it + $notice->selectAdd('id'); + + $notice->orderBy('created DESC, id DESC'); + + if (!is_null($offset)) { + $notice->limit($offset, $limit); + } + + $notice->whereAdd('is_local ='. Notice::REMOTE); + // -1 == blacklisted, -2 == gateway (i.e. Twitter) + $notice->whereAdd('is_local !='. Notice::LOCAL_NONPUBLIC); + $notice->whereAdd('is_local !='. Notice::GATEWAY); + + Notice::addWhereSinceId($notice, $since_id); + Notice::addWhereMaxId($notice, $max_id); + + if (!empty($this->selectVerbs)) { + $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb')); + } + + $ids = array(); + + if ($notice->find()) { + while ($notice->fetch()) { + $ids[] = $notice->id; + } + } + + $notice->free(); + $notice = NULL; + + return $ids; + } +} diff --git a/lib/publicnoticestream.php b/lib/publicnoticestream.php index 34f7b4a1de..757c2164c0 100644 --- a/lib/publicnoticestream.php +++ b/lib/publicnoticestream.php @@ -81,13 +81,8 @@ class RawPublicNoticeStream extends NoticeStream $notice->limit($offset, $limit); } - if (common_config('public', 'localonly')) { - $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC); - } else { - // -1 == blacklisted, -2 == gateway (i.e. Twitter) - $notice->whereAdd('is_local !='. Notice::LOCAL_NONPUBLIC); - $notice->whereAdd('is_local !='. Notice::GATEWAY); - } + // This feed always gives only local activities. + $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC); Notice::addWhereSinceId($notice, $since_id); Notice::addWhereMaxId($notice, $max_id); diff --git a/lib/router.php b/lib/router.php index a3be38ebbd..bcdeee80c7 100644 --- a/lib/router.php +++ b/lib/router.php @@ -949,8 +949,12 @@ class Router } } else { $m->connect('main/public', array('action' => 'public')); - $m->connect('', array('action' => 'public')); $m->connect('main/all', array('action' => 'networkpublic')); + if (common_config('site', 'localonly')) { + $m->connect('', array('action' => 'public')); + } else { + $m->connect('', array('action' => 'networkpublic')); + } $m->connect('rss', array('action' => 'publicrss')); $m->connect('featuredrss', array('action' => 'featuredrss')); $m->connect('featured/', array('action' => 'featured')); diff --git a/lib/threadingnetworkpublicnoticestream.php b/lib/threadingnetworkpublicnoticestream.php new file mode 100644 index 0000000000..f733c43725 --- /dev/null +++ b/lib/threadingnetworkpublicnoticestream.php @@ -0,0 +1,11 @@ +