XPressME Integration Kit

Trac

source: trunk/wp-content/themes/xpress_default/blocks/recent_comments_block.php @ 41

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

ブロック複製時でも、モジュール外に配置した場合、同一キャッシュを使用し同じ結果を表示してしまうバグを修正。
ブロックのshow_func内でブロックIDを取得する方法がわからないので、ブロックオプションから、識別コードを取得して、キャッシュのIDとする。

コメントブロックオプション(コメントタイプの選択)が有効にならないバグ修正

File size: 4.1 KB
Line 
1<?php
2if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ;
3
4function 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
10        $this_template = empty( $options[4] ) ? 'db:'.$mydirname.'_block_comments.html' : trim( $options[4] );
11        $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
12       
13        $myts =& MyTextSanitizer::getInstance();
14
15        $this_url = '/modules/'. $mydirname;
16        $call_url = $_SERVER['REQUEST_URI'];
17       
18        $disp_all = in_array('0',$selected);
19        $disp_comment = in_array('1',$selected);
20        $disp_trackback = in_array('2',$selected);
21        $disp_pingback = in_array('3',$selected);
22       
23        $type_select = '';
24        if (!$disp_all){                       
25                if ($disp_comment){
26                        $in_where =  "''";
27                }
28                if ($disp_trackback){
29                        if (empty($in_where)) $in_where =  "'trackback' "; else $in_where .=  ",'trackback'";
30                }
31                               
32                if ($disp_pingback){
33                        if (empty($in_where)) $in_where =  "'pingback' "; else $in_where .=  ",'pingback'";
34                }
35               
36                if (! empty($in_where)){
37                        $type_select = " AND comment_type IN($in_where) ";                             
38                }
39        }
40       
41        global $wpdb;
42        $block = array();
43               
44        if (!is_null($wpdb)){
45                $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 ";
46                $comment_sql .= "FROM $wpdb->comments LEFT JOIN $wpdb->posts ON  $wpdb->posts.ID = $wpdb->comments.comment_post_ID ";
47                $comment_sql .= "WHERE comment_approved = '1' AND post_type = 'post'  AND post_status = 'publish' $type_select ";
48                $comment_sql .= "ORDER BY comment_date_gmt DESC LIMIT $disp_count";
49
50                $comments = $wpdb->get_results($comment_sql);
51                $format = get_settings('date_format') . ' ' . get_settings('time_format');                             
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 ? xoops_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(get_settings('date_format'),$comment->comment_unix_time) ,
79                                        'comment_date_time' => date(get_settings('date_format') . ' ' . get_settings('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                }
99        }
100        return $block ;
101}
102?>
Note: See TracBrowser for help on using the repository browser.