1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
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: | |
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: | |