• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to Extend a handler ?

R

ragtek

Guest
#5
But why would you want that? What are you trying to achieve?

1. You could create a own handler and change the "content type handler" in the database (table xf_content_type_field).(don't forget to rebuild the cache)
2. If you want to change some values, you could maybe only "overwrite" the Attachment Model

No, nothing to chat.
 

DroidHost

Well-known member
#6
PHP:
protected function _canViewAttachment(array $attachment, array $viewingUser)

    {

        $postModel = $this->_getPostModel();

        $post = $postModel->getPostById($attachment['content_id'], array(

            'join' => XenForo_Model_Post::FETCH_THREAD | XenForo_Model_Post::FETCH_FORUM | XenForo_Model_Post::FETCH_USER,

            'permissionCombinationId' => $viewingUser['permission_combination_id']

        ));

        if (!$post)

        {

            return false;

        }

        $permissions = XenForo_Permission::unserializePermissions($post['node_permission_cache']);

        $canViewPost = $postModel->canViewPostAndContainer(

            $post, $post, $post, $null, $permissions, $viewingUser

        );

        if (!$canViewPost)

        {

            return false;

        }

        return $postModel->canViewAttachmentOnPost(

            $post, $post, $post, $null, $permissions, $viewingUser

        );

    }
I have something in my mind... which ....
I want to add an if to seperate the view to show pic and hide zip files ...
 

DroidHost

Well-known member
#7
the same thing is in the model !

why ?
PHP:
    /**
    * Determines if the specified attachment can be viewed. Unassociated attachments
    * can be viewed if the temp hash is known.
    *
    * @param array $attachment
    * @param string $tempHash
    * @param array|null $viewingUser Viewing user ref; if null, uses visitor
    *
    * @return boolean
    */
    public function canViewAttachment(array $attachment, $tempHash = '', array $viewingUser = null)
    {
        if (!empty($attachment['temp_hash']) && empty($attachment['content_id']))
        {
            // can view temporary attachments as long as the hash is known
            return ($tempHash === $attachment['temp_hash']);
        }
        else
        {
            $attachmentHandler = $this->getAttachmentHandler($attachment['content_type']);
            return ($attachmentHandler && $attachmentHandler->canViewAttachment($attachment, $viewingUser));
        }
    }
 
R

ragtek

Guest
#8
I think
1. You could create a own handler and change the "content type handler" in the database (table xf_content_type_field).(don't forget to rebuild the cache)
is the only way.

But i'm not sure.
That's something i'd also like for my community, but i had no time to check if it's possible (and i hope it's something for 1.1 ^^ )
 

DroidHost

Well-known member
#9
I think is the only way.

But i'm not sure.
That's something i'd also like for my community, but i had no time to check if it's possible (and i hope it's something for 1.1 ^^ )
after making this code
PHP:
public function canViewAttachment(array $attachment, $tempHash = '', array $viewingUser = null)
{
    $params = parent::canViewAttachment();
    die(print_r($params->$attachment));
    return $params ;
}
this msg came up :
Code:
Argument 1 passed to XenForo_Model_Attachment::canViewAttachment() must be an array, none given, called in C:\xampp\htdocs\xen\library\DroidHost\AttachmentPerUsergroup\Model.php on line 26 and defined
 

DroidHost

Well-known member
#10
After modification to :
PHP:
public function canViewAttachment(array $attachment, $tempHash = '', array $viewingUser = null)
{
    $params = parent::canViewAttachment(array( $attachment, $tempHash = '', array ($viewingUser = null)));
    die(print_r($params->$attachment));
    return $params ;
}
it gives me :

Server Error

Undefined index: content_type
 

SheepCow

Well-known member
#11
You've gone a bit crazy with the arguments passed to the function. You only want to pass the arguments, not the signature of the function:

PHP:
public function canViewAttachment(array $attachment, $tempHash = '', array $viewingUser = null)
{
    $canView = parent::canViewAttachment($attachment, $tempHash, $viewingUser);

    if ($canView)
    {
        // parent said they could view this, can they really?
        $canView = false; // no, haha.
    }

    return $canView;
}