Code:
<?php
/**
* This observer written to work with core ZC 1.5.3 and above looks for the header end found in the includes/templates/YOUR_RESPONSIVE_TEMPLATE/common/html_header.php file
* and if applicable conditions are met to finally load the specifically identified responsive_XXX_CONDITION.css template override CSS file for the template style (XXX such as mobile, tablet, or default)
* that meets the desired override CONDITION such as used for standard templates.
**/
class zcObserverResponsiveTemplateCssLoad extends base {
function __construct() {
$observe_me = array();
$observe_me[] = 'NOTIFY_HTML_HEAD_END';
$this->attach($this, $observe_me);
}
function updateNotifyHtmlHeadEnd(&$calling_class, $notifier, $current_page_base) {
global $detect, $responsive_mobile, $responsive_tablet, $responsive_default, $sheets_array, $manufacturers_id, $tmp_products_id, $tmp_pagename, $ezpage_id, $tmp_cats;
/* $responsive_mobile = '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'responsive_mobile.css' . '" /><link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'jquery.mmenu.all.css' . '" />';
$responsive_tablet = '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'responsive_tablet.css' . '" /><link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'jquery.mmenu.all.css' . '" />';
$responsive_default = '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'responsive_default.css' . '" />';*/
if (in_array($current_page_base,explode(",",'popup_image,popup_image_additional')) ) {
$responsive_prefix = '';
} else {
echo '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . 'responsive.css' . '" />';
if ( $detect->isMobile() && !$detect->isTablet() || $_SESSION['layoutType'] == 'mobile' ) {
$responsive_prefix = 'responsive_mobile';
} else if ( $detect->isTablet() || $_SESSION['layoutType'] == 'tablet' ){
$responsive_prefix = 'responsive_tablet';
} else if ( $_SESSION['layoutType'] == 'full' ) {
$responsive_prefix = '';
} else {
$responsive_prefix = 'responsive_default';
}
}
if (zen_not_null($responsive_prefix) && (isset($responsive_mobile) || isset($responsive_tablet) || isset($responsive_default))) {
/**
* load all template-specific stylesheets, named like "responsive_XXXX_style*.css", alphabetically where XXXX is the responsive template type (mobile, tablet or default)
*/
$directory_array = $template->get_template_part($template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css'), '/^' . $responsive_prefix . '_style/', '.css');
foreach($directory_array as $key=>$value) { // Updated for PHP 7.2 mc12345678 2017-06-29
echo '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . $value . '" />'."\n";
}
/**
* load responsive_xxxx stylesheets on a per-page/per-language/per-product/per-manufacturer/per-category basis. Concept by Juxi Zoza adapted by mc12345678. Reuses the $sheets_array as defined in the common/header_php.php file which includes a slash prefix. Could assign that array in here with/without the slash but then would need to maintain the list in both places, if the header file removes the front slash then the substr function below is unnecessary (replace substr($value, 1) with just $value). The substr function does not specifically address files with UTF-8 filenames. That requires mb_substr and that "determination" to use that function has *not* been included below, but may need to be considered if the css file does not load after performing applicable validation that CSS files are "ready" to be loaded (clearing cache, cookies, etc...)
*/
foreach($sheets_array as $key=>$value) { // Updated for PHP 7.2 mc12345678 2017-06-29
//echo "<!--looking for: $value-->\n";
$perpagefile = $template->get_template_dir('.css', DIR_WS_TEMPLATE, $current_page_base, 'css') . '/' . $responsive_prefix . '_' . substr($value, 1) . '.css';
if (file_exists($perpagefile)) echo '<link rel="stylesheet" type="text/css" href="' . $perpagefile .'" />'."\n";
}
/**
* custom category handling for a parent and all its children ... works for any responsive_xxx_c_XX_XX_children.css where xxx is the responsive template type (mobile, tablet or default) and XX_XX is any parent category
*/
$value = '';
foreach($tmp_cats as $val) {
$value .= $val;
$perpagefile = $template->get_template_dir('.css', DIR_WS_TEMPLATE, $current_page_base, 'css') . '/' . $responsive_prefix . '_' . 'c_' . $value . '_children.css';
if (file_exists($perpagefile)) echo '<link rel="stylesheet" type="text/css" href="' . $perpagefile .'" />'."\n";
$perpagefile = $template->get_template_dir('.css', DIR_WS_TEMPLATE, $current_page_base, 'css') . '/' . $responsive_prefix . '_' . $_SESSION['language'] . '_c_' . $value . '_children.css';
if (file_exists($perpagefile)) echo '<link rel="stylesheet" type="text/css" href="' . $perpagefile .'" />'."\n";
$value .= '_';
}
/**
* load printer-friendly stylesheets -- named like "responsive_XXX_print*.css", alphabetically
*/
$directory_array = $template->get_template_part($template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css'), '/^' . $responsive_prefix . '_' . 'print/', '.css');
sort($directory_array);
foreach ($directory_array as $key=>$value) { mc12345678 2017-06-29
echo '<link rel="stylesheet" type="text/css" media="print" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . $value . '" />'."\n";
}
}
}
}
Bookmarks