boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Hack] Top Commenters with Count
Goto page 1, 2  Next
 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
Cyberian75



Joined: 26 Sep 2002
Posts: 1095
Location: Oregon

PostPosted: Wed May 21, 2003 3:57 pm    Post subject: [Hack] Top Commenters with Count Reply with quote

You are welcome to improve on this draft hack. It's very ugly right now.

Code:

<?php
//By Michael H. Park (http://www.MichaelPark.net)

function topcommentcount($commenter) {
   global $tablecomments, $querycount;

   $tccquery = "SELECT COUNT(comment_author) AS totalcount FROM $tablecomments WHERE comment_author = '$commenter'";
         
   $tccresult = mysql_query($tccquery) or die(mysql_error());
   $rowcount = mysql_fetch_object($tccresult);
   
   $commentcount = $rowcount->totalcount;
   
   $querycount++;
   
   return($commentcount);
}

function topcommenters() {
   global $tablecomments, $querycount;

   $tcquery = "SELECT DISTINCT comment_author, comment_author_url " .
            " FROM $tablecomments " .
              " WHERE comment_content NOT LIKE '%<trackback />%' AND comment_content NOT LIKE '%<pingback />%' " .
              " AND comment_content != ''" .
               " ORDER BY comment_author";
         
   $tcresult = mysql_query($tcquery) or die(mysql_error());
   
   $querycount++;
      
   while ($rows = mysql_fetch_array($tcresult)) {
      $commentauthor = stripslashes($rows["comment_author"]);
      $commentauthorurl = $rows["comment_author_url"];
   
      $commentcount = topcommentcount($commentauthor);

      if (empty($commentauthorurl) || strlen($commentauthorurl) < 12) {
         echo $commentauthor.' ('.$commentcount.')<br>';
      }
      else {
         echo '<a href="'.$commentauthorurl.'" target="_blank">'.$commentauthor.'</a>'.' ('.$commentcount.')<br>';
      }
   }
}
?>

_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
epolady



Joined: 30 Jul 2002
Posts: 800
Location: Texas

PostPosted: Wed May 21, 2003 8:08 pm    Post subject: Reply with quote

Where does a php newbie such as myself put this code? Razz
Back to top
View user's profile Send private message
Cyberian75



Joined: 26 Sep 2002
Posts: 1095
Location: Oregon

PostPosted: Wed May 21, 2003 8:18 pm    Post subject: Reply with quote

I don't recommend using it until someone fixes it up. Very Happy
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Sydney



Joined: 11 Feb 2003
Posts: 20
Location: Netherlands

PostPosted: Thu Jun 26, 2003 9:42 am    Post subject: Reply with quote

Could someone fix it up??
*puppy dog eyes*
_________________
Sydney
Back to top
View user's profile Send private message Visit poster's website
GooGirl



Joined: 15 Jul 2003
Posts: 19

PostPosted: Fri Aug 01, 2003 12:13 am    Post subject: Reply with quote

I like it as it is! Can I use it??

I uploaded it and all, but it's not ordering the comments from highest to lowest.. it's just listing all the commenters and the number of comments next to their name. What would I have to include in this to get it ordered?:

Code:
<?php topcommenters(); ?>


Cool idea Very Happy And thanks if you can help!
_________________
"That which you do not risk leaves you risking so much more."
Always,
~GooGirl
Back to top
View user's profile Send private message Send e-mail
Cyberian75



Joined: 26 Sep 2002
Posts: 1095
Location: Oregon

PostPosted: Fri Aug 01, 2003 2:20 am    Post subject: Reply with quote

Try replacing the following:

Code:

ORDER BY comment_author


With the following:

Code:

ORDER BY comment_author DESC

_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Gadget Girl



Joined: 25 Jan 2002
Posts: 305
Location: Virginia

PostPosted: Fri Aug 01, 2003 11:19 pm    Post subject: Reply with quote

How do I pull this into the blog sidebar?

Code:
<?php topcommenters(); ?>
Isn't working.

Code:
<?php include ("/home/xxx/public_html/xxx/topcommenters.php"); ?>
Isn't working either, it's just blank.
Back to top
View user's profile Send private message
Cyberian75



Joined: 26 Sep 2002
Posts: 1095
Location: Oregon

PostPosted: Sat Aug 02, 2003 1:40 am    Post subject: Reply with quote

Where did you copy the code in?
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Gadget Girl



Joined: 25 Jan 2002
Posts: 305
Location: Virginia

PostPosted: Sat Aug 02, 2003 1:57 am    Post subject: Reply with quote

I just made it a php file. There wasn't any instructions as to what to do with it in this thread.
Back to top
View user's profile Send private message
Cyberian75



Joined: 26 Sep 2002
Posts: 1095
Location: Oregon

PostPosted: Sat Aug 02, 2003 4:37 pm    Post subject: Reply with quote

You have to include that file at the bottom of "b2template.functions.php" file right before "?>".
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Gadget Girl



Joined: 25 Jan 2002
Posts: 305
Location: Virginia

PostPosted: Sat Aug 02, 2003 7:09 pm    Post subject: Reply with quote

It's a great hack, now that I know where to put it and what to include where.

Code:
function add_filter($tag, $function_to_add) {
   global $b2_filter;
   if (isset($b2_filter[$tag])) {
      $functions = $b2_filter[$tag];
      if (is_array($functions)) {
         foreach($functions as $function) {
            $new_functions[] = $function;
         }
      } elseif (is_string($functions)) {
         $new_functions[] = $functions;
      }
/* this is commented out because it just makes PHP die silently
   for no apparent reason
      if (is_array($function_to_add)) {
         foreach($function_to_add as $function) {
            if (!in_array($function, $b2_filter[$tag])) {
               $new_functions[] = $function;
            }
         }
      } else */if (is_string($function_to_add)) {
         if (!@in_array($function_to_add, $b2_filter[$tag])) {
            $new_functions[] = $function_to_add;
         }
      }
      $b2_filter[$tag] = $new_functions;
   } else {
      $b2_filter[$tag] = array($function_to_add);
   }
   return true;
}

function topcommentcount($commenter) {
   global $tablecomments, $querycount;

   $tccquery = "SELECT COUNT(comment_author) AS totalcount FROM $tablecomments WHERE comment_author = '$commenter'";
         
   $tccresult = mysql_query($tccquery) or die(mysql_error());
   $rowcount = mysql_fetch_object($tccresult);
   
   $commentcount = $rowcount->totalcount;
   
   $querycount++;
   
   return($commentcount);
}

function topcommenters() {
   global $tablecomments, $querycount;

   $tcquery = "SELECT DISTINCT comment_author, comment_author_url " .
            " FROM $tablecomments " .
              " WHERE comment_content NOT LIKE '%<trackback />%' AND comment_content NOT LIKE '%<pingback />%' " .
              " AND comment_content != ''" .
               " ORDER BY comment_author";
         
   $tcresult = mysql_query($tcquery) or die(mysql_error());
   
   $querycount++;
       
   while ($rows = mysql_fetch_array($tcresult)) {
      $commentauthor = stripslashes($rows["comment_author"]);
      $commentauthorurl = $rows["comment_author_url"];
   
      $commentcount = topcommentcount($commentauthor);

      if (empty($commentauthorurl) || strlen($commentauthorurl) < 12) {
         echo $commentauthor.' ('.$commentcount.')<br>';
      }
      else {
         echo '<a href="'.$commentauthorurl.'" target="_blank">'.$commentauthor.'</a>'.' ('.$commentcount.')<br>';
      }
   }
}


Put the above code as is, in the b2template.functions.php right before the end ?>

Then, put
Code:
<?php topcommenters(); ?>
in your sidebar to pull it into your blog and show the commenters tally.

Sara
Back to top
View user's profile Send private message
Gadget Girl



Joined: 25 Jan 2002
Posts: 305
Location: Virginia

PostPosted: Sat Aug 02, 2003 7:14 pm    Post subject: Reply with quote

Now that it's working, any clues as to show say the top 10 commenters only? Right now it's showing all the commenters alphabetically.
Back to top
View user's profile Send private message
Cyberian75



Joined: 26 Sep 2002
Posts: 1095
Location: Oregon

PostPosted: Sat Aug 02, 2003 8:26 pm    Post subject: Reply with quote

My intention was to list them from the highest number of comments. Apparently, though, it doesn't work as intended.

Anyway, to limit the number, put "limit 10" at the end of the SQL query in the second function.
_________________
Michael P.
Back to top
View user's profile Send private message Visit poster's website AIM Address
patrick



Joined: 22 Jul 2003
Posts: 4
Location: new jersey

PostPosted: Sat Aug 02, 2003 10:17 pm    Post subject: Reply with quote

erm... stupid question but what exactly does it do?
_________________
o.O___patrick
Back to top
View user's profile Send private message
Gadget Girl



Joined: 25 Jan 2002
Posts: 305
Location: Virginia

PostPosted: Sat Aug 02, 2003 10:18 pm    Post subject: Reply with quote

Thanks for the help Michael, but I have tried putting limit 10 everywhere and there is an error. Where exactly should it go? Please paste the line and where to find it and add the code as well, thanks.

Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group