* @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); }
/**
* Notice stream for a conversation
$notice->limit($offset, $limit);
}
- if (!empty($this->selectVerbs)) {
- $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
- }
+ self::filterVerbs($notice, $this->selectVerbs);
// ORDER BY
// currently imitates the previously used "_reverseChron" sorting
* @link http://status.net/
*/
-if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Stream of notices for a profile's "all" feed
protected $target = null;
protected $inbox = null;
+ protected $selectVerbs = array();
+
/**
* Constructor
*
*/
function __construct(Profile $target)
{
+ parent::__construct();
$this->target = $target;
- $this->unselectVerbs = array(ActivityVerb::DELETE);
}
/**
if (!empty($max_id)) {
$notice->whereAdd(sprintf('notice.id <= %d', $max_id));
}
- if (!empty($this->selectVerbs)) {
- $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
- }
- if (!empty($this->unselectVerbs)) {
- $notice->whereAddIn('!verb', $this->unselectVerbs, $notice->columnType('verb'));
- }
+
+ self::filterVerbs($notice, $this->selectVerbs);
+
$notice->limit($offset, $limit);
// notice.id will give us even really old posts, which were
// recently imported. For example if a remote instance had
Notice::addWhereSinceId($notice, $since_id);
Notice::addWhereMaxId($notice, $max_id);
- if (!empty($this->selectVerbs)) {
- $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
- }
+ self::filterVerbs($notice, $this->selectVerbs);
$ids = array();
* @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 for notice streams
*/
abstract class NoticeStream
{
- protected $selectVerbs = null; // must be set to array
- protected $unselectVerbs = null; // must be set to array
+ protected $selectVerbs = array(ActivityVerb::POST => true,
+ ActivityVerb::DELETE => false);
public function __construct()
{
- if ($this->selectVerbs === null) {
- $this->selectVerbs = array(ActivityVerb::POST, ActivityUtils::resolveUri(ActivityVerb::POST, true));
- }
- if ($this->unselectVerbs === null) {
- $this->unselectVerbs = array(ActivityVerb::DELETE);
+ foreach ($this->selectVerbs as $key=>$val) {
+ // to avoid database inconsistency issues we select both relative and absolute verbs
+ $this->selectVerbs[ActivityUtils::resolveUri($key)] = $val;
+ $this->selectVerbs[ActivityUtils::resolveUri($key, true)] = $val;
}
}
{
return Notice::multiGet('id', $ids);
}
+
+ static function filterVerbs(Notice $notice, array $selectVerbs)
+ {
+ $filter = array_keys(array_filter($selectVerbs));
+ if (!empty($filter)) {
+ // include verbs in selectVerbs with values that equate to true
+ $notice->whereAddIn('verb', $filter, $notice->columnType('verb'));
+ }
+
+ $filter = array_keys(array_filter($selectVerbs, function ($v) { return !$v; }));
+ if (!empty($filter)) {
+ // exclude verbs in selectVerbs with values that equate to false
+ $notice->whereAddIn('!verb', $filter, $notice->columnType('verb'));
+ }
+
+ unset($filter);
+ }
}
* @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 by a profile
Notice::addWhereSinceId($notice, $since_id);
Notice::addWhereMaxId($notice, $max_id);
- if (!empty($this->selectVerbs)) {
- $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
- }
- if (!empty($this->unselectVerbs)) {
- $notice->whereAddIn('!verb', $this->unselectVerbs, $notice->columnType('verb'));
- }
+ self::filterVerbs($notice, $this->selectVerbs);
$notice->orderBy('created DESC, id DESC');
* @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); }
/**
* Public stream
Notice::addWhereSinceId($notice, $since_id);
Notice::addWhereMaxId($notice, $max_id);
- if (!empty($this->selectVerbs)) {
- $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
- }
+ self::filterVerbs($notice, $this->selectVerbs);
$ids = array();
* @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 mentions of me
Notice::addWhereMaxId($reply, $max_id, 'notice_id', 'reply.modified');
if (!empty($this->selectVerbs)) {
+ // this is a little special since we have to join in Notice
$reply->joinAdd(array('notice_id', 'notice:id'));
- $reply->whereAddIn('notice.verb', $this->selectVerbs, 'string');
+
+ $filter = array_keys(array_filter($this->selectVerbs));
+ if (!empty($filter)) {
+ // include verbs in selectVerbs with values that equate to true
+ $reply->whereAddIn('notice.verb', $filter, 'string');
+ }
+
+ $filter = array_keys(array_filter($this->selectVerbs, function ($v) { return !$v; }));
+ if (!empty($filter)) {
+ // exclude verbs in selectVerbs with values that equate to false
+ $reply->whereAddIn('!notice.verb', $filter, 'string');
+ }
}
$reply->orderBy('reply.modified DESC, reply.notice_id DESC');
* @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 tag
Notice::addWhereMaxId($nt, $max_id, 'notice_id');
if (!empty($this->selectVerbs)) {
- $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb'));
- }
- if (!empty($this->unselectVerbs)) {
- $notice->whereAddIn('!verb', $this->unselectVerbs, $notice->columnType('verb'));
+ $nt->joinAdd(array('notice_id', 'notice:id'));
+
+ $filter = array_keys(array_filter($this->selectVerbs));
+ if (!empty($filter)) {
+ // include verbs in selectVerbs with values that equate to true
+ $nt->whereAddIn('notice.verb', $filter, 'string');
+ }
+
+ $filter = array_keys(array_filter($this->selectVerbs, function ($v) { return !$v; }));
+ if (!empty($filter)) {
+ // exclude verbs in selectVerbs with values that equate to false
+ $nt->whereAddIn('!notice.verb', $filter, 'string');
+ }
}
$nt->orderBy('created DESC, notice_id DESC');
* @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); }
/**
* Notice stream for favorites
protected $user_id;
protected $own;
+ protected $selectVerbs = array();
+
function __construct($user_id, $own)
{
parent::__construct();
$this->user_id = $user_id;
$this->own = $own;
-
- $this->selectVerbs = array();
}
/**