"monthly", //reset hourly, daily, weekly, monthly, yearly, all OR # (eg 30 days)
"limit" => 10, //maximum number of commentator's to show
"filter_users" => "Administrator,admin", //commma seperated list of users ("nate,jeff,etc").
"filter_user_ids" => "1,2", //comma sperated list of user_ids ("1,2")
"filter_urls" => "", //commma seperated list of full or partial URL's (www.badsite.com,etc)
"none_text" => "None yet!", //if there are no commentators, what should we display?
"make_links" => 1, //link the commentator's name to thier website?
"number_of_comments" => "y", //show number of comments next to their name? y=yes n=no
"name_limit" => 28, //maximum number of characters a commentator's name can be, before we cut it off with an ellipse
"start_html" => "
",
"end_html" => "",
);
//first we need to format options so they are useable
$ns_options = ns_format_options($ns_options);
function ns_substr_ellipse($str, $len) {
if(strlen($str) > $len) {
$str = substr($str, 0, $len-3) . "...";
}
return $str;
}
//temporary until i can condense this into one query in $commenters
function ns_get_user_url($user) {
global $wpdb, $ns_options;
$url = $wpdb->get_var("
SELECT comment_author_url
FROM $wpdb->comments
WHERE comment_author = '".addslashes($user)."'
AND comment_author_url != 'http://'
$ns_options[filter_urls]
ORDER BY comment_date DESC LIMIT 1
");
return $url;
}
function ns_show_top_commentators() {
global $wpdb, $ns_options;
if($ns_options["reset"] != '') {
if(!is_numeric($ns_options["reset"])) {
$reset_sql = "DATE_FORMAT(comment_date, '$ns_options[reset]') = DATE_FORMAT(CURDATE(), '$ns_options[reset]')";
} else {
$reset_sql = "comment_date >= CURDATE() - INTERVAL $ns_options[reset] DAY";
}
} else {
$reset_sql = "1=1";
}
$commenters = $wpdb->get_results("
SELECT COUNT(comment_author) AS comment_comments, comment_author
FROM $wpdb->comments o
WHERE $reset_sql
AND comment_author NOT IN($ns_options[filter_users])
AND user_id NOT IN($ns_options[filter_user_ids])
AND comment_author != ''
AND comment_type != 'pingback'
AND comment_approved = '1'
GROUP BY comment_author
ORDER BY comment_comments DESC LIMIT $ns_options[limit]
");
if(is_array($commenters)) {
foreach ($commenters as $k) {
if($ns_options["make_links"] == 1) {
$url = ns_get_user_url($k->comment_author);
}
echo $ns_options["start_html"];
if(trim($url) != '' && $ns_options["make_links"] == 1) {
echo "";
}
echo ns_substr_ellipse($k->comment_author, $ns_options["name_limit"]);
if(trim($url) != '' && $ns_options["make_links"] == 1) {
echo "";
}
if($ns_options["number_of_comments"] == 'y') {
echo " (" . $k->comment_comments . ")\n";
}
echo $ns_options["end_html"] . "\n";
unset($url);
}
} else {
echo $ns_options["start_html"] . $ns_options["none_text"] . $ns_options["end_html"];;
}
}
function ns_format_options($options) {
//$reset needs to turn into %sql format
if($options["reset"] == "hourly") {
$options["reset"] = "%Y-%m-%d %H";
} elseif($options["reset"] == "daily") {
$options["reset"] = "%Y-%m-%d";
} elseif($options["reset"] == "weekly") {
$options["reset"] = "%Y-%v";
} elseif($options["reset"] == "monthly") {
$options["reset"] = "%Y-%m";
} elseif($options["reset"] == "yearly") {
$options["reset"] = "%Y";
} elseif($options["reset"] == "all") {
$options["reset"] = "";
} elseif(is_numeric($options["reset"])) {
$options["reset"] = $options["reset"]; //last x days
} else {
$options["reset"] = "%Y-%m"; //just use monthly
}
//$filter urls needs to be comma seperated with single quotes
$filter_urls = trim($options["filter_urls"]);
if($filter_urls) { $filter_urls = explode(",", $filter_urls); } else { $filter_urls = array(); }
for($i=0; $i