[ChooseTheme] Fixed plugin
This commit is contained in:
parent
0ecf9eb649
commit
66edc49bcf
|
@ -22,22 +22,26 @@
|
||||||
* @license GNU Affero General Public License http://www.gnu.org/licenses/
|
* @license GNU Affero General Public License http://www.gnu.org/licenses/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ChooseThemePlugin extends Plugin {
|
defined('GNUSOCIAL') || die();
|
||||||
|
|
||||||
|
class ChooseThemePlugin extends Plugin
|
||||||
|
{
|
||||||
const PLUGIN_VERSION = '0.1.0';
|
const PLUGIN_VERSION = '0.1.0';
|
||||||
|
|
||||||
public function onRouterInitialized(URLMapper $m) {
|
public function onRouterInitialized(URLMapper $m)
|
||||||
|
{
|
||||||
$m->connect('main/choosethemesettings', ['action' => 'choosethemesettings']);
|
$m->connect('main/choosethemesettings', ['action' => 'choosethemesettings']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPluginVersion(array &$versions): bool {
|
public function onPluginVersion(array &$versions): bool
|
||||||
|
{
|
||||||
$versions[] = array('name' => 'ChooseTheme',
|
$versions[] = ['name' => 'ChooseTheme',
|
||||||
'version' => self::PLUGIN_VERSION,
|
'version' => self::PLUGIN_VERSION,
|
||||||
'author' => 'Knut Erik "abjectio" Hollund',
|
'author' => 'Knut Erik "abjectio" Hollund',
|
||||||
'homepage' => 'https://gitlab.com/kollektivet0x242/gsp-choosetheme',
|
'homepage' => 'https://gitlab.com/kollektivet0x242/gsp-choosetheme',
|
||||||
'rawdescription' =>
|
'rawdescription' =>
|
||||||
// TRANS: Plugin description.
|
// TRANS: Module description.
|
||||||
_m('Allowing user to select the preferred theme.'));
|
_m('Allowing user to select the preferred theme.')];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,24 +50,28 @@ class ChooseThemePlugin extends Plugin {
|
||||||
*
|
*
|
||||||
* @param Action $action action being executed
|
* @param Action $action action being executed
|
||||||
*
|
*
|
||||||
* @return boolean hook return
|
* @return bool hook return
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function onEndAccountSettingsNav(Action $action) {
|
public function onEndAccountSettingsNav(Action $action): bool
|
||||||
|
{
|
||||||
$action_name = $action->getActionName();
|
$action_name = $action->getActionName();
|
||||||
|
|
||||||
$action->menuItem(common_local_url('choosethemesettings'),
|
$action->menuItem(
|
||||||
|
common_local_url('choosethemesettings'),
|
||||||
// TRANS: Poll plugin menu item on user settings page.
|
// TRANS: Poll plugin menu item on user settings page.
|
||||||
_m('MENU', 'Theme'),
|
_m('MENU', 'Theme'),
|
||||||
// TRANS: Poll plugin tooltip for user settings menu item.
|
// TRANS: Poll plugin tooltip for user settings menu item.
|
||||||
_m('Choose Theme'),
|
_m('Choose Theme'),
|
||||||
$action_name === 'themesettings');
|
$action_name === 'themesettings'
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function onStartShowStylesheets(Action $action) {
|
public function onStartShowStylesheets(Action $action)
|
||||||
|
{
|
||||||
//get the theme and set the current config for site and theme.
|
//get the theme and set the current config for site and theme.
|
||||||
if ($action->getScoped() instanceof Profile) {
|
if ($action->getScoped() instanceof Profile) {
|
||||||
$site_theme = common_config('site', 'theme');
|
$site_theme = common_config('site', 'theme');
|
||||||
|
|
|
@ -22,18 +22,17 @@
|
||||||
* @license GNU Affero General Public License http://www.gnu.org/licenses/
|
* @license GNU Affero General Public License http://www.gnu.org/licenses/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET') && !defined('GNUSOCIAL')) {
|
defined('GNUSOCIAL') || die();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
class ChooseThemeSettingsAction extends SettingsAction {
|
|
||||||
|
|
||||||
|
|
||||||
|
class ChooseThemeSettingsAction extends SettingsAction
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Title of the page
|
* Title of the page
|
||||||
* @return string Page title
|
* @return string Page title
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function title() {
|
public function title(): string
|
||||||
|
{
|
||||||
// TRANS: Page title.
|
// TRANS: Page title.
|
||||||
return _m('Choose theme settings');
|
return _m('Choose theme settings');
|
||||||
}
|
}
|
||||||
|
@ -41,8 +40,10 @@ class ChooseThemeSettingsAction extends SettingsAction {
|
||||||
/**
|
/**
|
||||||
* Instructions for use
|
* Instructions for use
|
||||||
* @return string Instructions for use
|
* @return string Instructions for use
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function getInstructions() {
|
public function getInstructions(): string
|
||||||
|
{
|
||||||
// TRANS: Page instructions.
|
// TRANS: Page instructions.
|
||||||
return _m('Choose theme');
|
return _m('Choose theme');
|
||||||
}
|
}
|
||||||
|
@ -51,8 +52,8 @@ class ChooseThemeSettingsAction extends SettingsAction {
|
||||||
* Show the form for ChooseTheme
|
* Show the form for ChooseTheme
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function showContent() {
|
public function showContent(): void
|
||||||
|
{
|
||||||
$site_theme = common_config('site', 'theme');
|
$site_theme = common_config('site', 'theme');
|
||||||
$prefs = $this->scoped->getPref('chosen_theme', 'theme', $site_theme);
|
$prefs = $this->scoped->getPref('chosen_theme', 'theme', $site_theme);
|
||||||
if ($prefs === null) {
|
if ($prefs === null) {
|
||||||
|
@ -70,41 +71,42 @@ class ChooseThemeSettingsAction extends SettingsAction {
|
||||||
/**
|
/**
|
||||||
* Handler method
|
* Handler method
|
||||||
*
|
*
|
||||||
* @param array $argarray is ignored since it's now passed in in prepare()
|
* @return string
|
||||||
* @return void
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function handlePost() {
|
public function doPost(): string
|
||||||
|
{
|
||||||
//Get a list of available themes on instance
|
//Get a list of available themes on instance
|
||||||
$available_themes = Theme::listAvailable();
|
$available_themes = Theme::listAvailable();
|
||||||
$chosen_theme = $available_themes[(int)$this->arg('dwct', '0')];
|
$chosen_theme = $available_themes[(int)$this->arg('dwct', '0')];
|
||||||
|
|
||||||
$this->success = true;
|
$this->msg = 'Settings saved.';
|
||||||
$this->msg = _m('Settings saved.');
|
|
||||||
|
|
||||||
$this->success = $this->scoped->setPref('chosen_theme', 'theme', $chosen_theme);
|
$success = $this->scoped->setPref('chosen_theme', 'theme', $chosen_theme);
|
||||||
// TRANS: Confirmation shown when user profile settings are saved.
|
// TRANS: Confirmation shown when user profile settings are saved.
|
||||||
if(!$this->success) $this->msg = _('No valid theme chosen.');
|
if (!$success) {
|
||||||
|
$this->msg = 'No valid theme chosen.';
|
||||||
|
}
|
||||||
|
|
||||||
$this->showForm(_($this->msg), $this->success);
|
return _m($this->msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ChooseThemeForm extends Form {
|
class ChooseThemeForm extends Form
|
||||||
|
{
|
||||||
protected $prefs = null;
|
protected $prefs = null;
|
||||||
|
|
||||||
|
|
||||||
function __construct($out, $prefs) {
|
public function __construct($out, $prefs)
|
||||||
|
{
|
||||||
parent::__construct($out);
|
parent::__construct($out);
|
||||||
|
|
||||||
if ($prefs != null) {
|
if ($prefs != null) {
|
||||||
$this->prefs = $prefs;
|
$this->prefs = $prefs;
|
||||||
} else {
|
} else {
|
||||||
$prefs = common_config('site','theme');
|
$this->prefs = common_config('site', 'theme');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,9 +115,11 @@ class ChooseThemeForm extends Form {
|
||||||
* Display the form fields that make up the data of the form.
|
* Display the form fields that make up the data of the form.
|
||||||
* Sub-classes should overload this to show their data.
|
* Sub-classes should overload this to show their data.
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function formData() {
|
public function formData(): void
|
||||||
|
{
|
||||||
|
|
||||||
//Get a list of available themes on instance
|
//Get a list of available themes on instance
|
||||||
$available_themes = Theme::listAvailable();
|
$available_themes = Theme::listAvailable();
|
||||||
|
@ -135,7 +139,6 @@ class ChooseThemeForm extends Form {
|
||||||
$this->elementEnd('li');
|
$this->elementEnd('li');
|
||||||
$this->elementEnd('ul');
|
$this->elementEnd('ul');
|
||||||
$this->elementEnd('fieldset');
|
$this->elementEnd('fieldset');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,7 +149,7 @@ class ChooseThemeForm extends Form {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function formActions()
|
public function formActions(): void
|
||||||
{
|
{
|
||||||
$this->submit('submit', _('Save'));
|
$this->submit('submit', _('Save'));
|
||||||
}
|
}
|
||||||
|
@ -156,10 +159,11 @@ class ChooseThemeForm extends Form {
|
||||||
*
|
*
|
||||||
* Should be unique on the page. Sub-classes should overload this
|
* Should be unique on the page. Sub-classes should overload this
|
||||||
* to show their own IDs.
|
* to show their own IDs.
|
||||||
* @return int ID of the form
|
* @return string ID of the form
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function id() {
|
public function id(): string
|
||||||
|
{
|
||||||
return 'form_choosetheme_prefs';
|
return 'form_choosetheme_prefs';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +175,8 @@ class ChooseThemeForm extends Form {
|
||||||
* @return string URL to post to
|
* @return string URL to post to
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function action() {
|
public function action(): string
|
||||||
|
{
|
||||||
return common_local_url('choosethemesettings');
|
return common_local_url('choosethemesettings');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +186,8 @@ class ChooseThemeForm extends Form {
|
||||||
* @return string the form's class
|
* @return string the form's class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function formClass() {
|
public function formClass(): string
|
||||||
|
{
|
||||||
return 'form_settings';
|
return 'form_settings';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user