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.
 
 
 
 
 
 

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