[44] | 1 | <?php
|
---|
[451] | 2 | // Block Version: 1.0
|
---|
[44] | 3 | function recent_comments_block($options)
|
---|
| 4 | {
|
---|
| 5 | $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
|
---|
[120] | 6 | $this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_recent_comments_block.html' : trim( $options[1] );
|
---|
| 7 | $disp_count = empty( $options[2] ) ? '10' : $options[2] ;
|
---|
| 8 | $disp_length = empty( $options[3] ) ? '30' : $options[3] ;
|
---|
[142] | 9 | $date_format = empty( $options[4] ) ? '' : $options[4] ;
|
---|
| 10 | $time_format = empty( $options[5] ) ? '' : $options[5] ;
|
---|
[451] | 11 | $com_select = empty( $options[6] ) ? '0' : $options[6] ;
|
---|
[142] | 12 |
|
---|
[451] | 13 | $selected = explode(',' , $com_select);
|
---|
| 14 |
|
---|
[95] | 15 | $mydirpath = get_xpress_dir_path();
|
---|
[44] | 16 |
|
---|
[142] | 17 | if (empty($date_format)) $date_format = get_settings('date_format');
|
---|
| 18 | if (empty($time_format)) $time_format = get_settings('time_format');
|
---|
| 19 |
|
---|
[44] | 20 | $disp_all = in_array('0',$selected);
|
---|
| 21 | $disp_comment = in_array('1',$selected);
|
---|
| 22 | $disp_trackback = in_array('2',$selected);
|
---|
| 23 | $disp_pingback = in_array('3',$selected);
|
---|
| 24 |
|
---|
| 25 | $type_select = '';
|
---|
| 26 | if (!$disp_all){
|
---|
| 27 | if ($disp_comment){
|
---|
| 28 | $in_where = "''";
|
---|
| 29 | }
|
---|
| 30 | if ($disp_trackback){
|
---|
| 31 | if (empty($in_where)) $in_where = "'trackback' "; else $in_where .= ",'trackback'";
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | if ($disp_pingback){
|
---|
| 35 | if (empty($in_where)) $in_where = "'pingback' "; else $in_where .= ",'pingback'";
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | if (! empty($in_where)){
|
---|
| 39 | $type_select = " AND comment_type IN($in_where) ";
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | global $wpdb;
|
---|
| 44 | $block = array();
|
---|
| 45 |
|
---|
| 46 | if (!is_null($wpdb)){
|
---|
| 47 | $comment_sql = "SELECT comment_ID,comment_post_ID,comment_author,comment_author_email,comment_author_url,comment_content, comment_type,UNIX_TIMESTAMP(comment_date) as comment_unix_time ";
|
---|
| 48 | $comment_sql .= "FROM $wpdb->comments LEFT JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID ";
|
---|
[360] | 49 | if (xpress_is_wp_version('<','2.1')){
|
---|
[262] | 50 | $comment_sql .= "WHERE comment_approved = '1' AND post_status = 'publish' $type_select ";
|
---|
| 51 | } else {
|
---|
| 52 | $comment_sql .= "WHERE comment_approved = '1' AND post_type = 'post' AND post_status = 'publish' $type_select ";
|
---|
| 53 | }
|
---|
[44] | 54 | $comment_sql .= "ORDER BY comment_date_gmt DESC LIMIT $disp_count";
|
---|
| 55 | $comments = $wpdb->get_results($comment_sql);
|
---|
| 56 |
|
---|
| 57 | if ( $comments ) {
|
---|
| 58 | $output .= '<ul>';
|
---|
| 59 | $item_no = 0;
|
---|
| 60 | foreach ($comments as $comment){
|
---|
| 61 | $comment_content = $comment->comment_content;
|
---|
| 62 | $comment_excerpt = ($disp_length>0 ? xpress_substr($comment_content, 0, $disp_length): $comment->comment_content);
|
---|
[360] | 63 | $comment_link = get_comment_link($comment->comment_ID);
|
---|
[44] | 64 | $comment_title = $comment_excerpt;
|
---|
| 65 | $comment_title_link = "<a href='$comment_link' rel='external nofollow' class='url'>$comment_title</a>";
|
---|
| 66 |
|
---|
[269] | 67 | $post_link = get_permalink($comment->comment_post_ID);
|
---|
[44] | 68 | $post_title = get_the_title($comment->comment_post_ID);
|
---|
| 69 | $post_title_link = '<a href="'. $post_link . '">' . $post_title . '</a>';
|
---|
| 70 |
|
---|
| 71 | $author_link = $comment->comment_author_url;
|
---|
| 72 | $author_name = $comment->comment_author;
|
---|
| 73 | $author_name_link = (( empty( $author_link ) || 'http://' == $author_link ) ? $author_name : "<a href='$author_link' rel='external nofollow' class='url'>$author_name</a>");
|
---|
| 74 |
|
---|
| 75 | $comment_type = (empty($comment->comment_type) ? 'comment': $comment->comment_type);
|
---|
[269] | 76 |
|
---|
| 77 | $post_title_comment_link = '<a href="'. $comment_link . '">' . $post_title . '</a>';
|
---|
| 78 | $from_auther_to_post = sprintf(__('%1$s on %2$s','xpress'), $author_name_link , $post_title_comment_link );
|
---|
[44] | 79 |
|
---|
| 80 | $row_data = array(
|
---|
| 81 | 'comment_ID' => $comment->comment_ID ,
|
---|
| 82 | 'comment_post_ID' => $comment->comment_post_ID ,
|
---|
[142] | 83 | 'comment_date' => date($date_format,$comment->comment_unix_time) ,
|
---|
| 84 | 'comment_date_time' => date($date_format . ' ' . $time_format,$comment->comment_unix_time) ,
|
---|
[44] | 85 | 'comment_content' => $comment_content ,
|
---|
[110] | 86 | 'comment_excerpt' => $comment_excerpt ,
|
---|
[44] | 87 | 'comment_link' => $comment_link,
|
---|
| 88 | 'comment_title' => $comment_title ,
|
---|
| 89 | 'comment_title_link' => $comment_title_link ,
|
---|
| 90 | 'post_link' => $post_link,
|
---|
| 91 | 'post_title' => $post_title,
|
---|
| 92 | 'post_title_link' => $post_title_link,
|
---|
| 93 | 'author_link' => $author_link,
|
---|
| 94 | 'author_name' => $author_name,
|
---|
[110] | 95 | 'author_name_link' => $author_name_link,
|
---|
| 96 | 'comment_type' => $comment_type,
|
---|
[44] | 97 | 'from_auther_to_post' => $from_auther_to_post
|
---|
| 98 | );
|
---|
| 99 |
|
---|
| 100 | $block['contents']['item'.$item_no] = $row_data;
|
---|
| 101 | $item_no++;
|
---|
| 102 | }
|
---|
[104] | 103 | $block['data_count'] = $item_no;
|
---|
[44] | 104 | }
|
---|
| 105 | }
|
---|
| 106 | return $block ;
|
---|
| 107 | }
|
---|
| 108 | ?> |
---|