XPressME Integration Kit

Trac

source: trunk/wp-content/themes/xpress_default/blocks/recent_posts_list_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: 6.7 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        $selected = array_slice($options,8); // 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        if(empty($tag_select)) $tag_where = ''; else $tag_where = "tag='$tag_select'&";
19       
20        global $wpdb,$wp_query;
21        $block = array();
22        $item_no = 0;   
23        if (!is_null($wpdb)){
24                $wp_query->in_the_loop = true;          //for use the_tags() in multi lopp
25                if (array_search(0,$selected)===0) {
26                        $r = new WP_Query($tag_where ."showposts=$disp_count&what_to_show=posts&nopaging=0&post_status=publish");
27
28                } else {
29                        $cat_id = implode(',',$selected);
30                        $r = new WP_Query($tag_where . "cat=$cat_id&showposts=$disp_count&what_to_show=posts&nopaging=0&post_status=publish");
31                }
32                while($r->have_posts()){                       
33                        $r->the_post();
34                        ob_start();
35                                the_ID();
36                                $post_id = ob_get_contents();
37                        ob_end_clean();
38                       
39                        ob_start();
40                                the_title();
41                                $title = ob_get_contents();
42                        ob_end_clean();
43                       
44                        ob_start();
45                                the_permalink();
46                                $permalink = ob_get_contents();
47                        ob_end_clean();                                 
48                       
49                        ob_start();
50                                the_author_posts_link();
51                                $author = ob_get_contents();
52                        ob_end_clean();
53                       
54                        ob_start();
55                                the_category(' &bull; ');
56                                $category = ob_get_contents();
57                        ob_end_clean();
58                       
59                        ob_start();
60                                the_tags(__('Tags:', 'kubrick') . ' ',' &bull; ','');
61                                $tags = ob_get_contents();
62                        ob_end_clean();
63                       
64                        ob_start();
65                                the_modified_date($date_format);
66                                $post_modified_date = ob_get_contents();
67                        ob_end_clean();
68                       
69                        ob_start();
70                                the_modified_date($time_format);
71                                $post_modified_time = ob_get_contents();
72                        ob_end_clean();
73                       
74                        ob_start();
75                                the_time($date_format);
76                                $post_date = ob_get_contents();
77                        ob_end_clean();
78                       
79                        ob_start();
80                                the_time($time_format);
81                                $post_time = ob_get_contents();
82                        ob_end_clean();
83                       
84                       
85                        ob_start();
86                                comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
87                                $comments_popup_link = ob_get_contents();
88                        ob_end_clean();
89                       
90                        $red_sec = $disp_red *60*60*24;
91                        $green_sec = $disp_green *60*60*24;
92                        ob_start();
93                                the_time('U');
94                                $check_time = ob_get_contents();
95                        ob_end_clean();
96                        $elapse = time() - $check_time;
97                        $new_mark = '';
98                        if ($elapse < $red_sec ) {
99                                $new_mark = '<em style="color: red; font-size: small;">New! </em>';
100
101                        } else if ($elapse < $green_sec) {
102                                $new_mark = '<em style="color: green; font-size: small;">New! </em>';
103                        }
104                       
105                        $post_title = '<a href="' . $permalink . '">' . $title . '</a>';
106                        $post_date_time = $post_date . ' ' . $post_time ;
107                        $post_modified_date_time = $post_modified_date . ' ' . $post_modified_time ;
108                        $trackback_url = trackback_url(false);
109                        $post_viwes = xpress_post_views_count($post_id,'views: %d' ,false);
110//                      if (empty($tags)) $tags = __('Not Tag');
111
112                        $row_data = array(
113                                'post_id'               => $post_id ,
114                                'new_mark'              => $new_mark ,
115                                'post_title'    => $post_title ,
116                                'post_date' => $post_date ,
117                                'post_time' => $post_time ,
118                                'post_date_time' => $post_date_time ,
119                                'post_modified_date' => $post_modified_date ,
120                                'post_modified_time' => $post_modified_time ,
121                                'post_modified_date_time' => $post_modified_date_time ,
122                                'post_author'   => $author ,
123                                'post_category'         => $category , 
124                                'post_tags'             => $tags,
125                                'post_views'            => $post_viwes,
126                                'comment_link'  => $comments_popup_link ,
127                                'trackback_url' => $trackback_url
128                        );
129                       
130                        $block['contents']['item'.$item_no] = $row_data;
131                        $item_no++;
132                }
133                $block['data_count'] = $item_no;  //xml unserialise error
134        }
135        return $block ;
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180               
181        if (strstr($call_url,$this_url)){
182                $output ='<!-- xpress_recent_entries direct load -->' . "\n";
183                if (array_search(0,$selected)===0) {
184                        $r = new WP_Query("showposts=$disp_count&what_to_show=posts&nopaging=0&post_status=publish");
185                } else {
186                        $cat_id = implode(',',$selected);
187                        $r = new WP_Query("cat=$cat_id&showposts=$disp_count&what_to_show=posts&nopaging=0&post_status=publish");
188                }       
189                if ($r->have_posts()) {
190                        $red_sec = $disp_red *60*60*24;
191                        $green_sec = $disp_green *60*60*24;
192                        $output .= '<!-- xpress_recent_block -->' . "\n" . '<ul>';
193                        while ($r->have_posts()){
194                                $r->the_post();
195                                ob_start();
196                                        if ( get_the_title() ) {
197                                                the_title();
198                                        } else {
199                                                the_ID();
200                                        }
201                                        $title = ob_get_contents();
202                                ob_end_clean();
203                                ob_start();
204                                        the_time('U');
205                                        $post_time = ob_get_contents();
206                                ob_end_clean();
207                                $elapse = time() - $post_time;
208                                $new_mark = '';
209                                if ($elapse < $red_sec ) {
210                                        $new_mark = '<em style="color: red; font-size: small;">New!</em>';
211
212                                } else if ($elapse < $green_sec) {
213                                        $new_mark = '<em style="color: green; font-size: small;">New!</em>';
214                                }
215                                ob_start();
216                                        the_permalink();
217                                        $permalink = ob_get_contents();
218                                ob_end_clean();
219                                ob_start();
220                                        the_author();
221                                        $author = ob_get_contents();
222                                ob_end_clean();
223                                $output .=  '<li><a href="' . $permalink . '">' . $title . '</a> ';
224                                if ($show_new) {
225                                        $output .= $new_mark ;
226                                }
227                                if ($show_author){
228                                        $output .= ' ' . $author;
229                                }
230                                switch($show_date){
231                                        case 1 :
232                                                $format = get_settings('date_format');
233                                                $output .= '<p class="recentpost_time">(' . date($format,$post_time) . ')</p>';
234                                                break;
235                                        case 2 :
236                                                $format = get_settings('date_format') . ' ' . get_settings('time_format');
237                                                $output .= '<p class="recentpost_time">(' . date($format,$post_time) . ')</p>';
238                                                break;
239                                        default :                                                       
240                                }
241                                $output .= '</li>'. "\n";                               
242                        }
243                        $output .= '</ul>';
244                }
245                $block['content'] = $output;
246        } else {
247                $para  = '?showposts=' . $disp_count;
248                $para .= '&show_new=' . $show_new;
249                $para .= '&disp_red=' . $disp_red;
250                $para .= '&disp_green=' . $disp_green;
251                $para .= '&show_author=' . $show_author;
252                $para .= '&show_date=' .$show_date;
253                $para .= '&cat_id=' . implode(',',$selected);
254
255                $block['content'] = fetch_block($mydirname,$bid,'recent_entries_block',$para);
256        }
257        return $block ;
258
259}
260
261?>
Note: See TracBrowser for help on using the repository browser.