Exemple #1
0
 function downloadSampleDataPackage()
 {
     $obj_sampledata_helper = new JSNSampleDataHelper();
     $obj_sampledata_helper->setSampleDataURL();
     $foldername = 'tmp';
     $folderpath = JPATH_ROOT . DS . $foldername;
     $link = '';
     $template_style_id = JRequest::getInt('template_style_id', 0, 'GET');
     $session = JFactory::getSession();
     $login_identifier = md5('state_login_' . strtolower($this->_template_name));
     $sdExtSesId = md5('exts_info_' . strtolower($this->_template_name));
     $sdFileSesId = md5('sample_data_file_' . strtolower($this->_template_name));
     $sdExtFaiedSesId = md5('exts_failed_install_' . strtolower($this->_template_name));
     $state_login = $session->get($login_identifier, false, 'jsntemplatesession');
     $session->clear($sdExtSesId, 'jsntemplatesession');
     $session->clear($sdExtFaiedSesId, 'jsntemplatesession');
     $session->clear($sdFileSesId, 'jsntemplatesession');
     $failedExts = $session->get($sdExtFaiedSesId, array(), 'jsntemplatesession');
     if (!$state_login) {
         jexit('Invalid Token');
     }
     if (is_writable($folderpath)) {
         $joomla_version = $this->_obj_utils->getJoomlaVersion();
         $downloadURL = JSN_SAMPLE_DATA_FILE_URL;
         $objJSNDownloadPackage = new JSNDownloadPackage($downloadURL);
         $result = $objJSNDownloadPackage->download();
         if ($result) {
             $result = (string) $result;
             $releaseTool = JRequest::getVar('release_tool', 0);
             if ($releaseTool == 1) {
                 echo json_encode(array('download' => true, 'sampleDataFile' => (string) $result, 'connection' => true, 'exts' => ''));
                 return;
             } else {
                 /* Read the xml file for the list of to-be-installed exts */
                 $extsToInstall = array();
                 if (JFile::exists(JPATH_ROOT . DS . 'tmp' . DS . $result)) {
                     /* Array with full info. of available exts */
                     $extInfo = array();
                     /* Array with brief info of will-be-installed exts */
                     $extBriefInfo = '';
                     $extList = '';
                     $hasInstallation = false;
                     $xmlReaderInstance = new JSNReadXMLFile();
                     $sdHelperInstance = new JSNSampleDataHelper();
                     $unpack = $sdHelperInstance->unpackPackage($result);
                     if ($unpack) {
                         $installExts = $xmlReaderInstance->getSampleDataFileContent($unpack, $this->_template_name, true);
                         if ($installExts) {
                             foreach ($installExts as $ext) {
                                 /* Form an array of extensions for user to choose */
                                 /* Check JSN exts, only ones with show="true" flag */
                                 if ($ext->author === 'joomlashine') {
                                     if ($ext->show === true) {
                                         /* Check if the extension would be installed */
                                         $checkResult = $sdHelperInstance->determineExtInstallation($ext);
                                         $extList[$ext->name]['install'] = $checkResult->toInstall;
                                         $extList[$ext->name]['desc'] = $ext->description;
                                         if ($ext->productUrl != '') {
                                             $extList[$ext->name]['url'] = '<a target="_blank" href="' . $ext->productUrl . '">' . JText::_('JSN_SAMPLE_DATA_EXT_SELECT_PRODUCT_LINK_TEXT') . '</a>';
                                         }
                                         if ($ext->productDesc != '') {
                                             $extList[$ext->name]['productDesc'] = $ext->productDesc;
                                         }
                                         /* Show appropriate message for the extensions selection: new install/upgrade */
                                         if ($checkResult->toInstall === true) {
                                             if ($checkResult->outdated === true) {
                                                 $extList[$ext->name]['message'] = JText::_('JSN_SAMPLE_DATA_EXT_SELECT_UPDATE');
                                             } else {
                                                 $extList[$ext->name]['message'] = JText::_('JSN_SAMPLE_DATA_EXT_SELECT_NEW');
                                             }
                                         }
                                         if (isset($ext->extDep) && count($ext->extDep)) {
                                             $depList = array();
                                             foreach ($ext->extDep as $extDep) {
                                                 if (isset($installExts[$extDep])) {
                                                     $depInfo = $installExts[$extDep];
                                                     $resultDep = $sdHelperInstance->determineExtInstallation($depInfo);
                                                     if ($resultDep->toInstall === true) {
                                                         $extList[$ext->name]['depInstall'] = true;
                                                         $depList[$depInfo->name]['install'] = true;
                                                         $depList[$depInfo->name]['desc'] = $depInfo->description;
                                                         if ($resultDep->outdated === true) {
                                                             $depList[$depInfo->name]['message'] = JText::_('JSN_SAMPLE_DATA_EXT_SELECT_UPDATE');
                                                         } else {
                                                             $depList[$depInfo->name]['message'] = JText::_('JSN_SAMPLE_DATA_EXT_SELECT_NEW');
                                                         }
                                                     }
                                                 }
                                             }
                                             $extList[$ext->name]['deps'] = $depList;
                                         }
                                         /* Set a flag that there's at least one ext installation needed */
                                         if ($checkResult->toInstall === true || isset($extList[$ext->name]['deps']) && count($extList[$ext->name]['deps'])) {
                                             $hasInstallation = true;
                                         }
                                     }
                                     $ext->toInstall = $checkResult->toInstall;
                                     $ext->exist = $checkResult->exist;
                                     $ext->outdated = $checkResult->outdated;
                                     $ext->proEdition = $checkResult->proEdition;
                                     $extInfo[$ext->name] = $ext;
                                 } else {
                                     /* Temporarily force not install sample data for 3rd-party exts like EasyBlog */
                                     $failedExts[$ext->name]['exist'] = false;
                                     $failedExts[$ext->name]['message'] = '';
                                     /* Check 3rd-party exts' sample data need to be installed or not */
                                     // $extensionExists = $sdHelperInstance->checkExistingExtension($ext->name, $ext->type);
                                     // if ($ext->hasData == true)
                                     // {
                                     // 	if ($extensionExists === false)
                                     // 	{
                                     // 		$failedExts[$ext->name]['exist'] = $extensionExists;
                                     // 		$failedExts[$ext->name]['message'] = JText::sprintf('JSN_SAMPLE_DATA_3RD_EXT_NOT_INSTALLED', $ext->description);
                                     // 	}
                                     // 	else
                                     // 	{
                                     // 		$extManifestInfo = $xmlReaderInstance->getExtensionManifestFileInformation($ext->name, $ext->manifestPath);
                                     // 		if ($extManifestInfo['version'] != $ext->version)
                                     // 		{
                                     // 			$failedExts[$ext->name]['exist'] = $extensionExists;
                                     // 			$failedExts[$ext->name]['message'] = JText::sprintf('JSN_SAMPLE_DATA_EXT_OUTDATED_DETAIL', $ext->description, $ext->version);
                                     // 		}
                                     // 	}
                                     // }
                                 }
                             }
                         }
                         $sdHelperInstance->deleteSampleDataFolder($unpack);
                     }
                     if ($hasInstallation === false) {
                         $sdHelperInstance->determineFailedExtensions($failedExts, $extInfo);
                     }
                     $session->set($sdExtSesId, $extInfo, 'jsntemplatesession');
                     $session->set($sdExtFaiedSesId, $failedExts, 'jsntemplatesession');
                     $session->set($sdFileSesId, $result, 'jsntemplatesession');
                     echo json_encode(array('download' => true, 'sampleDataFile' => (string) $result, 'connection' => true, 'hasInstallation' => $hasInstallation, 'exts' => $extList));
                     return;
                 } else {
                     echo json_encode(array('download' => false, 'sampleDataFile' => '', 'message' => JText::_('JSN_SAMPLE_DATA_PACKAGE_FILE_NOT_FOUND'), 'connection' => true));
                     return;
                 }
             }
         } else {
             echo json_encode(array('download' => false, 'message' => JText::_('JSN_SAMPLE_DATA_DOWNLOAD_FAILED'), 'redirect_link' => $link, 'connection' => false));
             return;
         }
     } else {
         echo json_encode(array('download' => false, 'message' => JText::_('JSN_SAMPLE_DATA_TEMP_FOLDER_UNWRITABLE'), 'redirect_link' => $link, 'connection' => true));
         return;
     }
     return;
 }
 function JSNDownloadTemplatePackage($downloadURL, $packageName = '')
 {
     parent::JSNDownloadPackage($downloadURL, $packageName);
     $this->_objArchive = JArchive::getAdapter('zip');
 }