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