BxStrmModule.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. * Stream module
  13. */
  14. class BxStrmModule extends BxBaseModTextModule
  15. {
  16. protected $_oEngine;
  17. function __construct(&$aModule)
  18. {
  19. parent::__construct($aModule);
  20. $CNF = &$this->_oConfig->CNF;
  21. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  22. $CNF['FIELD_PUBLISHED'],
  23. $CNF['FIELD_ANONYMOUS'],
  24. $CNF['FIELD_DISABLE_COMMENTS']
  25. ));
  26. }
  27. public function getStreamEngine ()
  28. {
  29. if ($this->_oEngine)
  30. return $this->_oEngine;
  31. $sEngine = getParam('bx_stream_engine');
  32. bx_import('Engine' . $sEngine, $this->_aModule);
  33. $sClass = 'BxStrmEngine' . $sEngine;
  34. $this->_oEngine = new $sClass;
  35. return $this->_oEngine;
  36. }
  37. public function actionStreamViewers ($iContentId = 0)
  38. {
  39. header('Content-Type:text/javascript; charset=utf-8');
  40. $CNF = &$this->_oConfig->CNF;
  41. $mixedContent = $this->_getContent($iContentId, 'getContentInfoById');
  42. if ($mixedContent === false) {
  43. echo json_encode(['viewers' => _t('_sys_txt_error_occured')]);
  44. exit;
  45. }
  46. list($iContentId, $aContentInfo) = $mixedContent;
  47. $iNum = $this->getStreamEngine()->getViewersNum($aContentInfo[$CNF['FIELD_KEY']]);
  48. echo json_encode(['viewers' => $iNum !== false ? _t('_bx_stream_txt_viewers', (int)$iNum) : _t('_bx_stream_txt_wait_for_stream'), 'num' => $iNum]);
  49. }
  50. public function serviceStreamViewers ($iContentId = 0)
  51. {
  52. return $this->_serviceTemplateFunc ('entryStreamViewers', $iContentId);
  53. }
  54. public function serviceStreamPlayer ($iContentId = 0)
  55. {
  56. return $this->_serviceTemplateFunc ('entryStreamPlayer', $iContentId);
  57. }
  58. public function serviceStreamRtmpSettings ($iContentId = 0)
  59. {
  60. $CNF = &$this->_oConfig->CNF;
  61. $mixedContent = $this->_getContent($iContentId, 'getContentInfoById');
  62. if ($mixedContent === false)
  63. return false;
  64. list($iContentId, $aContentInfo) = $mixedContent;
  65. if ($aContentInfo[$CNF['FIELD_AUTHOR']] !== bx_get_logged_profile_id() && !isAdmin())
  66. return false;
  67. $a = $this->getStreamEngine()->getRtmpSettings($aContentInfo[$CNF['FIELD_KEY']]);
  68. if (!$a)
  69. return false;
  70. $aForm = array(
  71. 'form_attrs' => array(
  72. 'name' => 'bx-stream-stmp-settings',
  73. ),
  74. 'inputs' => array(
  75. 'url' => array(
  76. 'type' => 'text',
  77. 'name' => 'url',
  78. 'caption' => _t('_bx_stream_form_entry_input_server'),
  79. 'value' => $a['server'],
  80. ),
  81. 'key' => array(
  82. 'type' => 'password',
  83. 'name' => 'key',
  84. 'caption' => _t('_bx_stream_form_entry_input_stream_key'),
  85. 'value' => $a['key'],
  86. ),
  87. ),
  88. );
  89. $oForm = new BxTemplFormView ($aForm);
  90. return $oForm->getCode();
  91. }
  92. /**
  93. * Entry post for Timeline module
  94. */
  95. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  96. {
  97. $CNF = &$this->_oConfig->CNF;
  98. $aResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  99. if(empty($aResult) || !is_array($aResult) || empty($aResult['date']))
  100. return $aResult;
  101. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  102. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $aResult['date'])
  103. $aResult['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  104. return $aResult;
  105. }
  106. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  107. {
  108. $CNF = &$this->_oConfig->CNF;
  109. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  110. if ($aContentInfo && $aContentInfo[$CNF['FIELD_DISABLE_COMMENTS']] == 1)
  111. return false;
  112. return parent::serviceCheckAllowedCommentsPost($iContentId, $sObjectComments);
  113. }
  114. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  115. {
  116. $CNF = &$this->_oConfig->CNF;
  117. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  118. if ($aContentInfo && $aContentInfo[$CNF['FIELD_DISABLE_COMMENTS']] == 1)
  119. return false;
  120. return parent::serviceCheckAllowedCommentsView($iContentId, $sObjectComments);
  121. }
  122. public function checkAllowedSetThumb ($iContentId = 0)
  123. {
  124. return CHECK_ACTION_RESULT_ALLOWED;
  125. }
  126. }
  127. /** @} */