BxVideosModule.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Videos Videos
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Videos module
  13. */
  14. class BxVideosModule extends BxBaseModTextModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. }
  20. public function actionParseEmbedLink() {
  21. $sCode = bx_get('code');
  22. $aRes = $this->parseEmbedLink($sCode);
  23. if ($aRes) echo $aRes['embed'];
  24. }
  25. public function actionEmbed($iContentId, $sUnitTemplate = '', $sAddCode = '')
  26. {
  27. return parent::actionEmbed($iContentId, 'unit_gallery_embed.html');
  28. }
  29. public function parseEmbedLink($sLink) {
  30. $aEmbedProviders = $this->_oDb->getEmbedProviders();
  31. if ($aEmbedProviders) foreach ($aEmbedProviders as $aEmbedProvider) {
  32. if (!$aEmbedProvider['class_name']) continue;
  33. if ($aEmbedProvider['class_file'])
  34. require_once(BX_DIRECTORY_PATH_ROOT . $aEmbedProvider['class_file']);
  35. $oLinkParser = new $aEmbedProvider['class_name']($this);
  36. if ($mResult = $oLinkParser->parseLink($sLink))
  37. return $mResult;
  38. }
  39. return false;
  40. }
  41. /**
  42. * @page service Service Calls
  43. * @section bx_videos Videos
  44. * @subsection bx_videos-page_blocks Page Blocks
  45. * @subsubsection bx_videos-entity_video_block entity_video_block
  46. *
  47. * @code bx_srv('bx_videos', 'entity_video_block', [...]); @endcode
  48. *
  49. * Get page block with video player.
  50. *
  51. * @param $iContentId (optional) video ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  52. * @return HTML string with block content to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  53. *
  54. * @see BxVideosModule::serviceEntityVideoBlock
  55. */
  56. /**
  57. * @ref bx_videos-entity_video_block "entity_video_block"
  58. */
  59. public function serviceEntityVideoBlock ($iContentId = 0)
  60. {
  61. $mixedContent = $this->_getContent($iContentId);
  62. if($mixedContent === false)
  63. return false;
  64. list($iContentId, $aContentInfo) = $mixedContent;
  65. return $this->_oTemplate->entryVideo($aContentInfo);
  66. }
  67. /**
  68. * @page service Service Calls
  69. * @section bx_videos Videos
  70. * @subsection bx_videos-page_blocks Page Blocks
  71. * @subsubsection bx_videos-entity_rating entity_rating
  72. *
  73. * @code bx_srv('bx_videos', 'entity_rating', [...]); @endcode
  74. *
  75. * Get page block with Stars based video's rating.
  76. *
  77. * @param $iContentId (optional) video ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  78. * @return HTML string with block content to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  79. *
  80. * @see BxVideosModule::serviceEntityRating
  81. */
  82. /**
  83. * @ref bx_videos-entity_rating "entity_rating"
  84. */
  85. public function serviceEntityRating($iContentId = 0)
  86. {
  87. return $this->_serviceTemplateFunc ('entryRating', $iContentId);
  88. }
  89. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  90. {
  91. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  92. if ($aContentInfo['video_source'] == 'embed' && !empty($aContentInfo['video_embed_data'])) {
  93. if (!is_array($aContentInfo['video_embed_data'])) $aContentInfo['video_embed_data'] = unserialize($aContentInfo['video_embed_data']);
  94. if (isset($aContentInfo['video_embed_data']['embed']) && !empty($aContentInfo['video_embed_data']['embed'])) {
  95. $aResult['images'] = array();
  96. $aResult['top_raw'] = $this->_oTemplate->getResponsiveEmbed($aContentInfo['video_embed_data']['embed'], isset($aBrowseParams['dynamic_mode']) ? $aBrowseParams['dynamic_mode'] : false);
  97. return $aResult;
  98. }
  99. }
  100. if(!empty($aResult['videos']) && is_array($aResult['videos']))
  101. $aResult['images'] = array();
  102. return $aResult;
  103. }
  104. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  105. {
  106. list($iImageId, $sImageThumb, $sImageGallery, $sImageCover) = $this->_oTemplate->getUnitImages($aContentInfo);
  107. if(empty($sImageGallery) && !empty($sImageThumb))
  108. $sImageGallery = $sImageThumb;
  109. if(empty($sImageGallery))
  110. return array();
  111. return array(
  112. array('id' => $iImageId, 'url' => $sUrl, 'src' => $sImageGallery, 'src_orig' => $sImageCover),
  113. );
  114. }
  115. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  116. {
  117. $CNF = &$this->_oConfig->CNF;
  118. if(empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  119. return array();
  120. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  121. $iFile = (int)$aContentInfo[$CNF['FIELD_VIDEO']];
  122. $aFile = $oStorage->getFile($iFile);
  123. if(empty($aFile) || !is_array($aFile) || strncmp('video/', $aFile['mime_type'], 6) !== 0)
  124. return array();
  125. $oTcvPoster = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  126. $oTciPoster = BxDolTranscoder::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_POSTER']);
  127. $oTcvMp4 = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  128. $oTcvMp4Hd = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  129. if(!($oTcvPoster || $oTciPoster) || !$oTcvMp4 || !$oTcvMp4Hd)
  130. return array();
  131. $sPosterSrc = !empty($CNF['FIELD_POSTER']) ? $CNF['FIELD_POSTER'] : $CNF['FIELD_THUMB'];
  132. if(!empty($sPosterSrc) && !empty($aContentInfo[$sPosterSrc]) && $oTciPoster)
  133. $sPoster = $oTciPoster->getFileUrl($aContentInfo[$sPosterSrc]);
  134. else
  135. $sPoster = $oTcvPoster->getFileUrl($iFile);
  136. $sVideoUrl = $oStorage->getFileUrlById($iFile);
  137. $aVideoFile = $oStorage->getFile($iFile);
  138. $sVideoUrlHd = '';
  139. if (!empty($aVideoFile['dimensions']) && $oTcvMp4Hd->isProcessHD($aVideoFile['dimensions']))
  140. $sVideoUrlHd = $oTcvMp4Hd->getFileUrl($iFile);
  141. return array(
  142. $iFile => array(
  143. 'id' => $iFile,
  144. 'src_poster' => $sPoster,
  145. 'src_mp4' => $oTcvMp4->getFileUrl($iFile),
  146. 'src_mp4_hd' => $sVideoUrlHd
  147. )
  148. );
  149. }
  150. }
  151. /** @} */