XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/themes/xpress_default/blocks/recent_comments_block_theme.php @ 436

Last change on this file since 436 was 436, checked in by toemon, 14 years ago

ブロックオプション、 コメントタイプをカンマ区切りデータとして格納するようにした。 #243

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