Esempio n. 1
0
 /**
  * Return all available metaData
  * @param MediaInformation $information
  * @return array
  */
 public function getMetaData(MediaInformation $information)
 {
     $subdef = $information->getResource();
     $record = $subdef->get_record();
     $thumbnail = $record->get_thumbnail();
     $request = $information->getResourceRequest();
     $baseUrl = $request->getSchemeAndHttpHost() . $request->getBasePath();
     $ogMetaData = [];
     $embedMedia = [];
     $oembedMetaData = [];
     $substitutionPath = sprintf('/assets/common/images/icons/substitution/%s.png', str_replace('/', '_', $record->getMimeType()));
     $resourceUrl = $information->getUrl();
     $embedMedia['title'] = $record->get_title();
     $embedMedia['url'] = $resourceUrl;
     switch ($record->getType()) {
         case 'video':
             $ogMetaData['og:type'] = 'video.other';
             $ogMetaData['og:image'] = $baseUrl . $thumbnail->get_url();
             $ogMetaData['og:image:width'] = $thumbnail->get_width();
             $ogMetaData['og:image:height'] = $thumbnail->get_height();
             $embedMedia['coverUrl'] = $baseUrl . $thumbnail->get_url();
             $embedMedia['source'] = [];
             $embedMedia['source'][] = ['url' => $resourceUrl, 'type' => $subdef->get_mime()];
             $embedMedia['dimensions'] = $this->getDimensions($subdef);
             $oembedMetaData['type'] = 'video';
             $oembedMetaData['html'] = sprintf('<iframe width="%d" height="%d" src="%s" frameborder="0" allowfullscreen></iframe>', $embedMedia['dimensions']['width'], $embedMedia['dimensions']['height'], $this->getEmbedUrl($resourceUrl));
             break;
         case 'flexpaper':
         case 'document':
             $ogMetaData['og:type'] = 'article';
             $ogMetaData['og:image'] = $baseUrl . $thumbnail->get_url();
             $ogMetaData['og:image:width'] = $thumbnail->get_width();
             $ogMetaData['og:image:height'] = $thumbnail->get_height();
             $oembedMetaData['type'] = 'link';
             $embedMedia['dimensions'] = $this->getDimensions($subdef);
             break;
         case 'audio':
             $ogMetaData['og:type'] = 'music.song';
             $ogMetaData['og:image'] = $baseUrl . $substitutionPath;
             $ogMetaData['og:image:width'] = $thumbnail->get_width();
             $ogMetaData['og:image:height'] = $thumbnail->get_height();
             $oembedMetaData['type'] = 'link';
             $embedMedia['source'] = [];
             $embedMedia['source'][] = ['url' => $resourceUrl, 'type' => $subdef->get_mime()];
             $embedMedia['coverUrl'] = $baseUrl . $substitutionPath;
             // set default dimension for player
             $embedMedia['dimensions'] = ['width' => 320, 'height' => 320, 'top' => 0];
             break;
         default:
             $oembedMetaData['type'] = 'photo';
             $ogMetaData['og:type'] = 'image';
             $ogMetaData['og:image'] = (string) $record->get_preview()->get_permalink()->get_url();
             $ogMetaData['og:image:width'] = $subdef->get_width();
             $ogMetaData['og:image:height'] = $subdef->get_height();
             $embedMedia['dimensions'] = $this->getDimensions($subdef);
             break;
     }
     return ['options' => ['autoplay' => false], 'oembedMetaData' => $oembedMetaData, 'ogMetaData' => $ogMetaData, 'embedMedia' => $embedMedia];
 }
 /**
  * Render Embed Twig view
  * @param MediaInformation $mediaInformation
  * @param array            $metaData
  * @return string
  */
 public function renderEmbed(MediaInformation $mediaInformation, array $metaData)
 {
     $record = $mediaInformation->getResource()->get_record();
     // load predefined opts:
     $config = ['video_autoplay' => false, 'video_options' => [], 'video_available_speeds' => [], 'video_player' => 'videojs', 'audio_player' => 'videojs', 'document_player' => 'flexpaper', 'document' => ['enable_pdfjs' => true]];
     if (isset($this->app['phraseanet.configuration']['embed_bundle'])) {
         // override default option with phraseanet defined:
         $config = array_merge($config, $this->app['phraseanet.configuration']['embed_bundle']);
     }
     switch ($record->getType()) {
         case 'video':
             if ($metaData['options']['autoplay'] === true) {
                 $config['video_autoplay'] = true;
             }
             $template = 'video.html.twig';
             break;
         case 'flexpaper':
         case 'document':
             $template = 'document.html.twig';
             // if document type is pdf and player is active, let's use original documents:
             $ie8OrLess = preg_match('/(?i)msie [6-8]/', $_SERVER['HTTP_USER_AGENT']);
             if ($record->getMimeType() == 'application/pdf' && !$ie8OrLess) {
                 if ($config['document']['enable_pdfjs'] === true) {
                     if ($record->has_subdef('document')) {
                         $subdef = $record->get_subdef('document');
                         $config['document_player'] = 'pdfjs';
                         $metaData['embedMedia']['url'] = (string) $subdef->get_permalink()->get_url();
                     }
                 }
             }
             break;
         case 'audio':
             if ($metaData['options']['autoplay'] === true) {
                 $config['audio_autoplay'] = true;
             }
             $template = 'audio.html.twig';
             break;
         default:
             $template = 'image.html.twig';
             break;
     }
     $twigOptions = array_merge($config, $metaData);
     return $this->app['twig']->render('@alchemy_embed/iframe/' . $template, $twigOptions);
 }
Esempio n. 3
0
 /**
  * Render Embed Twig view
  * @param MediaInformation $mediaInformation
  * @param array            $metaData
  * @return string
  */
 public function renderEmbed(MediaInformation $mediaInformation, array $metaData)
 {
     $record = $mediaInformation->getResource()->get_record();
     $embedConfig = $this->embedService->getConfiguration();
     switch ($record->getType()) {
         case 'video':
             if ($metaData['options']['autoplay'] === true) {
                 $embedConfig['video']['autoplay'] = true;
             }
             $template = 'video.html.twig';
             break;
         case 'flexpaper':
         case 'document':
             $template = 'document.html.twig';
             // if document type is pdf and player is active, let's use original documents:
             $ie8OrLess = preg_match('/(?i)msie [6-8]/', $_SERVER['HTTP_USER_AGENT']);
             if ($record->getMimeType() == 'application/pdf' && !$ie8OrLess) {
                 if ($embedConfig['document']['enable-pdfjs'] === true) {
                     if ($record->has_subdef('document')) {
                         $subdef = $record->get_subdef('document');
                         $embedConfig['document']['player'] = 'pdfjs';
                         $metaData['embedMedia']['url'] = (string) $subdef->get_permalink()->get_url();
                     }
                 }
             }
             break;
         case 'audio':
             if ($metaData['options']['autoplay'] === true) {
                 $embedConfig['audio']['autoplay'] = true;
             }
             $template = 'audio.html.twig';
             break;
         default:
             $template = 'image.html.twig';
             break;
     }
     $twigOptions = array_merge($embedConfig, $metaData);
     return $this->app['twig']->render('@alchemy_embed/iframe/' . $template, $twigOptions);
 }
Esempio n. 4
0
 /**
  * list available video text tracks (only metadatas)
  * @param MediaInformation $media
  * @return array
  */
 public function getAvailableVideoTextTracks(MediaInformation $media)
 {
     $record = $media->getResource()->get_record();
     $videoTextTrack = [];
     if ($record->getType() === 'video') {
         $databox = $record->getDatabox();
         $vttIds = [];
         $vttMetadata = [];
         // extract vtt ids and labels
         foreach ($databox->get_meta_structure() as $meta) {
             $foundParts = [];
             if (preg_match('/^VideoTextTrack(.*)$/iu', $meta->get_name(), $foundParts)) {
                 $vttIds[] = $meta->get_id();
                 /*
                 Available HTML5 track types:
                     - captions
                     - chapters
                     - descriptions
                     - metadata
                     - subtitles
                 */
                 $kind = '';
                 $setAsDefault = false;
                 $vttFoundKind = strtolower($foundParts[1]);
                 switch ($vttFoundKind) {
                     case 'chapters':
                         $setAsDefault = true;
                         $kind = 'chapters';
                         break;
                     default:
                         $kind = 'subtitles';
                 }
                 $vttMetadata[$meta->get_id()] = ['label' => empty($foundParts[1]) ? 'default' : $foundParts[1], 'srclang' => '', 'default' => $setAsDefault, 'kind' => $kind];
             }
         }
         // extract vtt metadatas from ids
         foreach ($record->get_caption()->get_fields(null, true) as $field) {
             $metaStructId = $field->get_meta_struct_id();
             if (!in_array($metaStructId, $vttIds)) {
                 continue;
             }
             foreach ($field->get_values() as $value) {
                 $videoTextTrack[] = array_merge(['src' => $this->getEmbedVttUrl($media->getUrl(), ['choice' => $metaStructId]), 'id' => $metaStructId], $vttMetadata[$metaStructId]);
             }
         }
     }
     return $videoTextTrack;
 }