]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Sitemap/actions/noticesitemap.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / Sitemap / actions / noticesitemap.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show list of user pages
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  Sitemap
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * sitemap for users
36  *
37  * @category Sitemap
38  * @package  StatusNet
39  * @author   Evan Prodromou <evan@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43 class NoticesitemapAction extends SitemapAction
44 {
45     var $notices = null;
46     var $j = 0;
47
48     function prepare($args)
49     {
50         parent::prepare($args);
51
52         $y = $this->trimmed('year');
53
54         $m = $this->trimmed('month');
55         $d = $this->trimmed('day');
56
57         $i = $this->trimmed('index');
58
59         $y += 0;
60         $m += 0;
61         $d += 0;
62         $i += 0;
63
64         $this->notices = $this->getNotices($y, $m, $d, $i);
65         $this->j       = 0;
66
67         return true;
68     }
69
70     function nextUrl()
71     {
72         if ($this->j < count($this->notices)) {
73             $n = $this->notices[$this->j];
74             $this->j++;
75             return array(common_local_url('shownotice', array('notice' => $n[0])),
76                          common_date_w3dtf($n[1]),
77                          'never',
78                          null);
79         } else {
80             return null;
81         }
82     }
83
84     function getNotices($y, $m, $d, $i)
85     {
86         $n = Notice::cacheGet("sitemap:notice:$y:$m:$d:$i");
87
88         if ($n === false) {
89
90             $notice = new Notice();
91
92             $begindt = sprintf('%04d-%02d-%02d 00:00:00', $y, $m, $d);
93
94             // XXX: estimates 1d == 24h, which screws up days
95             // with leap seconds (1d == 24h + 1s). Thankfully they're
96             // few and far between.
97
98             $theend = strtotime($begindt) + (24 * 60 * 60);
99             $enddt  = common_sql_date($theend);
100
101             $notice->selectAdd();
102             $notice->selectAdd('id, created');
103
104             $notice->whereAdd("created >= '$begindt'");
105             $notice->whereAdd("created <  '$enddt'");
106
107             $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
108
109             $notice->orderBy('created');
110
111             $offset = ($i-1) * SitemapPlugin::NOTICES_PER_MAP;
112             $limit  = SitemapPlugin::NOTICES_PER_MAP;
113
114             $notice->limit($offset, $limit);
115
116             $notice->find();
117
118             $n = array();
119
120             while ($notice->fetch()) {
121                 $n[] = array($notice->id, $notice->created);
122             }
123
124             $c = Cache::instance();
125
126             if (!empty($c)) {
127                 $c->set(Cache::key("sitemap:notice:$y:$m:$d:$i"),
128                         $n,
129                         Cache::COMPRESSED,
130                         ((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60)));
131             }
132         }
133
134         return $n;
135     }
136 }