3 * ChooseTheme - GNU social plugin enabling user to select preferred theme
4 * Copyright (C) 2015, kollektivet0x242.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @author Knut Erik Hollund <knut.erik@unlike.no>
20 * @copyright 2015 kollektivet0x242. http://www.kollektivet0x242.no
22 * @license GNU Affero General Public License http://www.gnu.org/licenses/
25 if (!defined('STATUSNET') && !defined('GNUSOCIAL')) {
29 class ChooseThemeSettingsAction extends SettingsAction {
34 * @return string Page title
38 return _m('Choose theme settings');
42 * Instructions for use
43 * @return string Instructions for use
45 function getInstructions() {
46 // TRANS: Page instructions.
47 return _m('Choose theme');
51 * Show the form for ChooseTheme
54 function showContent() {
56 $site_theme = common_config('site','theme');
57 $prefs = $this->scoped->getPref('chosen_theme', 'theme',$site_theme);
58 if ($prefs === null) {
59 common_debug('No chosen theme found in database for user.');
62 //Get a list of available themes on instance
63 $available_themes = Theme::listAvailable();
64 $chosenone = array_search($prefs,$available_themes,true);
65 $form = new ChooseThemeForm($this, $chosenone);
73 * @param array $argarray is ignored since it's now passed in in prepare()
76 function handlePost() {
78 //Get a list of available themes on instance
79 $available_themes = Theme::listAvailable();
80 $chosen_theme = $available_themes[(int)$this->arg('dwct','0')];
82 $this->success = true;
83 $this->msg = _('Settings saved.');
85 $this->success = $this->scoped->setPref('chosen_theme', 'theme', $chosen_theme);
86 // TRANS: Confirmation shown when user profile settings are saved.
87 if(!$this->success) $this->msg = _('No valid theme chosen.');
89 $this->showForm(_($this->msg), $this->success);
94 class ChooseThemeForm extends Form {
96 protected $prefs = null;
99 function __construct($out, $prefs) {
100 parent::__construct($out);
103 $this->prefs = $prefs;
105 $prefs = common_config('site','theme');
111 * Visible or invisible data elements
113 * Display the form fields that make up the data of the form.
114 * Sub-classes should overload this to show their data.
118 function formData() {
120 //Get a list of available themes on instance
121 $available_themes = Theme::listAvailable();
123 //Remove theme 'licenses' from selectable themes.
124 //The 'licenses' theme is not an actual theme and
125 //will just mess-up the gui.
126 $key = array_search('licenses',$available_themes);
128 unset($available_themes[$key]);
131 $this->elementStart('fieldset');
132 $this->elementStart('ul', 'form_data');
133 $this->elementStart('li');
134 $this->dropdown('dwct','Themes',$available_themes,'Select a theme',false, $this->prefs);
135 $this->elementEnd('li');
136 $this->elementEnd('ul');
137 $this->elementEnd('fieldset');
142 * Buttons for form actions
144 * Submit and cancel buttons (or whatever)
145 * Sub-classes should overload this to show their own buttons.
149 function formActions()
151 $this->submit('submit', _('Save'));
157 * Should be unique on the page. Sub-classes should overload this
158 * to show their own IDs.
159 * @return int ID of the form
163 return 'form_choosetheme_prefs';
167 * Action of the form.
169 * URL to post to. Should be overloaded by subclasses to give
170 * somewhere to post to.
171 * @return string URL to post to
175 return common_local_url('choosethemesettings');
179 * Class of the form. May include space-separated list of multiple classes.
181 * @return string the form's class
184 function formClass() {
185 return 'form_settings';