Cover.php 2.9 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;
  21. use App\Core\Event;
  22. use App\Core\Modules\Plugin;
  23. use App\Core\Router;
  24. use App\Util\Common;
  25. use EventResult;
  26. use Plugin\Cover\Controller as C;
  27. use Symfony\Component\HttpFoundation\Request;
  28. /**
  29. * Cover plugin main class
  30. *
  31. * @package GNUsocial
  32. * @category CoverPlugin
  33. *
  34. * @author Daniel Brandao <up201705812@fe.up.pt>
  35. * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
  36. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  37. */
  38. class Cover extends Plugin
  39. {
  40. /**
  41. * Map URLs to actions
  42. */
  43. public function onAddRoute(Router $r): EventResult
  44. {
  45. $r->connect('settings_profile_cover', 'settings/cover', [Controller\Cover::class, 'coversettings']);
  46. $r->connect('cover', '/cover', [Controller\Cover::class, 'cover']);
  47. return Event::next;
  48. }
  49. /**
  50. * @param SettingsTabsType $tabs
  51. */
  52. public function onPopulateSettingsTabs(Request $request, string $section, &$tabs): EventResult
  53. {
  54. if ($section === 'profile') {
  55. $tabs[] = [
  56. 'title' => 'Cover',
  57. 'desc' => 'Change your cover.',
  58. 'id' => 'settings-cover',
  59. 'controller' => C\Cover::coverSettings($request),
  60. ];
  61. }
  62. return Event::next;
  63. }
  64. /**
  65. * Populate twig vars
  66. *
  67. * @return bool hook value; true means continue processing, false means stop.
  68. *
  69. * public function onStartTwigPopulateVars(array &$vars): \EventResult
  70. * {
  71. * if (Common::user() != null) {
  72. * $cover = DB::find('cover', ['actor_id' => Common::user()->getId()]);
  73. * if ($cover != null) {
  74. * $vars['profile_extras'][] = ['name' => 'cover', 'vars' => ['img' => '/cover']];
  75. * } else {
  76. * $vars['profile_extras'][] = ['name' => 'cover', 'vars' => []];
  77. * }
  78. * }
  79. * return Event::next;
  80. * }*/
  81. /**
  82. * Output our dedicated stylesheet
  83. *
  84. * @param string[] $styles stylesheets path
  85. */
  86. public function onStartShowStyles(array &$styles): EventResult
  87. {
  88. $styles[] = 'assets/css/cover.css';
  89. return Event::next;
  90. }
  91. }