]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/flagprofile.php
Merge commit 'origin/0.9.x' into 0.9.x
[quix0rs-gnu-social.git] / plugins / UserFlag / flagprofile.php
1 <?php
2 /**
3  * Add a flag to a profile
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) 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  * Action to flag a profile.
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
44 class FlagprofileAction extends ProfileFormAction
45 {
46     /**
47      * Take arguments for running
48      *
49      * @param array $args $_REQUEST args
50      *
51      * @return boolean success flag
52      */
53
54     function prepare($args)
55     {
56         if (!parent::prepare($args)) {
57             return false;
58         }
59
60         $user = common_current_user();
61
62         assert(!empty($user)); // checked above
63         assert(!empty($this->profile)); // checked above
64
65         if (User_flag_profile::exists($this->profile->id,
66                                       $user->id))
67         {
68             $this->clientError(_('Flag already exists.'));
69             return false;
70         }
71
72         return true;
73     }
74
75
76     /**
77      * Handle request
78      *
79      * Overriding the base Action's handle() here to deal check
80      * for Ajax and return an HXR response if necessary
81      *
82      * @param array $args $_REQUEST args; handled in prepare()
83      *
84      * @return void
85      */
86
87     function handle($args)
88     {
89         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
90             $this->handlePost();
91             if (!$this->boolean('ajax')) {
92                 $this->returnToArgs();
93             }
94         }
95     }
96
97     /**
98      * Handle POST
99      *
100      * @return void
101      */
102
103     function handlePost()
104     {
105         $user = common_current_user();
106
107         assert(!empty($user));
108         assert(!empty($this->profile));
109
110         $ufp = new User_flag_profile();
111
112         $ufp->profile_id = $this->profile->id;
113         $ufp->user_id    = $user->id;
114         $ufp->created    = common_sql_now();
115
116         if (!$ufp->insert()) {
117             throw new ServerException(sprintf(_("Couldn't flag profile '%s' for review."),
118                                               $this->profile->nickname));
119         }
120
121         $ufp->free();
122
123         if ($this->boolean('ajax')) {
124             $this->ajaxResults();
125         }
126     }
127
128     function ajaxResults() {
129         header('Content-Type: text/xml;charset=utf-8');
130         $this->xw->startDocument('1.0', 'UTF-8');
131         $this->elementStart('html');
132         $this->elementStart('head');
133         $this->element('title', null, _('Flagged for review'));
134         $this->elementEnd('head');
135         $this->elementStart('body');
136         $this->element('p', 'flagged', _('Flagged'));
137         $this->elementEnd('body');
138         $this->elementEnd('html');
139     }
140 }
141