Actions

API15

JInstallerHelper/unpack

From Joomla! Documentation

< API15:JInstallerHelper
Revision as of 13:32, 12 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Unpacks a file and verifies it as a Joomla element package Supports .gz .tar .tar.gz and .zip

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

unpack($p_filename)
Parameter Name Default Value Description
$p_filename $p_filename The uploaded package filename or install directory

Returns

Array Two elements - extractdir and packagefile

Defined in

libraries/joomla/installer/helper.php

Importing

jimport( 'joomla.installer.helper' );

Source Body

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 = JArchive::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'] = JInstallerHelper::detectType($extractdir))
        {
                return $retval;
        } else
        {
                return false;
        }
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />