summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2023-08-08 14:51:08 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2023-08-10 08:20:39 +0200
commite5a0d65af411c3d717bfc5e2739d50d516e98c7d (patch)
tree67856bfd89667e172e796ce1811fcba322a71253 /apps/dav
parent231cec61ef4892889b4291f80fb76a1483bef6b2 (diff)
downloadnextcloud-server-e5a0d65af411c3d717bfc5e2739d50d516e98c7d.tar.gz
nextcloud-server-e5a0d65af411c3d717bfc5e2739d50d516e98c7d.zip
feat(caldav): linkify location in scheduling mails
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/CalDAV/Schedule/IMipService.php44
1 files changed, 42 insertions, 2 deletions
diff --git a/apps/dav/lib/CalDAV/Schedule/IMipService.php b/apps/dav/lib/CalDAV/Schedule/IMipService.php
index 8596500f320..e6d1bbcd875 100644
--- a/apps/dav/lib/CalDAV/Schedule/IMipService.php
+++ b/apps/dav/lib/CalDAV/Schedule/IMipService.php
@@ -6,6 +6,7 @@ declare(strict_types=1);
* @copyright 2022 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
+ * @author Richard Steinmetz <richard@steinmetz.cloud>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -106,6 +107,40 @@ class IMipService {
}
/**
+ * Like generateDiffString() but linkifies the property values if they are urls.
+ */
+ private function generateLinkifiedDiffString(VEvent $vevent, VEvent $oldVEvent, string $property, string $default): ?string {
+ if (!isset($vevent->$property)) {
+ return $default;
+ }
+ /** @var string|null $newString */
+ $newString = $vevent->$property->getValue();
+ $oldString = isset($oldVEvent->$property) ? $oldVEvent->$property->getValue() : null;
+ if ($oldString !== $newString) {
+ return sprintf(
+ "<span style='text-decoration: line-through'>%s</span><br />%s",
+ $this->linkify($oldString) ?? $oldString ?? '',
+ $this->linkify($newString) ?? $newString ?? ''
+ );
+ }
+ return $this->linkify($newString) ?? $newString;
+ }
+
+ /**
+ * Convert a given url to a html link element or return null otherwise.
+ */
+ private function linkify(?string $url): ?string {
+ if ($url === null) {
+ return null;
+ }
+ if (!str_starts_with($url, 'http://') && !str_starts_with($url, 'https://')) {
+ return null;
+ }
+
+ return sprintf('<a href="%1$s">%1$s</a>', htmlspecialchars($url));
+ }
+
+ /**
* @param VEvent $vEvent
* @param VEvent|null $oldVEvent
* @return array
@@ -121,11 +156,15 @@ class IMipService {
$data['meeting_url_html'] = self::readPropertyWithDefault($vEvent, 'URL', $defaultVal);
+ if (($locationHtml = $this->linkify($data['meeting_location'])) !== null) {
+ $data['meeting_location_html'] = $locationHtml;
+ }
+
if(!empty($oldVEvent)) {
$oldMeetingWhen = $this->generateWhenString($oldVEvent);
$data['meeting_title_html'] = $this->generateDiffString($vEvent, $oldVEvent, 'SUMMARY', $data['meeting_title']);
$data['meeting_description_html'] = $this->generateDiffString($vEvent, $oldVEvent, 'DESCRIPTION', $data['meeting_description']);
- $data['meeting_location_html'] = $this->generateDiffString($vEvent, $oldVEvent, 'LOCATION', $data['meeting_location']);
+ $data['meeting_location_html'] = $this->generateLinkifiedDiffString($vEvent, $oldVEvent, 'LOCATION', $data['meeting_location']);
$oldUrl = self::readPropertyWithDefault($oldVEvent, 'URL', $defaultVal);
$data['meeting_url_html'] = !empty($oldUrl) && $oldUrl !== $data['meeting_url'] ? sprintf('<a href="%1$s">%1$s</a>', $oldUrl) : $data['meeting_url'];
@@ -246,6 +285,7 @@ class IMipService {
$newDescription = isset($vEvent->DESCRIPTION) && (string)$vEvent->DESCRIPTION !== '' ? (string)$vEvent->DESCRIPTION : $defaultVal;
$newUrl = isset($vEvent->URL) && (string)$vEvent->URL !== '' ? sprintf('<a href="%1$s">%1$s</a>', $vEvent->URL) : $defaultVal;
$newLocation = isset($vEvent->LOCATION) && (string)$vEvent->LOCATION !== '' ? (string)$vEvent->LOCATION : $defaultVal;
+ $newLocationHtml = $this->linkify($newLocation) ?? $newLocation;
$data = [];
$data['meeting_when_html'] = $newMeetingWhen === '' ?: sprintf($strikethrough, $newMeetingWhen);
@@ -256,7 +296,7 @@ class IMipService {
$data['meeting_description'] = $newDescription;
$data['meeting_url_html'] = $newUrl !== '' ? sprintf($strikethrough, $newUrl) : '';
$data['meeting_url'] = isset($vEvent->URL) ? (string)$vEvent->URL : '';
- $data['meeting_location_html'] = $newLocation !== '' ? sprintf($strikethrough, $newLocation) : '';
+ $data['meeting_location_html'] = $newLocationHtml !== '' ? sprintf($strikethrough, $newLocationHtml) : '';
$data['meeting_location'] = $newLocation;
return $data;
}