bookmarksnoticestream.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. defined('GNUSOCIAL') || die();
  17. class RawBookmarksNoticeStream extends NoticeStream
  18. {
  19. protected $user_id;
  20. protected $own;
  21. public function __construct($user_id, $own)
  22. {
  23. $this->user_id = $user_id;
  24. $this->own = $own;
  25. }
  26. public function getNoticeIds($offset, $limit, $since_id, $max_id)
  27. {
  28. $notice = new Notice();
  29. $qry = null;
  30. $qry = 'SELECT notice.* FROM notice ';
  31. $qry .= 'INNER JOIN bookmark ON bookmark.uri = notice.uri ';
  32. $qry .= 'WHERE bookmark.profile_id = ' . $this->user_id . ' ';
  33. $qry .= 'AND notice.is_local <> ' . Notice::GATEWAY . ' ';
  34. if ($since_id != 0) {
  35. $qry .= 'AND notice.id > ' . $since_id . ' ';
  36. }
  37. if ($max_id != 0) {
  38. $qry .= 'AND notice.id <= ' . $max_id . ' ';
  39. }
  40. // NOTE: we sort by bookmark time, not by notice time!
  41. $qry .= 'ORDER BY created DESC ';
  42. if (!is_null($offset)) {
  43. $qry .= "LIMIT $limit OFFSET $offset";
  44. }
  45. $notice->query($qry);
  46. $ids = array();
  47. while ($notice->fetch()) {
  48. $ids[] = $notice->id;
  49. }
  50. $notice->free();
  51. unset($notice);
  52. return $ids;
  53. }
  54. }
  55. /**
  56. * Notice stream for bookmarks
  57. *
  58. * @category Stream
  59. * @package StatusNet
  60. * @author Stephane Berube <chimo@chromic.org>
  61. * @copyright 2011 StatusNet, Inc.
  62. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  63. * @link http://status.net/
  64. */
  65. class BookmarksNoticeStream extends ScopingNoticeStream
  66. {
  67. public function __construct($user_id, $own, Profile $scoped = null)
  68. {
  69. $stream = new RawBookmarksNoticeStream($user_id, $own);
  70. if ($own) {
  71. $key = 'bookmark:ids_by_user_own:'.$user_id;
  72. } else {
  73. $key = 'bookmark:ids_by_user:'.$user_id;
  74. }
  75. parent::__construct(new CachingNoticeStream($stream, $key), $scoped);
  76. }
  77. }