]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/settingsaction.php
8624803ac41705150a1d9d815bd89d0fc44648fa
[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 require_once INSTALLDIR.'/lib/settingsgroupnav.php';
35
36 /**
37  * Base class for settings group of actions
38  *
39  * @category Settings
40  * @package  Laconica
41  * @author   Evan Prodromou <evan@controlyourself.ca>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://laconi.ca/
44  *
45  * @see      Widget
46  */
47
48 class SettingsAction extends Action
49 {
50     /**
51      * A message for the user.
52      */
53
54     var $msg = null;
55
56     /**
57      * Whether the message is a good one or a bad one.
58      */
59
60     var $success = false;
61
62     /**
63      * Handle input and output a page
64      *
65      * @param array $args $_REQUEST arguments
66      *
67      * @return void
68      */
69
70     function handle($args)
71     {
72         parent::handle($args);
73         if (!common_logged_in()) {
74             $this->clientError(_('Not logged in.'));
75             return;
76         } else if (!common_is_real_login()) {
77             // Cookie theft means that automatic logins can't
78             // change important settings or see private info, and
79             // _all_ our settings are important
80             common_set_returnto($this->selfUrl());
81             common_redirect(common_local_url('login'));
82         } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
83             $this->handlePost();
84         } else {
85             $this->showForm();
86         }
87     }
88
89     /**
90      * Handle a POST request
91      *
92      * @return boolean success flag
93      */
94
95     function handlePost()
96     {
97         return false;
98     }
99
100     /**
101      * show the settings form
102      *
103      * @param string $msg     an extra message for the user
104      * @param string $success good message or bad message?
105      *
106      * @return void
107      */
108
109     function showForm($msg=null, $success=false)
110     {
111         $this->msg     = $msg;
112         $this->success = $success;
113
114         $this->showPage();
115     }
116
117     /**
118      * show human-readable instructions for the page
119      *
120      * @return void
121      */
122
123     function showPageNotice()
124     {
125         if ($this->msg) {
126             $this->element('div', ($this->success) ? 'success' : 'error',
127                            $this->msg);
128         } else {
129             $inst   = $this->getInstructions();
130             $output = common_markup_to_html($inst);
131
132             $this->elementStart('div', 'instructions');
133             $this->raw($output);
134             $this->elementEnd('div');
135         }
136     }
137
138     /**
139      * instructions recipe for sub-classes
140      *
141      * Subclasses should override this to return readable instructions. They'll
142      * be processed by common_markup_to_html().
143      *
144      * @return string instructions text
145      */
146
147     function getInstructions()
148     {
149         return '';
150     }
151
152     /**
153      * Show the local navigation menu
154      *
155      * This is the same for all settings, so we show it here.
156      *
157      * @return void
158      */
159
160     function showLocalNav()
161     {
162         $menu = new SettingsGroupNav($this);
163         $menu->show();
164     }
165 }