Commit 65a23474 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)
parent ff925646
...@@ -111,6 +111,7 @@ function edit_comment_submit(Pieform $form, $values) { ...@@ -111,6 +111,7 @@ function edit_comment_submit(Pieform $form, $values) {
$owner = $view->get('owner'); $owner = $view->get('owner');
$group = $comment->get('group'); $group = $comment->get('group');
$newdescription = EmbeddedImage::prepare_embedded_images($values['message'], 'comment', $comment->get('id'), $group); $newdescription = EmbeddedImage::prepare_embedded_images($values['message'], 'comment', $comment->get('id'), $group);
$newdescription = ArtefactTypeComment::remove_comments_classes($newdescription);
$comment->set('description', $newdescription); $comment->set('description', $newdescription);
$approvecomments = $view->get('approvecomments'); $approvecomments = $view->get('approvecomments');
if (!empty($group) && ($approvecomments || (!$approvecomments && $view->user_comments_allowed($USER) == 'private')) && $values['ispublic'] && !$USER->can_edit_view($view)) { 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 { ...@@ -126,6 +126,9 @@ class LeapImportComment extends LeapImportArtefactPlugin {
if ($type == 'text') { if ($type == 'text') {
$description = format_whitespace($description); $description = format_whitespace($description);
} }
else {
$description = ArtefactTypeComment::remove_comments_classes($description);
}
if (isset($entry->author->name) && strlen($entry->author->name)) { if (isset($entry->author->name) && strlen($entry->author->name)) {
$authorname = (string)$entry->author->name; $authorname = (string)$entry->author->name;
} }
......
...@@ -1166,6 +1166,29 @@ class ArtefactTypeComment extends ArtefactType { ...@@ -1166,6 +1166,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, * 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, * in case of comment on artefact it will be the view the artefact sits on,
...@@ -1604,11 +1627,11 @@ function add_feedback_form_validate(Pieform $form, $values) { ...@@ -1604,11 +1627,11 @@ function add_feedback_form_validate(Pieform $form, $values) {
function add_feedback_form_submit(Pieform $form, $values) { function add_feedback_form_submit(Pieform $form, $values) {
global $view, $artefact, $USER; global $view, $artefact, $USER;
require_once('embeddedimage.php'); require_once('embeddedimage.php');
$data = (object) array( $data = (object) array(
'title' => get_string('Comment', 'artefact.comment'), 'title' => get_string('Comment', 'artefact.comment'),
'description' => $values['message'], 'description' => ArtefactTypeComment::remove_comments_classes($values['message']),
); );
if ($artefact) { if ($artefact) {
$data->onartefact = $artefact->get('id'); $data->onartefact = $artefact->get('id');
$data->owner = $artefact->get('owner'); $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