1 | <?php
|
---|
2 | // Block Version: 1.0
|
---|
3 | function popular_posts_block($options)
|
---|
4 | {
|
---|
5 | $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
|
---|
6 | $this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_block_popular.html' : trim( $options[1] );
|
---|
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 | $tag_select = $options[6] ;
|
---|
12 | $cat_select = empty( $options[7] ) ? '0' : $options[7] ;
|
---|
13 |
|
---|
14 | $selected = explode(',' , $cat_select);
|
---|
15 |
|
---|
16 | $mydirpath = get_xpress_dir_path();
|
---|
17 |
|
---|
18 | if (empty($date_format)) $date_format = get_settings('date_format');
|
---|
19 | if (empty($time_format)) $time_format = get_settings('time_format');
|
---|
20 | if (array_search(0,$selected)===0) $cat_select = 0;
|
---|
21 |
|
---|
22 | $cat_select;
|
---|
23 | $block = array();
|
---|
24 | $item_no = 0;
|
---|
25 |
|
---|
26 | $selected_author_id = xpress_selected_author_id('echo=0');
|
---|
27 |
|
---|
28 | global $wpdb,$wp_query,$xoops_db;
|
---|
29 |
|
---|
30 | $db_prefix = get_wp_prefix();
|
---|
31 |
|
---|
32 | $post_tb = $wpdb->posts;
|
---|
33 | $view_tb = $db_prefix . 'views';
|
---|
34 | $user_tb = $db_prefix . 'users';
|
---|
35 |
|
---|
36 | $term_relationships_tb = $wpdb->term_relationships; // upper 2.3
|
---|
37 | $term_taxonomy = $wpdb->term_taxonomy; // upper 2.3
|
---|
38 | $terms_tb = $wpdb->terms; // upper 2.3
|
---|
39 |
|
---|
40 | $post2cat_tb = $wpdb->post2cat; //under 2.3
|
---|
41 | $categories_tb = $wpdb->categories; //under 2.3
|
---|
42 |
|
---|
43 | include ($mydirpath . '/wp-includes/version.php');
|
---|
44 |
|
---|
45 | $select = "SELECT $view_tb.post_views, $post_tb.ID, $post_tb.post_title, $post_tb.post_date";
|
---|
46 | if ($wp_db_version >= 6124){
|
---|
47 | $from = " FROM (((";
|
---|
48 | $from .= " $post_tb LEFT JOIN $view_tb ON $post_tb.ID = $view_tb.post_id)";
|
---|
49 | $from .= " INNER JOIN $term_relationships_tb ON $post_tb.ID = $term_relationships_tb.object_id)";
|
---|
50 | $from .= " INNER JOIN $term_taxonomy ON $term_relationships_tb.term_taxonomy_id = $term_taxonomy.term_taxonomy_id)";
|
---|
51 | $from .= " INNER JOIN $terms_tb ON $term_taxonomy.term_id = $terms_tb.term_id ";
|
---|
52 |
|
---|
53 | $where = " WHERE $post_tb.post_type = 'post' AND $post_tb.post_status = 'publish'";
|
---|
54 | // if (!empty($selected_author_id)){
|
---|
55 | // $where .= " AND ($post_tb.post_author = $selected_author_id) ";
|
---|
56 | // $where .= " AND ($post_tb.post_author = 2) ";
|
---|
57 | // }
|
---|
58 |
|
---|
59 | if ($cat_select) {
|
---|
60 | $where .= " AND ($term_taxonomy.term_id IN ($cat_select))";
|
---|
61 | }
|
---|
62 |
|
---|
63 | if (!empty($tag_select)) {
|
---|
64 | $tag_id_list= get_tag_id($tag_select);
|
---|
65 | if (!empty($tag_id_list))
|
---|
66 | $where .= " AND ($term_taxonomy.term_id IN ($tag_id_list))";
|
---|
67 | }
|
---|
68 | } else {
|
---|
69 | $from = " FROM ((";
|
---|
70 | $from .= " $post_tb LEFT JOIN $view_tb ON $post_tb.ID = $view_tb.post_id)";
|
---|
71 | $from .= " LEFT JOIN $post2cat_tb ON $post_tb.ID = $post2cat_tb.post_id)";
|
---|
72 | $from .= " INNER JOIN $user_tb ON $post_tb.post_author = $user_tb.ID";
|
---|
73 |
|
---|
74 | $where = " WHERE ($post_tb.post_status = 'publish') AND (UNIX_TIMESTAMP($post_tb.post_date) <= UNIX_TIMESTAMP())" ;
|
---|
75 |
|
---|
76 | if ($cat_select) {
|
---|
77 | $where .= " AND ($post2cat_tb.category_id IN ($cat_select))";
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | if ($show_month_range > 0) {
|
---|
83 | $where .= " AND (UNIX_TIMESTAMP($post_tb.post_date) >= UNIX_TIMESTAMP(DATE_ADD(CURRENT_DATE, INTERVAL -$show_month_range month)))";
|
---|
84 | }
|
---|
85 | $order_limmit = " GROUP BY $post_tb.ID ORDER BY $view_tb.post_views DESC LIMIT 0, $disp_count";
|
---|
86 | $sql = $select . $from . $where . $order_limmit;
|
---|
87 |
|
---|
88 | $populars = $wpdb->get_results($sql);
|
---|
89 |
|
---|
90 | foreach ($populars as $popular){
|
---|
91 | $wp_query->in_the_loop = true; //for use the_tags() in multi lopp
|
---|
92 | $r = new WP_Query("p=$popular->ID");
|
---|
93 | if($r->have_posts()){
|
---|
94 | $r->the_post();
|
---|
95 | ob_start();
|
---|
96 | the_ID();
|
---|
97 | $post_id = ob_get_contents();
|
---|
98 | ob_end_clean();
|
---|
99 |
|
---|
100 | ob_start();
|
---|
101 | the_title();
|
---|
102 | $title = ob_get_contents();
|
---|
103 | ob_end_clean();
|
---|
104 |
|
---|
105 | ob_start();
|
---|
106 | the_permalink();
|
---|
107 | $permalink = ob_get_contents();
|
---|
108 | ob_end_clean();
|
---|
109 |
|
---|
110 | ob_start();
|
---|
111 | the_author_posts_link();
|
---|
112 | $author = ob_get_contents();
|
---|
113 | ob_end_clean();
|
---|
114 |
|
---|
115 | ob_start();
|
---|
116 | the_category(' • ');
|
---|
117 | $category = ob_get_contents();
|
---|
118 | ob_end_clean();
|
---|
119 |
|
---|
120 | if (function_exists('the_tags')){
|
---|
121 | ob_start();
|
---|
122 | the_tags(__('Tags:', 'xpress') . ' ',' • ','');
|
---|
123 | $tags = ob_get_contents();
|
---|
124 | ob_end_clean();
|
---|
125 | } else {
|
---|
126 | $tags = '';
|
---|
127 | }
|
---|
128 |
|
---|
129 | ob_start();
|
---|
130 | the_modified_date($date_format);
|
---|
131 | $post_modified_date = ob_get_contents();
|
---|
132 | ob_end_clean();
|
---|
133 |
|
---|
134 | ob_start();
|
---|
135 | the_modified_date($time_format);
|
---|
136 | $post_modified_time = ob_get_contents();
|
---|
137 | ob_end_clean();
|
---|
138 |
|
---|
139 | ob_start();
|
---|
140 | the_time($date_format);
|
---|
141 | $post_date = ob_get_contents();
|
---|
142 | ob_end_clean();
|
---|
143 |
|
---|
144 | ob_start();
|
---|
145 | the_time($time_format);
|
---|
146 | $post_time = ob_get_contents();
|
---|
147 | ob_end_clean();
|
---|
148 |
|
---|
149 |
|
---|
150 | ob_start();
|
---|
151 | comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
|
---|
152 | $comments_popup_link = ob_get_contents();
|
---|
153 | ob_end_clean();
|
---|
154 |
|
---|
155 |
|
---|
156 | $post_title = '<a href="' . $permalink . '">' . $title . '</a>';
|
---|
157 | $post_date_time = $post_date . ' ' . $post_time ;
|
---|
158 | $post_modified_date_time = $post_modified_date . ' ' . $post_modified_time ;
|
---|
159 | $trackback_url = trackback_url(false);
|
---|
160 | $post_viwes = xpress_post_views_count('post_id=' . $post_id . '&format=' . __('Views :%d', 'xpress'). '&echo=0');
|
---|
161 |
|
---|
162 | // if (empty($tags)) $tags = __('Not Tag');
|
---|
163 |
|
---|
164 | $row_data = array(
|
---|
165 | 'post_id' => $post_id ,
|
---|
166 | 'post_title' => $post_title ,
|
---|
167 | 'post_date' => $post_date ,
|
---|
168 | 'post_time' => $post_time ,
|
---|
169 | 'post_date_time' => $post_date_time ,
|
---|
170 | 'post_modified_date' => $post_modified_date ,
|
---|
171 | 'post_modified_time' => $post_modified_time ,
|
---|
172 | 'post_modified_date_time' => $post_modified_date_time ,
|
---|
173 | 'post_author' => $author ,
|
---|
174 | 'post_category' => $category ,
|
---|
175 | 'post_tags' => $tags,
|
---|
176 | 'post_views' => $post_viwes,
|
---|
177 | 'comment_link' => $comments_popup_link ,
|
---|
178 | 'trackback_url' => $trackback_url
|
---|
179 | );
|
---|
180 | $block['contents']['item'.$item_no] = $row_data;
|
---|
181 | $item_no++;
|
---|
182 | }
|
---|
183 | } // end of foreach
|
---|
184 | $block['data_count'] = $item_no; //xml unserialise error
|
---|
185 | return $block ;
|
---|
186 | }
|
---|
187 |
|
---|
188 | function get_tag_id($tag_list = ''){
|
---|
189 | global $wpdb,$wp_query;
|
---|
190 |
|
---|
191 | if (empty($tag_list)) return '';
|
---|
192 |
|
---|
193 | $tag_arrys = explode(',',$tag_list);
|
---|
194 | $tag_str = '';
|
---|
195 | foreach ($tag_arrys as $tag_s){
|
---|
196 | if (!empty($tag_str)) $tag_str .= ',';
|
---|
197 | $tag_str .= "'" . $tag_s . "'";
|
---|
198 | }
|
---|
199 |
|
---|
200 | $db_xpress_terms = $wpdb->terms; // upper 2.3
|
---|
201 | $db_xpress_term_taxonomy = $wpdb->term_taxonomy; // upper 2.3
|
---|
202 |
|
---|
203 | $query = "
|
---|
204 | SELECT $db_xpress_terms.term_id as tag_ID
|
---|
205 | FROM $db_xpress_terms LEFT JOIN $db_xpress_term_taxonomy ON $db_xpress_terms.term_id = $db_xpress_term_taxonomy.term_id
|
---|
206 | WHERE $db_xpress_term_taxonomy.taxonomy = 'post_tag' AND $db_xpress_terms.name IN ($tag_str)
|
---|
207 | ";
|
---|
208 |
|
---|
209 | $tags = $wpdb->get_results($query);
|
---|
210 | $no =0;
|
---|
211 | foreach ($tags as $tag){
|
---|
212 | $tags_id[$no] = $tag->tag_ID;
|
---|
213 | $no++;
|
---|
214 | }
|
---|
215 | $tags_id_list = implode(',' , $tags_id);
|
---|
216 | return $tags_id_list;
|
---|
217 | }
|
---|
218 | ?> |
---|