Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
archiveentry.php
1
<?php
2
namespace
Bitrix\Main\Engine\Response\Zip
;
3
4
use
Bitrix\Main\Application
;
5
use
Bitrix\Main\Text\Encoding
;
6
use
Bitrix\Main\Config\Option
;
7
use
Bitrix\Main\Web\Uri
;
8
use CFile;
9
14
class
ArchiveEntry
15
{
20
protected
$name
;
21
26
protected
$path
;
27
32
protected
$size
;
33
38
protected
$crc32
;
39
43
protected
function
__construct
()
44
{}
45
50
public
function
getName
()
51
{
52
return
$this->name
;
53
}
54
60
public
function
setName
(
$name
)
61
{
62
$this->name =
$name
;
63
64
return
$this;
65
}
66
71
public
function
getPath
()
72
{
73
return
$this->path
;
74
}
75
80
public
function
getSize
()
81
{
82
return
$this->size
;
83
}
84
88
public
function
getCrc32
()
89
{
90
return
$this->crc32
;
91
}
92
99
public
static
function
createFromFilePath
($filePath,
$name
=
null
)
100
{
101
$fileArray = CFile::MakeFileArray($filePath);
102
103
if
(\is_array($fileArray))
104
{
105
return
self::createFromFile
([
106
'ID'
=> 0,
107
'ORIGINAL_NAME'
=> $fileArray[
'name'
],
108
'FILE_SIZE'
=> $fileArray[
'size'
],
109
'SRC'
=> mb_substr($fileArray[
'tmp_name'
], mb_strlen(self::getDocRoot())),
110
],
$name
);
111
}
112
113
return
null
;
114
}
115
122
public
static
function
createFromFileId
($fileId, $moduleId =
null
)
123
{
124
$fileArray = CFile::getFileArray($fileId);
125
126
// check file exists
127
if
(!\is_array($fileArray) || empty($fileArray[
'SRC'
]))
128
{
129
return
null
;
130
}
131
132
// check module restriction
133
if
(
134
$moduleId !==
null
&&
135
(
136
!isset($fileArray[
'MODULE_ID'
]) ||
137
$fileArray[
'MODULE_ID'
] !== $moduleId
138
)
139
)
140
{
141
return
null
;
142
}
143
144
return
self::createFromFile
($fileArray);
145
}
146
153
protected
static
function
createFromFile
(array $fileArray,
$name
=
null
)
154
{
155
$zipEntry =
new
static
();
156
$zipEntry->setName(
$name
?: $fileArray[
'ORIGINAL_NAME'
]);
157
$zipEntry->size = (int)$fileArray[
'FILE_SIZE'
];
158
159
if
(empty($fileArray[
'SRC'
]))
160
{
161
$fileArray[
'SRC'
] = CFile::getFileSrc($fileArray);
162
}
163
164
$fromClouds =
false
;
165
$filename = $fileArray[
'SRC'
];
166
if
(isset($fileArray[
'HANDLER_ID'
]) && !empty($fileArray[
'HANDLER_ID'
]))
167
{
168
$fromClouds =
true
;
169
}
170
171
if
($fromClouds)
172
{
173
$filename = preg_replace(
'~^(http[s]?)(\://)~i'
,
'\\1.'
, $filename);
174
$cloudUploadPath = Option::get(
175
'main'
,
176
'bx_cloud_upload'
,
177
'/upload/bx_cloud_upload/'
178
);
179
$zipEntry->path = $cloudUploadPath . $filename;
180
}
181
else
182
{
183
$zipEntry->path = $filename;
184
}
185
$zipEntry->path = Uri::urnEncode($zipEntry->path,
'UTF-8'
);
186
187
return
$zipEntry;
188
}
189
194
protected
static
function
getDocRoot
()
195
{
196
static
$docRoot =
null
;
197
198
if
($docRoot ===
null
)
199
{
200
$context =
Application::getInstance
()->getContext();
201
$server = $context->getServer();
202
$docRoot = $server->getDocumentRoot();
203
}
204
205
return
$docRoot;
206
}
207
212
public
function
__toString
()
213
{
214
$crc32
= $this->
getCrc32
()?:
'-'
;
215
$name
= Encoding::convertEncoding(
216
$this->
getName
(),
217
LANG_CHARSET,
218
'UTF-8'
219
);
220
221
return
"{$crc32} {$this->getSize()} {$this->getPath()} {$name}"
;
222
}
223
}
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getInstance
static getInstance()
Definition
application.php:95
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\Engine\Response\Zip\ArchiveEntry
Definition
archiveentry.php:15
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\__construct
__construct()
Definition
archiveentry.php:43
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\$path
$path
Definition
archiveentry.php:26
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\getDocRoot
static getDocRoot()
Definition
archiveentry.php:194
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\setName
setName($name)
Definition
archiveentry.php:60
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\getPath
getPath()
Definition
archiveentry.php:71
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\getName
getName()
Definition
archiveentry.php:50
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\getCrc32
getCrc32()
Definition
archiveentry.php:88
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\$crc32
$crc32
Definition
archiveentry.php:38
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\createFromFile
static createFromFile(array $fileArray, $name=null)
Definition
archiveentry.php:153
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\__toString
__toString()
Definition
archiveentry.php:212
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\getSize
getSize()
Definition
archiveentry.php:80
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\createFromFilePath
static createFromFilePath($filePath, $name=null)
Definition
archiveentry.php:99
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\$name
$name
Definition
archiveentry.php:20
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\$size
$size
Definition
archiveentry.php:32
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\createFromFileId
static createFromFileId($fileId, $moduleId=null)
Definition
archiveentry.php:122
Bitrix\Main\Text\Encoding
Definition
encoding.php:8
Bitrix\Main\Web\Uri
Definition
uri.php:17
Bitrix\Main\Engine\Response\Zip
Definition
archive.php:2
modules
main
lib
engine
response
zip
archiveentry.php
Создано системой
1.10.0