/** * Unpacks a file and verifies it as a Joomla element package * Supports .gz .tar .tar.gz and .zip * * @static * @param string $p_filename The uploaded package filename or install directory * @return boolean True on success, False on error * @since 1.5 */ static function unpack($p_filename) { // Path to the archive $archivename = $p_filename; // Temporary folder to extract the archive into $tmpdir = uniqid('install_'); // Clean the paths to use for archive extraction $extractdir = JPath::clean(dirname($p_filename) . DS . $tmpdir); $archivename = JPath::clean($archivename); // do the unpacking of the archive $result = self::archive_extract($archivename, $extractdir); if ($result === false) { return false; } /* * Lets set the extraction directory and package file in the result array so we can * cleanup everything properly later on. */ $retval['extractdir'] = $extractdir; $retval['packagefile'] = $archivename; /* * Try to find the correct install directory. In case the package is inside a * subdirectory detect this and set the install directory to the correct path. * * List all the items in the installation directory. If there is only one, and * it is a folder, then we will set that folder to be the installation folder. */ $dirList = array_merge(JFolder::files($extractdir, ''), JFolder::folders($extractdir, '')); if (count($dirList) == 1) { if (JFolder::exists($extractdir . DS . $dirList[0])) { $extractdir = JPath::clean($extractdir . DS . $dirList[0]); } } /* * We have found the install directory so lets set it and then move on * to detecting the extension type. */ $retval['dir'] = $extractdir; /* * Get the extension type and return the directory/type array on success or * false on fail. */ if ($retval['type'] = isJInstallerHelper::detectType($extractdir)) { return $retval; } else { return false; } }