SMF 2.1: Remove inline tags for deleted attachments from message

Started by GL700Wing, June 16, 2022, 02:57:33 AM

Previous topic - Next topic

GL700Wing

In response to the Deleting attachments from a post topic (and because it was also annoying me) I have come up with the following solution ...


In ./Sources/Post.php

Find:
// An array to hold all the attachments for this topic.
$context['current_attachments'] = array();

Add After:

// Tip/Trick: Remove inline tags for deleted attachments from message ...
$_SESSION['attach_del'] = array();

Find:
// Coming from the quickReply?
Add Before:
// Tip/Trick: Remove inline tags for deleted attachments from message ...
if (!empty($_SESSION['attach_del']))
{
$pattern = '#\[attach (id=\d+)(.+?)\]([^\[]*)(\[/attach])?#i' . ($context['utf8'] ? 'u' : '');
preg_match_all($pattern, $_POST['message'], $inlineTags, PREG_PATTERN_ORDER);
foreach ($_SESSION['attach_del'] as $attachID)
{
$key = array_search('id=' . $attachID, $inlineTags[1]);
if ($key !== false)
$_POST['message'] = str_replace($inlineTags[0][$key], '', $_POST['message']);
}
}



In ./Sources/ManageAttachments.php

Find:
$attach[] = $row['id_attach'];
Add After:

// Tip/Trick: Remove inline tags for deleted attachments from message ...
$_SESSION['attach_del'][] = (int) $row['id_attach'];
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Ripi


Advertisement: