From dce7b1420f2e3e6e2d0397da3583e2abaa0cd362 Mon Sep 17 00:00:00 2001 From: Hans Kuijpers Date: Tue, 30 Sep 2014 11:32:28 +0200 Subject: [PATCH 1/4] add new logic to helper.class.php --- helper.class.php | 177 ++++++++++++++++++++++++++++++++++++++++++-- helper.php | 161 ++++++---------------------------------- index.php | 39 +++++++--- templateDetails.xml | 87 +++++++++++++++++++--- 4 files changed, 301 insertions(+), 163 deletions(-) diff --git a/helper.class.php b/helper.class.php index 2962864..720ad7e 100644 --- a/helper.class.php +++ b/helper.class.php @@ -3,7 +3,42 @@ class ThisTemplateHelper { - static public function isHome() + + static public function adjustHead($template) + { + // Determine the variables + $doc = JFactory::getDocument(); + $head = $doc->getHeadData(); + $site_title = $template->params->get('sitetitle'); + + // remove deprecated meta-data (html5) + //unset($head['metaTags']['http-equiv']); + //unset($head['metaTags']['standard']['title']); + //unset($head['metaTags']['standard']['rights']); + //unset($head['metaTags']['standard']['language']); + + // Robots if you wish + //unset($head['metaTags']['standard']['robots']); + + $doc->setHeadData($head); + + // New meta + //$doc->setMetadata( 'X-UA-Compatible', 'IE=edge,chrome=1' ); + //$doc->setMetadata( 'viewport', 'width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=yes' ); + //$doc->setMetadata( 'HandheldFriendly', 'true' ); + //$doc->setMetadata( 'apple-mobile-web-app-capable', 'yes' ); + //$doc->setMetadata( 'copyright', $site_title ); + + //Yandex and Google Webmaster-tools if you wish + //$doc->setMetadata('yandex-verification', 'xxxxxxxxxxxxxxxx'); + //$doc->setMetadata('google-verification', 'xxxxxxxxxxxxxxxx'); + + // Remove or rewrite + //$doc->setGenerator(''); + $doc->setGenerator($site_title); + } + + static public function isHome() { // Fetch the active menu-item $menu = JFactory::getApplication()->getMenu(); @@ -16,10 +51,10 @@ static public function isHome() static public function loadCss($template) { // Determine the variables + $doc = JFactory::getDocument(); $cssmode = $template->params->get('cssmode', 'css'); $templateUrl = 'templates/'.$template->template; $templateDir = JPATH_SITE.'/templates/'.$template->template.'/'; - $doc = JFactory::getDocument(); $versionLess = '1.6.3'; $versionBootstrap = '3.2.0'; @@ -30,9 +65,7 @@ static public function loadCss($template) unset($doc->_styleSheets['/components/com_rsform/assets/css/front.css']); // Google Fonts - $doc->addStyleSheet('//fonts.googleapis.com/css?family=Roboto:400,300,700'); - $doc->addStyleSheet('//fonts.googleapis.com/css?family=Roboto+Slab:400,300,700'); - $doc->addStyleSheet('//fonts.googleapis.com/css?family=Roboto+Condensed:400,700,300'); + $doc->addStyleSheet('//fonts.googleapis.com/css?family=Open+Sans:400,300,700'); switch($cssmode) { @@ -78,4 +111,138 @@ static public function loadCss($template) $doc->addStyleSheet($templateUrl.'/css/compiled.css'); } } + + static public function getAnalytics($template) + { + // Determine the variables + $doc = JFactory::getDocument(); + $analytics = $template->params->get('analytics',0); + $analyticsId = $template->params->get('analyticsid'); + + // Analytics + switch ($analytics) { + case 0: + break; + case 1: + // Google Analytics - load in head + if($analyticsId) { + $analyticsScript = " + + var _gaq = _gaq || []; + _gaq.push(['_setAccount', '" . $analyticsId . "']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + "; + $doc->addScriptDeclaration($analyticsScript); + } + break; + case 2: + // Universal Google Universal Analytics - load in head + if($analyticsId) { + $analyticsScript = " + + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', '" . $analyticsId . "', 'auto'); + ga('send', 'pageview'); + "; + $doc->addScriptDeclaration($analyticsScript); + } + break; + case 3: + // Google Analytics - load in head + $isAnalyticsGTM = true; + if($analyticsId) { + $analyticsScript = " + + + + + "; + return $analyticsScript; + } + break; + } + } + + static public function getLogo($template) + { + // Determine the variables + $sitebrand = $template->params->get('sitebrand',0); + $site_title = $template->params->get('sitetitle'); + $site_tagline = $template->params->get('sitetagline'); + $site_logo = $template->params->get('sitelogo'); + $site_logosvg = $template->params->get('sitelogosvg'); + $site_url = JURI::root(); + + // Site Logo + switch ($sitebrand) { + case 0: + break; + case 1: + // using an image + if ($site_logo AND $site_title) + { + $logo = '' . htmlspecialchars($site_title) . ''; + return $logo; + } + break; + case 2: + // using an SVG image + if ($site_logosvg AND $site_title) + { + $logo = '' . htmlspecialchars($site_title) . ''; + // using SVGInjector to inject the image + self::getSVGInjector($template); + return $logo; + } + break; + case 3: + // using the title + if ($site_title) + { + $logo .= '' . htmlspecialchars($site_title) . ''; + return $logo; + } + break; + case 4: + // using the title and the tag line + if ($site_title AND $site_tagline) + { + $logo .= '' . htmlspecialchars($site_title) . '' . htmlspecialchars($site_tagline) . ''; + return $logo; + } + break; + case 5: + // using the tag line + if ($site_tagline) + { + $logo .= '' . htmlspecialchars($site_tagline) . ''; + return $logo; + } + break; + } + } + + static public function getSVGInjector($template) + { + // Determine the variables + $doc = JFactory::getDocument(); + $templateUrl = 'templates/'.$template->template; + + $doc->addScript($templateUrl.'js/svg-injector/svg-injector.min.js'); + } } diff --git a/helper.php b/helper.php index d6ef20f..fdaa6ed 100644 --- a/helper.php +++ b/helper.php @@ -15,36 +15,6 @@ $browser = JBrowser::getInstance(); $config = JFactory::getConfig(); $template = 'templates/' . $this->template; -$logo_image = $this->params->get('logoFile'); -$site_title = $config->get('sitename'); -$site_desc = $this->params->get('sitedescription'); -$analytics = $this->params->get('analytics'); -$analyticsId = $this->params->get('analyticsid'); - -// get html head data -$head = $doc->getHeadData(); -// remove deprecated meta-data (html5) -unset($head['metaTags']['http-equiv']); -unset($head['metaTags']['standard']['title']); -unset($head['metaTags']['standard']['rights']); -unset($head['metaTags']['standard']['language']); -// Robots if you wish -//unset($head['metaTags']['standard']['robots']); -$doc->setHeadData($head); - -// New meta -$doc->setMetadata( 'X-UA-Compatible', 'IE=edge,chrome=1' ); -$doc->setMetadata( 'viewport', 'width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=yes' ); -$doc->setMetadata( 'HandheldFriendly', 'true' ); -$doc->setMetadata( 'apple-mobile-web-app-capable', 'yes' ); -$doc->setMetadata( 'copyright', $site_title ); -//Yandex and Google Webmaster-tools if you wish -//$doc->setMetadata('yandex-verification', 'xxxxxxxxxxxxxxxx'); -//$doc->setMetadata('google-verification', 'xxxxxxxxxxxxxxxx'); - -// Remove or rewrite -//$doc->setGenerator(''); -$doc->setGenerator($site_title); // Detecting Active Variables $option = $app->input->getCmd('option', ''); @@ -52,27 +22,42 @@ $layout = $app->input->getCmd('layout', ''); $task = $app->input->getCmd('task', ''); $itemid = $app->input->getCmd('Itemid', ''); -$sitename = $app->getCfg('sitename'); $grid = 12; $gridSidebar = 3; $gridSidebarPos = 'left'; $gridSidebarOffset = 1; +// Include adjust meta tags in HEAD +ThisTemplateHelper::adjustHead($this); + +// Include CSS +ThisTemplateHelper::loadCss($this); + +// Include Analytics +ThisTemplateHelper::getAnalytics($this); + +// Logo +$logo = ThisTemplateHelper::getLogo($this); + +// Load SVG Injection +if ($this->params->get('svginjection')) +{ + ThisTemplateHelper::getSVGInjector($this); +} -// To enable use of site configuration -$pageParams = $app->getParams(); -// Determine home (@todo: What is this, Hans?) + + + + +// Determine home if(ThisTemplateHelper::isHome()) { $siteHome = "home"; } else { $siteHome = "sub"; } -// Include CSS -ThisTemplateHelper::loadCss($this); - // Add scripts $doc->addScript($template.'/js/application.js'); if($browser->getBrowser() == 'msie' && $browser->getMajor() < 9 ) { @@ -84,59 +69,15 @@ // Determine whether to show sidebar-A (@todo: Jisse, clean up this mess) $SidebarA = false; -//$SidebarAMageBridgePages = array('customer', 'membership', 'software', 'sales'); -//hideLeftMageBridgePages = array('customer/account/login'); -//$hideLeftMenuItems = array(11, 185, 282, 308, 316, 332, 348, 353, 354, 355, 362, 380); if ($this->countModules('left')) $SidebarA = true; -//if ($this->countModules('left-usermenu') && JFactory::getUser()->guest == 0) $SidebarA = true; -//if (JRequest::getCmd('option') == 'com_magebridge' && $magebridge->isPage($SidebarAMageBridgePages) == false) $SidebarA = false; -//if (JRequest::getCmd('option') == 'com_magebridge' && $magebridge->isPage($hideLeftMageBridgePages)) $SidebarA = false; if (!empty($active) && $active->home == true) $SidebarA = false; -//if (in_array(JRequest::getCmd('Itemid'), $hideLeftMenuItems)) $SidebarA = false; -//if (JRequest::getCmd('option') == 'com_search') $SidebarA = false; -//if (JRequest::getCmd('option') == 'com_kunena') $SidebarA = false; -//if (JRequest::getCmd('option') == 'com_simplelists' && JRequest::getInt('category_id') == 239) $SidebarA = false; -//if (JRequest::getCmd('option') == 'com_products' && JRequest::getCmd('view') == 'extension') $SidebarA = true; -//if (JRequest::getCmd('option') == 'com_products' && JRequest::getCmd('view') == 'extensions') $SidebarA = false; -//if (JRequest::getCmd('option') == 'com_products' && JRequest::getCmd('view') == 'services') $SidebarA = false; -//if (JRequest::getCmd('option') == 'com_products' && JRequest::getCmd('view') == 'platform') $SidebarA = false; + // Check upon the current page layout $pagelayout = $this->params->get('pagelayout', '1column'); if($SidebarA == true) $pagelayout = '2column-left'; - - -// Favicon -if ($this->params->get('templateFavicon')) -{ - $this->addFavicon(JURI::root() . $this->params->get('templateFavicon')); -} - -// Logo -if ($logo_image) -{ - // Custom logo image - $logo = '' . $sitename . ''; -} -elseif (($site_title) && ($site_desc)) -{ - // Title and description - $logo = '' . htmlspecialchars($site_title) . '' . htmlspecialchars($site_desc) . ''; -} -elseif (($site_title) && (!$site_desc)) -{ - // Title only - $logo = '' . htmlspecialchars($site_title) . ''; -} -else -{ - // Load default template logo - $logo = '' . $sitename . ''; -} - - // Width calculations $span = ''; @@ -160,59 +101,3 @@ $span = $grid; } -// Analytics -switch ($analytics) { - case 0: - break; - case 1: - // Google Analytics - load in head - if($analyticsId) { - $analyticsScript = " - - var _gaq = _gaq || []; - _gaq.push(['_setAccount', '" . $analyticsId . "']); - _gaq.push(['_trackPageview']); - - (function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - })(); -"; - $doc->addScriptDeclaration($analyticsScript); - } - break; - case 2: - // Universal Google Universal Analytics - load in head - if($analyticsId) { - $analyticsScript = " - - (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ - (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), - m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) - })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); - - ga('create', '" . $analyticsId . "', 'auto'); - ga('send', 'pageview'); -"; - $doc->addScriptDeclaration($analyticsScript); - } - break; - case 3: - // Google Analytics - load in head - $isAnalyticsGTM = true; - if($analyticsId) { - $analyticsScript = " - - - - -"; - } - break; -} \ No newline at end of file diff --git a/index.php b/index.php index 787d958..5fe07b2 100644 --- a/index.php +++ b/index.php @@ -17,9 +17,10 @@ " itemscope itemtype="http://schema.org/WebPage">