2018-03-17 02:22:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @file src/Content/Widget/CalendarExport.php
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Content\Widget;
|
|
|
|
|
2018-03-17 21:42:28 +01:00
|
|
|
use Friendica\Content\Feature;
|
2018-10-31 15:35:50 +01:00
|
|
|
use Friendica\Core\Renderer;
|
2020-01-04 23:42:01 +01:00
|
|
|
use Friendica\DI;
|
2018-03-17 02:22:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TagCloud widget
|
|
|
|
*
|
|
|
|
* @author Rabuzarus
|
|
|
|
*/
|
|
|
|
class CalendarExport
|
|
|
|
{
|
|
|
|
/**
|
2020-01-19 07:05:23 +01:00
|
|
|
* Get the events widget.
|
2018-03-17 02:22:19 +01:00
|
|
|
*
|
|
|
|
* @return string Formated HTML of the calendar widget.
|
2019-01-06 22:06:53 +01:00
|
|
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
2018-03-17 02:22:19 +01:00
|
|
|
*/
|
|
|
|
public static function getHTML() {
|
2020-01-04 23:42:01 +01:00
|
|
|
$a = DI::app();
|
2018-03-17 02:22:19 +01:00
|
|
|
|
2018-08-11 23:05:42 +02:00
|
|
|
if (empty($a->data['user'])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-16 03:46:55 +02:00
|
|
|
$owner_uid = intval($a->data['user']['uid']);
|
2018-03-17 21:42:28 +01:00
|
|
|
|
|
|
|
// The permission testing is a little bit tricky because we have to respect many cases.
|
|
|
|
|
|
|
|
// It's not the private events page (we don't get the $owner_uid for /events).
|
|
|
|
if (!local_user() && !$owner_uid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-18 06:32:43 +01:00
|
|
|
/*
|
|
|
|
* If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and
|
|
|
|
* export feature isn't enabled.
|
|
|
|
*/
|
2018-03-17 02:22:19 +01:00
|
|
|
/*
|
2018-03-18 06:23:38 +01:00
|
|
|
* Cal logged in user (test permission at foreign profile page).
|
|
|
|
* If the $owner uid is available we know it is part of one of the profile pages (like /cal).
|
|
|
|
* So we have to test if if it's the own profile page of the logged in user
|
|
|
|
* or a foreign one. For foreign profile pages we need to check if the feature
|
|
|
|
* for exporting the cal is enabled (otherwise the widget would appear for logged in users
|
|
|
|
* on foreigen profile pages even if the widget is disabled).
|
2018-03-17 02:22:19 +01:00
|
|
|
*/
|
2018-03-18 06:23:38 +01:00
|
|
|
if (local_user() != $owner_uid && !Feature::isEnabled($owner_uid, "export_calendar")) {
|
2018-03-17 02:22:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// $a->data is only available if the profile page is visited. If the visited page is not part
|
|
|
|
// of the profile page it should be the personal /events page. So we can use $a->user.
|
2019-10-16 14:35:14 +02:00
|
|
|
$user = ($a->data['user']['nickname'] ?? '') ?: $a->user['nickname'];
|
2018-03-17 02:22:19 +01:00
|
|
|
|
2019-05-18 17:33:35 +02:00
|
|
|
$tpl = Renderer::getMarkupTemplate("widget/events.tpl");
|
2018-10-31 15:35:50 +01:00
|
|
|
$return = Renderer::replaceMacros($tpl, [
|
2020-01-18 20:52:34 +01:00
|
|
|
'$etitle' => DI::l10n()->t("Export"),
|
|
|
|
'$export_ical' => DI::l10n()->t("Export calendar as ical"),
|
|
|
|
'$export_csv' => DI::l10n()->t("Export calendar as csv"),
|
2018-03-17 02:22:19 +01:00
|
|
|
'$user' => $user
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|