[geeklog-hg] geeklog: Staticpages that do not execute php can now be cached.
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Thu Jul 11 19:34:34 EDT 2013
changeset 9171:ac56c2abe522
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/ac56c2abe522
user: Tom <websitemaster at cogeco.net>
date: Tue Jul 09 15:10:01 2013 -0400
description:
Staticpages that do not execute php can now be cached.
diffstat:
plugins/staticpages/functions.inc | 105 +++++++++++--
plugins/staticpages/language/english.php | 2 +
plugins/staticpages/language/english_utf-8.php | 4 +-
plugins/staticpages/services.inc.php | 86 ++++-------
plugins/staticpages/sql/mssql_install.php | 2 +
plugins/staticpages/sql/mssql_updates.php | 4 +
plugins/staticpages/sql/mysql_install.php | 1 +
plugins/staticpages/sql/mysql_updates.php | 6 +-
plugins/staticpages/sql/pgsql_install.php | 1 +
plugins/staticpages/sql/pgsql_updates.php | 6 +-
plugins/staticpages/templates/admin/editor.thtml | 9 +-
plugins/staticpages/templates/admin/editor_advanced.thtml | 9 +-
plugins/staticpages/templates/centerblock.thtml | 4 +
plugins/staticpages/templates/spcomments.thtml | 4 +
plugins/staticpages/templates/staticpage.thtml | 4 +
public_html/admin/plugins/staticpages/index.php | 14 +-
system/lib-template.php | 16 +-
17 files changed, 192 insertions(+), 85 deletions(-)
diffs (truncated from 686 to 300 lines):
diff -r 53915d861ebc -r ac56c2abe522 plugins/staticpages/functions.inc
--- a/plugins/staticpages/functions.inc Sun Jul 07 09:44:54 2013 -0400
+++ b/plugins/staticpages/functions.inc Tue Jul 09 15:10:01 2013 -0400
@@ -315,7 +315,10 @@
$retval = '';
// get content
- $content = SP_render_content(stripslashes($A['sp_content']), $A['sp_php'], $query);
+ $content = $A['sp_content'];
+ if (!empty($query)) {
+ $content = COM_highlightQuery($content, $query);
+ }
if ($A['sp_format'] == 'blankpage') {
// The format is "blank page", only return the content of the page - nothing else.
@@ -545,8 +548,7 @@
. '/staticpages/index.php?page=' . $page);
$print->set_var('sp_url', $sp_url);
$print->set_var('sp_title', stripslashes($A['sp_title']));
- $print->set_var('sp_content',
- SP_render_content(stripslashes($A['sp_content']), $A['sp_php']));
+ $print->set_var('sp_content', $A['sp_content']);
$author_name = COM_getDisplayName($A['owner_id']);
$author_username = DB_getItem($_TABLES['users'], 'username',
@@ -671,7 +673,7 @@
if ($mode == 'print') {
$retval = SP_printPage($page, $retval);
} elseif ($mode =='autotag') {
- $retval = SP_render_content(stripslashes($retval['sp_content']), $retval['sp_php']);
+ $retval = $retval['sp_content'];
} else {
$retval = SP_displayPage($page, $retval, $comment_order, $comment_mode, $comment_page, $msg, $query);
}
@@ -1135,7 +1137,7 @@
$svc_msg = array();
if (PLG_invokeService('staticpages', 'get', $args, $SP_retval, $svc_msg) == PLG_RET_OK) {
- $content = SP_render_content(stripslashes($SP_retval['sp_content']), $SP_retval['sp_php']);
+ $content = $SP_retval['sp_content'];
}
$spage->set_var('content', $content);
@@ -1472,6 +1474,17 @@
$current_version = '1.6.5';
break;
+
+ case '1.6.5':
+ if (isset($_UPDATES[$current_version])) {
+ $_SQL = $_UPDATES[$current_version];
+ foreach ($_SQL as $sql) {
+ DB_query($sql);
+ }
+ }
+
+ $current_version = '1.6.6';
+ break;
default:
$done = true;
@@ -1660,19 +1673,77 @@
/**
* Render the actual content of a static page (without any surrounding blocks)
*
-* @param string $sp_content the content (HTML or PHP source)
-* @param int $sp_php flag: 1 = content is PHP source, 0 = is HTML
-* @param string $query optional search query string to highlight
-* @return string rendered content (HTML)
+* @param string $sp_id the id
+* @param string $sp_content the content (HTML or PHP source)
+* @param int $sp_php flag: 1 = content is PHP source, 0 = is HTML
+* @param int $cache_time the max cache time of this page
+* @param string $template_id the max cache time of this page
+* @return string rendered content (HTML)
*
*/
-function SP_render_content($sp_content, $sp_php, $query = '')
+function SP_render_content($sp_id, $sp_content, $sp_php, $cache_time = 0, $template_id = '')
{
global $_SP_CONF, $LANG_STATIC;
$retval = '';
-
+
+ // Retrieve non php staticpage from cache
+ if ($cache_time > 0 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);
+ $now = time();
+ if (($now - $lu) < $cache_time ) {
+ return $retval;
+ } else {
+ $retval = '';
+ }
+ }
+ }
+
+ // See if uses template, if so get it
+ if ($template_id != '') {
+
+ $retval = '';
+ $mode = '';
+
+ $xmlObject = simplexml_load_string($sp_content);
+
+ // create array of XML data
+ $tag = array();
+ foreach($xmlObject->variable as $variable) {
+ $key = $variable["name"] . '';
+ $value = $variable->data;
+ $tag[$key] = $value;
+ }
+
+ // Loop through variables to replace any autotags first
+ foreach ($tag as &$value) {
+ $value = PLG_replaceTags($value);
+ }
+
+ $args = array(
+ 'sp_id' => $template_id,
+ 'mode' => $mode,
+ 'template' => true, // tells service that it is okay to retrieve a template staticpage since requested by another staticpage
+ 'gl_svc' => ''
+ );
+ $svc_msg = array();
+
+ if (PLG_invokeService('staticpages', 'get', $args, $retval, $svc_msg) == PLG_RET_OK) {
+ $retval['sp_content'] = str_replace(array_keys($tag), array_values($tag), $retval['sp_content']);
+ // Remove any unknown staticpage template variables as long as they use the curly brackets ie {templatevariable}
+ // If template variable format is different then any unused ones will display
+ $retval['sp_content'] = preg_replace('/{[^ \t\r\n}]+}/', '', $retval['sp_content']);
+
+ $sp_content = $retval['sp_content'];
+ }
+ }
+
if ($_SP_CONF['allow_php'] == 1) {
+
// Check for type (ie html or php)
if ($sp_php == 1) {
$retval = eval($sp_content);
@@ -1685,21 +1756,19 @@
$retval = $sp_content;
}
$retval = PLG_replaceTags($retval);
- if (! empty($query)) {
- $retval = COM_highlightQuery($retval, $query);
- }
} else {
if ($sp_php != 0) {
COM_errorLog("PHP in static pages is disabled. Can not display page.", 1);
$retval .= $LANG_STATIC['deny_msg'];
} else {
$retval .= PLG_replaceTags($sp_content);
- if (! empty($query)) {
- $retval = COM_highlightQuery($retval, $query);
- }
}
}
+
+ $sp_content = stripslashes($sp_content);
+ if ($cache_time > 0 AND $sp_php == 0) { CACHE_create_instance($cacheInstance, $retval, 0); }
+
return $retval;
}
@@ -2018,7 +2087,7 @@
$svc_msg = array();
if (PLG_invokeService('staticpages', 'get', $args, $retval, $svc_msg) == PLG_RET_OK) {
- $props[$p] = SP_render_content(stripslashes($retval['sp_content']), $retval['sp_php']);
+ $props[$p] = $retval['sp_content'];
}
break;
case 'id':
diff -r 53915d861ebc -r ac56c2abe522 plugins/staticpages/language/english.php
--- a/plugins/staticpages/language/english.php Sun Jul 07 09:44:54 2013 -0400
+++ b/plugins/staticpages/language/english.php Tue Jul 09 15:10:01 2013 -0400
@@ -121,6 +121,8 @@
'draft' => 'Draft',
'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.',
'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.'
);
diff -r 53915d861ebc -r ac56c2abe522 plugins/staticpages/language/english_utf-8.php
--- a/plugins/staticpages/language/english_utf-8.php Sun Jul 07 09:44:54 2013 -0400
+++ b/plugins/staticpages/language/english_utf-8.php Tue Jul 09 15:10:01 2013 -0400
@@ -120,7 +120,9 @@
'use_template_msg' => 'If this Static Page is not a template, you can assign it to use a template. If a selection is made then remember that the content of this page must follow the proper XML format.',
'draft' => 'Draft',
'draft_yes' => 'Yes',
- 'draft_no' => 'No',
+ '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.',
'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.'
);
diff -r 53915d861ebc -r ac56c2abe522 plugins/staticpages/services.inc.php
--- a/plugins/staticpages/services.inc.php Sun Jul 07 09:44:54 2013 -0400
+++ b/plugins/staticpages/services.inc.php Tue Jul 09 15:10:01 2013 -0400
@@ -228,6 +228,10 @@
$args['draft_flag'] = 'on';
}
+ if (empty($args['cache_time'])) {
+ $args['cache_time'] = 0;
+ }
+
if (empty($args['template_flag'])) {
$args['template_flag'] = '';
}
@@ -273,6 +277,7 @@
$sp_old_id = $args['sp_old_id'];
$sp_centerblock = $args['sp_centerblock'];
$draft_flag = $args['draft_flag'];
+ $cache_time = $args['cache_time'];
$template_flag = $args['template_flag'];
$template_id = $args['template_id'];
$sp_help = '';
@@ -387,6 +392,15 @@
$sp_php = 0;
}
+ // If PHP page then no cache
+ if ($sp_php == 0) {
+ if ($cache_time < 0) {
+ $cache_time = 0;
+ }
+ } else {
+ $cache_time = 0;
+ }
+
// If marked as a template then set id to nothing and other default settings
if ($template_flag == 1) {
$template_id = '';
@@ -395,6 +409,7 @@
$sp_label = "";
$sp_centerblock = 0;
$sp_php = 0;
+ $cache_time = 0;
$sp_inblock = 0;
$sp_nf = 0;
@@ -467,9 +482,9 @@
$datecreated = date('Y-m-d H:i:s');
}
- DB_save($_TABLES['staticpage'], 'sp_id,sp_title,sp_page_title, sp_content,created,modified,sp_hits,sp_format,sp_onmenu,sp_label,commentcode,meta_description,meta_keywords,template_flag,template_id,draft_flag,owner_id,group_id,'
+ DB_save($_TABLES['staticpage'], 'sp_id,sp_title,sp_page_title, sp_content,created,modified,sp_hits,sp_format,sp_onmenu,sp_label,commentcode,meta_description,meta_keywords,template_flag,template_id,draft_flag,cache_time,owner_id,group_id,'
.'perm_owner,perm_group,perm_members,perm_anon,sp_php,sp_nf,sp_centerblock,sp_help,sp_where,sp_inblock,postmode',
- "'$sp_id','$sp_title','$sp_page_title','$sp_content','$datecreated',NOW(),$sp_hits,'$sp_format',$sp_onmenu,'$sp_label','$commentcode','$meta_description','$meta_keywords',$template_flag,'$template_id',$draft_flag,$owner_id,$group_id,"
+ "'$sp_id','$sp_title','$sp_page_title','$sp_content','$datecreated',NOW(),$sp_hits,'$sp_format',$sp_onmenu,'$sp_label','$commentcode','$meta_description','$meta_keywords',$template_flag,'$template_id',$draft_flag,$cache_time,$owner_id,$group_id,"
."$perm_owner,$perm_group,$perm_members,$perm_anon,'$sp_php','$sp_nf',$sp_centerblock,'$sp_help',$sp_where,"
."'$sp_inblock','$postmode'");
@@ -603,6 +618,7 @@
'sp_hits',
'sp_format',
'draft_flag',
+ 'cache_time',
'owner_id',
'group_id',
'perm_owner',
@@ -667,7 +683,7 @@
if (! empty($perms)) {
$perms = ' AND ' . $perms;
}
-
+
// Topic Permissions
$topic_perms = COM_getTopicSQL('', 0, 'ta');
if ($topic_perms != "") {
@@ -686,8 +702,8 @@
$sql['mysql'] = "SELECT sp_title,sp_page_title,sp_content,sp_hits,created,modified,sp_format,"
. "commentcode,meta_description,meta_keywords,template_flag,template_id,draft_flag,"
. "owner_id,group_id,perm_owner,perm_group,"
- . "perm_members,perm_anon,sp_help,sp_php,"
- . "sp_inblock FROM {$_TABLES['staticpage']}, {$_TABLES['topic_assignments']} ta "
+ . "perm_members,perm_anon,sp_help,sp_php,sp_inblock,cache_time "
+ . "FROM {$_TABLES['staticpage']}, {$_TABLES['topic_assignments']} ta "
. "WHERE (sp_id = '$page')" . $perms
. " AND ta.type = 'staticpages' AND ta.id = sp_id " . $topic_perms;
$sql['mssql'] = "SELECT sp_title,sp_page_title,"
@@ -696,7 +712,7 @@
. "CAST(meta_description AS text) AS meta_description,"
. "CAST(meta_keywords AS text) AS meta_keywords,template_flag,template_id,draft_flag,"
. "owner_id,group_id,perm_owner,perm_group,perm_members,"
- . "perm_anon,sp_help,sp_php,sp_inblock "
+ . "perm_anon,sp_help,sp_php,sp_inblock,cache_time "
. "FROM {$_TABLES['staticpage']}, {$_TABLES['topic_assignments']} ta WHERE (sp_id = '$page')"
. $perms
More information about the geeklog-cvs
mailing list