971a2c5b753ef49a5ec6d0c116d895085e2a22b2
[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\system\html\input\HtmlInputProcessor;
6
7 /**
8 * IMessageEmbeddedObjectHandler implementation for attachments.
9 *
10 * @author Marcel Werk
11 * @copyright 2001-2017 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\System\Message\Embedded\Object
14 */
15 class AttachmentMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandler {
16 /**
17 * @inheritDoc
18 */
19 public function parse(HtmlInputProcessor $htmlInputProcessor, array $embeddedData) {
20 if (empty($embeddedData['attach'])) {
21 return [];
22 }
23
24 $attachmentIDs = [];
25 for ($i = 0, $length = count($embeddedData['attach']); $i < $length; $i++) {
26 $attributes = $embeddedData['attach'][$i];
27 $attachmentID = (!empty($attributes[0])) ? intval($attributes[0]) : 0;
28
29 if ($attachmentID > 0) {
30 $attachmentIDs[] = $attachmentID;
31 }
32 }
33
34 if (!empty($attachmentIDs)) {
35 $attachmentList = new AttachmentList();
36 $attachmentList->getConditionBuilder()->add("attachment.attachmentID IN (?)", [$attachmentIDs]);
37 $attachmentList->readObjectIDs();
38
39 return $attachmentList->getObjectIDs();
40 }
41
42 return [];
43 }
44
45 /**
46 * @inheritDoc
47 */
48 public function loadObjects(array $objectIDs) {
49 $attachmentList = new AttachmentList();
50 $attachmentList->setObjectIDs($objectIDs);
51 $attachmentList->readObjects();
52
53 // group attachments by object type
54 $groupedAttachments = [];
55 foreach ($attachmentList->getObjects() as $attachment) {
56 if (!isset($groupedAttachments[$attachment->objectTypeID])) $groupedAttachments[$attachment->objectTypeID] = [];
57 $groupedAttachments[$attachment->objectTypeID][] = $attachment;
58 }
59
60 // check permissions
61 foreach ($groupedAttachments as $objectTypeID => $attachments) {
62 $processor = ObjectTypeCache::getInstance()->getObjectType($objectTypeID)->getProcessor();
63 if ($processor !== null) {
64 $processor->setPermissions($attachments);
65 }
66 }
67
68 return $attachmentList->getObjects();
69 }
70 }