Skip to content

Instantly share code, notes, and snippets.

@renekreijveld
Last active February 22, 2018 01:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save renekreijveld/4a5b31aedfa5f2977a67 to your computer and use it in GitHub Desktop.
Save renekreijveld/4a5b31aedfa5f2977a67 to your computer and use it in GitHub Desktop.
Logic.php to include in Joomla 3.x templates
<?php
// Template by DSD business internet // www.gakijken.nl //
defined('_JEXEC') or die;
// Connect with Joomla
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$session = JFactory::getSession();
// Get variables
$option = $app->input->getCmd('option', '');
$view = $app->input->getCmd('view', '');
$layout = $app->input->getCmd('layout', '');
$task = $app->input->getCmd('task', '');
$itemid = $app->input->getCmd('Itemid', '');
$id = $app->input->getCmd('id', '');
$sitename = $app->getCfg('sitename');
$menu = $app->getMenu();
$menu_active = $menu->getActive();
$frontpage = ($menu_active == $menu->getDefault() ? true : false);
$templateparams = $app->getTemplate(true)->params;
$templateUrl = $this->baseurl.'/templates/'.$this->template;
$templateDir = JPATH_THEMES . '/' . $this->template . '/';
$ualayout = $session->get('ualayout');
// Browser info
jimport('joomla.environment.browser');
$browser = JBrowser::getInstance();
$browserType = $browser->getBrowser();
$browserVersion = $browser->getMajor();
// Call JavaScript to be able to unset it :-S
JHtml::_('behavior.framework');
JHtml::_('bootstrap.framework');
JHtml::_('jquery.framework');
JHtml::_('bootstrap.tooltip');
// Unset unwanted JavaScript
unset($this->_scripts[$this->baseurl .'/media/system/js/mootools-core.js']);
unset($this->_scripts[$this->baseurl .'/media/system/js/mootools-more.js']);
unset($this->_scripts[$this->baseurl .'/media/system/js/caption.js']);
unset($this->_scripts[$this->baseurl .'/media/system/js/core.js']);
unset($this->_scripts[$this->baseurl .'/media/jui/js/jquery.min.js']);
unset($this->_scripts[$this->baseurl .'/media/jui/js/jquery-noconflict.js']);
unset($this->_scripts[$this->baseurl .'/media/jui/js/jquery-migrate.min.js']);
unset($this->_scripts[$this->baseurl .'/media/jui/js/bootstrap.min.js']);
unset($this->_scripts[$this->baseurl .'/media/system/js/tabs-state.js']);
unset($this->_scripts[$this->baseurl .'/media/system/js/validate.js']);
unset($this->_scripts[$this->baseurl .'/media/com_finder/js/autocompleter.js']);
if (isset($this->_script['text/javascript']))
{
$this->_script['text/javascript'] = preg_replace('%jQuery\(window\)\.on\(\'load\'\,\s*function\(\)\s*\{\s*new\s*JCaption\(\'img.caption\'\);\s*}\s*\);\s*%', '', $this->_script['text/javascript']);
$this->_script['text/javascript'] = preg_replace("%\s*jQuery\(document\)\.ready\(function\(\)\{\s*jQuery\('\.hasTooltip'\)\.tooltip\(\{\"html\":\s*true,\"container\":\s*\"body\"\}\);\s*\}\);\s*%", '', $this->_script['text/javascript']);
// Unset completly if empty
if (empty($this->_script['text/javascript']))
{
unset($this->_script['text/javascript']);
}
}
// Unset unwanted CSS
$unset_css = array('com_finder');
foreach($this->_styleSheets as $name=>$style)
{
foreach($unset_css as $css)
{
if (strpos($name,$css) !== false)
{
unset($this->_styleSheets[$name]);
}
}
}
// Add Javascripts
if ($frontpage) {
$doc->addScript($templateUrl . '/js/home.min.js', 'text/javascript');
} else {
$doc->addScript($templateUrl . '/js/next.min.js', 'text/javascript');
}
// Add Stylesheets
$cssmode = $templateparams->get('cssmode');
switch($cssmode)
{
case 'css':
$doc->addStyleSheet($templateUrl.'/css/site.css');
break;
case 'phpless':
// Automatically compile LESS using https://github.com/oyejorge/less.php
$cssFile = $templateDir.'css/site.compiled.css';
$lessFile = $templateDir.'less/site.less';
if(filemtime($lessFile) > filemtime($cssFile)) {
require_once $templateDir.'lib/less.php/lessc.inc.php';
$options = array(
'compress' => true,
'sourceMap' => true,
'sourceMapWriteTo' => $templateDir . 'css/site.compiled.map',
'sourceMapURL' => $templateUrl . '/css/site.compiled.map'
);
$parser = new Less_Parser( $options );
$parser->parseFile($lessFile, $templateUrl . '/less/');
$css = $parser->getCss();
file_put_contents($cssFile, $css);
}
$doc->addStyleSheet($templateUrl.'/css/site.compiled.css');
break;
default:
$doc->addStyleSheet($templateUrl.'/css/site.css');
}
// Set MetaData
$doc->setMetaData('viewport', 'width=device-width, initial-scale=1.0' );
$doc->setMetaData('content-type', 'text/html', true );
$doc->setGenerator($sitename);
// Custom Icons
if ($ualayout == "desktop") :
$doc->addFavicon($templateUrl . '/favicon.png','image/png','shortcut icon');
else :
$doc->addCustomTag('<link rel="apple-touch-icon" sizes="57x57" href="' . $templateUrl . '/icons/apple-touch-icon-57x57.png">');
$doc->addCustomTag('<link rel="apple-touch-icon" sizes="60x60" href="' . $templateUrl . '/icons/apple-touch-icon-60x60.png">');
$doc->addCustomTag('<link rel="apple-touch-icon" sizes="72x72" href="' . $templateUrl . '/icons/apple-touch-icon-72x72.png">');
$doc->addCustomTag('<link rel="apple-touch-icon" sizes="76x76" href="' . $templateUrl . '/icons/apple-touch-icon-76x76.png">');
$doc->addCustomTag('<link rel="apple-touch-icon" sizes="114x114" href="' . $templateUrl . '/icons/apple-touch-icon-114x114.png">');
$doc->addCustomTag('<link rel="apple-touch-icon" sizes="120x120" href="' . $templateUrl . '/icons/apple-touch-icon-120x120.png">');
$doc->addCustomTag('<link rel="apple-touch-icon" sizes="144x144" href="' . $templateUrl . '/icons/apple-touch-icon-144x144.png">');
$doc->addCustomTag('<link rel="apple-touch-icon" sizes="152x152" href="' . $templateUrl . '/icons/apple-touch-icon-152x152.png">');
$doc->addCustomTag('<link rel="apple-touch-icon" sizes="180x180" href="' . $templateUrl . '/icons/apple-touch-icon-180x180.png">');
$doc->addCustomTag('<link rel="icon" type="image/png" sizes="16x16" href="' . $templateUrl . '/icons/favicon-16x16.png">');
$doc->addCustomTag('<link rel="icon" type="image/png" sizes="32x32" href="' . $templateUrl . '/icons/favicon-32x32.png">');
$doc->addCustomTag('<link rel="icon" type="image/png" sizes="96x96" href="' . $templateUrl . '/icons/favicon-96x96.png">');
$doc->addCustomTag('<link rel="manifest" href="' . $templateUrl . '/icons/manifest.json">');
$doc->addCustomTag('<meta name="msapplication-TileColor" content="#da532c">');
$doc->addCustomTag('<meta name="msapplication-TileImage" content="' . $templateUrl . '/icons/mstile-144x144.png">');
$doc->addCustomTag('<meta name="theme-color" content="#ffffff">');
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment