Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.1 KiB

  1. <?php
  2. /*
  3. * @file src/Content/Widget/CalendarExport.php
  4. */
  5. namespace Friendica\Content\Widget;
  6. use Friendica\Content\Feature;
  7. use Friendica\Core\L10n;
  8. use Friendica\Core\Renderer;
  9. /**
  10. * TagCloud widget
  11. *
  12. * @author Rabuzarus
  13. */
  14. class CalendarExport
  15. {
  16. /**
  17. * @brief Get the events widget.
  18. *
  19. * @return string Formated HTML of the calendar widget.
  20. * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  21. */
  22. public static function getHTML() {
  23. $a = \get_app();
  24. if (empty($a->data['user'])) {
  25. return;
  26. }
  27. $owner_uid = intval($a->data['user']['uid']);
  28. // The permission testing is a little bit tricky because we have to respect many cases.
  29. // It's not the private events page (we don't get the $owner_uid for /events).
  30. if (!local_user() && !$owner_uid) {
  31. return;
  32. }
  33. /*
  34. * If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and
  35. * export feature isn't enabled.
  36. */
  37. /*
  38. * Cal logged in user (test permission at foreign profile page).
  39. * If the $owner uid is available we know it is part of one of the profile pages (like /cal).
  40. * So we have to test if if it's the own profile page of the logged in user
  41. * or a foreign one. For foreign profile pages we need to check if the feature
  42. * for exporting the cal is enabled (otherwise the widget would appear for logged in users
  43. * on foreigen profile pages even if the widget is disabled).
  44. */
  45. if (local_user() != $owner_uid && !Feature::isEnabled($owner_uid, "export_calendar")) {
  46. return;
  47. }
  48. // $a->data is only available if the profile page is visited. If the visited page is not part
  49. // of the profile page it should be the personal /events page. So we can use $a->user.
  50. $user = ($a->data['user']['nickname'] ?? '') ?: $a->user['nickname'];
  51. $tpl = Renderer::getMarkupTemplate("widget/events.tpl");
  52. $return = Renderer::replaceMacros($tpl, [
  53. '$etitle' => L10n::t("Export"),
  54. '$export_ical' => L10n::t("Export calendar as ical"),
  55. '$export_csv' => L10n::t("Export calendar as csv"),
  56. '$user' => $user
  57. ]);
  58. return $return;
  59. }
  60. }