Cover.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /**
  25. * Cover plugin main class
  26. *
  27. * @package GNUsocial
  28. * @category CoverPlugin
  29. *
  30. * @author Daniel Brandao <up201705812@fe.up.pt>
  31. * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
  32. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  33. */
  34. class Cover extends Plugin
  35. {
  36. /**
  37. * Map URLs to actions
  38. *
  39. * @param RouteLoader $r
  40. *
  41. * @return bool hook value; true means continue processing, false means stop.
  42. */
  43. public function onAddRoute(RouteLoader $r): bool
  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. * Populate twig vars
  51. *
  52. * @param array $vars
  53. *
  54. * @return bool hook value; true means continue processing, false means stop.
  55. */
  56. public function onStartTwigPopulateVars(array &$vars): bool
  57. {
  58. $vars['profile_tabs'][] = ['title' => 'Cover',
  59. 'route' => 'settings_profile_cover',
  60. ];
  61. if (Common::user() != null) {
  62. $cover = DB::find('cover', ['gsactor_id' => Common::user()->getId()]);
  63. if ($cover != null) {
  64. $vars['profile_extras'][] = ['name' => 'cover', 'vars' => ['img' => '/cover']];
  65. } else {
  66. $vars['profile_extras'][] = ['name' => 'cover', 'vars' => []];
  67. }
  68. }
  69. return Event::next;
  70. }
  71. /**
  72. * Output our dedicated stylesheet
  73. *
  74. * @param array $styles stylesheets path
  75. *
  76. * @return bool hook value; true means continue processing, false means stop.
  77. */
  78. public function onStartShowStyles(array &$styles): bool
  79. {
  80. $styles[] = 'cover/cover.css';
  81. return Event::next;
  82. }
  83. }