bookmarksnoticestream.php 2.0 KB

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