Fixed embedded attachments and attachment permissions
authorMarcel Werk <burntime@woltlab.com>
Tue, 8 Jan 2013 23:09:04 +0000 (00:09 +0100)
committerMarcel Werk <burntime@woltlab.com>
Tue, 8 Jan 2013 23:09:04 +0000 (00:09 +0100)
files/lib/data/conversation/message/ConversationMessage.class.php
files/lib/data/conversation/message/ConversationMessageAction.class.php
files/lib/data/conversation/message/ViewableConversationMessageList.class.php
files/lib/page/ConversationPage.class.php
files/lib/system/attachment/ConversationMessageAttachmentObjectType.class.php
userGroupOption.xml

index d561863b7821292ece134462110a7b6ea9faf8ae..fd366b13a532c0c5ed86bed324b0ec79dd0a08bc 100644 (file)
@@ -1,8 +1,10 @@
 <?php
 namespace wcf\data\conversation\message;
+use wcf\data\attachment\GroupedAttachmentList;
 use wcf\data\conversation\Conversation;
 use wcf\data\DatabaseObject;
 use wcf\data\IMessage;
+use wcf\system\bbcode\AttachmentBBCode;
 use wcf\system\bbcode\MessageParser;
 use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
@@ -39,10 +41,38 @@ class ConversationMessage extends DatabaseObject implements IMessage {
         * @see wcf\data\IMessage::getFormattedMessage()
         */
        public function getFormattedMessage() {
+               // assign embedded attachments
+               AttachmentBBCode::setObjectID($this->messageID);
+               
+               // parse and return message
                MessageParser::getInstance()->setOutputType('text/html');
                return MessageParser::getInstance()->parse($this->message, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes);
        }
        
+       /**
+        * Gets and assigns embedded attachments.
+        *
+        * @return      wcf\data\attachment\GroupedAttachmentList
+        */
+       public function getAttachments() {
+               if (MODULE_ATTACHMENT == 1 && $this->attachments) {
+                       $attachmentList = new GroupedAttachmentList('com.woltlab.wcf.conversation.message');
+                       $attachmentList->getConditionBuilder()->add('attachment.objectID IN (?)', array($this->messageID));
+                       $attachmentList->readObjects();
+                       $attachmentList->setPermissions(array(
+                               'canDownload' => WCF::getSession()->getPermission('user.blog.canDownloadAttachment'),
+                               'canViewPreview' => WCF::getSession()->getPermission('user.blog.canViewAttachmentPreview')
+                       ));
+                               
+                       // set embedded attachments
+                       AttachmentBBCode::setAttachmentList($attachmentList);
+                               
+                       return $attachmentList;
+               }
+       
+               return null;
+       }
+       
        /**
         * Returns an excerpt of this message.
         * 
index 578d8ba84bee992248cca609de91f89072d7191e..830ed0653d60cd14a42e50e1fcad16ae84ce2438 100644 (file)
@@ -321,6 +321,7 @@ class ConversationMessageAction extends AbstractDatabaseObjectAction implements
                
                // load new message
                $this->message = new ConversationMessage($this->message->messageID);
+               $this->message->getAttachments();
                
                return array(
                        'actionName' => 'save',
index 1fd752ff73d16e7b88f4c69494160b423a9b7e5f..0f31d32f412b3c33766c45f443bbe65c3cb7847f 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\data\conversation\message;
 use wcf\data\attachment\GroupedAttachmentList;
+use wcf\system\bbcode\AttachmentBBCode;
 
 /**
  * Represents a list of viewable conversation messages.
@@ -87,6 +88,9 @@ class ViewableConversationMessageList extends ConversationMessageList {
                        $this->attachmentList = new GroupedAttachmentList('com.woltlab.wcf.conversation.message');
                        $this->attachmentList->getConditionBuilder()->add('attachment.objectID IN (?)', array($this->attachmentObjectIDs));
                        $this->attachmentList->readObjects();
+                       
+                       // set embedded attachments
+                       AttachmentBBCode::setAttachmentList($this->attachmentList);
                }
        }
        
index 6bb069249f5606a95cf8264b4eed62452ab7e9db..7d2b4983a277020aa3b1963fe50ec145e8b3a93e 100644 (file)
@@ -178,6 +178,14 @@ class ConversationPage extends MultipleLinkPage {
                        $messageIDs[] = $message->messageID;
                }
                MessageQuoteManager::getInstance()->initObjects('com.woltlab.wcf.conversation.message', $messageIDs);
+               
+               // set attachment permissions
+               if ($this->objectList->getAttachmentList() !== null) {
+                       $this->objectList->getAttachmentList()->setPermissions(array(
+                               'canDownload' => true,
+                               'canViewPreview' => true                
+                       ));
+               }
        }
        
        /**
index 2757d3fe49684bf6407ad3a25592458e3783f450..014dacc3a3f106fd47e30caaed6cf4d8f0a8d242 100644 (file)
@@ -3,18 +3,40 @@ namespace wcf\system\attachment;
 use wcf\data\conversation\message\ConversationMessage;
 use wcf\data\conversation\Conversation;
 use wcf\system\WCF;
+use wcf\util\ArrayUtil;
 
 /**
  * Attachment object type implementation for conversations.
  * 
  * @author     Marcel Werk
- * @copyright  2009-2012 WoltLab GmbH
+ * @copyright  2009-2013 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf.conversation
  * @subpackage system.attachment
  * @category   Community Framework
  */
 class ConversationMessageAttachmentObjectType extends AbstractAttachmentObjectType {
+       /**
+        * @see wcf\system\attachment\IAttachmentObjectType::getMaxSize()
+        */
+       public function getMaxSize() {
+               return WCF::getSession()->getPermission('user.conversation.maxAttachmentSize');
+       }
+       
+       /**
+        * @see wcf\system\attachment\IAttachmentObjectType::getAllowedExtensions()
+        */
+       public function getAllowedExtensions() {
+               return ArrayUtil::trim(explode("\n", WCF::getSession()->getPermission('user.conversation.allowedAttachmentExtensions')));
+       }
+       
+       /**
+        * @see wcf\system\attachment\IAttachmentObjectType::getMaxCount()
+        */
+       public function getMaxCount() {
+               return WCF::getSession()->getPermission('user.conversation.maxAttachmentCount');
+       }
+       
        /**
         * @see wcf\system\attachment\IAttachmentObjectType::canDownload()
         */
index 808d9d02c36a720ff7848d1053d78b4c754c9bd7..68b22591f14653882427e92282f33c3e274e1c88 100644 (file)
@@ -61,7 +61,7 @@
                        <option name="user.conversation.maxAttachmentSize">
                                <categoryname>user.conversation</categoryname>
                                <optiontype>integer</optiontype>
-                               <defaultvalue>150000</defaultvalue>
+                               <defaultvalue>1000000</defaultvalue>
                                <options>module_attachment</options>
                        </option>
                        <option name="user.conversation.allowedAttachmentExtensions">