1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
archive.php
См. документацию.
1<?php
3
6
7class Archive extends HttpResponse
8{
9 public const MOD_ZIP_HEADER_NAME = 'X-Archive-Files';
14 protected string $name;
15
20 protected array $entries = [];
21
26 public function __construct(string $name)
27 {
28 parent::__construct();
29
30 $this->name = $name;
31 $this->addHeader(self::MOD_ZIP_HEADER_NAME, 'zip');
32 }
33
38 public function addEntry($archiveEntry): void
39 {
40 if ($archiveEntry instanceof ArchiveEntry)
41 {
42 $this->entries[] = $archiveEntry;
43 }
44 elseif ($archiveEntry instanceof EntryInterface)
45 {
46 $this->entries[] = $archiveEntry;
47 }
48 }
49
50 private function convertEntryInterfaceToString(EntryInterface $entry): string
51 {
52 $crc32 = ($entry->getCrc32() !== '') ? $entry->getCrc32() : '-';
53 $name = $entry->getPath();
54
55 return "{$crc32} {$entry->getSize()} {$entry->getServerRelativeUrl()} {$name}";
56 }
57
62 public function isEmpty(): bool
63 {
64 return empty($this->entries);
65 }
66
71 protected function getFileList(): string
72 {
73 $list = [];
74 foreach ($this->entries as $entry)
75 {
76 if ($entry instanceof ArchiveEntry)
77 {
78 $list[] = (string)$entry;
79 }
80 elseif ($entry instanceof EntryInterface)
81 {
82 $list[] = $this->convertEntryInterfaceToString($entry);
83 }
84 }
85
86 return implode("\n", $list);
87 }
88
89 protected function setContentDispositionHeader(): void
90 {
91 $utfName = Uri::urnEncode($this->name, 'UTF-8');
92 $translitName = \CUtil::translit($this->name, LANGUAGE_ID, [
93 'max_len' => 1024,
94 'safe_chars' => '.',
95 'replace_space' => '-',
96 ]);
97 $this->addHeader(
98 'Content-Disposition',
99 "attachment; filename=\"{$translitName}\"; filename*=utf-8''{$utfName}"
100 );
101 }
102
103 public function send(): void
104 {
105 if (!$this->isEmpty())
106 {
108 $this->setContent(
109 $this->getFileList()
110 );
111 }
112
113 parent::send();
114 }
115}
Определения archiveentry.php:14
addEntry($archiveEntry)
Определения archive.php:38
__construct(string $name)
Определения archive.php:26
const MOD_ZIP_HEADER_NAME
Определения archive.php:9
addHeader($name, $value='')
Определения httpresponse.php:72
setContent($content)
Определения response.php:31
Определения uri.php:17
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
Определения entryinterface.php:6
getPath()
getCrc32()
$name
Определения menu_edit.php:35
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393