1: <?php
2: /**
3: * Copyright (C) Apis Networks, Inc - All Rights Reserved.
4: *
5: * Unauthorized copying of this file, via any medium, is
6: * strictly prohibited without consent. Any dissemination of
7: * material herein is prohibited.
8: *
9: * For licensing inquiries email <licensing@apisnetworks.com>
10: *
11: * Written by Matt Saladna <matt@apisnetworks.com>, May 2017
12: */
13:
14: /**
15: * @package Compression
16: * Provides zip compression/decompression routines in the file manager
17: */
18: class Zip_Filter extends Archive_Base
19: {
20: public static function extract_files($archive, $dest, array $file = null, ?array $opts = array())
21: {
22: $zip = new ZipArchive();
23: if (!$zip->open($archive)) {
24: return error("unable to open archive `%(file)s': %(reason)s", [
25: 'file' => $archive,
26: 'reason' => $zip->getStatusString()
27: ]);
28: }
29: $zip->extractTo($dest, $file);
30: $zip->close();
31:
32: return true;
33: }
34:
35: public static function list_files($archive, ?array $opts = array())
36: {
37: $zip = new ZipArchive();
38: if (!$zip->open($archive)) {
39: return error("unable to open archive `%(file)s': %(reason)s", [
40: 'file' => $archive,
41: 'reason' => $zip->getStatusString()
42: ]);
43: }
44: $files = [];
45: $n = $zip->count();
46: for ($i = 0; $i < $n; $i++) {
47: $stat = $zip->statIndex($i);
48: $name = $stat['name'];
49: $files[] = [
50: 'file_name' => $name,
51: 'file_type' => $name[-1] === '/' ? 'dir' : 'file',
52: 'can_read' => true,
53: 'can_write' => true,
54: 'can_execute' => true,
55: 'size' => !$stat['size'] ? FILESYSTEM_BLKSZ*1024 : $stat['size'],
56: 'packed_size' => $stat['comp_size'],
57: 'crc' => sprintf("%08X", $stat['crc'] ?? 0),
58: 'link' => 0,
59: 'date' => $stat['mtime']
60: ];
61: }
62: return $files;
63:
64: }
65: }
66: