[geeklog-hg] geeklog: For Staticpage plugin added default cache time for new ...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Thu Oct 24 06:58:04 EDT 2013


changeset 9323:d21ade11962e
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/d21ade11962e
user: Tom <websitemaster at cogeco.net>
date: Thu Oct 24 06:57:25 2013 -0400
description:
For Staticpage plugin added default cache time for new pages. Added ability to have page always cached and never regenerated until page is edited

diffstat:

 plugins/staticpages/configuration_validation.php |   2 ++
 plugins/staticpages/functions.inc                |  16 ++++++++++------
 plugins/staticpages/install_defaults.php         |   8 ++++++++
 plugins/staticpages/install_updates.php          |  18 ++++++++++++++++++
 plugins/staticpages/language/english.php         |   3 ++-
 plugins/staticpages/language/english_utf-8.php   |   3 ++-
 plugins/staticpages/services.inc.php             |   8 ++++----
 public_html/docs/english/staticpages.html        |  11 +++++++++++
 public_html/docs/japanese/staticpages.html       |  13 ++++++++++++-
 9 files changed, 69 insertions(+), 13 deletions(-)

diffs (218 lines):

diff -r ce4684a09ccc -r d21ade11962e plugins/staticpages/configuration_validation.php
--- a/plugins/staticpages/configuration_validation.php	Thu Oct 24 06:53:57 2013 -0400
+++ b/plugins/staticpages/configuration_validation.php	Thu Oct 24 06:57:25 2013 -0400
@@ -60,6 +60,8 @@
     'rule' => array('inList', array('0', '-1'), true)
 );
 $_CONF_VALIDATE['staticpages']['draft_flag'] = array('rule' => 'boolean');
+$_CONF_VALIDATE['staticpages']['disable_breadcrumbs_staticpages'] = array('rule' => 'boolean');
+$_CONF_VALIDATE['staticpages']['default_cache_time'] = array('rule' => 'numeric');
 
 // What's New Block
 $_CONF_VALIDATE['staticpages']['newstaticpagesinterval'] = array('rule' => 'numeric');
diff -r ce4684a09ccc -r d21ade11962e plugins/staticpages/functions.inc
--- a/plugins/staticpages/functions.inc	Thu Oct 24 06:53:57 2013 -0400
+++ b/plugins/staticpages/functions.inc	Thu Oct 24 06:57:25 2013 -0400
@@ -1479,6 +1479,8 @@
                     DB_query($sql);
                 }
             }
+            
+            SP_update_ConfValues_1_6_5();
 
             $current_version = '1.6.6';
             break;             
@@ -1685,14 +1687,16 @@
     $retval = '';
     
     // Retrieve non php staticpage from cache
-    if ($cache_time > 0 AND $sp_php == 0) {
+    if ($cache_time > -1 AND $sp_php == 0) {
         // Don't need to cache per theme since not rendered in a block yet 
         $cacheInstance = 'staticpage__' . $sp_id . '__' . CACHE_security_hash();
-        $retval = CACHE_check_instance($cacheInstance, 0);
-        if ($retval) {
-            $lu = CACHE_get_instance_update($cacheInstance, 0);
+        $retval = CACHE_check_instance($cacheInstance);
+        if ($retval AND $cache_time == -1) {
+            return $retval;
+        } elseif ($retval AND $cache_time > 0) {        
+            $lu = CACHE_get_instance_update($cacheInstance);
             $now = time();
-            if (($now - $lu) < $cache_time ) {
+            if (($now - $lu) < $cache_time) {
                 return $retval;
             } else {
                 $retval = '';
@@ -1762,7 +1766,7 @@
     
     $sp_content = stripslashes($sp_content);
 
-    if ($cache_time > 0 AND $sp_php == 0) { CACHE_create_instance($cacheInstance, $sp_content, 0); }
+    if (($cache_time > 0 OR $cache_time == -1) AND $sp_php == 0) { CACHE_create_instance($cacheInstance, $sp_content); }
     
     return $sp_content;
 }
diff -r ce4684a09ccc -r d21ade11962e plugins/staticpages/install_defaults.php
--- a/plugins/staticpages/install_defaults.php	Thu Oct 24 06:53:57 2013 -0400
+++ b/plugins/staticpages/install_defaults.php	Thu Oct 24 06:57:25 2013 -0400
@@ -124,6 +124,12 @@
 // Whether to display breadcrumbs on staticpages
 $_SP_DEFAULT['disable_breadcrumbs_staticpages'] = 0;
 
+// The default cache time for a staticpage. Possible values:
+// 1 or more = Amount of seconds a static page will be cached before it is regenerated and saved again to a new cache file
+//  0 = Not cached. Page is always regenerated
+// -1 = Always cached and only regenerated when the page is updated and saved through the edit staticpage editor
+$_SP_DEFAULT['default_cache_time'] = 0;
+
 // Define default permissions for new pages created from the Admin panel.
 // Permissions are perm_owner, perm_group, perm_members, perm_anon (in that
 // order). Possible values:
@@ -198,6 +204,8 @@
                 0, 0, 0, 127, true, 'staticpages', 0);
         $c->add('disable_breadcrumbs_staticpages', $_SP_DEFAULT['disable_breadcrumbs_staticpages'], 'select',
                 0, 0, 0, 128, true, 'staticpages', 0);        
+        $c->add('default_cache_time', $_SP_DEFAULT['default_cache_time'], 'text',
+                0, 0, null, 129, true, 'staticpages', 0);
 
         $c->add('tab_whatsnew', NULL, 'tab', 0, 1, NULL, 0, true, 'staticpages', 1);
         $c->add('fs_whatsnew', NULL, 'fieldset', 0, 1, NULL, 0, true, 'staticpages', 1);
diff -r ce4684a09ccc -r d21ade11962e plugins/staticpages/install_updates.php
--- a/plugins/staticpages/install_updates.php	Thu Oct 24 06:53:57 2013 -0400
+++ b/plugins/staticpages/install_updates.php	Thu Oct 24 06:57:25 2013 -0400
@@ -73,4 +73,22 @@
     return true;
 }
 
+
+function SP_update_ConfValues_1_6_5()
+{
+    global $_CONF, $_TABLES, $_SP_DEFAULT;
+
+    require_once $_CONF['path_system'] . 'classes/config.class.php';
+
+    $c = config::get_instance();
+
+    require_once $_CONF['path'] . 'plugins/staticpages/install_defaults.php';
+
+    // Cache Time
+    $c->add('default_cache_time', $_SP_DEFAULT['default_cache_time'], 'text',
+            0, 0, null, 129, true, 'staticpages', 0);
+    
+    return true;
+}
+
 ?>
\ No newline at end of file
diff -r ce4684a09ccc -r d21ade11962e plugins/staticpages/language/english.php
--- a/plugins/staticpages/language/english.php	Thu Oct 24 06:53:57 2013 -0400
+++ b/plugins/staticpages/language/english.php	Thu Oct 24 06:57:25 2013 -0400
@@ -122,7 +122,7 @@
     'draft_yes' => 'Yes',
     'draft_no' => 'No', 
     'cache_time'        => 'Cache Time',
-    'cache_time_desc'   => 'This staticpage content will be cached for no longer than this many seconds. If 0 caching is disabled (3600 = 1 hour,  86400 = 1 day). Staticpages with PHP enabled or are a template will not be cached.',
+    'cache_time_desc'   => 'This staticpage content will be cached for no longer than this many seconds. If 0 caching is disabled. If -1 cached until page is edited again. Staticpages with PHP enabled or are a template will not be cached. (3600 = 1 hour,  86400 = 1 day)',
     'autotag_desc_staticpage' => '[staticpage: id alternate title] - Displays a link to a static page using the static page title as the title. An alternate title may be specified but is not required.',
     'autotag_desc_staticpage_content' => '[staticpage_content: id] - Displays the contents of a staticpage.'
 );
@@ -163,6 +163,7 @@
     'comment_code' => 'Comment Default',
     'draft_flag' => 'Draft Flag Default',
     'disable_breadcrumbs_staticpages' => 'Disable Breadcrumbs',
+    'default_cache_time' => 'Default Cache Time',
     'newstaticpagesinterval' => 'New Static Page Interval',
     'hidenewstaticpages' => 'New Static Pages',
     'title_trim_length' => 'Title Trim Length',
diff -r ce4684a09ccc -r d21ade11962e plugins/staticpages/language/english_utf-8.php
--- a/plugins/staticpages/language/english_utf-8.php	Thu Oct 24 06:53:57 2013 -0400
+++ b/plugins/staticpages/language/english_utf-8.php	Thu Oct 24 06:57:25 2013 -0400
@@ -122,7 +122,7 @@
     'draft_yes' => 'Yes',
     'draft_no' => 'No',
     'cache_time'        => 'Cache Time',
-    'cache_time_desc'   => 'This staticpage content will be cached for no longer than this many seconds. If 0 caching is disabled (3600 = 1 hour,  86400 = 1 day). Staticpages with PHP enabled or are a template will not be cached.',
+    'cache_time_desc'   => 'This staticpage content will be cached for no longer than this many seconds. If 0 caching is disabled. If -1 cached until page is edited again. Staticpages with PHP enabled or are a template will not be cached. (3600 = 1 hour,  86400 = 1 day)',
     'autotag_desc_staticpage' => '[staticpage: id alternate title] - Displays a link to a static page using the static page title as the title. An alternate title may be specified but is not required.',
     'autotag_desc_staticpage_content' => '[staticpage_content: id] - Displays the contents of a staticpage.'
 );
@@ -163,6 +163,7 @@
     'comment_code' => 'Comment Default',
     'draft_flag' => 'Draft Flag Default',
     'disable_breadcrumbs_staticpages' => 'Disable Breadcrumbs',
+    'default_cache_time' => 'Default Cache Time',
     'newstaticpagesinterval' => 'New Static Page Interval',
     'hidenewstaticpages' => 'New Static Pages',
     'title_trim_length' => 'Title Trim Length',
diff -r ce4684a09ccc -r d21ade11962e plugins/staticpages/services.inc.php
--- a/plugins/staticpages/services.inc.php	Thu Oct 24 06:53:57 2013 -0400
+++ b/plugins/staticpages/services.inc.php	Thu Oct 24 06:57:25 2013 -0400
@@ -229,7 +229,7 @@
         }
         
         if (empty($args['cache_time'])) {
-            $args['cache_time'] = 0;
+            $args['cache_time'] = $_SP_CONF['default_cache_time'];;
         }        
         
         if (empty($args['template_flag'])) {
@@ -394,11 +394,11 @@
         
         // If PHP page then no cache
         if ($sp_php == 0) {
-            if ($cache_time < 0) {
-                $cache_time = 0;
+            if ($cache_time < -1) {
+                $cache_time = $_SP_CONF['default_cache_time'];
             }
         } else {
-            $cache_time = 0;
+            $cache_time = $_SP_CONF['default_cache_time'];
         }
         
         // If marked as a template then set id to nothing and other default settings
diff -r ce4684a09ccc -r d21ade11962e public_html/docs/english/staticpages.html
--- a/public_html/docs/english/staticpages.html	Thu Oct 24 06:53:57 2013 -0400
+++ b/public_html/docs/english/staticpages.html	Thu Oct 24 06:57:25 2013 -0400
@@ -253,6 +253,17 @@
   <td>0</td>
   <td>Whether the page's breadcrumbs should be displayed (0) or not (1).</td>
 </tr>
+<tr class="r2">
+  <td><a name="desc_default_cache_time">default_cache_time</a></td>
+  <td>0</td>
+  <td>The default cache time for a staticpage. Possible values:<br>
+    <ul>
+        <li>1 or more = Amount of seconds a static page will be cached before it is regenerated and saved again to a new cache file.</li>
+        <li>0 = Not cached. Page is always regenerated.</li>
+        <li>-1 = Always cached and only regenerated when the page is updated and saved through the staticpage editor.</li>
+    </ul>
+</td>
+</tr>
 </table>
 
 <h3><a name="whatsnew">What's New Block</a></h3>
diff -r ce4684a09ccc -r d21ade11962e public_html/docs/japanese/staticpages.html
--- a/public_html/docs/japanese/staticpages.html	Thu Oct 24 06:53:57 2013 -0400
+++ b/public_html/docs/japanese/staticpages.html	Thu Oct 24 06:57:25 2013 -0400
@@ -243,7 +243,18 @@
   <td>0</td>
   <td>パンくずリストを無効(0)、または有効(1)にします。</td>
 </tr>
-
+<tr class="r2">
+  <td><a name="desc_default_cache_time">default_cache_time</a></td>
+  <td>0</td>
+  <td>The default cache time for a staticpage. Possible values:<br>
+    <ul>
+        <li>1 or more = Amount of seconds a static page will be cached before it is regenerated and saved again to a new cache file.</li>
+        <li>0 = Not cached. Page is always regenerated.</li>
+        <li>-1 = Always cached and only regenerated when the page is updated and saved through the staticpage editor.</li>
+    </ul>
+</td>
+</tr>
+</table>
 
 <h3><a name="whatsnew">新着ブロック</a></h3>
 



More information about the geeklog-cvs mailing list