noticebyurl.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * Notice stream of notices with a given attachment
  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 Bookmark
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2010 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. /**
  36. * List notices that contain/link to/use a given URL
  37. *
  38. * @category Bookmark
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @copyright 2010 StatusNet, Inc.
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  43. * @link http://status.net/
  44. */
  45. class NoticebyurlAction extends Action
  46. {
  47. protected $url = null;
  48. protected $file = null;
  49. protected $notices = null;
  50. protected $page = null;
  51. /**
  52. * For initializing members of the class.
  53. *
  54. * @param array $args misc. arguments
  55. *
  56. * @return boolean true
  57. * @throws ClientException
  58. */
  59. function prepare(array $args = [])
  60. {
  61. parent::prepare($args);
  62. $this->file = File::getKV('id', $this->trimmed('id'));
  63. if (empty($this->file)) {
  64. // TRANS: Client exception thrown when an unknown URL is provided.
  65. throw new ClientException(_m('Unknown URL.'));
  66. }
  67. $pageArg = $this->trimmed('page');
  68. $this->page = (empty($pageArg)) ? 1 : intval($pageArg);
  69. $this->notices = $this->file->stream(($this->page - 1) * NOTICES_PER_PAGE,
  70. NOTICES_PER_PAGE + 1);
  71. return true;
  72. }
  73. /**
  74. * Title of the page
  75. *
  76. * @return string page title
  77. */
  78. function title()
  79. {
  80. if ($this->page == 1) {
  81. // TRANS: Title of notice stream of notices with a given attachment (first page).
  82. // TRANS: %s is the URL.
  83. return sprintf(_m('Notices linking to %s'), $this->file->url);
  84. } else {
  85. // TRANS: Title of notice stream of notices with a given attachment (all but first page).
  86. // TRANS: %1$s is the URL, %2$s is the page number.
  87. return sprintf(_m('Notices linking to %1$s, page %2$d'),
  88. $this->file->url,
  89. $this->page);
  90. }
  91. }
  92. /**
  93. * Handler method
  94. *
  95. * @return void
  96. */
  97. function handle()
  98. {
  99. $this->showPage();
  100. }
  101. /**
  102. * Show main page content.
  103. *
  104. * Shows a list of the notices that link to the given URL
  105. *
  106. * @return void
  107. */
  108. function showContent()
  109. {
  110. $nl = new NoticeList($this->notices, $this);
  111. $nl->show();
  112. $cnt = $nl->show();
  113. $this->pagination($this->page > 1,
  114. $cnt > NOTICES_PER_PAGE,
  115. $this->page,
  116. 'noticebyurl',
  117. array('id' => $this->file->id));
  118. }
  119. /**
  120. * Return true if read only.
  121. *
  122. * MAY override
  123. *
  124. * @param array $args other arguments
  125. *
  126. * @return boolean is read only action?
  127. */
  128. function isReadOnly($args)
  129. {
  130. return true;
  131. }
  132. /**
  133. * Return last modified, if applicable.
  134. *
  135. * MAY override
  136. *
  137. * @return string last modified http header
  138. */
  139. function lastModified()
  140. {
  141. // For comparison with If-Last-Modified
  142. // If not applicable, return null
  143. return null;
  144. }
  145. /**
  146. * Return etag, if applicable.
  147. *
  148. * MAY override
  149. *
  150. * @return string etag http header
  151. */
  152. function etag()
  153. {
  154. return null;
  155. }
  156. }