upstream V3 development https://www.gnusocial.rocks/v3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

101 lines
3.0 KiB

  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. use App\Util\Exception\RedirectException;
  25. use App\Util\Exception\ServerException;
  26. use App\Util\Formatting;
  27. use Plugin\ProfileColor\Controller as C;
  28. use Symfony\Component\HttpFoundation\Request;
  29. /**
  30. * Profile Color plugin main class
  31. *
  32. * @package GNUsocial
  33. * @category ProfileColor
  34. *
  35. * @author Daniel Brandao <up201705812@fe.up.pt>
  36. * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
  37. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  38. */
  39. class ProfileColor extends Plugin
  40. {
  41. /**
  42. * Map URLs to actions
  43. *
  44. * @param RouteLoader $r
  45. *
  46. * @return bool hook value; true means continue processing, false means stop.
  47. */
  48. public function onAddRoute(RouteLoader $r): bool
  49. {
  50. $r->connect('settings_profile_color', 'settings/color', [Controller\ProfileColor::class, 'profileColorSettings']);
  51. return Event::next;
  52. }
  53. /**
  54. * @param Request $request
  55. * @param $tabs
  56. * @return bool
  57. * @throws RedirectException
  58. * @throws ServerException
  59. */
  60. public function onPopulateProfileSettingsTabs(Request $request, &$tabs)
  61. {
  62. // TODO avatar template shouldn't be on settings folder
  63. $tabs[] = [
  64. 'title' => 'Color',
  65. 'desc' => 'Change your profile color.',
  66. 'controller' => C\ProfileColor::profileColorSettings($request),
  67. ];
  68. return Event::next;
  69. }
  70. /**
  71. * Renders profileColorView, which changes the background color of that profile.
  72. *
  73. * @param $vars
  74. * @param $res
  75. * @return bool
  76. */
  77. public function onAppendCardProfile($vars, &$res): bool
  78. {
  79. $actor = $vars['actor'];
  80. if ($actor !== null) {
  81. $actor_id = $actor->getId();
  82. $color = DB::find('profile_color', ['actor_id' => $actor_id]);
  83. if ($color !== null) {
  84. $res[] = Formatting::twigRenderFile('/profileColor/profileColorView.html.twig', ['profile_color' => $color, 'actor' => $actor_id]);
  85. }
  86. }
  87. return Event::next;
  88. }
  89. }