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: * Provides rar compression/decompression routines in the file manager
16: *
17: * @package Compression
18: */
19: class Rar_Filter extends Archive_Base
20: {
21: protected static $binary_handler = [
22: 'read' => 'rar', 'write' => 'rar'
23: ];
24: protected static $mapping_list = [
25: 'list' => 'lt',
26: 'extract_all' => 'x'
27: ];
28:
29: public static function extract_files($mArchive, $mDestination, $mFile = null)
30: {
31: //print ($mArchive. ' '.$mDestination);
32: $proc = self::exec(
33: static::$binary_handler['write'] . ' '
34: . static::$mapping_list['extract_all'] . ' ' . $mArchive
35: . ' ' . $mDestination
36: );
37:
38: return $proc;
39: }
40:
41: public static function list_files($mArchive)
42: {
43: $proc = self::exec(
44: static::$binary_handler['read'] . ' '
45: . static::$mapping_list['list'] . ' ' . $mArchive
46: );
47: $proc = explode("\n", trim($proc['output']));
48: $files = array();
49: foreach ($proc as $line) {
50:
51: if (!preg_match('!(.+?)\s+(\d+)\s+(\d+)\s+\d+%\s+([0-9\-]+ \d\d?:\d\d)\s+([A-Z\.]+)\s+([A-F0-9]+)!',
52: $line, $matches)
53: ) {
54: continue;
55: }
56: list ($null, $file_name, $size, $packed_size, $date, $attr, $crc) = $matches;
57: $files[] = array(
58: 'file_name' => $file_name,
59: 'file_type' => $file_name[strlen($file_name) - 1] == '/' ? 'dir' : 'file',
60: 'can_read' => true,
61: 'can_write' => true,
62: 'can_execute' => true,
63: 'size' => $size,
64: 'packed_size' => $packed_size,
65: 'crc' => $crc,
66: 'link' => 0,
67: 'date' => strtotime($date)
68: );
69: }
70:
71: return $files;
72:
73: }
74: }
75:
76: ?>
77: