]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Favorite/actions/favor.php
"Notice posted" message in Ajax title for NewnoticeAction
[quix0rs-gnu-social.git] / plugins / Favorite / actions / favor.php
1 <?php
2 /**
3  * Favor action.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  GNUsocial
9  * @author   Evan Prodromou <evan@status.net>
10  * @author   Robin Millette <millette@status.net>
11  * @author   Mikael Nordfeldth <mmn@hethane.se>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://www.gnu.org/software/social/
14  *
15  * StatusNet - the distributed open-source microblogging tool
16  * Copyright (C) 2008, 2009, StatusNet, Inc.
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Affero General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU Affero General Public License for more details.
27  *
28  * You should have received a copy of the GNU Affero General Public License
29  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31
32 if (!defined('GNUSOCIAL')) { exit(1); }
33
34 /**
35  * FavorAction class.
36  *
37  * @category Action
38  * @package  GNUsocial
39  * @author   Evan Prodromou <evan@status.net>
40  * @author   Robin Millette <millette@status.net>
41  * @author   Mikael Nordfeldth <mmn@hethane.se>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://www.gnu.org/software/social/
44  */
45 class FavorAction extends FormAction
46 {
47     protected $needPost = true;
48
49     protected $object = null;
50
51     protected function prepare(array $args=array())
52     {
53         parent::prepare($args);
54
55         $this->target = Notice::getKV($this->trimmed('notice'));
56         if (!$this->target instanceof Notice) {
57             throw new ServerException(_m('No such notice.'));
58         }
59         if (!$this->target->inScope($this->scoped)) {
60             // TRANS: Client error displayed when trying to reply to a notice a the target has no access to.
61             // TRANS: %1$s is a user nickname, %2$d is a notice ID (number).
62             throw new ClientException(sprintf(_m('%1$s has no right to reply to notice %2$d.'), $this->scoped->getNickname(), $this->target->id), 403);
63         }
64
65         return true;
66     }
67
68     protected function handlePost()
69     {
70         parent::handlePost();
71
72         if (Fave::existsForProfile($this->target, $this->scoped)) {
73             // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
74             throw new AlreadyFulfilledException(_('You have already favorited this!'));
75         }
76
77         $now = common_sql_now();
78
79         $act = new Activity();
80         $act->id = Fave::newUri($this->scoped, $this->target, $now);
81         $act->type = Fave::getObjectType();
82         $act->actor = $this->scoped->asActivityObject();
83         $act->target = $this->target->asActivityObject();
84         $act->objects = array(clone($act->target));
85         $act->verb = ActivityVerb::FAVORITE;
86         $act->title = ActivityUtils::verbToTitle($act->verb);
87         $act->time = strtotime($now);
88         // TRANS: Notification given when a user marks a notice as favorite.
89         // TRANS: %1$s is a user name or full name, %2$s is a notice URI, %3$s the link to the user's profile.
90         $act->content = sprintf(_('<a href="%3$s">%1$s</a> marked notice <a href="%2$s">%2$s</a> as a favorite.'),
91                                 htmlspecialchars($this->scoped->getBestName()),
92                                 htmlspecialchars($this->target->getUrl()),
93                                 htmlspecialchars($this->scoped->getUrl()));
94
95
96         $stored = Notice::saveActivity($act, $this->scoped,
97                                         array('uri'=>$act->id));
98
99         Fave::blowCacheForProfileId($this->scoped->id);
100
101         return _('Favorited the notice');
102     }
103
104     protected function showContent()
105     {
106         if ($this->target instanceof Notice) {
107             $disfavor = new DisfavorForm($this, $this->target);
108             $disfavor->show();
109         }
110     }
111 }