BxVideosModule.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. /**
  21. * @page service Service Calls
  22. * @section bx_videos Videos
  23. * @subsection bx_videos-page_blocks Page Blocks
  24. * @subsubsection bx_videos-entity_video_block entity_video_block
  25. *
  26. * @code bx_srv('bx_videos', 'entity_video_block', [...]); @endcode
  27. *
  28. * Get page block with video player.
  29. *
  30. * @param $iContentId (optional) video ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  31. * @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.
  32. *
  33. * @see BxVideosModule::serviceEntityVideoBlock
  34. */
  35. /**
  36. * @ref bx_videos-entity_video_block "entity_video_block"
  37. */
  38. public function serviceEntityVideoBlock ($iContentId = 0)
  39. {
  40. $mixedContent = $this->_getContent($iContentId);
  41. if($mixedContent === false)
  42. return false;
  43. list($iContentId, $aContentInfo) = $mixedContent;
  44. return $this->_oTemplate->entryVideo($aContentInfo);
  45. }
  46. /**
  47. * @page service Service Calls
  48. * @section bx_videos Videos
  49. * @subsection bx_videos-page_blocks Page Blocks
  50. * @subsubsection bx_videos-entity_rating entity_rating
  51. *
  52. * @code bx_srv('bx_videos', 'entity_rating', [...]); @endcode
  53. *
  54. * Get page block with Stars based video's rating.
  55. *
  56. * @param $iContentId (optional) video ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  57. * @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.
  58. *
  59. * @see BxVideosModule::serviceEntityRating
  60. */
  61. /**
  62. * @ref bx_videos-entity_rating "entity_rating"
  63. */
  64. public function serviceEntityRating($iContentId = 0)
  65. {
  66. return $this->_serviceTemplateFunc ('entryRating', $iContentId);
  67. }
  68. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  69. {
  70. $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  71. if(!empty($aResult['videos']) && is_array($aResult['videos']))
  72. $aResult['images'] = array();
  73. return $aResult;
  74. }
  75. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  76. {
  77. list($sImageThumb, $sImageGallery, $sImageCover) = $this->_oTemplate->getUnitImages($aContentInfo);
  78. if(empty($sImageGallery) && !empty($sImageThumb))
  79. $sImageGallery = $sImageThumb;
  80. if(empty($sImageGallery))
  81. return array();
  82. return array(
  83. array('url' => $sUrl, 'src' => $sImageGallery, 'src_orig' => $sImageCover),
  84. );
  85. }
  86. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  87. {
  88. $CNF = &$this->_oConfig->CNF;
  89. if(empty($CNF['OBJECT_STORAGE_VIDEOS']) || empty($CNF['OBJECT_VIDEOS_TRANSCODERS']))
  90. return array();
  91. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_VIDEOS']);
  92. $iFile = (int)$aContentInfo[$CNF['FIELD_VIDEO']];
  93. $aFile = $oStorage->getFile($iFile);
  94. if(empty($aFile) || !is_array($aFile) || strncmp('video/', $aFile['mime_type'], 6) !== 0)
  95. return array();
  96. $oTcvPoster = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']);
  97. $oTciPoster = BxDolTranscoder::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_POSTER']);
  98. $oTcvMp4 = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']);
  99. $oTcvMp4Hd = BxDolTranscoder::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']);
  100. if(!($oTcvPoster || $oTciPoster) || !$oTcvMp4 || !$oTcvMp4Hd)
  101. return array();
  102. $sPosterSrc = !empty($CNF['FIELD_POSTER']) ? $CNF['FIELD_POSTER'] : $CNF['FIELD_THUMB'];
  103. if(!empty($sPosterSrc) && !empty($aContentInfo[$sPosterSrc]) && $oTciPoster)
  104. $sPoster = $oTciPoster->getFileUrl($aContentInfo[$sPosterSrc]);
  105. else
  106. $sPoster = $oTcvPoster->getFileUrl($iFile);
  107. $sVideoUrl = $oStorage->getFileUrlById($iFile);
  108. $aVideoSize = $oTcvMp4Hd->getVideoSize($sVideoUrl);
  109. $sVideoUrlHd = '';
  110. if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] >= 720)
  111. $sVideoUrlHd = $oTcvMp4Hd->getFileUrl($iFile);
  112. return array(
  113. $iFile => array(
  114. 'id' => $iFile,
  115. 'src_poster' => $sPoster,
  116. 'src_mp4' => $oTcvMp4->getFileUrl($iFile),
  117. 'src_mp4_hd' => $sVideoUrlHd
  118. )
  119. );
  120. }
  121. }
  122. /** @} */