Cover.php 3.0 KB

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