ChooseThemePlugin.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * ChooseTheme - GNU social plugin enabling user to select a preferred theme
  4. * Copyright (C) 2015, kollektivet0x242.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @author Knut Erik Hollund <knut.erik@unlike.no>
  20. * @copyright 2015 kollektivet0x242. http://www.kollektivet0x242.no
  21. *
  22. * @license GNU Affero General Public License http://www.gnu.org/licenses/
  23. */
  24. class ChooseThemePlugin extends Plugin {
  25. public function onRouterInitialized(URLMapper $m) {
  26. $m->connect('main/choosethemesettings', array('action' => 'choosethemesettings'));
  27. }
  28. public function onPluginVersion(array &$versions) {
  29. $versions[] = array('name' => 'ChooseTheme',
  30. 'version' => '0.1',
  31. 'author' => 'Knut Erik "abjectio" Hollund',
  32. 'homepage' => 'https://gitlab.com/kollektivet0x242/gsp-choosetheme',
  33. 'rawdescription' =>
  34. // TRANS: Plugin description.
  35. _m('Allowing user to select the preferred theme.'));
  36. return true;
  37. }
  38. /**
  39. * Menu item for ChooseTheme
  40. *
  41. * @param Action $action action being executed
  42. *
  43. * @return boolean hook return
  44. */
  45. function onEndAccountSettingsNav(Action $action) {
  46. $action_name = $action->getActionName();
  47. $action->menuItem(common_local_url('choosethemesettings'),
  48. // TRANS: Poll plugin menu item on user settings page.
  49. _m('MENU', 'Theme'),
  50. // TRANS: Poll plugin tooltip for user settings menu item.
  51. _m('Choose Theme'),
  52. $action_name === 'themesettings');
  53. return true;
  54. }
  55. function onStartShowStylesheets(Action $action) {
  56. //get the theme and set the current config for site and theme.
  57. if($action->getScoped() instanceof Profile) {
  58. $site_theme = common_config('site','theme');
  59. $user_theme = $action->getScoped()->getPref('chosen_theme', 'theme', $site_theme);
  60. common_config_set('site', 'theme', $user_theme);
  61. }
  62. return true;
  63. }
  64. }