[100] | 1 | <?php
|
---|
| 2 | function recent_posts_list_block($options)
|
---|
| 3 | {
|
---|
| 4 | $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
|
---|
[120] | 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] ;
|
---|
[142] | 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 |
|
---|
[100] | 14 | $mydirpath = get_xpress_dir_path();
|
---|
| 15 |
|
---|
[142] | 16 | if (empty($date_format)) $date_format = get_settings('date_format');
|
---|
| 17 | if (empty($time_format)) $time_format = get_settings('time_format');
|
---|
[100] | 18 | if(empty($tag_select)) $tag_where = ''; else $tag_where = "tag='$tag_select'&";
|
---|
[157] | 19 |
|
---|
[272] | 20 | $selected_author_id = xpress_selected_author_id('echo=0');
|
---|
[157] | 21 | if (!empty($selected_author_id)){
|
---|
| 22 | $author_where ="author=$selected_author_id&";
|
---|
| 23 | } else {
|
---|
| 24 | $author_where = '';
|
---|
| 25 | }
|
---|
[100] | 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) {
|
---|
[157] | 33 | $r = new WP_Query($author_where . $tag_where ."showposts=$disp_count&what_to_show=posts&nopaging=0&post_status=publish");
|
---|
[100] | 34 |
|
---|
| 35 | } else {
|
---|
| 36 | $cat_id = implode(',',$selected);
|
---|
[157] | 37 | $r = new WP_Query($author_where . $tag_where . "cat=$cat_id&showposts=$disp_count&what_to_show=posts&nopaging=0&post_status=publish");
|
---|
[100] | 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 |
|
---|
[262] | 66 | if (function_exists('the_tags')){
|
---|
| 67 | ob_start();
|
---|
| 68 | the_tags(__('Tags:', 'xpress') . ' ',' • ','');
|
---|
| 69 | $tags = ob_get_contents();
|
---|
| 70 | ob_end_clean();
|
---|
| 71 | } else {
|
---|
| 72 | $tags = '';
|
---|
| 73 | }
|
---|
[100] | 74 |
|
---|
| 75 | ob_start();
|
---|
[142] | 76 | the_modified_date($date_format);
|
---|
[100] | 77 | $post_modified_date = ob_get_contents();
|
---|
| 78 | ob_end_clean();
|
---|
[262] | 79 |
|
---|
[100] | 80 | ob_start();
|
---|
[142] | 81 | the_modified_date($time_format);
|
---|
[100] | 82 | $post_modified_time = ob_get_contents();
|
---|
| 83 | ob_end_clean();
|
---|
| 84 |
|
---|
| 85 | ob_start();
|
---|
[142] | 86 | the_time($date_format);
|
---|
[100] | 87 | $post_date = ob_get_contents();
|
---|
| 88 | ob_end_clean();
|
---|
| 89 |
|
---|
| 90 | ob_start();
|
---|
[142] | 91 | the_time($time_format);
|
---|
[100] | 92 | $post_time = ob_get_contents();
|
---|
| 93 | ob_end_clean();
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | ob_start();
|
---|
| 97 | comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
|
---|
| 98 | $comments_popup_link = ob_get_contents();
|
---|
| 99 | ob_end_clean();
|
---|
| 100 |
|
---|
| 101 | $red_sec = $disp_red *60*60*24;
|
---|
| 102 | $green_sec = $disp_green *60*60*24;
|
---|
| 103 | ob_start();
|
---|
| 104 | the_time('U');
|
---|
| 105 | $check_time = ob_get_contents();
|
---|
| 106 | ob_end_clean();
|
---|
| 107 | $elapse = time() - $check_time;
|
---|
| 108 | $new_mark = '';
|
---|
| 109 | if ($elapse < $red_sec ) {
|
---|
[121] | 110 | $new_mark = '<em style="color: red; font-size: small;">New! </em>';
|
---|
[100] | 111 |
|
---|
| 112 | } else if ($elapse < $green_sec) {
|
---|
[121] | 113 | $new_mark = '<em style="color: green; font-size: small;">New! </em>';
|
---|
[100] | 114 | }
|
---|
| 115 |
|
---|
| 116 | $post_title = '<a href="' . $permalink . '">' . $title . '</a>';
|
---|
| 117 | $post_date_time = $post_date . ' ' . $post_time ;
|
---|
| 118 | $post_modified_date_time = $post_modified_date . ' ' . $post_modified_time ;
|
---|
| 119 | $trackback_url = trackback_url(false);
|
---|
[272] | 120 | $post_viwes = xpress_post_views_count('post_id=' . $post_id . '&format=' . __('Views :%d', 'xpress'). '&echo=0');
|
---|
| 121 |
|
---|
[100] | 122 | // if (empty($tags)) $tags = __('Not Tag');
|
---|
| 123 |
|
---|
| 124 | $row_data = array(
|
---|
| 125 | 'post_id' => $post_id ,
|
---|
| 126 | 'new_mark' => $new_mark ,
|
---|
| 127 | 'post_title' => $post_title ,
|
---|
| 128 | 'post_date' => $post_date ,
|
---|
| 129 | 'post_time' => $post_time ,
|
---|
| 130 | 'post_date_time' => $post_date_time ,
|
---|
| 131 | 'post_modified_date' => $post_modified_date ,
|
---|
| 132 | 'post_modified_time' => $post_modified_time ,
|
---|
| 133 | 'post_modified_date_time' => $post_modified_date_time ,
|
---|
| 134 | 'post_author' => $author ,
|
---|
| 135 | 'post_category' => $category ,
|
---|
| 136 | 'post_tags' => $tags,
|
---|
| 137 | 'post_views' => $post_viwes,
|
---|
| 138 | 'comment_link' => $comments_popup_link ,
|
---|
| 139 | 'trackback_url' => $trackback_url
|
---|
| 140 | );
|
---|
| 141 |
|
---|
| 142 | $block['contents']['item'.$item_no] = $row_data;
|
---|
| 143 | $item_no++;
|
---|
| 144 | }
|
---|
| 145 | $block['data_count'] = $item_no; //xml unserialise error
|
---|
| 146 | }
|
---|
| 147 | return $block ;
|
---|
| 148 | }
|
---|
| 149 | ?> |
---|