From 28e5a3b978c705e20457b5c71a086e6ba23757d0 Mon Sep 17 00:00:00 2001 From: msquare Date: Sun, 21 Aug 2016 22:58:09 +0200 Subject: user_ical rewrite (remove codacy issues) --- includes/helper/error_helper.php | 2 +- includes/pages/user_ical.php | 108 ++++++++++++++++++++++++--------------- includes/sys_page.php | 10 ++++ 3 files changed, 79 insertions(+), 41 deletions(-) diff --git a/includes/helper/error_helper.php b/includes/helper/error_helper.php index b4b4f248..58d0ac86 100644 --- a/includes/helper/error_helper.php +++ b/includes/helper/error_helper.php @@ -6,7 +6,7 @@ * @param string $message */ function engelsystem_error($message) { - die($message); + raw_output($message); } ?> \ No newline at end of file diff --git a/includes/pages/user_ical.php b/includes/pages/user_ical.php index 2f3d5cd5..c38a336c 100644 --- a/includes/pages/user_ical.php +++ b/includes/pages/user_ical.php @@ -1,54 +1,82 @@ $shifts + */ +function send_ical_from_shifts($shifts) { header("Content-Type: text/calendar; charset=utf-8"); - $html = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//-//Engelsystem//DE\r\nCALSCALE:GREGORIAN\r\n"; + $output = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//-//Engelsystem//DE\r\nCALSCALE:GREGORIAN\r\n"; foreach ($ical_shifts as $shift) { - $html .= "BEGIN:VEVENT\r\n"; - $html .= "UID:" . md5($shift['start'] . $shift['end'] . $shift['name']) . "\r\n"; - $html .= "SUMMARY:" . str_replace("\n", "\\n", $shift['name']) . " (" . str_replace("\n", "\\n", $shift['title']) . ")\r\n"; - if(isset($shift['Comment'])) - $html .= "DESCRIPTION:" . str_replace("\n", "\\n", $shift['Comment']) . "\r\n"; - $html .= "DTSTART;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['start']) . "\r\n"; - $html .= "DTEND;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['end']) . "\r\n"; - $html .= "LOCATION:" . $shift['room_name'] . "\r\n"; - $html .= "END:VEVENT\r\n"; + $output .= make_ical_entry_from_shift($shift); + } + $output .= "END:VCALENDAR\r\n"; + $output = trim($output, "\x0A"); + header("Content-Length: " . strlen($output)); + raw_output($output); +} + +/** + * Renders an ical vevent from given shift. + * + * @param Shift $shift + */ +function make_ical_entry_from_shift($shift) { + $output = "BEGIN:VEVENT\r\n"; + $output .= "UID:" . md5($shift['start'] . $shift['end'] . $shift['name']) . "\r\n"; + $output .= "SUMMARY:" . str_replace("\n", "\\n", $shift['name']) . " (" . str_replace("\n", "\\n", $shift['title']) . ")\r\n"; + if (isset($shift['Comment'])) { + $output .= "DESCRIPTION:" . str_replace("\n", "\\n", $shift['Comment']) . "\r\n"; } - $html .= "END:VCALENDAR\r\n"; - $html = trim($html, "\x0A"); - header("Content-Length: " . strlen($html)); - echo $html; - die(); + $output .= "DTSTART;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['start']) . "\r\n"; + $output .= "DTEND;TZID=Europe/Berlin:" . date("Ymd\THis", $shift['end']) . "\r\n"; + $output .= "LOCATION:" . $shift['Name'] . "\r\n"; + $output .= "END:VEVENT\r\n"; + return $output; } ?> diff --git a/includes/sys_page.php b/includes/sys_page.php index 967a0172..52cffb26 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -8,6 +8,16 @@ function redirect($to) { die(); } +/** + * Echoes given output and dies. + * + * @param String $output + */ +function raw_output($output) { + echo $output; + die(); +} + /** * Gibt den gefilterten REQUEST Wert ohne Zeilenumbrüche zurück */ -- cgit v1.2.3-54-g00ecf