[552] | 1 | <?php
|
---|
| 2 | // Block Version: 1.0
|
---|
| 3 | function global_popular_posts_block($options)
|
---|
| 4 | {
|
---|
| 5 | $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
|
---|
[792] | 6 | $this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_grobal_popular_posts_block.html' : trim( $options[1] );
|
---|
[552] | 7 | $disp_count = empty( $options[2] ) ? '10' : $options[2] ;
|
---|
| 8 | $show_month_range = empty( $options[3] ) ? '0' : $options[3] ;
|
---|
| 9 | $date_format = empty( $options[4] ) ? '' : $options[4] ;
|
---|
| 10 | $time_format = empty( $options[5] ) ? '' : $options[5] ;
|
---|
| 11 |
|
---|
| 12 | $selected = explode(',' , $cat_select);
|
---|
| 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 |
|
---|
| 19 | $cat_select;
|
---|
| 20 | $block = array();
|
---|
| 21 | $item_no = 0;
|
---|
| 22 |
|
---|
| 23 | $selected_author_id = xpress_selected_author_id('echo=0');
|
---|
| 24 |
|
---|
| 25 | $data_array = array();
|
---|
| 26 |
|
---|
| 27 | global $wpdb,$wp_query,$xoops_db,$wp_rewrite;
|
---|
| 28 |
|
---|
| 29 | if (xpress_is_multiblog()){
|
---|
| 30 | $blogs = get_blog_list(0,'all');
|
---|
| 31 | foreach ($blogs AS $blog) {
|
---|
| 32 | switch_to_blog($blog['blog_id']);
|
---|
| 33 | $wp_rewrite->init();
|
---|
[555] | 34 |
|
---|
| 35 | $blog_title = get_bloginfo('name');
|
---|
| 36 | $blog_link = get_bloginfo('url');
|
---|
| 37 | $blog_title_link = '<a href="' . $blog_link . '">' . $blog_title . '</a>' ;
|
---|
[552] | 38 |
|
---|
| 39 | $db_prefix = get_wp_prefix();
|
---|
| 40 |
|
---|
| 41 | $post_tb = $wpdb->posts;
|
---|
| 42 | $view_tb = $db_prefix . 'views';
|
---|
| 43 | $user_tb = $db_prefix . 'users';
|
---|
| 44 |
|
---|
| 45 | $term_relationships_tb = $wpdb->term_relationships; // upper 2.3
|
---|
| 46 | $term_taxonomy = $wpdb->term_taxonomy; // upper 2.3
|
---|
| 47 | $terms_tb = $wpdb->terms; // upper 2.3
|
---|
| 48 |
|
---|
| 49 | $post2cat_tb = $wpdb->post2cat; //under 2.3
|
---|
| 50 | $categories_tb = $wpdb->categories; //under 2.3
|
---|
| 51 |
|
---|
| 52 | include ($mydirpath . '/wp-includes/version.php');
|
---|
| 53 |
|
---|
| 54 | $select = "SELECT $view_tb.post_views, $post_tb.ID, $post_tb.post_title, $post_tb.post_date";
|
---|
| 55 | if ($wp_db_version >= 6124){
|
---|
| 56 | $from = " FROM (((";
|
---|
| 57 | $from .= " $post_tb LEFT JOIN $view_tb ON $post_tb.ID = $view_tb.post_id)";
|
---|
| 58 | $from .= " INNER JOIN $term_relationships_tb ON $post_tb.ID = $term_relationships_tb.object_id)";
|
---|
| 59 | $from .= " INNER JOIN $term_taxonomy ON $term_relationships_tb.term_taxonomy_id = $term_taxonomy.term_taxonomy_id)";
|
---|
| 60 | $from .= " INNER JOIN $terms_tb ON $term_taxonomy.term_id = $terms_tb.term_id ";
|
---|
| 61 |
|
---|
| 62 | $where = " WHERE $post_tb.post_type = 'post' AND $post_tb.post_status = 'publish'";
|
---|
| 63 | } else {
|
---|
| 64 | $from = " FROM ((";
|
---|
| 65 | $from .= " $post_tb LEFT JOIN $view_tb ON $post_tb.ID = $view_tb.post_id)";
|
---|
| 66 | $from .= " LEFT JOIN $post2cat_tb ON $post_tb.ID = $post2cat_tb.post_id)";
|
---|
| 67 | $from .= " INNER JOIN $user_tb ON $post_tb.post_author = $user_tb.ID";
|
---|
| 68 |
|
---|
| 69 | $where = " WHERE ($post_tb.post_status = 'publish') AND (UNIX_TIMESTAMP($post_tb.post_date) <= UNIX_TIMESTAMP())" ;
|
---|
| 70 |
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | if ($show_month_range > 0) {
|
---|
| 75 | $where .= " AND (UNIX_TIMESTAMP($post_tb.post_date) >= UNIX_TIMESTAMP(DATE_ADD(CURRENT_DATE, INTERVAL -$show_month_range month)))";
|
---|
| 76 | }
|
---|
| 77 | $order_limmit = " GROUP BY $post_tb.ID ORDER BY $view_tb.post_views DESC LIMIT 0, $disp_count";
|
---|
| 78 | $sql = $select . $from . $where . $order_limmit;
|
---|
| 79 |
|
---|
| 80 | $populars = $wpdb->get_results($sql);
|
---|
| 81 |
|
---|
| 82 | foreach ($populars as $popular){
|
---|
| 83 | $wp_query->in_the_loop = true; //for use the_tags() in multi lopp
|
---|
| 84 | $r = new WP_Query("p=$popular->ID");
|
---|
| 85 | if($r->have_posts()){
|
---|
| 86 | $r->the_post();
|
---|
| 87 | ob_start();
|
---|
| 88 | the_ID();
|
---|
| 89 | $post_id = ob_get_contents();
|
---|
| 90 | ob_end_clean();
|
---|
| 91 |
|
---|
| 92 | ob_start();
|
---|
| 93 | the_title();
|
---|
| 94 | $title = ob_get_contents();
|
---|
| 95 | ob_end_clean();
|
---|
| 96 |
|
---|
| 97 | ob_start();
|
---|
| 98 | the_permalink();
|
---|
| 99 | $permalink = ob_get_contents();
|
---|
| 100 | ob_end_clean();
|
---|
| 101 |
|
---|
| 102 | ob_start();
|
---|
| 103 | the_author_posts_link();
|
---|
| 104 | $author = ob_get_contents();
|
---|
| 105 | ob_end_clean();
|
---|
| 106 |
|
---|
| 107 | ob_start();
|
---|
| 108 | the_category(' • ');
|
---|
| 109 | $category = ob_get_contents();
|
---|
| 110 | ob_end_clean();
|
---|
| 111 |
|
---|
| 112 | if (function_exists('the_tags')){
|
---|
| 113 | ob_start();
|
---|
| 114 | the_tags(__('Tags:', 'xpress') . ' ',' • ','');
|
---|
| 115 | $tags = ob_get_contents();
|
---|
| 116 | ob_end_clean();
|
---|
| 117 | } else {
|
---|
| 118 | $tags = '';
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | ob_start();
|
---|
| 122 | the_modified_date($date_format);
|
---|
| 123 | $post_modified_date = ob_get_contents();
|
---|
| 124 | ob_end_clean();
|
---|
| 125 |
|
---|
| 126 | ob_start();
|
---|
| 127 | the_modified_date($time_format);
|
---|
| 128 | $post_modified_time = ob_get_contents();
|
---|
| 129 | ob_end_clean();
|
---|
| 130 |
|
---|
| 131 | ob_start();
|
---|
| 132 | the_time($date_format);
|
---|
| 133 | $post_date = ob_get_contents();
|
---|
| 134 | ob_end_clean();
|
---|
| 135 |
|
---|
| 136 | ob_start();
|
---|
| 137 | the_time($time_format);
|
---|
| 138 | $post_time = ob_get_contents();
|
---|
| 139 | ob_end_clean();
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | ob_start();
|
---|
| 143 | comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
|
---|
| 144 | $comments_popup_link = ob_get_contents();
|
---|
| 145 | ob_end_clean();
|
---|
| 146 |
|
---|
| 147 |
|
---|
| 148 | $post_title = '<a href="' . $permalink . '">' . $title . '</a>';
|
---|
| 149 | $post_date_time = $post_date . ' ' . $post_time ;
|
---|
| 150 | $post_modified_date_time = $post_modified_date . ' ' . $post_modified_time ;
|
---|
| 151 | $trackback_url = trackback_url(false);
|
---|
| 152 | $post_views = xpress_post_views_count('post_id=' . $post_id . '&format=' . __('Views :%d', 'xpress'). '&echo=0');
|
---|
| 153 | $post_views_num = (int) xpress_post_views_count("post_id={$post_id}&format=%d&echo=0");
|
---|
| 154 | $row_data = array(
|
---|
[555] | 155 | 'blog_title' => $blog_title ,
|
---|
| 156 | 'blog_link' => $blog_link ,
|
---|
| 157 | 'blog_title_link' => $blog_title_link ,
|
---|
[552] | 158 | 'post_id' => $post_id ,
|
---|
| 159 | 'post_title' => $post_title ,
|
---|
| 160 | 'post_date' => $post_date ,
|
---|
| 161 | 'post_time' => $post_time ,
|
---|
| 162 | 'post_date_time' => $post_date_time ,
|
---|
| 163 | 'post_modified_date' => $post_modified_date ,
|
---|
| 164 | 'post_modified_time' => $post_modified_time ,
|
---|
| 165 | 'post_modified_date_time' => $post_modified_date_time ,
|
---|
| 166 | 'post_author' => $author ,
|
---|
| 167 | 'post_category' => $category ,
|
---|
| 168 | 'post_tags' => $tags,
|
---|
| 169 | 'post_views' => $post_views,
|
---|
| 170 | 'post_views_num' => $post_views_num,
|
---|
| 171 | 'comment_link' => $comments_popup_link ,
|
---|
| 172 | 'trackback_url' => $trackback_url
|
---|
| 173 | );
|
---|
| 174 | $data_array[] = $row_data;
|
---|
| 175 | }
|
---|
| 176 | } // end of foreach
|
---|
| 177 | restore_current_blog();
|
---|
| 178 | $wp_rewrite->init();
|
---|
| 179 | }
|
---|
[554] | 180 | usort($data_array, "post_views_cmp");
|
---|
| 181 | if (!empty($disp_count)){
|
---|
| 182 | $data_array = array_slice($data_array,0,$disp_count);
|
---|
| 183 | }
|
---|
[552] | 184 |
|
---|
[554] | 185 | $item_no = 0;
|
---|
| 186 | foreach ($data_array as $data) {
|
---|
| 187 | $block['contents']['item'.$item_no] = $data;
|
---|
| 188 | $item_no++;
|
---|
| 189 | }
|
---|
| 190 | $block['data_count'] = $item_no;
|
---|
| 191 | } else {
|
---|
| 192 | $block['err_message'] = __('This blog is not set to the multi blog.', 'xpress');
|
---|
[552] | 193 | }
|
---|
| 194 | return $block ;
|
---|
| 195 | }
|
---|
| 196 | function post_views_cmp($a, $b)
|
---|
| 197 | {
|
---|
| 198 | return $b['post_views_num'] - $a['post_views_num'];
|
---|
| 199 | }
|
---|
| 200 | ?> |
---|