]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Bookmark/actions/noticebyurl.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / Bookmark / actions / noticebyurl.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * Notice stream of notices with a given attachment
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Bookmark
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2010 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * List notices that contain/link to/use a given URL
39  *
40  * @category  Bookmark
41  * @package   StatusNet
42  * @author    Evan Prodromou <evan@status.net>
43  * @copyright 2010 StatusNet, Inc.
44  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45  * @link      http://status.net/
46  */
47 class NoticebyurlAction extends Action
48 {
49     protected $url     = null;
50     protected $file    = null;
51     protected $notices = null;
52     protected $page    = null;
53
54     /**
55      * For initializing members of the class.
56      *
57      * @param array $argarray misc. arguments
58      *
59      * @return boolean true
60      */
61     function prepare($argarray)
62     {
63         parent::prepare($argarray);
64
65         $this->file = File::getKV('id', $this->trimmed('id'));
66
67         if (empty($this->file)) {
68             // TRANS: Client exception thrown when an unknown URL is provided.
69             throw new ClientException(_m('Unknown URL.'));
70         }
71
72         $pageArg = $this->trimmed('page');
73
74         $this->page = (empty($pageArg)) ? 1 : intval($pageArg);
75
76         $this->notices = $this->file->stream(($this->page - 1) * NOTICES_PER_PAGE,
77                                              NOTICES_PER_PAGE + 1);
78
79         return true;
80     }
81
82     /**
83      * Title of the page
84      *
85      * @return string page title
86      */
87     function title()
88     {
89         if ($this->page == 1) {
90             // TRANS: Title of notice stream of notices with a given attachment (first page).
91             // TRANS: %s is the URL.
92             return sprintf(_m('Notices linking to %s'), $this->file->url);
93         } else {
94             // TRANS: Title of notice stream of notices with a given attachment (all but first page).
95             // TRANS: %1$s is the URL, %2$s is the page number.
96             return sprintf(_m('Notices linking to %1$s, page %2$d'),
97                            $this->file->url,
98                            $this->page);
99         }
100     }
101
102     /**
103      * Handler method
104      *
105      * @param array $argarray is ignored since it's now passed in in prepare()
106      *
107      * @return void
108      */
109     function handle($argarray=null)
110     {
111         $this->showPage();
112     }
113
114     /**
115      * Show main page content.
116      *
117      * Shows a list of the notices that link to the given URL
118      *
119      * @return void
120      */
121     function showContent()
122     {
123         $nl = new NoticeList($this->notices, $this);
124
125         $nl->show();
126
127         $cnt = $nl->show();
128
129         $this->pagination($this->page > 1,
130                           $cnt > NOTICES_PER_PAGE,
131                           $this->page,
132                           'noticebyurl',
133                           array('id' => $this->file->id));
134     }
135
136     /**
137      * Return true if read only.
138      *
139      * MAY override
140      *
141      * @param array $args other arguments
142      *
143      * @return boolean is read only action?
144      */
145     function isReadOnly($args)
146     {
147         return true;
148     }
149
150     /**
151      * Return last modified, if applicable.
152      *
153      * MAY override
154      *
155      * @return string last modified http header
156      */
157     function lastModified()
158     {
159         // For comparison with If-Last-Modified
160         // If not applicable, return null
161         return null;
162     }
163
164     /**
165      * Return etag, if applicable.
166      *
167      * MAY override
168      *
169      * @return string etag http header
170      */
171     function etag()
172     {
173         return null;
174     }
175 }