1<?php
2
3/////////////////////////////////////////////////////////////////
4/// getID3() by James Heinrich <info@getid3.org>               //
5//  available at https://github.com/JamesHeinrich/getID3       //
6//            or https://www.getid3.org                        //
7//            or http://getid3.sourceforge.net                 //
8//  see readme.txt for more details                            //
9/////////////////////////////////////////////////////////////////
10//                                                             //
11// module.archive.rar.php                                      //
12// module for analyzing RAR files                              //
13// dependencies: NONE                                          //
14//                                                            ///
15/////////////////////////////////////////////////////////////////
16
17if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
18	exit;
19}
20
21class getid3_rar extends getid3_handler
22{
23	/**
24	 * @var bool
25	 */
26	public $option_use_rar_extension = false;
27
28	/**
29	 * @return bool
30	 */
31	public function Analyze() {
32		$info = &$this->getid3->info;
33
34		$info['fileformat'] = 'rar';
35
36		if ($this->option_use_rar_extension === true) {
37			if (function_exists('rar_open')) {
38				if ($rp = rar_open($info['filenamepath'])) {
39					$info['rar']['files'] = array();
40					$entries = rar_list($rp);
41					foreach ($entries as $entry) {
42						$info['rar']['files'] = getid3_lib::array_merge_clobber($info['rar']['files'], getid3_lib::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize()));
43					}
44					rar_close($rp);
45					return true;
46				} else {
47					$this->error('failed to rar_open('.$info['filename'].')');
48				}
49			} else {
50				$this->error('RAR support does not appear to be available in this PHP installation');
51			}
52		} else {
53			$this->error('PHP-RAR processing has been disabled (set $getid3_rar->option_use_rar_extension=true to enable)');
54		}
55		return false;
56
57	}
58
59}
60