XPressME Integration Kit

Trac

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

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

ブロックのバージョン管理実装 Fixes #246

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