[geeklog-cvs] geeklog: User profile page now uses PLG_getWhatsNewComment to di...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Tue Mar 16 15:20:23 EDT 2010


changeset 7798:a4240b2a68c4
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/a4240b2a68c4
user: Tom <websitemaster at cogeco.net>
date: Tue Mar 16 14:53:55 2010 -0400
description:
User profile page now uses PLG_getWhatsNewComment to display the 10 last comments of a user.

diffstat:

 system/lib-plugins.php |  59 ++++++++++++++++++++---------
 system/lib-user.php    |  62 +++++++++++-------------------
 2 files changed, 64 insertions(+), 57 deletions(-)

diffs (174 lines):

diff -r 84e3ae00ca06 -r a4240b2a68c4 system/lib-plugins.php
--- a/system/lib-plugins.php	Thu Mar 11 10:14:31 2010 -0500
+++ b/system/lib-plugins.php	Tue Mar 16 14:53:55 2010 -0400
@@ -1938,35 +1938,58 @@
 
 
 /**
-* Ask plugins if they want to add new comments to Geeklog's What's New block.
+* Ask plugins if they want to add new comments to Geeklog's What's New block or 
+* User Profile Page.
 *
-* @return   array   $whatsnew
+
+* @param    string  $type       Plugin name. '' for all plugins.
+* @param    string  $numreturn  If 0 will return results for What's New Block. 
+*                               If > 0 will return last X new comments for User Profile.
+* @param    string  $uid        ID of the user to return results for. 0 = all users.
+* @return   array list of new comments (dups, type, title, sid, lastdate) or (sid, title, cid, unixdate)
 *
 */
-function PLG_getWhatsNewComment()
+function PLG_getWhatsNewComment($type = '', $numreturn = 0, $uid = 0)
 {
-    global $_PLUGINS;
+    global $_PLUGINS, $_CONF;
 
-    $whatsnew= array();
+    $whatsnew = array();
+    $plugintypes = array();
+
+    // Get Story new comment info first
+    if (($type == 'article') || ($type == 'story') || ($type == '')) {
+        require_once $_CONF['path_system'] . 'lib-story.php';
+        $whatsnew  = plugin_getwhatsnewcomment_story($numreturn, $uid);
+        
+        if ($type == '') {
+            $plugintypes = $_PLUGINS;
+        }
+    } else {
+        $plugintypes[] = $type;
+    }
+   
+     if (!($type == 'article') || ($type == 'story')) {
+        // Now check new comments for plugins
+        foreach ($plugintypes as $pi_name) {
+            $fn_head = 'plugin_whatsnewsupported_' . $pi_name;
+            if (function_exists($fn_head)) {
+                $supported = $fn_head();
+                if (is_array($supported)) {
+                    list($headline, $byline) = $supported;
     
-    foreach ($_PLUGINS as $pi_name) {
-        $fn_head = 'plugin_whatsnewsupported_' . $pi_name;
-        if (function_exists($fn_head)) {
-            $supported = $fn_head();
-            if (is_array($supported)) {
-                list($headline, $byline) = $supported;
-
-                $fn_new = 'plugin_getwhatsnewcomment_' . $pi_name;
-                if (function_exists($fn_new)) {
-                    $tempwhatsnew = $fn_new ();
-                    if(!empty($tempwhatsnew) && is_array($tempwhatsnew)) {
-                        $whatsnew = array_merge($tempwhatsnew, $whatsnew);
+                    $fn_new = 'plugin_getwhatsnewcomment_' . $pi_name;
+                    if (function_exists($fn_new)) {
+                        $tempwhatsnew = $fn_new ($numreturn, $uid);
+                        if(!empty($tempwhatsnew) && is_array($tempwhatsnew)) {
+                            $whatsnew = array_merge($tempwhatsnew, $whatsnew);
+                        }
                     }
                 }
             }
         }
     }
 
+    // Now check new comments for custom changes
     $fn_head = 'CUSTOM_whatsnewsupported';
     if (function_exists($fn_head)) {
         $supported = $fn_head();
@@ -1975,7 +1998,7 @@
 
             $fn_new = 'CUSTOM_getwhatsnewcomment';
             if (function_exists($fn_new)) {
-                $tempwhatsnew = $fn_new ();
+                $tempwhatsnew = $fn_new ($numreturn, $uid);
                 if(!empty($tempwhatsnew) && is_array($tempwhatsnew)) {
                     $whatsnew = array_merge($tempwhatsnew, $whatsnew);
                 }
diff -r 84e3ae00ca06 -r a4240b2a68c4 system/lib-user.php
--- a/system/lib-user.php	Thu Mar 11 10:14:31 2010 -0500
+++ b/system/lib-user.php	Tue Mar 16 14:53:55 2010 -0400
@@ -1031,42 +1031,25 @@
     }
 
     // list of last 10 comments by this user
-    $sidArray = array();
-    if (count($tids) > 0) {
-        // first, get a list of all stories the current visitor has access to
-        $sql = "SELECT sid FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW()) AND (tid IN ($topics))" . COM_getPermSQL('AND');
-        $result = DB_query($sql);
-        $numsids = DB_numRows($result);
-        for ($i = 1; $i <= $numsids; $i++) {
-            $S = DB_fetchArray($result);
-            $sidArray[] = $S['sid'];
-        }
-    }
-    $sidList = implode("', '",$sidArray);
-    $sidList = "'$sidList'";
-
-    // then, find all comments by the user in those stories
-    $sql = "SELECT sid,title,cid,UNIX_TIMESTAMP(date) AS unixdate FROM {$_TABLES['comments']} WHERE (uid = $uid) GROUP BY sid,title,cid,UNIX_TIMESTAMP(date)";
-
-    /**
-    * SQL NOTE:  Using a HAVING clause is usually faster than a where if the
-    * field is part of the select
-    * if (!empty ($sidList)) {
-    *     $sql .= " AND (sid in ($sidList))";
-    * }
-    */
-    if (! empty($sidList)) {
-        $sql .= " HAVING sid in ($sidList)";
-    }
-    $sql .= " ORDER BY unixdate DESC LIMIT 10";
-
-    $result = DB_query($sql);
-    $nrows = DB_numRows($result);
-    if ($nrows > 0) {
-        for ($i = 0; $i < $nrows; $i++) {
-            $C = DB_fetchArray($result);
-            $user_templates->set_var('cssid', ($i % 2) + 1);
-            $user_templates->set_var('row_number', ($i + 1) . '.');
+    $new_plugin_comments = array();
+    $new_plugin_comments = PLG_getWhatsNewComment('', 10, $uid);
+    
+    if( !empty($new_plugin_comments) ) {
+        // Sort array by element lastdate newest to oldest
+        foreach($new_plugin_comments as $k=>$v) {		
+            $b[$k] = strtolower($v['unixdate']);	
+        }	
+        arsort($b);	
+        foreach($b as $key=>$val) {		
+            $temp[] = $new_plugin_comments[$key];	
+        }	   
+        $new_plugin_comments = $temp;   
+           
+        $i = 0;
+        foreach ($new_plugin_comments as $C) {
+            $i = $i + 1;
+            $user_templates->set_var('cssid', ($i % 2));
+            $user_templates->set_var('row_number', ($i) . '.');
             $C['title'] = str_replace('$', '$', $C['title']);
             $comment_url = $_CONF['site_url']
                          . '/comment.php?mode=view&cid=' . $C['cid'];
@@ -1079,6 +1062,10 @@
             $commenttime = COM_getUserDateTimeFormat($C['unixdate']);
             $user_templates->set_var('comment_date', $commenttime[0]);
             $user_templates->parse('comment_row', 'row', true);
+            
+            if ($count == 10) {
+                break;   
+            }
         }
     } else {
         $user_templates->set_var('comment_row',
@@ -1093,9 +1080,6 @@
     $user_templates->set_var('number_stories', COM_numberFormat($N['count']));
     $user_templates->set_var('lang_number_comments', $LANG04[85]);
     $sql = "SELECT COUNT(*) AS count FROM {$_TABLES['comments']} WHERE (uid = $uid)";
-    if (! empty($sidList)) {
-        $sql .= " AND (sid in ($sidList))";
-    }
     $result = DB_query($sql);
     $N = DB_fetchArray($result);
     $user_templates->set_var('number_comments', COM_numberFormat($N['count']));



More information about the geeklog-cvs mailing list