From 3bfdb64f433f6d3bbf6f755e0d5cb3424d6bbb2e Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Fri, 17 Feb 2017 09:16:16 +0800 Subject: [PATCH] MDL-54887 calendar: PR fixes * Use the calendar_event::description property and format it using format_text() on it in order to apply the appropriate filters. * Then use html_to_text() on it to strip the tags and convert the description to plain text while converting
and

tags to line breaks. --- calendar/export_execute.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/calendar/export_execute.php b/calendar/export_execute.php index 736415afc24..3964b213cb0 100644 --- a/calendar/export_execute.php +++ b/calendar/export_execute.php @@ -183,7 +183,6 @@ $events = calendar_get_events($timestart, $timeend, $users, $groups, array_keys( $ical = new iCalendar; $ical->add_property('method', 'PUBLISH'); -$PAGE->set_context(context_user::instance($userid)); foreach($events as $event) { if (!empty($event->modulename)) { $cm = get_coursemodule_from_instance($event->modulename, $event->instance); @@ -196,12 +195,17 @@ foreach($events as $event) { $me = new calendar_event($event); // To use moodle calendar event services. $ev = new iCalendar_event; // To export in ical format. - $ev->add_property('uid', $event->id.'@'.$hostaddress); - $ev->add_property('summary', format_string($event->name, true, array('context' => $me->context))); - $descr = format_string($event->description, true, array('context' => $me->context)); - $ev->add_property('description', clean_param($descr, PARAM_NOTAGS)); + // Set iCal event summary from event name. + $ev->add_property('summary', format_string($event->name, true, ['context' => $me->context])); + + // Format the description text. + $description = format_text($me->description, $me->format, ['context' => $me->context]); + // Then convert it to plain text, since it's the only format allowed for the event description property. + // We use html_to_text in order to convert
and

tags to new line characters for descriptions in HTML format. + $description = html_to_text($description, 0); + $ev->add_property('description', $description); $ev->add_property('class', 'PUBLIC'); // PUBLIC / PRIVATE / CONFIDENTIAL $ev->add_property('last-modified', Bennu::timestamp_to_datetime($event->timemodified));