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