BxStrmTemplate.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 Stream Stream
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Module representation.
  13. */
  14. class BxStrmTemplate extends BxBaseModTextTemplate
  15. {
  16. function __construct(&$oConfig, &$oDb)
  17. {
  18. $this->MODULE = 'bx_stream';
  19. parent::__construct($oConfig, $oDb);
  20. }
  21. public function getLiveBadge ($aContentInfo)
  22. {
  23. $CNF = &$this->getModule()->_oConfig->CNF;
  24. if (!$aContentInfo || $aContentInfo[$CNF['FIELD_STATUS']] != 'active')
  25. return '';
  26. return $this->parseHtmlByName('stream_badge.html', array(
  27. 'label' => _t('_bx_stream_txt_live_now'),
  28. ));
  29. }
  30. public function entryStreamBroadcast ($aContentInfo)
  31. {
  32. $oEngine = $this->getModule()->getStreamEngine();
  33. if (!$oEngine->isSreamFromBrowser())
  34. return MsgBox(_t('_bx_stream_from_webcam_not_supported'));
  35. $mixedMsg = $this->getModule()->checkAllowedAdd (false);
  36. if ($mixedMsg !== CHECK_ACTION_RESULT_ALLOWED)
  37. return MsgBox($mixedMsg);
  38. $CNF = &$this->getModule()->_oConfig->CNF;
  39. return $this->parseHtmlByName('stream_broadcast_ome.html', array(
  40. 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]),
  41. 'broadcast_url' => $oEngine->getWebrtcIngestUrl($aContentInfo[$CNF['FIELD_KEY']]),
  42. 'popup_share' => $this->popupShare($aContentInfo),
  43. 'popup_settings' => $this->popupSettings($aContentInfo),
  44. ));
  45. }
  46. public function popupShare ($aContentInfo)
  47. {
  48. $CNF = &$this->getModule()->_oConfig->CNF;
  49. $sUrlViewStream = 'page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . (int)$aContentInfo['id'];
  50. $sUrlViewStream = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($sUrlViewStream));
  51. $sUrlEmbed = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'embed/' . (int)$aContentInfo['id'];
  52. $aForm = array(
  53. 'form_attrs' => array(
  54. 'name' => 'bx-stream-form-share',
  55. 'class' => 'bx-def-margin',
  56. ),
  57. 'inputs' => array(
  58. 'url' => array(
  59. 'type' => 'text',
  60. 'name' => 'url'.time(),
  61. 'caption' => _t('_bx_stream_field_link'),
  62. 'value' => $sUrlViewStream,
  63. 'attrs' => array('readonly' => 'readonly'),
  64. ),
  65. 'embed' => array(
  66. 'type' => 'text',
  67. 'name' => 'embed'.time(),
  68. 'caption' => _t('_bx_stream_field_embed'),
  69. 'value' => '<iframe width="560" height="315" frameborder="0" allow="autoplay; picture-in-picture" allowfullscreen src="' . $sUrlEmbed . '"></iframe>',
  70. 'attrs' => array('readonly' => 'readonly'),
  71. ),
  72. ),
  73. );
  74. $oForm = new BxTemplFormView ($aForm);
  75. return BxTemplFunctions::getInstance()->popupBox('bx-stream-popup-share', _t('_bx_stream_popup_share'), $oForm->getCode(), true);
  76. }
  77. public function popupSettings ($aContentInfo)
  78. {
  79. $CNF = &$this->getModule()->_oConfig->CNF;
  80. $aForm = array(
  81. 'form_attrs' => array(
  82. 'name' => 'bx-stream-form-settings',
  83. 'onsubmit' => 'return false',
  84. 'onreset' => 'return false',
  85. ),
  86. 'inputs' => array(
  87. 'audio' => array(
  88. 'type' => 'select',
  89. 'name' => 'audio',
  90. 'caption' => _t('_bx_stream_field_audio_source'),
  91. 'value' => '',
  92. ),
  93. 'video' => array(
  94. 'type' => 'select',
  95. 'name' => 'video',
  96. 'caption' => _t('_bx_stream_field_video_source'),
  97. 'value' => '',
  98. ),
  99. ),
  100. );
  101. $oForm = new BxTemplFormView ($aForm);
  102. return BxTemplFunctions::getInstance()->popupBox('bx-stream-popup-settings', _t('_bx_stream_popup_settings'), $oForm->getCode(), true);
  103. }
  104. public function entryStreamViewers ($aContentInfo)
  105. {
  106. $CNF = &$this->getModule()->_oConfig->CNF;
  107. return $this->parseHtmlByName('stream_viewers.html', array(
  108. 'viewers' => _t('_bx_stream_txt_viewers_loading'),
  109. 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]),
  110. 'url' => BX_DOL_URL_MODULES . '?r=' . $this->getModule()->_oConfig->getUri() . '/stream_viewers/' . $aContentInfo[$CNF['FIELD_ID']]
  111. ));
  112. }
  113. public function entryStreamPlayer ($aContentInfo, $aOptions = [])
  114. {
  115. $CNF = &$this->getModule()->_oConfig->CNF;
  116. $sSources = getParam('bx_stream_sources_pattern');
  117. $sHost = getParam('bx_stream_server_host');
  118. $sApp = getParam('bx_stream_app');
  119. if (!$sSources || !$sHost)
  120. return MsgBox(_t('_bx_stream_txt_no_config'));
  121. $sSources = str_replace(
  122. ['{host}', '{app}', '{key}', '{params}'],
  123. [$sHost, $sApp, $aContentInfo[$CNF['FIELD_KEY']], ''],
  124. $sSources
  125. );
  126. $this->addJs('ovenplayer/ovenplayer.js');
  127. if (getParam('bx_stream_dash_enabled'))
  128. $this->addJs('ovenplayer/dash.all.min.js');
  129. if (getParam('bx_stream_hls_enabled'))
  130. $this->addJs('ovenplayer/hls.min.js');
  131. $this->addJsTranslation('_bx_stream_txt_wait_for_stream');
  132. $sImage = '';
  133. $mixedImage = $this->_getHeaderImage($aContentInfo);
  134. if($mixedImage !== false) {
  135. if($o = BxDolTranscoder::getObjectInstance($mixedImage['transcoder']))
  136. $sImage = $o->getFileUrlById($mixedImage['id']);
  137. }
  138. if (!isset($aOptions['mute']))
  139. $aOptions['mute'] = getParam('bx_stream_mute') ? 1 : 0;
  140. return $this->parseHtmlByName('stream_player.html', array(
  141. 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]),
  142. 'sources' => $sSources,
  143. 'mute' => $aOptions['mute'],
  144. 'image' => $sImage,
  145. ));
  146. }
  147. public function embedStream($aContentInfo)
  148. {
  149. $CNF = &$this->getModule()->_oConfig->CNF;
  150. // TODO: visibility and other checks
  151. $sCode = $this->parseHtmlByName('stream_embed.html', array(
  152. 'player' => $this->entryStreamPlayer ($aContentInfo, ['mute' => (getParam('bx_stream_mute_embed') ? 1 : 0)]),
  153. 'viewers' => $this->entryStreamViewers ($aContentInfo),
  154. ));
  155. $this->addCss('main.css');
  156. // display page
  157. $oTemplate = BxDolTemplate::getInstance();
  158. $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
  159. $oTemplate->setPageHeader ($aContentInfo[$CNF['FIELD_TITLE']]);
  160. $oTemplate->setPageContent ('page_main_code', $sCode);
  161. $oTemplate->getPageCode();
  162. exit;
  163. }
  164. /**
  165. * Use Gallery image for both because currently there is no Unit types with small thumbnails.
  166. */
  167. protected function getUnitThumbAndGallery ($aData)
  168. {
  169. list($sPhotoThumb, $sPhotoGallery) = parent::getUnitThumbAndGallery($aData);
  170. return array($sPhotoGallery, $sPhotoGallery);
  171. }
  172. public function getTmplVarsText($aData)
  173. {
  174. $a = parent::getTmplVarsText($aData);
  175. $a['bx_if:show_image']['condition'] = false;
  176. return $a;
  177. }
  178. }
  179. /** @} */