]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Bookmark/lib/bookmarksnoticestream.php
plugins onAutoload now only overloads if necessary (extlibs etc.)
[quix0rs-gnu-social.git] / plugins / Bookmark / lib / bookmarksnoticestream.php
1 <?php
2
3 class RawBookmarksNoticeStream extends NoticeStream
4 {
5     protected $user_id;
6     protected $own;
7
8     function __construct($user_id, $own)
9     {
10         $this->user_id = $user_id;
11         $this->own     = $own;
12     }
13
14     function getNoticeIds($offset, $limit, $since_id, $max_id)
15     {
16         $notice = new Notice();
17         $qry = null;
18
19         $qry =  'SELECT notice.* FROM notice ';
20         $qry .= 'INNER JOIN bookmark ON bookmark.uri = notice.uri ';
21         $qry .= 'WHERE bookmark.profile_id = ' . $this->user_id . ' ';
22         $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' ';
23
24         if ($since_id != 0) {
25             $qry .= 'AND notice.id > ' . $since_id . ' ';
26         }
27
28         if ($max_id != 0) {
29             $qry .= 'AND notice.id <= ' . $max_id . ' ';
30         }
31
32         // NOTE: we sort by bookmark time, not by notice time!
33         $qry .= 'ORDER BY created DESC ';
34         if (!is_null($offset)) {
35             $qry .= "LIMIT $limit OFFSET $offset";
36         }
37
38         $notice->query($qry);
39         $ids = array();
40         while ($notice->fetch()) {
41             $ids[] = $notice->id;
42         }
43
44         $notice->free();
45         unset($notice);
46         return $ids;
47     }
48 }
49
50 /**
51  * Notice stream for bookmarks
52  *
53  * @category  Stream
54  * @package   StatusNet
55  * @author    Stephane Berube <chimo@chromic.org>
56  * @copyright 2011 StatusNet, Inc.
57  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
58  * @link      http://status.net/
59  */
60
61 class BookmarksNoticeStream extends ScopingNoticeStream
62 {
63     function __construct($user_id, $own, $profile = -1)
64     {
65         $stream = new RawBookmarksNoticeStream($user_id, $own);
66
67         if ($own) {
68             $key = 'bookmark:ids_by_user_own:'.$user_id;
69         } else {
70             $key = 'bookmark:ids_by_user:'.$user_id;
71         }
72
73         if (is_int($profile) && $profile == -1) {
74             $profile = Profile::current();
75         }
76
77         parent::__construct(new CachingNoticeStream($stream, $key),
78                             $profile);
79     }
80 }