BxStrmGridRecordings.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 Antispam Antispam
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  12. class BxStrmGridRecordings extends BxTemplGrid
  13. {
  14. protected $_iContentId;
  15. public function __construct ($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct ($aOptions, $oTemplate);
  18. $this->_iContentId = (int)bx_get('id');
  19. $this->_sDefaultSortingOrder = 'DESC';
  20. $this->_aQueryAppend['id'] = $this->_iContentId;
  21. }
  22. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  23. {
  24. if (!$this->_iContentId || !isLogged())
  25. $this->_aOptions['source'] .= " AND 0 ";
  26. elseif (isAdmin())
  27. $this->_aOptions['source'] .= BxDolDb::getInstance()->prepareAsString(" AND `sys_storage_ghosts`.`content_id` = ?", $this->_iContentId);
  28. else
  29. $this->_aOptions['source'] .= BxDolDb::getInstance()->prepareAsString(" AND `sys_storage_ghosts`.`content_id` = (SELECT `bx_stream_streams`.`id` FROM `bx_stream_streams` WHERE `bx_stream_streams`.`id` = ? AND `bx_stream_streams`.`author` = ? LIMIT 1)", $this->_iContentId, bx_get_logged_profile_id());
  30. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  31. }
  32. protected function _getCellSize ($mixedValue, $sKey, $aField, $aRow)
  33. {
  34. return parent::_getCellDefault (_t_format_size($mixedValue), $sKey, $aField, $aRow);
  35. }
  36. protected function _getCellAdded ($mixedValue, $sKey, $aField, $aRow)
  37. {
  38. return parent::_getCellDefault (bx_time_js($mixedValue, BX_FORMAT_DATE), $sKey, $aField, $aRow);
  39. }
  40. protected function _getActionPublish ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  41. {
  42. $aModule = BxDolModuleQuery::getInstance()->getModuleByName('bx_videos');
  43. return $aModule && $aModule['enabled'] ? parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow) : '';
  44. }
  45. public function performActionDelete()
  46. {
  47. $aIds = $this->_prepareAction();
  48. $aIdsAffected = array ();
  49. foreach ($aIds as $mixedId) {
  50. if (!$this->_delete((int)$mixedId))
  51. continue;
  52. $aIdsAffected[] = (int)$mixedId;
  53. }
  54. echoJson([
  55. 'grid' => $this->getCode(false),
  56. 'blink' => $aIdsAffected,
  57. ]);
  58. }
  59. public function performActionDownload()
  60. {
  61. $sUrl = false;
  62. if (!empty($aIds = $this->_prepareAction()))
  63. $sUrl = $this->_download(array_shift($aIds));
  64. echoJson(!$sUrl ? [] : [
  65. 'open_url' => $sUrl,
  66. ]);
  67. }
  68. public function performActionPublish()
  69. {
  70. $sUrl = false;
  71. $sErrorMsg = '';
  72. if (!empty($aIds = $this->_prepareAction()))
  73. $sUrl = $this->_publish(array_shift($aIds), $sErrorMsg);
  74. if ($sUrl) {
  75. $a = ['redirect' => $sUrl];
  76. }
  77. elseif ($sErrorMsg) {
  78. $s = BxTemplFunctions::getInstance()->popupBox(
  79. 'bx_stream_popup',
  80. _t('_Error'),
  81. MsgBox($sErrorMsg)
  82. );
  83. $a = ['popup' => $s];
  84. }
  85. else {
  86. $a = [];
  87. }
  88. echoJson($a);
  89. }
  90. protected function _prepareAction()
  91. {
  92. $iAffected = 0;
  93. $aIds = bx_get('ids');
  94. if (!$aIds || !is_array($aIds)) {
  95. $this->_echoResultJson(array());
  96. exit;
  97. }
  98. return $aIds;
  99. }
  100. protected function _delete($iFileId)
  101. {
  102. if (!($oStorage = $this->_actionWithStorage($iFileId)))
  103. return false;
  104. return $oStorage->deleteFile($iFileId);
  105. }
  106. protected function _download($iFileId)
  107. {
  108. if (!($oStorage = $this->_actionWithStorage($iFileId)))
  109. return false;
  110. return $oStorage->getFileUrlById($iFileId);
  111. }
  112. protected function _publish($iFileId, &$sErrorMsg)
  113. {
  114. $oModule = BxDolModule::getInstance('bx_videos');
  115. if (!$oModule || !$oModule->isEnabled())
  116. return false;
  117. if (!($oStorage = $this->_actionWithStorage($iFileId)))
  118. return false;
  119. if (!($sFileUrl = $oStorage->getFileUrlById($iFileId))) {
  120. $sErrorMsg = $oStorage->getErrorString();
  121. return false;
  122. }
  123. if (empty($oModule->_oConfig->CNF['OBJECT_STORAGE_VIDEOS']) || empty($oModule->_oConfig->CNF['URI_ADD_ENTRY']))
  124. return false;
  125. $oStorageVideos = BxDolStorage::getObjectInstance($oModule->_oConfig->CNF['OBJECT_STORAGE_VIDEOS']);
  126. if (!$oStorageVideos)
  127. return false;
  128. $iFileIdNew = $oStorageVideos->storeFileFromUrl($sFileUrl, false, bx_get_logged_profile_id());
  129. if (!$iFileIdNew) {
  130. $sErrorMsg = $oStorageVideos->getErrorString();
  131. return false;
  132. }
  133. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $oModule->_oConfig->CNF['URI_ADD_ENTRY']));
  134. }
  135. protected function _actionWithStorage($iFileId)
  136. {
  137. $oStorage = BxDolStorage::getObjectInstance('bx_stream_recordings');
  138. $aFile = $oStorage->getGhost($iFileId);
  139. if (!$aFile || empty($aFile['content_id']))
  140. return false;
  141. $oContentInfo = BxDolContentInfo::getObjectInstance('bx_stream');
  142. if (!$oContentInfo)
  143. return false;
  144. $iProfileId = $oContentInfo->getContentAuthor($aFile['content_id']);
  145. if (!$iProfileId || $iProfileId != bx_get_logged_profile_id())
  146. return false;
  147. return $oStorage;
  148. }
  149. }
  150. /** @} */