]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profileformaction.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[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 class ProfileFormAction extends RedirectingAction
44 {
45     var $profile = null;
46
47     /**
48      * Take arguments for running
49      *
50      * @param array $args $_REQUEST args
51      *
52      * @return boolean success flag
53      */
54     function prepare($args)
55     {
56         parent::prepare($args);
57
58         $this->checkSessionToken();
59
60         if (!common_logged_in()) {
61             if ($_SERVER['REQUEST_METHOD'] == 'POST') {
62             // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
63                 $this->clientError(_('Not logged in.'));
64             } else {
65                 // Redirect to login.
66                 common_set_returnto($this->selfUrl());
67                 $user = common_current_user();
68                 if (Event::handle('RedirectToLogin', array($this, $user))) {
69                     common_redirect(common_local_url('login'), 303);
70                 }
71             }
72             return false;
73         }
74
75         $id = $this->trimmed('profileid');
76
77         if (!$id) {
78             // TRANS: Client error displayed when trying to change user options without specifying a user to work on.
79             $this->clientError(_('No profile specified.'));
80             return false;
81         }
82
83         $this->profile = Profile::staticGet('id', $id);
84
85         if (!$this->profile) {
86             // TRANS: Client error displayed when trying to change user options without specifying an existing user to work on.
87             $this->clientError(_('No profile with that ID.'));
88             return false;
89         }
90
91         return true;
92     }
93
94     /**
95      * Handle request
96      *
97      * Shows a page with list of favorite notices
98      *
99      * @param array $args $_REQUEST args; handled in prepare()
100      *
101      * @return void
102      */
103     function handle($args)
104     {
105         parent::handle($args);
106
107         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
108             $this->handlePost();
109             $this->returnToPrevious();
110         }
111     }
112
113     /**
114      * handle a POST request
115      *
116      * sub-classes should overload this request
117      *
118      * @return void
119      */
120     function handlePost()
121     {
122         // TRANS: Server error displayed when using an unimplemented method.
123         $this->serverError(_("Unimplemented method."));
124     }
125 }