ProfileColor.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 Plugin\ProfileColor\Controller as C;
  25. use Symfony\Component\HttpFoundation\Request;
  26. /**
  27. * Profile Color plugin main class
  28. *
  29. * @package GNUsocial
  30. * @category ProfileColor
  31. *
  32. * @author Daniel Brandao <up201705812@fe.up.pt>
  33. * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
  34. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  35. */
  36. class ProfileColor extends Plugin
  37. {
  38. /**
  39. * Map URLs to actions
  40. *
  41. * @param RouteLoader $r
  42. *
  43. * @return bool hook value; true means continue processing, false means stop.
  44. */
  45. public function onAddRoute(RouteLoader $r): bool
  46. {
  47. $r->connect('settings_profile_color', 'settings/color', [Controller\ProfileColor::class, 'profilecolorsettings']);
  48. return Event::next;
  49. }
  50. public function onPopulateProfileSettingsTabs(Request $request, &$tabs)
  51. {
  52. // TODO avatar template shouldn't be on settings folder
  53. $tabs[] = [
  54. 'title' => 'Color',
  55. 'desc' => 'Change your profile color.',
  56. 'controller' => C\ProfileColor::profileColorSettings($request),
  57. ];
  58. return Event::next;
  59. }
  60. /**
  61. * Populate twig vars
  62. *
  63. * @param array $vars
  64. *
  65. * @return bool hook value; true means continue processing, false means stop.
  66. */
  67. public function onStartTwigPopulateVars(array &$vars): bool
  68. {
  69. /*$vars['profile_tabs'][] = [
  70. 'title' => 'Color',
  71. 'desc' => 'Change your profile color.',
  72. 'path' => 'profilecolor/profilecolor.html.twig',
  73. ];*/
  74. if (Common::user() != null) {
  75. $color = DB::find('profile_color', ['gsactor_id' => Common::user()->getId()]);
  76. if ($color != null) {
  77. $vars['profile_extras'][] = ['name' => 'profilecolor', 'vars' => ['color' => $color->getColor()]];
  78. }
  79. }
  80. return Event::next;
  81. }
  82. /**
  83. * Output our dedicated stylesheet
  84. *
  85. * @param array $styles stylesheets path
  86. *
  87. * @return bool hook value; true means continue processing, false means stop.
  88. */
  89. public function onStartShowStyles(array &$styles): bool
  90. {
  91. $styles[] = 'profilecolor/profilecolor.css';
  92. return Event::next;
  93. }
  94. }