Commit ca51e4f7 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic

Bug 1804328: Clean 'modal' and 'modal-..' classes from comments

behatnotneeded

Change-Id: I5b59c45ef7b84b947615ed4ccd8a0651aa935fdb
(cherry picked from commit c7dc45bc)
(cherry picked from commit 65a23474)
parent 309d31fb
......@@ -111,6 +111,7 @@ function edit_comment_submit(Pieform $form, $values) {
$owner = $view->get('owner');
$group = $comment->get('group');
$newdescription = EmbeddedImage::prepare_embedded_images($values['message'], 'comment', $comment->get('id'), $group);
$newdescription = ArtefactTypeComment::remove_comments_classes($newdescription);
$comment->set('description', $newdescription);
$approvecomments = $view->get('approvecomments');
if (!empty($group) && ($approvecomments || (!$approvecomments && $view->user_comments_allowed($USER) == 'private')) && $values['ispublic'] && !$USER->can_edit_view($view)) {
......
......@@ -126,6 +126,9 @@ class LeapImportComment extends LeapImportArtefactPlugin {
if ($type == 'text') {
$description = format_whitespace($description);
}
else {
$description = ArtefactTypeComment::remove_comments_classes($description);
}
if (isset($entry->author->name) && strlen($entry->author->name)) {
$authorname = (string)$entry->author->name;
}
......
......@@ -1155,6 +1155,29 @@ class ArtefactTypeComment extends ArtefactType {
}
}
/*
* Removes the classes from the text of the comment thst could interfere
* with the comment display
* @param string $comment the text content of the comment
*/
public static function remove_comments_classes($comment) {
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadHTML($comment);
$xpath = new DOMXPath($dom);
$expression = "//div[contains(@class,'modal-docked')]|//div[contains(@class,'modal')]|//div[contains(@class,'modal-dialog')]|//div[contains(@class,'modal-lg')]";
foreach ($xpath->evaluate($expression) as $section) {
$section->removeAttribute('class');
}
return $dom->saveHTML();
}
/**
* Fetch all users that are currently watching the view the comment is being added to,
* in case of comment on artefact it will be the view the artefact sits on,
......@@ -1580,11 +1603,11 @@ function add_feedback_form_validate(Pieform $form, $values) {
function add_feedback_form_submit(Pieform $form, $values) {
global $view, $artefact, $USER;
require_once('embeddedimage.php');
$data = (object) array(
'title' => get_string('Comment', 'artefact.comment'),
'description' => $values['message'],
'description' => ArtefactTypeComment::remove_comments_classes($values['message']),
);
if ($artefact) {
$data->onartefact = $artefact->get('id');
$data->owner = $artefact->get('owner');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment