ProfileColor.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. // {{{ License
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. // }}}
  18. namespace Plugin\ProfileColor;
  19. use App\Core\DB\DB;
  20. use App\Core\Event;
  21. use App\Core\Modules\Plugin;
  22. use App\Core\Router\RouteLoader;
  23. use App\Util\Common;
  24. /**
  25. * Profile Color plugin main class
  26. *
  27. * @package GNUsocial
  28. * @category ProfileColor
  29. *
  30. * @author Daniel Brandao <up201705812@fe.up.pt>
  31. * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. */
  34. class ProfileColor extends Plugin
  35. {
  36. /**
  37. * Map URLs to actions
  38. *
  39. * @param RouteLoader $r
  40. *
  41. * @return bool hook value; true means continue processing, false means stop.
  42. */
  43. public function onAddRoute(RouteLoader $r): bool
  44. {
  45. $r->connect('settings_profile_color', 'settings/color', [Controller\ProfileColor::class, 'profilecolorsettings']);
  46. return Event::next;
  47. }
  48. /**
  49. * Populate twig vars
  50. *
  51. * @param array $vars
  52. *
  53. * @return bool hook value; true means continue processing, false means stop.
  54. */
  55. public function onStartTwigPopulateVars(array &$vars): bool
  56. {
  57. $vars['profile_tabs'][] = ['title' => 'Color',
  58. 'route' => 'settings_profile_color',
  59. ];
  60. if (Common::user() != null) {
  61. $color = DB::find('profile_color', ['gsactor_id' => Common::user()->getId()]);
  62. if ($color != null) {
  63. $vars['profile_extras'][] = ['name' => 'profilecolor', 'vars' => ['color' => $color->getColor()]];
  64. }
  65. }
  66. return Event::next;
  67. }
  68. /**
  69. * Output our dedicated stylesheet
  70. *
  71. * @param array $styles stylesheets path
  72. *
  73. * @return bool hook value; true means continue processing, false means stop.
  74. */
  75. public function onStartShowStyles(array &$styles): bool
  76. {
  77. $styles[] = 'profilecolor/profilecolor.css';
  78. return Event::next;
  79. }
  80. }