1 | <?php
|
---|
2 | function xpress_user_access_level(){
|
---|
3 | global $current_user;
|
---|
4 |
|
---|
5 | $level = @$current_user->user_level;
|
---|
6 | $role = @$current_user->roles[0];
|
---|
7 | switch ($role){
|
---|
8 | case 'administrator':
|
---|
9 | $role_level = 10;
|
---|
10 | break;
|
---|
11 | case 'editor':
|
---|
12 | $role_level = 7;
|
---|
13 | break;
|
---|
14 | case 'author':
|
---|
15 | $role_level = 2;
|
---|
16 | break;
|
---|
17 | case 'contributor':
|
---|
18 | $role_level = 1;
|
---|
19 | break;
|
---|
20 | default:
|
---|
21 | $role_level = 0;
|
---|
22 | }
|
---|
23 |
|
---|
24 | if ($level > $role_level){
|
---|
25 | return $level;
|
---|
26 | } else {
|
---|
27 | return $role_level;
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | function xpress_is_contributor()
|
---|
32 | {
|
---|
33 | global $current_user;
|
---|
34 | get_currentuserinfo();
|
---|
35 | if (xpress_user_access_level() > 3)
|
---|
36 | return true;
|
---|
37 | else
|
---|
38 | return false;
|
---|
39 | }
|
---|
40 |
|
---|
41 | function xpress_is_multiblog() {
|
---|
42 | global $xoops_config;
|
---|
43 |
|
---|
44 | if (function_exists('is_multisite') && is_multisite()) return true;
|
---|
45 | return false;
|
---|
46 | }
|
---|
47 |
|
---|
48 | function xpress_is_multiblog_root() {
|
---|
49 | global $blog_id;
|
---|
50 | if ( xpress_is_multiblog() && $blog_id == BLOG_ID_CURRENT_SITE){
|
---|
51 | return true;
|
---|
52 | } else {
|
---|
53 | return false;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | function xpress_is_wp_version($operator='==',$comp_version){
|
---|
58 | global $xoops_config;
|
---|
59 | return version_compare($xoops_config->wp_version, $comp_version, $operator);
|
---|
60 | }
|
---|
61 |
|
---|
62 | function xpress_is_theme_sidebar_disp(){
|
---|
63 | global $xpress_config;
|
---|
64 | if (is_wordpress_style()) return true;
|
---|
65 | return $xpress_config->is_theme_sidebar_disp;
|
---|
66 | }
|
---|
67 |
|
---|
68 | function xpress_is_author_view_count(){
|
---|
69 | global $xpress_config;
|
---|
70 | return $xpress_config->is_author_view_count;
|
---|
71 | }
|
---|
72 |
|
---|
73 | function xpress_is_multi_user(){
|
---|
74 | global $xpress_config;
|
---|
75 | return $xpress_config->is_multi_user;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | function xpress_the_title($args = '')
|
---|
80 | {
|
---|
81 | $defaults = array(
|
---|
82 | 'echo' => 1
|
---|
83 | );
|
---|
84 | $r = wp_parse_args( $args, $defaults );
|
---|
85 |
|
---|
86 | extract( $r );
|
---|
87 |
|
---|
88 | $output = '<div class ="xpress-post-header">' . "\n";
|
---|
89 |
|
---|
90 | if (function_exists('hotDates')) {
|
---|
91 | ob_start();
|
---|
92 | hotDates();
|
---|
93 | $output .= ob_get_contents();
|
---|
94 | ob_end_clean();
|
---|
95 | }
|
---|
96 | $output .= '<div class ="xpress-post-title">' . "\n";
|
---|
97 | $output .= '<h2><a href="';
|
---|
98 | ob_start();
|
---|
99 | the_permalink();
|
---|
100 | $output .= ob_get_contents();
|
---|
101 | ob_end_clean();
|
---|
102 |
|
---|
103 | if(function_exists('the_title_attribute')){
|
---|
104 | $title = the_title_attribute('echo=0');
|
---|
105 | } else {
|
---|
106 | ob_start();
|
---|
107 | the_title();
|
---|
108 | $title = ob_get_contents();
|
---|
109 | ob_end_clean();
|
---|
110 | }
|
---|
111 |
|
---|
112 | $output .= '" rel="bookmark" title="';
|
---|
113 | $output .= sprintf(__('Permanent Link to %s', 'xpress'), $title);
|
---|
114 | $output .= '">';
|
---|
115 | $output .= $title;
|
---|
116 | $output .= '</a></h2>' . "\n";
|
---|
117 | $output .= '</div>' . "\n";
|
---|
118 | $output .= '</div>' . "\n";
|
---|
119 |
|
---|
120 | if ($echo)
|
---|
121 | echo $output;
|
---|
122 | else
|
---|
123 | return $output;
|
---|
124 |
|
---|
125 | }
|
---|
126 |
|
---|
127 | function xpress_selected_author($args ='' ) {
|
---|
128 | $defaults = array(
|
---|
129 | 'echo' => 1
|
---|
130 | );
|
---|
131 | $r = wp_parse_args( $args, $defaults );
|
---|
132 |
|
---|
133 | extract( $r );
|
---|
134 |
|
---|
135 | $output = '';
|
---|
136 | $author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
|
---|
137 | if (!empty($_COOKIE[$author_cookie])){
|
---|
138 | $uid = intval($_COOKIE[$author_cookie]);
|
---|
139 | $user_info = get_userdata($uid);
|
---|
140 | $output = $user_info->display_name;
|
---|
141 | }
|
---|
142 | if ($echo)
|
---|
143 | echo $output;
|
---|
144 | else
|
---|
145 | return $output;
|
---|
146 |
|
---|
147 | }
|
---|
148 | function xpress_selected_author_id($args ='' ) {
|
---|
149 | $defaults = array(
|
---|
150 | 'echo' => 1
|
---|
151 | );
|
---|
152 | $r = wp_parse_args( $args, $defaults );
|
---|
153 |
|
---|
154 | extract( $r );
|
---|
155 | $output = '';
|
---|
156 | $author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
|
---|
157 | if (!empty($_COOKIE[$author_cookie])){
|
---|
158 | $output = intval($_COOKIE[$author_cookie]);
|
---|
159 | } else {
|
---|
160 | $output = '';
|
---|
161 | }
|
---|
162 | if ($echo)
|
---|
163 | echo $output;
|
---|
164 | else
|
---|
165 | return $output;
|
---|
166 | }
|
---|
167 |
|
---|
168 | function xpress_now_user_level($args ='' ) {
|
---|
169 | global $current_user;
|
---|
170 | $defaults = array(
|
---|
171 | 'echo' => 1
|
---|
172 | );
|
---|
173 | $r = wp_parse_args( $args, $defaults );
|
---|
174 |
|
---|
175 | extract( $r );
|
---|
176 |
|
---|
177 | $output = xpress_user_access_level();
|
---|
178 | if ($echo)
|
---|
179 | echo $output;
|
---|
180 | else
|
---|
181 | return $output;
|
---|
182 | }
|
---|
183 |
|
---|
184 | function xpress_credit($args ='')
|
---|
185 | {
|
---|
186 | global $wp_version , $xoops_config;
|
---|
187 | if ($xoops_config->is_wpmu) {
|
---|
188 | global $wpmu_version;
|
---|
189 | }
|
---|
190 |
|
---|
191 | $defaults = array(
|
---|
192 | 'echo' => 1,
|
---|
193 | 'no_link' => 0
|
---|
194 | );
|
---|
195 | $r = wp_parse_args( $args, $defaults );
|
---|
196 |
|
---|
197 | extract( $r );
|
---|
198 |
|
---|
199 | $xpress_version = $xoops_config->module_version;
|
---|
200 | $xpress_codename = $xoops_config->module_codename;
|
---|
201 | if ($no_link){
|
---|
202 | if ($xoops_config->is_wpmu) {
|
---|
203 | $output = 'XPressMU Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename);
|
---|
204 | $output .= '(included WordPress MU ' . $wpmu_version. ')';
|
---|
205 | } else {
|
---|
206 | $output = 'XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename);
|
---|
207 | if (strstr($wp_version,'ME')){
|
---|
208 | $output .= '(included WordPress ' . $wp_version . ')';
|
---|
209 | } else {
|
---|
210 | $output .= '(included WordPress ' . $wp_version . ')';
|
---|
211 | }
|
---|
212 | }
|
---|
213 | } else {
|
---|
214 | if ($xoops_config->is_wpmu) {
|
---|
215 | $output = '<a href="http://ja.xpressme.info"'. " target='_blank'" . '>XPressMU Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
|
---|
216 | $output .= '(included <a href="http://mu.wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress MU ' . $wpmu_version . '</a>)';
|
---|
217 | } else {
|
---|
218 | $output = '<a href="http://ja.xpressme.info"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
|
---|
219 | if (strstr($wp_version,'ME')){
|
---|
220 | $output .= '(included <a href="http://wpme.sourceforge.jp/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
|
---|
221 | } else {
|
---|
222 | $output .= '(included <a href="http://wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
|
---|
223 | }
|
---|
224 | }
|
---|
225 | }
|
---|
226 | if ($echo)
|
---|
227 | echo $output;
|
---|
228 | else
|
---|
229 | return $output;
|
---|
230 | }
|
---|
231 |
|
---|
232 | function xpress_convert_time($args ='')
|
---|
233 | {
|
---|
234 | $defaults = array(
|
---|
235 | 'echo' => 1,
|
---|
236 | 'format' => '(%.3f sec.)'
|
---|
237 | );
|
---|
238 | $r = wp_parse_args( $args, $defaults );
|
---|
239 |
|
---|
240 | extract( $r );
|
---|
241 |
|
---|
242 | $output = sprintf($format,timer_stop(0));
|
---|
243 | if ($echo)
|
---|
244 | echo $output;
|
---|
245 | else
|
---|
246 | return $output;
|
---|
247 | }
|
---|
248 |
|
---|
249 | function xpress_left_arrow_post_link($args ='')
|
---|
250 | {
|
---|
251 | global $xpress_config;
|
---|
252 | $defaults = array(
|
---|
253 | 'echo' => 1
|
---|
254 | );
|
---|
255 | $r = wp_parse_args( $args, $defaults );
|
---|
256 |
|
---|
257 | extract( $r );
|
---|
258 |
|
---|
259 | $ret = '';
|
---|
260 |
|
---|
261 | $link_str = '« %link';
|
---|
262 |
|
---|
263 | if($xpress_config->is_left_postnavi_old){
|
---|
264 | $link_title = $xpress_config->old_post_link_text;
|
---|
265 | ob_start();
|
---|
266 | if ($xpress_config->is_postnavi_title_disp)
|
---|
267 | previous_post_link($link_str);
|
---|
268 | else
|
---|
269 | previous_post_link($link_str,$link_title);
|
---|
270 | $ret = ob_get_contents();
|
---|
271 | ob_end_clean();
|
---|
272 | ob_start();
|
---|
273 | previous_post_link('%link',$link_title);
|
---|
274 | $GLOBALS['left_arrow_post_link'] = ob_get_contents();
|
---|
275 | ob_end_clean();
|
---|
276 |
|
---|
277 | } else {
|
---|
278 | $link_title = $xpress_config->newer_post_link_text;
|
---|
279 | ob_start();
|
---|
280 | if ($xpress_config->is_postnavi_title_disp)
|
---|
281 | next_post_link($link_str);
|
---|
282 | else
|
---|
283 | next_post_link($link_str,$link_title);
|
---|
284 | $ret = ob_get_contents();
|
---|
285 | ob_end_clean();
|
---|
286 | ob_start();
|
---|
287 | next_post_link('%link',$link_title);
|
---|
288 | $GLOBALS['left_arrow_post_link'] = ob_get_contents();
|
---|
289 | ob_end_clean();
|
---|
290 |
|
---|
291 | }
|
---|
292 |
|
---|
293 | if ($xpress_config->is_postnavi_title_disp){
|
---|
294 | $on_mouse_show = $link_title;
|
---|
295 | } else {
|
---|
296 | if($xpress_config->is_left_postnavi_old){
|
---|
297 | ob_start();
|
---|
298 | previous_post_link('%link');
|
---|
299 | $on_mouse_show = ob_get_contents();
|
---|
300 | ob_end_clean();
|
---|
301 | } else {
|
---|
302 | ob_start();
|
---|
303 | next_post_link('%link');
|
---|
304 | $on_mouse_show = ob_get_contents();
|
---|
305 | ob_end_clean();
|
---|
306 | }
|
---|
307 | $pattern = "<a[^>]*?>(.*)<\/a>";
|
---|
308 | preg_match("/".$pattern."/s", $on_mouse_show, $body_matches);
|
---|
309 | $on_mouse_show = $body_matches[1];
|
---|
310 | }
|
---|
311 | $output = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
|
---|
312 |
|
---|
313 | if (icon_exists($xpress_config->post_left_arrow_image_link)){
|
---|
314 | $img_link = str_replace($link_title,"<img src=\"$xpress_config->post_left_arrow_image_link\" align=\"absmiddle\"/>",$GLOBALS['left_arrow_post_link']);
|
---|
315 | $img_link = str_replace('rel=','title="'.$on_mouse_show.'" rel=',$img_link);
|
---|
316 | $output = str_replace('«',$img_link , $output);
|
---|
317 | }
|
---|
318 |
|
---|
319 | if ($echo)
|
---|
320 | echo $output;
|
---|
321 | else
|
---|
322 | return $output;
|
---|
323 | }
|
---|
324 |
|
---|
325 | function xpress_right_arrow_post_link($args ='')
|
---|
326 | {
|
---|
327 | global $xpress_config;
|
---|
328 | $defaults = array(
|
---|
329 | 'echo' => 1
|
---|
330 | );
|
---|
331 | $r = wp_parse_args( $args, $defaults );
|
---|
332 |
|
---|
333 | extract( $r );
|
---|
334 |
|
---|
335 | $ret = '';
|
---|
336 |
|
---|
337 | $link_str = '%link »';
|
---|
338 |
|
---|
339 | if($xpress_config->is_left_postnavi_old){
|
---|
340 | $link_title = $xpress_config->newer_post_link_text;
|
---|
341 | ob_start();
|
---|
342 | if ($xpress_config->is_postnavi_title_disp)
|
---|
343 | next_post_link($link_str);
|
---|
344 | else
|
---|
345 | next_post_link($link_str,$link_title);
|
---|
346 | $ret = ob_get_contents();
|
---|
347 | ob_end_clean();
|
---|
348 | ob_start();
|
---|
349 | next_post_link('%link',$link_title);
|
---|
350 | $GLOBALS['right_arrow_post_link'] = ob_get_contents();
|
---|
351 | ob_end_clean();
|
---|
352 |
|
---|
353 | } else {
|
---|
354 | $link_title = $xpress_config->old_post_link_text;
|
---|
355 | ob_start();
|
---|
356 | if ($xpress_config->is_postnavi_title_disp)
|
---|
357 | previous_post_link($link_str);
|
---|
358 | else
|
---|
359 | previous_post_link($link_str,$link_title);
|
---|
360 | $ret = ob_get_contents();
|
---|
361 | ob_end_clean();
|
---|
362 | ob_start();
|
---|
363 | previous_post_link('%link',$link_title);
|
---|
364 | $GLOBALS['right_arrow_post_link'] = ob_get_contents();
|
---|
365 | ob_end_clean();
|
---|
366 |
|
---|
367 | }
|
---|
368 |
|
---|
369 | if ($xpress_config->is_postnavi_title_disp){
|
---|
370 | $on_mouse_show = $link_title;
|
---|
371 | } else {
|
---|
372 | if($xpress_config->is_left_postnavi_old){
|
---|
373 | ob_start();
|
---|
374 | next_post_link('%link');
|
---|
375 | $on_mouse_show = ob_get_contents();
|
---|
376 | ob_end_clean();
|
---|
377 | } else {
|
---|
378 | ob_start();
|
---|
379 | previous_post_link('%link');
|
---|
380 | $on_mouse_show = ob_get_contents();
|
---|
381 | ob_end_clean();
|
---|
382 | }
|
---|
383 | $pattern = "<a[^>]*?>(.*)<\/a>";
|
---|
384 | preg_match("/".$pattern."/s", $on_mouse_show, $body_matches);
|
---|
385 | $on_mouse_show = $body_matches[1];
|
---|
386 | }
|
---|
387 | $output = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
|
---|
388 |
|
---|
389 | if (icon_exists($xpress_config->post_right_arrow_image_link)){
|
---|
390 | $img_link = str_replace($link_title,"<img src=\"$xpress_config->post_right_arrow_image_link\" align=\"absmiddle\"/>",$GLOBALS['right_arrow_post_link']);
|
---|
391 | $img_link = str_replace('rel=','title="'.$on_mouse_show.'" rel=',$img_link);
|
---|
392 | $output = str_replace('»',$img_link , $output);
|
---|
393 | }
|
---|
394 |
|
---|
395 | if ($echo)
|
---|
396 | echo $output;
|
---|
397 | else
|
---|
398 | return $output;
|
---|
399 | }
|
---|
400 | // page link
|
---|
401 | function xpress_left_arrow_posts_link($args ='')
|
---|
402 | {
|
---|
403 | global $xpress_config;
|
---|
404 | $defaults = array(
|
---|
405 | 'echo' => 1
|
---|
406 | );
|
---|
407 | $r = wp_parse_args( $args, $defaults );
|
---|
408 |
|
---|
409 | extract( $r );
|
---|
410 |
|
---|
411 | $output = '';
|
---|
412 |
|
---|
413 | if($xpress_config->is_left_page_navi_old){
|
---|
414 | $link_title = $xpress_config->old_page_link_text;
|
---|
415 | ob_start();
|
---|
416 | next_posts_link("« $link_title");
|
---|
417 | $output = ob_get_contents();
|
---|
418 | ob_end_clean();
|
---|
419 | } else {
|
---|
420 | $link_title = $xpress_config->newer_page_link_text;
|
---|
421 | ob_start();
|
---|
422 | previous_posts_link("« $link_title");
|
---|
423 | $output = ob_get_contents();
|
---|
424 | ob_end_clean();
|
---|
425 | }
|
---|
426 |
|
---|
427 | if (icon_exists($xpress_config->page_left_arrow_image_link)){
|
---|
428 | $output = $img_link . str_replace('«','' , $output);
|
---|
429 | $img_link = str_replace($link_title,"<img src=\"$xpress_config->page_left_arrow_image_link\" align=\"absmiddle\"/>",$output);
|
---|
430 | $output = $img_link . $output;
|
---|
431 | }
|
---|
432 |
|
---|
433 | if ($echo)
|
---|
434 | echo $output;
|
---|
435 | else
|
---|
436 | return $output;
|
---|
437 | }
|
---|
438 |
|
---|
439 |
|
---|
440 | function xpress_right_arrow_posts_link($args ='')
|
---|
441 | {
|
---|
442 | global $xpress_config;
|
---|
443 | $defaults = array(
|
---|
444 | 'echo' => 1
|
---|
445 | );
|
---|
446 | $r = wp_parse_args( $args, $defaults );
|
---|
447 |
|
---|
448 | extract( $r );
|
---|
449 |
|
---|
450 | $output = '';
|
---|
451 |
|
---|
452 | if($xpress_config->is_left_page_navi_old){
|
---|
453 | $link_title = $xpress_config->newer_page_link_text;
|
---|
454 | ob_start();
|
---|
455 | previous_posts_link("$link_title »");
|
---|
456 | $output = ob_get_contents();
|
---|
457 | ob_end_clean();
|
---|
458 | } else {
|
---|
459 | $link_title = $xpress_config->old_page_link_text;
|
---|
460 | ob_start();
|
---|
461 | next_posts_link("$link_title »");
|
---|
462 | $output = ob_get_contents();
|
---|
463 | ob_end_clean();
|
---|
464 | }
|
---|
465 |
|
---|
466 | if (icon_exists($xpress_config->page_right_arrow_image_link)){
|
---|
467 | $output = $img_link . str_replace('»','' , $output);
|
---|
468 | $img_link = str_replace($link_title,"<img src=\"$xpress_config->page_right_arrow_image_link\" align=\"absmiddle\"/>",$output);
|
---|
469 | $output = $output . $img_link;
|
---|
470 | }
|
---|
471 | if ($echo)
|
---|
472 | echo $output;
|
---|
473 | else
|
---|
474 | return $output;
|
---|
475 | }
|
---|
476 |
|
---|
477 | function xpress_substr($str, $start, $length, $trimmarker = '...')
|
---|
478 | {
|
---|
479 | if (function_exists('mb_substr')){
|
---|
480 | $str2 = mb_substr( $str , $start , $length);
|
---|
481 | return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
|
---|
482 | } else {
|
---|
483 | return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
|
---|
484 | }
|
---|
485 | }
|
---|
486 |
|
---|
487 | function icon_exists($str = '')
|
---|
488 | {
|
---|
489 | global $xpress_config;
|
---|
490 | $root_path = $_SERVER['DOCUMENT_ROOT'];
|
---|
491 | $root_pattern = str_replace(".","\.",$root_path);
|
---|
492 | $root_pattern = '/'. str_replace("/","\/",$root_pattern) . '/';
|
---|
493 | $host = str_replace(".","\.",$_SERVER['SERVER_NAME']);
|
---|
494 | $pattern = "/https?:\/\/{$host}/";
|
---|
495 | if (preg_match($pattern,$str)){
|
---|
496 | $str = preg_replace($pattern,$root_path,$str);
|
---|
497 | } else if (!preg_match($root_pattern,$str)){
|
---|
498 | $str = $root_path.$str;
|
---|
499 | }
|
---|
500 | return file_exists($str);
|
---|
501 | }
|
---|
502 |
|
---|
503 |
|
---|
504 | // views count
|
---|
505 | // Set and retrieves post views given a post ID or post object.
|
---|
506 | // Retrieves post views given a post ID or post object.
|
---|
507 | function xpress_post_views_count($args ='') {
|
---|
508 | global $xoops_db,$wpdb;
|
---|
509 | global $blog_id;
|
---|
510 | static $post_cache_views;
|
---|
511 |
|
---|
512 | $defaults = array(
|
---|
513 | 'post_id' => 0,
|
---|
514 | 'format'=> __('views :%d','xpressme'),
|
---|
515 | 'echo' => 1
|
---|
516 | );
|
---|
517 | $r = wp_parse_args( $args, $defaults );
|
---|
518 |
|
---|
519 | extract( $r );
|
---|
520 |
|
---|
521 | if ( empty($post_id) ) {
|
---|
522 | if ( isset($GLOBALS['post']) )
|
---|
523 | $post_id = $GLOBALS['post']->ID;
|
---|
524 | }
|
---|
525 | if ( empty($blogid) ) {
|
---|
526 | $blogid = $blog_id;
|
---|
527 | }
|
---|
528 |
|
---|
529 | $post_id = intval($post_id);
|
---|
530 | if($post_id==0) return null;
|
---|
531 | if(!isset($post_cache_views[$post_id])){
|
---|
532 | if (is_null($blogid)){
|
---|
533 | $blog_where = '';
|
---|
534 | } else {
|
---|
535 | $blog_where = ' AND blog_id = '. $blogid;
|
---|
536 | }
|
---|
537 | $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id " . $blog_where;
|
---|
538 | $post_views = $xoops_db->get_var($sql);
|
---|
539 | if (!$post_views) {
|
---|
540 | $post_cache_views[$post_id] = 0;
|
---|
541 | }else{
|
---|
542 | $post_cache_views[$post_id] = $post_views;
|
---|
543 | }
|
---|
544 | }
|
---|
545 | $v_count = intval($post_cache_views[$post_id]);
|
---|
546 |
|
---|
547 | if (empty($format)) $format = __('views :%d','xpressme');
|
---|
548 |
|
---|
549 | $output = sprintf($format,$v_count);
|
---|
550 |
|
---|
551 | if ($echo)
|
---|
552 | echo $output;
|
---|
553 | else
|
---|
554 | return $output;
|
---|
555 | }
|
---|
556 |
|
---|
557 | function set_post_views_count($content) {
|
---|
558 | if ( empty($_GET["feed"]) && empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
|
---|
559 | post_views_counting();
|
---|
560 | }
|
---|
561 | return $content;
|
---|
562 | }
|
---|
563 |
|
---|
564 | // Set post views given a post ID or post object.
|
---|
565 | function post_views_counting($post_id = 0) {
|
---|
566 | global $xoops_db,$wpdb;
|
---|
567 | global $table_prefix;
|
---|
568 | global $blog_id;
|
---|
569 | static $views;
|
---|
570 |
|
---|
571 | $post_id = intval($post_id);
|
---|
572 | if ( empty($post_id) && isset($GLOBALS['post']) ){
|
---|
573 | $post_id = $GLOBALS['post']->ID;
|
---|
574 | }
|
---|
575 |
|
---|
576 | $views_db = get_wp_prefix() . 'views';
|
---|
577 | if (is_null($blog_id)) $blog_id = 0;
|
---|
578 |
|
---|
579 | if($post_id==0 || !empty($views[$post_id])) return null;
|
---|
580 |
|
---|
581 | if(!xpress_is_author_view_count()){
|
---|
582 | $current_user_id = $GLOBALS['current_user']->ID;
|
---|
583 | $post_author_id = $GLOBALS['post']->post_author;
|
---|
584 | if ($current_user_id ==$post_author_id) return null;
|
---|
585 | }
|
---|
586 | if (is_null($blog_id)){
|
---|
587 | $blog_where = '';
|
---|
588 | } else {
|
---|
589 | $blog_where = ' AND blog_id = ' . $blog_id;
|
---|
590 | }
|
---|
591 | $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id" . $blog_where;
|
---|
592 | $post_views_found = $xoops_db->get_var($sql);
|
---|
593 | if($post_views_found){
|
---|
594 | $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id" . $blog_where;
|
---|
595 | }else{
|
---|
596 | if (is_null($blog_id)){
|
---|
597 | $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
|
---|
598 | } else {
|
---|
599 | $sql = "INSERT INTO " . $views_db . " (blog_id, post_id, post_views) VALUES ($blog_id, $post_id, 1)";
|
---|
600 | }
|
---|
601 | }
|
---|
602 | $xoops_db->query($sql);
|
---|
603 | return true;
|
---|
604 | }
|
---|
605 |
|
---|
606 | function get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$more_link_text = '') {
|
---|
607 | global $post,$xpress_config;
|
---|
608 |
|
---|
609 | $blog_encoding = get_option('blog_charset');
|
---|
610 | $text = get_the_content('');
|
---|
611 | if (function_exists('strip_shortcodes')){ //@since WP2.5
|
---|
612 | $text = strip_shortcodes( $text );
|
---|
613 | }
|
---|
614 | $text = apply_filters('the_content', $text);
|
---|
615 | $text = str_replace(']]>', ']]>', $text);
|
---|
616 | $text = strip_tags($text);
|
---|
617 | $is_almost_ascii = ($xpress_config->ascii_judged_rate < round(@(mb_strlen($text, $blog_encoding) / strlen($text)) * 100)) ? true : false;
|
---|
618 | if($is_almost_ascii) {
|
---|
619 | $words = explode(' ', $text, $excerpt_length_word + 1);
|
---|
620 |
|
---|
621 | if(count($words) > $excerpt_length_word) {
|
---|
622 | array_pop($words);
|
---|
623 | array_push($words, ' ... ');
|
---|
624 | $text = implode(' ', $words);
|
---|
625 | if (!empty($more_link_text)) $text .= '<div class="xpress-more-link"><a href="'. get_permalink() . "\">".$more_link_text .'</a></div>';
|
---|
626 |
|
---|
627 | }
|
---|
628 | }
|
---|
629 | elseif(mb_strlen($text, $blog_encoding) > $excerpt_length_character) {
|
---|
630 | $text = mb_substr($text, 0, $xpress_config->excerpt_length_character, $blog_encoding) . ' ... ';
|
---|
631 | if (!empty($more_link_text)) $text .= '<div class="xpress-more-link"><a href="'. get_permalink() . "\">".$more_link_text .'</a></div>';
|
---|
632 | }
|
---|
633 |
|
---|
634 | return $text;
|
---|
635 | }
|
---|
636 |
|
---|
637 | function xpress_the_content($args ='')
|
---|
638 | {
|
---|
639 | global $post,$xpress_config;
|
---|
640 |
|
---|
641 | $defaults = array(
|
---|
642 | 'more_link_text'=> $xpress_config->more_link_text,
|
---|
643 | 'stripteaser' => 0,
|
---|
644 | 'more_file' => '',
|
---|
645 | 'configration_select' => 1,
|
---|
646 | 'do_excerpt' => 0,
|
---|
647 | 'excerpt_length_word' => $xpress_config->excerpt_length_word ,
|
---|
648 | 'excerpt_length_character' => $xpress_config->excerpt_length_character ,
|
---|
649 | 'excerpt_more_link_text' => $xpress_config->excerpt_more_link_text ,
|
---|
650 | 'echo' => 1
|
---|
651 | );
|
---|
652 | $r = wp_parse_args( $args, $defaults );
|
---|
653 |
|
---|
654 | extract( $r );
|
---|
655 |
|
---|
656 | if ($configration_select){
|
---|
657 | if ($xpress_config->is_content_excerpt)
|
---|
658 | $do_excerpt = 1;
|
---|
659 | else
|
---|
660 | $do_excerpt = 0;
|
---|
661 | }
|
---|
662 |
|
---|
663 | if ($do_excerpt){
|
---|
664 | $content = get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$excerpt_more_link_text);
|
---|
665 | } else {
|
---|
666 | $content = get_the_content($more_link_text,$stripteaser,$more_file);
|
---|
667 | $content = apply_filters('the_content', $content);
|
---|
668 | $content = str_replace(']]>', ']]>', $content);
|
---|
669 | }
|
---|
670 | if ($echo)
|
---|
671 | echo $content;
|
---|
672 | else
|
---|
673 | return $content;
|
---|
674 | }
|
---|
675 |
|
---|
676 | function xpress_post_new_link($args ='')
|
---|
677 | {
|
---|
678 | global $xoops_config;
|
---|
679 |
|
---|
680 | $defaults = array(
|
---|
681 | 'link_title'=> 'Post New',
|
---|
682 | 'echo' => 1
|
---|
683 | );
|
---|
684 | $r = wp_parse_args( $args, $defaults );
|
---|
685 |
|
---|
686 | extract( $r );
|
---|
687 |
|
---|
688 |
|
---|
689 | if (xpress_is_wp_version('>=','2.1')){
|
---|
690 | $output = '<a href="'. get_bloginfo('url') . '/wp-admin/post-new.php' . '">' . $link_title . '</a>';
|
---|
691 | } else {
|
---|
692 | $output = '<a href="'. get_bloginfo('url') . '/wp-admin/post.php' . '">' . $link_title . '</a>';
|
---|
693 | }
|
---|
694 | if ($echo)
|
---|
695 | echo $output;
|
---|
696 | else
|
---|
697 | return $output;
|
---|
698 | }
|
---|
699 |
|
---|
700 | function xpress_conditional_title($args ='')
|
---|
701 | {
|
---|
702 | $defaults = array(
|
---|
703 | 'echo' => 1
|
---|
704 | );
|
---|
705 | $r = wp_parse_args( $args, $defaults );
|
---|
706 |
|
---|
707 | extract( $r );
|
---|
708 |
|
---|
709 | $selected_author = xpress_selected_author('echo=0');
|
---|
710 |
|
---|
711 | $output = __('Main', 'xpressme');
|
---|
712 | $output = '';
|
---|
713 | if (is_category())
|
---|
714 | $output = sprintf(__('Archive for the ‘%s’ Category', 'xpressme'), single_cat_title('', false));
|
---|
715 | if (function_exists( 'is_tag' )){
|
---|
716 | if (is_tag())
|
---|
717 | $output = sprintf(__('Posts Tagged ‘%s’', 'xpressme'), single_tag_title('', false) );
|
---|
718 | }
|
---|
719 | if (is_day())
|
---|
720 | $output = sprintf(__('Archive for %s|Daily archive page', 'xpressme'), get_the_time(__('F jS, Y', 'xpressme')));
|
---|
721 | if (is_month())
|
---|
722 | $output = sprintf(__('Archive for %s|Monthly archive page', 'xpressme'), get_the_time(__('F, Y', 'xpressme')));
|
---|
723 | if (is_year())
|
---|
724 | $output = sprintf(__('Archive for %s|Yearly archive page', 'xpressme'), get_the_time(__('Y', 'xpressme')));
|
---|
725 | if (is_author()){
|
---|
726 | if (empty($selected_author))
|
---|
727 | $output = sprintf(__('Archive for the ‘%s’ Author', 'xpressme'), get_author_name( get_query_var('author')));
|
---|
728 | }
|
---|
729 | if (is_search())
|
---|
730 | $output = sprintf(__('Search Results of word ‘%s’', 'xpressme'), get_search_query());
|
---|
731 |
|
---|
732 | if (!empty($selected_author)){
|
---|
733 | $selected_id = xpress_selected_author_id('echo=0');
|
---|
734 | // $output = get_avatar($selected_id,$size = '32') . sprintf(__('Article of %s', 'xpressme'), $selected_author) . ' - ' . $output;
|
---|
735 | if (empty($output))
|
---|
736 | $output = sprintf(__('Article of %s', 'xpressme'), $selected_author) ;
|
---|
737 | else
|
---|
738 | $output = sprintf(__('Article of %s', 'xpressme'), $selected_author) . ' - ' . $output;
|
---|
739 | }
|
---|
740 | if ($echo)
|
---|
741 | echo $output;
|
---|
742 | else
|
---|
743 | return $output;
|
---|
744 | }
|
---|
745 |
|
---|
746 | // The content of the trackback/pingback to the post is returned by the list.
|
---|
747 | function xpress_pings_list($args =''){
|
---|
748 | $defaults = array(
|
---|
749 | 'echo' => 1
|
---|
750 | );
|
---|
751 | $r = wp_parse_args( $args, $defaults );
|
---|
752 |
|
---|
753 | extract( $r );
|
---|
754 |
|
---|
755 | $trackbacks = xpress_get_pings();
|
---|
756 | if (! empty($trackbacks)) {
|
---|
757 | $output = '<ol id="xpress_pingslist"> ';
|
---|
758 |
|
---|
759 | foreach ($trackbacks as $trackback){
|
---|
760 | $list = date(get_settings('date_format'),$trackback['date']) . ' <a target="_blank" href="' . $trackback['site_url'] . '" rel="external nofollow">' . sprintf(__('From %1$s on site %2$s','xpressme'),$trackback['title'],$trackback['site_name']) . "</a>\n" ;
|
---|
761 |
|
---|
762 | $output .= '<li>';
|
---|
763 | $output .= $list ;
|
---|
764 | $output .= '</li>';
|
---|
765 |
|
---|
766 | }
|
---|
767 | $output .= '</ol>' ;
|
---|
768 | } else {
|
---|
769 | $output = '';
|
---|
770 | }
|
---|
771 |
|
---|
772 | if ($echo)
|
---|
773 | echo $output;
|
---|
774 | else
|
---|
775 | return $output;
|
---|
776 | }
|
---|
777 |
|
---|
778 | // The amount of the trackback/pingback to the post is returned.
|
---|
779 | function xpress_pings_number( $args ='' ) {
|
---|
780 | $defaults = array(
|
---|
781 | 'zero' => __('No Trackback/Pingback', 'xpressme'),
|
---|
782 | 'one' => __('One Trackback/Pingback', 'xpressme'),
|
---|
783 | 'more' => __('% TrackBack/Pingback', 'xpressme'),
|
---|
784 | 'deprecated' => '',
|
---|
785 | 'echo' => 1
|
---|
786 | );
|
---|
787 | $r = wp_parse_args( $args, $defaults );
|
---|
788 |
|
---|
789 | extract( $r );
|
---|
790 |
|
---|
791 | $pings = xpress_get_pings();
|
---|
792 | if (empty($pings)){
|
---|
793 | $number = 0;
|
---|
794 | }else {
|
---|
795 | $number = count($pings);
|
---|
796 | }
|
---|
797 | if ( $number > 1 )
|
---|
798 | $output = str_replace('%', number_format_i18n($number), $more);
|
---|
799 | elseif ( $number == 0 )
|
---|
800 | $output = $zero;
|
---|
801 | else // must be one
|
---|
802 | $output = $one;
|
---|
803 |
|
---|
804 | if ($echo)
|
---|
805 | echo $output;
|
---|
806 | else
|
---|
807 | return $output;
|
---|
808 | }
|
---|
809 |
|
---|
810 | // xpress_get_pings() is a subfunction used with xpress_pings_number() and xpress_pings_list().
|
---|
811 | function xpress_get_pings()
|
---|
812 | {
|
---|
813 | global $withcomments, $post, $wpdb, $id, $trackback, $user_login, $user_ID, $user_identity;
|
---|
814 |
|
---|
815 | if ( ! (is_single() || is_page() || $withcomments) )
|
---|
816 | return;
|
---|
817 |
|
---|
818 | /** @todo Use API instead of SELECTs. */
|
---|
819 | if ( $user_ID) {
|
---|
820 | $trackbacks = $wpdb->get_results(sprintf("SELECT * , UNIX_TIMESTAMP(comment_date) AS comment_timestamp ,UNIX_TIMESTAMP(comment_date_gmt) AS comment_timestamp_gmt FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) AND ( comment_type = 'trackback' OR comment_type = 'pingback' ) ORDER BY comment_date", $post->ID, $user_ID));
|
---|
821 | } else if ( empty($trackback_author) ) {
|
---|
822 | $trackbacks = $wpdb->get_results(sprintf("SELECT * , UNIX_TIMESTAMP(comment_date) AS comment_timestamp ,UNIX_TIMESTAMP(comment_date_gmt) AS comment_timestamp_gmt FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND ( comment_type = 'trackback' OR comment_type = 'pingback' ) ORDER BY comment_date", $post->ID));
|
---|
823 | } else {
|
---|
824 | $trackbacks = $wpdb->get_results(sprintf("SELECT * , UNIX_TIMESTAMP(comment_date) AS comment_timestamp ,UNIX_TIMESTAMP(comment_date_gmt) AS comment_timestamp_gmt FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) AND ( comment_type = 'trackback' OR comment_type = 'pingback' ) ORDER BY comment_date", $post->ID, $trackback_author, $trackback_author_email));
|
---|
825 | }
|
---|
826 |
|
---|
827 | if ($trackbacks){
|
---|
828 | $ret = array();
|
---|
829 | foreach ($trackbacks as $trackback){
|
---|
830 |
|
---|
831 | $pattern = '<strong>(.*)<\/strong>(.*)';
|
---|
832 | if ( preg_match ( "/".$pattern."/i", $trackback->comment_content , $match ) ){
|
---|
833 | $title = $match[1];
|
---|
834 | $content = $match[2];
|
---|
835 | }
|
---|
836 | if (empty($title)) $title = $trackback->comment_author;
|
---|
837 |
|
---|
838 |
|
---|
839 | $row_data = array(
|
---|
840 | 'ID' => $trackback->comment_ID ,
|
---|
841 | 'post_ID' => $trackback->comment_post_ID ,
|
---|
842 | 'site_name' => $trackback->comment_author ,
|
---|
843 | 'site_url' => $trackback->comment_author_url ,
|
---|
844 | 'title' => $title ,
|
---|
845 | 'content' => $content ,
|
---|
846 | 'date' => $trackback->comment_timestamp ,
|
---|
847 | 'date_gmt' => $trackback->comment_timestamp_gmt ,
|
---|
848 | 'agent' => $trackback->comment_agent ,
|
---|
849 | 'type' => $trackback->comment_type ,
|
---|
850 | 'IP' => $trackback->comment_author_IP ,
|
---|
851 | );
|
---|
852 | array_push($ret,$row_data);
|
---|
853 | }
|
---|
854 | return $ret;
|
---|
855 | }
|
---|
856 | return false;
|
---|
857 | }
|
---|
858 |
|
---|
859 | function xpress_get_calendar($args = '') {
|
---|
860 | global $wpdb, $m, $monthnum, $year, $wp_locale, $posts , $xoops_config;
|
---|
861 |
|
---|
862 | $defaults = array(
|
---|
863 | sun_color => '#DB0000',
|
---|
864 | sat_color => '#004D99',
|
---|
865 | initial => true
|
---|
866 | );
|
---|
867 | $r = wp_parse_args( $args, $defaults );
|
---|
868 |
|
---|
869 | extract( $r );
|
---|
870 |
|
---|
871 | ob_start();
|
---|
872 | get_calendar(true);
|
---|
873 | $calendar = ob_get_contents();
|
---|
874 | ob_end_clean();
|
---|
875 | $calendar = preg_replace('/<th abbr=/', '<th align="center" abbr=', $calendar); //week name align center
|
---|
876 | $calendar = preg_replace('/<td>/', '<td align="center">', $calendar); //days align center
|
---|
877 | $calendar = preg_replace('/<td id="today">/', '<td id="today" align="center">', $calendar); //today align center
|
---|
878 | $calendar = preg_replace('/<span style="color:[^>]*>/', '', $calendar); //wp2011 color delete
|
---|
879 | $calendar = preg_replace('/<\/span>/', '', $calendar); //wp2011 color delete
|
---|
880 |
|
---|
881 | $week_begins = intval(get_option('start_of_week'));
|
---|
882 | $head_pattrn = '<thead>\s*<tr>\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*(<th[^>]*>[^<]*<\/th>)\s*<\/tr>\s*<\/thead>';
|
---|
883 | if(preg_match('/'. $head_pattrn . '/s' ,$calendar,$head_match)){
|
---|
884 | $sun_index = 1 - $week_begins;
|
---|
885 | if ($sun_index < 1) $sun_index = $sun_index +7;
|
---|
886 | $sat_index = 7 - $week_begins;
|
---|
887 | if ($sat_index < 1) $sat_index = $sat_index +7;
|
---|
888 |
|
---|
889 | $sun_head = $head_match[$sun_index];
|
---|
890 | $sat_head = $head_match[$sat_index];
|
---|
891 |
|
---|
892 | $pattrn = '(<th[^>]*>)(.*)(<\/th>)';
|
---|
893 | if(preg_match('/'. $pattrn . '/' ,$sun_head,$sun_match)){
|
---|
894 | $sun_head_after = $sun_match[1] . '<span style="color: ' . $sun_color . '">' . $sun_match[2] . '</span>'. $sun_match[3];
|
---|
895 | $calendar = str_replace($sun_head,$sun_head_after,$calendar);
|
---|
896 | }
|
---|
897 | if(preg_match('/'. $pattrn . '/' ,$sat_head,$sat_match)){
|
---|
898 | $sat_head_after = $sat_match[1] . '<span style="color: ' . $sat_color . '">' . $sat_match[2] . '</span>'. $sat_match[3];
|
---|
899 | $calendar = str_replace($sat_head,$sat_head_after,$calendar);
|
---|
900 | }
|
---|
901 | }
|
---|
902 | return $calendar;
|
---|
903 | }
|
---|
904 |
|
---|
905 | function xpress_grobal_recent_posts($num = 10,$post_list='')
|
---|
906 | {
|
---|
907 | global $wpdb, $wp_rewrite , $switched , $blog_id;
|
---|
908 | if (empty($date_format)) $date_format = get_settings('date_format');
|
---|
909 | if (empty($time_format)) $time_format = get_settings('time_format');
|
---|
910 |
|
---|
911 | $first_blogid = $blog_id;
|
---|
912 | $num = (int)$num;
|
---|
913 | // $wp_query->in_the_loop = true; //for use the_tags() in multi lopp
|
---|
914 | $data_array = array();
|
---|
915 | if (xpress_is_multiblog()){
|
---|
916 | $blogs = get_blog_list(0,'all');
|
---|
917 | foreach ($blogs AS $blog) {
|
---|
918 | switch_to_blog($blog['blog_id']);
|
---|
919 | $wp_rewrite->init(); // http://core.trac.wordpress.org/ticket/12040 is solved, it is unnecessary.
|
---|
920 |
|
---|
921 | if (empty($num)){
|
---|
922 | query_posts("post_status=publish");
|
---|
923 | } else {
|
---|
924 | query_posts("showposts=$num&post_status=publish");
|
---|
925 | }
|
---|
926 | if (have_posts()){
|
---|
927 | while(have_posts()){
|
---|
928 | $data = new stdClass();
|
---|
929 |
|
---|
930 | the_post();
|
---|
931 | ob_start();
|
---|
932 | the_ID();
|
---|
933 | $data->post_id = ob_get_contents();
|
---|
934 | ob_end_clean();
|
---|
935 |
|
---|
936 | $data->brog_id = $blog['blog_id'];
|
---|
937 | $data->blog_name = get_bloginfo('name');
|
---|
938 | $data->blog_url = get_bloginfo('url');
|
---|
939 | $data->blog_link = '<a href="' . $data->blog_url . '">' . $data->blog_name . '</a>' ;
|
---|
940 |
|
---|
941 |
|
---|
942 | ob_start();
|
---|
943 | the_title();
|
---|
944 | $data->title = ob_get_contents();
|
---|
945 | ob_end_clean();
|
---|
946 | $data->post_permalink = get_blog_permalink($data->brog_id, $data->post_id);
|
---|
947 | $data->title_link = '<a href="' . $data->post_permalink . '">' . $data->title . '</a>' ;
|
---|
948 |
|
---|
949 | ob_start();
|
---|
950 | the_author_posts_link();
|
---|
951 | $data->post_author = ob_get_contents();
|
---|
952 | ob_end_clean();
|
---|
953 |
|
---|
954 | ob_start();
|
---|
955 | the_category(' • ');
|
---|
956 | $data->post_category = ob_get_contents();
|
---|
957 | ob_end_clean();
|
---|
958 |
|
---|
959 | if (function_exists('the_tags')){
|
---|
960 | ob_start();
|
---|
961 | the_tags(__('Tags:', 'xpress') . ' ',' • ','');
|
---|
962 | $data->post_tags = ob_get_contents();
|
---|
963 | ob_end_clean();
|
---|
964 | } else {
|
---|
965 | $data->tags = '';
|
---|
966 | }
|
---|
967 |
|
---|
968 | $data->the_content = xpress_the_content('echo=0');
|
---|
969 |
|
---|
970 | ob_start();
|
---|
971 | the_content();
|
---|
972 | $data->the_full_content = ob_get_contents();
|
---|
973 | ob_end_clean();
|
---|
974 |
|
---|
975 | ob_start();
|
---|
976 | the_modified_date($date_format);
|
---|
977 | $data->post_modified_date = ob_get_contents();
|
---|
978 | ob_end_clean();
|
---|
979 |
|
---|
980 | ob_start();
|
---|
981 | the_modified_date($time_format);
|
---|
982 | $data->post_modified_time = ob_get_contents();
|
---|
983 | ob_end_clean();
|
---|
984 | $data->post_modified_date_time = $data->post_modified_date . ' ' . $data->post_modified_time;
|
---|
985 |
|
---|
986 | ob_start();
|
---|
987 | the_time('U');
|
---|
988 | $data->post_unix_time = ob_get_contents();
|
---|
989 | ob_end_clean();
|
---|
990 |
|
---|
991 | ob_start();
|
---|
992 | the_time($date_format);
|
---|
993 | $data->post_date = ob_get_contents();
|
---|
994 | ob_end_clean();
|
---|
995 |
|
---|
996 | ob_start();
|
---|
997 | the_time($time_format);
|
---|
998 | $data->post_time = ob_get_contents();
|
---|
999 | ob_end_clean();
|
---|
1000 |
|
---|
1001 | $data->post_date_time = $data->post_date . ' ' . $data->post_time;
|
---|
1002 |
|
---|
1003 | ob_start();
|
---|
1004 | comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
|
---|
1005 | $data->comments_link = ob_get_contents();
|
---|
1006 | ob_end_clean();
|
---|
1007 |
|
---|
1008 | $data->post_views = xpress_post_views_count('post_id=' . $data->post_id . '&blogid=' . $data->brog_id . '&format=' . __('Views :%d', 'xpress'). '&echo=0');
|
---|
1009 |
|
---|
1010 | $data_array[] = $data;
|
---|
1011 | } // end whilwe
|
---|
1012 | } // end if
|
---|
1013 | restore_current_blog();
|
---|
1014 | // $wp_rewrite->init();
|
---|
1015 | } // end foreach
|
---|
1016 | // switch_to_blog($first_blogid);
|
---|
1017 | $wp_rewrite->init(); // http://core.trac.wordpress.org/ticket/12040 is solved, it is unnecessary.
|
---|
1018 |
|
---|
1019 | restore_current_blog();
|
---|
1020 | usort($data_array, "the_time_cmp");
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | if (!empty($num)){
|
---|
1024 | $data_array = array_slice($data_array,0,$num);
|
---|
1025 | }
|
---|
1026 | return $data_array;
|
---|
1027 | }
|
---|
1028 | function the_time_cmp($a, $b)
|
---|
1029 | {
|
---|
1030 | return - strcasecmp($a->post_unix_time, $b->post_unix_time);
|
---|
1031 | }
|
---|
1032 |
|
---|
1033 | function xpress_get_blog_option($option_name,$b_id = 1)
|
---|
1034 | {
|
---|
1035 | global $wpdb;
|
---|
1036 | $db_prefix = get_wp_prefix();
|
---|
1037 |
|
---|
1038 | if (empty($b_id)) $b_id =1;
|
---|
1039 | $blog_prefix = '';
|
---|
1040 | if ($b_id >1) $blog_prefix = $b_id . '_';
|
---|
1041 | $options_tb = $db_prefix . $blog_prefix .'options';
|
---|
1042 |
|
---|
1043 | $sql = "SELECT option_value FROM $options_tb WHERE option_name = $option_name";
|
---|
1044 | $ret_val = $wpdb->get_var($sql);
|
---|
1045 | return $ret_val;
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | function xpress_create_new_blog_link($args ='' ) {
|
---|
1049 | global $xoops_config;
|
---|
1050 |
|
---|
1051 | global $current_user;
|
---|
1052 | $defaults = array(
|
---|
1053 | 'echo' => 1
|
---|
1054 | );
|
---|
1055 | $r = wp_parse_args( $args, $defaults );
|
---|
1056 |
|
---|
1057 | extract( $r );
|
---|
1058 | $result = xpress_create_new_blog();
|
---|
1059 | if (!empty($result)){
|
---|
1060 | $output = $result['link'];
|
---|
1061 | } else {
|
---|
1062 | $output = '';
|
---|
1063 | }
|
---|
1064 |
|
---|
1065 | if ($echo)
|
---|
1066 | echo $output;
|
---|
1067 | else
|
---|
1068 | return $output;
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | function xpress_create_new_blog() {
|
---|
1072 | global $xoops_config;
|
---|
1073 | global $current_user;
|
---|
1074 | $ret = array();
|
---|
1075 |
|
---|
1076 | if (xpress_is_multiblog() && is_user_logged_in()){
|
---|
1077 | $primary_blog_id = @$current_user->primary_blog;
|
---|
1078 | if (!empty($primary_blog_id)) return $ret;
|
---|
1079 | $active_signup = get_site_option( 'registration' );
|
---|
1080 | if ( !$active_signup ) $active_signup = 'none';
|
---|
1081 | switch ($active_signup){
|
---|
1082 | case 'all':
|
---|
1083 | case 'blog':
|
---|
1084 | $ret['url'] = $xoops_config->module_url . '/wp-signup.php';
|
---|
1085 | $ret['menu_url'] = 'wp-signup.php';
|
---|
1086 | $ret['title'] = __('Create New Blog','xpressme');
|
---|
1087 | $ret['link'] = '<a href="' . $ret['url'] . '">' . $ret['title'] . '</a>';
|
---|
1088 | break;
|
---|
1089 | case 'user':
|
---|
1090 | case 'none':
|
---|
1091 | default:
|
---|
1092 | }
|
---|
1093 | }
|
---|
1094 | return $ret;
|
---|
1095 | }
|
---|
1096 | function xpress_primary_blog_link() {
|
---|
1097 | global $xoops_config;
|
---|
1098 | global $current_user;
|
---|
1099 | global $blog_id;
|
---|
1100 | $ret = array();
|
---|
1101 |
|
---|
1102 | if (xpress_is_multiblog() && is_user_logged_in()){
|
---|
1103 | $blog_list = get_blog_list();
|
---|
1104 | $root_path = get_blog_status(1,'path');
|
---|
1105 | $primary_blog_id = @$current_user->primary_blog;
|
---|
1106 | if(empty($primary_blog_id)) return $ret;
|
---|
1107 | $primary_path = get_blog_status($primary_blog_id,'path');
|
---|
1108 | $script = str_replace($root_path, "", $primary_path);
|
---|
1109 | if ($primary_blog_id !== $blog_id){
|
---|
1110 | $ret['url'] = get_blogaddress_by_id($primary_blog_id);
|
---|
1111 | $ret['menu_url'] = $script;
|
---|
1112 | $ret['title'] = __('Your Primary Blog','xpressme');
|
---|
1113 | $ret['link'] = '<a href="' . $ret['url'] . '">' . $ret['title'] . '</a>';
|
---|
1114 | }
|
---|
1115 | }
|
---|
1116 | return $ret;
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 | ?> |
---|