2015-06-06 18:28:34 +09:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ChooseTheme - GNU social plugin enabling user to select preferred theme
|
|
|
|
* Copyright (C) 2015, kollektivet0x242.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @author Knut Erik Hollund <knut.erik@unlike.no>
|
|
|
|
* @copyright 2015 kollektivet0x242. http://www.kollektivet0x242.no
|
|
|
|
*
|
|
|
|
* @license GNU Affero General Public License http://www.gnu.org/licenses/
|
|
|
|
*/
|
|
|
|
|
2019-08-04 22:07:00 +09:00
|
|
|
defined('GNUSOCIAL') || die();
|
2015-06-06 18:28:34 +09:00
|
|
|
|
2019-08-04 22:07:00 +09:00
|
|
|
class ChooseThemeSettingsAction extends SettingsAction
|
|
|
|
{
|
2015-06-06 18:28:34 +09:00
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
* @return string Page title
|
2019-08-04 22:07:00 +09:00
|
|
|
* @throws Exception
|
2015-06-06 18:28:34 +09:00
|
|
|
*/
|
2019-08-04 22:07:00 +09:00
|
|
|
public function title(): string
|
|
|
|
{
|
2015-06-06 18:28:34 +09:00
|
|
|
// TRANS: Page title.
|
|
|
|
return _m('Choose theme settings');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instructions for use
|
|
|
|
* @return string Instructions for use
|
2019-08-04 22:07:00 +09:00
|
|
|
* @throws Exception
|
2015-06-06 18:28:34 +09:00
|
|
|
*/
|
2019-08-04 22:07:00 +09:00
|
|
|
public function getInstructions(): string
|
|
|
|
{
|
2015-06-06 18:28:34 +09:00
|
|
|
// TRANS: Page instructions.
|
|
|
|
return _m('Choose theme');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for ChooseTheme
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-08-04 22:07:00 +09:00
|
|
|
public function showContent(): void
|
|
|
|
{
|
|
|
|
$site_theme = common_config('site', 'theme');
|
|
|
|
$prefs = $this->scoped->getPref('chosen_theme', 'theme', $site_theme);
|
2015-06-06 18:28:34 +09:00
|
|
|
if ($prefs === null) {
|
|
|
|
common_debug('No chosen theme found in database for user.');
|
|
|
|
}
|
2019-08-04 22:07:00 +09:00
|
|
|
|
|
|
|
//Get a list of available themes on instance
|
|
|
|
$available_themes = Theme::listAvailable();
|
|
|
|
$chosenone = array_search($prefs, $available_themes, true);
|
2015-06-06 18:28:34 +09:00
|
|
|
$form = new ChooseThemeForm($this, $chosenone);
|
|
|
|
$form->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler method
|
|
|
|
*
|
2019-08-04 22:07:00 +09:00
|
|
|
* @return string
|
|
|
|
* @throws Exception
|
2015-06-06 18:28:34 +09:00
|
|
|
*/
|
2019-08-04 22:07:00 +09:00
|
|
|
public function doPost(): string
|
|
|
|
{
|
|
|
|
//Get a list of available themes on instance
|
|
|
|
$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);
|
|
|
|
// TRANS: Confirmation shown when user profile settings are saved.
|
|
|
|
if (!$success) {
|
|
|
|
$this->msg = 'No valid theme chosen.';
|
|
|
|
}
|
|
|
|
|
|
|
|
return _m($this->msg);
|
2015-06-06 18:28:34 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-04 22:07:00 +09:00
|
|
|
class ChooseThemeForm extends Form
|
|
|
|
{
|
2015-06-06 18:28:34 +09:00
|
|
|
protected $prefs = null;
|
|
|
|
|
2019-08-04 22:07:00 +09:00
|
|
|
|
|
|
|
public function __construct($out, $prefs)
|
|
|
|
{
|
2015-06-06 18:28:34 +09:00
|
|
|
parent::__construct($out);
|
|
|
|
|
2019-08-04 22:07:00 +09:00
|
|
|
if ($prefs != null) {
|
|
|
|
$this->prefs = $prefs;
|
|
|
|
} else {
|
|
|
|
$this->prefs = common_config('site', 'theme');
|
|
|
|
}
|
|
|
|
}
|
2015-06-06 18:28:34 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Visible or invisible data elements
|
|
|
|
*
|
|
|
|
* Display the form fields that make up the data of the form.
|
|
|
|
* Sub-classes should overload this to show their data.
|
|
|
|
* @return void
|
2019-08-04 22:07:00 +09:00
|
|
|
* @throws Exception
|
2015-06-06 18:28:34 +09:00
|
|
|
*/
|
|
|
|
|
2019-08-04 22:07:00 +09:00
|
|
|
public function formData(): void
|
|
|
|
{
|
|
|
|
|
|
|
|
//Get a list of available themes on instance
|
|
|
|
$available_themes = Theme::listAvailable();
|
|
|
|
|
|
|
|
//Remove theme 'licenses' from selectable themes.
|
|
|
|
//The 'licenses' theme is not an actual theme and
|
|
|
|
//will just mess-up the gui.
|
|
|
|
$key = array_search('licenses', $available_themes);
|
|
|
|
if ($key != false) {
|
|
|
|
unset($available_themes[$key]);
|
|
|
|
}
|
|
|
|
|
2015-06-06 18:28:34 +09:00
|
|
|
$this->elementStart('fieldset');
|
|
|
|
$this->elementStart('ul', 'form_data');
|
|
|
|
$this->elementStart('li');
|
2019-08-04 22:07:00 +09:00
|
|
|
$this->dropdown('dwct', _m('Themes'), $available_themes, _m('Select a theme'), false, $this->prefs);
|
2015-06-06 18:28:34 +09:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementEnd('ul');
|
|
|
|
$this->elementEnd('fieldset');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Buttons for form actions
|
|
|
|
*
|
|
|
|
* Submit and cancel buttons (or whatever)
|
|
|
|
* Sub-classes should overload this to show their own buttons.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2019-08-04 22:07:00 +09:00
|
|
|
public function formActions(): void
|
2015-06-06 18:28:34 +09:00
|
|
|
{
|
|
|
|
$this->submit('submit', _('Save'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ID of the form
|
|
|
|
*
|
|
|
|
* Should be unique on the page. Sub-classes should overload this
|
|
|
|
* to show their own IDs.
|
2019-08-04 22:07:00 +09:00
|
|
|
* @return string ID of the form
|
2015-06-06 18:28:34 +09:00
|
|
|
*/
|
|
|
|
|
2019-08-04 22:07:00 +09:00
|
|
|
public function id(): string
|
|
|
|
{
|
2015-06-06 18:28:34 +09:00
|
|
|
return 'form_choosetheme_prefs';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action of the form.
|
|
|
|
*
|
|
|
|
* URL to post to. Should be overloaded by subclasses to give
|
|
|
|
* somewhere to post to.
|
|
|
|
* @return string URL to post to
|
|
|
|
*/
|
|
|
|
|
2019-08-04 22:07:00 +09:00
|
|
|
public function action(): string
|
|
|
|
{
|
2015-06-06 18:28:34 +09:00
|
|
|
return common_local_url('choosethemesettings');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class of the form. May include space-separated list of multiple classes.
|
|
|
|
*
|
|
|
|
* @return string the form's class
|
|
|
|
*/
|
|
|
|
|
2019-08-04 22:07:00 +09:00
|
|
|
public function formClass(): string
|
|
|
|
{
|
2015-06-06 18:28:34 +09:00
|
|
|
return 'form_settings';
|
|
|
|
}
|
|
|
|
}
|