Source for file helper.php
Documentation is available at helper.php
* @package Joomla.Libraries
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
jimport('joomla.filesystem.folder');
* @package Joomla.Libraries
* @param string $url URL of file to download
* @param string $target Download target filename [optional]
* @return mixed Path to downloaded package or boolean false on failure
$track_errors =
ini_get('track_errors');
ini_set('user_agent', $version->getUserAgent('Installer'));
$response =
$http->get($url);
if (302 ==
$response->code && isset
($response->headers['Location']))
return self::downloadPackage($response->headers['Location']);
elseif (200 !=
$response->code)
JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT', $response->code), JLog::WARNING, 'jerror');
if (isset
($response->headers['Content-Disposition']))
$contentfilename =
explode("\"", $response->headers['Content-Disposition']);
$target =
$contentfilename[1];
// Set the target path if not given
$target =
$config->get('tmp_path') .
'/' .
self::getFilenameFromURL($url);
$target =
$config->get('tmp_path') .
'/' .
basename($target);
// Restore error tracking to what it was before
ini_set('track_errors', $track_errors);
// Bump the max execution time because not using built in php zip libs are slow
// Return the name of the downloaded package
* Unpacks a file and verifies it as a Joomla element package
* Supports .gz .tar .tar.gz and .zip
* @param string $p_filename The uploaded package filename or install directory
* @param boolean $alwaysReturnArray If should return false (and leave garbage behind) or return $retval['type']=false
* @return mixed Array on success or boolean false on failure
public static function unpack($p_filename, $alwaysReturnArray =
false)
$archivename =
$p_filename;
// Temporary folder to extract the archive into
// Clean the paths to use for archive extraction
// Do the unpacking of the archive
$retval['extractdir'] =
null;
$retval['packagefile'] =
$archivename;
* Let's 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.
if (count($dirList) ==
1)
$extractdir =
JPath::clean($extractdir .
'/' .
$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
$retval['type'] =
self::detectType($extractdir);
if ($retval['type'] ||
$alwaysReturnArray)
* Method to detect the extension type from a package directory
* @param string $p_dir Path to package directory
* @return mixed Extension type string or boolean false on fail
// Search the install dir for an XML file
JLog::add(JText::_('JLIB_INSTALLER_ERROR_NOTFINDXMLSETUPFILE'), JLog::WARNING, 'jerror');
foreach ($files as $file)
if ($xml->getName() !=
'extension')
$type = (string)
$xml->attributes()->type;
JLog::add(JText::_('JLIB_INSTALLER_ERROR_NOTFINDJOOMLAXMLSETUPFILE'), JLog::WARNING, 'jerror');
* Gets a file name out of a url
* @param string $url URL to get name from
* @return mixed String filename or boolean false if failed
return $parts[count($parts) -
1];
* Clean up temporary uploaded package and unpacked extension
* @param string $package Path to the uploaded package file
* @param string $resultdir Path to the unpacked extension
* @return boolean True on success
// Does the unpacked extension directory exist?
if ($resultdir &&
is_dir($resultdir))
// Is the package file a valid file?
// It might also be just a base filename
* Splits contents of a sql file into array of discreet queries.
* Queries need to be delimited with end of statement marker ';'
* @param string $query The SQL statement.
* @return array Array of queries
* @deprecated 13.3 Use JDatabaseDriver::splitSql() directly
JLog::add('JInstallerHelper::splitSql() is deprecated. Use JDatabaseDriver::splitSql() instead.', JLog::WARNING, 'deprecated');
return $db->splitSql($query);
Documentation generated on Tue, 19 Nov 2013 15:04:24 +0100 by phpDocumentor 1.4.3