XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/themes/xpress_default/blocks/recent_posts_list_block_theme.php @ 435

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

ブロックオプション、カテゴリのマルチセレクトをカンマ区切りデータとして格納するようにした。 #243

File size: 4.6 KB
Line 
1<?php
2function recent_posts_list_block($options)
3{
4        $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
5        $this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_recent_posts_list_block.html' : trim( $options[1] );
6        $disp_count = empty( $options[2] ) ? '10' : $options[2] ;
7        $disp_red = empty( $options[3] ) ? '1' : $options[3] ;
8        $disp_green = empty( $options[4] ) ? '7' : $options[4] ;
9        $date_format = empty( $options[5] ) ? '' : $options[5] ;
10        $time_format = empty( $options[6] ) ? '' : $options[6] ;
11        $tag_select = $options[7] ;
12        $cat_select = empty( $options[8] ) ? '0' : $options[8] ;
13       
14        $selected = explode(',' , $cat_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        if(empty($tag_select)) $tag_where = ''; else $tag_where = "tag='$tag_select'&";
21        if (array_search(0,$selected)===0) $cat_select = 0;
22
23        $selected_author_id = xpress_selected_author_id('echo=0');     
24        if (!empty($selected_author_id)){
25                $author_where ="author=$selected_author_id&";
26        } else {
27                $author_where = '';
28        }
29       
30        global $wpdb,$wp_query;
31        $block = array();
32        $item_no = 0;   
33        if (!is_null($wpdb)){
34                $wp_query->in_the_loop = true;          //for use the_tags() in multi lopp
35                if ($cat_select) {
36                        $r = new WP_Query($author_where . $tag_where . "cat=$cat_select&showposts=$disp_count&what_to_show=posts&nopaging=0&post_status=publish");
37                } else {
38                        $r = new WP_Query($author_where . $tag_where ."showposts=$disp_count&what_to_show=posts&nopaging=0&post_status=publish");
39                }
40                while($r->have_posts()){                       
41                        $r->the_post();
42                        ob_start();
43                                the_ID();
44                                $post_id = ob_get_contents();
45                        ob_end_clean();
46                       
47                        ob_start();
48                                the_title();
49                                $title = ob_get_contents();
50                        ob_end_clean();
51                       
52                        ob_start();
53                                the_permalink();
54                                $permalink = ob_get_contents();
55                        ob_end_clean();                                 
56                       
57                        ob_start();
58                                the_author_posts_link();
59                                $author = ob_get_contents();
60                        ob_end_clean();
61                       
62                        ob_start();
63                                the_category(' &bull; ');
64                                $category = ob_get_contents();
65                        ob_end_clean();
66                       
67                        if (function_exists('the_tags')){
68                                ob_start();
69                                        the_tags(__('Tags:', 'xpress') . ' ',' &bull; ','');
70                                        $tags = ob_get_contents();
71                                ob_end_clean();
72                        } else {
73                                $tags = '';
74                        }
75                       
76                        ob_start();
77                                the_modified_date($date_format);
78                                $post_modified_date = ob_get_contents();
79                        ob_end_clean();
80
81                        ob_start();
82                                the_modified_date($time_format);
83                                $post_modified_time = ob_get_contents();
84                        ob_end_clean();
85                       
86                        ob_start();
87                                the_time($date_format);
88                                $post_date = ob_get_contents();
89                        ob_end_clean();
90                       
91                        ob_start();
92                                the_time($time_format);
93                                $post_time = ob_get_contents();
94                        ob_end_clean();
95                       
96                       
97                        ob_start();
98                                comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
99                                $comments_popup_link = ob_get_contents();
100                        ob_end_clean();
101                       
102                        $red_sec = $disp_red *60*60*24;
103                        $green_sec = $disp_green *60*60*24;
104                        ob_start();
105                                the_time('U');
106                                $check_time = ob_get_contents();
107                        ob_end_clean();
108                        $elapse = time() - $check_time;
109                        $new_mark = '';
110                        if ($elapse < $red_sec ) {
111                                $new_mark = '<em style="color: red; font-size: small;">New! </em>';
112
113                        } else if ($elapse < $green_sec) {
114                                $new_mark = '<em style="color: green; font-size: small;">New! </em>';
115                        }
116                       
117                        $post_title = '<a href="' . $permalink . '">' . $title . '</a>';
118                        $post_date_time = $post_date . ' ' . $post_time ;
119                        $post_modified_date_time = $post_modified_date . ' ' . $post_modified_time ;
120                        $trackback_url = trackback_url(false);
121                        $post_viwes = xpress_post_views_count('post_id=' . $post_id . '&format=' . __('Views :%d', 'xpress'). '&echo=0');
122
123//                      if (empty($tags)) $tags = __('Not Tag');
124
125                        $row_data = array(
126                                'post_id'               => $post_id ,
127                                'new_mark'              => $new_mark ,
128                                'post_title'    => $post_title ,
129                                'post_date' => $post_date ,
130                                'post_time' => $post_time ,
131                                'post_date_time' => $post_date_time ,
132                                'post_modified_date' => $post_modified_date ,
133                                'post_modified_time' => $post_modified_time ,
134                                'post_modified_date_time' => $post_modified_date_time ,
135                                'post_author'   => $author ,
136                                'post_category'         => $category , 
137                                'post_tags'             => $tags,
138                                'post_views'            => $post_viwes,
139                                'comment_link'  => $comments_popup_link ,
140                                'trackback_url' => $trackback_url
141                        );
142                       
143                        $block['contents']['item'.$item_no] = $row_data;
144                        $item_no++;
145                }
146                $block['data_count'] = $item_no;  //xml unserialise error
147        }
148        return $block ;
149}
150?>
Note: See TracBrowser for help on using the repository browser.