Skip to content

Commit

Permalink
Merge branch 'MDL-61052-35' of git://github.com/damyon/moodle into MO…
Browse files Browse the repository at this point in the history
…ODLE_35_STABLE
  • Loading branch information
David Monllao committed Oct 22, 2018
2 parents a9354db + 3bea0fa commit f9f8edc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
28 changes: 14 additions & 14 deletions mod/assign/feedback/editpdf/classes/document_services.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,22 @@ private static function hash($assignment, $userid, $attemptnumber) {
* @return string New html with no image tags.
*/
protected static function strip_images($html) {
// Load HTML and suppress any parsing errors (DOMDocument->loadHTML() does not current support HTML5 tags).
$dom = new DOMDocument();
$dom->loadHTML("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" . $html);
$images = $dom->getElementsByTagName('img');
$i = 0;

for ($i = ($images->length - 1); $i >= 0; $i--) {
$node = $images->item($i);

if ($node->hasAttribute('alt')) {
$replacement = ' [ ' . $node->getAttribute('alt') . ' ] ';
} else {
$replacement = ' ';
libxml_use_internal_errors(true);
$dom->loadHTML('<?xml version="1.0" encoding="UTF-8" ?>' . $html);
libxml_clear_errors();

// Find all img tags.
if ($imgnodes = $dom->getElementsByTagName('img')) {
// Replace img nodes with the img alt text without overriding DOM elements.
for ($i = ($imgnodes->length - 1); $i >= 0; $i--) {
$imgnode = $imgnodes->item($i);
$alt = ($imgnode->hasAttribute('alt')) ? ' [ ' . $imgnode->getAttribute('alt') . ' ] ' : ' ';
$textnode = $dom->createTextNode($alt);

$imgnode->parentNode->replaceChild($textnode, $imgnode);
}

$text = $dom->createTextNode($replacement);
$node->parentNode->replaceChild($text, $node);
}
$count = 1;
return str_replace("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", "", $dom->saveHTML(), $count);
Expand Down
7 changes: 3 additions & 4 deletions mod/assign/submission/onlinetext/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,9 @@ public function get_files(stdClass $submission, stdClass $user) {
// Note that this check is the same logic as the result from the is_empty function but we do
// not call it directly because we already have the submission record.
if ($onlinetextsubmission && !empty($onlinetextsubmission->onlinetext)) {
$finaltext = $this->assignment->download_rewrite_pluginfile_urls($onlinetextsubmission->onlinetext, $user, $this);
$formattedtext = format_text($finaltext,
$onlinetextsubmission->onlineformat,
array('context'=>$this->assignment->get_context()));
// Do not pass the text through format_text. The result may not be displayed in Moodle and
// may be passed to external services such as document conversion or portfolios.
$formattedtext = $this->assignment->download_rewrite_pluginfile_urls($onlinetextsubmission->onlinetext, $user, $this);
$head = '<head><meta charset="UTF-8"></head>';
$submissioncontent = '<!DOCTYPE html><html>' . $head . '<body>'. $formattedtext . '</body></html>';

Expand Down

0 comments on commit f9f8edc

Please sign in to comment.