tag.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008, 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('GNUSOCIAL')) { exit(1); }
  20. // @todo FIXME: documentation missing.
  21. class TagAction extends ManagedAction
  22. {
  23. var $notice;
  24. var $tag;
  25. var $page;
  26. protected function prepare(array $args=array())
  27. {
  28. parent::prepare($args);
  29. $taginput = $this->trimmed('tag');
  30. $this->tag = common_canonical_tag($taginput);
  31. if (empty($this->tag)) {
  32. throw new ClientException(_('No valid tag data.'));
  33. }
  34. // after common_canonical_tag we have a lowercase, no-specials tag string
  35. if ($this->tag !== $taginput) {
  36. common_redirect(common_local_url('tag', array('tag' => $this->tag)), 301);
  37. }
  38. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  39. common_set_returnto($this->selfUrl());
  40. $this->notice = Notice_tag::getStream($this->tag)->getNotices(($this->page-1)*NOTICES_PER_PAGE,
  41. NOTICES_PER_PAGE + 1);
  42. if($this->page > 1 && $this->notice->N == 0){
  43. // TRANS: Client error when page not found (404).
  44. $this->clientError(_('No such page.'), 404);
  45. }
  46. return true;
  47. }
  48. function title()
  49. {
  50. if ($this->page == 1) {
  51. // TRANS: Title for first page of notices with tags.
  52. // TRANS: %s is the tag.
  53. return sprintf(_('Notices tagged with %s'), $this->tag);
  54. } else {
  55. // TRANS: Title for all but the first page of notices with tags.
  56. // TRANS: %1$s is the tag, %2$d is the page number.
  57. return sprintf(_('Notices tagged with %1$s, page %2$d'),
  58. $this->tag,
  59. $this->page);
  60. }
  61. }
  62. function getFeeds()
  63. {
  64. return array(new Feed(Feed::JSON,
  65. common_local_url('ApiTimelineTag',
  66. array('format' => 'as',
  67. 'tag' => $this->tag)),
  68. // TRANS: Link label for feed on "notices with tag" page.
  69. // TRANS: %s is the tag the feed is for.
  70. sprintf(_('Notice feed for tag %s (Activity Streams JSON)'),
  71. $this->tag)),
  72. new Feed(Feed::RSS1,
  73. common_local_url('tagrss',
  74. array('tag' => $this->tag)),
  75. // TRANS: Link label for feed on "notices with tag" page.
  76. // TRANS: %s is the tag the feed is for.
  77. sprintf(_('Notice feed for tag %s (RSS 1.0)'),
  78. $this->tag)),
  79. new Feed(Feed::RSS2,
  80. common_local_url('ApiTimelineTag',
  81. array('format' => 'rss',
  82. 'tag' => $this->tag)),
  83. // TRANS: Link label for feed on "notices with tag" page.
  84. // TRANS: %s is the tag the feed is for.
  85. sprintf(_('Notice feed for tag %s (RSS 2.0)'),
  86. $this->tag)),
  87. new Feed(Feed::ATOM,
  88. common_local_url('ApiTimelineTag',
  89. array('format' => 'atom',
  90. 'tag' => $this->tag)),
  91. // TRANS: Link label for feed on "notices with tag" page.
  92. // TRANS: %s is the tag the feed is for.
  93. sprintf(_('Notice feed for tag %s (Atom)'),
  94. $this->tag)));
  95. }
  96. protected function showContent()
  97. {
  98. if(Event::handle('StartTagShowContent', array($this))) {
  99. $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
  100. $cnt = $nl->show();
  101. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  102. $this->page, 'tag', array('tag' => $this->tag));
  103. Event::handle('EndTagShowContent', array($this));
  104. }
  105. }
  106. function isReadOnly($args)
  107. {
  108. return true;
  109. }
  110. }