]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/actions/flagprofile.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / UserFlag / actions / 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 class FlagprofileAction extends ProfileFormAction
44 {
45     /**
46      * Take arguments for running
47      *
48      * @param array $args $_REQUEST args
49      *
50      * @return boolean success flag
51      */
52     function prepare(array $args=array())
53     {
54         if (!parent::prepare($args)) {
55             return false;
56         }
57
58         $user = common_current_user();
59
60         assert(!empty($user)); // checked above
61         assert(!empty($this->profile)); // checked above
62
63         return true;
64     }
65
66     /**
67      * Handle request
68      *
69      * Overriding the base Action's handle() here to deal check
70      * for Ajax and return an HXR response if necessary
71      *
72      * @param array $args $_REQUEST args; handled in prepare()
73      *
74      * @return void
75      */
76     function handle(array $args=array())
77     {
78         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
79             $this->handlePost();
80             if (!$this->boolean('ajax')) {
81                 $this->returnToPrevious();
82             }
83         }
84     }
85
86     /**
87      * Handle POST
88      *
89      * @return void
90      */
91     function handlePost()
92     {
93         $user = common_current_user();
94
95         assert(!empty($user));
96         assert(!empty($this->profile));
97
98         // throws an exception on error
99
100         if (User_flag_profile::exists($this->profile->id,
101                                       $user->id)) {
102             // We'll return to the profile page (or return the updated AJAX form)
103             // showing the current state, so no harm done.
104         } else {
105             User_flag_profile::create($user->id, $this->profile->id);
106         }
107
108         if ($this->boolean('ajax')) {
109             $this->ajaxResults();
110         }
111     }
112
113     /**
114      * Return results as AJAX message
115      *
116      * @return void
117      */
118     function ajaxResults()
119     {
120         $this->startHTML('text/xml;charset=utf-8');
121         $this->elementStart('head');
122         // TRANS: AJAX form title for a flagged profile.
123         $this->element('title', null, _m('Flagged for review'));
124         $this->elementEnd('head');
125         $this->elementStart('body');
126         // TRANS: Body text for AJAX form when a profile has been flagged for review.
127         $this->element('p', 'flagged', _m('Flagged'));
128         $this->elementEnd('body');
129         $this->endHTML();
130     }
131 }