tag.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. common_redirect(common_local_url('publictagcloud'), 301);
  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, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
  41. if($this->page > 1 && $this->notice->N == 0){
  42. // TRANS: Client error when page not found (404).
  43. $this->clientError(_('No such page.'), 404);
  44. }
  45. return true;
  46. }
  47. function title()
  48. {
  49. if ($this->page == 1) {
  50. // TRANS: Title for first page of notices with tags.
  51. // TRANS: %s is the tag.
  52. return sprintf(_('Notices tagged with %s'), $this->tag);
  53. } else {
  54. // TRANS: Title for all but the first page of notices with tags.
  55. // TRANS: %1$s is the tag, %2$d is the page number.
  56. return sprintf(_('Notices tagged with %1$s, page %2$d'),
  57. $this->tag,
  58. $this->page);
  59. }
  60. }
  61. function getFeeds()
  62. {
  63. return array(new Feed(Feed::JSON,
  64. common_local_url('ApiTimelineTag',
  65. array('format' => 'as',
  66. 'tag' => $this->tag)),
  67. // TRANS: Link label for feed on "notices with tag" page.
  68. // TRANS: %s is the tag the feed is for.
  69. sprintf(_('Notice feed for tag %s (Activity Streams JSON)'),
  70. $this->tag)),
  71. new Feed(Feed::RSS1,
  72. common_local_url('tagrss',
  73. array('tag' => $this->tag)),
  74. // TRANS: Link label for feed on "notices with tag" page.
  75. // TRANS: %s is the tag the feed is for.
  76. sprintf(_('Notice feed for tag %s (RSS 1.0)'),
  77. $this->tag)),
  78. new Feed(Feed::RSS2,
  79. common_local_url('ApiTimelineTag',
  80. array('format' => 'rss',
  81. 'tag' => $this->tag)),
  82. // TRANS: Link label for feed on "notices with tag" page.
  83. // TRANS: %s is the tag the feed is for.
  84. sprintf(_('Notice feed for tag %s (RSS 2.0)'),
  85. $this->tag)),
  86. new Feed(Feed::ATOM,
  87. common_local_url('ApiTimelineTag',
  88. array('format' => 'atom',
  89. 'tag' => $this->tag)),
  90. // TRANS: Link label for feed on "notices with tag" page.
  91. // TRANS: %s is the tag the feed is for.
  92. sprintf(_('Notice feed for tag %s (Atom)'),
  93. $this->tag)));
  94. }
  95. protected function showContent()
  96. {
  97. if(Event::handle('StartTagShowContent', array($this))) {
  98. $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
  99. $cnt = $nl->show();
  100. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  101. $this->page, 'tag', array('tag' => $this->tag));
  102. Event::handle('EndTagShowContent', array($this));
  103. }
  104. }
  105. function isReadOnly($args)
  106. {
  107. return true;
  108. }
  109. }