MyBB Community Forums

Full Version: Replacing Attachment Inside Post
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ive been working on a plugin that hides attachments to specific users.
( I know there are plugins out there, but non that do what I require specifically )

Basically what I have at the moment is this line of code that replaces the the attachment with a custom template:
eval("\$post['attachments'] = \"".$templates->get("hideattachmentsuntilreply")."\";");

The problem is when the attachment is inserted into the post using the 'Insert into Post' button the plugin no longer works.

What can I do to replace the attachment if its placed into the post?

Thanks
Can you please paste the entire function of your plugin's hook ?
global $gid, $mybb, $db, $templates, $attachcache, $lang;
		
		$lang->load("hideattachmentsuntilreply", false, true);
		
		$haurgroups = explode(",",$mybb->settings['hideattachmentsuntilreply_groups']);
		$haurwhite = explode(",",$mybb->settings['hideattachmentsuntilreply_white']);

		if($mybb->settings['hideattachmentsuntilreply_enable'] == 1)
		{
			if(in_array($mybb->user['usergroup'], $haurgroups))
			{
				if(in_array($mybb->user['uid'], $haurwhite))
				{
				}
				else
				{
					if(is_array($attachcache[$post['pid']]) && $mybb->user['uid'] != $post['uid'] && !is_moderator($post['fid']))
					{
						$query = $db->simple_select("posts", "pid", "tid = '".$post['tid']."' AND uid = '".$mybb->user['uid']."'");
						
						if(!$db->num_rows($query) || $mybb->user['uid'] == 0)
						{
							eval("\$post['attachments'] = \"".$templates->get("hideattachmentsuntilreply")."\";");
						}
					}
				}
			}
			else
			{
			}
					
				
		}
	}

Still needs some tidying up.
What hook you've used ?

Try attachment_end hook with function code something like this;
global $gid, $mybb, $db, $templates, $attachcache, $lang, $post;
        
$lang->load("hideattachmentsuntilreply", false, true);
        
$haurgroups = explode(",",$mybb->settings['hideattachmentsuntilreply_groups']);
$haurwhite = explode(",",$mybb->settings['hideattachmentsuntilreply_white']);

if($mybb->settings['hideattachmentsuntilreply_enable'] == 1 && in_array($mybb->user['usergroup'], $haurgroups) && !in_array($mybb->user['uid'], $haurwhite))
{
	if($mybb->user['uid'] != $post['uid'] && !is_moderator($post['fid']))
	{
		$query = $db->simple_select("posts", "COUNT(pid) AS post_count", "tid = '".$post['tid']."' AND uid = '".$mybb->user['uid']."'");
		$posted = $db->fetch_field($query, "post_count");

		if(!$posted)
		{
			eval("\$post['attachments'] = \"".$templates->get("hideattachmentsuntilreply")."\";");
		}
	}
}
Oh sorry, i used the postbit hook, ill try your code thanks
Also please excuse the inapproriate variable names xD

And unfortunatly that code didnt work :/ inline attachments were still accessible
If you're using postbit hook then use something like this;
function FUNCTION_NAME(&$post)
{
global $gid, $mybb, $db, $templates, $attachcache, $lang;
        
$lang->load("hideattachmentsuntilreply", false, true);
        
$haurgroups = explode(",",$mybb->settings['hideattachmentsuntilreply_groups']);
$haurwhite = explode(",",$mybb->settings['hideattachmentsuntilreply_white']);

if($mybb->settings['hideattachmentsuntilreply_enable'] == 1 && in_array($mybb->user['usergroup'], $haurgroups) && !in_array($mybb->user['uid'], $haurwhite))
{
    if($mybb->user['uid'] != $post['uid'] && !is_moderator($post['fid']))
    {
        $query = $db->simple_select("posts", "COUNT(pid) AS post_count", "tid = '".$post['tid']."' AND uid = '".$mybb->user['uid']."'");
        $posted = $db->fetch_field($query, "post_count");

        if(!$posted)
        {
            eval("\$post['attachments'] = \"".$templates->get("hideattachmentsuntilreply")."\";");
        }
    }
}
}
The code above provides the same outcome as my original code.
I see the hidden attachment message, but the inline attachment is still visible and it is still possible to download.

I can setup a test account on my test forum if you would like?
I asked Pirata for support and he told me I need to remove the inline attachments tags before they're parsed.

I have no idea what that means, so if anyone can shed any light of this I will be greatful.