MDL-54887 calendar: PR fixes
authorJun Pataleta <jun@moodle.com>
Fri, 17 Feb 2017 01:16:16 +0000 (09:16 +0800)
committerJun Pataleta <jun@moodle.com>
Tue, 30 May 2017 08:52:12 +0000 (16:52 +0800)
* 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 <br> and <p> tags to
line breaks.

calendar/export_execute.php

index 535c11e..c604f22 100644 (file)
@@ -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 <br> and <p> 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));