<?php

/*
Plugin Name: tkzy get recent comments
Version: X-kai
Plugin URI: http://tkzy.net/index.php?p=68
Description: Retrieves a list of the most recent commenters and trackbackers.
Author: tkzy
Author URI: http://tkzy.net/
*/
/*
posttitleの前に画像挿入し、コメンテーターをツリー化。48行目$daysの値を変えることにより、更新画像の表示日数を決定する。
hack by Masayan 
URL:http://wp.mmrt-jp.net/
*/

    
function tkzy_get_recent_comments($limit 10) {
        global 
$wpdb$tablecomments$tableposts;
        global 
$siteurl$blogfilename;
        
$comments $wpdb->get_results("SELECT ID, comment_ID, post_title,  post_name, post_date, comment_author, comment_author_url, comment_date 
        FROM $tableposts, $tablecomments WHERE $tableposts.ID=$tablecomments.comment_post_ID and comment_approved='1' 
        ORDER BY $tablecomments.comment_date DESC LIMIT $limit"
);
        
$output '';
    function 
sort_comment_by_date($a$b){
        if( 
$b->ID == $a->ID ){
            return 
mysql2date('U',$a->comment_date) - mysql2date('U',$b->comment_date);
            }
            return 
mysql2date('U',$b->post_date) - mysql2date('U',$a->post_date);
        }
        if(
$comments){
            
usort($comments"sort_comment_by_date");
        }
        
$new_post_ID = -1;
        
$title_image '<img height="11" alt="post" src="画像保存場所" width="11" />';//追加
        
$author_tree '└';//追加

        
foreach ($comments as $comment) {
            if (
$comment->ID != $new_post_ID) { // next post
                
if ($new_post_ID != -1) { $output .= "\t</ul>\n</li>\n"; }
                    
$post_title stripslashes($comment->post_title);
                    
$permalink get_permalink($comment->ID) . "#comments";
                    
//$permalink = get_settings('siteurl') . "/$blogfilename?p=$comment->ID&amp;c=1";//修正
                    
$output .= "<li>";
                    
$output .= "$title_image <a href=\"$permalink\">$post_title</a>\n";//追加・変更
                    
$output .= "\t<ul>\n";
                    
$new_post_ID $comment->ID;
            }

                    
$comment_date $comment->comment_date;
                    
$days1//set this to how many days are considered NEW!
                    
$date time();
                    
$entry mysql2date('U'$comment_date);
                    
$diff = ($date $entry) / 86400;

                if (
$days $diff) {
                    
$mark '<img height="6" src="画像保存場所" width="30" alt="" />';
                } else { 
$mark ''; }

            
$output .= "\t\t<li><span class=\"comment_author\">$author_tree ".tkzy_get_comment_author_link($comment,25). "</span>".
            
" $mark</li>\n";//変更
        
}
            
$output .= "\t</ul>\n</li>\n";
            echo 
$output;
    }
    
    function 
tkzy_get_comment_author_link($my_comment,$abbr=0) {
        
// modified comment_author_link()
        
$ret "";
        
$url trim(stripslashes($my_comment->comment_author_url));
        
//$email = stripslashes($my_comment->comment_author_email);
        
$author stripslashes($my_comment->comment_author);
        if (empty(
$author)) {
            
$author "Anonymous";
        }
        if (
$abbr && mb_strlen($author) > $abbr) {
            
$author mb_substr($author0$abbr);
            
$author .= "..";
        }

        
$url str_replace('http://url'''$url);
        
$url preg_replace('|[^a-z0-9-_.?#=&;,/:~]|i'''$url);
        if (empty(
$url) && empty($email)) {
            
$ret .= $author;
        } else {
            
$ret .= '<a href="';
        if (
$url) {
            
$url str_replace(';//''://'$url);
            
$url = (!strstr($url'://')) ? 'http://'.$url $url;
            
$url preg_replace('/&([^#])(?![a-z]{2,8};)/''&#038;$1'$url);
            
$ret .= $url;
        } 
/*else {
            $ret .= 'mailto:'.antispambot($email);
        }*/
            
$ret .= '" rel="external">' $author '</a>';
        }
        return 
$ret;
    }
?>