Commit 44cc873c authored by Robert Lyon's avatar Robert Lyon Committed by Cecilia Vela Gurovic

Bug 1844748: Trying to get property of non-object on comment delete

To test - see bug report

Also should fix the error
DOMDocument::loadHTML(): Misplaced DOCTYPE declaration in Entity, line: 1

When deleting a comment on someone elses page

behatnotneeded

Change-Id: I5bdbcb239d0f8f887355238bf89eb04facc85420
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent aef1675e
......@@ -798,7 +798,9 @@ class ArtefactTypeComment extends ArtefactType {
}
else if (($candelete || $item->isauthor) && !$is_export_preview) {
$check = get_record_sql('SELECT v.* FROM {view} v WHERE v.id = ?', array($data->view), ERROR_MULTIPLE);
if ($check->submittedstatus == View::UNSUBMITTED ||
($item->canedit && $item->private) ||
($item->canedit && $item->id == $lastcomment->id && $item->ts > $editableafter)
) {
$item->deleteform = pieform(self::delete_comment_form($item->id, $data->blockid, $data->artefact, $data->threaded));
......@@ -1522,7 +1524,7 @@ function delete_comment_submit(Pieform $form, $values) {
// unless it is the last comment still with in the editable timeframe
$editableafter = time() - 60 * get_config_plugin('artefact', 'comment', 'commenteditabletime');
$lastcomment = ($artefact) ? $comment::last_public_comment($viewid, $artefact) : $comment::last_public_comment($viewid, null);
if ($comment->get('id') == $lastcomment->id && $comment->get('mtime') > $editableafter) {
if ($comment->get('private') || ($comment->get('id') == $lastcomment->id && $comment->get('mtime') > $editableafter)) {
$candelete = 1;
}
else {
......@@ -2154,7 +2156,7 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin {
);
$this->users[$key]->emailmessage = get_string_from_language(
$lang, 'feedbacknotificationtext', 'artefact.comment',
$authorname, $title, $posttime, trim(html2text(htmlspecialchars($body))), get_config('wwwroot') . $this->url
$authorname, $title, $posttime, trim(html2text($body)), get_config('wwwroot') . $this->url
);
}
}
......
......@@ -3984,7 +3984,10 @@ function clean_css($input_css, $preserve_css=false) {
function html2text($html, $fragment=true) {
require_once('htmltotext/htmltotext.php');
if ($fragment) {
$html = '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head>' . $html;
// Check if fragment is actually a fragment as tinymce can return a valid html page
if (!preg_match('/^<(HTML|\!doctype).*?>/i', $html)) {
$html = '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head>' . $html;
}
}
$h2t = new HtmltoText($html, get_config('wwwroot'));
return $h2t->text();
......
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