123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?php
- defined('GNUSOCIAL') || die();
- class ChooseThemeSettingsAction extends SettingsAction
- {
-
- public function title(): string
- {
-
- return _m('Choose theme settings');
- }
-
- public function getInstructions(): string
- {
-
- return _m('Choose theme');
- }
-
- public function showContent(): void
- {
- $site_theme = common_config('site', 'theme');
- $prefs = $this->scoped->getPref('chosen_theme', 'theme', $site_theme);
- if ($prefs === null) {
- common_debug('No chosen theme found in database for user.');
- }
-
- $available_themes = Theme::listAvailable();
- $chosenone = array_search($prefs, $available_themes, true);
- $form = new ChooseThemeForm($this, $chosenone);
- $form->show();
- }
-
- public function doPost(): string
- {
-
- $available_themes = Theme::listAvailable();
- $chosen_theme = $available_themes[(int)$this->arg('dwct', '0')];
- $this->msg = 'Settings saved.';
- $success = $this->scoped->setPref('chosen_theme', 'theme', $chosen_theme);
-
- if (!$success) {
- $this->msg = 'No valid theme chosen.';
- }
- return _m($this->msg);
- }
- }
- class ChooseThemeForm extends Form
- {
- protected $prefs = null;
- public function __construct($out, $prefs)
- {
- parent::__construct($out);
- if ($prefs != null) {
- $this->prefs = $prefs;
- } else {
- $this->prefs = common_config('site', 'theme');
- }
- }
-
- public function formData(): void
- {
-
- $available_themes = Theme::listAvailable();
-
-
-
- $key = array_search('licenses', $available_themes);
- if ($key != false) {
- unset($available_themes[$key]);
- }
- $this->elementStart('fieldset');
- $this->elementStart('ul', 'form_data');
- $this->elementStart('li');
- $this->dropdown('dwct', _m('Themes'), $available_themes, _m('Select a theme'), false, $this->prefs);
- $this->elementEnd('li');
- $this->elementEnd('ul');
- $this->elementEnd('fieldset');
- }
-
- public function formActions(): void
- {
- $this->submit('submit', _('Save'));
- }
-
- public function id(): string
- {
- return 'form_choosetheme_prefs';
- }
-
- public function action(): string
- {
- return common_local_url('choosethemesettings');
- }
-
- public function formClass(): string
- {
- return 'form_settings';
- }
- }
|