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