/**
  * Install downloaded package to joomla system
  *
  * @return  void
  */
 public function installAction()
 {
     JSNTplHelper::isDisabledFunction('set_time_limit') or set_time_limit(0);
     $config = JFactory::getConfig();
     $config->set('debug', 0);
     if (!is_file($packageFile = $this->session->get($this->template['id'] . '.upgradePackage'))) {
         throw new Exception("Package file not found: {$packageFile}");
     }
     // Load extension installation library
     jimport('joomla.installer.helper');
     $language = JFactory::getLanguage();
     $language->load('lib_joomla', JPATH_SITE);
     // Unpack downloaded upgrade package
     $unpackedInfo = JInstallerHelper::unpack($packageFile);
     if (empty($unpackedInfo) or !isset($unpackedInfo['dir'])) {
         throw new Exception(JText::_('JSN_TPLFW_ERROR_CANNOT_EXTRACT_TEMPLATE_PACKAGE_FILE'));
     }
     // Check if template is copied to another name
     if ($xml = simplexml_load_file($unpackedInfo['dir'] . '/template/templateDetails.xml')) {
         if (strcasecmp($this->template['name'], trim((string) $xml->name)) != 0) {
             // Update templateDetails.xml with new name
             $content = str_replace((string) $xml->name, $this->template['name'], JFile::read($unpackedInfo['dir'] . '/template/templateDetails.xml'));
             JFile::write($unpackedInfo['dir'] . '/template/templateDetails.xml', $content);
         }
     }
     // Upgrade now
     $installer = JInstaller::getInstance();
     $installer->setUpgrade(true);
     $installResult = $installer->install($unpackedInfo['dir']);
     if ($installResult === false) {
         foreach (JError::getErrors() as $error) {
             throw $error;
         }
     }
     // Clean up temporary data
     JInstallerHelper::cleanupInstall($packageFile, $unpackedInfo['dir']);
     // Retrieve style id of installed package
     $q = $this->dbo->getQuery(true);
     $q->select('id');
     $q->from('#__template_styles');
     $q->where('template = ' . $q->quote($this->template['name']));
     $this->dbo->setQuery($q);
     $styleId = $this->dbo->loadResult();
     $q = $this->dbo->getQuery(true);
     $q->update('#__template_styles');
     $q->set('home = 0');
     $q->where('client_id = 0');
     $this->dbo->setQuery($q);
     $this->dbo->{$this->queryMethod}();
     $q = $this->dbo->getQuery(true);
     $q->update('#__template_styles');
     $q->set('home = 1');
     $q->where('id = ' . (int) $styleId);
     $this->dbo->setQuery($q);
     $this->dbo->{$this->queryMethod}();
     $this->setResponse(array('styleId' => $styleId));
 }
Beispiel #2
0
 /**
  * Action to handle install extension request.
  *
  * @param   string  $id  Identified name of the extension to be installed.
  *
  * @return  void
  */
 public function installExtensionAction($id = null)
 {
     JSNTplHelper::isDisabledFunction('set_time_limit') or set_time_limit(0);
     // Get necessary variables
     $config = JFactory::getConfig();
     $user = JFactory::getUser();
     $tmpPath = $config->get('tmp_path');
     if (empty($id)) {
         $id = $this->request->getString('id');
     }
     // Disable debug system
     $config->set('debug', 0);
     // Path to sample data file
     $xmlFiles = glob("{$tmpPath}/{$this->template['name']}_sampledata/*.xml");
     if (empty($xmlFiles)) {
         throw new Exception(JText::_('JSN_TPLFW_ERROR_CANNOT_EXTRACT_SAMPLE_DATA_PACKAGE'));
     }
     // Load XML document
     $xml = simplexml_load_file(current($xmlFiles));
     $extensions = $xml->xpath("//extension[@identifiedname=\"{$id}\"]");
     if (!empty($extensions)) {
         $extension = current($extensions);
         $name = (string) $extension['name'];
         $type = (string) $extension['type'];
         switch ($type) {
             case 'component':
                 $name = 'com_' . $name;
                 break;
             case 'module':
                 $name = 'mod_' . $name;
                 break;
         }
         $this->_cleanExtensionAssets($name);
         // Install JSN Extension Framework first if not already installed
         if ($type == 'component') {
             // Get details about JSN Extension Framework
             $extfw = $xml->xpath('//extension[@identifiedname="ext_framework"]');
             if (!empty($extfw)) {
                 $extfw = current($extfw);
                 if ($this->_getExtensionState((string) $extfw['name'], (string) $extfw['version']) != 'installed') {
                     // Install JSN Extension Framework
                     try {
                         $this->installExtensionAction('ext_framework');
                     } catch (Exception $e) {
                         throw $e;
                     }
                 }
             }
         }
     }
     // Download package from lightcart
     try {
         $packageFile = JSNTplApiLightcart::downloadPackage($id, 'FREE', null, null, "{$tmpPath}/{$this->template['name']}_sampledata/");
     } catch (Exception $e) {
         throw $e;
     }
     if (!is_file($packageFile)) {
         throw new Exception("Package file not found: {$packageFile}");
     }
     // Load extension installation library
     jimport('joomla.installer.helper');
     // Rebuild menu structure
     $this->_rebuildMenus();
     // Extract downloaded package
     $unpackedInfo = JInstallerHelper::unpack($packageFile);
     $installer = JInstaller::getInstance();
     if (empty($unpackedInfo) or !isset($unpackedInfo['dir'])) {
         throw new Exception(JText::_('JSN_TPLFW_ERROR_CANNOT_EXTRACT_EXTENSION_PACKAGE_FILE'));
     }
     // Install extracted package
     $installResult = $installer->install($unpackedInfo['dir']);
     if ($installResult === false) {
         foreach (JError::getErrors() as $error) {
             throw $error;
         }
     }
     // Clean up temporary data
     JInstallerHelper::cleanupInstall($packageFile, $unpackedInfo['dir']);
     $this->_activeExtension(array('type' => $type, 'name' => $name));
     // Rebuild menu structure
     $this->_rebuildMenus();
 }
 public function downloadFrameworkAction()
 {
     if (!JSNTplHelper::isDisabledFunction('set_time_limit')) {
         set_time_limit(0);
     }
     // Download package file
     try {
         JSNTplApiLightcart::downloadPackage('tpl_framework');
     } catch (Exception $e) {
         throw $e;
     }
 }