filenoticestream.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Stream of notices that reference an URL
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Stream
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. class FileNoticeStream extends ScopingNoticeStream
  32. {
  33. function __construct($file, Profile $scoped=null)
  34. {
  35. parent::__construct(new CachingNoticeStream(new RawFileNoticeStream($file),
  36. 'file:notice-ids:'.$file->id),
  37. $scoped);
  38. }
  39. }
  40. /**
  41. * Raw stream for a file
  42. *
  43. * @category Stream
  44. * @package StatusNet
  45. * @author Evan Prodromou <evan@status.net>
  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 RawFileNoticeStream extends NoticeStream
  51. {
  52. protected $file = null;
  53. function __construct($file)
  54. {
  55. $this->file = $file;
  56. }
  57. /**
  58. * Stream of notices linking to this URL
  59. *
  60. * @param integer $offset Offset to show; default is 0
  61. * @param integer $limit Limit of notices to show
  62. * @param integer $since_id Since this notice
  63. * @param integer $max_id Before this notice
  64. *
  65. * @return array ids of notices that link to this file
  66. */
  67. function getNoticeIds($offset, $limit, $since_id, $max_id)
  68. {
  69. $f2p = new File_to_post();
  70. $f2p->selectAdd();
  71. $f2p->selectAdd('post_id');
  72. $f2p->file_id = $this->file->id;
  73. Notice::addWhereSinceId($f2p, $since_id, 'post_id', 'modified');
  74. Notice::addWhereMaxId($f2p, $max_id, 'post_id', 'modified');
  75. $f2p->orderBy('modified DESC, post_id DESC');
  76. if (!is_null($offset)) {
  77. $f2p->limit($offset, $limit);
  78. }
  79. $ids = array();
  80. if ($f2p->find()) {
  81. while ($f2p->fetch()) {
  82. $ids[] = $f2p->post_id;
  83. }
  84. }
  85. return $ids;
  86. }
  87. }