/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.
This commit is contained in:
Mikael Nordfeldth 2015-01-28 20:25:39 +01:00
parent eaaef2aec9
commit a5d27d9ce7
8 changed files with 169 additions and 52 deletions

66
actions/networkpublic.php Normal file
View File

@ -0,0 +1,66 @@
<?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();
}
}

View File

@ -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));
}
}

View File

@ -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));
}
/**

View File

@ -0,0 +1,66 @@
<?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;
}
}

View File

@ -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);

View File

@ -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'));

View File

@ -0,0 +1,11 @@
<?php
if (!defined('GNUSOCIAL')) { exit(1); }
class ThreadingNetworkPublicNoticeStream extends ThreadingNoticeStream
{
public function __construct(Profile $scoped=null)
{
parent::__construct(new NetworkPublicNoticeStream($scoped));
}
}

View File

@ -0,0 +1,11 @@
<?php
if (!defined('GNUSOCIAL')) { exit(1); }
class ThreadingPublicNoticeStream extends ThreadingNoticeStream
{
function __construct($scoped)
{
parent::__construct(new PublicNoticeStream($scoped));
}
}