75f4e1e29d860624516162aa6ba96e09791a594e
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\message\embedded\object;
3 use wcf\data\attachment\AttachmentList;
4 use wcf\data\object\type\ObjectTypeCache;
5 use wcf\util\ArrayUtil;
6
7 /**
8 * IMessageEmbeddedObjectHandler implementation for attachments.
9 *
10 * @author Marcel Werk
11 * @copyright 2001-2016 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package com.woltlab.wcf
14 * @subpackage system.message.embedded.object
15 * @category Community Framework
16 */
17 class AttachmentMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandler {
18 /**
19 * @inheritDoc
20 */
21 public function parseMessage($message) {
22 $parsedAttachmentIDs = array_unique(ArrayUtil::toIntegerArray(array_merge(self::getFirstParameters($message, 'attach'), self::getTextParameters($message, 'attach'))));
23 if (!empty($parsedAttachmentIDs)) {
24 $attachmentIDs = [];
25 foreach ($parsedAttachmentIDs as $parsedAttachmentID) {
26 if ($parsedAttachmentID) $attachmentIDs[] = $parsedAttachmentID;
27 }
28
29 if (!empty($attachmentIDs)) {
30 $attachmentList = new AttachmentList();
31 $attachmentList->getConditionBuilder()->add("attachment.attachmentID IN (?)", [$attachmentIDs]);
32 $attachmentList->readObjectIDs();
33
34 return $attachmentList->getObjectIDs();
35 }
36 }
37
38 return false;
39 }
40
41 /**
42 * @inheritDoc
43 */
44 public function loadObjects(array $objectIDs) {
45 $attachmentList = new AttachmentList();
46 $attachmentList->setObjectIDs($objectIDs);
47 $attachmentList->readObjects();
48
49 // group attachments by object type
50 $groupedAttachments = [];
51 foreach ($attachmentList->getObjects() as $attachment) {
52 if (!isset($groupedAttachments[$attachment->objectTypeID])) $groupedAttachments[$attachment->objectTypeID] = [];
53 $groupedAttachments[$attachment->objectTypeID][] = $attachment;
54 }
55
56 // check permissions
57 foreach ($groupedAttachments as $objectTypeID => $attachments) {
58 $processor = ObjectTypeCache::getInstance()->getObjectType($objectTypeID)->getProcessor();
59 if ($processor !== null) {
60 $processor->setPermissions($attachments);
61 }
62 }
63
64 return $attachmentList->getObjects();
65 }
66 }