BxFilesModule.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 Files Files
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Files module
  13. */
  14. class BxFilesModule extends BxBaseModTextModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. }
  20. public function checkAllowedSetThumb ()
  21. {
  22. return _t('_sys_txt_access_denied');
  23. }
  24. public function actionDownload($iContentId, $sToken = '')
  25. {
  26. $CNF = $this->_oConfig->CNF;
  27. $aData = $this->_oDb->getContentInfoById((int)$iContentId);
  28. if (!$aData) {
  29. $this->_oTemplate->displayPageNotFound();
  30. return;
  31. }
  32. if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedView($aData)) {
  33. $this->_oTemplate->displayAccessDenied();
  34. return;
  35. }
  36. $aFile = $this->getContentFile($aData);
  37. if (!$aFile) {
  38. $this->_oTemplate->displayPageNotFound();
  39. return;
  40. }
  41. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  42. if (!$oStorage) {
  43. $this->_oTemplate->displayErrorOccured();
  44. return;
  45. }
  46. if (!$oStorage->download($aFile['remote_id'], $sToken)) {
  47. $this->_oTemplate->displayErrorOccured();
  48. return;
  49. }
  50. exit;
  51. }
  52. public function getContentFile($aData)
  53. {
  54. $CNF = $this->_oConfig->CNF;
  55. if (!isset($aData[$CNF['FIELD_AUTHOR']]) || !isset($aData[$CNF['FIELD_ID']]))
  56. return false;
  57. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  58. if (!$oStorage)
  59. return false;
  60. $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]);
  61. if (!$aGhostFiles)
  62. return false;
  63. return array_pop($aGhostFiles);
  64. }
  65. public function serviceEntityFilePreview($iContentId = 0)
  66. {
  67. return $this->_serviceTemplateFunc ('entryFilePreview', $iContentId);
  68. }
  69. }
  70. /** @} */