/**
  * Checking template version for auto update
  *
  * @return  void
  */
 public function checkUpdateAction()
 {
     $response = array();
     try {
         $templateVersion = JSNTplHelper::getTemplateVersion($this->template['name']);
         $templateInfo = JSNTplApiLightcart::getProductDetails('cat_template', $this->template['id']);
         $response['template'] = array('currentVersion' => $templateVersion, 'newVersion' => $templateInfo->version, 'hasUpdate' => version_compare($templateInfo->version, $templateVersion, '>'));
     } catch (Exception $ex) {
         $response['template'] = array('currentVersion' => $templateVersion, 'newVersion' => $templateVersion, 'hasUpdate' => false);
     }
     try {
         $frameworkInfo = JSNTplApiLightcart::getProductDetails('cat_template', JSN_TPLFRAMEWORK_ID);
         $response['framework'] = array('currentVersion' => JSN_TPLFRAMEWORK_VERSION, 'newVersion' => $frameworkInfo->version, 'hasUpdate' => version_compare($frameworkInfo->version, JSN_TPLFRAMEWORK_VERSION, '>'));
     } catch (Exception $ex) {
         $response['framework'] = array('currentVersion' => JSN_TPLFRAMEWORK_VERSION, 'newVersion' => JSN_TPLFRAMEWORK_VERSION, 'hasUpdate' => false);
     }
     $this->setResponse($response);
 }
Beispiel #2
0
/**
 * Autoload class file of JSN Template Framework.
 *
 * @param   string  $className  Name of class needs to be loaded.
 *
 * @return  boolean
 */
function jsn_template_framework_class_loader($className)
{
    if (strpos($className, 'JSNTpl') === 0) {
        $path = strtolower(preg_replace('/([A-Z])/', '/\\1', substr($className, 6)));
        $fullPath = JSN_PATH_TPLFRAMEWORK_LIBRARIES . '/' . $path;
        // Load alternative class for backward compatible with old template version
        $app = JFactory::getApplication();
        $tpl = $app->getTemplate();
        if ($app->isSite() and substr($tpl, 0, 4) == 'jsn_' and !JSNTplVersion::isCompatible($tpl, JSNTplHelper::getTemplateVersion($tpl))) {
            if (is_file("{$fullPath}_v1.php") and is_readable("{$fullPath}_v1.php")) {
                $fullPath .= '_v1';
            }
        }
        if (is_file("{$fullPath}.php") and is_readable("{$fullPath}.php")) {
            return include_once "{$fullPath}.php";
        }
        return false;
    }
}
Beispiel #3
0
 */
// No direct access
defined('_JEXEC') or die('Restricted index access');
// Load template framework
if (!defined('JSN_PATH_TPLFRAMEWORK')) {
    require_once JPATH_ROOT . '/plugins/system/jsntplframework/jsntplframework.defines.php';
    require_once JPATH_ROOT . '/plugins/system/jsntplframework/libraries/joomlashine/loader.php';
}
// Preparing template parameters
JSNTplTemplateHelper::prepare();
// Get template utilities
$jsnutils = JSNTplUtils::getInstance();
?>
<!DOCTYPE html>
<!-- <?php 
echo $this->template . ' ' . JSNTplHelper::getTemplateVersion($this->template);
?>
 -->
<html lang="<?php 
echo $this->language;
?>
" dir="<?php 
echo $this->direction;
?>
">
<head>
	<jdoc:include type="head" />
</head>
<body id="jsn-master" class="<?php 
echo $this->bodyClass;
?>
$template = JSNTplTemplateRecognization::detect($this->data->template);
// Prepare template name for link generation
$templateName = 'jsn-' . strtolower($template->name);
// Generate template introduction link
$templateLink = "http://www.joomlashine.com/joomla-templates/{$templateName}.html";
// Process template edition
$edition = $this->templateEdition->getEdition();
if ($edition == 'FREE') {
    $editionClass = 'jsn-free-edition';
} else {
    $editionClass = 'jsn-pro-edition';
}
// Get next template edition
$nextEdition = str_replace('PRO ', '', $this->templateEdition->getNextEdition());
// Get installed template version
$version = JSNTplHelper::getTemplateVersion($this->data->template);
?>
<div class="jsn-master"><div id="jsn-template-config" class="jsn-bootstrap <?php 
echo $wrapperClass;
?>
 <?php 
echo $editionClass;
?>
">
	<form action="" method="POST" name="adminForm" id="style-form">
		<input type="hidden" name="task" />
		<input type="hidden" name="customized" value="<?php 
echo @count($this->data->params) ? 'yes' : 'no';
?>
" />
		<?php 
Beispiel #5
0
 /**
  * Action to execute queries from sample data file
  *
  * @return  void
  */
 public function installDataAction()
 {
     try {
         // Create a backup of Joomla database
         $this->_backupDatabase();
         // Initialize variables
         $config = JFactory::getConfig();
         $tmpPath = $config->get('tmp_path');
         $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));
         $version = (string) $xml['version'];
         $joomla_ver = (string) $xml['joomla-version'];
         // Compare versions
         $templateVersion = JSNTplHelper::getTemplateVersion($this->template['name']);
         $joomlaVersion = new JVersion();
         if (version_compare($templateVersion, $version, '<')) {
             throw new Exception(JText::sprintf('JSN_TPLFW_ERROR_SAMPLE_DATA_OUT_OF_DATED', $templateVersion), 99);
         }
         if (!empty($joomla_ver) and version_compare($joomlaVersion->getShortVersion(), $joomla_ver, '<')) {
             throw new Exception(JText::sprintf('JSN_TPLFW_ERROR_JOOMLA_OUT_OF_DATE', $joomlaVersion->getShortVersion()), 99);
         }
         $thirdComponents = array();
         $thirdComponentErrors = array();
         // Looping to each extension type=component to get information and dependencies
         foreach ($xml->xpath('//extension[@author="3rd_party"]') as $component) {
             if (isset($component['author']) && $component['author'] == '3rd_party') {
                 $attrs = (array) $component->attributes();
                 $attrs = $attrs['@attributes'];
                 $componentType = (string) $attrs['type'];
                 $namePrefix = array('component' => 'com_', 'module' => 'mod_');
                 $componentName = isset($namePrefix[(string) $attrs['type']]) ? $namePrefix[$componentType] . $attrs['name'] : (string) $attrs['name'];
                 $state = $this->_getExtensionState($componentName, (string) $attrs['version'], true);
                 $thirdComponents[] = array('id' => $attrs['name'], 'state' => $state, 'full_name' => (string) $attrs['full_name'], 'version' => (string) $attrs['version'], 'type' => $componentType);
             }
         }
         if (count($thirdComponents)) {
             foreach ($thirdComponents as $thirdComponent) {
                 if ($thirdComponent['state'] == 'install') {
                     $thirdComponentErrors[] = JText::sprintf('JSN_TPLFW_ERROR_THIRD_EXTENSION_NOT_INSTALLED', strtoupper($thirdComponent['full_name']) . ' ' . $thirdComponent['type'], $thirdComponent['version']);
                 } elseif ($thirdComponent['state'] == 'update') {
                     $thirdComponentErrors[] = JText::sprintf('JSN_TPLFW_ERROR_THIRD_EXTENSION_NEED_TO_INSTALLED', strtoupper($thirdComponent['full_name']) . ' ' . $thirdComponent['type'], $thirdComponent['version']);
                 } elseif ($thirdComponent['state'] == 'unsupported') {
                     $thirdComponentErrors[] = JText::sprintf('JSN_TPLFW_ERROR_THIRD_EXTENSION_NOT_SUPPORTED', strtoupper($thirdComponent['full_name']) . ' ' . $thirdComponent['type'], $thirdComponent['version']);
                 } else {
                     //do nothing
                 }
             }
         }
         if (count($thirdComponentErrors)) {
             $strThirdComponentError = '<ul>';
             foreach ($thirdComponentErrors as $thirdComponentError) {
                 $strThirdComponentError .= '<li>' . $thirdComponentError . '</li>';
             }
             $strThirdComponentError .= '</ul>';
             throw new Exception(JText::sprintf('JSN_TPLFW_ERROR_THIRD_EXTENSION', $strThirdComponentError), 99);
         }
         // Temporary backup data
         $this->_backupThirdPartyModules();
         $this->_backupThirdPartyAdminModules();
         $this->_backupThirdPartyMenus();
         // Start transaction before manipulate database
         $this->dbo->transactionStart();
         // Delete admin modules
         $this->_deleteThirdPartyAdminModules();
         // Disable execution timeout
         if (!JSNTplHelper::isDisabledFunction('set_time_limit')) {
             set_time_limit(0);
         }
         $attentions = array();
         // Loop each extension to execute queries
         foreach ($xml->xpath('//extension') as $extension) {
             if (isset($extension['author']) && $extension['author'] == 'joomlashine') {
                 $extensionType = (string) $extension['type'];
                 $namePrefix = array('component' => 'com_', 'module' => 'mod_');
                 $extensionName = isset($namePrefix[(string) $extension['type']]) ? $namePrefix[$extensionType] . $extension['name'] : (string) $extension['name'];
                 // Check if JoomlaShine extension is installed
                 $canInstall = JSNTplHelper::isInstalledExtension($extensionName);
                 if ($canInstall == false and $extensionType == 'component') {
                     // Add to attention list when extension is not installed
                     $attentions[] = array('id' => (string) $extension['name'], 'name' => (string) $extension['description'], 'url' => (string) $extension['producturl']);
                 }
             } else {
                 $canInstall = true;
                 $extensionName = 'com_' . (string) $extension['name'];
             }
             if ($canInstall === true) {
                 // Get sample data queries
                 if ($queries = $extension->xpath("task[@name=\"dbinstall\"]/parameters/parameter") and @count($queries)) {
                     // Execute sample data queries
                     foreach ($queries as $query) {
                         // Find remote assets then download to local system
                         if (preg_match_all('#(http://demo.joomlashine.com/[^\\s\\t\\r\\n]+/media/joomlashine/)[^\\s\\t\\r\\n]+\\.(js|css|bmp|gif|ico|jpg|png|svg|ttf|otf|eot|woff)#', $query, $matches, PREG_SET_ORDER)) {
                             foreach ($matches as $match) {
                                 $keepAsIs = false;
                                 if (!isset($this->mediaFolder)) {
                                     // Detect a writable folder to store demo assets
                                     foreach (array('media', 'cache', 'tmp') as $folder) {
                                         $folder = JPATH_ROOT . "/{$folder}";
                                         if (is_dir($folder) and is_writable($folder) and JFolder::create("{$folder}/joomlashine")) {
                                             $this->mediaFolder = "{$folder}/joomlashine";
                                             break;
                                         }
                                     }
                                 }
                                 if (isset($this->mediaFolder)) {
                                     // Generate path to store demo asset
                                     $mediaFile = str_replace($match[1], "{$this->mediaFolder}/", $match[0]);
                                     // Download demo asset only once
                                     if (!is_file($mediaFile)) {
                                         try {
                                             JSNTplHttpRequest::get($match[0], $mediaFile);
                                         } catch (Exception $e) {
                                             $keepAsIs = true;
                                         }
                                     }
                                     // Alter sample data query
                                     if (!$keepAsIs) {
                                         $query = str_replace($match[0], str_replace(JPATH_ROOT . '/', '', $mediaFile), $query);
                                     }
                                 }
                             }
                         }
                         // Execute query
                         $this->dbo->setQuery((string) $query);
                         if (!$this->dbo->{$this->queryMethod}()) {
                             throw new Exception($this->dbo->getErrorMsg());
                         }
                     }
                 }
             }
         }
         // Restore backed up data
         $this->_restoreThirdPartyData();
         $this->_rebuildMenus();
         // Disable default template
         $q = $this->dbo->getQuery(true);
         $q->update('#__template_styles');
         $q->set('home = 0');
         $q->where('client_id = 0');
         $q->where('home = 1');
         $this->dbo->setQuery($q);
         if (!$this->dbo->{$this->queryMethod}()) {
             throw new Exception($this->dbo->getErrorMsg());
         }
         // Set installed template the default one
         $q = $this->dbo->getQuery(true);
         $q->update('#__template_styles');
         $q->set('home = 1');
         $q->where('id = ' . (int) $this->request->getInt('styleId'));
         $this->dbo->setQuery($q);
         if (!$this->dbo->{$this->queryMethod}()) {
             throw new Exception($this->dbo->getErrorMsg());
         }
         // Commit database change
         $this->dbo->transactionCommit();
         // Clean up temporary data
         JInstallerHelper::cleanupInstall("{$tmpPath}/{$this->template['name']}_sampledata.zip", "{$tmpPath}/{$this->template['name']}_sampledata");
         // Clean up assets table for extension that is not installed
         if (count($attentions)) {
             foreach ($attentions as $attention) {
                 $this->_cleanExtensionAssets('com_' . $attention['id']);
             }
         }
         // Set final response
         $this->setResponse(array('attention' => $attentions));
     } catch (Exception $e) {
         throw $e;
     }
 }
 /**
  * Preparing template parameters for the template
  *
  * @return  void
  */
 private function _prepare($loadTemplateCSS, $loadTemplateJS)
 {
     $this->_loadTemplateCSS = $loadTemplateCSS;
     $this->_loadTemplateJS = $loadTemplateJS;
     $templateParams = isset($this->_document->params) ? $this->_document->params : null;
     $templateName = isset($this->_document->template) ? $this->_document->template : null;
     if (empty($templateParams) or empty($templateName) or $templateName == 'system') {
         $templateDetails = JFactory::getApplication()->getTemplate(true);
         $templateParams = $templateDetails->params;
         $templateName = $templateDetails->template;
     }
     // Update show content on frontpage parameter
     $app = JFactory::getApplication();
     $menu = $app->getMenu()->getActive();
     $lang = JFactory::getLanguage();
     $lang->load('plg_system_jsntplframework', JPATH_ADMINISTRATOR);
     $manifest = JSNTplHelper::getManifest($templateName);
     $this->_document->app = JFactory::getApplication();
     $this->_document->template = $templateName;
     $this->_document->version = JSNTplHelper::getTemplateVersion($templateName);
     $this->_document->isFree = !isset($manifest->edition) || $manifest->edition == 'FREE';
     $this->_document->uri = JFactory::getUri();
     $this->_document->rootUrl = $this->_document->uri->root(true);
     $this->_document->templateUrl = $this->_document->rootUrl . '/templates/' . $this->_document->template;
     $columns = array('columnPromoLeft', 'columnPromoRight', 'columnLeft', 'columnRight', 'columnInnerleft', 'columnInnerright');
     // Find customizable columns
     $customColumns = $manifest->xpath('//fieldset[@name="jsn-columns-size"]');
     if (count($customColumns) > 0) {
         $columns = array();
         foreach (end($customColumns)->children() as $column) {
             $columns[] = (string) $column['name'];
         }
     }
     // Add columns to overriable parameter list
     foreach ($columns as $column) {
         $className = $column;
         if (strpos($column, 'column') === 0) {
             $className = substr($column, 6);
         }
         $this->_overrideAttributes[strtolower($className . 'width')] = array('type' => 'integer', 'name' => $column);
     }
     // Load template parameters
     $params = $this->loadParams($templateParams->toArray(), $templateName, true);
     // Detect browser information
     $this->_document->browserInfo = JSNTplUtils::getInstance()->getBrowserInfo();
     $this->_document->isIE = @$this->_document->browserInfo['browser'] == 'msie';
     $this->_document->isIE7 = @$this->_document->browserInfo['browser'] == 'msie' && (int) @$this->_document->browserInfo['version'] == 7;
     // Custom direction from url parameter
     $direction = JFactory::getApplication()->input->getCmd('jsn_setdirection', $this->_document->direction);
     $this->_document->direction = $direction;
     // Apply custom params
     $params = $this->_overrideCustomParams($params);
     $params['showFrontpage'] = is_object($menu) && $menu->home == 1 ? $params['showFrontpage'] == 1 : true;
     if ($this->_document->isFree === true) {
         $params['mobileSupport'] = false;
         $params['useCSS3Effect'] = false;
     }
     // Prepare logo parameter
     if ($params['logoColored']) {
         $params['logoFile'] = "templates/{$templateName}/images/colors/{$params['templateColor']}/logo.png";
     }
     if ($params['mobileSupport'] == false) {
         $params['desktopSwitcher'] = false;
     }
     if (!preg_match('/^[a-zA-Z]+:\\/\\//i', $params['logoFile'])) {
         $params['logoFile'] = JUri::root(true) . '/' . $params['logoFile'];
     }
     // Prepare color variation to show in site tool
     if ($params['colorSelector'] and !@count($params['sitetoolsColorsItems'])) {
         $params['sitetoolsColorsItems'] = $manifest->xpath('//*[@name="sitetoolsColors"]/option');
         if (!$params['sitetoolsColorsItems'] or !@count($params['sitetoolsColorsItems'])) {
             $xml = simplexml_load_file(JSN_PATH_TPLFRAMEWORK . '/libraries/joomlashine/template/params.xml');
             $params['sitetoolsColorsItems'] = $xml->xpath('//*[@name="sitetoolsColors"]/option');
         }
         foreach ($params['sitetoolsColorsItems'] as &$color) {
             $color = (string) $color['value'];
         }
     }
     // Prepare Google Analytics code
     $params['codeAnalytic'] = trim($params['codeAnalytic']);
     if (!empty($params['codeAnalytic'])) {
         if (strpos($params['codeAnalytic'], '<script') === false) {
             $params['codeAnalytic'] = '<script type="text/javascript">' . $params['codeAnalytic'];
         }
         if (strpos($params['codeAnalytic'], '</script>') === false) {
             $params['codeAnalytic'] = $params['codeAnalytic'] . '</script>';
         }
     }
     // Binding parameters to document object
     $this->_document->params = new JRegistry();
     foreach ($params as $key => $value) {
         $this->_document->params->set($key, $value);
         $this->_document->{$key} = $value;
     }
     // Assign helper object
     $this->_document->helper = $this;
     $this->_document->attributes = $this->_overrideAttributes;
     $this->_document->templatePrefix = $this->_document->template . '_';
     // Prepare body class
     $this->_prepareBodyClass();
     // Prepare template styles
     $this->_prepareHead();
 }
Beispiel #7
0
 /**
  * Action to execute queries from sample data file
  *
  * @return  void
  */
 public function installDataAction()
 {
     // Disable execution timeout
     if (!JSNTplHelper::isDisabledFunction('set_time_limit')) {
         set_time_limit(0);
     }
     try {
         // Create a backup of Joomla database
         $this->_backupDatabase();
         // Initialize variables
         if (!isset($this->temporary_path) || empty($this->temporary_path)) {
             $config = JFactory::getConfig();
             $this->temporary_path = $config->get('tmp_path') . "/{$this->template['name']}_sampledata.zip";
             $this->temporary_path = pathinfo($this->temporary_path, PATHINFO_DIRNAME) . '/' . pathinfo($this->temporary_path, PATHINFO_FILENAME);
             JPath::clean($this->temporary_path);
         }
         $xmlFiles = glob("{$this->temporary_path}/*.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));
         $version = (string) $xml['version'];
         $joomla_ver = (string) $xml['joomla-version'];
         // Compare versions
         $templateVersion = JSNTplHelper::getTemplateVersion($this->template['name']);
         $joomlaVersion = new JVersion();
         if (version_compare($templateVersion, $version, '<')) {
             throw new Exception(JText::sprintf('JSN_TPLFW_ERROR_SAMPLE_DATA_OUT_OF_DATED', $templateVersion), 99);
         }
         if (!empty($joomla_ver) and version_compare($joomlaVersion->getShortVersion(), $joomla_ver, '<')) {
             throw new Exception(JText::sprintf('JSN_TPLFW_ERROR_JOOMLA_OUT_OF_DATE', $joomlaVersion->getShortVersion()), 99);
         }
         $thirdComponents = array();
         $thirdComponentErrors = array();
         // Looping to each extension type=component to get information and dependencies
         foreach ($xml->xpath('//extension[@author="3rd_party"]') as $component) {
             if (isset($component['author']) && $component['author'] == '3rd_party') {
                 $attrs = (array) $component->attributes();
                 $attrs = $attrs['@attributes'];
                 $componentType = (string) $attrs['type'];
                 $namePrefix = array('component' => 'com_', 'module' => 'mod_');
                 $componentName = isset($namePrefix[(string) $attrs['type']]) ? $namePrefix[$componentType] . $attrs['name'] : (string) $attrs['name'];
                 $state = $this->_getExtensionState($componentName, (string) $attrs['version'], true, (string) $attrs['type']);
                 $thirdComponents[] = array('id' => $attrs['name'], 'state' => $state, 'full_name' => (string) $attrs['full_name'], 'version' => (string) $attrs['version'], 'type' => $componentType);
             }
         }
         if (count($thirdComponents)) {
             foreach ($thirdComponents as $thirdComponent) {
                 if ($thirdComponent['state'] == 'install') {
                     $thirdComponentErrors[] = JText::sprintf('JSN_TPLFW_ERROR_THIRD_EXTENSION_NOT_INSTALLED', strtoupper($thirdComponent['full_name']) . ' ' . $thirdComponent['type'], $thirdComponent['version']);
                 } elseif ($thirdComponent['state'] == 'update') {
                     $thirdComponentErrors[] = JText::sprintf('JSN_TPLFW_ERROR_THIRD_EXTENSION_NEED_TO_INSTALLED', strtoupper($thirdComponent['full_name']) . ' ' . $thirdComponent['type'], $thirdComponent['version']);
                 } elseif ($thirdComponent['state'] == 'unsupported') {
                     $thirdComponentErrors[] = JText::sprintf('JSN_TPLFW_ERROR_THIRD_EXTENSION_NOT_SUPPORTED', strtoupper($thirdComponent['full_name']) . ' ' . $thirdComponent['type'], $thirdComponent['version']);
                 } else {
                     //do nothing
                 }
             }
         }
         if (count($thirdComponentErrors)) {
             $strThirdComponentError = '<ul>';
             foreach ($thirdComponentErrors as $thirdComponentError) {
                 $strThirdComponentError .= '<li>' . $thirdComponentError . '</li>';
             }
             $strThirdComponentError .= '</ul>';
             throw new Exception(JText::sprintf('JSN_TPLFW_ERROR_THIRD_EXTENSION', $strThirdComponentError), 99);
         }
         // Temporary backup data
         $this->_backupThirdPartyModules();
         $this->_backupThirdPartyAdminModules();
         $this->_backupThirdPartyMenus();
         // Delete admin modules
         $this->_deleteThirdPartyAdminModules();
         // Loop each extension to execute queries
         $attentions = array();
         foreach ($xml->xpath('//extension') as $extension) {
             // Get sample data queries.
             $queries = $extension->xpath('task[@name="dbinstall"]/parameters/parameter');
             // Verify extension.
             $canInstall = true;
             $extensionType = (string) $extension['type'];
             $namePrefix = array('component' => 'com_', 'module' => 'mod_');
             $extensionName = isset($namePrefix[(string) $extension['type']]) ? $namePrefix[$extensionType] . $extension['name'] : (string) $extension['name'];
             if (isset($extension['author']) && $extension['author'] == 'joomlashine') {
                 // Check if JoomlaShine extension is installed
                 $canInstall = JSNTplHelper::isInstalledExtension($extensionName, $extensionType);
                 if ($canInstall == false and $extensionType == 'component') {
                     // Add to attention list when extension is not installed
                     $attentions[] = array('id' => (string) $extension['name'], 'name' => (string) $extension['description'], 'url' => (string) $extension['producturl']);
                 }
             } elseif ($extension['type'] == 'component') {
                 // Check if 3rd-party component is installed.
                 $canInstall = JSNTplHelper::isInstalledExtension($extensionName);
                 if (!$canInstall) {
                     // Add to attention list.
                     $attentions[] = array('id' => (string) $extension['name'], 'name' => (string) $extension['title'], 'modules' => $extension->xpath('modules/module'), 'plugins' => $extension->xpath('plugins/plugin'), 'display' => count($queries) ? true : false);
                 } else {
                     // Verify version of the installed 3rd-party component.
                     $state = $this->_getExtensionState($extensionName, (string) $extension['version'], true);
                     if ('update' == $state) {
                         // Add to attention list.
                         $attentions[] = array('id' => (string) $extension['name'], 'name' => (string) $extension['title'], 'modules' => $extension->xpath('modules/module'), 'plugins' => $extension->xpath('plugins/plugin'), 'message' => JText::sprintf('JSN_TPLFW_UPDATE_3RD_PARTY_EXTENSION_FIRST', $this->_getExtensionVersion($extensionName), (string) $extension['version']), 'display' => count($queries) ? true : false);
                         $canInstall = false;
                     } elseif ('unsupported' == $state) {
                         // Add to attention list.
                         $attentions[] = array('id' => (string) $extension['name'], 'name' => (string) $extension['title'], 'modules' => $extension->xpath('modules/module'), 'plugins' => $extension->xpath('plugins/plugin'), 'message' => JText::sprintf('JSN_TPLFW_UNSUPPORTED_3RD_PARTY_EXTENSION_VERSION', $this->_getExtensionVersion($extensionName), (string) $extension['version']), 'display' => count($queries) ? true : false);
                         $canInstall = false;
                     } else {
                         // Make sure all required modules are installed also.
                         $missing = array();
                         foreach ($extension->xpath('modules/module') as $module) {
                             if (!@is_dir(JPATH_ROOT . '/modules/' . (string) $module)) {
                                 if ((string) $module['title'] != '') {
                                     $missing[] = (string) $module['title'];
                                 }
                             }
                         }
                         foreach ($extension->xpath('plugins/plugin') as $plugin) {
                             if (!@is_dir(JPATH_ROOT . '/plugins/' . (string) $plugin['group'] . '/' . (string) $plugin)) {
                                 if ((string) $plugin['title'] != '') {
                                     $missing[] = (string) $plugin['title'];
                                 }
                             }
                         }
                         if (count($missing)) {
                             // Add to attention list.
                             $attentions[] = array('id' => (string) $extension['name'], 'name' => (string) $extension['title'], 'modules' => $extension->xpath('modules/module'), 'plugins' => $extension->xpath('plugins/plugin'), 'missing' => $missing, 'message' => JText::_('JSN_TPLFW_MISSING_3RD_PARTY_EXTENSION_DEPENDENCIES'), 'display' => count($queries) ? true : false);
                             $canInstall = false;
                         }
                     }
                 }
             }
             if ($canInstall) {
                 // Execute sample data queries
                 foreach ($queries as $query) {
                     // Find remote assets then download to local system
                     if (preg_match_all('#(http://demo.joomlashine.com/[^\\s\\t\\r\\n]+/media/joomlashine/)[^\\s\\t\\r\\n]+\\.(js|css|bmp|gif|ico|jpg|png|svg|ttf|otf|eot|woff)#', $query, $matches, PREG_SET_ORDER)) {
                         foreach ($matches as $match) {
                             $keepAsIs = false;
                             if (!isset($this->mediaFolder)) {
                                 // Detect a writable folder to store demo assets
                                 foreach (array('media', 'cache', 'tmp') as $folder) {
                                     $folder = JPATH_ROOT . "/{$folder}";
                                     if (is_dir($folder) and is_writable($folder) and JFolder::create("{$folder}/joomlashine")) {
                                         $this->mediaFolder = "{$folder}/joomlashine";
                                         break;
                                     }
                                 }
                             }
                             if (isset($this->mediaFolder)) {
                                 // Generate path to store demo asset
                                 $mediaFile = str_replace($match[1], "{$this->mediaFolder}/", $match[0]);
                                 // Download demo asset only once
                                 if (!is_file($mediaFile)) {
                                     try {
                                         JSNTplHttpRequest::get($match[0], $mediaFile);
                                     } catch (Exception $e) {
                                         $keepAsIs = true;
                                     }
                                 }
                                 // Alter sample data query
                                 if (!$keepAsIs) {
                                     $query = str_replace($match[0], str_replace(JPATH_ROOT . '/', '', $mediaFile), $query);
                                 }
                             }
                         }
                     }
                     // Execute query
                     $this->dbo->setQuery((string) $query);
                     if (!$this->dbo->{$this->queryMethod}()) {
                         throw new Exception($this->dbo->getErrorMsg());
                     }
                 }
                 // Update component ID for linked menu items.
                 if ($extension['type'] == 'component') {
                     // Get component ID.
                     $query = $this->dbo->getQuery(true);
                     $query->select('extension_id')->from('#__extensions')->where('type = ' . $query->quote('component'))->where('element = ' . $query->quote($extensionName));
                     $this->dbo->setQuery($query);
                     $component_id = $this->dbo->loadResult();
                     // Update component ID for all menu items that link to this component.
                     $query = $this->dbo->getQuery(true);
                     $query->update('#__menu')->set('component_id = ' . $query->quote($component_id))->where('type = ' . $query->quote('component'))->where("link LIKE 'index.php?option={$extensionName}&%'");
                     $this->dbo->setQuery($query);
                     if (!$this->dbo->{$this->queryMethod}()) {
                         throw new Exception($this->dbo->getErrorMsg());
                     }
                 }
                 // Copy images if has.
                 if (isset($extension['images']) && @is_dir($this->temporary_path . '/' . (string) $extension['images'])) {
                     // Backup existing folder.
                     JFolder::move(JPATH_ROOT . '/' . (string) $extension['images'], JPATH_ROOT . '/' . (string) $extension['images'] . '-backup-at-' . date('y-m-d_H-i-s'));
                     // Delete current folder.
                     JFolder::delete(JPATH_ROOT . '/' . (string) $extension['images']);
                     // Move sample images folder.
                     JFolder::move($this->temporary_path . '/' . (string) $extension['images'], JPATH_ROOT . '/' . (string) $extension['images']);
                 }
                 // Download and install extended style if has.
                 if (isset($extension['ext-style-package'])) {
                     // Download extended style package.
                     $template = JSNTplTemplateRecognization::detect($this->template['name']);
                     $fileUrl = 'http://www.joomlashine.com/index.php?option=com_lightcart&controller=remoteconnectauthentication' . '&task=authenticate&tmpl=component&upgrade=yes&identified_name=ext_style&edition=' . '&joomla_version=' . JSNTplHelper::getJoomlaVersion(2) . '&file_attr=' . '{"identified_template_name":"tpl_' . strtolower($template->name) . '"' . ',"ext_style":"' . (string) $extension['ext-style-package'] . '"}';
                     // Download file to temporary folder.
                     try {
                         $response = JSNTplHttpRequest::get($fileUrl, $this->temporary_path . '/' . (string) $extension['ext-style-package'] . '_ext_style.zip');
                     } catch (Exception $e) {
                         throw $e;
                     }
                     // Check download response headers.
                     if ($response['header']['content-type'] != 'application/zip') {
                         throw new Exception(JText::_('JSN_TPLFW_ERROR_DOWNLOAD_CANNOT_LOCATED_FILE'));
                     }
                     // Install extended style.
                     JArchive::extract($this->temporary_path . '/' . (string) $extension['ext-style-package'] . '_ext_style.zip', JPATH_ROOT . '/' . (string) $extension['ext-style-path']);
                     // Fix for old extended style package of OS Property.
                     if (false !== strpos((string) $extension['ext-style-path'], '/com_osproperty/')) {
                         $template = 'jsn_' . strtolower($template->name);
                         if (@file_exists(JPATH_ROOT . '/' . (string) $extension['ext-style-path'] . "/{$template}/template.xml")) {
                             JFile::copy(JPATH_ROOT . '/' . (string) $extension['ext-style-path'] . "/{$template}/template.xml", JPATH_ROOT . '/' . (string) $extension['ext-style-path'] . "/{$template}/{$template}.xml");
                         }
                     }
                 }
                 // Manipulate data for K2.
                 if ('com_k2' == $extensionName) {
                     // Update user mapping for K2 items table.
                     $user = JFactory::getUser();
                     $query = $this->dbo->getQuery(true);
                     $query->update('#__k2_items')->set('created_by = ' . $query->quote($user->id));
                     $this->dbo->setQuery($query);
                     if (!$this->dbo->{$this->queryMethod}()) {
                         throw new Exception($this->dbo->getErrorMsg());
                     }
                     // Update user mapping for K2 users table.
                     $query = $this->dbo->getQuery(true);
                     $query->update('#__k2_users')->set('userID = ' . $query->quote($user->id));
                     $this->dbo->setQuery($query);
                     if (!$this->dbo->{$this->queryMethod}()) {
                         throw new Exception($this->dbo->getErrorMsg());
                     }
                 }
                 // Manipulate data for OS Property.
                 if ('com_osproperty' == $extensionName) {
                     // Update user mapping for agents table.
                     $user = JFactory::getUser();
                     $query = $this->dbo->getQuery(true);
                     $query->update('#__osrs_agents')->set('user_id = ' . $query->quote($user->id));
                     $this->dbo->setQuery($query);
                     if (!$this->dbo->{$this->queryMethod}()) {
                         throw new Exception($this->dbo->getErrorMsg());
                     }
                 }
                 // Unpublish menu item replacement published before.
                 if (isset($extension['menu-replacement'])) {
                     $items = array_map('intval', explode(',', (string) $extension['menu-replacement']));
                     $query = $this->dbo->getQuery(true);
                     $query->update('#__menu')->set('published = 0')->where('id IN (' . implode(', ', $items) . ')')->where('published = 1');
                     $this->dbo->setQuery($query);
                     if (!$this->dbo->{$this->queryMethod}()) {
                         throw new Exception($this->dbo->getErrorMsg());
                     }
                 }
                 // Unpublish module replacement published before.
                 if (isset($extension['module-replacement'])) {
                     $items = array_map('intval', explode(',', (string) $extension['module-replacement']));
                     $query = $this->dbo->getQuery(true);
                     $query->update('#__modules')->set('published = 0')->where('id IN (' . implode(', ', $items) . ')')->where('published = 1');
                     $this->dbo->setQuery($query);
                     if (!$this->dbo->{$this->queryMethod}()) {
                         throw new Exception($this->dbo->getErrorMsg());
                     }
                 }
             } else {
                 // Check if sample data contains menu item replacement for use when extension is missing.
                 if (isset($extension['menu-replacement'])) {
                     if (isset($menu_replacement)) {
                         $menu_replacement = array_merge($menu_replacement, array_map('intval', explode(',', (string) $extension['menu-replacement'])));
                     } else {
                         $menu_replacement = array_map('intval', explode(',', (string) $extension['menu-replacement']));
                     }
                 }
                 // Check if sample data contains module replacement for use when extension is missing.
                 if (isset($extension['module-replacement'])) {
                     if (isset($module_replacement)) {
                         $module_replacement = array_merge($module_replacement, array_map('intval', explode(',', (string) $extension['module-replacement'])));
                     } else {
                         $module_replacement = array_map('intval', explode(',', (string) $extension['module-replacement']));
                     }
                 }
             }
         }
         // Disable default template
         $query = $this->dbo->getQuery(true);
         $query->update('#__template_styles');
         $query->set('home = 0');
         $query->where('client_id = 0');
         $query->where('home = 1');
         $this->dbo->setQuery($query);
         if (!$this->dbo->{$this->queryMethod}()) {
             throw new Exception($this->dbo->getErrorMsg());
         }
         // Set installed template the default one
         $query = $this->dbo->getQuery(true);
         $query->update('#__template_styles');
         $query->set('home = 1');
         $query->where('id = ' . (int) $this->request->getInt('styleId'));
         $this->dbo->setQuery($query);
         if (!$this->dbo->{$this->queryMethod}()) {
             throw new Exception($this->dbo->getErrorMsg());
         }
         // Publish menu item replacement.
         if (isset($menu_replacement)) {
             $query = $this->dbo->getQuery(true);
             $query->update('#__menu')->set('published = 1')->where('id IN (' . implode(', ', $menu_replacement) . ')');
             $this->dbo->setQuery($query);
             if (!$this->dbo->{$this->queryMethod}()) {
                 throw new Exception($this->dbo->getErrorMsg());
             }
         }
         // Publish module replacement.
         if (isset($module_replacement)) {
             $query = $this->dbo->getQuery(true);
             $query->update('#__modules')->set('published = 1')->where('id IN (' . implode(', ', $module_replacement) . ')');
             $this->dbo->setQuery($query);
             if (!$this->dbo->{$this->queryMethod}()) {
                 throw new Exception($this->dbo->getErrorMsg());
             }
         }
     } catch (Exception $e) {
         $error = $e;
     }
     // Restore backed up data
     $this->_restoreThirdPartyData();
     $this->_rebuildMenus();
     // Clean up temporary data
     JInstallerHelper::cleanupInstall("{$this->temporary_path}.zip", $this->temporary_path);
     // Clean up junk data for extension that is not installed
     if (count($attentions)) {
         foreach ($attentions as $i => $attention) {
             // Clean up junk data imported during sample data installation.
             $this->_cleanJunkData('com_' . $attention['id'], isset($attention['modules']) ? $attention['modules'] : null, isset($attention['plugins']) ? $attention['plugins'] : null);
             // Make sure extension has name defined.
             if (!isset($attention['name']) || empty($attention['name'])) {
                 unset($attentions[$i]);
             } elseif (isset($attention['display']) && !$attention['display']) {
                 unset($attentions[$i]);
             } else {
                 // Remove data that are not necessary any more.
                 if (isset($attention['modules'])) {
                     unset($attentions[$i]['modules']);
                 }
                 if (isset($attention['plugins'])) {
                     unset($attentions[$i]['plugins']);
                 }
             }
         }
     }
     // Check if there is any error catched?
     if (isset($error)) {
         throw $error;
     }
     // Set final response
     $this->setResponse(array('attention' => array_values($attentions)));
 }
Beispiel #8
0
 /**
  * Preparing template parameters for the template
  *
  * @return  void
  */
 private function _prepare($loadTemplateCSS, $loadTemplateJS)
 {
     $this->_loadTemplateCSS = $loadTemplateCSS;
     $this->_loadTemplateJS = $loadTemplateJS;
     $templateParams = isset($this->_document->params) ? $this->_document->params : null;
     $templateName = isset($this->_document->template) ? $this->_document->template : null;
     if (empty($templateParams) or empty($templateName) or $templateName == 'system') {
         $templateDetails = JFactory::getApplication()->getTemplate(true);
         $templateParams = $templateDetails->params;
         $templateName = $templateDetails->template;
     }
     // Get template information
     $this->_template = JSNTplTemplateRecognization::detect($templateName);
     // Update show content on frontpage parameter
     $app = JFactory::getApplication();
     $menu = $app->getMenu()->getActive();
     $lang = JFactory::getLanguage();
     $lang->load('plg_system_jsntplframework', JPATH_ADMINISTRATOR);
     $manifest = JSNTplHelper::getManifest($templateName);
     $this->_document->app = JFactory::getApplication();
     $this->_document->template = $templateName;
     $this->_document->version = JSNTplHelper::getTemplateVersion($templateName);
     $this->_document->isFree = empty($manifest->edition) || $manifest->edition == 'FREE';
     $this->_document->uri = JFactory::getUri();
     $this->_document->rootUrl = $this->_document->uri->root(true);
     $this->_document->templateUrl = $this->_document->rootUrl . '/templates/' . $this->_document->template;
     $columns = array('columnPromoLeft', 'columnPromoRight', 'columnLeft', 'columnRight', 'columnInnerleft', 'columnInnerright');
     // Find customizable columns
     $customColumns = $manifest->xpath('//fieldset[@name="jsn-columns-size"]');
     if (count($customColumns) > 0) {
         $columns = array();
         foreach (end($customColumns)->children() as $column) {
             $columns[] = (string) $column['name'];
         }
     }
     // Add columns to overriable parameter list
     foreach ($columns as $column) {
         $className = $column;
         if (strpos($column, 'column') === 0) {
             $className = substr($column, 6);
         }
         $this->_overrideAttributes[strtolower($className . 'width')] = array('type' => 'string', 'name' => $column);
     }
     // Load template parameters
     $params = $this->loadParams($templateParams->toArray(), $templateName, true);
     // Detect browser information
     $this->_document->browserInfo = JSNTplUtils::getInstance()->getBrowserInfo();
     $this->_document->isIE = @$this->_document->browserInfo['browser'] == 'msie';
     $this->_document->isIE7 = @$this->_document->browserInfo['browser'] == 'msie' && (int) @$this->_document->browserInfo['version'] == 7;
     // Custom direction from url parameter
     $direction = JFactory::getApplication()->input->getCmd('jsn_setdirection', $this->_document->direction);
     $this->_document->direction = $direction;
     // Apply custom params
     $params = $this->_overrideCustomParams($params);
     $params['showFrontpage'] = is_object($menu) && $menu->home == 1 ? $params['showFrontpage'] == 1 : true;
     // Prepare logo parameter
     if ($params['logoColored']) {
         $params['logoFile'] = "templates/{$templateName}/images/colors/{$params['templateColor']}/logo.png";
     }
     if (!empty($params['logoFile']) and !preg_match('/^[a-zA-Z]+:\\/\\//i', $params['logoFile'])) {
         $params['logoFile'] = JUri::root(true) . '/' . $params['logoFile'];
     }
     // Prepare color variation to show in site tool
     if (!isset($params['sitetoolsColorsItems']) and $colorSettings = json_decode($params['sitetoolsColors'])) {
         if (!count($colorSettings->colors)) {
             $params['sitetoolsColorsItems'] = array();
         }
     }
     if ($params['sitetoolsColors'] and !isset($params['sitetoolsColorsItems'])) {
         $params['sitetoolsColorsItems'] = $manifest->xpath('//*[@name="sitetoolsColors"]/option');
         if (!$params['sitetoolsColorsItems'] or !@count($params['sitetoolsColorsItems'])) {
             $xml = simplexml_load_file(JSN_PATH_TPLFRAMEWORK . '/libraries/joomlashine/template/params.xml');
             $params['sitetoolsColorsItems'] = $xml->xpath('//*[@name="sitetoolsColors"]/option');
         }
         if ($params['sitetoolsColorsItems']) {
             foreach ($params['sitetoolsColorsItems'] as &$color) {
                 $color = (string) $color['value'];
             }
         }
         $params['sitetoolsColorsItems'] != false or $params['sitetoolsColorsItems'] = array();
     }
     $params['colorSelector'] = count($params['sitetoolsColorsItems']) ? true : false;
     // Check if site tools has tool to show
     if ($params['sitetoolStyle']) {
         $visible = count($params['sitetoolsColorsItems']);
         if (!$visible) {
             $params['sitetoolStyle'] = false;
         }
     }
     // Prepare Google Analytics code
     $params['codeAnalytic'] = trim($params['codeAnalytic']);
     if (!empty($params['codeAnalytic'])) {
         if (strpos($params['codeAnalytic'], '<script') === false) {
             $params['codeAnalytic'] = '<script type="text/javascript">' . $params['codeAnalytic'];
         }
         if (strpos($params['codeAnalytic'], '</script>') === false) {
             $params['codeAnalytic'] = $params['codeAnalytic'] . '</script>';
         }
     }
     // Check if user specified custom width for any column
     foreach ($columns as $column) {
         if (isset($params[$column])) {
             // Re-generate column name
             $columnName = str_replace('column-', '', strtolower(preg_replace('/([A-Z])/', '-\\1', $column)));
             foreach (array('promoColumns', 'mainColumns', 'contentColumns') as $row) {
                 foreach ($params[$row] as $id => $class) {
                     // Re-fine ID
                     $realId = preg_replace('/^\\d+:/', '', $id);
                     if (str_replace('-', '', $realId) == str_replace('-', '', $columnName)) {
                         if (strcasecmp(substr($params[$column], 0, 4), 'span') != 0) {
                             // Convert framework v1 value type to compatible with framework v2
                             $span = round($params[$column] / (100 / 12));
                         } else {
                             $span = intval(substr($params[$column], 4));
                         }
                         // Alter current parameter value
                         $currentSpan = intval(substr($class, 4));
                         if ($currentSpan != $span) {
                             $params[$row][$id] = "span{$span}";
                             foreach ($params[$row] as $id => $class) {
                                 if (preg_match('/(\\d+:)?(promo|content|component)/', $id)) {
                                     $params[$row][$id] = 'span' . (intval(substr($class, 4)) + ($currentSpan - $span));
                                     // Done altering
                                     break;
                                 }
                             }
                         }
                         // Done altering
                         break 2;
                     }
                 }
             }
         }
     }
     // Process column width
     if (strcasecmp(get_class($this->_document), 'JDocumentHTML') == 0) {
         $utils = JSNTplUtils::getInstance();
         foreach (array('promoColumns', 'mainColumns', 'contentColumns', 'userColumns') as $row) {
             $visible = count($params[$row]);
             $spacing = 0;
             $columns = array();
             foreach ($params[$row] as $id => $class) {
                 // Re-fine ID
                 $realId = preg_replace('/^\\d+:/', '', $id);
                 // Detect the visibility of this column
                 if (!in_array($realId, array('content', 'component')) and !$utils->countModules($realId)) {
                     $visible--;
                     $spacing += intval(str_replace('span', '', $class));
                     $columns[$id] = 0;
                 } else {
                     $columns[$id] = 1;
                 }
             }
             // Expand visible columns if neccessary
             if ($visible < count($params[$row])) {
                 foreach ($columns as $id => $status) {
                     if (!$status) {
                         // Column is invisible, unset data
                         unset($params[$row][$id]);
                     } elseif ($visible > 0) {
                         // Alter column spanning
                         if (count($columns) > 3) {
                             $params[$row][$id] = preg_replace('/span\\d+/i', 'span' . 12 / $visible, $params[$row][$id]);
                         } elseif ($visible == 1) {
                             $params[$row][$id] = preg_replace('/span\\d+/i', 'span12', $params[$row][$id]);
                         }
                     }
                 }
                 if (count($columns) == 3 and $visible == 2) {
                     // Sort columns to ensure correct source code order
                     ksort($columns);
                     $ordering = array_keys($columns);
                     // Always expand main column if left or right is invisible
                     if ($columns[$ordering[0]] and $row != 'userColumns') {
                         $span = intval(str_replace('span', '', $params[$row][$ordering[0]]));
                         $params[$row][$ordering[0]] = preg_replace('/span\\d+/i', 'span' . ($span + $spacing), $params[$row][$ordering[0]]);
                     } else {
                         foreach ($ordering as $key) {
                             if ($columns[$key]) {
                                 $params[$row][$key] = preg_replace('/span\\d+/i', 'span6', $params[$row][$key]);
                             }
                         }
                     }
                 }
             }
             // Set visual column ordering
             $columns = array();
             $ordering = 0;
             foreach ($params[$row] as $id => $class) {
                 // Add class to indicate the order of this column
                 $params[$row][$id] .= ' order' . $ordering++;
             }
             // Sort columns for correct source code ordering
             ksort($params[$row]);
             foreach ($params[$row] as $id => $class) {
                 // Store data for processing visual ordering later
                 $columns[] = array('id' => $id, 'class' => $class);
             }
             // Process visual ordering for visible columns
             foreach ($columns as $ordering => $column) {
                 $visualOrdering = intval(preg_replace('/^.*order(\\d+).*$/', '\\1', $column['class']));
                 $offset = 0;
                 if ($ordering < $visualOrdering) {
                     for ($i = $ordering + 1; $i < $visible; $i++) {
                         $nextOrdering = intval(preg_replace('/^.*order(\\d+).*$/', '\\1', $columns[$i]['class']));
                         if (($ordering == 0 or $nextOrdering > 0) and $nextOrdering < $visualOrdering) {
                             $offset += intval(preg_replace('/^.*span(\\d+).*$/', '\\1', $columns[$i]['class']));
                         }
                     }
                 } elseif ($ordering > 0 and $ordering == $visualOrdering and $ordering + 1 < $visible) {
                     for ($i = 0; $i < $ordering; $i++) {
                         if (preg_match('/offset\\d+/', $columns[$i]['class'])) {
                             $offset -= intval(preg_replace('/^.*span(\\d+).*$/', '\\1', $columns[$i]['class']));
                         }
                     }
                     if ($offset < 0) {
                         $offset -= intval(preg_replace('/^.*span(\\d+).*$/', '\\1', $columns[$ordering]['class']));
                     }
                 } elseif ($ordering > $visualOrdering) {
                     for ($i = 0; $i < $ordering; $i++) {
                         $prevOrdering = intval(preg_replace('/^.*order(\\d+).*$/', '\\1', $columns[$i]['class']));
                         if ($prevOrdering > $visualOrdering) {
                             if (preg_match('/offset\\d+/', $columns[$i]['class'])) {
                                 $offset -= intval(preg_replace('/^.*span(\\d+).*$/', '\\1', $columns[$i]['class']));
                                 $offset -= intval(preg_replace('/^.*offset(\\d+).*$/', '\\1', $columns[$i]['class']));
                             } elseif (strpos($columns[$i]['class'], 'offset-') === false) {
                                 $offset -= intval(preg_replace('/^.*span(\\d+).*$/', '\\1', $columns[$i]['class']));
                             }
                         } elseif ($i > 0 and $prevOrdering < $visualOrdering) {
                             $offset += intval(preg_replace('/^.*span(\\d+).*$/', '\\1', $columns[$i]['class']));
                         }
                     }
                 }
                 // Set offset so the column display in correct visual ordering
                 if ($offset != 0) {
                     $columns[$ordering]['class'] = preg_replace('/(order\\d+)/', "\\1 offset{$offset}", $columns[$ordering]['class']);
                 }
             }
             // Update column IDs and classes
             foreach ($columns as $column) {
                 unset($params[$row][$column['id']]);
                 // Re-fine ID
                 $realId = preg_replace('/^\\d+:/', '', $column['id']);
                 // Re-fine column order
                 $ordering = intval(preg_replace('/^.*order(\\d+).*$/', '\\1', $column['class'])) + 1;
                 // Split classes to span, order and offset
                 $classes = explode(' ', preg_replace('/order\\d+/', "order{$ordering}", $column['class']));
                 // Reset column data
                 $params[$row][$realId] = array('span' => $classes[0], 'order' => isset($classes[1]) ? $classes[1] : '', 'offset' => isset($classes[2]) ? $classes[2] : '');
             }
         }
         // Prepare social icons
         $socialIcons = array();
         foreach ((array) @$params['socialIcons']['status'] as $channel) {
             // Set default value
             if (@empty($params['socialIcons'][$channel]['link']) and in_array($channel, array('facebook', 'twitter', 'youtube'))) {
                 if (!@isset($params['socialIcons'][$channel]['title'])) {
                     $params['socialIcons'][$channel]['title'] = JText::_('JSN_TPLFW_SOCIAL_NETWORK_INTEGRATION_' . strtoupper($channel));
                 }
                 $params['socialIcons'][$channel]['link'] = "http://www.{$channel}.com/joomlashine";
             }
             if (!@empty($params['socialIcons'][$channel]['link'])) {
                 $socialIcons[$channel] = $params['socialIcons'][$channel];
             }
         }
     }
     $params['socialIcons'] = $socialIcons;
     // Backward compatible: set templateStyle parameter as it still be used in component output only template file
     $params['templateStyle'] = $params['fontStyle']['style'];
     // Binding parameters to document object
     $this->_document->params = new JRegistry();
     foreach ($params as $key => $value) {
         $this->_document->params->set($key, $value);
         $this->_document->{$key} = $value;
     }
     // Assign helper object
     $this->_document->helper = $this;
     $this->_document->attributes = $this->_overrideAttributes;
     $this->_document->templatePrefix = $this->_document->template . '_';
     // Prepare body class
     $this->_prepareBodyClass();
     // Prepare template styles
     $this->_prepareHead();
 }
Beispiel #9
0
 /**
  * This method use to generate XML for template form definition
  *
  * @return  object
  */
 private function _generateFormXML()
 {
     $adminXml = simplexml_load_string('<?xml version="1.0" encoding="utf-8" ?><form><fields name="jsn"></fields></form>');
     $optionsXml = $this->templateXml->options;
     $context = array();
     if (JSNTplVersion::isCompatible($this->data->template, JSNTplHelper::getTemplateVersion($this->data->template))) {
         $formXml = simplexml_load_file(JSN_PATH_TPLFRAMEWORK . '/libraries/joomlashine/template/params.xml');
     } else {
         // Template is not compatible with framework v2, load old params declaration file
         $formXml = simplexml_load_file(JSN_PATH_TPLFRAMEWORK . '/libraries/joomlashine/template/params_v1.xml');
     }
     foreach ($optionsXml->xpath('//*[@method]') as $node) {
         $nodeType = (string) $node->getName();
         $method = (string) $node['method'];
         if (!in_array($nodeType, array('fieldset', 'field'))) {
             continue;
         }
         if (!isset($context[$method])) {
             $context[$method] = array();
         }
         $context[$method][(string) $node['name']] = $node;
     }
     $this->_addNodes($formXml->fields->children(), $adminXml->fields, $context);
     // Disable fieldset when edition is free
     if (strtolower($this->templateEdition->getEdition()) == 'free') {
         foreach ($adminXml->xpath('//fieldset[@pro="true"]') as $fieldset) {
             foreach ($fieldset->children() as $input) {
                 if ($input->getName() == 'fieldset') {
                     foreach ($input->children() as $_input) {
                         $_input->addAttribute('disabled', 'true');
                     }
                     continue;
                 }
                 $input->addAttribute('disabled', 'true');
             }
         }
     }
     $replacement = array('{templateUrl}' => JUri::root(true) . '/templates/' . $this->data->template);
     // Set default values
     foreach ($this->templateXml->xpath('//defaults/option') as $option) {
         $name = (string) $option['name'];
         $value = '';
         if (isset($option['value'])) {
             $value = (string) $option['value'];
         } elseif (count($option->children()) > 0) {
             $_value = array();
             foreach ($option->children() as $item) {
                 $_value[] = (string) $item;
             }
             $value = implode("\r\n", $_value);
         }
         foreach ($adminXml->xpath('//field[@name="' . $name . '"]') as $field) {
             $field['defaultValue'] = str_replace(array_keys($replacement), array_values($replacement), $value);
         }
     }
     $logoField = current($adminXml->xpath('//field[@name="logoFile"]'));
     $logoField['defaultValue'] = 'templates/' . $this->data->template . '/images/logo.png';
     return $adminXml;
 }
Beispiel #10
0
 /**
  * Retrieve template detailed information and store
  * it in the memory
  *
  * @param   string  $name  The template name
  * @return  void
  */
 private function _parseTemplateInfo($name)
 {
     if (!($details = JSNTplTemplateRecognization::detect($name))) {
         JFactory::getApplication()->enqueueMessage("The template {$name} is not a valid JoomlaShine template!");
     }
     $this->template = array('name' => $name, 'realName' => JText::_($name), 'id' => JSNTplHelper::getTemplateId($name), 'edition' => JSNTplHelper::getTemplateEdition($name), 'version' => JSNTplHelper::getTemplateVersion($name));
 }