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