Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

FileUpload Addon for Private Messages

Hi everybody,

Did anyone managed to integrate FileUpload with private messages.
My users actually asking for this, so this would be a nice features.

Thank you for information.

  • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
  • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla

Comments

  • hi @phreak you could have this sponsored with the author @Tim

  • Anyone willing to integrate it and get paid. Im also looking for a routine that resizes the server-side picture on upload, please send me price and time suggestion via PM. Thanx. :)

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • I was able to insert the code for the uploader and got it to appear on any form on any page. The question I guess would be how to actually insert it , I did it on firebug. Just copied and pasted the html and java like this. Right under the last page form
    div class= Buttons. I added spaces between the < > so they would show. Remove them if you wish to test this or copy a fresh one off the source.

    < div class="AttachFileWrapper AttachmentWindow" spawned="true" >
       < div class="AttachFileLink" >
          < a href="javascript:void(0);" >Attach a file< /a >
          < div class="CurrentUploader" >< form name="frm53247_form" id="frm53247_form" target="frm53247" enctype="multipart/form-data" classname="FileUpload" method="POST" action="/post/upload/UploadAttachment_1" >< input type="file" name="UploadAttachment_1" id="UploadAttachment_1" rel="frm53247_form" style="opacity: 0; ">
       < /div >
       < div class="AttachFileContainer" >
          < div class="PrototypicalAttachment" style="display:none;" >
             < div class="Attachment" >
                < div class="FilePreview" >< /div >
                < div class="FileHover" >
                   <  div class="FileMeta" >
                      < div >
                         < span class="FileName" >Filename< /span >
                         < span class="FileSize" >File Size< /span >
                      < /div >
                      < span class="FileOptions" >
                      < a class="InsertImage Hidden" >Insert Image< /a >
                      < a class="DeleteFile" >Delete< /a >
                   < /div >
                < /div >
             < /div >
             < div class="UploadProgress" >
                < div class="Foreground" >< strong >Uploading...< /strong  >< /div >
                < div class="Background" > < /div >
                < div > < /div >
             < /div >
          < /div >
       < /div >
    < / div >
    
    < script type="text/javascript" >
       if (GdnUploaders)
          GdnUploaders.Prepare();
    < /script >
  • edited February 2013

    Maybe something like this could work by adding the function to the upload plugin?

    The idea here is to add the controller for that form wether it is conversations controller or messages controller not sure...

     /**
        * DrawAttachFile function.
        * 
        * Helper method that allows the plugin to insert the file uploader UI into the 
        * Conversation Forms.
        *
        * @access public
        * @param mixed $Sender
        * @return void
        *//
     
    
      public function DrawAttachFile($Controller) {
          if (!$this->IsEnabled()) return;
          if (!$this->CanUpload) return;
          
          echo $Controller->FetchView($this->GetView('attach_file.php'));
       }
    
    
     /**
        * ConversationsController_BeforeConversationRender_Handler function.
        * 
        * @access public
        * @param mixed $Sender
        * @return void
        *//
      
    
    
     public function ConversationsController_BeforeConversationRender_Handler($Sender) {
          // Cache the list of media. Don't want to do multiple queries!
          $this->CacheAttachedMedia($Sender);
       }
      
      
       /**
        * CacheAttachedMedia function.
        * 
        * @access protected
        * @param mixed $Sender
        * @return void
        */
     
    
      protected function CacheAttachedMedia($Sender) {
          if (!$this->IsEnabled()) return;
          
          $Conversation = $Sender->Data('ConversationData');
          $ConversationIDList = array();
          
          if ($Conversation && $Conversation instanceof Gdn_DataSet) {
             $Conversation->DataSeek(-1);
             while ($Conversation = $Conversation->NextRow())
                $ConversationIDList[] = $Conversation->ConversationID;
          } elseif ($Sender->Conversation) {
             $ConversationIDList[] = $Sender->ConversationID = $Sender->Conversation->ConversationID;
          }
          if (isset($Sender->Conversation) && isset($Sender->Conversation->ConversationID)) {
             $ConversationIDList[] = $Sender->Conversation->ConversationID;
          }
          
          $MediaData = $this->MediaModel()->PreloadConversationMedia($Sender->ConversationID, $ConversationIDList);
    
          $MediaArray = array();
          if ($MediaData !== FALSE) {
             $MediaData->DataSeek(-1);
             while ($Media = $MediaData->NextRow()) {
                $MediaArray[$Media->ForeignTable.'/'.$Media->ForeignID][] = $Media;
             }
          }
                
          $this->MediaCache = $MediaArray;
       }
    
    
     //
        * ConversationsController_AfterConversationBody_Handler function.
        * 
        * @access public
        * @param mixed $Sender
        * @return void
        
      //
    
     public function ConversationsController_AfterConversationBody_Handler($Sender) {
          $this->AttachUploadsToConversation($Sender);
       }
       
       
        * AttachUploadsToConversation function.
        * 
        * @access protected
        * @param mixed $Sender
        * @return void
        
       protected function AttachUploadsToConversations($Controller) {
          if (!$this->IsEnabled()) return;
          
          $Type = strtolower($RawType = $Controller->EventArguments['Type']);
    
          if (StringEndsWith($Controller->RequestMethod, 'Conversation', TRUE) && $Type != 'Conversation') {
             $Type = 'conversation';
             $RawType = 'Conversation';
             if (!isset($Controller->Conversations))
                return;
             $Controller->EventArguments['Conversation'] = $Controller->Conversations;
          }
    
          $MediaList = $this->MediaCache;
          if (!is_array($MediaList)) return;
          
          $Param = (($Type == 'conversation') ? 'ConversationID' : 'ConversationID');
          $MediaKey = $Type.'/'.$Controller->EventArguments[$RawType]->$Param;
          if (array_key_exists($MediaKey, $MediaList)) {
             $Controller->SetData('ConversationMediaList', $MediaList[$MediaKey]);
             $Controller->SetData('GearImage', $this->GetWebResource('images/gear.png'));
             $Controller->SetData('Garbage', $this->GetWebResource('images/trash.png'));
             $Controller->SetData('CanDownload', $this->CanDownload);
             echo $Controller->FetchView($this->GetView('link_files.php'));
          }
       }
     
    
        
        //* ConversationsController_Download_Create function.
        * 
        * @access public
        * @param mixed $Sender
        * @return void
    //
        
       public function ConversationsController_Download_Create($Sender) {
          if (!$this->IsEnabled()) return;
          if (!$this->CanDownload) throw new PermissionException("File could not be streamed: Access is denied");
       
          list($MediaID) = $Sender->RequestArgs;
          $Media = $this->MediaModel()->GetID($MediaID);
          
          if (!$Media) return;
          
          $Filename = Gdn::Request()->Filename();
          if (!$Filename) $Filename = $Media->Name;
          
          $DownloadPath = CombinePaths(array(MediaModel::PathUploads(),GetValue('Path', $Media)));
    
          if (in_array(strtolower(pathinfo($Filename, PATHINFO_EXTENSION)), array('bmp', 'gif', 'jpg', 'jpeg', 'png')))
             $ServeMode = 'inline';
          else
             $ServeMode = 'attachment';
    
          $this->EventArguments['Media'] = $Media;
          $this->FireEvent('BeforeDownload');
          
          return Gdn_FileSystem::ServeFile($DownloadPath, $Filename, '', $ServeMode);
          throw new Exception('File could not be streamed: missing file ('.$DownloadPath.').');
          
          exit();
       }
       
      
    
     //**
        * ConversationsController_AfterConversationSave_Handler function.
        * 
        * @access public
        * @param mixed $Sender
        * @return void
        *//
      
    
     public function ConversationsController_AfterConversationSave_Handler($Sender) {
          if (!$Sender->EventArguments['Conversation']) return;
          
          $ConversationID = $Sender->EventArguments['Conversation']->ConversationID;
          $AttachedFilesData = Gdn::Request()->GetValue('AttachedUploads');
          $AllFilesData = Gdn::Request()->GetValue('AllUploads');
          
          $this->AttachAllFiles($AttachedFilesData, $AllFilesData, $ConversationID, 'conversation');
       }
       
          
  • @vrijvlinder: Uhh, thanx for diving into this. This is a little steep for me, but i'll try to find out what is going on here. :) Thanx

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • sweet, i was here i think i might need this as well. thumbs up @vrijvlinder you nailed it again :0

  • @phreak said:
    Hi everybody,

    Did anyone managed to integrate FileUpload with private messages.
    My users actually asking for this, so this would be a nice features.

    Adding it to the list as well, then.

  • peregrineperegrine MVP
    edited March 2013

    @vrijvlinder said:
    Maybe something like this could work by adding the function to the upload plugin?

    The idea here is to add the controller for that form wether it is conversations controller or messages controller not sure...

    nice start - if you want to proceed since you seem to thrive on this.

    take a look at both the current fileupload plugin (and take what you need), then study

    applications/conversations

    and study the methods and controllers and events that you can use, and create your own new plugin, since what you are doing will be sufficiently different that it seems worthy of a totally new addon (and that way you can isolate any issues you have with plugin, by disabling it).
    Make sure you give all methods, functions, etc totally new names so as not to create conflict with the original fileupload plugin since both will likely be used at the same time).

    test your new plugin first as well as you can and them add it to the repository,

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine

    you mean make a new plugin from this called conversation upload? hmm I am not sure I am good enough to succeed but I will take a stab , why the hell not ? The worst that can happen is it won't work :)

Sign In or Register to comment.