storage.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. //ob_start();
  10. require_once('./inc/header.inc.php');
  11. $sStorageObject = bx_process_input(bx_get('o'));
  12. $sFile = bx_process_input(bx_get('f'));
  13. $sToken = bx_process_input(bx_get('t'));
  14. $oStorage = BxDolStorage::getObjectInstance($sStorageObject);
  15. if (!$oStorage || !method_exists($oStorage, 'download')) {
  16. ob_end_clean();
  17. bx_storage_download_error_occured();
  18. exit;
  19. }
  20. $i = strrpos($sFile, '.');
  21. $sRemoteId = ($i !== false) ? substr($sFile, 0, $i) : $sFile;
  22. if (!$sRemoteId) {
  23. ob_end_clean();
  24. bx_storage_download_error_occured();
  25. exit;
  26. }
  27. // redirect for remote storage in case if some references still pointing to local storage
  28. $aObject = $oStorage->getObjectData();
  29. if ('Local' != $aObject['engine']) {
  30. $sUrl = $oStorage->getFileUrlByRemoteId($sFile);
  31. if (!$sUrl) {
  32. $sFile = preg_replace("/\.[A-Za-z0-9]+$/", '', $sFile);
  33. $sUrl = $oStorage->getFileUrlByRemoteId($sFile);
  34. }
  35. // Tmp fix for storages renaming in the past
  36. if (!$sUrl && 'bx_posts_files' == $sStorageObject && ($oStorage = BxDolStorage::getObjectInstance('bx_posts_covers')))
  37. $sUrl = $oStorage->getFileUrlByRemoteId($sFile);
  38. if (!$sUrl)
  39. bx_storage_download_error_occured();
  40. else
  41. header("Location: " . $sUrl);
  42. exit;
  43. }
  44. if (!$oStorage->download($sRemoteId, $sToken)) {
  45. $iError = $oStorage->getErrorCode();
  46. switch ($iError) {
  47. case BX_DOL_STORAGE_ERR_FILE_NOT_FOUND:
  48. bx_storage_download_error_occured();
  49. exit;
  50. case BX_DOL_STORAGE_ERR_PERMISSION_DENIED:
  51. bx_storage_download_error_occured('displayAccessDenied');
  52. exit;
  53. default:
  54. bx_storage_download_error_occured('displayErrorOccured');
  55. exit;
  56. }
  57. }
  58. function bx_storage_download_error_occured($sMethod = 'displayPageNotFound')
  59. {
  60. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  61. $oTemplate = BxDolTemplate::getInstance();
  62. $oTemplate->$sMethod ();
  63. }
  64. /** @} */