Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: GL700Wing on June 16, 2022, 02:57:33 AM

Title: SMF 2.1: Remove inline tags for deleted attachments from message
Post by: GL700Wing on June 16, 2022, 02:57:33 AM
In response to the Deleting attachments from a post (https://www.simplemachines.org/community/index.php?topic=581724.0) 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'];
Title: Re: SMF 2.1: Remove inline tags for deleted attachments from message
Post by: Ripi on June 20, 2022, 08:36:11 AM
Hello,

Very usefull, thanks for sharing.