noticestreamaction.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. if (!defined('GNUSOCIAL')) { exit(1); }
  3. abstract class NoticestreamAction extends ProfileAction
  4. {
  5. protected $notice = null; // holds the stream result
  6. protected function prepare(array $args=array()) {
  7. parent::prepare($args);
  8. // In case we need more info than ProfileAction->doPreparation() gives us
  9. $this->doStreamPreparation();
  10. // fetch the actual stream stuff
  11. try {
  12. $stream = $this->getStream();
  13. $this->notice = $stream->getNotices(($this->page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
  14. } catch (PrivateStreamException $e) {
  15. $this->notice = new Notice();
  16. $this->notice->whereAdd('FALSE');
  17. }
  18. if ($this->page > 1 && $this->notice->N == 0) {
  19. // TRANS: Client error when page not found (404).
  20. $this->clientError(_('No such page.'), 404);
  21. }
  22. return true;
  23. }
  24. protected function doStreamPreparation()
  25. {
  26. // pass by default
  27. }
  28. public function extraHeaders()
  29. {
  30. parent::extraHeaders();
  31. foreach ($this->getFeeds() as $feed) {
  32. $heads = [];
  33. if ($feed->getUrl() !== null) $heads[] = "Link: <".htmlspecialchars($feed->getUrl()).">;";
  34. if ($feed->rel() !== null) $heads[] = "rel=\"".htmlspecialchars($feed->rel())."\"";
  35. if ($feed->rel() !== null) $heads[] = "type=\"".htmlspecialchars($feed->mimeType())."\"";
  36. if (!empty($heads)) {
  37. $head = implode(" ", $heads);
  38. header($head, false);
  39. }
  40. }
  41. }
  42. // this fetches the NoticeStream
  43. abstract public function getStream();
  44. }