Skip to content

Commit

Permalink
MDL-65026 course: Fix modules intro formatting in WS
Browse files Browse the repository at this point in the history
The Web Service seems to be doing excessive text cleaning.
  • Loading branch information
jleyva committed Sep 16, 2019
1 parent 1c3efe4 commit dfd4881
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 32 deletions.
7 changes: 4 additions & 3 deletions mod/assign/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion mod/book/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion mod/chat/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 3 additions & 4 deletions mod/choice/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions mod/data/classes/external/database_summary_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ protected function get_format_parameters_for_intro() {
return [
'component' => 'mod_data',
'filearea' => 'intro',
'options' => array('noclean' => true),
];
}
}
1 change: 1 addition & 0 deletions mod/data/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<button>Test with HTML allowed.</button>';
$database1 = self::getDataGenerator()->create_module('data', $record);

// Second database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ protected function get_format_parameters_for_intro() {
return [
'component' => 'mod_feedback',
'filearea' => 'intro',
'options' => array('noclean' => true),
];
}

Expand Down
5 changes: 3 additions & 2 deletions mod/folder/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions mod/forum/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions mod/glossary/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion mod/imscp/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions mod/label/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions mod/lesson/classes/external/lesson_summary_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ protected function get_format_parameters_for_intro() {
return [
'component' => 'mod_lesson',
'filearea' => 'intro',
'options' => array('noclean' => true),
];
}
}
3 changes: 2 additions & 1 deletion mod/lti/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 3 additions & 2 deletions mod/page/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions mod/quiz/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions mod/quiz/tests/external_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public function test_mod_quiz_get_quizzes_by_courses() {
// Second quiz.
$record = new stdClass();
$record->course = $course2->id;
$record->intro = '<button>Test with HTML allowed.</button>';
$quiz2 = self::getDataGenerator()->create_module('quiz', $record);

// Execute real Moodle enrolment as we'll call unenrol() method on the instance later.
Expand Down
7 changes: 4 additions & 3 deletions mod/resource/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
3 changes: 2 additions & 1 deletion mod/scorm/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion mod/survey/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions mod/url/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion mod/wiki/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ protected function get_format_parameters_for_intro() {
return [
'component' => 'mod_workshop',
'filearea' => 'intro',
'options' => array('noclean' => true),
];
}

Expand Down

0 comments on commit dfd4881

Please sign in to comment.