]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/repeat.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / actions / repeat.php
1 <?php
2
3 /**
4  * Repeat action.
5  *
6  * PHP version 5
7  *
8  * @category Action
9  * @package  StatusNet
10  * @author   Evan Prodromou <evan@status.net>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://status.net/
13  *
14  * StatusNet - the distributed open-source microblogging tool
15  * Copyright (C) 2008, 2009, StatusNet, Inc.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 /**
36  * Repeat action
37  *
38  * @category Action
39  * @package  StatusNet
40  * @author   Evan Prodromou <evan@status.net>
41  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
42  * @link     http://status.net/
43  */
44
45 class RepeatAction extends Action
46 {
47     var $user = null;
48     var $notice = null;
49
50     function prepare($args)
51     {
52         parent::prepare($args);
53
54         $this->user = common_current_user();
55
56         if (empty($this->user)) {
57             $this->clientError(_('Only logged-in users can repeat notices.'));
58             return false;
59         }
60
61         $id = $this->trimmed('notice');
62
63         if (empty($id)) {
64             $this->clientError(_('No notice specified.'));
65             return false;
66         }
67
68         $this->notice = Notice::staticGet('id', $id);
69
70         if (empty($this->notice)) {
71             $this->clientError(_('No notice specified.'));
72             return false;
73         }
74
75         if ($this->user->id == $this->notice->profile_id) {
76             $this->clientError(_("You can't repeat your own notice."));
77             return false;
78         }
79
80         $token  = $this->trimmed('token-'.$id);
81
82         if (empty($token) || $token != common_session_token()) {
83             $this->clientError(_('There was a problem with your session token. Try again, please.'));
84             return false;
85         }
86
87         $profile = $this->user->getProfile();
88
89         if ($profile->hasRepeated($id)) {
90             $this->clientError(_('You already repeated that notice.'));
91             return false;
92         }
93
94         return true;
95     }
96
97     /**
98      * Class handler.
99      *
100      * @param array $args query arguments
101      *
102      * @return void
103      */
104
105     function handle($args)
106     {
107         $repeat = $this->notice->repeat($this->user->id, 'web');
108
109
110
111         if ($this->boolean('ajax')) {
112             $this->startHTML('text/xml;charset=utf-8');
113             $this->elementStart('head');
114             $this->element('title', null, _('Repeated'));
115             $this->elementEnd('head');
116             $this->elementStart('body');
117             $this->element('p', array('id' => 'repeat_response',
118                                       'class' => 'repeated'),
119                                 _('Repeated!'));
120             $this->elementEnd('body');
121             $this->elementEnd('html');
122         } else {
123             // FIXME!
124         }
125     }
126 }