From 231ddd5a8dc1a6ee59a3b8eba9869960f814e723 Mon Sep 17 00:00:00 2001 From: Soon-Systems Date: Tue, 7 Feb 2017 09:28:51 +0100 Subject: [PATCH 1/2] MDL-54887 calendar: Format summary + description of an event for export --- calendar/export_execute.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/calendar/export_execute.php b/calendar/export_execute.php index a711b766080..535c11e386b 100644 --- a/calendar/export_execute.php +++ b/calendar/export_execute.php @@ -184,6 +184,7 @@ $events = calendar_get_legacy_events($timestart, $timeend, $users, $groups, arra $ical = new iCalendar; $ical->add_property('method', 'PUBLISH'); +$PAGE->set_context(context_user::instance($userid)); foreach($events as $event) { if (!empty($event->modulename)) { $instances = get_fast_modinfo($event->courseid, $userid)->get_instances_of($event->modulename); @@ -194,10 +195,15 @@ foreach($events as $event) { $hostaddress = str_replace('http://', '', $CFG->wwwroot); $hostaddress = str_replace('https://', '', $hostaddress); - $ev = new iCalendar_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', $event->name); - $ev->add_property('description', clean_param($event->description, PARAM_NOTAGS)); + + $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)); + $ev->add_property('class', 'PUBLIC'); // PUBLIC / PRIVATE / CONFIDENTIAL $ev->add_property('last-modified', Bennu::timestamp_to_datetime($event->timemodified)); $ev->add_property('dtstamp', Bennu::timestamp_to_datetime()); // now From e083ac1cde4759c50be6ce9f63a60996b541c529 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Fri, 17 Feb 2017 09:16:16 +0800 Subject: [PATCH 2/2] 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 535c11e386b..c604f22ed17 100644 --- a/calendar/export_execute.php +++ b/calendar/export_execute.php @@ -184,7 +184,6 @@ $events = calendar_get_legacy_events($timestart, $timeend, $users, $groups, arra $ical = new iCalendar; $ical->add_property('method', 'PUBLISH'); -$PAGE->set_context(context_user::instance($userid)); foreach($events as $event) { if (!empty($event->modulename)) { $instances = get_fast_modinfo($event->courseid, $userid)->get_instances_of($event->modulename); @@ -197,12 +196,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));