Exemplo n.º 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;
 }
Exemplo n.º 2
0
# Websites: http://www.joomlashine.com
# Technical Support:  Feedback - http://www.joomlashine.com/contact-us/get-support.html
# @license - GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
# @version $Id: jsn_installsampledata.php 14966 2012-08-11 04:19:46Z tuyetvt $
-------------------------------------------------------------------------*/
defined('_JEXEC') or die('Restricted access');
require_once 'includes' . DS . 'jsn_defines.php';
require_once 'includes' . DS . 'lib' . DS . 'jsn_utils.php';
require_once 'includes' . DS . 'lib' . DS . 'jsn_backup.php';
require_once 'includes' . DS . 'lib' . DS . 'jsn_readxmlfile.php';
require_once 'includes' . DS . 'lib' . DS . 'jsn_sampledata_helper.php';
global $error;
$obj_read_xml_file = new JSNReadXMLFile();
$obj_utils = new JSNUtils();
$obj_sampledata_helper = new JSNSampleDataHelper();
$obj_sampledata_helper->setSampleDataURL();
$backup_obj = JSNBackup::getInstance();
$template_manifest = $obj_read_xml_file->getTemplateManifestFileInformation();
$joomla_version = $obj_utils->getJoomlaVersion();
$folderWritable = $obj_sampledata_helper->checkFolderPermission();
//////////////////////////////////////MAIN//////////////////////////////////////
$folderFailList = '';
if (count($folderWritable) > 0) {
    $folderFailList = '<div id="jsn-li-folder-perm-failed">' . JText::_('JSN_SAMPLE_DATA_FOLDER_PERMISSION_MES') . '<ul>';
    foreach ($folderWritable as $failed) {
        $folderFailList .= '<li>' . $failed . '</li>';
    }
    $folderFailList .= '</ul>' . JText::_('JSN_SAMPLE_DATA_FOLDER_PERMISSION_MES2') . '<div class="jsn-install-admin-navigation"><hr class="jsn-horizontal-line" />' . '<button class="action-submit" type="button" id="jsn-perm-try-again" onclick="JSNSampleData.checkFolderPermission(\'' . strtolower($template_manifest['full_name']) . '\',\'' . JURI::root() . '\');">' . JText::_('JSN_SAMPLE_DATA_FOLDER_PERMISSION_TRY_AGAIN_BUTTON') . '</button></div></div>';
}
$frontIndexPath = JURI::root() . $obj_utils->determineFrontendIndex();
$strLiveDemoLink = 'http://demo.joomlashine.com/joomla-templates/' . $template_manifest['name'] . '/index.php';