tagrss.php 2.43 KB
Newer Older
tryggvib's avatar
tryggvib committed
1 2
<?php
/*
3
 * StatusNet - the distributed open-source microblogging tool
4
 * Copyright (C) 2008, 2009, StatusNet, Inc.
tryggvib's avatar
tryggvib committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

20
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
tryggvib's avatar
tryggvib committed
21 22 23 24

require_once(INSTALLDIR.'/lib/rssaction.php');

// Formatting of RSS handled by Rss10Action
25 26
class TagrssAction extends Rss10Action
{
Robin Millette's avatar
Robin Millette committed
27
    var $tag;
tryggvib's avatar
tryggvib committed
28

Robin Millette's avatar
Robin Millette committed
29 30 31
    function prepare($args) {
        parent::prepare($args);
        $tag = common_canonical_tag($this->trimmed('tag'));
32 33
        $this->tag = Notice_tag::staticGet('tag', $tag);
        if (!$this->tag) {
34
            // TRANS: Client error when requesting a tag feed for a non-existing tag.
35
            $this->clientError(_('No such tag.'));
36 37
            return false;
        } else {
38
            $this->notices = $this->getNotices($this->limit);
39 40 41
            return true;
        }
    }
tryggvib's avatar
tryggvib committed
42

Robin Millette's avatar
Robin Millette committed
43
    function getNotices($limit=0)
44
    {
45
        $tag = $this->tag;
tryggvib's avatar
tryggvib committed
46

47
        if (is_null($tag)) {
Evan Prodromou's avatar
Evan Prodromou committed
48
            return null;
49
        }
tryggvib's avatar
tryggvib committed
50

51 52 53 54
        $notice = Notice_tag::getStream($tag->tag, 0, ($limit == 0) ? NOTICES_PER_PAGE : $limit);
        while ($notice->fetch()) {
            $notices[] = clone($notice);
        }
tryggvib's avatar
tryggvib committed
55

56 57
        return $notices;
    }
tryggvib's avatar
tryggvib committed
58

Robin Millette's avatar
Robin Millette committed
59
    function getChannel()
60
    {
Robin Millette's avatar
Robin Millette committed
61
        $tagname = $this->tag->tag;
62 63 64
        $c = array('url' => common_local_url('tagrss', array('tag' => $tagname)),
               'title' => $tagname,
               'link' => common_local_url('tagrss', array('tag' => $tagname)),
65 66
               // TRANS: Tag feed description.
               // TRANS: %1$s is the tag name, %2$s is the StatusNet sitename.
67 68
               'description' => sprintf(_('Updates tagged with %1$s on %2$s!'),
                                        $tagname, common_config('site', 'name')));
69 70
        return $c;
    }
71

72
    function isReadOnly($args)
73 74 75
    {
        return true;
    }
tryggvib's avatar
tryggvib committed
76
}