1. 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 ?

Discussion in 'XenForo Development Discussions' started by DroidHost, Jun 7, 2011.

  1. DroidHost

    DroidHost Well-Known Member

    How to Extend a handler ?

    Simple .....!
    outside ... controller , model .....
     
  2. ragtek

    ragtek Guest

    hm?

    what do you mean?
     
  3. DroidHost

    DroidHost Well-Known Member

    I want to deal with this File:

    PHP:
    class XenForo_AttachmentHandler_Post extends XenForo_AttachmentHandler_Abstract
     
  4. DroidHost

    DroidHost Well-Known Member

    Do have something to chat with you ?:cautious: gtalk ... etc
     
  5. ragtek

    ragtek Guest

    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.
     
  6. DroidHost

    DroidHost Well-Known Member

    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 ...
     
  7. DroidHost

    DroidHost Well-Known Member

    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));
            }
        }
     
  8. ragtek

    ragtek Guest

    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 ^^ )
     
  9. DroidHost

    DroidHost Well-Known Member

    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
     
  10. DroidHost

    DroidHost Well-Known Member

    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 :

     
  11. SheepCow

    SheepCow Well-Known Member

    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;
    }
     
    DroidHost likes this.
  12. DroidHost

    DroidHost Well-Known Member

    Ya. I can be that crazy .....
    I see now
     

Share This Page