XPressME Integration Kit

Trac

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

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

ブロックオプションのうち$this_templateをポストしていなかったため、オプション変更時にデータずれが発生するバグを修正

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