4 * @file src/Content/Widget/CalendarExport.php
7 namespace Friendica\Content\Widget;
9 use Friendica\Content\Feature;
10 use Friendica\Core\Renderer;
21 * Get the events widget.
23 * @return string Formated HTML of the calendar widget.
24 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
26 public static function getHTML() {
29 if (empty($a->data['user'])) {
33 $owner_uid = intval($a->data['user']['uid']);
35 // The permission testing is a little bit tricky because we have to respect many cases.
37 // It's not the private events page (we don't get the $owner_uid for /events).
38 if (!local_user() && !$owner_uid) {
43 * If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and
44 * export feature isn't enabled.
47 * Cal logged in user (test permission at foreign profile page).
48 * If the $owner uid is available we know it is part of one of the profile pages (like /cal).
49 * So we have to test if if it's the own profile page of the logged in user
50 * or a foreign one. For foreign profile pages we need to check if the feature
51 * for exporting the cal is enabled (otherwise the widget would appear for logged in users
52 * on foreigen profile pages even if the widget is disabled).
54 if (local_user() != $owner_uid && !Feature::isEnabled($owner_uid, "export_calendar")) {
58 // $a->data is only available if the profile page is visited. If the visited page is not part
59 // of the profile page it should be the personal /events page. So we can use $a->user.
60 $user = ($a->data['user']['nickname'] ?? '') ?: $a->user['nickname'];
62 $tpl = Renderer::getMarkupTemplate("widget/events.tpl");
63 $return = Renderer::replaceMacros($tpl, [
64 '$etitle' => DI::l10n()->t("Export"),
65 '$export_ical' => DI::l10n()->t("Export calendar as ical"),
66 '$export_csv' => DI::l10n()->t("Export calendar as csv"),