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