1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 
<?php
    /**
     * Copyright (C) Apis Networks, Inc - All Rights Reserved.
     *
     * Unauthorized copying of this file, via any medium, is
     * strictly prohibited without consent. Any dissemination of
     * material herein is prohibited.
     *
     * For licensing inquiries email <licensing@apisnetworks.com>
     *
     * Written by Matt Saladna <matt@apisnetworks.com>, May 2017
     */

    /**
     * Provides rar compression/decompression routines in the file manager
     *
     * @package Compression
     */
    class Rar_Filter extends Archive_Base
    {
        protected $binary_handler;
        protected $mapping_list;

        public function __construct(&$mClass)
        {
            $this->binary_handler = array('read' => 'rar', 'write' => 'rar');
            $this->mapping_list = array(
                'list'        => 'lt',
                'extract_all' => 'x'
            );
        }

        public static function extract_files($mArchive, $mDestination, $mFile = null)
        {
            //print ($mArchive. ' '.$mDestination);
            $proc = self::exec(
                $this->binary_handler['write'] . ' '
                . $this->mapping_list['extract_all'] . ' ' . $mArchive
                . ' ' . $mDestination
            );

            return $proc;
        }

        public static function list_files($mArchive)
        {
            $proc = self::exec(
                $this->binary_handler['read'] . ' '
                . $this->mapping_list['list'] . ' ' . $mArchive
            );
            $proc = explode("\n", trim($proc['output']));
            $files = array();
            foreach ($proc as $line) {

                if (!preg_match('!(.+?)\s+([0-9]+)\s+([0-9]+)\s+[0-9]+%\s+([0-9\-]+ [0-9][0-9]?:[0-9][0-9])\s+([A-Z\.]+)\s+([A-F0-9]+)!',
                    $line, $matches)
                ) {
                    continue;
                }
                list ($null, $file_name, $size, $packed_size, $date, $attr, $crc) = $matches;
                $files[] = array(
                    'file_name'   => $file_name,
                    'file_type'   => $file_name[strlen($file_name) - 1] == '/' ? 'dir' : 'file',
                    'can_read'    => true,
                    'can_write'   => true,
                    'can_execute' => true,
                    'size'        => $size,
                    'packed_size' => $packed_size,
                    'crc'         => $crc,
                    'link'        => 0,
                    'date'        => strtotime($date)
                );
            }

            return $files;

        }
    }

?>