favorited.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List of popular notices
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Public
  23. * @package StatusNet
  24. * @author Zach Copley <zach@status.net>
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2008-2009 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * List of popular notices
  33. *
  34. * We provide a list of the most popular notices. Popularity
  35. * is measured by
  36. *
  37. * @category Personal
  38. * @package StatusNet
  39. * @author Zach Copley <zach@status.net>
  40. * @author Evan Prodromou <evan@status.net>
  41. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  42. * @link http://status.net/
  43. */
  44. class FavoritedAction extends Action
  45. {
  46. var $page = null;
  47. /**
  48. * Title of the page
  49. *
  50. * @return string Title of the page
  51. */
  52. function title()
  53. {
  54. if ($this->page == 1) {
  55. // TRANS: Page title for first page of favorited notices.
  56. return _('Popular notices');
  57. } else {
  58. // TRANS: Page title for all but first page of favorited notices.
  59. // TRANS: %d is the page number being displayed.
  60. return sprintf(_('Popular notices, page %d'), $this->page);
  61. }
  62. }
  63. /**
  64. * Instructions for use
  65. *
  66. * @return instructions for use
  67. */
  68. function getInstructions()
  69. {
  70. // TRANS: Description on page displaying favorited notices.
  71. return _('The most popular notices on the site right now.');
  72. }
  73. /**
  74. * Is this page read-only?
  75. *
  76. * @return boolean true
  77. */
  78. function isReadOnly($args)
  79. {
  80. return true;
  81. }
  82. /**
  83. * Take arguments for running
  84. *
  85. * @param array $args $_REQUEST args
  86. *
  87. * @return boolean success flag
  88. *
  89. * @todo move queries from showContent() to here
  90. */
  91. function prepare($args)
  92. {
  93. parent::prepare($args);
  94. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  95. common_set_returnto($this->selfUrl());
  96. return true;
  97. }
  98. /**
  99. * Handle request
  100. *
  101. * Shows a page with list of favorite notices
  102. *
  103. * @param array $args $_REQUEST args; handled in prepare()
  104. *
  105. * @return void
  106. */
  107. function handle($args)
  108. {
  109. parent::handle($args);
  110. $this->showPage();
  111. }
  112. /**
  113. * Show the page notice
  114. *
  115. * Shows instructions for the page
  116. *
  117. * @return void
  118. */
  119. function showPageNotice()
  120. {
  121. $instr = $this->getInstructions();
  122. $output = common_markup_to_html($instr);
  123. $this->elementStart('div', 'instructions');
  124. $this->raw($output);
  125. $this->elementEnd('div');
  126. }
  127. function showEmptyList()
  128. {
  129. // TRANS: Text displayed instead of a list when a site does not yet have any favourited notices.
  130. $message = _('Favorite notices appear on this page but no one has favorited one yet.') . ' ';
  131. if (common_logged_in()) {
  132. // TRANS: Additional text displayed instead of a list when a site does not yet have any favourited notices for logged in users.
  133. $message .= _('Be the first to add a notice to your favorites by clicking the fave button next to any notice you like.');
  134. }
  135. else {
  136. // TRANS: Additional text displayed instead of a list when a site does not yet have any favourited notices for not logged in users.
  137. // TRANS: %%action.register%% is a registration link. "[link text](link)" is Mark Down. Do not change the formatting.
  138. $message .= _('Why not [register an account](%%action.register%%) and be the first to add a notice to your favorites!');
  139. }
  140. $this->elementStart('div', 'guide');
  141. $this->raw(common_markup_to_html($message));
  142. $this->elementEnd('div');
  143. }
  144. /**
  145. * Content area
  146. *
  147. * Shows the list of popular notices
  148. *
  149. * @return void
  150. */
  151. function showContent()
  152. {
  153. $stream = new PopularNoticeStream(Profile::current());
  154. $notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE+1);
  155. $nl = new NoticeList($notice, $this);
  156. $cnt = $nl->show();
  157. if ($cnt == 0) {
  158. $this->showEmptyList();
  159. }
  160. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  161. $this->page, 'favorited');
  162. }
  163. }