/** * Saves attachments in the Media Library and attaches them to the end of the message. * * @param WiseChatChannel $channel * @param array $attachments Array of attachments * * @return array Array consisting of the two elements: a shortcode representing the attachments and array of IDs of created attachments */ private function saveAttachments($channel, $attachments) { if (!is_array($attachments) || count($attachments) === 0) { return array(null, array()); } WiseChatContainer::load('rendering/filters/WiseChatShortcodeConstructor'); $firstAttachment = $attachments[0]; $data = $firstAttachment['data']; $data = substr($data, strpos($data, ",") + 1); $decodedData = base64_decode($data); $attachmentShortcode = null; $attachmentIds = array(); if ($this->options->isOptionEnabled('enable_images_uploader') && $firstAttachment['type'] === 'image') { $image = $this->imagesService->saveImage($decodedData); if (is_array($image)) { $attachmentShortcode = ' ' . WiseChatShortcodeConstructor::getImageShortcode($image['id'], $image['image'], $image['image-th'], '_'); $attachmentIds = array($image['id']); } } if ($this->options->isOptionEnabled('enable_attachments_uploader') && $firstAttachment['type'] === 'file') { $fileName = $firstAttachment['name']; $file = $this->attachmentsService->saveAttachment($fileName, $decodedData, $channel->getName()); if (is_array($file)) { $attachmentShortcode = ' ' . WiseChatShortcodeConstructor::getAttachmentShortcode($file['id'], $file['file'], $fileName); $attachmentIds = array($file['id']); } } return array($attachmentShortcode, $attachmentIds); }