[geeklog-hg] geeklog: Added support for ETag with themes. ETag option needs t...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sun Jul 28 09:30:40 EDT 2013


changeset 9230:41567b113ad0
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/41567b113ad0
user: Tom <websitemaster at cogeco.net>
date: Sat Jul 27 17:57:04 2013 -0400
description:
Added support for ETag with themes. ETag option needs to be set in functions.php and style.css.php file must exist in themes directory. CSS cache files now cleared when rest of cache is cleared. New internal config variable theme_etag. Added data/layout_css directory to store css cache files.

diffstat:

 public_html/admin/install/lib-install.php     |    1 +
 public_html/layout/modern_curve/functions.php |   50 +++++++-
 public_html/layout/modern_curve/style.css.php |  162 ++++++++++++++++---------
 public_html/lib-common.php                    |   10 +-
 system/classes/scripts.class.php              |   23 ++-
 system/lib-template.php                       |   13 +-
 6 files changed, 175 insertions(+), 84 deletions(-)

diffs (truncated from 415 to 300 lines):

diff -r 937b29cc613b -r 41567b113ad0 public_html/admin/install/lib-install.php
--- a/public_html/admin/install/lib-install.php	Sat Jul 27 17:42:06 2013 -0400
+++ b/public_html/admin/install/lib-install.php	Sat Jul 27 17:57:04 2013 -0400
@@ -1398,6 +1398,7 @@
     }
 
     INST_clearCacheDirectories($_CONF['path'] . 'data/layout_cache/', $plugin);
+    INST_clearCacheDirectories($_CONF['path'] . 'data/layout_css/', $plugin);
 }
 
 function INST_checkCacheDir($path,$template,$classCounter)
diff -r 937b29cc613b -r 41567b113ad0 public_html/layout/modern_curve/functions.php
--- a/public_html/layout/modern_curve/functions.php	Sat Jul 27 17:42:06 2013 -0400
+++ b/public_html/layout/modern_curve/functions.php	Sat Jul 27 17:57:04 2013 -0400
@@ -46,7 +46,8 @@
 {
     return array(
         'image_type' => 'png',
-        'doctype' => 'xhtml10strict', 
+        'doctype' => 'xhtml10strict',
+        'etag' => true,
         'supported_version_theme' => '2.0.0' // support new theme format for the later Geeklog 2.0.0
     );
 }
@@ -57,14 +58,57 @@
 function theme_css_modern_curve()
 {
     global $_CONF, $LANG_DIRECTION;
-    
-    return array(
+         
+    /* // Sample css settings
+    return array(        
          array(
              'name' => 'theme', // Not required but if set to theme then will always be loaded first
              'file' => '/layout/' . $_CONF['theme'] . '/style.css.php?dir=' . $LANG_DIRECTION, 
              'attributes' => array('media' => 'all'), // Not requred
              'priority'   => 100  // Not requred, default = 100
          )
+    );         
+     */    
+
+    // Instead of importing all files in a single css file we will load them seperately 
+    // since each file needs to be processed by style.css.php for language template vars
+    return array(
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/compatible.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/default.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/common.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/layout.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/block.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/option.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/form.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/story.css'),
+         
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/article/article.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/comment/comment.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/navbar/navbar.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/preferences/preferences.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/search/search.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/stats/stats.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/submit/submit.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/trackback/trackback.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/users/users.css'),
+         
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/common.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/block.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/envcheck.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/group.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/lists.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/commandcontrol.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/plugins.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/story.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/topic.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/trackback.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/user.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/admin/configuration.css'),
+         
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/plugin/japanize.css'),
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/plugin/sitecalendar.css'),
+         
+         array('file' => '/layout/' . $_CONF['theme'] . '/css/tooltips/tooltips.css'),
     );
 }
 
diff -r 937b29cc613b -r 41567b113ad0 public_html/layout/modern_curve/style.css.php
--- a/public_html/layout/modern_curve/style.css.php	Sat Jul 27 17:42:06 2013 -0400
+++ b/public_html/layout/modern_curve/style.css.php	Sat Jul 27 17:57:04 2013 -0400
@@ -31,15 +31,12 @@
 
 require_once '../../siteconfig.php';
 
-$theme = 'modern_curve'; // Theme Name
-$default_theme = ''; // Default theme name. If nothing leave as blank string
-$path_themes = '../'; // Assumes the default if not then change
-
-$css_path_default='';
-if (!empty($default_theme)) {
-    $css_path_default = $path_themes . $default_theme . '/css/';
+// Get theme
+if (isset($_GET['theme'])) {
+    $theme = $_GET['theme'];
+} else {
+    exit();
 }
-$css_path = $path_themes . $theme . '/css/';
 
 // Create directions for RTL support
 $left  = 'left';
@@ -51,10 +48,88 @@
     $right = 'left';
     $dir = 'rtl';
 }
+$LANG_DIRECTION = $dir; // Need to set this for themes function.php file
+
+// Set Path Variables
+$path_html = $_CONF['path'] . 'public_html';
+$path_themes = $path_html . '/layout/'; 
+$path_layout = $path_themes . $theme . '/';
+
+/**
+* Get Theme Info
+*/
+if (file_exists($path_layout . 'functions.php')) {
+    require_once $path_layout . 'functions.php';
+} else {
+    exit;    
+}
+
+/**
+ * Get the configuration values from the theme
+ */
+$theme_default = ''; // Default is none
+$path_layout_default = ''; // Default is none
+$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')) {
+        require_once $path_layout_default . 'functions.php';
+    } else {
+        exit;    
+    }
+    
+    /* 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)) {
+        foreach ($func() as $info) {
+            $info['priority'] = (!empty($info['priority']))   ? $info['priority']   : 100;
+            $cssfiles[] = $info;
+        }
+    }        
+}
+/* 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)) {
+    foreach ($func() as $info) {
+        $info['priority'] = (!empty($info['priority']))   ? $info['priority']   : 100;
+        $cssfiles[] = $info;
+    }
+}
+/*
+// Sort CSS Files based on priority if needed
+$priority = array();
+foreach($cssfiles as $k => $d) {
+  $priority[$k] = $d['priority'];
+}
+array_multisort($priority, SORT_ASC, $cssfiles);
+*/
+// Add in custom.css at end after sort
+if (!empty($theme_default)) {
+    $info = array();
+    $info['file'] = '/layout/' . $theme_default . '/custom.css';
+    $info['priority'] = 1000;
+    $cssfiles[] = $info;
+}
+$info = array();
+$info['file'] = '/layout/' . $theme . '/custom.css';
+$info['priority'] = 1000;
+$cssfiles[] = $info;
 
 // We assume /data directory is right under $_CONF['path'] directory.  If you
 // have moved or renamed /data directory, please change the following line accordingly.
-$etag_filename =  $_CONF['path'] . 'data/' . $theme . '_' . $dir . '_etag.cache';
+$etag_filename =  $_CONF['path'] . 'data/layout_css/' . $theme . '_' . $dir . '_etag.cache';
 
 if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
     if (is_readable($etag_filename)) {
@@ -76,62 +151,27 @@
 header('Content-Type: text/css; charset=UTF-8');
 header('ETag: "' . $etag . '"');
 
-// List of CSS files to be loaded
-$files = array(
-    'compatible.css',
-    'default.css',
-    'common.css',
-    'layout.css',
-    'block.css',
-    'option.css',
-    'form.css',
-    'story.css',
+// 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'];  
 
-    'article/article.css',
-    'comment/comment.css',
-    'navbar/navbar.css',
-    'preferences/preferences.css',
-    'search/search.css',
-    'stats/stats.css',
-    'submit/submit.css',
-    'trackback/trackback.css',
-    'users/users.css',
-
-    'admin/common.css',
-    'admin/block.css',
-    'admin/envcheck.css',
-    'admin/group.css',
-    'admin/lists.css',
-    'admin/commandcontrol.css',
-    'admin/plugins.css',
-    'admin/story.css',
-    'admin/topic.css',
-    'admin/trackback.css',
-    'admin/user.css',
-    'admin/configuration.css',
-
-    'plugin/japanize.css',
-    'plugin/sitecalendar.css',
-
-    'tooltips/tooltips.css', 
-    
-    'custom.css'
-);
-
-// Output the contents of each file
-foreach ($files as $file) {
-    $full_filepath = '';
-    if (!empty($default_theme)) {
+    if (!empty($theme_default)) {
         // First add own theme css file if found else add default css file
-        if (is_readable($css_path . $file)) {
-            $full_filepath = $css_path . $file;
-        } elseif (is_readable($css_path_default . $file)) {
-            $full_filepath = $css_path_default . $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_path . $file)) {
-            $full_filepath = $css_path . $file;
+        if (is_readable($css_file)) {
+            $full_filepath = $css_file;
         }
     }
     
@@ -141,7 +181,7 @@
         $css = preg_replace("@\s*\n+\s*@sm", "\n", $css); // strip indentation
     
         // Replace {right} and {left} placeholders with actual values.
-        // Used for RTL support.
+        // Used for RTL support in some themes.
         $css = str_replace('{right}', $right, $css);
         $css = str_replace('{left}', $left, $css);
     
diff -r 937b29cc613b -r 41567b113ad0 public_html/lib-common.php
--- a/public_html/lib-common.php	Sat Jul 27 17:42:06 2013 -0400
+++ b/public_html/lib-common.php	Sat Jul 27 17:57:04 2013 -0400
@@ -348,6 +348,7 @@
 $_CONF['theme_default'] = ''; // Default is none
 $_CONF['path_layout_default'] = ''; // Default is none
 $_CONF['supported_version_theme'] = '1.8.1'; // if the themes supported version of the theme engine not found assume lowest version
+$_CONF['theme_etag'] = false;
 $func = "theme_config_" . $_CONF['theme'];
 if (function_exists($func)) {
     $theme_config = $func();
@@ -357,9 +358,8 @@
         $_CONF['theme_default'] = $theme_config['theme_default'];
         $_CONF['path_layout_default'] = $_CONF['path_themes'] . $_CONF['theme_default'] . '/';



More information about the geeklog-cvs mailing list