[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/components/com_installer/models/ -> install.php (source)

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


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1