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