We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

noticesearchrss.php 3.2 KB
Newer Older
1
<?php
Robin Millette's avatar
Robin Millette committed
2 3 4 5 6 7
/**
 * RSS feed for notice search action class.
 *
 * PHP version 5
 *
 * @category Action
8
 * @package  StatusNet
9 10
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
11
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
13
 *
14
 * StatusNet - the distributed open-source microblogging tool
15
 * Copyright (C) 2008, 2009, StatusNet, Inc.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * 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/>.
 */

31
if (!defined('STATUSNET') && !defined('LACONICA')) {
Robin Millette's avatar
Robin Millette committed
32 33
    exit(1);
}
34

Robin Millette's avatar
Robin Millette committed
35
require_once INSTALLDIR.'/lib/rssaction.php';
36

Robin Millette's avatar
Robin Millette committed
37 38 39 40 41 42
/**
 * RSS feed for notice search action class.
 *
 * Formatting of RSS handled by Rss10Action
 *
 * @category Action
43
 * @package  StatusNet
44 45
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
46
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
48
 */
49 50
class NoticesearchrssAction extends Rss10Action
{
51 52
    function init()
    {
53 54
        return true;
    }
55

56 57 58 59 60 61
    function prepare($args)
    {
        parent::prepare($args);
        $this->notices = $this->getNotices();
        return true;
    }
Mike Cochrane's avatar
Mike Cochrane committed
62

Robin Millette's avatar
Robin Millette committed
63
    function getNotices($limit=0)
64
    {
65 66
        $q = $this->trimmed('q');
        $notices = array();
Mike Cochrane's avatar
Mike Cochrane committed
67

68
        $notice = new Notice();
69

70
        $search_engine = $notice->getSearchEngine('notice');
71
        $search_engine->set_sort_mode('chron');
72

73
        if (!$limit) $limit = 20;
74
        $search_engine->limit(0, $limit, true);
75 76 77 78 79
        if (false === $search_engine->query($q)) {
            $cnt = 0;
        } else {
            $cnt = $notice->find();
        }
Mike Cochrane's avatar
Mike Cochrane committed
80

81 82 83 84
        if ($cnt > 0) {
            while ($notice->fetch()) {
                $notices[] = clone($notice);
            }
85
        }
Mike Cochrane's avatar
Mike Cochrane committed
86

87 88
        return $notices;
    }
Mike Cochrane's avatar
Mike Cochrane committed
89

Robin Millette's avatar
Robin Millette committed
90
    function getChannel()
91
    {
92 93
        $q = $this->trimmed('q');
        $c = array('url' => common_local_url('noticesearchrss', array('q' => $q)),
94
                   // TRANS: RSS notice search feed title. %s is the query.
95
                   'title' => sprintf(_('Updates with "%s"'), $q),
96
                   'link' => common_local_url('noticesearch', array('q' => $q)),
97 98 99
                   // TRANS: RSS notice search feed description.
                   // TRANS: %1$s is the query, %2$s is the StatusNet site name.
                   'description' => sprintf(_('Updates matching search term "%1$s" on %2$s.'),
100
                                            $q, common_config('site', 'name')));
101 102
        return $c;
    }
Mike Cochrane's avatar
Mike Cochrane committed
103

Robin Millette's avatar
Robin Millette committed
104
    function getImage()
105
    {
Evan Prodromou's avatar
Evan Prodromou committed
106
        return null;
107
    }
108

109
    function isReadOnly($args)
110 111 112
    {
        return true;
    }
113
}