[geeklog-hg] geeklog: Fixed a bug where count views incremented for the autho...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Wed Jan 22 06:24:41 EST 2014


changeset 9440:2047c1c3e8ca
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/2047c1c3e8ca
user: Kenji ITO <mystralkk at gmail.com>
date: Wed Jan 22 10:15:52 2014 +0900
description:
Fixed a bug where count views incremented for the author of an article or a static page (patch provided by sandeep, feature request #0001572)

diffstat:

 plugins/staticpages/functions.inc |  138 +++++++++++++++++++++----------------
 public_html/article.php           |   13 ++-
 2 files changed, 86 insertions(+), 65 deletions(-)

diffs (truncated from 488 to 300 lines):

diff -r 4ed9d1ffa8ba -r 2047c1c3e8ca plugins/staticpages/functions.inc
--- a/plugins/staticpages/functions.inc	Wed Jan 22 10:14:16 2014 +0900
+++ b/plugins/staticpages/functions.inc	Wed Jan 22 10:15:52 2014 +0900
@@ -101,7 +101,7 @@
             $order .= 'sp_id';
         }
     }
-    
+
     if (!empty($topic)) {
         $topic_sql = " AND (ta.tid = '$topic' OR ta.tid = '" . TOPIC_ALL_OPTION . "')";
     } else {
@@ -111,7 +111,7 @@
             $topic_sql = " AND (ta.tid = '" . TOPIC_ALL_OPTION . "')";
         }
     }
-    
+
     // Have to recheck for homeonly and all since the staticpage could be that
     $com_topic_sql = COM_getTopicSQL('', 0, 'ta');
     if ($com_topic_sql != "") {
@@ -212,7 +212,7 @@
     if ($ret > 0) { // failure //FIXME: some failures should not return to comment form
         $retval .= CMT_commentForm($title, $comment, $id, $pid, 'staticpages',
                                   $LANG03[14], $postmode);
-        
+
         if (!defined('COMMENT_ON_SAME_PAGE')) {
             $retval = COM_createHTMLDocument($retval, array('pagetitle' => $LANG03[1]));
         } else {
@@ -353,18 +353,18 @@
         $spage = COM_newTemplate($template_path);
         $spage->set_file(array('page'     => 'staticpage.thtml',
                                'comments' => 'spcomments.thtml'));
-        
+
         $spage->set_var('sp_id', $page);
-        
+
         if ($A['sp_inblock'] == 1) {
             $spage->set_var('block_start', COM_startBlock(stripslashes($A['sp_title']), $A['sp_help'],
                             COM_getBlockTemplate('_staticpages_block', 'header')));            
         }        
-        
+
         if (XHTML != '') {
             $spage->set_var('xmlns', ' xmlns="http://www.w3.org/1999/xhtml"');
         }
-        
+
         $breadcrumb_trail = '';
         if ($_CONF['supported_version_theme'] == '1.8.1') {
             if (!$_SP_CONF['disable_breadcrumbs_staticpages']) {
@@ -484,12 +484,12 @@
 
         // Call to plugins to set template variables
         PLG_templateSetVars('staticpage', $spage);
-        
+
         if ($A['sp_inblock'] == 1) {
             $spage->set_var('block_end', COM_endBlock(COM_getBlockTemplate('_staticpages_block',
                                                          'footer')));
         }
-        
+
 
         $retval .= $spage->finish($spage->parse('output', 'page'));
 
@@ -510,7 +510,7 @@
         } else {
             $rightblock = -1;
         }
-        
+
         $breadcrumbs = '';
         if (!$_SP_CONF['disable_breadcrumbs_staticpages']) {
             $breadcrumbs = TOPIC_breadcrumbs('staticpages', $page);
@@ -653,7 +653,7 @@
 */
 function SP_returnStaticpage($page='', $mode='', $comment_order = 'ASC', $comment_mode = 'nested', $comment_page = 1, $msg = 0, $query = '')
 {
-    global $_TABLES;
+    global $_TABLES, $_USER;
 
     $retval = '';
 
@@ -664,9 +664,20 @@
     $svc_msg = array();
 
     if (PLG_invokeService('staticpages', 'get', $args, $retval, $svc_msg) == PLG_RET_OK) {
-        //// Grab page id from database since some comparisons are case sensitive and staticpage ids are not.
-        $page = DB_getItem($_TABLES['staticpage'], 'sp_id', "sp_id = '$page' ");
-        
+        // Grab page id from database since some comparisons are case sensitive
+        // and staticpage ids are not.
+        $result = DB_query(
+            "SELECT sp_id, owner_id "
+            . "FROM {$_TABLES['staticpage']} "
+            . "WHERE (sp_id = '" . DB_escapeString($page) . "')"
+        );
+
+        if ($result !== false) {
+            list ($page, $owner_id) = DB_fetchArray($result);
+        } else {
+            $owner_id = 0;
+        }
+
         if ($mode == 'print') {
             $retval = SP_printPage($page, $retval);
         } elseif ($mode =='autotag') {
@@ -675,9 +686,16 @@
             $retval = SP_displayPage($page, $retval, $comment_order, $comment_mode, $comment_page, $msg, $query);
         }
 
-        // increment hit counter for page
-        DB_query("UPDATE {$_TABLES['staticpage']} SET sp_hits = sp_hits + 1 WHERE (sp_id = '$page') AND (draft_flag = 0) AND (template_flag = 0)");
-
+        // Increment hit counter for page, but don't count views for the author
+        // of the page (feature request #0001572)
+        if (COM_isAnonUser() || ($_USER['uid'] != $owner_id)) {
+            DB_query(
+                "UPDATE {$_TABLES['staticpage']} "
+                . "SET sp_hits = sp_hits + 1 "
+                . "WHERE (sp_id = '" . DB_escapeString($page) . "')  "
+                . "  AND (draft_flag = 0) AND (template_flag = 0) "
+            );
+        }
     }
 
     return $retval;
@@ -771,7 +789,7 @@
 
     if ($_SP_CONF['includesearch'] == 1) {
         $tmp['staticpages'] = $LANG_STATIC['staticpages'];
-        
+
         return $tmp;
     }
 }
@@ -825,7 +843,7 @@
             $sql .= "AND (ta.tid IN('".TOPIC_ALL_OPTION."',{$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND (ta.tid = '".$topic."' OR ta.tid = '".TOPIC_ALL_OPTION."')))) ";
         }
     }
-        
+
     if ($_SP_CONF['includesearchcenterblocks'] == 0) {
         $sql .='AND sp_centerblock = 0 ';
     }
@@ -873,7 +891,7 @@
             $sql .= "AND (ta.tid IN('".TOPIC_ALL_OPTION."',{$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND (ta.tid = '".$topic."' OR ta.tid = '".TOPIC_ALL_OPTION."')))) ";
         }
     }    
-    
+
     $search_c = new SearchCriteria('comments', array($LANG_STATIC['staticpages'],$LANG09[66]));
 
     $columns = array('title' => 'c.title', 'comment');
@@ -1035,7 +1053,7 @@
         WHERE (sp_centerblock = 1) AND (draft_flag = 0) AND (template_flag = 0) 
         AND ta.type = 'staticpages' AND ta.id = sp_id
         " . COM_getLangSql('sp_id', 'AND') . ' AND ' . $moresql . $perms . " ORDER BY " . $sort;
-        
+
     $result = DB_query($spsql);
 
     $pages = DB_numRows($result);
@@ -1065,7 +1083,7 @@
             $template_path = staticpages_templatePath();
             $spage = COM_newTemplate($template_path);
             $spage->set_file(array('page' => 'centerblock.thtml'));
-            
+
             if (($S['sp_inblock'] == 1) && !empty ($S['sp_title'])
                 && (($where != 0) || ($S['sp_format'] != 'blankpage'))) {
                $spage->set_var('block_start', COM_startBlock ($S['sp_title'], $S['sp_help'],
@@ -1132,18 +1150,18 @@
                         'mode'  => $mode
                          );
             $svc_msg = array();
-        
+
             if (PLG_invokeService('staticpages', 'get', $args, $SP_retval, $svc_msg) == PLG_RET_OK) {  
                 $content = $SP_retval['sp_content'];
             }
-            
+
             $spage->set_var('content', $content);
-            
+
             if (($S['sp_inblock'] == 1) && !empty ($S['sp_title']) &&
                     (($where != 0) || ($S['sp_format'] != 'blankpage'))) {
                 $spage->set_var('block_end', COM_endBlock(COM_getBlockTemplate('_staticpages_centerblock', 'footer')));
             }
-            
+
             $retval .= $spage->finish($spage->parse('output', 'page'));
 
             if ($where == 0) {
@@ -1152,7 +1170,7 @@
                 } elseif ($S['sp_format'] != 'blankpage') {
                     $rightblock = -1;
                 }
-                
+
                 if ($S['sp_format'] != 'blankpage') {
                     $retval = COM_createHTMLDocument($retval, array('what' => $what, 'rightblock' => $rightblock));
                 }
@@ -1247,7 +1265,7 @@
             $_SP_CONF[$p][2], $_SP_CONF[$p][3]) == $flag) {
             $tagnames[] = 'staticpage';
         }
-        
+
         if (count($tagnames) > 0) {
             return $tagnames;
         }
@@ -1446,15 +1464,15 @@
                 // Set new Tab column to whatever fieldset is
                 $sql = "UPDATE {$_TABLES['conf_values']} SET tab = fieldset WHERE group_name = 'staticpages'";
                 DB_query($sql);
-                
+
                 SP_update_ConfValues_1_6_3();
             }
-            
+
             SP_update_ConfigSecurity_1_6_3();
 
             $current_version = '1.6.4';
             break;
-            
+
         case '1.6.4':
             if (isset($_UPDATES[$current_version])) {
                 $_SQL = $_UPDATES[$current_version];
@@ -1471,7 +1489,7 @@
 
             $current_version = '1.6.5';
             break; 
-        
+
         case '1.6.5':
             if (isset($_UPDATES[$current_version])) {
                 $_SQL = $_UPDATES[$current_version];
@@ -1491,7 +1509,7 @@
 
             $current_version = '1.6.6';
             break;             
-            
+
         default:
             $done = true;
         }
@@ -1692,7 +1710,7 @@
     global $_SP_CONF, $LANG_STATIC;
 
     $retval = '';
-    
+
     // Retrieve non php staticpage from cache
     if ($cache_time > -1 AND $sp_php == 0) {
         // Don't need to cache per theme since not rendered in a block yet 
@@ -1710,15 +1728,15 @@
             }
         }    
     }    
-    
+
     // 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) {
@@ -1726,12 +1744,12 @@
             $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,
@@ -1739,17 +1757,17 @@
                     'gl_svc' => ''
                      );



More information about the geeklog-cvs mailing list