XF 2.1 Image Attachments always visible to guests

Sysnative

Well-known member
Hey all,

I'm trying to create an addon, to allow Image attachments to always be visible to guests, whilst all other attachments (e.g. .zip .gz etc) follow the normal permissions.

I've managed to get through the permissions with the following code:

PHP:
class Post extends XFCP_Post
{

    public function canView(Attachment $attachment, Entity $container, &$error = null)
    {
        /** @var \XF\Entity\Post $container */
        if (!$container->canView())
        {
            return false;
        }

        $extension_type = $attachment->getExtension();

        if(in_array($extension_type, array("png", "jpg", "jpeg")))
        {
            return true;
        }
        else
        {
            /** @var \XF\Entity\Thread $thread */
            $thread = $container->Thread;

            return $thread->canViewAttachments($error);
        }
    }
}

However I'm having issues making sure that the lightbox / thumbnails for image attachments works the same for usergroups with view attachment permission, vs guests/other usersgroups.

For users with View Attachment permissions, a post with an attached image looks like this:

1569753618807.png


Whereas for guests / usergroups without permissions, the image is displaying as a thumbnail + lightbox:

1569753568717.png

Permissions for non-image attachments seem to be working correctly, so I think the attachment/post class is working correctly.

This seems to be displayed via the bb_code_tag_attach template, but I can't find in the PHP code where the $full variable is set, or whether this comes from a specific option somewhere in the page.

Two questions:

1) Does my overall approach through extending the Attachment/Post class seem sensible?
2) How can I modify the thumbnail/lightbox display, so that the "full" attachment is always displayed if the attachment type is png/jpg/jpeg?

Thanks in advance for any help!
 
Top Bottom