Example #1
0
 function autoUpdateTemplate()
 {
     jimport('joomla.utilities.xmlelement');
     $session = JFactory::getSession();
     $login_identifier = md5('state_update_login_' . strtolower($this->_template_name));
     $state_login = $session->get($login_identifier, false, 'jsntemplatesession');
     $modified_file_identifier = md5('state_modified_file_' . strtolower($this->_template_name));
     $modified_files = $session->get($modified_file_identifier, array(), 'jsntemplatesession');
     $tmp_path = JPATH_ROOT . DS . 'tmp';
     if (!$state_login) {
         jexit('Invalid Token');
     }
     if ($this->_template_edition != '' && $this->_template_edition != 'free') {
         $edition = $this->_template_edition;
     } else {
         $edition = 'free';
     }
     if ($edition == 'free') {
         $templateNameParts = explode('_', strtolower($this->_template_name));
         $link = 'http://www.joomlashine.com/joomla-templates/' . $templateNameParts[0] . '-' . $templateNameParts[1] . '-download.html';
         $msg_manual_download = JText::sprintf('JSN_UPDATE_DOWNLOAD_FREE', $link);
     } else {
         $link = 'http://www.joomlashine.com/customer-area.html';
         $msg_manual_download = '<span class="jsn-red-message">Unable to download file</span>. Please try to <a href="http://www.joomlashine.com/customer-area.html" target="_blank" class="link-action">download file from Customer Area</a>, then select it:';
     }
     $package_name = JRequest::getCmd('package_name');
     $backup_file = JRequest::getCmd('backup_file');
     $package_path = $tmp_path . DS . $package_name;
     $obj_updater_helper = new JSNUpdaterHelper();
     $obj_auto_updater_helper = new JSNAutoUpdaterHelper();
     $unpack = $obj_auto_updater_helper->unpack($package_path);
     if ($unpack) {
         $files = $obj_updater_helper->compareChecksumFile($unpack['dir']);
         $installer = JSNInstaller::getInstance();
         $strXML = '';
         $tmpArray = array();
         $deleted_files = array();
         $new_manifest = $obj_updater_helper->findManifest($unpack['dir']);
         $tmp_new_version = $new_manifest->version;
         $new_version = $tmp_new_version->data();
         $old_version = $this->_template_version;
         $compare_version = $this->_obj_utils->compareVersion($new_version, $old_version);
         if ($compare_version == 0) {
             $tmpArray = array_merge($tmpArray, $modified_files);
         } else {
             if (isset($files['added'])) {
                 $tmpArray = array_merge($tmpArray, $files['added']);
             }
             if (isset($files['modified'])) {
                 $tmpArray = array_merge($tmpArray, $files['modified']);
             }
             if (isset($files['deleted'])) {
                 $deleted_files = $files['deleted'];
             }
         }
         if (isset($files['modified']) && count($files['modified']) && count($modified_files)) {
             foreach ($files['modified'] as $item1) {
                 foreach ($modified_files as $item2) {
                     if ($item1 == $item2) {
                         echo json_encode(array('update' => false, 'backup_file_name' => '', 'message' => '', 'manual' => false, 'redirect' => true));
                         return;
                     }
                 }
             }
         }
         $tmpArray = array_merge($tmpArray, array('template.checksum'));
         if (count($tmpArray)) {
             $strXML = '<?xml version="1.0" encoding="UTF-8" ?><extension><files>';
             foreach ($tmpArray as $value) {
                 $strXML .= '<filename>' . $value . '</filename>';
             }
             foreach ($files['modified'] as $value) {
                 $strXML .= '<filename>' . $value . '</filename>';
             }
             $strXML .= '</files></extension>';
         }
         if (!empty($strXML)) {
             $new_tmp_xml = new JXMLElement($strXML);
         } else {
             $new_tmp_xml = null;
         }
         if (!$installer->install($unpack['dir'], $new_tmp_xml, $deleted_files)) {
             echo json_encode(array('update' => false, 'backup_file_name' => '', 'message' => JText::sprintf('JSN_UPDATE_INSTALL_FAILED', $link), 'manual' => true, 'redirect' => false));
         } else {
             echo json_encode(array('update' => true, 'backup_file_name' => $backup_file, 'message' => '', 'manual' => false, 'redirect' => false));
         }
     } else {
         echo json_encode(array('update' => false, 'backup_file_name' => '', 'message' => JText::sprintf('JSN_UPDATE_UNPACK_FAILED', $link), 'manual' => true, 'redirect' => false));
     }
     $obj_updater_helper->destroySession();
     $obj_updater_helper->deleteInstallationPackage($unpack['packagefile'], $unpack['dir']);
     return;
 }
Example #2
0
/**
 * @author    JoomlaShine.com http://www.joomlashine.com
 * @copyright Copyright (C) 2008 - 2011 JoomlaShine.com. All rights reserved.
 * @license   GNU/GPL v2 http://www.gnu.org/licenses/gpl-2.0.html
 * @version   $Id: jsn_autoupdater.php 11613 2012-03-08 09:31:14Z hieudm $
 */
// No direct access
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_readxmlfile.php';
require_once 'includes' . DS . 'lib' . DS . 'jsn_auto_updater_helper.php';
$session = JFactory::getSession();
$obj_read_xml_file = new JSNReadXMLFile();
$obj_utils = new JSNUtils();
$obj_updater_helper = new JSNAutoUpdaterHelper();
$template_manifest = $obj_read_xml_file->getTemplateManifestFileInformation();
$manifest_cache = $obj_utils->getTemplateManifestCache();
$manifest_cache = json_decode($manifest_cache);
/* Determine front-end index path, including lang sef if available */
$frontIndexPath = JURI::root() . $obj_utils->determineFrontendIndex();
/* Form template identified_name */
$explodedName = explode('_', $template_manifest['name']);
$templateIdName = 'tpl_' . $explodedName[1];
/* Get template latest version from session if possible */
$templateVersionSesId = md5('template_version_' . strtolower($template_manifest['full_name']));
$versionFromSes = $session->get($templateVersionSesId, null, 'jsntemplatesession');
if (!is_null($versionFromSes)) {
    $latest_version = $versionFromSes;
} else {
    $latest_version = $obj_utils->getLatestProductVersion($templateIdName, 'template');