]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ChooseTheme/actions/choosethemesettings.php
Debugging output in OStatus for easier reading+greping
[quix0rs-gnu-social.git] / plugins / ChooseTheme / actions / choosethemesettings.php
1 <?php
2 /**
3  * ChooseTheme - GNU social plugin enabling user to select preferred theme
4  * Copyright (C) 2015, kollektivet0x242.
5  *
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.
10  *
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.
15  *
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/>.
18  *
19  * @author   Knut Erik Hollund <knut.erik@unlike.no>
20  * @copyright 2015 kollektivet0x242. http://www.kollektivet0x242.no
21  *
22  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
23  */
24
25 if (!defined('STATUSNET') && !defined('GNUSOCIAL')) {
26     exit(1);
27 }
28
29 class ChooseThemeSettingsAction extends SettingsAction {
30         
31
32     /**
33      * Title of the page
34      * @return string Page title
35      */
36     function title() {
37         // TRANS: Page title.
38         return _m('Choose theme settings');
39     }
40
41     /**
42      * Instructions for use
43      * @return string Instructions for use
44      */
45     function getInstructions() {
46         // TRANS: Page instructions.
47         return _m('Choose theme');
48     }
49
50     /**
51      * Show the form for ChooseTheme
52      * @return void
53      */
54     function showContent() {
55
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.');
60         }
61         
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);
66         $form->show();
67     }
68
69
70     /**
71      * Handler method
72      *
73      * @param array $argarray is ignored since it's now passed in in prepare()
74      * @return void
75      */
76     function handlePost() {
77                 
78         //Get a list of available themes on instance
79         $available_themes = Theme::listAvailable();
80         $chosen_theme = $available_themes[(int)$this->arg('dwct','0')];
81                 
82         $this->success = true;
83         $this->msg = _m('Settings saved.');
84
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.');
88  
89         $this->showForm(_($this->msg), $this->success);
90     }
91 }
92
93
94 class ChooseThemeForm extends Form {
95
96     protected $prefs = null;
97     
98
99     function __construct($out, $prefs) {
100         parent::__construct($out);
101
102         if ($prefs!=null) {
103                         $this->prefs = $prefs;
104         } else {
105                         $prefs = common_config('site','theme');
106         }
107         
108 }
109
110     /**
111      * Visible or invisible data elements
112      *
113      * Display the form fields that make up the data of the form.
114      * Sub-classes should overload this to show their data.
115      * @return void
116      */
117
118     function formData() {
119
120         //Get a list of available themes on instance
121         $available_themes = Theme::listAvailable();
122                 
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);
127         if($key!=false){
128                 unset($available_themes[$key]);
129         }               
130                 
131         $this->elementStart('fieldset');
132         $this->elementStart('ul', 'form_data');
133         $this->elementStart('li');
134         $this->dropdown('dwct',_m('Themes'),$available_themes,_m('Select a theme'),false, $this->prefs);
135         $this->elementEnd('li');
136         $this->elementEnd('ul');
137         $this->elementEnd('fieldset');
138       
139     }
140
141     /**
142      * Buttons for form actions
143      *
144      * Submit and cancel buttons (or whatever)
145      * Sub-classes should overload this to show their own buttons.
146      * @return void
147      */
148
149     function formActions()
150     {
151         $this->submit('submit', _('Save'));
152     }
153
154     /**
155      * ID of the form
156      *
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
160      */
161
162     function id() {
163         return 'form_choosetheme_prefs';
164     }
165
166     /**
167      * Action of the form.
168      *
169      * URL to post to. Should be overloaded by subclasses to give
170      * somewhere to post to.
171      * @return string URL to post to
172      */
173
174     function action() { 
175         return common_local_url('choosethemesettings');
176     }
177
178     /**
179      * Class of the form. May include space-separated list of multiple classes.
180      *
181      * @return string the form's class
182      */
183
184     function formClass() {
185         return 'form_settings';
186     }
187 }