Example #1
0
 function doupload()
 {
     // Get the uploaded file information
     $userfile = JRequest::getVar('theme', null, 'files', 'array');
     $lang = JFactory::getLanguage();
     $lang->load('com_installer');
     // Make sure that file uploads are enabled in php
     if (!(bool) ini_get('file_uploads')) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLFILE'));
         $this->setRedirect("index.php?option=" . APP_EXTENSION . "&task=themes.upload");
         return true;
     }
     // Make sure that zlib is loaded so that the package can be unpacked
     if (!extension_loaded('zlib')) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLZLIB'));
         $this->setRedirect("index.php?option=" . APP_EXTENSION . "&task=themes.upload");
         return true;
     }
     // If there is no uploaded file, we have a problem...
     if (!is_array($userfile)) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_NO_FILE_SELECTED'));
         $this->setRedirect("index.php?option=" . APP_EXTENSION . "&task=themes.upload");
         return true;
     }
     // Check if there was a problem uploading the file.
     if ($userfile['error'] || $userfile['size'] < 1) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLUPLOADERROR'));
         $this->setRedirect("index.php?option=" . APP_EXTENSION . "&task=themes.upload");
         return true;
     }
     // Build the appropriate paths
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path') . '/' . $userfile['name'];
     $tmp_src = $userfile['tmp_name'];
     // Move uploaded file
     jimport('joomla.filesystem.file');
     $uploaded = JFile::upload($tmp_src, $tmp_dest);
     jimport('joomla.installer.helper');
     $package = JTheFactoryThemesHelper::unpackTheme($tmp_dest);
     // Was the package unpacked?
     if (!$package) {
         JError::raiseWarning('', JText::_('COM_INSTALLER_UNABLE_TO_FIND_INSTALL_PACKAGE'));
         $this->setRedirect("index.php?option=" . APP_EXTENSION . "&task=themes.upload");
         return true;
     }
     JTheFactoryThemesHelper::installTheme($package['dir']);
     if (!is_file($package['packagefile'])) {
         $config = JFactory::getConfig();
         $package['packagefile'] = $config->get('tmp_path') . '/' . $package['packagefile'];
     }
     JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
     $this->setRedirect("index.php?option=" . APP_EXTENSION . "&task=themes.listthemes", JText::_("FACTORY_THEME_INSTALLED"));
 }