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