forked from GNUsocial/gnu-social
Merge branch 'nightly' into 'nightly'
Adding ChooseTheme plugin into the plugin repository This merge request propose the plugin ChooseTheme as a part of the plugin repository for GNU social. See merge request !9
This commit is contained in:
commit
f4b0756e70
0
avatar/.gitignore
vendored
0
avatar/.gitignore
vendored
0
background/.gitignore
vendored
0
background/.gitignore
vendored
0
file/.gitignore
vendored
0
file/.gitignore
vendored
74
plugins/ChooseTheme/ChooseThemePlugin.php
Normal file
74
plugins/ChooseTheme/ChooseThemePlugin.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ChooseTheme - GNU social plugin enabling user to select a 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/
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ChooseThemePlugin extends Plugin {
|
||||||
|
|
||||||
|
public function onRouterInitialized(URLMapper $m) {
|
||||||
|
$m->connect('main/choosethemesettings', array('action' => 'choosethemesettings'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPluginVersion(array &$versions) {
|
||||||
|
|
||||||
|
$versions[] = array('name' => 'ChooseTheme',
|
||||||
|
'version' => '0.1',
|
||||||
|
'author' => 'Knut Erik "abjectio" Hollund',
|
||||||
|
'homepage' => 'https://gitlab.com/kollektivet0x242/gsp-choosetheme',
|
||||||
|
'rawdescription' =>
|
||||||
|
// TRANS: Plugin description.
|
||||||
|
_m('Allowing user to select the preferred theme.'));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Menu item for ChooseTheme
|
||||||
|
*
|
||||||
|
* @param Action $action action being executed
|
||||||
|
*
|
||||||
|
* @return boolean hook return
|
||||||
|
*/
|
||||||
|
function onEndAccountSettingsNav(Action $action) {
|
||||||
|
$action_name = $action->getActionName();
|
||||||
|
|
||||||
|
$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');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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');
|
||||||
|
$user_theme = $action->getScoped()->getPref('chosen_theme', 'theme', $site_theme);
|
||||||
|
common_config_set('site', 'theme', $user_theme);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
13
plugins/ChooseTheme/README.md
Normal file
13
plugins/ChooseTheme/README.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
### Choose theme
|
||||||
|
A simple plugin for [GNU social software](http://gnu.io/social/).
|
||||||
|
The plugin enables the user to select their own theme, independently on site setting and other users.
|
||||||
|
|
||||||
|
#### Enable plugin
|
||||||
|
- Include this code in your GNU social instance.
|
||||||
|
- Edit your `config.php` to include `addPlugin("ChooseTheme");`
|
||||||
|
|
||||||
|
#### How-to
|
||||||
|
- Choose settings from the GNU social menu. Choose 'Theme' on left menu.
|
||||||
|
- Select a theme and press 'Save'.
|
||||||
|
|
||||||
|
|
187
plugins/ChooseTheme/actions/choosethemesettings.php
Normal file
187
plugins/ChooseTheme/actions/choosethemesettings.php
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
<?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/
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('STATUSNET') && !defined('GNUSOCIAL')) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
class ChooseThemeSettingsAction extends SettingsAction {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title of the page
|
||||||
|
* @return string Page title
|
||||||
|
*/
|
||||||
|
function title() {
|
||||||
|
// TRANS: Page title.
|
||||||
|
return _m('Choose theme settings');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instructions for use
|
||||||
|
* @return string Instructions for use
|
||||||
|
*/
|
||||||
|
function getInstructions() {
|
||||||
|
// TRANS: Page instructions.
|
||||||
|
return _m('Choose theme');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for ChooseTheme
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function showContent() {
|
||||||
|
|
||||||
|
$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.');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get a list of available themes on instance
|
||||||
|
$available_themes = Theme::listAvailable();
|
||||||
|
$chosenone = array_search($prefs,$available_themes,true);
|
||||||
|
$form = new ChooseThemeForm($this, $chosenone);
|
||||||
|
$form->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler method
|
||||||
|
*
|
||||||
|
* @param array $argarray is ignored since it's now passed in in prepare()
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function handlePost() {
|
||||||
|
|
||||||
|
//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->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.');
|
||||||
|
|
||||||
|
$this->showForm(_($this->msg), $this->success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ChooseThemeForm extends Form {
|
||||||
|
|
||||||
|
protected $prefs = null;
|
||||||
|
|
||||||
|
|
||||||
|
function __construct($out, $prefs) {
|
||||||
|
parent::__construct($out);
|
||||||
|
|
||||||
|
if ($prefs!=null) {
|
||||||
|
$this->prefs = $prefs;
|
||||||
|
} else {
|
||||||
|
$prefs = common_config('site','theme');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
function formData() {
|
||||||
|
|
||||||
|
//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]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$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');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buttons for form actions
|
||||||
|
*
|
||||||
|
* Submit and cancel buttons (or whatever)
|
||||||
|
* Sub-classes should overload this to show their own buttons.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
function formActions()
|
||||||
|
{
|
||||||
|
$this->submit('submit', _('Save'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID of the form
|
||||||
|
*
|
||||||
|
* Should be unique on the page. Sub-classes should overload this
|
||||||
|
* to show their own IDs.
|
||||||
|
* @return int ID of the form
|
||||||
|
*/
|
||||||
|
|
||||||
|
function id() {
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
|
function action() {
|
||||||
|
return common_local_url('choosethemesettings');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class of the form. May include space-separated list of multiple classes.
|
||||||
|
*
|
||||||
|
* @return string the form's class
|
||||||
|
*/
|
||||||
|
|
||||||
|
function formClass() {
|
||||||
|
return 'form_settings';
|
||||||
|
}
|
||||||
|
}
|
62
plugins/ChooseTheme/locale/ChooseTheme.pot
Normal file
62
plugins/ChooseTheme/locale/ChooseTheme.pot
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
# SOME DESCRIPTIVE TITLE.
|
||||||
|
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||||
|
# This file is distributed under the same license as the GNU social package.
|
||||||
|
# FIRST AUTHOR abjectio@kollektivet0x242.no, 2015.
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Choose Theme\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2015-06-10 22:00+0100\n"
|
||||||
|
"PO-Revision-Date: 2015-06-10 22:01+0100\n"
|
||||||
|
"Last-Translator: Knut Erik Hollund <knut.erik@unlike.no>\n"
|
||||||
|
"Language-Team: kollektivet0x242.no <abjectio@kollektivet0x242.no>\n"
|
||||||
|
"Language: en\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 1.5.4\n"
|
||||||
|
"X-Poedit-Basepath: ./actions\n"
|
||||||
|
"X-Poedit-KeywordsList: _m\n"
|
||||||
|
"X-Poedit-SearchPath-0: ./actions\n"
|
||||||
|
"X-Poedit-SearchPath-1: .\n"
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:38
|
||||||
|
msgid "Choose theme settings"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:47
|
||||||
|
msgid "Choose theme"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:83
|
||||||
|
msgid "Settings saved."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:87
|
||||||
|
msgid "No valid theme chosen."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:134
|
||||||
|
msgid "Themes"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:134
|
||||||
|
msgid "Select a theme"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:151
|
||||||
|
msgid "Save"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: ChooseThemePlugin.php:39
|
||||||
|
msgid "Allowing user to select the preferred theme."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: ChooseThemePlugin.php:55
|
||||||
|
msgid "MENU"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: ChooseThemePlugin.php:57
|
||||||
|
msgid "Choose Theme"
|
||||||
|
msgstr ""
|
62
plugins/ChooseTheme/locale/nb/LC_MESSAGES/ChooseTheme.po
Normal file
62
plugins/ChooseTheme/locale/nb/LC_MESSAGES/ChooseTheme.po
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
# SOME DESCRIPTIVE TITLE.
|
||||||
|
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||||
|
# This file is distributed under the same license as the GNU social package.
|
||||||
|
# FIRST AUTHOR abjectio@kollektivet0x242.no, 2015.
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Choose Theme\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2015-06-10 22:00+0100\n"
|
||||||
|
"PO-Revision-Date: 2015-06-10 22:04+0100\n"
|
||||||
|
"Last-Translator: Knut Erik Hollund <knut.erik@unlike.no>\n"
|
||||||
|
"Language-Team: kollektivet0x242.no <abjectio@kollektivet0x242.no>\n"
|
||||||
|
"Language: nb\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 1.5.4\n"
|
||||||
|
"X-Poedit-Basepath: ./actions\n"
|
||||||
|
"X-Poedit-KeywordsList: _m\n"
|
||||||
|
"X-Poedit-SearchPath-0: ./actions\n"
|
||||||
|
"X-Poedit-SearchPath-1: .\n"
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:38
|
||||||
|
msgid "Choose theme settings"
|
||||||
|
msgstr "Innstillinger"
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:47
|
||||||
|
msgid "Choose theme"
|
||||||
|
msgstr "Velg tema"
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:83
|
||||||
|
msgid "Settings saved."
|
||||||
|
msgstr "Innstillinger lagret."
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:87
|
||||||
|
msgid "No valid theme chosen."
|
||||||
|
msgstr "Ingen gyldige tema er valgt."
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:134
|
||||||
|
msgid "Themes"
|
||||||
|
msgstr "Temaer"
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:134
|
||||||
|
msgid "Select a theme"
|
||||||
|
msgstr "Velg tema"
|
||||||
|
|
||||||
|
#: actions/choosethemesettings.php:151
|
||||||
|
msgid "Save"
|
||||||
|
msgstr "Lagre"
|
||||||
|
|
||||||
|
#: ChooseThemePlugin.php:39
|
||||||
|
msgid "Allowing user to select the preferred theme."
|
||||||
|
msgstr "Lar brukeren velge sitt foretrukne tema."
|
||||||
|
|
||||||
|
#: ChooseThemePlugin.php:55
|
||||||
|
msgid "MENU"
|
||||||
|
msgstr "Tema"
|
||||||
|
|
||||||
|
#: ChooseThemePlugin.php:57
|
||||||
|
msgid "Choose Theme"
|
||||||
|
msgstr "Velg tema"
|
Loading…
Reference in New Issue
Block a user