From d1f257acc56c81aa3dee96ac4d8f406c80c8d5bc Mon Sep 17 00:00:00 2001 From: rvdforst Date: Thu, 27 Jun 2024 12:46:21 +0200 Subject: [PATCH 1/3] Update ICS.php --- includes/ICS/ICS.php | 76 +++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/includes/ICS/ICS.php b/includes/ICS/ICS.php index 4178981..1527a6c 100644 --- a/includes/ICS/ICS.php +++ b/includes/ICS/ICS.php @@ -6,8 +6,15 @@ class ICS { + // Date and time format public const DT_FORMAT = 'Ymd\THis\Z'; + // Carriage return and line feed + const CRLF = "\r\n"; + + // Length of line in bytes + const LINE_LENGTH = 70; + /** * iCalendar data array. * @@ -86,7 +93,7 @@ public function build(): string fn ($row) => $this->split($row), $this->render() ); - return implode("\r\n", $rows); + return implode(self::CRLF, $rows); } /** @@ -139,13 +146,12 @@ private function sanitizeValue(string $value, string $key = ''): string case 'dtstart': $value = $this->formatTimestamp($value); break; - case 'summary': case 'description': case 'location': - $value = $this->escStr($value, true); + $value = $this->escStr($value); break; default: - $value = $this->escStr($value); + $value = $value; } return $value; @@ -164,60 +170,50 @@ private function formatTimestamp(string $timestamp): string } /** - * Escape special characters. + * Escapes , and ; characters in text type fields. * - * @param string $input - * @param boolean $specialChars + * @param string $value The string to escape * @return string */ - private function escStr(string $input, $specialChars = false): string + private function escStr(string $value): string { - if ($specialChars) { - $input = preg_replace('/([\,;])/', '\\\$1', $input); - } - $input = str_replace("\n", "\\n", $input); - $input = str_replace("\r", "\\r", $input); - return $input; + $value = preg_replace('/((? 75) { + $start = 0; - // Subsequent line break limit is $lineLimit - 1 due to leading whitespace - $output .= "\n " . mb_substr($line, 0, $lineLimit - 1); + while ($start < $length) { + $cut = mb_strcut($value, $start, self::LINE_LENGTH, 'UTF-8'); + $output .= $cut; + $start = $start + strlen($cut); - while (mb_strlen($line) > $lineLimit - 1) { - $line = mb_substr($line, $lineLimit - 1); - $output .= "\n " . mb_substr($line, 0, $lineLimit - 1); + // Add space if not last line + if ($start < $length) { + $output .= self::CRLF . ' '; } } - $pos = $newLinepos; + } else { + $output = $value; } return $output; From 50a60f4705869f9bf5f1b1229517a3c3db3d49c6 Mon Sep 17 00:00:00 2001 From: rvdforst Date: Thu, 27 Jun 2024 12:46:32 +0200 Subject: [PATCH 2/3] Update Utils.php --- includes/Utils.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/Utils.php b/includes/Utils.php index 02568da..b8f7f47 100644 --- a/includes/Utils.php +++ b/includes/Utils.php @@ -893,6 +893,10 @@ public static function titleFilter($where, $wp_query) */ public static function validateDate($date) { + if (empty($date)) { + return false; + } + if ($date instanceof \DateTime) { return true; } From c9363e0bbcd5d41d384f00dfd5260c72151f3e7f Mon Sep 17 00:00:00 2001 From: rvdforst Date: Thu, 27 Jun 2024 12:46:36 +0200 Subject: [PATCH 3/3] Update rrze-calendar.php --- rrze-calendar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rrze-calendar.php b/rrze-calendar.php index ca3bc1d..e231e2b 100644 --- a/rrze-calendar.php +++ b/rrze-calendar.php @@ -4,7 +4,7 @@ Plugin Name: RRZE Calendar Plugin URI: https://github.com/RRZE-Webteam/rrze-calendar Description: Import and output of FAU public events. -Version: 2.2.8 +Version: 2.2.9 Author: RRZE Webteam Author URI: https://blogs.fau.de/webworking/ License: GNU General Public License v3.0