MyBB Community Forums
Replacing Attachment Inside Post - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Support (https://community.mybb.com/forum-72.html)
+---- Thread: Replacing Attachment Inside Post (/thread-113402.html)



Replacing Attachment Inside Post - BleepyEvans - 2012-02-13

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


RE: Replacing Attachment Inside Post - Yaldaram - 2012-02-13

Can you please paste the entire function of your plugin's hook ?


RE: Replacing Attachment Inside Post - BleepyEvans - 2012-02-13

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.


RE: Replacing Attachment Inside Post - Yaldaram - 2012-02-13

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")."\";");
		}
	}
}



RE: Replacing Attachment Inside Post - BleepyEvans - 2012-02-13

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


RE: Replacing Attachment Inside Post - Yaldaram - 2012-02-13

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")."\";");
        }
    }
}
}



RE: Replacing Attachment Inside Post - BleepyEvans - 2012-02-13

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.