]> git.mxchange.org Git - friendica.git/blob - src/Content/Widget/CalendarExport.php
Finally fix the permissions for Widget\CalendarExport
[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
12 require_once 'boot.php';
13 require_once 'include/text.php';
14
15 /**
16  * TagCloud widget
17  *
18  * @author Rabuzarus
19  */
20 class CalendarExport
21 {
22         /**
23          * @brief Get the events widget.
24          *
25          * @return string Formated HTML of the calendar widget.
26          */
27         public static function getHTML() {
28                 $a = get_app();
29
30                 $owner_uid = $a->data['user']['uid'];
31
32                 // The permission testing is a little bit tricky because we have to respect many cases.
33
34                 // It's not the private events page (we don't get the $owner_uid for /events).
35                 if (!local_user() && !$owner_uid) {
36                         return;
37                 }
38
39                 /*
40                  * Cal logged in user (test permission at foreign profile page).
41                  * If the $owner uid is available we know it is part of one of the profile pages (like /cal).
42                  * So we have to test if if it's the own profile page of the logged in user
43                  * or a foreign one. For foreign profile pages we need to check if the feature
44                  * for exporting the cal is enabled (otherwise the widget would appear for logged in users
45                  * on foreigen profile pages even if the widget is disabled).
46                  */
47                 if (local_user() != $owner_uid && !Feature::isEnabled($owner_uid, "export_calendar")) {
48                         return;
49                 }
50
51                 // $a->data is only available if the profile page is visited. If the visited page is not part
52                 // of the profile page it should be the personal /events page. So we can use $a->user.
53                 $user = defaults($a->data['user'], 'nickname', $a->user['nickname']);
54
55                 $tpl = get_markup_template("events_aside.tpl");
56                 $return = replace_macros($tpl, [
57                         '$etitle'      => L10n::t("Export"),
58                         '$export_ical' => L10n::t("Export calendar as ical"),
59                         '$export_csv'  => L10n::t("Export calendar as csv"),
60                         '$user'        => $user
61                 ]);
62
63                 return $return;
64         }
65 }