Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
archiveentry.php
1<?php
3
4use \Bitrix\Main\Text\Encoding;
5use \Bitrix\Main\Config\Option;
6use \Bitrix\Landing\File;
7use \Bitrix\Landing\Manager;
8
10{
15 protected $name;
16
21 protected $path;
22
27 protected $fileId;
28
33 protected $size;
34
38 protected function __construct()
39 {
40 $this->fileId = 0;
41 }
42
48 public static function createFromFilePath($filePath)
49 {
50 $fileArray = \CFile::MakeFileArray($filePath);
51
52 if ($fileArray)
53 {
55 'ID' => 0,
56 'ORIGINAL_NAME' => $fileArray['name'],
57 'FILE_SIZE' => $fileArray['size'],
58 'SRC' => substr(
59 $fileArray['tmp_name'],
60 strlen(Manager::getDocRoot())
61 ),
62 ]);
63 }
64
65 return null;
66 }
67
73 public static function createFromFileId($fileId)
74 {
75 $fileArray = File::getFileArray($fileId);
76
77 if (
78 !$fileArray ||
79 empty($fileArray['SRC'])
80 )
81 {
82 return null;
83 }
84
85 return self::createFromFile($fileArray);
86 }
87
93 protected static function createFromFile(array $fileArray)
94 {
95 $zipEntry = new static;
96 $zipEntry->name = $fileArray['ORIGINAL_NAME'];
97 $zipEntry->fileId = $fileArray['ID'];
98 $zipEntry->size = $fileArray['FILE_SIZE'];
99
100 $fromClouds = false;
101 $filename = $fileArray['SRC'];
102
103 if (isset($fileArray['HANDLER_ID']) && !empty($fileArray['HANDLER_ID']))
104 {
105 $fromClouds = true;
106 }
107
108 unset($fileArray);
109
110 if ($fromClouds)
111 {
112 $filename = preg_replace('~^(http[s]?)(\://)~i', '\\1.' , $filename);
113 $cloudUploadPath = Option::get(
114 'main',
115 'bx_cloud_upload',
116 '/upload/bx_cloud_upload/'
117 );
118 $zipEntry->path = $cloudUploadPath . $filename;
119 unset($cloudUploadPath);
120 }
121 else
122 {
123 $zipEntry->path = self::encodeUrn(
124 Encoding::convertEncoding($filename, LANG_CHARSET, 'UTF-8')
125 );
126 }
127 unset($filename);
128
129 return $zipEntry;
130 }
131
137 protected function encodeUrn($uri)
138 {
139 $result = '';
140 $parts = preg_split(
141 "#(://|:\\d+/|/|\\?|=|&)#", $uri, -1, PREG_SPLIT_DELIM_CAPTURE
142 );
143
144 foreach ($parts as $i => $part)
145 {
146 $part = Manager::getApplication()->convertCharset(
147 $part,
148 LANG_CHARSET,
149 'UTF-8'
150 );
151 $result .= ($i % 2)
152 ? $part
153 : rawurlencode($part);
154 }
155 unset($parts, $i, $part);
156
157 return $result;
158 }
159
164 public function __toString()
165 {
166 $name = Encoding::convertEncoding(
167 $this->name,
168 LANG_CHARSET,
169 'UTF-8'
170 );
171 return "- {$this->size} {$this->path} /upload/{$this->fileId}/{$name}";
172 }
173}
static getFileArray($fileId)
Definition file.php:580
static getApplication()
Definition manager.php:71
__construct()
$path
encodeUrn($uri)
$fileId
static createFromFileId($fileId)
__toString()
$name
static createFromFile(array $fileArray)
static createFromFilePath($filePath)
$size