]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/settingsaction.php
new action for when we redirect to login page
[quix0rs-gnu-social.git] / lib / settingsaction.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Base class for settings actions
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Settings
23  * @package   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008-2009 Control Yourself, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Base class for settings group of actions
36  *
37  * @category Settings
38  * @package  Laconica
39  * @author   Evan Prodromou <evan@controlyourself.ca>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://laconi.ca/
42  *
43  * @see      Widget
44  */
45
46 class SettingsAction extends CurrentUserDesignAction
47 {
48     /**
49      * A message for the user.
50      */
51
52     var $msg = null;
53
54     /**
55      * Whether the message is a good one or a bad one.
56      */
57
58     var $success = false;
59
60     /**
61      * Handle input and output a page
62      *
63      * @param array $args $_REQUEST arguments
64      *
65      * @return void
66      */
67
68     function handle($args)
69     {
70         parent::handle($args);
71         if (!common_logged_in()) {
72             $this->clientError(_('Not logged in.'));
73             return;
74         } else if (!common_is_real_login()) {
75             // Cookie theft means that automatic logins can't
76             // change important settings or see private info, and
77             // _all_ our settings are important
78             common_set_returnto($this->selfUrl());
79             $user = common_current_user();
80             if (Event::handle('RedirectToLogin', array($this, $user))) {
81                 if ($user->hasOpenID()) {
82                     common_redirect(common_local_url('openidlogin'), 303);
83                 } else {
84                     common_redirect(common_local_url('login'), 303);
85                 }
86             }
87         } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
88             $this->handlePost();
89         } else {
90             $this->showForm();
91         }
92     }
93
94     /**
95      * Handle a POST request
96      *
97      * @return boolean success flag
98      */
99
100     function handlePost()
101     {
102         return false;
103     }
104
105     /**
106      * show the settings form
107      *
108      * @param string $msg     an extra message for the user
109      * @param string $success good message or bad message?
110      *
111      * @return void
112      */
113
114     function showForm($msg=null, $success=false)
115     {
116         $this->msg     = $msg;
117         $this->success = $success;
118
119         $this->showPage();
120     }
121
122     /**
123      * show human-readable instructions for the page
124      *
125      * @return void
126      */
127
128     function showPageNotice()
129     {
130         if ($this->msg) {
131             $this->element('div', ($this->success) ? 'success' : 'error',
132                            $this->msg);
133         } else {
134             $inst   = $this->getInstructions();
135             $output = common_markup_to_html($inst);
136
137             $this->elementStart('div', 'instructions');
138             $this->raw($output);
139             $this->elementEnd('div');
140         }
141     }
142
143     /**
144      * instructions recipe for sub-classes
145      *
146      * Subclasses should override this to return readable instructions. They'll
147      * be processed by common_markup_to_html().
148      *
149      * @return string instructions text
150      */
151
152     function getInstructions()
153     {
154         return '';
155     }
156
157 }