Skip to content

Commit

Permalink
Added sopport ETag (style.css.php) with the Denim and Denim Curve theme
Browse files Browse the repository at this point in the history
  • Loading branch information
dengenxp committed Dec 29, 2016
1 parent ece44df commit 829f268
Show file tree
Hide file tree
Showing 12 changed files with 457 additions and 29 deletions.
176 changes: 176 additions & 0 deletions public_html/layout/denim/css/style.css.php
@@ -0,0 +1,176 @@
<?php

/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 2.1 |
// +---------------------------------------------------------------------------+
// | style.css.php |
// | |
// | Preprocessor for CSS theme files |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2012 by the following authors: |
// | |
// | Authors: Rouslan Placella - rouslan@placella.com |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+

require_once '../../../siteconfig.php';

// get theme name
if (!isset($_GET['theme'])) {
exit;
}
$theme = $_GET['theme'];

// get package name
if (!isset($_GET['package'])) {
exit;
}
$package_name = $_GET['package'];

// get lang directions
$LANG_DIRECTION = 'ltr'; // need to set this for themes function.php file
if (isset($_GET['dir']) && $_GET['dir'] === 'rtl') {
$LANG_DIRECTION = 'rtl';
}

// set path variables
$path_html = dirname(dirname(dirname(getcwd()))); // Should always be the directory above
$path_themes = $path_html . '/layout/';
$path_layout = $path_themes . $theme . '/';

// set etag file name and path
// have moved or renamed /data directory, please change the following line accordingly.
$etag_filename = $_CONF['path'] . 'data/layout_css/' . $theme . '_' . $LANG_DIRECTION . '_etag.cache';

// get theme info
if (!file_exists($path_layout . 'functions.php')) {
exit;
}
require_once $path_layout . 'functions.php';

// get the configuration values from the theme
$theme_default = '';
$path_layout_default = '';
$func = "theme_config_" . $theme;
if (function_exists($func)) {
$theme_config = $func();
if (isset($theme_config['theme_default'])) {
$theme_default = $theme_config['theme_default'];
$path_layout_default = $path_themes . $theme_default . '/';
// reset fake config theme var to default so when fuction below loads in css files it will point to default
}
}

$cssfiles = array();

// load in default theme css files
if (!empty($theme_default)) {
if (!file_exists($path_layout_default . 'functions.php')) {
exit;
}
require_once $path_layout_default . 'functions.php';

// include scripts on behalf of the theme
$_CONF['theme'] = $theme_default; // Need to set this for default themes function.php file

$func = "theme_css_" . $theme_default;
if (function_exists($func)) {
$css_packages = $func();
foreach($css_packages as $package) {
if ($package['name'] === $package_name) {
$cssfiles = $package['css_items'];
break;
}
}
}
}

// include scripts on behalf of the theme
$_CONF['theme'] = $theme; // Need to set this for themes function.php file

$func = "theme_css_" . $theme;
if (function_exists($func)) {
$css_packages = $func();
foreach($css_packages as $package) {
if ($package['name'] === $package_name) {
$cssfiles = array_merge($cssfiles, $package['css_items']);
break;
}
}
}

// sort theme css files based on priority if needed
$priority = array();
foreach($cssfiles as $k => $d) {
$priority[$k] = $d['priority'];
}
array_multisort($priority, SORT_ASC, $cssfiles);

if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
if (is_readable($etag_filename)) {
$etag = file_get_contents($etag_filename);
if (!empty($etag) AND (trim($_SERVER['HTTP_IF_NONE_MATCH'], '"\'') === $etag)) {
header('HTTP/1.1 304 Not Modified');
header('Status: 304 Not Modified');
exit;
}
}
}

// creates a new ETag value and saves it into the file
$etag = md5(microtime(TRUE));
@file_put_contents($etag_filename, $etag);

// Send correct header type:
header('Content-Type: text/css; charset=UTF-8');
// Add Cache Expire in 1 week
header('Cache-control: must-revalidate');
header('Expires: '.gmdate('D, d M Y H:i:s', time() + 604800).' GMT');

header('ETag: "' . $etag . '"');

// Output the contents of each file
foreach ($cssfiles as $file) {
$full_filepath = '';
// Set css path variables
$css_file_default='';
if (!empty($theme_default)) {
$css_file_default = $path_html . $file['file'];
}
$css_file = $path_html . $file['file'];

if (!empty($theme_default)) {
// First add own theme css file if found else add default css file
if (is_readable($css_file)) {
$full_filepath = $css_file;
} elseif (is_readable($css_file_default)) {
$full_filepath = $css_file_default;
}
} else {
// Add theme css file if found
if (is_readable($css_file)) {
$full_filepath = $css_file;
}
}

if (!empty($full_filepath)) {
$css = file_get_contents($full_filepath);
echo $css . PHP_EOL;
}
}
Binary file added public_html/layout/denim/fonts/FontAwesome.otf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
66 changes: 52 additions & 14 deletions public_html/layout/denim/functions.php
Expand Up @@ -69,6 +69,7 @@ function theme_config_denim()
'tooltip' => 1,
'upload' => 0,
),
'enable_etag' => 0, // 1:enable or 0:disable ETag
'use_minified_css' => 0, // 1:use or 0:no_use minified css
'header_search' => 1, // 1:show or 0:hide header searchbox
'block_left_search' => 1, // 1:show or 0:hide left block searchbox
Expand All @@ -83,6 +84,7 @@ function theme_config_denim()
return array(
'image_type' => 'png',
'doctype' => 'xhtml5',
'etag' => false, // never set this true. instead use $options['enable_etag'] above.
'supported_version_theme' => '2.0.0', // support new theme format for the later Geeklog 2.0.0
'theme_plugins' => 'denim', // Not requred, you can specify compatible theme of template stored with some plugins
'options' => $options // Not requred, some options of this theme
Expand All @@ -105,39 +107,75 @@ function theme_css_denim()
}
$min = ($theme_var['options']['use_minified_css'] === 1) ? '.min' : '';

$result = array();
$result[] = array(
// array of css packages
$css_packages = array();

// main package items
$css_items = array();

// add uikit css
$css_items[] = array(
'name' => 'uikit',
'file' => '/vendor/uikit/css' . $direction . '/uikit' . $ui_theme . $min . '.css',
'attributes' => array('media' => 'all'),
'priority' => 80
);

$result[] = array(
// add some uikit component css
if (!empty($theme_var['options']['uikit_components'])) {
$uikit_components = array_merge($theme_var['options']['uikit_components']);
foreach ($uikit_components as $component => $value) {
if ($value !== 1) continue;
$componame = str_replace('_', '-', $component);
$css_items[] = array(
'name' => 'uk_' . $component,
'file' => '/vendor/uikit/css' . $direction . '/components/' . $componame . $ui_theme . $min . '.css',
'priority' => 81
);
}
}

// add main css of this theme
$css_items[] = array(
'name' => 'main', // don't use the name 'theme' to control the priority
'file' => '/layout/' . $_CONF['theme'] . '/css_' . $LANG_DIRECTION . '/style' . $ui_theme . $min . '.css',
'attributes' => array('media' => 'all'),
'priority' => 100
'priority' => 90
);

$result[] = array(
// add custom css of this theme
$css_items[] = array(
'name' => 'custom',
'file' => '/layout/' . $_CONF['theme'] . '/css_' . $LANG_DIRECTION . '/custom.css',
'attributes' => array('media' => 'all'),
'priority' => 101
'priority' => 91
);

if (!empty($theme_var['options']['uikit_components'])) {
$uikit_components = array_merge($theme_var['options']['uikit_components']);
foreach ($uikit_components as $component => $value) {
if ($value !== 1) continue;
$componame = str_replace('_', '-', $component);
// register main css package
$css_packages[] = array(
'name' => 'main_package',
'css_items' => $css_items,
);

// never packed css items
$never_packed_items = array();

$result = array();
$result = $never_packed_items;
if ($theme_var['options']['enable_etag'] === 1) {
foreach($css_packages as $package) {
$result[] = array(
'name' => 'uk_' . $component,
'file' => '/vendor/uikit/css' . $direction . '/components/' . $componame . $ui_theme . $min . '.css',
'priority' => 81
'name' => $package['name'],
'file' => '/layout/' . $_CONF['theme'] . '/css/style.css.php?theme='
. $_CONF['theme'] . '&amp;package=' . $package['name'] . '&amp;dir=' . $LANG_DIRECTION,
'css_items' => $package['css_items'],
'priority' => 90
);
}
} else {
foreach($css_packages as $package) {
$result = array_merge($result, $package['css_items']);
}
}

return $result;
Expand Down

0 comments on commit 829f268

Please sign in to comment.