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