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