Files
@ c7d7e38b2269
Branch filter:
Location: hot67beta/administrator/components/com_installer/models/install.php
c7d7e38b2269
5.9 KiB
text/x-php
Initial import of the site.
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | <?php
/**
* @version $Id: install.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla
* @subpackage Menus
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );
jimport( 'joomla.installer.installer' );
jimport('joomla.installer.helper');
/**
* Extension Manager Install Model
*
* @package Joomla
* @subpackage Installer
* @since 1.5
*/
class InstallerModelInstall extends JModel
{
/** @var object JTable object */
var $_table = null;
/** @var object JTable object */
var $_url = null;
/**
* Overridden constructor
* @access protected
*/
function __construct()
{
parent::__construct();
}
function install()
{
global $mainframe;
$this->setState('action', 'install');
switch(JRequest::getWord('installtype'))
{
case 'folder':
$package = $this->_getPackageFromFolder();
break;
case 'upload':
$package = $this->_getPackageFromUpload();
break;
case 'url':
$package = $this->_getPackageFromUrl();
break;
default:
$this->setState('message', 'No Install Type Found');
return false;
break;
}
// Was the package unpacked?
if (!$package) {
$this->setState('message', 'Unable to find install package');
return false;
}
// Get a database connector
//$db = & JFactory::getDBO();
// Get an installer instance
$installer =& JInstaller::getInstance();
// Install the package
if (!$installer->install($package['dir'])) {
// There was an error installing the package
$msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Error'));
$result = false;
} else {
// Package installed sucessfully
$msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Success'));
$result = true;
}
// Set some model state values
$mainframe->enqueueMessage($msg);
$this->setState('name', $installer->get('name'));
$this->setState('result', $result);
$this->setState('message', $installer->message);
$this->setState('extension.message', $installer->get('extension.message'));
// Cleanup the install files
if (!is_file($package['packagefile'])) {
$config =& JFactory::getConfig();
$package['packagefile'] = $config->getValue('config.tmp_path').DS.$package['packagefile'];
}
JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
return $result;
}
/**
* @param string The class name for the installer
*/
function _getPackageFromUpload()
{
// Get the uploaded file information
$userfile = JRequest::getVar('install_package', null, 'files', 'array' );
// Make sure that file uploads are enabled in php
if (!(bool) ini_get('file_uploads')) {
JError::raiseWarning('SOME_ERROR_CODE', JText::_('WARNINSTALLFILE'));
return false;
}
// Make sure that zlib is loaded so that the package can be unpacked
if (!extension_loaded('zlib')) {
JError::raiseWarning('SOME_ERROR_CODE', JText::_('WARNINSTALLZLIB'));
return false;
}
// If there is no uploaded file, we have a problem...
if (!is_array($userfile) ) {
JError::raiseWarning('SOME_ERROR_CODE', JText::_('No file selected'));
return false;
}
// Check if there was a problem uploading the file.
if ( $userfile['error'] || $userfile['size'] < 1 )
{
JError::raiseWarning('SOME_ERROR_CODE', JText::_('WARNINSTALLUPLOADERROR'));
return false;
}
// Build the appropriate paths
$config =& JFactory::getConfig();
$tmp_dest = $config->getValue('config.tmp_path').DS.$userfile['name'];
$tmp_src = $userfile['tmp_name'];
// Move uploaded file
jimport('joomla.filesystem.file');
$uploaded = JFile::upload($tmp_src, $tmp_dest);
// Unpack the downloaded package file
$package = JInstallerHelper::unpack($tmp_dest);
return $package;
}
/**
* Install an extension from a directory
*
* @static
* @return boolean True on success
* @since 1.0
*/
function _getPackageFromFolder()
{
// Get the path to the package to install
$p_dir = JRequest::getString('install_directory');
$p_dir = JPath::clean( $p_dir );
// Did you give us a valid directory?
if (!is_dir($p_dir)) {
JError::raiseWarning('SOME_ERROR_CODE', JText::_('Please enter a package directory'));
return false;
}
// Detect the package type
$type = JInstallerHelper::detectType($p_dir);
// Did you give us a valid package?
if (!$type) {
JError::raiseWarning('SOME_ERROR_CODE', JText::_('Path does not have a valid package'));
return false;
}
$package['packagefile'] = null;
$package['extractdir'] = null;
$package['dir'] = $p_dir;
$package['type'] = $type;
return $package;
}
/**
* Install an extension from a URL
*
* @static
* @return boolean True on success
* @since 1.5
*/
function _getPackageFromUrl()
{
// Get a database connector
$db = & JFactory::getDBO();
// Get the URL of the package to install
$url = JRequest::getString('install_url');
// Did you give us a URL?
if (!$url) {
JError::raiseWarning('SOME_ERROR_CODE', JText::_('Please enter a URL'));
return false;
}
// Download the package at the URL given
$p_file = JInstallerHelper::downloadPackage($url);
// Was the package downloaded?
if (!$p_file) {
JError::raiseWarning('SOME_ERROR_CODE', JText::_('Invalid URL'));
return false;
}
$config =& JFactory::getConfig();
$tmp_dest = $config->getValue('config.tmp_path');
// Unpack the downloaded package file
$package = JInstallerHelper::unpack($tmp_dest.DS.$p_file);
return $package;
}
}
|