Esempio n. 1
0
 private function createPostParameters(Profile $profile, Collection $collection, array $json) : CreatePostParameters
 {
     switch ((int) $json['typeId']) {
         default:
             throw new \Exception(sprintf('Unknown type_id `%s`', $json['type_id']));
         case 0:
             // "content", simple post
             return new CreatePostParameters(DefaultPostType::CODE_INT, $profile->getId(), $collection->getId(), $json['description'], []);
         case 2:
             // youtube
             $url = $json['url'];
             $parsedURL = parse_url($url);
             if (!isset($parsedURL['host'])) {
                 $url = 'https://www.youtube.com/watch?v=yKBLCcQObdQ';
                 $v = 'yKBLCcQObdQ';
             } else {
                 if (strtolower($parsedURL['host']) === 'youtu.be' || !isset($parsedURL['query'])) {
                     $v = str_replace('/', '', $parsedURL['path']);
                 } else {
                     $params = [];
                     parse_str(parse_url($url)['query'] ?? '', $params);
                     $v = $params['v'];
                 }
             }
             $linkAttachment = new Attachment();
             $linkAttachment->setMetadata(['url' => $url, 'resource' => 'youtube', 'source' => ['source' => 'external', 'origURL' => $url], 'metadata' => ['og' => ['basic' => ['description' => '', 'title' => '', 'url' => $url], 'og' => ['basic' => ['og:url' => $url, 'og:title' => '', 'og:type' => '', 'og:description' => '', 'og:determiner' => '', 'og:locale' => '', 'og:locale:alternate' => '', 'og:site_name' => ''], 'images' => [['og:image' => '', 'og:image:url' => '', 'og:image:type' => '', 'og:image:width' => '', 'og:image:height' => '']], 'videos' => [['og:video' => '', 'og:video:url' => '', 'og:video:type' => '', 'og:video:width' => '', 'og:video:height' => '']], 'audios' => [['og:video' => '', 'og:video:url' => '', 'og:video:type' => '']]]], 'youtubeId' => $v]]);
             $this->attachmentRepository->createAttachment($linkAttachment);
             return new CreatePostParameters(DefaultPostType::CODE_INT, $profile->getId(), $collection->getId(), $json['description'] ?? '', [$linkAttachment->getId()]);
         case 3:
             // link
             $options = json_decode($json['options'], true);
             $url = $options['url'];
             $params = [];
             parse_str(parse_url($url)['query'] ?? '', $params);
             $title = $options['title'] ?? '';
             $description = $options['description'] ?? '';
             $image = $options['image'] ?? '';
             $linkAttachment = new Attachment();
             $linkAttachment->setMetadata(['url' => $url, 'resource' => 'page', 'source' => ['source' => 'external', 'origURL' => $url], 'metadata' => ['og' => ['basic' => ['description' => $description, 'title' => $title, 'url' => $url], 'og' => ['basic' => ['og:url' => $url, 'og:title' => $title, 'og:type' => '', 'og:description' => $description, 'og:determiner' => '', 'og:locale' => '', 'og:locale:alternate' => '', 'og:site_name' => ''], 'images' => [['og:image' => $image, 'og:image:url' => $image, 'og:image:type' => '', 'og:image:width' => '', 'og:image:height' => '']], 'videos' => [['og:video' => '', 'og:video:url' => '', 'og:video:type' => '', 'og:video:width' => '', 'og:video:height' => '']], 'audios' => [['og:video' => '', 'og:video:url' => '', 'og:video:type' => '']]]]]]);
             $this->attachmentRepository->createAttachment($linkAttachment);
             return new CreatePostParameters(DefaultPostType::CODE_INT, $profile->getId(), $collection->getId(), $json['description'] ?? '', [$linkAttachment->getId()]);
     }
 }
Esempio n. 2
0
 public function getManyByIds(array $attachmentIds) : array
 {
     return $this->attachmentRepository->getManyByIds($attachmentIds);
 }