Skip to content

Commit

Permalink
Return the images from the HTML text of the question and answer, if a…
Browse files Browse the repository at this point in the history
…vailable
  • Loading branch information
edmundedgar committed Nov 3, 2012
1 parent 1bc87db commit 55181fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,18 @@ function sloodle_clean_for_output($str)
return sloodle_strip_new_lines(strip_tags(stripcslashes(@html_entity_decode($str, ENT_QUOTES, 'UTF-8'))));
}

/**
* Returns the src of the first <img> tag found in the html
* @param string str The string to clean.
* @return string
*/
function sloodle_extract_first_image_url($html) {
if (preg_match("/<img .*?(?=src)src=\"([^\"]+)\"/si", $html, $m)) {
return $m[1];
}
return '';
}

/**
* Returns the given string with new line characters removed
* Removes new line characters
Expand Down
9 changes: 7 additions & 2 deletions mod/quiz-1.0/linker_moodle_2_0_down.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@
/// Print all the questions
$number = quiz_first_questionnumber($attempt->layout, $pagelist);
foreach ($pagequestions as $i) {

$options = quiz_get_renderoptions($quiz->review, $states[$i]);
// Print the question
// var_dump($questions[$i]);
Expand Down Expand Up @@ -433,7 +434,8 @@
$q->maxgrade,
$q->single,
$shuffleanswers,
0 //$deferred // This variable doesn't seem to be mentioned anywhere else in the file
0, //$deferred // This variable doesn't seem to be mentioned anywhere else in the file
sloodle_extract_first_image_url($q->questiontext)
);

// Create an output array for our options (available answers) so that we can shuffle them later if necessary
Expand All @@ -451,7 +453,9 @@
$ov->question,
sloodle_clean_for_output($ov->answer),
$ov->fraction,
sloodle_clean_for_output($ov->feedback)
sloodle_clean_for_output($ov->feedback),
sloodle_extract_first_image_url($ov->answer),
sloodle_extract_first_image_url($ov->feedback)
);
}
}
Expand All @@ -466,6 +470,7 @@
$number += $questions[$i]->length;
}


$secondsleft = ($quiz->timeclose ? $quiz->timeclose : 999999999999) - time();
//if ($isteacher) {
// // For teachers ignore the quiz closing time
Expand Down

0 comments on commit 55181fc

Please sign in to comment.