]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profileformaction.php
Merge branch 'testing'
[quix0rs-gnu-social.git] / lib / profileformaction.php
1 <?php
2 /**
3  * Superclass for actions that operate on a user
4  *
5  * PHP version 5
6  *
7  * StatusNet - the distributed open-source microblogging tool
8  * Copyright (C) 2009, StatusNet, Inc.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category Action
24  * @package  StatusNet
25  * @author   Evan Prodromou <evan@status.net>
26  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
27  * @link     http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Superclass for actions that operate on a user
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 ProfileFormAction extends Action
45 {
46     var $profile = null;
47
48     /**
49      * Take arguments for running
50      *
51      * @param array $args $_REQUEST args
52      *
53      * @return boolean success flag
54      */
55
56     function prepare($args)
57     {
58         parent::prepare($args);
59
60         $this->checkSessionToken();
61
62         if (!common_logged_in()) {
63             $this->clientError(_('Not logged in.'));
64             return false;
65         }
66
67         $id = $this->trimmed('profileid');
68
69         if (!$id) {
70             $this->clientError(_('No profile specified.'));
71             return false;
72         }
73
74         $this->profile = Profile::staticGet('id', $id);
75
76         if (!$this->profile) {
77             $this->clientError(_('No profile with that ID.'));
78             return false;
79         }
80
81         return true;
82     }
83
84     /**
85      * Handle request
86      *
87      * Shows a page with list of favorite notices
88      *
89      * @param array $args $_REQUEST args; handled in prepare()
90      *
91      * @return void
92      */
93
94     function handle($args)
95     {
96         parent::handle($args);
97
98         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
99             $this->handlePost();
100             $this->returnToArgs();
101         }
102     }
103
104     /**
105      * Return to the calling page based on hidden arguments
106      *
107      * @return void
108      */
109
110     function returnToArgs()
111     {
112         foreach ($this->args as $k => $v) {
113             if ($k == 'returnto-action') {
114                 $action = $v;
115             } else if (substr($k, 0, 9) == 'returnto-') {
116                 $args[substr($k, 9)] = $v;
117             }
118         }
119
120         if ($action) {
121             common_redirect(common_local_url($action, $args), 303);
122         } else {
123             $this->clientError(_("No return-to arguments."));
124         }
125     }
126
127     /**
128      * handle a POST request
129      *
130      * sub-classes should overload this request
131      *
132      * @return void
133      */
134
135     function handlePost()
136     {
137         $this->serverError(_("Unimplemented method."));
138     }
139 }