BxStrmTemplate.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. $aForm = array(
  49. 'form_attrs' => array(
  50. 'name' => 'bx-stream-form-share',
  51. 'class' => 'bx-def-margin',
  52. ),
  53. 'inputs' => array(
  54. 'url' => array(
  55. 'type' => 'text',
  56. 'name' => 'url'.time(),
  57. 'caption' => '',
  58. 'value' => $sUrlViewStream,
  59. 'attrs' => array('readonly' => 'readonly'),
  60. ),
  61. ),
  62. );
  63. $oForm = new BxTemplFormView ($aForm);
  64. return BxTemplFunctions::getInstance()->popupBox('bx-stream-popup-share', _t('_bx_stream_popup_share'), $oForm->getCode(), true);
  65. }
  66. public function popupSettings ($aContentInfo)
  67. {
  68. $CNF = &$this->getModule()->_oConfig->CNF;
  69. $aForm = array(
  70. 'form_attrs' => array(
  71. 'name' => 'bx-stream-form-settings',
  72. 'onsubmit' => 'return false',
  73. 'onreset' => 'return false',
  74. ),
  75. 'inputs' => array(
  76. 'audio' => array(
  77. 'type' => 'select',
  78. 'name' => 'audio',
  79. 'caption' => _t('_bx_stream_field_audio_source'),
  80. 'value' => '',
  81. ),
  82. 'video' => array(
  83. 'type' => 'select',
  84. 'name' => 'video',
  85. 'caption' => _t('_bx_stream_field_video_source'),
  86. 'value' => '',
  87. ),
  88. ),
  89. );
  90. $oForm = new BxTemplFormView ($aForm);
  91. return BxTemplFunctions::getInstance()->popupBox('bx-stream-popup-settings', _t('_bx_stream_popup_settings'), $oForm->getCode(), true);
  92. }
  93. public function entryStreamViewers ($aContentInfo)
  94. {
  95. $CNF = &$this->getModule()->_oConfig->CNF;
  96. return $this->parseHtmlByName('stream_viewers.html', array(
  97. 'viewers' => _t('_bx_stream_txt_viewers_loading'),
  98. 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]),
  99. 'url' => BX_DOL_URL_MODULES . '?r=' . $this->getModule()->_oConfig->getUri() . '/stream_viewers/' . $aContentInfo[$CNF['FIELD_ID']]
  100. ));
  101. }
  102. public function entryStreamPlayer ($aContentInfo)
  103. {
  104. $CNF = &$this->getModule()->_oConfig->CNF;
  105. $sSources = getParam('bx_stream_sources_pattern');
  106. $sHost = getParam('bx_stream_server_host');
  107. $sApp = getParam('bx_stream_app');
  108. if (!$sSources || !$sHost)
  109. return MsgBox(_t('_bx_stream_txt_no_config'));
  110. $sSources = str_replace(
  111. ['{host}', '{app}', '{key}', '{params}'],
  112. [$sHost, $sApp, $aContentInfo[$CNF['FIELD_KEY']], ''],
  113. $sSources
  114. );
  115. $this->addJs('ovenplayer/ovenplayer.js');
  116. if (getParam('bx_stream_dash_enabled'))
  117. $this->addJs('ovenplayer/dash.all.min.js');
  118. if (getParam('bx_stream_hls_enabled'))
  119. $this->addJs('ovenplayer/hls.min.js');
  120. $this->addJsTranslation('_bx_stream_txt_wait_for_stream');
  121. return $this->parseHtmlByName('stream_player.html', array(
  122. 'suffix' => md5($aContentInfo[$CNF['FIELD_KEY']]),
  123. 'sources' => $sSources,
  124. ));
  125. }
  126. /**
  127. * Use Gallery image for both because currently there is no Unit types with small thumbnails.
  128. */
  129. protected function getUnitThumbAndGallery ($aData)
  130. {
  131. list($sPhotoThumb, $sPhotoGallery) = parent::getUnitThumbAndGallery($aData);
  132. return array($sPhotoGallery, $sPhotoGallery);
  133. }
  134. }
  135. /** @} */