Esempio n. 1
0
 function downloadTemplatePackage($post)
 {
     $session = JFactory::getSession();
     $login_identifier = md5('state_update_login_' . strtolower($this->_template_name));
     $state_login = $session->get($login_identifier, false, 'jsntemplatesession');
     if (!$state_login) {
         jexit('Invalid Token');
     }
     $link = JSN_TEMPLATE_AUTOUPDATE_URL . '&identified_name=' . urlencode($this->_identified_name) . '&based_identified_name=' . urlencode($this->_based_identified_name) . '&edition=' . urlencode($this->_edition) . '&joomla_version=' . urlencode($this->_joomla_version) . '&username='******'customer_username']) . '&password='******'customer_password']) . '&product_version=' . urlencode($this->_template_version) . '&upgrade=yes';
     $tmpName = strtolower($this->_name . '_' . str_replace(' ', '_', $this->_edition) . '.zip');
     $objJSNDownloadPackage = new JSNDownloadTemplatePackage($link, $tmpName);
     return $objJSNDownloadPackage->download();
 }
Esempio n. 2
0
 /**
  * This function is for installing extensions for sample data
  * This function DOES NOT actually install the extension, but acts as a
  * "proxy" to receive request from AJAX, then using HTTP Socket to send an
  * internal request to install the extension.
  * It is important to go this way because direct AJAX request to install
  * the extension might get interrupted because some extensions will perform
  * a 303 redirection after standard Joomla JInstaller process.
  */
 function requestInstallExtension()
 {
     $session = JFactory::getSession();
     $sdExtSesId = md5('exts_info_' . strtolower($this->_template_name));
     $sdExtInstallSesId = md5('exts_to_install_' . strtolower($this->_template_name));
     $sessionExtFailedId = md5('exts_failed_install_' . strtolower($this->_template_name));
     $sdFileSesId = md5('sample_data_file_' . strtolower($this->_template_name));
     $extInfoArray = $session->get($sdExtSesId, array(), 'jsntemplatesession');
     $flatInstallExts = $session->get($sdExtInstallSesId, array(), 'jsntemplatesession');
     $sdHelperInstance = new JSNSampleDataHelper();
     /* Get the submitted valirables */
     $extName = JRequest::getVar('ext_name');
     if (array_key_exists($extName, $extInfoArray)) {
         $extInfo = $extInfoArray[$extName];
         $installResult = true;
         $toContinue = true;
         $mes = '';
         $failedExts = $session->get($sessionExtFailedId, array(), 'jsntemplatesession');
         $sampleDataFile = '';
         /* Download latest version */
         require_once $this->_template_folder_path . DS . 'includes' . DS . 'lib' . DS . 'jsn_downloadtemplatepackage.php';
         $joomlaVersion = $this->_obj_utils->getJoomlaVersion(true);
         if ($extInfo->downloadUrl) {
             $link = $extInfo->downloadUrl;
         } else {
             $link = JSN_TEMPLATE_AUTOUPDATE_URL . '&identified_name=' . urlencode($extInfo->identifiedName) . '&joomla_version=' . $joomlaVersion . '&edition=free&upgrade=yes';
         }
         $tmpName = $extInfo->name . '-j' . $joomlaVersion . '.zip';
         $packageDownloaderInstance = new JSNDownloadTemplatePackage($link, $tmpName);
         $downloadResult = $packageDownloaderInstance->download();
         if (!$downloadResult || stripos($downloadResult, 'error0') !== false) {
             $installResult = false;
             $failedExts[$extInfo->name]['exist'] = $extInfo->exist;
             $mes = JText::_('JSN_SAMPLE_DATA_EXT_DOWNLOAD_FAILED');
             if ($extInfo->hasData === true) {
                 $failedExts[$extInfo->name]['message'] = JText::sprintf('JSN_SAMPLE_DATA_WARNING_EXT_INSTALL_FAILED', $extInfo->description);
             }
         } else {
             /* If download success, send HTTP Socket request to install */
             $url = JURI::root() . 'index.php?template=' . strtolower($this->_template_name) . '&tmpl=jsn_runajax&task=installExtension' . '&package=' . urlencode($downloadResult) . '&redirect=0';
             // The last argument NOFOLLOW = true means don't follow redirection
             $httpRequestInstance = new JSNHTTPSocket($url, null, null, 'get', true);
             $output = json_decode($httpRequestInstance->socketDownload());
             /* Assuming empty string (as redirection) returned means success */
             if (isset($output->result) && $output->result === false) {
                 $installResult = false;
                 if (isset($output->message) && $output->message != '') {
                     $mes = $output->message;
                 } else {
                     $mes = JText::_('JSN_SAMPLE_DATA_INSTALL_FAILED');
                 }
                 $failedExts[$extInfo->name]['exist'] = $extInfo->exist;
                 /* Only show warning for the extension which actually has sample data */
                 if ($extInfo->hasData === true) {
                     $failedExts[$extInfo->name]['message'] = JText::sprintf('JSN_SAMPLE_DATA_WARNING_EXT_INSTALL_FAILED', $extInfo->description);
                 }
             } else {
                 $installResult = true;
                 /**
                  * As ImageShow might not have completed the installation
                  * itself, so Joomla cannot remove the installation file.
                  * We need to delete installer package using an existing
                  * function of SampleData Helper.
                  */
                 $sdHelperInstance->deleteSampleDataFile($downloadResult);
                 /* Enable plugins as were not enabled by JInstaller */
                 $sdHelperInstance->enableInstalledPlugin($extInfo->name, $extInfo->type);
             }
         }
         /* Change to the next extension if available */
         if (array_key_exists($extName, $flatInstallExts)) {
             unset($flatInstallExts[$extName]);
             if (count($flatInstallExts) > 0) {
                 $arrayKeys = array_keys($flatInstallExts);
                 $nextExt = $arrayKeys[0];
                 $childOf = $flatInstallExts[$nextExt]['childOf'];
                 $isLastExt = $flatInstallExts[$nextExt]['isLastExt'];
             } else {
                 $nextExt = '';
                 $childOf = '';
                 $isLastExt = false;
             }
             $sampleDataFile = $session->get($sdFileSesId, '', 'jsntemplatesession');
             $session->set($sdExtInstallSesId, $flatInstallExts, 'jsntemplatesession');
             $session->set($sessionExtFailedId, $failedExts, 'jsntemplatesession');
             echo json_encode(array('installExt' => $installResult, 'extName' => $extName, 'message' => $mes, 'nextExt' => $nextExt, 'childOf' => $childOf, 'isLastExt' => $isLastExt, 'tocontinue' => $toContinue, 'sampleDataFile' => $sampleDataFile));
         }
     }
     exit;
 }
Esempio n. 3
0
 function downloadTemplatePackage($post, $edition)
 {
     $link = JSN_TEMPLATE_AUTOUPDATE_URL . '&identified_name=' . urlencode($this->_identified_name) . '&edition=' . urlencode($edition) . '&joomla_version=' . urlencode($this->_joomla_version) . '&username='******'&password='******'&product_version=' . urlencode($this->_template_version) . '&upgrade=yes';
     $tmpName = strtolower($this->_name . '_' . str_replace(' ', '_', $edition) . '.zip');
     $objJSNDownloadPackage = new JSNDownloadTemplatePackage($link, $tmpName);
     return $objJSNDownloadPackage->download();
 }