X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fnoticestream.php;h=2b04a89ca4297c4ba905634af275f2f4ec188626;hb=73dbc5ca1b203758693f73d6423fea71ef6b6fb6;hp=be28aa61867526f56214ca9ed7f9f6b9534e20a7;hpb=31b29fde50e9664e1b70064c043879ce87553883;p=quix0rs-gnu-social.git diff --git a/lib/noticestream.php b/lib/noticestream.php index be28aa6186..2b04a89ca4 100644 --- a/lib/noticestream.php +++ b/lib/noticestream.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 for notice streams @@ -46,6 +42,18 @@ if (!defined('STATUSNET')) { */ abstract class NoticeStream { + protected $selectVerbs = array(ActivityVerb::POST => true, + ActivityVerb::SHARE => true); + + public function __construct() + { + 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; + } + } + abstract function getNoticeIds($offset, $limit, $since_id, $max_id); function getNotices($offset, $limit, $sinceId = null, $maxId = null) @@ -59,42 +67,23 @@ abstract class NoticeStream static function getStreamByIds($ids) { - $cache = Cache::instance(); - - if (!empty($cache)) { - $notices = array(); - foreach ($ids as $id) { - $n = Notice::staticGet('id', $id); - if (!empty($n)) { - $notices[] = $n; - } - } - return new ArrayWrapper($notices); - } else { - $notice = new Notice(); - if (empty($ids)) { - //if no IDs requested, just return the notice object - return $notice; - } - $notice->whereAdd('id in (' . implode(', ', $ids) . ')'); - - $notice->find(); - - $temp = array(); - - while ($notice->fetch()) { - $temp[$notice->id] = clone($notice); - } - - $wrapped = array(); + return Notice::multiGet('id', $ids); + } - foreach ($ids as $id) { - if (array_key_exists($id, $temp)) { - $wrapped[] = $temp[$id]; - } - } + 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')); + } - return new ArrayWrapper($wrapped); + $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); } }