XPressME Integration Kit

Trac

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

Last change on this file since 142 was 142, checked in by toemon, 15 years ago

ブロックオプションで日付スタイルをカスタマイズできるオプションを追加 bump Ver0.19

File size: 4.1 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    $selected = array_slice($options,6); // get allowed cats
13
14        $mydirpath = get_xpress_dir_path();
15       
16        if (empty($date_format)) $date_format = get_settings('date_format');
17        if (empty($time_format)) $time_format = get_settings('time_format');
18       
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 ";
48                $comment_sql .= "WHERE comment_approved = '1' AND post_type = 'post'  AND post_status = 'publish' $type_select ";
49                $comment_sql .= "ORDER BY comment_date_gmt DESC LIMIT $disp_count";
50
51                $comments = $wpdb->get_results($comment_sql);
52               
53                if ( $comments ) {
54                        $output .= '<ul>';
55                        $item_no = 0;
56                        foreach ($comments as $comment){
57                                $comment_content = $comment->comment_content;
58                                $comment_excerpt = ($disp_length>0 ? xpress_substr($comment_content, 0, $disp_length): $comment->comment_content);
59
60                                $comment_link = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID ;
61                                $comment_title = $comment_excerpt;
62                                $comment_title_link = "<a href='$comment_link' rel='external nofollow' class='url'>$comment_title</a>";
63
64                                $post_link = get_comment_link($comment->comment_ID);
65                                $post_title = get_the_title($comment->comment_post_ID);
66                                $post_title_link = '<a href="'. $post_link . '">' . $post_title . '</a>';
67                               
68                                $author_link = $comment->comment_author_url;
69                                $author_name = $comment->comment_author;
70                                $author_name_link = (( empty( $author_link ) || 'http://' == $author_link ) ? $author_name : "<a href='$author_link' rel='external nofollow' class='url'>$author_name</a>");
71
72                                $comment_type = (empty($comment->comment_type) ? 'comment': $comment->comment_type);
73                                $from_auther_to_post = sprintf(__('%1$s on %2$s'), $author_name_link , $post_title_link );
74
75                                $row_data = array(
76                                        'comment_ID'            => $comment->comment_ID ,
77                                        'comment_post_ID'       => $comment->comment_post_ID ,
78                                        'comment_date'          => date($date_format,$comment->comment_unix_time) ,
79                                        'comment_date_time' => date($date_format . ' ' . $time_format,$comment->comment_unix_time) ,
80                                        'comment_content'       => $comment_content ,
81                                        'comment_excerpt'       => $comment_excerpt ,
82                                        'comment_link'          => $comment_link,
83                                        'comment_title'         => $comment_title ,
84                                        'comment_title_link' => $comment_title_link ,
85                                        'post_link'             => $post_link,
86                                        'post_title'            => $post_title,
87                                        'post_title_link'       => $post_title_link,
88                                        'author_link'           => $author_link,
89                                        'author_name'           => $author_name,
90                                        'author_name_link'      => $author_name_link,
91                                        'comment_type'          => $comment_type,
92                                        'from_auther_to_post' => $from_auther_to_post
93                                );
94                               
95                                $block['contents']['item'.$item_no] = $row_data;
96                                $item_no++;
97                        }
98                        $block['data_count'] = $item_no;
99                }
100        }
101        return $block ;
102}
103?>
Note: See TracBrowser for help on using the repository browser.