Cover.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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\Cover;
  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\Cover\Controller as C;
  25. use Symfony\Component\HttpFoundation\Request;
  26. /**
  27. * Cover plugin main class
  28. *
  29. * @package GNUsocial
  30. * @category CoverPlugin
  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 Cover 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_cover', 'settings/cover', [Controller\Cover::class, 'coversettings']);
  48. $r->connect('cover', '/cover', [Controller\Cover::class, 'cover']);
  49. return Event::next;
  50. }
  51. public function onPopulateProfileSettingsTabs(Request $request, &$tabs)
  52. {
  53. $tabs[] = [
  54. 'title' => 'Cover',
  55. 'desc' => 'Change your cover.',
  56. 'controller' => C\Cover::coverSettings($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. /*if (Common::user() != null) {
  70. $cover = DB::find('cover', ['gsactor_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[] = 'cover/cover.css';
  89. return Event::next;
  90. }
  91. }