XPressME Integration Kit

Trac

source: branches/Ver2.4/xpressme_integration_kit/wp-content/themes/xpress_default/blocks/global_recent_comments_block_theme.php @ 792

Last change on this file since 792 was 792, checked in by toemon, 13 years ago

マルチサイト用、最近の投稿(全ブログ)ブロックのオプションに「対象ブログの除外」、「ブログ毎に抽出」を追加、ブロックオプションのデフォルトテンプレートの誤りを修正

File size: 5.6 KB
Line 
1<?php
2// Block Version: 1.0
3function global_recent_comments_block($options)
4{
5        $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
6        $this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_global_recent_comments_block.html' : trim( $options[1] );
7        $disp_count = empty( $options[2] ) ? '10' : $options[2] ;
8        $disp_length = empty( $options[3] ) ? '30' : $options[3] ;
9        $date_format = empty( $options[4] ) ? '' : $options[4] ;
10        $time_format = empty( $options[5] ) ? '' : $options[5] ;
11        $com_select = empty( $options[6] ) ? '0' : $options[6] ;
12
13        $selected = explode(',' , $com_select);
14
15        $mydirpath = get_xpress_dir_path();
16       
17        if (empty($date_format)) $date_format = get_settings('date_format');
18        if (empty($time_format)) $time_format = get_settings('time_format');
19       
20        $disp_all = in_array('0',$selected);
21        $disp_comment = in_array('1',$selected);
22        $disp_trackback = in_array('2',$selected);
23        $disp_pingback = in_array('3',$selected);
24       
25        $type_select = '';
26        if (!$disp_all){                       
27                if ($disp_comment){
28                        $in_where =  "''";
29                }
30                if ($disp_trackback){
31                        if (empty($in_where)) $in_where =  "'trackback' "; else $in_where .=  ",'trackback'";
32                }
33                               
34                if ($disp_pingback){
35                        if (empty($in_where)) $in_where =  "'pingback' "; else $in_where .=  ",'pingback'";
36                }
37               
38                if (! empty($in_where)){
39                        $type_select = " AND comment_type IN($in_where) ";                             
40                }
41        }
42       
43        global $wpdb, $wp_rewrite , $switched , $blog_id;
44        $block = array();
45        $comment_array = array();
46        if (xpress_is_multiblog()){
47                $blogs = get_blog_list(0,'all');
48                foreach ($blogs AS $blog) {
49                        switch_to_blog($blog['blog_id']);
50                        $wp_rewrite->init();
51                        if (!is_null($wpdb)){
52                                $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 ";
53                                $comment_sql .= "FROM $wpdb->comments LEFT JOIN $wpdb->posts ON  $wpdb->posts.ID = $wpdb->comments.comment_post_ID ";
54                                if (xpress_is_wp_version('<','2.1')){
55                                        $comment_sql .= "WHERE comment_approved = '1' AND post_status = 'publish' $type_select ";
56                                } else {
57                                        $comment_sql .= "WHERE comment_approved = '1' AND post_type = 'post'  AND post_status = 'publish' $type_select ";
58                                }
59                                $comment_sql .= "ORDER BY comment_date_gmt DESC LIMIT $disp_count";
60                                $comments = $wpdb->get_results($comment_sql);
61                               
62                                if ( $comments ) {
63                                                $blog_title = get_bloginfo('name');
64                                                $blog_link = get_bloginfo('url');
65                                                $blog_title_link = '<a href="' . $blog_link . '">' . $blog_title . '</a>' ;
66                                        foreach ($comments as $comment){
67                                                $comment_content = $comment->comment_content;
68                                                $comment_unix_time = $comment->comment_unix_time;
69                                                $comment_excerpt = ($disp_length>0 ? xpress_substr($comment_content, 0, $disp_length): $comment->comment_content);
70                                                $comment_link = get_comment_link($comment->comment_ID);
71                                                $comment_title = $comment_excerpt;
72                                                $comment_title_link = "<a href='$comment_link' rel='external nofollow' class='url'>$comment_title</a>";
73
74                                                $post_link = get_permalink($comment->comment_post_ID);
75                                                $post_title = get_the_title($comment->comment_post_ID);
76                                                $post_title_link = '<a href="'. $post_link . '">' . $post_title . '</a>';
77                                               
78                                                $author_link = $comment->comment_author_url;
79                                                $author_name = $comment->comment_author;
80                                                $author_name_link = (( empty( $author_link ) || 'http://' == $author_link ) ? $author_name : "<a href='$author_link' rel='external nofollow' class='url'>$author_name</a>");
81
82                                                $comment_type = (empty($comment->comment_type) ? 'comment': $comment->comment_type);
83                                               
84                                                $post_title_comment_link = '<a href="'. $comment_link . '">' . $post_title . '</a>';
85                                                $from_auther_to_post = sprintf(__('%1$s on %2$s','xpress'), $author_name_link , $post_title_comment_link );
86
87                                                $row_data = array(
88                                                        'blog_title' => $blog_title ,
89                                                        'blog_link' => $blog_link ,
90                                                        'blog_title_link' => $blog_title_link ,
91                                                        'comment_ID'            => $comment->comment_ID ,
92                                                        'comment_post_ID'       => $comment->comment_post_ID ,
93                                                        'comment_unix_time' => $comment_unix_time ,
94                                                        'comment_date'          => date($date_format,$comment->comment_unix_time) ,
95                                                        'comment_date_time' => date($date_format . ' ' . $time_format,$comment->comment_unix_time) ,
96                                                        'comment_content'       => $comment_content ,
97                                                        'comment_excerpt'       => $comment_excerpt ,
98                                                        'comment_link'          => $comment_link,
99                                                        'comment_title'         => $comment_title ,
100                                                        'comment_title_link' => $comment_title_link ,
101                                                        'post_link'             => $post_link,
102                                                        'post_title'            => $post_title,
103                                                        'post_title_link'       => $post_title_link,
104                                                        'author_link'           => $author_link,
105                                                        'author_name'           => $author_name,
106                                                        'author_name_link'      => $author_name_link,
107                                                        'comment_type'          => $comment_type,
108                                                        'from_auther_to_post' => $from_auther_to_post
109                                                );
110                                                $comment_array[] = $row_data;
111                                        }
112                                        $block['data_count'] = $item_no;
113                                }
114                        }
115                        restore_current_blog();
116                        $wp_rewrite->init();
117                } // end of foreach
118                usort($comment_array, "the_comment_time_cmp");
119                if (!empty($disp_count)){
120                        $comment_array = array_slice($comment_array,0,$disp_count);
121                }
122
123                $item_no = 0;
124                foreach ($comment_array AS $comment) {
125                        $block['contents']['item'.$item_no] = $comment;
126                        $item_no++;
127                }
128                $block['data_count'] = $item_no;
129        } else {
130                $block['err_message'] = __('This blog is not set to the multi blog.', 'xpress');
131        }
132
133        return $block ;
134}
135function the_comment_time_cmp($a, $b)
136{
137    return - strcasecmp($a['comment_unix_time'], $b['comment_unix_time']);
138}
139
140?>
Note: See TracBrowser for help on using the repository browser.