BxStrmTemplate.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. $CNF = &$this->getModule()->_oConfig->CNF;
  36. return $this->parseHtmlByName('stream_broadcast_ome.html', array(
  37. 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]),
  38. 'broadcast_url' => $oEngine->getWebrtcIngestUrl($aContentInfo[$CNF['FIELD_KEY']]),
  39. 'popup_share' => $this->popupShare($aContentInfo),
  40. 'popup_settings' => $this->popupSettings($aContentInfo),
  41. ));
  42. }
  43. public function popupShare ($aContentInfo)
  44. {
  45. $CNF = &$this->getModule()->_oConfig->CNF;
  46. $sUrlViewStream = 'page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . (int)$aContentInfo['id'];
  47. $sUrlViewStream = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($sUrlViewStream);
  48. $sUrlEmbed = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'embed_stream/' . (int)$aContentInfo['id'];
  49. $aForm = array(
  50. 'form_attrs' => array(
  51. 'name' => 'bx-stream-form-share',
  52. 'class' => 'bx-def-margin',
  53. ),
  54. 'inputs' => array(
  55. 'url' => array(
  56. 'type' => 'text',
  57. 'name' => 'url'.time(),
  58. 'caption' => _t('_bx_stream_field_link'),
  59. 'value' => $sUrlViewStream,
  60. 'attrs' => array('readonly' => 'readonly'),
  61. ),
  62. 'embed' => array(
  63. 'type' => 'text',
  64. 'name' => 'embed'.time(),
  65. 'caption' => _t('_bx_stream_field_embed'),
  66. 'value' => '<iframe width="560" height="315" frameborder="0" allow="autoplay; picture-in-picture" allowfullscreen src="' . $sUrlEmbed . '"></iframe>',
  67. 'attrs' => array('readonly' => 'readonly'),
  68. ),
  69. ),
  70. );
  71. $oForm = new BxTemplFormView ($aForm);
  72. return BxTemplFunctions::getInstance()->popupBox('bx-stream-popup-share', _t('_bx_stream_popup_share'), $oForm->getCode(), true);
  73. }
  74. public function popupSettings ($aContentInfo)
  75. {
  76. $CNF = &$this->getModule()->_oConfig->CNF;
  77. $aForm = array(
  78. 'form_attrs' => array(
  79. 'name' => 'bx-stream-form-settings',
  80. 'onsubmit' => 'return false',
  81. 'onreset' => 'return false',
  82. ),
  83. 'inputs' => array(
  84. 'audio' => array(
  85. 'type' => 'select',
  86. 'name' => 'audio',
  87. 'caption' => _t('_bx_stream_field_audio_source'),
  88. 'value' => '',
  89. ),
  90. 'video' => array(
  91. 'type' => 'select',
  92. 'name' => 'video',
  93. 'caption' => _t('_bx_stream_field_video_source'),
  94. 'value' => '',
  95. ),
  96. ),
  97. );
  98. $oForm = new BxTemplFormView ($aForm);
  99. return BxTemplFunctions::getInstance()->popupBox('bx-stream-popup-settings', _t('_bx_stream_popup_settings'), $oForm->getCode(), true);
  100. }
  101. public function entryStreamViewers ($aContentInfo)
  102. {
  103. $CNF = &$this->getModule()->_oConfig->CNF;
  104. return $this->parseHtmlByName('stream_viewers.html', array(
  105. 'viewers' => _t('_bx_stream_txt_viewers_loading'),
  106. 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]),
  107. 'url' => BX_DOL_URL_MODULES . '?r=' . $this->getModule()->_oConfig->getUri() . '/stream_viewers/' . $aContentInfo[$CNF['FIELD_ID']]
  108. ));
  109. }
  110. public function entryStreamPlayer ($aContentInfo)
  111. {
  112. $CNF = &$this->getModule()->_oConfig->CNF;
  113. $sSources = getParam('bx_stream_sources_pattern');
  114. $sHost = getParam('bx_stream_server_host');
  115. $sApp = getParam('bx_stream_app');
  116. if (!$sSources || !$sHost)
  117. return MsgBox(_t('_bx_stream_txt_no_config'));
  118. $sSources = str_replace(
  119. ['{host}', '{app}', '{key}', '{params}'],
  120. [$sHost, $sApp, $aContentInfo[$CNF['FIELD_KEY']], ''],
  121. $sSources
  122. );
  123. $this->addJs('ovenplayer/ovenplayer.js');
  124. if (getParam('bx_stream_dash_enabled'))
  125. $this->addJs('ovenplayer/dash.all.min.js');
  126. if (getParam('bx_stream_hls_enabled'))
  127. $this->addJs('ovenplayer/hls.min.js');
  128. $this->addJsTranslation('_bx_stream_txt_wait_for_stream');
  129. return $this->parseHtmlByName('stream_player.html', array(
  130. 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]),
  131. 'sources' => $sSources,
  132. ));
  133. }
  134. public function embedStream($aContentInfo)
  135. {
  136. $CNF = &$this->getModule()->_oConfig->CNF;
  137. // TODO: visibility and other checks
  138. $sCode = $this->parseHtmlByName('stream_embed.html', array(
  139. 'player' => $this->entryStreamPlayer ($aContentInfo),
  140. 'viewers' => $this->entryStreamViewers ($aContentInfo),
  141. ));
  142. $this->addCss('main.css');
  143. // display page
  144. $oTemplate = BxDolTemplate::getInstance();
  145. $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
  146. $oTemplate->setPageHeader ($aContentInfo[$CNF['FIELD_TITLE']]);
  147. $oTemplate->setPageContent ('page_main_code', $sCode);
  148. $oTemplate->getPageCode();
  149. exit;
  150. }
  151. /**
  152. * Use Gallery image for both because currently there is no Unit types with small thumbnails.
  153. */
  154. protected function getUnitThumbAndGallery ($aData)
  155. {
  156. list($sPhotoThumb, $sPhotoGallery) = parent::getUnitThumbAndGallery($aData);
  157. return array($sPhotoGallery, $sPhotoGallery);
  158. }
  159. }
  160. /** @} */