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.0KB

  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. */
  21. public static function getHTML() {
  22. $a = get_app();
  23. if (empty($a->data['user'])) {
  24. return;
  25. }
  26. $owner_uid = $a->data['user']['uid'];
  27. // The permission testing is a little bit tricky because we have to respect many cases.
  28. // It's not the private events page (we don't get the $owner_uid for /events).
  29. if (!local_user() && !$owner_uid) {
  30. return;
  31. }
  32. /*
  33. * If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and
  34. * export feature isn't enabled.
  35. */
  36. /*
  37. * Cal logged in user (test permission at foreign profile page).
  38. * If the $owner uid is available we know it is part of one of the profile pages (like /cal).
  39. * So we have to test if if it's the own profile page of the logged in user
  40. * or a foreign one. For foreign profile pages we need to check if the feature
  41. * for exporting the cal is enabled (otherwise the widget would appear for logged in users
  42. * on foreigen profile pages even if the widget is disabled).
  43. */
  44. if (local_user() != $owner_uid && !Feature::isEnabled($owner_uid, "export_calendar")) {
  45. return;
  46. }
  47. // $a->data is only available if the profile page is visited. If the visited page is not part
  48. // of the profile page it should be the personal /events page. So we can use $a->user.
  49. $user = defaults($a->data['user'], 'nickname', $a->user['nickname']);
  50. $tpl = Renderer::getMarkupTemplate("events_aside.tpl");
  51. $return = Renderer::replaceMacros($tpl, [
  52. '$etitle' => L10n::t("Export"),
  53. '$export_ical' => L10n::t("Export calendar as ical"),
  54. '$export_csv' => L10n::t("Export calendar as csv"),
  55. '$user' => $user
  56. ]);
  57. return $return;
  58. }
  59. }