From dfd4881589a7d45388dd43e78559a6f0bdb15b15 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Fri, 16 Aug 2019 11:53:51 +0100 Subject: [PATCH] MDL-65026 course: Fix modules intro formatting in WS The Web Service seems to be doing excessive text cleaning. --- mod/assign/externallib.php | 7 ++++--- mod/book/classes/external.php | 3 ++- mod/chat/classes/external.php | 3 ++- mod/choice/classes/external.php | 7 +++---- mod/data/classes/external/database_summary_exporter.php | 1 + mod/data/tests/externallib_test.php | 1 + .../classes/external/feedback_summary_exporter.php | 1 + mod/folder/classes/external.php | 5 +++-- mod/forum/externallib.php | 5 +++-- mod/glossary/classes/external.php | 6 ++++-- mod/imscp/classes/external.php | 4 +++- mod/label/classes/external.php | 6 +++--- mod/lesson/classes/external/lesson_summary_exporter.php | 1 + mod/lti/classes/external.php | 3 ++- mod/page/classes/external.php | 5 +++-- mod/quiz/classes/external.php | 5 +++-- mod/quiz/tests/external_test.php | 1 + mod/resource/classes/external.php | 7 ++++--- mod/scorm/classes/external.php | 3 ++- mod/survey/classes/external.php | 4 +++- mod/url/classes/external.php | 5 +++-- mod/wiki/classes/external.php | 3 ++- .../classes/external/workshop_summary_exporter.php | 1 + 23 files changed, 55 insertions(+), 32 deletions(-) diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php index 2da9021b80d81..5cc88bb55a7fb 100644 --- a/mod/assign/externallib.php +++ b/mod/assign/externallib.php @@ -462,9 +462,10 @@ public static function get_assignments($courseids = array(), $capabilities = arr // Return or not intro and file attachments depending on the plugin settings. if ($assign->show_intro()) { - - list($assignment['intro'], $assignment['introformat']) = external_format_text($module->intro, - $module->introformat, $context->id, 'mod_assign', 'intro', null); + $options = array('noclean' => true); + list($assignment['intro'], $assignment['introformat']) = + external_format_text($module->intro, $module->introformat, $context->id, 'mod_assign', 'intro', null, + $options); $assignment['introfiles'] = external_util::get_area_files($context->id, 'mod_assign', 'intro', false, false); diff --git a/mod/book/classes/external.php b/mod/book/classes/external.php index 189d2c68e8e17..2047f5a4bfd15 100644 --- a/mod/book/classes/external.php +++ b/mod/book/classes/external.php @@ -205,8 +205,9 @@ public static function get_books_by_courses($courseids = array()) { $bookdetails['course'] = $book->course; $bookdetails['name'] = external_format_string($book->name, $context->id); // Format intro. + $options = array('noclean' => true); list($bookdetails['intro'], $bookdetails['introformat']) = - external_format_text($book->intro, $book->introformat, $context->id, 'mod_book', 'intro', null); + external_format_text($book->intro, $book->introformat, $context->id, 'mod_book', 'intro', null, $options); $bookdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_book', 'intro', false, false); $bookdetails['numbering'] = $book->numbering; $bookdetails['navstyle'] = $book->navstyle; diff --git a/mod/chat/classes/external.php b/mod/chat/classes/external.php index 0ef65660cd321..d4012db8b1a32 100644 --- a/mod/chat/classes/external.php +++ b/mod/chat/classes/external.php @@ -549,8 +549,9 @@ public static function get_chats_by_courses($courseids = array()) { $chatdetails['course'] = $chat->course; $chatdetails['name'] = external_format_string($chat->name, $chatcontext->id); // Format intro. + $options = array('noclean' => true); list($chatdetails['intro'], $chatdetails['introformat']) = - external_format_text($chat->intro, $chat->introformat, $chatcontext->id, 'mod_chat', 'intro', null); + external_format_text($chat->intro, $chat->introformat, $chatcontext->id, 'mod_chat', 'intro', null, $options); $chatdetails['introfiles'] = external_util::get_area_files($chatcontext->id, 'mod_chat', 'intro', false, false); if (has_capability('mod/chat:chat', $chatcontext)) { diff --git a/mod/choice/classes/external.php b/mod/choice/classes/external.php index 8fc4e4cdde063..cdcadd117fd20 100644 --- a/mod/choice/classes/external.php +++ b/mod/choice/classes/external.php @@ -502,11 +502,10 @@ public static function get_choices_by_courses($courseids = array()) { $choicedetails['course'] = $choice->course; $choicedetails['name'] = external_format_string($choice->name, $context->id); // Format intro. + $options = array('noclean' => true); list($choicedetails['intro'], $choicedetails['introformat']) = - external_format_text($choice->intro, $choice->introformat, - $context->id, 'mod_choice', 'intro', null); - $choicedetails['introfiles'] = external_util::get_area_files($context->id, 'mod_choice', 'intro', false, - false); + external_format_text($choice->intro, $choice->introformat, $context->id, 'mod_choice', 'intro', null, $options); + $choicedetails['introfiles'] = external_util::get_area_files($context->id, 'mod_choice', 'intro', false, false); if (has_capability('mod/choice:choose', $context)) { $choicedetails['publish'] = $choice->publish; diff --git a/mod/data/classes/external/database_summary_exporter.php b/mod/data/classes/external/database_summary_exporter.php index 4499853ac105b..79e522d5b90f6 100644 --- a/mod/data/classes/external/database_summary_exporter.php +++ b/mod/data/classes/external/database_summary_exporter.php @@ -237,6 +237,7 @@ protected function get_format_parameters_for_intro() { return [ 'component' => 'mod_data', 'filearea' => 'intro', + 'options' => array('noclean' => true), ]; } } diff --git a/mod/data/tests/externallib_test.php b/mod/data/tests/externallib_test.php index f34f0328b8d1e..d2314aae9b6ca 100644 --- a/mod/data/tests/externallib_test.php +++ b/mod/data/tests/externallib_test.php @@ -141,6 +141,7 @@ public function test_mod_data_get_databases_by_courses() { $record = new stdClass(); $record->introformat = FORMAT_HTML; $record->course = $course1->id; + $record->intro = ''; $database1 = self::getDataGenerator()->create_module('data', $record); // Second database. diff --git a/mod/feedback/classes/external/feedback_summary_exporter.php b/mod/feedback/classes/external/feedback_summary_exporter.php index 2cccd93513104..856b67bc983be 100644 --- a/mod/feedback/classes/external/feedback_summary_exporter.php +++ b/mod/feedback/classes/external/feedback_summary_exporter.php @@ -173,6 +173,7 @@ protected function get_format_parameters_for_intro() { return [ 'component' => 'mod_feedback', 'filearea' => 'intro', + 'options' => array('noclean' => true), ]; } diff --git a/mod/folder/classes/external.php b/mod/folder/classes/external.php index f875c929b534b..81ccfc95ef32f 100644 --- a/mod/folder/classes/external.php +++ b/mod/folder/classes/external.php @@ -157,8 +157,9 @@ public static function get_folders_by_courses($courseids = array()) { // Entry to return. $folder->name = external_format_string($folder->name, $context->id); - list($folder->intro, $folder->introformat) = external_format_text($folder->intro, - $folder->introformat, $context->id, 'mod_folder', 'intro', null); + $options = array('noclean' => true); + list($folder->intro, $folder->introformat) = + external_format_text($folder->intro, $folder->introformat, $context->id, 'mod_folder', 'intro', null, $options); $folder->introfiles = external_util::get_area_files($context->id, 'mod_folder', 'intro', false, false); $returnedfolders[] = $folder; diff --git a/mod/forum/externallib.php b/mod/forum/externallib.php index 5a6fb60a7cc52..e60e2421e60e0 100644 --- a/mod/forum/externallib.php +++ b/mod/forum/externallib.php @@ -93,8 +93,9 @@ public static function get_forums_by_courses($courseids = array()) { $forum->name = external_format_string($forum->name, $context->id); // Format the intro before being returning using the format setting. - list($forum->intro, $forum->introformat) = external_format_text($forum->intro, $forum->introformat, - $context->id, 'mod_forum', 'intro', null); + $options = array('noclean' => true); + list($forum->intro, $forum->introformat) = + external_format_text($forum->intro, $forum->introformat, $context->id, 'mod_forum', 'intro', null, $options); $forum->introfiles = external_util::get_area_files($context->id, 'mod_forum', 'intro', false, false); // Discussions count. This function does static request cache. $forum->numdiscussions = forum_count_discussions($forum, $cm, $course); diff --git a/mod/glossary/classes/external.php b/mod/glossary/classes/external.php index e60ef92a91f5d..a06d115cc0207 100644 --- a/mod/glossary/classes/external.php +++ b/mod/glossary/classes/external.php @@ -222,8 +222,10 @@ public static function get_glossaries_by_courses($courseids = array()) { foreach ($glossaries as $glossary) { $context = context_module::instance($glossary->coursemodule); $glossary->name = external_format_string($glossary->name, $context->id); - list($glossary->intro, $glossary->introformat) = external_format_text($glossary->intro, $glossary->introformat, - $context->id, 'mod_glossary', 'intro', null); + $options = array('noclean' => true); + list($glossary->intro, $glossary->introformat) = + external_format_text($glossary->intro, $glossary->introformat, $context->id, 'mod_glossary', 'intro', null, + $options); $glossary->introfiles = external_util::get_area_files($context->id, 'mod_glossary', 'intro', false, false); // Make sure we have a number of entries per page. diff --git a/mod/imscp/classes/external.php b/mod/imscp/classes/external.php index 85292af661f7d..e8db88c9db7a3 100644 --- a/mod/imscp/classes/external.php +++ b/mod/imscp/classes/external.php @@ -163,8 +163,10 @@ public static function get_imscps_by_courses($courseids = array()) { if (has_capability('mod/imscp:view', $context)) { // Format intro. + $options = array('noclean' => true); list($imscpdetails['intro'], $imscpdetails['introformat']) = - external_format_text($imscp->intro, $imscp->introformat, $context->id, 'mod_imscp', 'intro', null); + external_format_text($imscp->intro, $imscp->introformat, $context->id, 'mod_imscp', 'intro', null, + $options); $imscpdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_imscp', 'intro', false, false); } diff --git a/mod/label/classes/external.php b/mod/label/classes/external.php index 064af2d7e7af2..6b575129dbbe7 100644 --- a/mod/label/classes/external.php +++ b/mod/label/classes/external.php @@ -91,9 +91,9 @@ public static function get_labels_by_courses($courseids = array()) { $context = context_module::instance($label->coursemodule); // Entry to return. $label->name = external_format_string($label->name, $context->id); - - list($label->intro, $label->introformat) = external_format_text($label->intro, - $label->introformat, $context->id, 'mod_label', 'intro', null); + $options = array('noclean' => true); + list($label->intro, $label->introformat) = + external_format_text($label->intro, $label->introformat, $context->id, 'mod_label', 'intro', null, $options); $label->introfiles = external_util::get_area_files($context->id, 'mod_label', 'intro', false, false); $returnedlabels[] = $label; diff --git a/mod/lesson/classes/external/lesson_summary_exporter.php b/mod/lesson/classes/external/lesson_summary_exporter.php index fb262be14dbf8..e0fa14a5d53f7 100644 --- a/mod/lesson/classes/external/lesson_summary_exporter.php +++ b/mod/lesson/classes/external/lesson_summary_exporter.php @@ -301,6 +301,7 @@ protected function get_format_parameters_for_intro() { return [ 'component' => 'mod_lesson', 'filearea' => 'intro', + 'options' => array('noclean' => true), ]; } } diff --git a/mod/lti/classes/external.php b/mod/lti/classes/external.php index b6e081ee14bdb..dad4370feea58 100644 --- a/mod/lti/classes/external.php +++ b/mod/lti/classes/external.php @@ -312,8 +312,9 @@ public static function get_ltis_by_courses($courseids = array()) { $viewablefields = []; if (has_capability('mod/lti:view', $context)) { + $options = array('noclean' => true); list($module['intro'], $module['introformat']) = - external_format_text($lti->intro, $lti->introformat, $context->id, 'mod_lti', 'intro', null); + external_format_text($lti->intro, $lti->introformat, $context->id, 'mod_lti', 'intro', null, $options); $module['introfiles'] = external_util::get_area_files($context->id, 'mod_lti', 'intro', false, false); $viewablefields = array('launchcontainer', 'showtitlelaunch', 'showdescriptionlaunch', 'icon', 'secureicon'); diff --git a/mod/page/classes/external.php b/mod/page/classes/external.php index 8b10f1e8370d8..511d22285f57a 100644 --- a/mod/page/classes/external.php +++ b/mod/page/classes/external.php @@ -157,8 +157,9 @@ public static function get_pages_by_courses($courseids = array()) { // Entry to return. $page->name = external_format_string($page->name, $context->id); - list($page->intro, $page->introformat) = external_format_text($page->intro, - $page->introformat, $context->id, 'mod_page', 'intro', null); + $options = array('noclean' => true); + list($page->intro, $page->introformat) = + external_format_text($page->intro, $page->introformat, $context->id, 'mod_page', 'intro', null, $options); $page->introfiles = external_util::get_area_files($context->id, 'mod_page', 'intro', false, false); $options = array('noclean' => true); diff --git a/mod/quiz/classes/external.php b/mod/quiz/classes/external.php index cfdc4a89d33ef..f7efb989a98ee 100644 --- a/mod/quiz/classes/external.php +++ b/mod/quiz/classes/external.php @@ -105,8 +105,9 @@ public static function get_quizzes_by_courses($courseids = array()) { if (has_capability('mod/quiz:view', $context)) { // Format intro. - list($quizdetails['intro'], $quizdetails['introformat']) = external_format_text($quiz->intro, - $quiz->introformat, $context->id, 'mod_quiz', 'intro', null); + $options = array('noclean' => true); + list($quizdetails['intro'], $quizdetails['introformat']) = + external_format_text($quiz->intro, $quiz->introformat, $context->id, 'mod_quiz', 'intro', null, $options); $quizdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_quiz', 'intro', false, false); $viewablefields = array('timeopen', 'timeclose', 'grademethod', 'section', 'visible', 'groupmode', diff --git a/mod/quiz/tests/external_test.php b/mod/quiz/tests/external_test.php index a5072f2f4326f..14dec66b12f37 100644 --- a/mod/quiz/tests/external_test.php +++ b/mod/quiz/tests/external_test.php @@ -176,6 +176,7 @@ public function test_mod_quiz_get_quizzes_by_courses() { // Second quiz. $record = new stdClass(); $record->course = $course2->id; + $record->intro = ''; $quiz2 = self::getDataGenerator()->create_module('quiz', $record); // Execute real Moodle enrolment as we'll call unenrol() method on the instance later. diff --git a/mod/resource/classes/external.php b/mod/resource/classes/external.php index 539aaf5279aa7..35a23fce88e9d 100644 --- a/mod/resource/classes/external.php +++ b/mod/resource/classes/external.php @@ -156,9 +156,10 @@ public static function get_resources_by_courses($courseids = array()) { $context = context_module::instance($resource->coursemodule); // Entry to return. $resource->name = external_format_string($resource->name, $context->id); - - list($resource->intro, $resource->introformat) = external_format_text($resource->intro, - $resource->introformat, $context->id, 'mod_resource', 'intro', null); + $options = array('noclean' => true); + list($resource->intro, $resource->introformat) = + external_format_text($resource->intro, $resource->introformat, $context->id, 'mod_resource', 'intro', null, + $options); $resource->introfiles = external_util::get_area_files($context->id, 'mod_resource', 'intro', false, false); $resource->contentfiles = external_util::get_area_files($context->id, 'mod_resource', 'content'); diff --git a/mod/scorm/classes/external.php b/mod/scorm/classes/external.php index aa0313916ae79..25a99c2dc423f 100644 --- a/mod/scorm/classes/external.php +++ b/mod/scorm/classes/external.php @@ -691,8 +691,9 @@ public static function get_scorms_by_courses($courseids = array()) { $module['coursemodule'] = $scorm->coursemodule; $module['course'] = $scorm->course; $module['name'] = external_format_string($scorm->name, $context->id); + $options = array('noclean' => true); list($module['intro'], $module['introformat']) = - external_format_text($scorm->intro, $scorm->introformat, $context->id, 'mod_scorm', 'intro', null); + external_format_text($scorm->intro, $scorm->introformat, $context->id, 'mod_scorm', 'intro', null, $options); $module['introfiles'] = external_util::get_area_files($context->id, 'mod_scorm', 'intro', false, false); // Check if the SCORM open and return warnings if so. diff --git a/mod/survey/classes/external.php b/mod/survey/classes/external.php index 0d53c41e18da6..8b361c14e7a09 100644 --- a/mod/survey/classes/external.php +++ b/mod/survey/classes/external.php @@ -104,8 +104,10 @@ public static function get_surveys_by_courses($courseids = array()) { } // Format intro. + $options = array('noclean' => true); list($surveydetails['intro'], $surveydetails['introformat']) = - external_format_text($survey->intro, $survey->introformat, $context->id, 'mod_survey', 'intro', null); + external_format_text($survey->intro, $survey->introformat, $context->id, 'mod_survey', 'intro', null, + $options); $surveydetails['introfiles'] = external_util::get_area_files($context->id, 'mod_survey', 'intro', false, false); diff --git a/mod/url/classes/external.php b/mod/url/classes/external.php index aba5d4079ea09..458a4c8aadba5 100644 --- a/mod/url/classes/external.php +++ b/mod/url/classes/external.php @@ -157,8 +157,9 @@ public static function get_urls_by_courses($courseids = array()) { // Entry to return. $url->name = external_format_string($url->name, $context->id); - list($url->intro, $url->introformat) = external_format_text($url->intro, - $url->introformat, $context->id, 'mod_url', 'intro', null); + $options = array('noclean' => true); + list($url->intro, $url->introformat) = + external_format_text($url->intro, $url->introformat, $context->id, 'mod_url', 'intro', null, $options); $url->introfiles = external_util::get_area_files($context->id, 'mod_url', 'intro', false, false); $returnedurls[] = $url; diff --git a/mod/wiki/classes/external.php b/mod/wiki/classes/external.php index 34a91c3240a51..4a1475595177b 100644 --- a/mod/wiki/classes/external.php +++ b/mod/wiki/classes/external.php @@ -102,8 +102,9 @@ public static function get_wikis_by_courses($courseids = array()) { $viewablefields = []; if (has_capability('mod/wiki:viewpage', $context)) { + $options = array('noclean' => true); list($module['intro'], $module['introformat']) = - external_format_text($wiki->intro, $wiki->introformat, $context->id, 'mod_wiki', 'intro', null); + external_format_text($wiki->intro, $wiki->introformat, $context->id, 'mod_wiki', 'intro', null, $options); $module['introfiles'] = external_util::get_area_files($context->id, 'mod_wiki', 'intro', false, false); $viewablefields = array('firstpagetitle', 'wikimode', 'defaultformat', 'forceformat', 'editbegin', 'editend', diff --git a/mod/workshop/classes/external/workshop_summary_exporter.php b/mod/workshop/classes/external/workshop_summary_exporter.php index d7a833280cd43..45edd78d9625e 100644 --- a/mod/workshop/classes/external/workshop_summary_exporter.php +++ b/mod/workshop/classes/external/workshop_summary_exporter.php @@ -325,6 +325,7 @@ protected function get_format_parameters_for_intro() { return [ 'component' => 'mod_workshop', 'filearea' => 'intro', + 'options' => array('noclean' => true), ]; }