filenoticestream.php 2.9 KB

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