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