]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/oldschoolsettings.php
Misses this file to merge. I like the comments.
[quix0rs-gnu-social.git] / actions / oldschoolsettings.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Settings panel for old-school UI
7  * 
8  * PHP version 5
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  Oldschool
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Old-school settings
39  *
40  * @category  Oldschool
41  * @package   StatusNet
42  * @author    Evan Prodromou <evan@status.net>
43  * @copyright 2011 StatusNet, Inc.
44  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45  * @link      http://status.net/
46  */
47
48 class OldschoolsettingsAction extends SettingsAction
49 {
50     /**
51      * Title of the page
52      *
53      * @return string Title of the page
54      */
55     function title()
56     {
57         // TRANS: Page title for profile settings.
58         return _('Old school UI settings');
59     }
60
61     /**
62      * Instructions for use
63      *
64      * @return instructions for use
65      */
66     function getInstructions()
67     {
68         // TRANS: Usage instructions for profile settings.
69         return _('If you like it "the old way", you can set that here.');
70     }
71
72     /**
73      * For initializing members of the class.
74      *
75      * @param array $argarray misc. arguments
76      *
77      * @return boolean true
78      */
79
80     function prepare($argarray)
81     {
82         if (!common_config('oldschool', 'enabled')) {
83             throw new ClientException("Old-school settings not enabled.");
84         }
85         parent::prepare($argarray);
86         return true;
87     }
88
89     /**
90      * Handler method
91      *
92      * @param array $argarray is ignored since it's now passed in in prepare()
93      *
94      * @return void
95      */
96
97     function handlePost()
98     {
99         $user = common_current_user();
100
101         $osp = Old_school_prefs::getKV('user_id', $user->id);
102         $orig = null;
103
104         if (!empty($osp)) {
105             $orig = clone($osp);
106         } else {
107             $osp = new Old_school_prefs();
108             $osp->user_id = $user->id;
109             $osp->created = common_sql_now();
110         }
111
112         $osp->stream_mode_only  = $this->boolean('stream_mode_only');
113         $osp->stream_nicknames  = $this->boolean('stream_nicknames');
114         $osp->modified          = common_sql_now();
115
116         if (!empty($orig)) {
117             $osp->update($orig);
118         } else {
119             $osp->insert();
120         }
121
122         // TRANS: Confirmation shown when user profile settings are saved.
123         $this->showForm(_('Settings saved.'), true);
124
125         return;
126     }
127
128     function showContent()
129     {
130         $user = common_current_user();
131         $form = new OldSchoolForm($this, $user);
132         $form->show();
133     }
134 }
135
136 class OldSchoolForm extends Form
137 {
138     var $user;
139
140     function __construct($out, $user)
141     {
142         parent::__construct($out);
143         $this->user = $user;
144     }
145
146     /**
147      * Visible or invisible data elements
148      *
149      * Display the form fields that make up the data of the form.
150      * Sub-classes should overload this to show their data.
151      *
152      * @return void
153      */
154
155     function formData()
156     {
157         $this->elementStart('fieldset');
158         $this->elementStart('ul', 'form_data');
159         $this->elementStart('li');
160         $this->checkbox('stream_mode_only', _('Only stream mode (no conversations) in timelines'),
161                         $this->user->streamModeOnly());
162         $this->elementEnd('li');
163         $this->elementStart('li');
164         $this->checkbox('stream_nicknames', _('Show nicknames (not full names) in timelines'),
165                         $this->user->streamNicknames());
166         $this->elementEnd('li');
167         $this->elementEnd('fieldset');
168         $this->elementEnd('ul');
169     }
170
171     /**
172      * Buttons for form actions
173      *
174      * Submit and cancel buttons (or whatever)
175      * Sub-classes should overload this to show their own buttons.
176      *
177      * @return void
178      */
179
180     function formActions()
181     {
182         $this->submit('submit', _('Save'));
183     }
184
185     /**
186      * ID of the form
187      *
188      * Should be unique on the page. Sub-classes should overload this
189      * to show their own IDs.
190      *
191      * @return int ID of the form
192      */
193
194     function id()
195     {
196         return 'form_oldschool';
197     }
198
199     /**
200      * Action of the form.
201      *
202      * URL to post to. Should be overloaded by subclasses to give
203      * somewhere to post to.
204      *
205      * @return string URL to post to
206      */
207
208     function action()
209     {
210         return common_local_url('oldschoolsettings');
211     }
212
213     /**
214      * Class of the form. May include space-separated list of multiple classes.
215      *
216      * @return string the form's class
217      */
218
219     function formClass()
220     {
221         return 'form_settings';
222     }
223 }