[geeklog-cvs] geeklog: Added the ability for Static Pages to use other Static ...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Fri Sep 17 09:54:45 EDT 2010


changeset 7975:f5141a9d84e2
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/f5141a9d84e2
user: Tom <websitemaster at cogeco.net>
date: Fri Sep 17 09:52:21 2010 -0400
description:
Added the ability for Static Pages to use other Static Pages as a template.

diffstat:

 plugins/staticpages/autoinstall.php                       |    2 +-
 plugins/staticpages/functions.inc                         |   46 +++--
 plugins/staticpages/language/english_utf-8.php            |    5 +
 plugins/staticpages/services.inc.php                      |  108 ++++++++++++-
 plugins/staticpages/sql/mssql_install.php                 |    2 +
 plugins/staticpages/sql/mssql_updates.php                 |    7 +-
 plugins/staticpages/sql/mysql_install.php                 |    2 +
 plugins/staticpages/sql/mysql_updates.php                 |    5 +
 plugins/staticpages/sql/pgsql_install.php                 |    4 +-
 plugins/staticpages/sql/pgsql_updates.php                 |   44 +++++
 plugins/staticpages/templates/admin/editor.thtml          |   11 +
 plugins/staticpages/templates/admin/editor_advanced.thtml |   11 +
 public_html/admin/plugins/staticpages/index.php           |   69 ++++++++-
 public_html/docs/history                                  |    2 +
 14 files changed, 285 insertions(+), 33 deletions(-)

diffs (truncated from 677 to 300 lines):

diff -r 5c2946db2f39 -r f5141a9d84e2 plugins/staticpages/autoinstall.php
--- a/plugins/staticpages/autoinstall.php	Fri Sep 10 13:20:31 2010 +0200
+++ b/plugins/staticpages/autoinstall.php	Fri Sep 17 09:52:21 2010 -0400
@@ -51,7 +51,7 @@
     $info = array(
         'pi_name'         => $pi_name,
         'pi_display_name' => $pi_display_name,
-        'pi_version'      => '1.6.2',
+        'pi_version'      => '1.6.3',
         'pi_gl_version'   => '1.6.1',
         'pi_homepage'     => 'http://www.geeklog.net/'
     );
diff -r 5c2946db2f39 -r f5141a9d84e2 plugins/staticpages/functions.inc
--- a/plugins/staticpages/functions.inc	Fri Sep 10 13:20:31 2010 +0200
+++ b/plugins/staticpages/functions.inc	Fri Sep 17 09:52:21 2010 -0400
@@ -102,7 +102,7 @@
         }
     }
 
-    $result = DB_query("SELECT sp_id, sp_label FROM {$_TABLES['staticpage']} WHERE (sp_onmenu = 1) AND (draft_flag = 0)" . COM_getPermSql('AND') . COM_getLangSql('sp_id', 'AND') . $order);
+    $result = DB_query("SELECT sp_id, sp_label FROM {$_TABLES['staticpage']} WHERE (sp_onmenu = 1) AND (draft_flag = 0) AND (template_flag = 0)" . COM_getPermSql('AND') . COM_getLangSql('sp_id', 'AND') . $order);
     $nrows = DB_numRows($result);
 
     $menuitems = array();
@@ -136,7 +136,7 @@
     $sql = "SELECT COUNT(*) AS count, commentcode, owner_id, group_id, perm_owner, "
         . "perm_group, perm_members, perm_anon "
         . "FROM {$_TABLES['staticpage']} "
-        . "WHERE (sp_id = '$id') AND (draft_flag = 0)" . COM_getPermSQL('AND')
+        . "WHERE (sp_id = '$id') AND (draft_flag = 0) AND (template_flag = 0)" . COM_getPermSQL('AND')
         . ' GROUP BY sp_id';
     $result = DB_query($sql);
     $A = DB_fetchArray($result);
@@ -177,7 +177,7 @@
     $retval = '';
 
     $commentcode = DB_getItem($_TABLES['staticpage'], 'commentcode',
-                              "(sp_id = '$id') AND (draft_flag = 0)");
+                              "(sp_id = '$id') AND (draft_flag = 0) AND (template_flag = 0)");
     if ($commentcode != 0) {
         return COM_refresh($_CONF['site_url'] . '/index.php');
     }
@@ -256,7 +256,7 @@
         } else {
             $perms .= ' AND';
         }
-        $perms .= ' (draft_flag = 0)';
+        $perms .= ' (draft_flag = 0) AND (template_flag = 0)';
     }
     $result = DB_query("SELECT COUNT(*) AS cnt FROM {$_TABLES['staticpage']}" . $perms);
     $A = DB_fetchArray($result);
@@ -627,7 +627,7 @@
         }
 
         // increment hit counter for page
-        DB_query("UPDATE {$_TABLES['staticpage']} SET sp_hits = sp_hits + 1 WHERE (sp_id = '$page') AND (draft_flag = 0)");
+        DB_query("UPDATE {$_TABLES['staticpage']} SET sp_hits = sp_hits + 1 WHERE (sp_id = '$page') AND (draft_flag = 0) AND (template_flag = 0)");
 
     }
 
@@ -651,7 +651,7 @@
     if (!empty($perms)) {
         $perms = ' AND ' . $perms;
     }
-    $result = DB_query("SELECT sp_id,sp_title,sp_page_title,sp_hits FROM {$_TABLES['staticpage']} WHERE (sp_hits > 0) AND (draft_flag = 0)" . $perms . ' ORDER BY sp_hits DESC LIMIT 10');
+    $result = DB_query("SELECT sp_id,sp_title,sp_page_title,sp_hits FROM {$_TABLES['staticpage']} WHERE (sp_hits > 0) AND (draft_flag = 0) AND (template_flag = 0)" . $perms . ' ORDER BY sp_hits DESC LIMIT 10');
     $nrows  = DB_numRows($result);
     if ($nrows > 0) {
         require_once $_CONF['path_system'] . 'lib-admin.php';
@@ -758,7 +758,7 @@
     $sql .= "UNIX_TIMESTAMP(sp.created) AS date, sp.owner_id AS uid, sp.sp_hits AS hits, ";
     $sql .= "CONCAT('/staticpages/index.php?page=', sp.sp_id) AS url ";
     $sql .= "FROM {$_TABLES['staticpage']} AS sp,{$_TABLES['users']} AS u ";
-    $sql .= "WHERE (sp.owner_id = u.uid) AND (draft_flag = 0)";
+    $sql .= "WHERE (sp.owner_id = u.uid) AND (draft_flag = 0) AND (template_flag = 0)";
     $sql .= COM_getPermSQL('AND') . COM_getLangSQL('sp_id', 'AND', 'sp') . ' ';
 
     if (!empty ($author)) {
@@ -798,7 +798,7 @@
     $sql .= "FROM {$_TABLES['users']} AS u, {$_TABLES['comments']} AS c ";
     $sql .= "LEFT JOIN {$_TABLES['staticpage']} AS s ON ((s.sp_id = c.sid) ";
     $sql .= COM_getPermSQL('AND',0,2,'s') . COM_getLangSQL('sp_id','AND','s') . ") ";
-    $sql .= "WHERE (u.uid = c.uid) AND (s.draft_flag = 0) AND (s.commentcode >= 0) AND (s.created <= NOW()) ";
+    $sql .= "WHERE (u.uid = c.uid) AND (s.draft_flag = 0) AND (s.template_flag = 0) AND (s.commentcode >= 0) AND (s.created <= NOW()) ";
 
     if (!empty($author)) {
         $sql .= "AND (c.uid = '$author') ";
@@ -961,7 +961,7 @@
     if (!empty ($perms)) {
         $perms = ' AND ' . $perms;
     }
-    $spsql = "SELECT sp_id,sp_title,sp_content,sp_format,created,modified,sp_hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon,sp_php,sp_inblock,sp_help FROM {$_TABLES['staticpage']} WHERE (sp_centerblock = 1) AND (draft_flag = 0)" . COM_getLangSql('sp_id', 'AND') . ' AND ' . $moresql . $perms . " ORDER BY " . $sort;
+    $spsql = "SELECT sp_id,sp_title,sp_content,sp_format,created,modified,sp_hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon,sp_php,sp_inblock,sp_help FROM {$_TABLES['staticpage']} WHERE (sp_centerblock = 1) AND (draft_flag = 0) AND (template_flag = 0)" . COM_getLangSql('sp_id', 'AND') . ' AND ' . $moresql . $perms . " ORDER BY " . $sort;
     $result = DB_query($spsql);
 
     $pages = DB_numRows($result);
@@ -1073,7 +1073,7 @@
             }
 
             // increment hit counter for page
-            DB_query("UPDATE {$_TABLES['staticpage']} SET sp_hits = sp_hits + 1 WHERE (sp_id = '{$S['sp_id']}') AND (draft_flag = 0)");
+            DB_query("UPDATE {$_TABLES['staticpage']} SET sp_hits = sp_hits + 1 WHERE (sp_id = '{$S['sp_id']}') AND (draft_flag = 0) AND (template_flag = 0)");
         }
     }
 
@@ -1248,6 +1248,18 @@
 
             $current_version = '1.6.2';
             break;
+            
+        case '1.6.2':
+            if (isset($_UPDATES[$current_version])) {
+                $_SQL = $_UPDATES[$current_version];
+                foreach ($_SQL as $sql) {
+                    DB_query($sql);
+                }
+            }
+
+            $current_version = '1.6.3';
+            break;
+            
 
         default:
             $done = true;
@@ -1530,7 +1542,7 @@
     $sql = array();
     $sql['mysql'] = "SELECT sp_id, sp_title 
         FROM {$_TABLES['staticpage']} 
-        WHERE sp_content IS NOT NULL AND (draft_flag = 0) AND ({$datecolumn} >= (DATE_SUB(NOW(), INTERVAL {$_SP_CONF['newstaticpagesinterval']} SECOND))) 
+        WHERE sp_content IS NOT NULL AND (draft_flag = 0) AND (template_flag = 0) AND ({$datecolumn} >= (DATE_SUB(NOW(), INTERVAL {$_SP_CONF['newstaticpagesinterval']} SECOND))) 
         {$extra_sql} 
         " . COM_getPermSQL('AND') . " 
         ORDER BY {$datecolumn} DESC LIMIT 15";
@@ -1539,7 +1551,7 @@
     
     $sql['pgsql'] = "SELECT sp_id, sp_title 
         FROM {$_TABLES['staticpage']} 
-        WHERE sp_content IS NOT NULL AND (draft_flag = 0) AND ({$datecolumn} >= (NOW() - INTERVAL '{$_SP_CONF['newstaticpagesinterval']} SECONDS')) 
+        WHERE sp_content IS NOT NULL AND (draft_flag = 0) AND (template_flag = 0) AND ({$datecolumn} >= (NOW() - INTERVAL '{$_SP_CONF['newstaticpagesinterval']} SECONDS')) 
         {$extra_sql} 
         " . COM_getPermSQL('AND') . " 
         ORDER BY {$datecolumn} DESC LIMIT 15";
@@ -1598,17 +1610,17 @@
     }    
     if ($numreturn == 0 ) {
         $sql['mysql'] = "SELECT DISTINCT COUNT(*) AS dups, type, title, sid, max(date) AS lastdate FROM {$_TABLES['comments']}, {$_TABLES['staticpage']} sp"
-            . " WHERE type = 'staticpages' AND (sp.sp_id = sid) AND (sp.commentcode >= 0) AND (sp.draft_flag = 0)" . COM_getPermSQL('AND', 0, 2, 'sp')
+            . " WHERE type = 'staticpages' AND (sp.sp_id = sid) AND (sp.commentcode >= 0) AND (sp.draft_flag = 0) AND (sp.template_flag = 0)" . COM_getPermSQL('AND', 0, 2, 'sp')
             . " AND (date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newcommentsinterval']} SECOND))) {$stwhere} GROUP BY sid,type, title, sid ORDER BY 5 DESC LIMIT 15";
         $sql['mssql'] = "SELECT DISTINCT COUNT(*) AS dups, type, title, sid, max(date) AS lastdate FROM {$_TABLES['comments']}, {$_TABLES['staticpage']} sp"
-            . " WHERE type = 'staticpages' AND (sp.sp_id = sid) AND (sp.commentcode >= 0) AND (sp.draft_flag = 0)" . COM_getPermSQL('AND', 0, 2, 'sp')
+            . " WHERE type = 'staticpages' AND (sp.sp_id = sid) AND (sp.commentcode >= 0) AND (sp.draft_flag = 0) AND (sp.template_flag = 0)" . COM_getPermSQL('AND', 0, 2, 'sp')
             . " AND (date >= (DATE_SUB(NOW(), INTERVAL {$_CONF['newcommentsinterval']} SECOND))) {$stwhere} GROUP BY sid,type, title, sid ORDER BY 5 DESC LIMIT 15";
         $sql['pgsql'] = "SELECT DISTINCT COUNT(*) AS dups, type, title, sid, max(date) AS lastdate FROM {$_TABLES['comments']}, {$_TABLES['staticpage']} sp"
-            . " WHERE type = 'staticpages' AND (sp.sp_id = sid) AND (sp.commentcode >= 0) AND (sp.draft_flag = 0)" . COM_getPermSQL('AND', 0, 2, 'sp')
+            . " WHERE type = 'staticpages' AND (sp.sp_id = sid) AND (sp.commentcode >= 0) AND (sp.draft_flag = 0) AND (sp.template_flag = 0)" . COM_getPermSQL('AND', 0, 2, 'sp')
             . " AND (date >= (NOW()+ INTERVAL '{$_CONF['newcommentsinterval']} SECOND')) {$stwhere}  GROUP BY sid,type, title, sid ORDER BY 5 DESC LIMIT 15";
     } else {
         $sql = "SELECT {$_TABLES['comments']}.sid, {$_TABLES['comments']}.title title, cid, UNIX_TIMESTAMP({$_TABLES['comments']}.date) AS unixdate FROM {$_TABLES['comments']}, {$_TABLES['staticpage']} sp"
-            . " WHERE type = 'staticpages' AND (sp.sp_id = sid) AND (sp.commentcode >= 0) AND (sp.draft_flag = 0)" . COM_getPermSQL('AND', 0, 2, 'sp')
+            . " WHERE type = 'staticpages' AND (sp.sp_id = sid) AND (sp.commentcode >= 0) AND (sp.draft_flag = 0) AND (sp.template_flag = 0)" . COM_getPermSQL('AND', 0, 2, 'sp')
             . "{$stwhere} ORDER BY unixdate DESC LIMIT $numreturn";
     }        
     $result = DB_query($sql);
@@ -1678,7 +1690,7 @@
     }
 
     // prepare SQL request
-    $where = ' WHERE (draft_flag = 0)';
+    $where = ' WHERE (draft_flag = 0) AND (template_flag = 0) ';
     if ($sp_id != '*') {
         $where .= " AND (sp_id = '" . addslashes($sp_id) . "')";
     }
diff -r 5c2946db2f39 -r f5141a9d84e2 plugins/staticpages/language/english_utf-8.php
--- a/plugins/staticpages/language/english_utf-8.php	Fri Sep 10 13:20:31 2010 +0200
+++ b/plugins/staticpages/language/english_utf-8.php	Fri Sep 17 09:52:21 2010 -0400
@@ -113,6 +113,11 @@
     'no_new_pages' => 'No new pages',
     'pages' => 'Pages',
     'comments' => 'Comments',
+    'template' => 'Template',
+    'use_template' => 'Use Template',
+    'template_msg' => 'When checked, this Static Page will be marked as a template.',
+    'none' => 'None',
+    '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'
diff -r 5c2946db2f39 -r f5141a9d84e2 plugins/staticpages/services.inc.php
--- a/plugins/staticpages/services.inc.php	Fri Sep 10 13:20:31 2010 +0200
+++ b/plugins/staticpages/services.inc.php	Fri Sep 17 09:52:21 2010 -0400
@@ -231,6 +231,15 @@
         if (empty($args['draft_flag']) && ($_SP_CONF['draft_flag'] == '1')) {
             $args['draft_flag'] = 'on';
         }
+        
+        if (empty($args['template_flag'])) {
+            $args['template_flag'] = '';
+        }
+
+        if (empty($args['template_id'])) {
+            $args['template_id'] = '';
+        }
+        
     }
 
     // END: Staticpages defaults 
@@ -263,6 +272,8 @@
     $sp_old_id = $args['sp_old_id'];
     $sp_centerblock = $args['sp_centerblock'];
     $draft_flag = $args['draft_flag'];
+    $template_flag = $args['template_flag'];
+    $template_id = $args['template_id'];
     $sp_help = '';
     if (!empty($args['sp_help'])) {
         $sp_help = $args['sp_help'];
@@ -341,6 +352,11 @@
         } else {
             $draft_flag = 0;
         }
+        if ($template_flag == 'on') {
+            $template_flag = 1;
+        } else {
+            $template_flag = 0;
+        }
 
         // Clean up the text
         if ($_SP_CONF['censor'] == 1) {
@@ -368,7 +384,37 @@
         if (($_SP_CONF['allow_php'] != 1) || !SEC_hasRights ('staticpages.PHP')) {
             $sp_php = 0;
         }
-
+        
+        // If marked as a template then set id to nothing and other default settings
+        if ($template_flag == 1) {
+            $template_id = '';
+            
+            $sp_onmenu = 0;
+            $sp_label = "";
+            $sp_centerblock = 0;
+            $sp_php = 0;
+            $sp_inblock = 0;
+            $sp_nf = 0;
+            
+            $sp_hits = 0;
+            $meta_description = "";
+            $meta_keywords = "";
+        } else {
+            if ($template_id != '') {
+                // If using a template, make sure php disabled
+                $sp_php = 0;
+                
+                // Double check template id exists and is still a template
+                $perms = SP_getPerms();
+                if (!empty($perms)) {
+                    $perms = ' AND ' . $perms;
+                }        
+                if (DB_getItem($_TABLES['staticpage'], 'COUNT(sp_id)',("sp_id = '$template_id' AND template_flag = 1 AND (draft_flag = 0)" . $perms)) == 0) {
+                    $template_id = '';
+                }
+            }
+        }
+        
         // make sure there's only one "entire page" static page per topic
         if (($sp_centerblock == 1) && ($sp_where == 0)) {
             $sql = "UPDATE {$_TABLES['staticpage']} SET sp_centerblock = 0 WHERE (sp_centerblock = 1) AND (sp_where = 0) AND (sp_tid = '$sp_tid') AND (draft_flag = 0)";
@@ -404,9 +450,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,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,owner_id,group_id,'
                 .'perm_owner,perm_group,perm_members,perm_anon,sp_php,sp_nf,sp_centerblock,sp_help,sp_tid,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',$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,$owner_id,$group_id,"
                         ."$perm_owner,$perm_group,$perm_members,$perm_anon,'$sp_php','$sp_nf',$sp_centerblock,'$sp_help','$sp_tid',$sp_where,"
                         ."'$sp_inblock','$postmode'");
 
@@ -482,6 +528,11 @@
         }
     }
 
+    // If a staticpage template, remove any use of the file
+    if (DB_getItem($_TABLES['staticpage'], 'template_flag', "sp_id = '$sp_id'") == 1) {
+        $sql = "UPDATE {$_TABLES['staticpage']} SET template_id = '' WHERE template_id = '$sp_id'";
+        $result = DB_query($sql);
+    }
     DB_delete($_TABLES['staticpage'], 'sp_id', $sp_id);
     DB_delete($_TABLES['comments'], array('sid',  'type'),
                                     array($sp_id, 'staticpages'));
@@ -569,7 +620,7 @@
         }
         $sql = array();
         $sql['mysql'] = "SELECT sp_title,sp_page_title,sp_content,sp_hits,created,modified,sp_format,"
-                      . "commentcode,meta_description,meta_keywords,draft_flag,"
+                      . "commentcode,meta_description,meta_keywords,template_flag,template_id,draft_flag,"
                       . "owner_id,group_id,perm_owner,perm_group,"
                       . "perm_members,perm_anon,sp_tid,sp_help,sp_php,"
                       . "sp_inblock FROM {$_TABLES['staticpage']} "



More information about the geeklog-cvs mailing list