', $after = '', $show_pass_post = false, $comment_color = "#999999") {
global $wpdb;
$request = "SELECT ID, post_title, comment_ID, comment_content, comment_author FROM $wpdb->posts, $wpdb->comments WHERE $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'";
if(!$show_pass_post) { $request .= "AND post_password ='' "; }
$request .= "AND comment_approved = '1' ORDER BY $wpdb->comments.comment_date DESC LIMIT $no_comments";
$comments = $wpdb->get_results($request);
$output = '';
foreach ($comments as $comment) {
$comment_author = stripslashes($comment->comment_author);
$comment_content = strip_tags($comment->comment_content);
$comment_content = stripslashes($comment_content);
$comment_post = stripslashes($comment->post_title);
$comment_excerpt =substr($comment_content,0,50);
$comment_excerpt = utf8_trim($comment_excerpt);
$permalink_post = get_permalink($comment->ID);
$permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
$output .= $before . '' . $comment_author . ' ' . '' . $comment_post . '' . '
' . '' . $comment_excerpt . '...' . '' . $after;
}
echo $output;
}
function get_recent_comments($no_comments = 5, $before = '
', $after = '', $show_pass_post = false) {
global $wpdb;
$request = "SELECT ID, comment_ID, comment_content, comment_author FROM $wpdb->posts, $wpdb->comments WHERE $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'";
if(!$show_pass_post) { $request .= "AND post_password ='' "; }
$request .= "AND comment_approved = '1' ORDER BY $wpdb->comments.comment_date DESC LIMIT
$no_comments";
$comments = $wpdb->get_results($request);
$output = '';
foreach ($comments as $comment) {
$comment_author = stripslashes($comment->comment_author);
$comment_content = strip_tags($comment->comment_content);
$comment_content = stripslashes($comment_content);
$comment_excerpt =substr($comment_content,0,50);
$comment_excerpt = utf8_trim($comment_excerpt);
$permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
$output .= $before . '' . $comment_author . ': ' . $comment_excerpt . '...' . $after;
}
echo $output;
}
function get_recent_comments_only($no_comments = 5, $before = ' ', $after = '', $show_pass_post = false) {
global $wpdb;
$request = "SELECT ID, comment_ID, comment_content, comment_author FROM $wpdb->posts, $wpdb->comments WHERE $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish' AND (post_type = 'post' OR post_type = 'page') AND comment_type = ''";
if(!$show_pass_post) { $request .= "AND post_password ='' "; }
$request .= "AND comment_approved = '1' ORDER BY $wpdb->comments.comment_date DESC LIMIT
$no_comments";
$comments = $wpdb->get_results($request);
$output = '';
foreach ($comments as $comment) {
$comment_author = stripslashes($comment->comment_author);
$comment_content = strip_tags($comment->comment_content);
$comment_content = stripslashes($comment_content);
$comment_excerpt =substr($comment_content,0,50);
$comment_excerpt = utf8_trim($comment_excerpt);
$permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
$output .= $before . '' . $comment_author . ': ' . $comment_excerpt . '...' . $after;
}
echo $output;
}
function get_recent_trackbacks($no_comments = 5, $before = ' ', $after = '', $show_pass_post = false) {
global $wpdb;
$request = "SELECT ID, comment_ID, comment_content, comment_author FROM $wpdb->posts, $wpdb->comments WHERE $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND (post_status = 'publish' AND post_type = 'post') OR (post_status = 'publish' AND post_type = 'page') AND (comment_type = 'trackback' OR comment_type ='pingback')";
if(!$show_pass_post) { $request .= "AND post_password ='' "; }
$request .= "AND comment_approved = '1' ORDER BY $wpdb->comments.comment_date DESC LIMIT
$no_comments";
$comments = $wpdb->get_results($request);
$output = '';
foreach ($comments as $comment) {
$comment_author = stripslashes($comment->comment_author);
$comment_content = strip_tags($comment->comment_content);
$comment_content = stripslashes($comment_content);
$comment_excerpt =substr($comment_content,0,50);
$comment_excerpt = utf8_trim($comment_excerpt);
$permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
$output .= $before . '' . $comment_author . ': ' . $comment_excerpt . '...' . $after;
}
echo $output;
}
// A trim function to remove the last character of a utf-8 string
// by following instructions on http://en.wikipedia.org/wiki/UTF-8
// dotann
function utf8_trim($str) {
$len = strlen($str);
for ($i=strlen($str)-1; $i>=0; $i-=1){
$hex .= ' '.ord($str[$i]);
$ch = ord($str[$i]);
if (($ch & 128)==0) return(substr($str,0,$i));
if (($ch & 192)==192) return(substr($str,0,$i));
}
return($str.$hex);
}
// Get Top Commented Posts
function get_mostcommented($limit = 5) {
global $wpdb, $post, $time_difference;
$mostcommenteds = $wpdb->get_results("SELECT $wpdb->posts.ID as ID, post_title, post_name, COUNT($wpdb->comments.comment_post_ID) AS 'comment_total' FROM $wpdb->posts LEFT JOIN $wpdb->comments ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND post_date < '".date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."' AND post_status = 'publish' AND post_type='post' AND post_password = '' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit");
foreach ($mostcommenteds as $post) {
$post_id = (int) $post->post_id;
$post_title = htmlspecialchars(stripslashes($post->post_title));
$comment_total = (int) $post->comment_total;
$permalink = get_permalink($post->ID);
echo "+ $post_title ($comment_total)
";
}
}
// Get Comments' Members Stats
// Treshhold = Number Of Posts User Must Have Before It Will Display His Name Out
// 5 = Default Treshhold; -1 = Disable Treshhold
function get_commentmembersstats($threshhold = 5) {
global $wpdb;
$comments = $wpdb->get_results("SELECT comment_author, comment_author_url, user_id, COUNT(comment_ID) AS 'comment_total' FROM $wpdb->comments WHERE comment_approved = '1' AND user_id != 1 GROUP BY comment_author ORDER BY comment_total DESC");
$no = 1;
foreach ($comments as $comment) {
$comment_author = htmlspecialchars(stripslashes($comment->comment_author));
$comment_author_url =stripslashes($comment->comment_author_url);
$comment_total = (int) $comment->comment_total;
if ($comment_author_url) {
$comment_author_link = "$comment_author";
} else {
$comment_author_link = "$comment_author";
}
echo "$comment_author ($comment_total) ";
$no++;
// If Total Comments Is Below Threshold
if($comment_total <= $threshhold && $threshhold != -1) {
return;
}
}
}
function random_posts ($limit = 5, $length = 400, $before = '', $after = '', $show_pass_post = false, $show_excerpt_in_title = true) {
global $wpdb;
$sql = "SELECT ID, post_title, post_date, post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ";
if(!$show_pass_post) $sql .= "AND post_password ='' ";
$sql .= "ORDER BY RAND() LIMIT $limit";
$posts = $wpdb->get_results($sql);
$output = '';
foreach ($posts as $post) {
$post_title = stripslashes($post->post_title);
$post_date = mysql2date('j.m.Y', $post->post_date);
$permalink = get_permalink($post->ID);
$post_content = strip_tags($post->post_content);
$post_content = stripslashes($post_content);
$post_strip = substr($post_content,0,$length);
$post_strip = utf8_trim($post_strip);
$post_strip = str_replace('"', '', $post_strip);
$output .= $before . '' . $post_title . '';
if(!$show_excerpt_in_title) {
$output .= ': ' . $post_strip . '... ';
}
$output .= $after;
}
echo $output;
}
function get_recent_posts($no_posts = 5, $before = '', $after = '', $show_pass_post = false, $skip_posts = 0) {
global $wpdb;
$request = "SELECT ID, post_title, post_date, post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_type='post' ";
if(!$show_pass_post) { $request .= "AND post_password ='' "; }
$request .= "ORDER BY post_date DESC LIMIT $skip_posts, $no_posts";
$posts = $wpdb->get_results($request);
$output = '';
foreach ($posts as $post) {
$post_title = stripslashes($post->post_title);
// $post_date = mysql2date('j.m.Y', $post->post_date);
$permalink = get_permalink($post->ID);
$output .= $before . '' . $post_title . ''. $after;
}
echo $output;
}
function get_recent_catposts($no_posts = 5, $catid = 1, $before = '', $after = '', $show_pass_post = false, $skip_posts = 0) {
global $wpdb;
$request = "SELECT ID, post_title, post_date, post_content, post_id, category_id FROM $wpdb->posts, $wpdb->post2cat WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type='post' AND $wpdb->post2cat.category_id = $catid AND $wpdb->posts.ID = $wpdb->post2cat.post_id ";
if(!$show_pass_post) { $request .= "AND post_password ='' "; }
$request .= "ORDER BY post_date DESC LIMIT $skip_posts, $no_posts";
$posts = $wpdb->get_results($request);
$output = '';
foreach ($posts as $post) {
$post_title = stripslashes($post->post_title);
// $post_date = mysql2date('j.m.Y', $post->post_date);
$permalink = get_permalink($post->ID);
$output .= $before . '' . $post_title . ''. $after;
}
echo $output;
}
function mul_excerpt ($excerpt) {
$myexcerpt = substr($excerpt,0,255);
return utf8_trim($myexcerpt) . '... ';
}
add_filter('the_excerpt', 'mul_excerpt');
add_filter('the_excerpt_rss', 'mul_excerpt');
?>