コード例 #1
0
 /**
  * Implement event onJSNTPLGetModuleLayoutPath to return the layout which override by JSN TemplateFrameWork
  *
  * @param   string $module  The name of the module
  * @param   string $layout  The name of the module layout.
  *
  * @return  $path on true/false
  */
 public function onJSNTPLGetModuleLayoutPath($module, $layout)
 {
     $app = JFactory::getApplication();
     if ($app->isSite() && JSNTplTemplateRecognization::detect()) {
         $JSNTPLfPath = JSN_PATH_TPLFRAMEWORK . '/html/' . $module . '/' . $layout . '.php';
         if (@file_exists($JSNTPLfPath)) {
             return $JSNTPLfPath;
         }
     }
     return false;
 }
コード例 #2
0
ファイル: sample.php プロジェクト: jdrzaic/joomla-dummy
 /**
  * Sample data package will be downloaded to temporary
  * folder in this action
  *
  * @return  void
  */
 public function downloadPackageAction()
 {
     JSNTplHelper::isDisabledFunction('set_time_limit') or set_time_limit(0);
     $config = JFactory::getConfig();
     $tmpPath = $config->get('tmp_path');
     $template = JSNTplTemplateRecognization::detect($this->template['name']);
     $fileUrl = 'http://www.joomlashine.com/joomla-templates/jsn-' . strtolower($template->name . '-' . preg_replace('/\\s(STANDARD|UNLIMITED)$/', '', $template->edition)) . '-sample-data-j' . (substr($version = JSNTplHelper::getJoomlaVersion(2, false), 0, 1) == '3' ? '30' : $version) . '.zip';
     // Download file to temporary folder
     try {
         $response = JSNTplHttpRequest::get($fileUrl, $tmpPath . "/{$this->template['name']}_sampledata.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'));
     }
     $listExtensions = $this->_extractExtensions($tmpPath . "/{$this->template['name']}_sampledata.zip");
     $this->setResponse($listExtensions);
 }
コード例 #3
0
 * @subpackage  TPLFramework
 * @author      JoomlaShine Team <*****@*****.**>
 * @copyright   Copyright (C) 2012 JoomlaShine.com. All Rights Reserved.
 * @license     GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
 *
 * Websites: http://www.joomlashine.com
 * Technical Support:  Feedback - http://www.joomlashine.com/contact-us/get-support.html
 */
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// Get all fieldset in XML
$fieldSets = $adminFormXml->fields->fieldset;
// Set appropriate wrapper class
$wrapperClass = 'jsn-joomla' . JSNTplHelper::getJoomlaVersion(1, false);
// Get template details
$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);
コード例 #4
0
ファイル: helper.php プロジェクト: jdrzaic/joomla-dummy
 /**
  * Retrieve edition of the template that determined by name
  *
  * @param   string  $name  The template name to retrieve edition
  * @return  string
  */
 public static function getTemplateEdition($name)
 {
     if ($details = JSNTplTemplateRecognization::detect($name)) {
         return $details->edition;
     }
     // Backward compatible
     $registry = JRegistry::getInstance('JSNTplFramework');
     if ($registry->exists('template.edition')) {
         return $registry->get('template.edition');
     }
     $manifest = JSNTplHelper::getManifest($name);
     $edition = isset($manifest->edition) ? (string) $manifest->edition : 'FREE';
     $registry->set('template.edition', $edition);
     return $edition;
 }
コード例 #5
0
ファイル: sample.php プロジェクト: rodhoff/MNW
 /**
  * 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)));
 }
コード例 #6
0
ファイル: helper.php プロジェクト: NallelyFlores89/basvec
 /**
  * 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();
 }
コード例 #7
0
 /**
  * Render template admin UI
  *
  * @return  void
  */
 public static function onAfterRender()
 {
     // Make sure our event handler is the last one executed
     if (!defined('JSN_TPLFW_LAST_EXECUTION')) {
         return;
     }
     // Get Joomla application object
     $app = JFactory::getApplication();
     // Detect method to use for getting and setting response body
     if (version_compare(JVERSION, '3.2.0', 'ge')) {
         $get = array($app, 'getBody');
         $set = array($app, 'setBody');
     } else {
         $get = array('JResponse', 'getBody');
         $set = array('JResponse', 'setBody');
     }
     if ($app->isAdmin()) {
         // Alter body tag
         $html = call_user_func($get);
         if (preg_match('/<body[^>]*>/i', $html, $match) and strpos($match[0], 'jsn-master tmpl-' . $app->getTemplate()) === false) {
             if (strpos($match[0], 'class=') === false) {
                 $match[1] = substr($match[0], 0, -1) . ' class=" jsn-master tmpl-' . $app->getTemplate() . ' ">';
             } else {
                 $match[1] = str_replace('class="', 'class=" jsn-master tmpl-' . $app->getTemplate() . ' ', $match[0]);
             }
             $html = str_replace($match[0], $match[1], $html);
         }
         call_user_func($set, $html);
         // Initialize template admin
         if (isset(self::$_templateAdmin) and self::$_templateAdmin instanceof JSNTplTemplateAdmin) {
             self::$_templateAdmin->render();
             // Clean-up Chosen calls if running on Joomla 3.1
             $JVersion = new JVersion();
             if (version_compare($JVersion->getShortVersion(), '3.1', '>=')) {
                 $html = call_user_func($get);
                 if (preg_match('#[\\r\\n][\\s\\t]+<link rel="stylesheet" href="[^"]*/media/jui/css/chosen\\.css" type="text/css" />#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 if (preg_match('#[\\r\\n][\\s\\t]+<script src="[^"]*/media/jui/js/chosen\\.jquery\\.min\\.js" type="text/javascript"></script>#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 if (preg_match('#[\\r\\n][\\s\\t]+jQuery\\(document\\)\\.ready\\(function \\(\\)\\{[\\r\\n][\\s\\t]+jQuery\\(\'select\'\\)\\.chosen\\(\\{[^\\}]+\\}\\);[\\r\\n][\\s\\t]+\\}\\);#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 call_user_func($set, $html);
             }
             // Clean-up HTML5 fall-back script if running on Joomla 3.2
             if (version_compare($JVersion->getShortVersion(), '3.2', '>=')) {
                 $html = call_user_func($get);
                 if (preg_match('#[\\r\\n][\\s\\t]+<script src="[^"]*/media/system/js/html5fallback(-uncompressed)?\\.js" type="text/javascript"></script>#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 call_user_func($set, $html);
             }
         }
         // Execute update checker
         self::checkUpdate();
     } elseif (JSNTplTemplateRecognization::detect()) {
         $document = JFactory::getDocument();
         $config = JFactory::getConfig();
         $html = call_user_func($get);
         // Optimize script tags position
         self::moveScriptTags($html);
         if (isset($document->helper) && $document->helper instanceof JSNTplTemplateHelper && $document->compression > 0) {
             // Verify cache directory
             if (!preg_match('#^(/|\\|[a-z]:)#i', $document->params->get('cacheDirectory'))) {
                 $cachePath = JPATH_ROOT . '/' . rtrim($document->params->get('cacheDirectory'), '\\/');
             } else {
                 $cachePath = rtrim($document->params->get('cacheDirectory'), '\\/');
             }
             if ($config->get('ftp_enable') or is_writable($cachePath)) {
                 // Start compress CSS
                 if ($document->compression == 1 or $document->compression == 2) {
                     $html = preg_replace_callback('/(<link([^>]+)rel=["|\']stylesheet["|\']([^>]*)>\\s*)+/i', array('JSNTplCompressCss', 'compress'), $html);
                 }
                 // Start compress JS
                 if ($document->compression == 1 or $document->compression == 3) {
                     $html = preg_replace_callback('/(<script([^>]+)src=["|\']([^"|\']+)["|\']([^>]*)>\\s*<\\/script>\\s*)+/i', array('JSNTplCompressJs', 'compress'), $html);
                 }
             }
         }
         call_user_func($set, $html);
     }
 }
コード例 #8
0
ファイル: base.php プロジェクト: jdrzaic/joomla-dummy
 /**
  * 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));
 }