OverwriteThemeBackgroundPlugin.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. defined('GNUSOCIAL') || die();
  17. /**
  18. * Allows administrators to overwrite his GNU social instance's background
  19. *
  20. * @category Plugin
  21. * @author Diogo Cordeiro <diogo@fc.up.pt>
  22. * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. /**
  26. * Handle plugin's events
  27. *
  28. * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
  29. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  30. */
  31. class OverwriteThemeBackgroundPlugin extends Plugin
  32. {
  33. const PLUGIN_VERSION = '0.1.1';
  34. /**
  35. * Route urls
  36. *
  37. * @param URLMapper $m
  38. * @return bool
  39. * @throws Exception
  40. */
  41. public function onRouterInitialized(URLMapper $m): bool
  42. {
  43. $m->connect('plugins/OverwriteThemeBackground/css/my_custom_theme_bg',
  44. ['action' => 'OverwriteThemeBackgroundCSS']);
  45. $m->connect('panel/overwritethemebackground',
  46. ['action' => 'overwritethemebackgroundAdminPanel']);
  47. return true;
  48. }
  49. /**
  50. * Plugin meta-data
  51. *
  52. * @param array $versions
  53. * @return bool hook true
  54. * @throws Exception
  55. */
  56. public function onPluginVersion(array &$versions): bool
  57. {
  58. $versions[] = [
  59. 'name' => 'Overwrite Theme Background',
  60. 'version' => self::PLUGIN_VERSION,
  61. 'author' => 'Diogo Cordeiro',
  62. 'homepage' => 'https://www.diogo.site/projects/GNU-social/plugins/OverwriteThemeBackgroundPlugin',
  63. // TRANS: Plugin description for OverwriteThemeBackground plugin.
  64. 'rawdescription' => _m('A friendly plugin for overwriting your theme\'s background style.')
  65. ];
  66. return true;
  67. }
  68. /**
  69. * Add our custom background css after theme's
  70. *
  71. * @param Action $action
  72. * @return bool hook true
  73. */
  74. public function onEndShowStyles(Action $action): bool
  75. {
  76. $action->cssLink(common_local_url('OverwriteThemeBackgroundCSS'));
  77. return true;
  78. }
  79. /**
  80. * Add a menu option for this plugin in Admin's UI
  81. *
  82. * @param AdminPanelNav $nav
  83. * @return bool hook true
  84. * @throws Exception
  85. */
  86. public function onEndAdminPanelNav(AdminPanelNav $nav): bool
  87. {
  88. if (AdminPanelAction::canAdmin('profilefields')) {
  89. $action_name = $nav->action->trimmed('action');
  90. $nav->out->menuItem(
  91. common_local_url('overwritethemebackgroundAdminPanel'),
  92. _m('Overwrite Theme Background'),
  93. _m('Customize your theme\'s background easily'),
  94. $action_name == 'overwritethemebackgroundAdminPanel',
  95. 'nav_overwritethemebackground_admin_panel'
  96. );
  97. }
  98. return true;
  99. }
  100. }