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