ChooseThemePlugin.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. defined('GNUSOCIAL') || die();
  25. class ChooseThemePlugin extends Plugin
  26. {
  27. const PLUGIN_VERSION = '0.1.0';
  28. public function onRouterInitialized(URLMapper $m)
  29. {
  30. $m->connect('main/choosethemesettings', ['action' => 'choosethemesettings']);
  31. }
  32. public function onPluginVersion(array &$versions): bool
  33. {
  34. $versions[] = ['name' => 'ChooseTheme',
  35. 'version' => self::PLUGIN_VERSION,
  36. 'author' => 'Knut Erik "abjectio" Hollund',
  37. 'homepage' => 'https://gitlab.com/kollektivet0x242/gsp-choosetheme',
  38. 'rawdescription' =>
  39. // TRANS: Module description.
  40. _m('Allowing user to select the preferred theme.')];
  41. return true;
  42. }
  43. /**
  44. * Menu item for ChooseTheme
  45. *
  46. * @param Action $action action being executed
  47. *
  48. * @return bool hook return
  49. * @throws Exception
  50. */
  51. public function onEndAccountSettingsNav(Action $action): bool
  52. {
  53. $action_name = $action->getActionName();
  54. $action->menuItem(
  55. common_local_url('choosethemesettings'),
  56. // TRANS: Poll plugin menu item on user settings page.
  57. _m('MENU', 'Theme'),
  58. // TRANS: Poll plugin tooltip for user settings menu item.
  59. _m('Choose Theme'),
  60. $action_name === 'themesettings'
  61. );
  62. return true;
  63. }
  64. public function onStartShowStylesheets(Action $action)
  65. {
  66. //get the theme and set the current config for site and theme.
  67. if ($action->getScoped() instanceof Profile) {
  68. $site_theme = common_config('site', 'theme');
  69. $user_theme = $action->getScoped()->getPref('chosen_theme', 'theme', $site_theme);
  70. common_config_set('site', 'theme', $user_theme);
  71. }
  72. return true;
  73. }
  74. }