mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
Merge branch 'MDL-61052-master' of git://github.com/damyon/moodle
This commit is contained in:
commit
57846fd010
2 changed files with 16 additions and 17 deletions
|
@ -120,22 +120,22 @@ EOD;
|
||||||
* @return string New html with no image tags.
|
* @return string New html with no image tags.
|
||||||
*/
|
*/
|
||||||
protected static function strip_images($html) {
|
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 = new DOMDocument();
|
||||||
$dom->loadHTML("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" . $html);
|
libxml_use_internal_errors(true);
|
||||||
$images = $dom->getElementsByTagName('img');
|
$dom->loadHTML('<?xml version="1.0" encoding="UTF-8" ?>' . $html);
|
||||||
$i = 0;
|
libxml_clear_errors();
|
||||||
|
|
||||||
for ($i = ($images->length - 1); $i >= 0; $i--) {
|
// Find all img tags.
|
||||||
$node = $images->item($i);
|
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);
|
||||||
|
|
||||||
if ($node->hasAttribute('alt')) {
|
$imgnode->parentNode->replaceChild($textnode, $imgnode);
|
||||||
$replacement = ' [ ' . $node->getAttribute('alt') . ' ] ';
|
|
||||||
} else {
|
|
||||||
$replacement = ' ';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$text = $dom->createTextNode($replacement);
|
|
||||||
$node->parentNode->replaceChild($text, $node);
|
|
||||||
}
|
}
|
||||||
$count = 1;
|
$count = 1;
|
||||||
return str_replace("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", "", $dom->saveHTML(), $count);
|
return str_replace("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", "", $dom->saveHTML(), $count);
|
||||||
|
|
|
@ -397,11 +397,10 @@ class assign_submission_onlinetext extends assign_submission_plugin {
|
||||||
|
|
||||||
// Note that this check is the same logic as the result from the is_empty function but we do
|
// 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.
|
// not call it directly because we already have the submission record.
|
||||||
if ($onlinetextsubmission && !empty($onlinetextsubmission->onlinetext)) {
|
if ($onlinetextsubmission) {
|
||||||
$finaltext = $this->assignment->download_rewrite_pluginfile_urls($onlinetextsubmission->onlinetext, $user, $this);
|
// Do not pass the text through format_text. The result may not be displayed in Moodle and
|
||||||
$formattedtext = format_text($finaltext,
|
// may be passed to external services such as document conversion or portfolios.
|
||||||
$onlinetextsubmission->onlineformat,
|
$formattedtext = $this->assignment->download_rewrite_pluginfile_urls($onlinetextsubmission->onlinetext, $user, $this);
|
||||||
array('context'=>$this->assignment->get_context()));
|
|
||||||
$head = '<head><meta charset="UTF-8"></head>';
|
$head = '<head><meta charset="UTF-8"></head>';
|
||||||
$submissioncontent = '<!DOCTYPE html><html>' . $head . '<body>'. $formattedtext . '</body></html>';
|
$submissioncontent = '<!DOCTYPE html><html>' . $head . '<body>'. $formattedtext . '</body></html>';
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue