filenoticestream.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. class FileNoticeStream extends ScopingNoticeStream
  36. {
  37. function __construct($file, $profile = -1)
  38. {
  39. if (is_int($profile) && $profile == -1) {
  40. $profile = Profile::current();
  41. }
  42. parent::__construct(new CachingNoticeStream(new RawFileNoticeStream($file),
  43. 'file:notice-ids:'.$file->id),
  44. $profile);
  45. }
  46. }
  47. /**
  48. * Raw stream for a file
  49. *
  50. * @category Stream
  51. * @package StatusNet
  52. * @author Evan Prodromou <evan@status.net>
  53. * @copyright 2011 StatusNet, Inc.
  54. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  55. * @link http://status.net/
  56. */
  57. class RawFileNoticeStream extends NoticeStream
  58. {
  59. protected $file = null;
  60. function __construct($file)
  61. {
  62. $this->file = $file;
  63. }
  64. /**
  65. * Stream of notices linking to this URL
  66. *
  67. * @param integer $offset Offset to show; default is 0
  68. * @param integer $limit Limit of notices to show
  69. * @param integer $since_id Since this notice
  70. * @param integer $max_id Before this notice
  71. *
  72. * @return array ids of notices that link to this file
  73. */
  74. function getNoticeIds($offset, $limit, $since_id, $max_id)
  75. {
  76. $f2p = new File_to_post();
  77. $f2p->selectAdd();
  78. $f2p->selectAdd('post_id');
  79. $f2p->file_id = $this->file->id;
  80. Notice::addWhereSinceId($f2p, $since_id, 'post_id', 'modified');
  81. Notice::addWhereMaxId($f2p, $max_id, 'post_id', 'modified');
  82. $f2p->orderBy('modified DESC, post_id DESC');
  83. if (!is_null($offset)) {
  84. $f2p->limit($offset, $limit);
  85. }
  86. $ids = array();
  87. if ($f2p->find()) {
  88. while ($f2p->fetch()) {
  89. $ids[] = $f2p->post_id;
  90. }
  91. }
  92. return $ids;
  93. }
  94. }