[geeklog-hg] geeklog: Allowed individual Blocks to be cached for x number of ...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Mon Jul 1 11:33:50 EDT 2013
changeset 9154:0e50c0174dce
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/0e50c0174dce
user: Tom <websitemaster at cogeco.net>
date: Mon Jul 01 11:32:14 2013 -0400
description:
Allowed individual Blocks to be cached for x number of seconds
diffstat:
language/english.php | 4 +-
language/english_utf-8.php | 4 +-
public_html/admin/block.php | 35 +++++++--
public_html/docs/english/theme.html | 1 +
public_html/layout/denim/admin/block/blockeditor.thtml | 10 ++-
public_html/layout/modern_curve/admin/block/blockeditor.thtml | 4 +
public_html/layout/professional/admin/block/blockeditor.thtml | 8 ++
public_html/layout/professional_css/admin/block/blockeditor.thtml | 10 ++-
public_html/lib-common.php | 22 +++++-
sql/mssql_tableanddata.php | 1 +
sql/mysql_tableanddata.php | 1 +
sql/pgsql_tableanddata.php | 1 +
sql/updates/mssql_2.0.0_to_2.0.1.php | 3 +
sql/updates/mysql_2.0.0_to_2.0.1.php | 3 +
sql/updates/pgsql_2.0.0_to_2.0.1.php | 4 +
15 files changed, 93 insertions(+), 18 deletions(-)
diffs (truncated from 374 to 300 lines):
diff -r 766fd8b12539 -r 0e50c0174dce language/english.php
--- a/language/english.php Sun Jun 30 21:16:38 2013 -0400
+++ b/language/english.php Mon Jul 01 11:32:14 2013 -0400
@@ -769,7 +769,9 @@
66 => 'Autotags',
67 => 'Check to allow autotags',
68 => 'The feed for this portal block is too long to display. Please set a maximum number of articles to import for the block in the block setup screen, or a global maximum in Geeklog Configuration.',
- 69 => 'Plugin Name'
+ 69 => 'Plugin Name',
+ 'cache_time' => 'Cache Time',
+ 'cache_time_desc' => 'This block will be cached for no longer than this many seconds. If 0 caching is disabled. (3600 = 1 hour, 86400 = 1 day)'
);
###############################################################################
diff -r 766fd8b12539 -r 0e50c0174dce language/english_utf-8.php
--- a/language/english_utf-8.php Sun Jun 30 21:16:38 2013 -0400
+++ b/language/english_utf-8.php Mon Jul 01 11:32:14 2013 -0400
@@ -769,7 +769,9 @@
66 => 'Autotags',
67 => 'Check to allow autotags',
68 => 'The feed for this portal block is too long to display. Please set a maximum number of articles to import for the block in the block setup screen, or a global maximum in Geeklog Configuration.',
- 69 => 'Plugin Name'
+ 69 => 'Plugin Name',
+ 'cache_time' => 'Cache Time',
+ 'cache_time_desc' => 'This block will be cached for no longer than this many seconds. If 0 caching is disabled. (3600 = 1 hour, 86400 = 1 day)'
);
###############################################################################
diff -r 766fd8b12539 -r 0e50c0174dce public_html/admin/block.php
--- a/public_html/admin/block.php Sun Jun 30 21:16:38 2013 -0400
+++ b/public_html/admin/block.php Mon Jul 01 11:32:14 2013 -0400
@@ -179,7 +179,7 @@
$sql['mssql'] = "SELECT bid, is_enabled, name, type, title, blockorder, cast(content as text) as content, rdfurl, ";
$sql['mssql'] .= "rdfupdated, rdflimit, onleft, phpblockfn, help, owner_id,group_id, ";
- $sql['mssql'] .= "perm_owner, perm_group, perm_members, perm_anon, allow_autotags FROM {$_TABLES['blocks']} WHERE bid ='$bid'";
+ $sql['mssql'] .= "perm_owner, perm_group, perm_members, perm_anon, allow_autotags, cache_time FROM {$_TABLES['blocks']} WHERE bid ='$bid'";
$sql['pgsql'] = "SELECT * FROM {$_TABLES['blocks']} WHERE bid ='$bid'";
@@ -207,6 +207,7 @@
$A['title'] = '';
$A['tid'] = '';
$A['blockorder'] = 0;
+ $A['cache_time'] = 0;
$A['content'] = '';
$A['allow_autotags'] = 0;
$A['rdfurl'] = '';
@@ -292,6 +293,10 @@
} elseif ($A['type'] == 'portal') {
$block_templates->set_var('portal_selected', 'selected="selected"');
}
+ $block_templates->set_var('lang_cachetime', $LANG21['cache_time']);
+ $block_templates->set_var('lang_cachetime_desc', $LANG21['cache_time_desc']);
+ $block_templates->set_var('cache_time', $A['cache_time']);
+
$block_templates->set_var('lang_accessrights', $LANG_ACCESS['accessrights']);
$block_templates->set_var('lang_owner', $LANG_ACCESS['owner']);
$ownername = COM_getDisplayName ($A['owner_id']);
@@ -536,7 +541,7 @@
* @return string HTML redirect or error message
*
*/
-function saveblock($bid, $name, $title, $help, $type, $blockorder, $content, $rdfurl, $rdfupdated, $rdflimit, $phpblockfn, $onleft, $owner_id, $group_id, $perm_owner, $perm_group, $perm_members, $perm_anon, $is_enabled, $allow_autotags)
+function saveblock($bid, $name, $title, $help, $type, $blockorder, $content, $rdfurl, $rdfupdated, $rdflimit, $phpblockfn, $onleft, $owner_id, $group_id, $perm_owner, $perm_group, $perm_members, $perm_anon, $is_enabled, $allow_autotags, $cache_time)
{
global $_CONF, $_TABLES, $LANG01, $LANG21, $MESSAGE, $_USER;
@@ -587,6 +592,10 @@
} else {
$allow_autotags = 0;
}
+
+ if (empty($cache_time) OR $cache_time < 0) {
+ $cache_time = 0;
+ }
if ($type == 'portal') {
$content = '';
@@ -652,16 +661,16 @@
}
if ($bid > 0) {
- DB_save($_TABLES['blocks'],'bid,name,title,help,type,blockorder,content,rdfurl,rdfupdated,rdflimit,phpblockfn,onleft,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon,is_enabled,allow_autotags,rdf_last_modified,rdf_etag',"$bid,'$name','$title','$help','$type','$blockorder','$content','$rdfurl','$rdfupdated','$rdflimit','$phpblockfn',$onleft,$owner_id,$group_id,$perm_owner,$perm_group,$perm_members,$perm_anon,$is_enabled,$allow_autotags,NULL,NULL");
+ DB_save($_TABLES['blocks'],'bid,name,title,help,type,blockorder,content,rdfurl,rdfupdated,rdflimit,phpblockfn,onleft,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon,is_enabled,allow_autotags,cache_time,rdf_last_modified,rdf_etag',"$bid,'$name','$title','$help','$type','$blockorder','$content','$rdfurl','$rdfupdated','$rdflimit','$phpblockfn',$onleft,$owner_id,$group_id,$perm_owner,$perm_group,$perm_members,$perm_anon,$is_enabled,$allow_autotags,$cache_time,NULL,NULL");
} else {
$sql = array();
$sql['mysql'] = $sql['mssql'] = "INSERT INTO {$_TABLES['blocks']} "
- .'(name,title,help,type,blockorder,content,rdfurl,rdfupdated,rdflimit,phpblockfn,onleft,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon,is_enabled,allow_autotags) '
- ."VALUES ('$name','$title','$help','$type','$blockorder','$content','$rdfurl','$rdfupdated','$rdflimit','$phpblockfn',$onleft,$owner_id,$group_id,$perm_owner,$perm_group,$perm_members,$perm_anon,$is_enabled,$allow_autotags)";
+ .'(name,title,help,type,blockorder,content,rdfurl,rdfupdated,rdflimit,phpblockfn,onleft,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon,is_enabled,allow_autotags,cache_time) '
+ ."VALUES ('$name','$title','$help','$type','$blockorder','$content','$rdfurl','$rdfupdated','$rdflimit','$phpblockfn',$onleft,$owner_id,$group_id,$perm_owner,$perm_group,$perm_members,$perm_anon,$is_enabled,$allow_autotags,$cache_time)";
$sql['pgsql'] = "INSERT INTO {$_TABLES['blocks']} "
- .'(bid,name,title,help,type,blockorder,content,rdfurl,rdfupdated,rdflimit,phpblockfn,onleft,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon,is_enabled,allow_autotags) '
- ."VALUES ((SELECT NEXTVAL('{$_TABLES['blocks']}_bid_seq')),'$name','$title','$help','$type','$blockorder','$content','$rdfurl','$rdfupdated','$rdflimit','$phpblockfn',$onleft,$owner_id,$group_id,$perm_owner,$perm_group,$perm_members,$perm_anon,$is_enabled,$allow_autotags)";
+ .'(bid,name,title,help,type,blockorder,content,rdfurl,rdfupdated,rdflimit,phpblockfn,onleft,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon,is_enabled,allow_autotags,cache_time) '
+ ."VALUES ((SELECT NEXTVAL('{$_TABLES['blocks']}_bid_seq')),'$name','$title','$help','$type','$blockorder','$content','$rdfurl','$rdfupdated','$rdflimit','$phpblockfn',$onleft,$owner_id,$group_id,$perm_owner,$perm_group,$perm_members,$perm_anon,$is_enabled,$allow_autotags,$cache_time)";
DB_query($sql);
$bid = DB_insertId();
@@ -673,6 +682,9 @@
TOPIC_saveTopicSelectionControl('block', $bid);
+ $cacheInstance = 'block__' . $bid . '__'; // remove any of this blocks instances if exists
+ CACHE_remove_instance($cacheInstance);
+
return COM_refresh ($_CONF['site_admin_url'] . '/block.php?msg=11');
} else {
if (empty($name)) {
@@ -830,6 +842,9 @@
TOPIC_deleteTopicAssignments('block', $bid);
DB_delete ($_TABLES['blocks'], 'bid', $bid);
+
+ $cacheInstance = 'block__' . $bid . '__'; // remove any of this blocks instances if exists
+ CACHE_remove_instance($cacheInstance);
return COM_refresh ($_CONF['site_admin_url'] . '/block.php?msg=12');
}
@@ -900,6 +915,10 @@
if (isset ($_POST['allow_autotags'])) {
$allow_autotags = $_POST['allow_autotags'];
}
+ $cache_time = 0;
+ if (isset ($_POST['cache_time'])) {
+ $cache_time = COM_applyFilter ($_POST['cache_time'], true);
+ }
$display .= saveblock ($bid, $_POST['name'], $_POST['title'],
$help, $_POST['type'], $_POST['blockorder'], $content,
$rdfurl, $rdfupdated,
@@ -908,7 +927,7 @@
COM_applyFilter ($_POST['group_id'], true),
$_POST['perm_owner'], $_POST['perm_group'],
$_POST['perm_members'], $_POST['perm_anon'],
- $is_enabled, $allow_autotags);
+ $is_enabled, $allow_autotags, $cache_time);
} elseif ($mode == 'edit') {
$tmp = editblock($bid);
$display = COM_createHTMLDocument($tmp, array('pagetitle' => $LANG21[3]));
diff -r 766fd8b12539 -r 0e50c0174dce public_html/docs/english/theme.html
--- a/public_html/docs/english/theme.html Sun Jun 30 21:16:38 2013 -0400
+++ b/public_html/docs/english/theme.html Mon Jul 01 11:32:14 2013 -0400
@@ -223,6 +223,7 @@
<li>Changed list id of "admin-moderation" to "admin-commandcontrol". This affects the Denim, Modern Curve and Proffesional CSS themes.</li>
<li>Moved all images from <tt>/tooltips/images/</tt> to <tt>/images/tooltips/</tt> and updated all tooltip template files under the <tt>/tooltips/</tt> directory to reflect the change.</li>
<li>Moved all images from <tt>/navbar/images/</tt> to <tt>/images/navbar/</tt> and updated required css files (different for each theme). Removed unused images for navbar from Denim and Modern Curve themes.</li>
+<li>Updated <tt>/admin/blocks/blockeditor.thtml</tt> and added in cache_time labels and input.</li>
</ul>
<h2><a name="changes">Theme changes in Geeklog 2.0.0</a></h2>
diff -r 766fd8b12539 -r 0e50c0174dce public_html/layout/denim/admin/block/blockeditor.thtml
--- a/public_html/layout/denim/admin/block/blockeditor.thtml Sun Jun 30 21:16:38 2013 -0400
+++ b/public_html/layout/denim/admin/block/blockeditor.thtml Mon Jul 01 11:32:14 2013 -0400
@@ -1,5 +1,4 @@
-
-<!-- admin/block/blockeditor.thtml { -->
+{# begin {templatelocation} #}
{start_block_editor}
<form action="{site_admin_url}/block.php" method="post" id="admin-blockeditor" class="compact">
@@ -46,6 +45,10 @@
<option value="portal" {portal_selected}>{lang_portalblock}</option>
</select>
</dd>
+
+ <dt><label for="admin-blockeditor-cachetime">{lang_cachetime}</label></dt>
+ <dd><input type="text" size="8" value="{cache_time}" name="cache_time" id="admin-blockeditor-cachetime" class="size1"{xhtml}></dd>
+ <dd class="description">{lang_cachetime_desc}</dd>
</dl>
<fieldset>
@@ -115,4 +118,5 @@
</form>
{end_block}
-<!-- } admin/block/blockeditor.thtml -->
+
+{# end {templatelocation} #}
diff -r 766fd8b12539 -r 0e50c0174dce public_html/layout/modern_curve/admin/block/blockeditor.thtml
--- a/public_html/layout/modern_curve/admin/block/blockeditor.thtml Sun Jun 30 21:16:38 2013 -0400
+++ b/public_html/layout/modern_curve/admin/block/blockeditor.thtml Mon Jul 01 11:32:14 2013 -0400
@@ -45,6 +45,10 @@
<option value="portal" {portal_selected}>{lang_portalblock}</option>
</select>
</dd>
+
+ <dt><label for="admin-blockeditor-cachetime">{lang_cachetime}</label></dt>
+ <dd><input type="text" size="8" value="{cache_time}" name="cache_time" id="admin-blockeditor-cachetime" class="text"{xhtml}></dd>
+ <dd class="description">{lang_cachetime_desc}</dd>
</dl>
</div>
diff -r 766fd8b12539 -r 0e50c0174dce public_html/layout/professional/admin/block/blockeditor.thtml
--- a/public_html/layout/professional/admin/block/blockeditor.thtml Sun Jun 30 21:16:38 2013 -0400
+++ b/public_html/layout/professional/admin/block/blockeditor.thtml Mon Jul 01 11:32:14 2013 -0400
@@ -1,3 +1,5 @@
+{# begin {templatelocation} #}
+
{start_block_editor}
<form action="{site_admin_url}/block.php" method="post">
<table cellspacing="0" cellpadding="3" width="100%">
@@ -45,6 +47,10 @@
</td>
</tr>
<tr>
+ <td class="alignright" style="vertical-align:top">{lang_cachetime}:</td>
+ <td><input type="text" size="8" name="cache_time" value="{cache_time}"{xhtml}><div class="pluginMediumText">{lang_cachetime_desc}</div></td>
+ </tr>
+ <tr>
<td colspan="2"><hr{xhtml}></td>
</tr>
<tr>
@@ -128,3 +134,5 @@
</table>
</form>
{end_block}
+
+{# end {templatelocation} #}
diff -r 766fd8b12539 -r 0e50c0174dce public_html/layout/professional_css/admin/block/blockeditor.thtml
--- a/public_html/layout/professional_css/admin/block/blockeditor.thtml Sun Jun 30 21:16:38 2013 -0400
+++ b/public_html/layout/professional_css/admin/block/blockeditor.thtml Mon Jul 01 11:32:14 2013 -0400
@@ -1,5 +1,4 @@
-
-<!-- admin/block/blockeditor.thtml { -->
+{# begin {templatelocation} #}
{start_block_editor}
<form action="{site_admin_url}/block.php" method="post" id="admin-blockeditor" class="compact">
@@ -46,6 +45,10 @@
<option value="portal" {portal_selected}>{lang_portalblock}</option>
</select>
</dd>
+
+ <dt><label for="admin-blockeditor-cachetime">{lang_cachetime}</label></dt>
+ <dd><input type="text" size="8" value="{cache_time}" name="cache_time" id="admin-blockeditor-cachetime" class="text"{xhtml}></dd>
+ <dd class="description">{lang_cachetime_desc}</dd>
</dl>
</div>
@@ -116,4 +119,5 @@
</ul>
</form>
{end_block}
-<!-- } admin/block/blockeditor.thtml -->
+
+{# end {templatelocation} #}
diff -r 766fd8b12539 -r 0e50c0174dce public_html/lib-common.php
--- a/public_html/lib-common.php Sun Jun 30 21:16:38 2013 -0400
+++ b/public_html/lib-common.php Mon Jul 01 11:32:14 2013 -0400
@@ -4413,7 +4413,7 @@
}
}
- $blocksql['mssql'] = "SELECT bid, is_enabled, name, b.type, title, blockorder, cast(content as text) as content, ";
+ $blocksql['mssql'] = "SELECT bid, is_enabled, name, b.type, title, blockorder, cast(content as text) as content, cache_time, ";
$blocksql['mssql'] .= "rdfurl, rdfupdated, rdflimit, onleft, phpblockfn, help, owner_id, ";
$blocksql['mssql'] .= "group_id, perm_owner, perm_group, perm_members, perm_anon, allow_autotags,UNIX_TIMESTAMP(rdfupdated) AS date ";
@@ -4575,6 +4575,23 @@
if( $A['type'] == 'gldefault' )
{
$retval .= COM_showBlock( $A['name'], $A['help'], $A['title'], $position );
+ } else {
+ // The only time cache_time would not be set if for dynamic blocks (they can handle their own caching if needed)
+ // Don't Cache default blocks either
+ if (isset($A['cache_time']) AND $A['cache_time'] > 0) {
+
+ $cacheInstance = 'block__' . $A['bid'] . '__' . CACHE_security_hash() . '__' . $_CONF['theme'];
+ $retval = CACHE_check_instance($cacheInstance, 0);
+ if ($retval) {
+ $lu = CACHE_get_instance_update($cacheInstance, 0);
+ $now = time();
+ if (($now - $lu) < $A['cache_time'] ) {
+ return $retval;
+ } else {
+ $retval = '';
+ }
+ }
+ }
}
if( $A['type'] == 'phpblock' && !$noboxes )
@@ -4624,7 +4641,6 @@
// Hack: If the block content starts with a '<' assume it
// contains HTML and do not call COM_nl2br() which would only add
// unwanted <br> tags.
-
if (substr(trim($blockcontent), 0, 1) != '<') {
$blockcontent = COM_nl2br($blockcontent);
}
@@ -4640,6 +4656,8 @@
. $blockcontent . LB
. COM_endBlock(COM_getBlockTemplate($A['name'], 'footer', $position));
}
+ // Cache only if enabled and not gldefault or dynamic
+ if (isset($A['cache_time']) AND $A['cache_time'] > 0 AND $A['type'] != 'gldefault') { CACHE_create_instance($cacheInstance, $retval, 0); }
return $retval;
More information about the geeklog-cvs
mailing list