]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Event/actions/timelist.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / Event / actions / timelist.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, 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  * @category  Event
20  * @package   StatusNet
21  * @author    Zach Copley <zach@status.net>
22  * @copyright 2011 StatusNet, Inc.
23  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
24  * @link      http://status.net/
25  */
26
27 if (!defined('STATUSNET')) {
28     exit(1);
29 }
30
31 /**
32  * Callback handler to populate end time dropdown
33  */
34 class TimelistAction extends Action {
35     private $start;
36     private $duration;
37
38     /**
39      * Get ready
40      *
41      * @param array $args misc. arguments
42      *
43      * @return boolean true
44      */
45     function prepare($args) {
46         parent::prepare($args);
47         $this->start = $this->arg('start');
48         $this->duration = $this->boolean('duration', false);
49         return true;
50     }
51
52     /**
53      * Handle input and ouput something
54      *
55      * @param array $args $_REQUEST arguments
56      *
57      * @return void
58      */
59     function handle($args)
60     {
61         parent::handle($args);
62
63         if (!common_logged_in()) {
64             // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
65             $this->clientError(_m('Not logged in.'));
66         }
67
68         if (!empty($this->start)) {
69             $times = EventTimeList::getTimes($this->start, $this->duration);
70         } else {
71             // TRANS: Client error when submitting a form with unexpected information.
72             $this->clientError(_m('Unexpected form submission.'));
73         }
74
75         if ($this->boolean('ajax')) {
76             header('Content-Type: application/json; charset=utf-8');
77             print json_encode($times);
78         } else {
79             // TRANS: Client error displayed when using an action in a non-AJAX way.
80             $this->clientError(_m('This action is AJAX only.'));
81         }
82     }
83
84     /**
85      * Override the regular error handler to show something more
86      * ajaxy
87      *
88      * @param string $msg   error message
89      * @param int    $code  error code
90      */
91     function clientError($msg, $code = 400) {
92         if ($this->boolean('ajax')) {
93             header('Content-Type: application/json; charset=utf-8');
94             print json_encode(
95                 array(
96                     'success' => false,
97                     'code'    => $code,
98                     'message' => $msg
99                 )
100             );
101         } else {
102             parent::clientError($msg, $code);
103         }
104     }
105 }