bookmarksnoticestream.php 1.9 KB

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