-
Notifications
You must be signed in to change notification settings - Fork 158
/
storage.php
101 lines (83 loc) · 2.86 KB
/
storage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Copyright (c) UNA, Inc - https://una.io
* MIT License - https://opensource.org/licenses/MIT
*
* @defgroup UnaCore UNA Core
* @{
*/
require_once('./inc/header.inc.php');
$sStorageObject = bx_process_input(bx_get('o'));
$sFile = bx_process_input(bx_get('f'));
$sToken = bx_process_input(bx_get('t'));
$oStorage = BxDolStorage::getObjectInstance($sStorageObject);
// upload action implementation
if ($oStorage && bx_get('a') == 'upload' && bx_get('t')) {
header('Content-Type: application/json; charset=utf-8');
$iProfileId = bx_get_logged_profile_id();
if (!($iId = $oStorage->storeFileFromForm($_FILES['file'], false, $iProfileId))) {
echo json_encode(array('error' => '1'));
exit;
}
$oStorage->afterUploadCleanup($iId, $iProfileId);
$aFileInfo = $oStorage->getFile($iId);
if ($aFileInfo && in_array($aFileInfo['ext'], array('jpg', 'jpeg', 'jpe', 'png'))) {
$oTranscoder = BxDolTranscoderImage::getObjectInstance(bx_get('t'));
$sUrl = $oTranscoder->getFileUrl($iId);
}
else {
$sUrl = $oStorage->getFileUrlById($iId);
}
echo json_encode(array('link' => $sUrl));
exit;
}
if (!$oStorage || !method_exists($oStorage, 'download')) {
ob_end_clean();
bx_storage_download_error_occured();
exit;
}
$i = strrpos($sFile, '.');
$sRemoteId = ($i !== false) ? substr($sFile, 0, $i) : $sFile;
if (!$sRemoteId) {
ob_end_clean();
bx_storage_download_error_occured();
exit;
}
// redirect for remote storage in case if some references still pointing to local storage
$aObject = $oStorage->getObjectData();
if ('Local' != $aObject['engine']) {
$sUrl = $oStorage->getFileUrlByRemoteId($sFile);
if (!$sUrl) {
$sFile = preg_replace("/\.[A-Za-z0-9]+$/", '', $sFile);
$sUrl = $oStorage->getFileUrlByRemoteId($sFile);
}
// Tmp fix for storages renaming in the past
if (!$sUrl && 'bx_posts_files' == $sStorageObject && ($oStorage = BxDolStorage::getObjectInstance('bx_posts_covers')))
$sUrl = $oStorage->getFileUrlByRemoteId($sFile);
if (!$sUrl)
bx_storage_download_error_occured();
else
header("Location: " . $sUrl);
exit;
}
if (!$oStorage->download($sRemoteId, $sToken)) {
$iError = $oStorage->getErrorCode();
switch ($iError) {
case BX_DOL_STORAGE_ERR_FILE_NOT_FOUND:
bx_storage_download_error_occured();
exit;
case BX_DOL_STORAGE_ERR_PERMISSION_DENIED:
bx_storage_download_error_occured('displayAccessDenied');
exit;
default:
bx_storage_download_error_occured('displayErrorOccured');
exit;
}
}
function bx_storage_download_error_occured($sMethod = 'displayPageNotFound')
{
require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
$oTemplate = BxDolTemplate::getInstance();
$oTemplate->$sMethod ();
}
/** @} */