Commit a5d27d9c authored by mmn's avatar mmn

/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.
parent eaaef2ae
<?php
if (!defined('GNUSOCIAL')) { exit(1); }
class NetworkpublicAction extends PublicAction
{
protected function streamPrepare()
{
if (!$this->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();
}
}
...@@ -45,7 +45,7 @@ define('MAX_PUBLIC_PAGE', 100); ...@@ -45,7 +45,7 @@ define('MAX_PUBLIC_PAGE', 100);
* @see PublicrssAction * @see PublicrssAction
* @see PublicxrdsAction * @see PublicxrdsAction
*/ */
class PublicAction extends Action class PublicAction extends ManagedAction
{ {
/** /**
* page of the stream we're on; default = 1 * page of the stream we're on; default = 1
...@@ -61,16 +61,8 @@ class PublicAction extends Action ...@@ -61,16 +61,8 @@ class PublicAction extends Action
return true; return true;
} }
/** protected function doPreparation()
* Read and validate arguments
*
* @param array $args URL parameters
*
* @return boolean success value
*/
protected function prepare(array $args=array())
{ {
parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
if ($this->page > MAX_PUBLIC_PAGE) { if ($this->page > MAX_PUBLIC_PAGE) {
...@@ -108,22 +100,6 @@ class PublicAction extends Action ...@@ -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 * Title of the page
* *
...@@ -219,9 +195,7 @@ class PublicAction extends Action ...@@ -219,9 +195,7 @@ class PublicAction extends Action
*/ */
function showContent() function showContent()
{ {
$user = common_current_user(); if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
if (!empty($user) && $user->streamModeOnly()) {
$nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE)); $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
} else { } else {
$nl = new ThreadedNoticeList($this->notice, $this, $this->scoped); $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped);
...@@ -234,7 +208,7 @@ class PublicAction extends Action ...@@ -234,7 +208,7 @@ class PublicAction extends Action
} }
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'public'); $this->page, $this->action);
} }
function showSections() function showSections()
...@@ -285,11 +259,3 @@ class PublicAction extends Action ...@@ -285,11 +259,3 @@ class PublicAction extends Action
$this->elementEnd('div'); $this->elementEnd('div');
} }
} }
class ThreadingPublicNoticeStream extends ThreadingNoticeStream
{
function __construct($profile)
{
parent::__construct(new PublicNoticeStream($profile));
}
}
...@@ -997,6 +997,7 @@ class Notice extends Managed_DataObject ...@@ -997,6 +997,7 @@ class Notice extends Managed_DataObject
if ($this->isPublic()) { if ($this->isPublic()) {
$this->blowStream('public'); $this->blowStream('public');
$this->blowStream('networkpublic');
} }
self::blow('notice:list-ids:conversation:%s', $this->conversation); self::blow('notice:list-ids:conversation:%s', $this->conversation);
...@@ -1041,6 +1042,7 @@ class Notice extends Managed_DataObject ...@@ -1041,6 +1042,7 @@ class Notice extends Managed_DataObject
if ($this->isPublic()) { if ($this->isPublic()) {
self::blow('public;last'); self::blow('public;last');
self::blow('networkpublic;last');
} }
self::blow('fave:by_notice', $this->id); self::blow('fave:by_notice', $this->id);
...@@ -2636,12 +2638,8 @@ class Notice extends Managed_DataObject ...@@ -2636,12 +2638,8 @@ class Notice extends Managed_DataObject
function isPublic() function isPublic()
{ {
if (common_config('public', 'localonly')) { return (($this->is_local != Notice::LOCAL_NONPUBLIC) &&
return ($this->is_local == Notice::LOCAL_PUBLIC); ($this->is_local != Notice::GATEWAY));
} else {
return (($this->is_local != Notice::LOCAL_NONPUBLIC) &&
($this->is_local != Notice::GATEWAY));
}
} }
/** /**
......
<?php
if (!defined('GNUSOCIAL')) { exit(1); }
class NetworkPublicNoticeStream extends ScopingNoticeStream
{
function __construct(Profile $scoped=null)
{
parent::__construct(new CachingNoticeStream(new RawNetworkPublicNoticeStream(),
'networkpublic'),
$scoped);
}
}
/**
* Raw public stream
*
* @category Stream
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @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;
}
}
...@@ -81,13 +81,8 @@ class RawPublicNoticeStream extends NoticeStream ...@@ -81,13 +81,8 @@ class RawPublicNoticeStream extends NoticeStream
$notice->limit($offset, $limit); $notice->limit($offset, $limit);
} }
if (common_config('public', 'localonly')) { // This feed always gives only local activities.
$notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC); $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);
}
Notice::addWhereSinceId($notice, $since_id); Notice::addWhereSinceId($notice, $since_id);
Notice::addWhereMaxId($notice, $max_id); Notice::addWhereMaxId($notice, $max_id);
......
...@@ -949,8 +949,12 @@ class Router ...@@ -949,8 +949,12 @@ class Router
} }
} else { } else {
$m->connect('main/public', array('action' => 'public')); $m->connect('main/public', array('action' => 'public'));
$m->connect('', array('action' => 'public'));
$m->connect('main/all', array('action' => 'networkpublic')); $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('rss', array('action' => 'publicrss'));
$m->connect('featuredrss', array('action' => 'featuredrss')); $m->connect('featuredrss', array('action' => 'featuredrss'));
$m->connect('featured/', array('action' => 'featured')); $m->connect('featured/', array('action' => 'featured'));
......
<?php
if (!defined('GNUSOCIAL')) { exit(1); }
class ThreadingNetworkPublicNoticeStream extends ThreadingNoticeStream
{
public function __construct(Profile $scoped=null)
{
parent::__construct(new NetworkPublicNoticeStream($scoped));
}
}
<?php
if (!defined('GNUSOCIAL')) { exit(1); }
class ThreadingPublicNoticeStream extends ThreadingNoticeStream
{
function __construct($scoped)
{
parent::__construct(new PublicNoticeStream($scoped));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment