]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/clearflag.php
remove require_once for disappeared TwitterBasicAuthClient
[quix0rs-gnu-social.git] / plugins / UserFlag / clearflag.php
1 <?php
2 /**
3  * Clear all flags for 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 clear flags for 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 ClearflagAction 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         return true;
66     }
67
68     /**
69      * Handle request
70      *
71      * Overriding the base Action's handle() here to deal check
72      * for Ajax and return an HXR response if necessary
73      *
74      * @param array $args $_REQUEST args; handled in prepare()
75      *
76      * @return void
77      */
78
79     function handle($args)
80     {
81         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
82             $this->handlePost();
83             if (!$this->boolean('ajax')) {
84                 $this->returnToPrevious();
85             }
86         }
87     }
88
89     /**
90      * Handle POST
91      *
92      * Executes the actions; deletes all flags
93      *
94      * @return void
95      */
96
97     function handlePost()
98     {
99         $ufp = new User_flag_profile();
100
101         $result = $ufp->query('UPDATE user_flag_profile ' .
102                               'SET cleared = now() ' .
103                               'WHERE cleared is null ' .
104                               'AND profile_id = ' . $this->profile->id);
105
106         if ($result == false) {
107             $msg = sprintf(_("Couldn't clear flags for profile '%s'."),
108                            $this->profile->nickname);
109             throw new ServerException($msg);
110         }
111
112         $ufp->free();
113
114         if ($this->boolean('ajax')) {
115             $this->ajaxResults();
116         }
117     }
118
119     /**
120      * Return results in ajax form
121      *
122      * @return void
123      */
124
125     function ajaxResults()
126     {
127         header('Content-Type: text/xml;charset=utf-8');
128         $this->xw->startDocument('1.0', 'UTF-8');
129         $this->elementStart('html');
130         $this->elementStart('head');
131         $this->element('title', null, _('Flags cleared'));
132         $this->elementEnd('head');
133         $this->elementStart('body');
134         $this->element('p', 'cleared', _('Cleared'));
135         $this->elementEnd('body');
136         $this->elementEnd('html');
137     }
138 }