XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/custom_functions.php @ 428

Last change on this file since 428 was 428, checked in by toemon, 14 years ago

WPMUで閲覧数が正常に機能しないバグ修正 Fixes #241

File size: 23.1 KB
Line 
1<?php
2function xpress_is_contributor()
3{
4        global $current_user;
5        get_currentuserinfo();
6        if ($current_user->user_level > 3)
7                return true;
8        else
9                return false;
10}
11
12function xpress_is_wpmu() {
13        global $xoops_config;
14       
15        return $xoops_config->is_wpmu;
16}
17
18function xpress_is_wp_version($operator='==',$comp_version){
19        global $xoops_config;
20        return version_compare($xoops_config->wp_version, $comp_version, $operator);
21}
22
23function xpress_is_theme_sidebar_disp(){
24        global $xpress_config;
25        if (is_wordpress_style()) return true;
26        return $xpress_config->is_theme_sidebar_disp;
27}       
28
29function xpress_is_author_view_count(){
30        global $xpress_config;
31        return $xpress_config->is_author_view_count;
32}
33
34function xpress_is_multi_user(){
35        global $xpress_config;
36        return $xpress_config->is_multi_user;
37}
38
39
40function xpress_the_title($args = '')
41{
42        $defaults = array(
43                'echo' => 1
44        );
45        $r = wp_parse_args( $args, $defaults );
46
47        extract( $r );
48
49        $output = '<div class ="xpress-post-header">' . "\n";
50       
51        if (function_exists('hotDates')) {
52                ob_start();
53                        hotDates();
54                        $output .= ob_get_contents();
55                ob_end_clean();
56        }
57        $output .= '<div class ="xpress-post-title">' . "\n";
58        $output .= '<h2><a href="';
59        ob_start();
60                the_permalink();
61                $output .= ob_get_contents();
62        ob_end_clean();
63       
64        if(function_exists('the_title_attribute')){
65                $title = the_title_attribute('echo=0');
66        } else {
67                ob_start();
68                        the_title();
69                        $title = ob_get_contents();
70                ob_end_clean();
71        }
72                                               
73        $output .= '" rel="bookmark" title="';
74        $output .= sprintf(__('Permanent Link to %s', 'xpress'), $title);
75        $output .= '">';
76        $output .= $title;
77        $output .= '</a></h2>' . "\n";
78        $output .= '</div>' . "\n";
79        $output .= '</div>' . "\n";
80       
81        if ($echo)
82                echo $output;
83        else
84                return $output;
85
86}
87
88function xpress_selected_author($args ='' ) {
89        $defaults = array(
90                'echo' => 1
91        );
92        $r = wp_parse_args( $args, $defaults );
93
94        extract( $r );
95
96        $output = '';
97        $author_cookie = get_xpress_dir_name() . "_select_author" ;
98        if (!empty($_COOKIE[$author_cookie])){
99                $uid = intval($_COOKIE[$author_cookie]);
100                $user_info = get_userdata($uid);
101                $output = $user_info->display_name;
102        }
103        if ($echo)
104                echo $output;
105        else
106                return $output;
107               
108}
109function xpress_selected_author_id($args ='' ) {
110        $defaults = array(
111                'echo' => 1
112        );
113        $r = wp_parse_args( $args, $defaults );
114
115        extract( $r );
116        $output = '';
117        $author_cookie = get_xpress_dir_name() . "_select_author" ;
118        if (!empty($_COOKIE[$author_cookie])){
119                $output = intval($_COOKIE[$author_cookie]);
120        } else {
121                $output = '';
122        }
123        if ($echo)
124                echo $output;
125        else
126                return $output;         
127}
128
129function xpress_now_user_level($args ='' ) {
130        global $current_user;
131        $defaults = array(
132                'echo' => 1
133        );
134        $r = wp_parse_args( $args, $defaults );
135
136        extract( $r );
137       
138        $output = @$current_user->user_level;
139        if ($echo)
140                echo $output;
141        else
142                return $output;
143}
144       
145function xpress_credit($args ='')
146{
147        global $wp_version , $xoops_config;
148        if ($xoops_config->is_wpmu) {
149                global $wpmu_version;
150        }
151       
152        $defaults = array(
153                'echo' => 1,
154                'no_link' => 0
155        );
156        $r = wp_parse_args( $args, $defaults );
157
158        extract( $r );
159       
160        $xpress_version = $xoops_config->module_version;
161        $xpress_codename = $xoops_config->module_codename;
162        if ($no_link){
163                $output = 'XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename);
164                if ($xoops_config->is_wpmu) {
165                        $output .= '(included WordPress MU ' . $wpmu_version. ')';
166                } else {
167                        if (strstr($wp_version,'ME')){
168                                $output .= '(included WordPress ' . $wp_version . ')';
169                        } else {
170                                $output .= '(included WordPress ' . $wp_version . ')';
171                        }
172                }
173        } else {
174                $output = '<a href="http://ja.xpressme.info"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
175                if ($xoops_config->is_wpmu) {
176                        $output .= '(included <a href="http://mu.wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress MU ' . $wpmu_version . '</a>)';
177                } else {
178                        if (strstr($wp_version,'ME')){
179                                $output .= '(included <a href="http://wpme.sourceforge.jp/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
180                        } else {
181                                $output .= '(included <a href="http://wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
182                        }
183                }
184        }               
185        if ($echo)
186                echo $output;
187        else
188                return $output;
189}
190
191function xpress_convert_time($args ='')
192{
193        $defaults = array(
194                'echo' => 1,
195                'format' => '(%.3f sec.)'               
196        );
197        $r = wp_parse_args( $args, $defaults );
198
199        extract( $r );
200       
201        $output =  sprintf($format,timer_stop(0));
202        if ($echo)
203                echo $output;
204        else
205                return $output;
206}
207
208function xpress_left_arrow_post_link($args ='')
209{
210        global $xpress_config;
211        $defaults = array(
212                'echo' => 1
213        );
214        $r = wp_parse_args( $args, $defaults );
215
216        extract( $r );
217       
218        $ret = '';
219               
220        if($xpress_config->is_left_postnavi_old){
221                $link_title = $xpress_config->old_post_link_text;
222                ob_start();
223                if ($xpress_config->is_postnavi_title_disp)
224                        previous_post_link('&laquo; %link');
225                else
226                        previous_post_link('&laquo; %link',$link_title);
227                $ret = ob_get_contents();
228                ob_end_clean();
229                ob_start();
230                        previous_post_link('%link',$link_title);
231                        $GLOBALS['left_arrow_post_link'] = ob_get_contents();
232                ob_end_clean();
233
234        } else {
235                $link_title = $xpress_config->newer_post_link_text;
236                ob_start();
237                if ($xpress_config->is_postnavi_title_disp)
238                        next_post_link('&laquo; %link');
239                else
240                        next_post_link('&laquo; %link',$link_title);
241                $ret = ob_get_contents();
242                ob_end_clean();
243                ob_start();
244                        next_post_link('%link',$link_title);
245                        $GLOBALS['left_arrow_post_link'] = ob_get_contents();
246                ob_end_clean();
247
248        }
249       
250        if ($xpress_config->is_postnavi_title_disp){
251                $on_mouse_show = $link_title;
252        } else  {
253                if($xpress_config->is_left_postnavi_old){
254                        ob_start();
255                                previous_post_link('%link');
256                                $on_mouse_show = ob_get_contents();
257                        ob_end_clean();
258                } else {
259                        ob_start();
260                                next_post_link('%link');
261                                $on_mouse_show = ob_get_contents();
262                        ob_end_clean();
263                }
264                $pattern = "<a[^>]*?>(.*)<\/a>";
265                preg_match("/".$pattern."/s",  $on_mouse_show, $body_matches);
266                $on_mouse_show = $body_matches[1];
267        }
268        $output = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
269
270        if ($echo)
271                echo $output;
272        else
273                return $output;
274}
275
276function xpress_right_arrow_post_link($args ='')
277{
278        global $xpress_config;
279        $defaults = array(
280                'echo' => 1
281        );
282        $r = wp_parse_args( $args, $defaults );
283
284        extract( $r );
285
286        $ret = '';             
287       
288        if($xpress_config->is_left_postnavi_old){
289                $link_title = $xpress_config->newer_post_link_text;
290                ob_start();
291                if ($xpress_config->is_postnavi_title_disp)
292                        next_post_link('%link &raquo;');
293                else
294                        next_post_link('%link &raquo;',$link_title);
295                $ret = ob_get_contents();
296                ob_end_clean();
297                ob_start();
298                        next_post_link('%link',$link_title);
299                        $GLOBALS['right_arrow_post_link'] = ob_get_contents();
300                ob_end_clean();
301
302        } else {
303                $link_title = $xpress_config->old_post_link_text;
304                ob_start();
305                if ($xpress_config->is_postnavi_title_disp)
306                        previous_post_link('%link &raquo;');
307                else
308                        previous_post_link('%link &raquo;',$link_title);
309                $ret = ob_get_contents();
310                ob_end_clean();
311                ob_start();
312                        previous_post_link('%link',$link_title);
313                        $GLOBALS['right_arrow_post_link'] = ob_get_contents();
314                ob_end_clean();
315
316        }
317       
318        if ($xpress_config->is_postnavi_title_disp){
319                $on_mouse_show = $link_title;
320        } else  {
321                if($xpress_config->is_left_postnavi_old){
322                        ob_start();
323                                next_post_link('%link');
324                                $on_mouse_show = ob_get_contents();
325                        ob_end_clean();
326                } else {
327                        ob_start();
328                                previous_post_link('%link');
329                                $on_mouse_show = ob_get_contents();
330                        ob_end_clean();
331                }
332                $pattern = "<a[^>]*?>(.*)<\/a>";
333                preg_match("/".$pattern."/s",  $on_mouse_show, $body_matches);
334                $on_mouse_show = $body_matches[1];
335        }
336        $output = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
337
338        if ($echo)
339                echo $output;
340        else
341                return $output;
342}
343// page link
344function xpress_left_arrow_posts_link($args ='')
345{
346        global $xpress_config;
347        $defaults = array(
348                'echo' => 1
349        );
350        $r = wp_parse_args( $args, $defaults );
351
352        extract( $r );
353
354        $output = '';
355               
356        if($xpress_config->is_left_page_navi_old){
357                $link_title = $xpress_config->old_page_link_text;
358                ob_start();
359                next_posts_link("&laquo; $link_title");
360                $output = ob_get_contents();
361                ob_end_clean();
362        } else {
363                $link_title = $xpress_config->newer_page_link_text;
364                ob_start();
365                previous_posts_link("&laquo; $link_title");
366                $output = ob_get_contents();
367                ob_end_clean();
368        }
369
370        if ($echo)
371                echo $output;
372        else
373                return $output;
374}
375
376function xpress_right_arrow_posts_link($args ='')
377{
378        global $xpress_config;
379        $defaults = array(
380                'echo' => 1
381        );
382        $r = wp_parse_args( $args, $defaults );
383
384        extract( $r );
385
386        $output = '';           
387       
388        if($xpress_config->is_left_page_navi_old){
389                $link_title = $xpress_config->newer_page_link_text;
390                ob_start();
391                previous_posts_link("$link_title &raquo;");
392                $output = ob_get_contents();
393                ob_end_clean();
394        } else {
395                $link_title = $xpress_config->old_page_link_text;
396                ob_start();
397                next_posts_link("$link_title &raquo;");
398                $output = ob_get_contents();
399                ob_end_clean();
400        }
401
402        if ($echo)
403                echo $output;
404        else
405                return $output;
406}
407
408function xpress_substr($str, $start, $length, $trimmarker = '...')
409{
410    if (function_exists('mb_substr')){
411        $str2 = mb_substr( $str , $start , $length);
412        return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
413    } else {
414        return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
415    }
416}
417
418
419// views count
420// Set and retrieves post views given a post ID or post object.
421// Retrieves post views given a post ID or post object.
422function xpress_post_views_count($args ='') {
423        global $xoops_db,$wpdb;
424        global $blog_id;
425        static $post_cache_views;
426
427        $defaults = array(
428                'post_id' => 0,
429                'format'=> __('views :%d','xpressme'),
430                'echo' => 1
431        );
432        $r = wp_parse_args( $args, $defaults );
433
434        extract( $r );
435
436        if ( empty($post_id) ) {
437                if ( isset($GLOBALS['post']) )
438                        $post_id = $GLOBALS['post']->ID;
439        }
440
441        $post_id = intval($post_id);
442        if($post_id==0) return null;
443        if(!isset($post_cache_views[$post_id])){
444                if (is_null($blog_id)){
445                        $blog_where = '';
446                } else {
447                        $blog_where = ' AND blog_id = '. $blog_id;
448                }
449                $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id " .  $blog_where;
450       $post_views = $xoops_db->get_var($sql);
451        if (!$post_views) {
452                $post_cache_views[$post_id] = 0;
453        }else{
454                $post_cache_views[$post_id] = $post_views;
455        }
456        }
457        $v_count = intval($post_cache_views[$post_id]);
458       
459        if (empty($format)) $format = __('views :%d','xpressme');
460       
461        $output = sprintf($format,$v_count);
462
463        if ($echo)
464                echo $output;
465        else
466                return $output;
467}
468
469function set_post_views_count(&$content) {
470        if ( empty($_GET["feed"]) &&  empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
471                post_views_counting();
472        }
473        return $content;
474}
475
476// Set post views given a post ID or post object.
477function post_views_counting($post_id = 0) {
478        global $xoops_db,$wpdb;
479        global $table_prefix;
480        global $blog_id;
481        static $views;
482       
483        $post_id = intval($post_id);
484        if ( empty($post_id) && isset($GLOBALS['post']) ){
485                $post_id = $GLOBALS['post']->ID;
486        }
487
488        $views_db = get_wp_prefix() . 'views';
489        if (is_null($blog_id)) $blog_id = 0;
490
491        if($post_id==0 || !empty($views[$post_id])) return null;
492       
493        if(!xpress_is_author_view_count()){
494                $current_user_id = $GLOBALS['current_user']->ID;
495                $post_author_id = $GLOBALS['post']->post_author;
496                if ($current_user_id ==$post_author_id) return null;
497        }
498        if (is_null($blog_id)){
499                $blog_where = '';
500        } else {
501                $blog_where = ' AND blog_id = ' . $blog_id;
502        }
503        $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id" . $blog_where;
504        $post_views_found = $xoops_db->get_var($sql);
505        if($post_views_found){
506        $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id" . $blog_where;
507    }else{
508        if (is_null($blog_id)){
509                        $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
510                } else {
511                        $sql = "INSERT INTO " . $views_db . " (blog_id, post_id, post_views) VALUES ($blog_id, $post_id, 1)";
512                }
513    }
514    $xoops_db->query($sql);
515        return true;
516}
517
518function get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$more_link_text = '') {
519        global $post,$xpress_config;
520       
521        $blog_encoding = get_option('blog_charset');
522        $text = get_the_content('');
523        if (function_exists('strip_shortcodes')){ //@since WP2.5
524                $text = strip_shortcodes( $text );
525        }
526        $text = apply_filters('the_content', $text);
527        $text = str_replace(']]>', ']]&gt;', $text);
528        $text = strip_tags($text);
529        $is_almost_ascii = ($xpress_config->ascii_judged_rate < round(@(mb_strlen($text, $blog_encoding) / strlen($text)) * 100)) ? true : false;
530        if($is_almost_ascii) {
531                $words = explode(' ', $text, $excerpt_length_word + 1);
532
533                if(count($words) > $excerpt_length_word) {
534                        array_pop($words);
535                        array_push($words, ' ... ');
536                        $text = implode(' ', $words);
537                        if (!empty($more_link_text)) $text .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
538
539                }
540        }
541        elseif(mb_strlen($text, $blog_encoding) > $excerpt_length_character) {
542                $text = mb_substr($text, 0, $xpress_config->excerpt_length_character, $blog_encoding) . ' ... ';
543                if (!empty($more_link_text)) $text .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
544        }
545
546        return $text;
547}
548
549function xpress_the_content($args ='')
550{
551        global $post,$xpress_config;
552       
553        $defaults = array(
554                'more_link_text'=> $xpress_config->more_link_text,
555                'stripteaser' => 0,
556                'more_file' => '',
557                'configration_select' => 1,
558                'do_excerpt' => 0,
559                'excerpt_length_word' => $xpress_config->excerpt_length_word ,
560                'excerpt_length_character' => $xpress_config->excerpt_length_character ,
561                'excerpt_more_link_text' => $xpress_config->excerpt_more_link_text ,
562                'echo' => 1
563        );
564        $r = wp_parse_args( $args, $defaults );
565
566        extract( $r );
567       
568        if ($configration_select){
569                if ($xpress_config->is_content_excerpt)
570                        $do_excerpt = 1;
571                else
572                        $do_excerpt = 0;
573        }
574       
575        if ($do_excerpt){
576                $content = get_xpress_excerpt_contents($excerpt_length_word,$excerpt_length_character,$excerpt_more_link_text);
577        } else {
578                $content = get_the_content($more_link_text,$stripteaser,$more_file);
579                $content = apply_filters('the_content', $content);
580                $content = str_replace(']]>', ']]&gt;', $content);
581        }       
582        if ($echo)
583                echo $content;
584        else
585                return $content;
586}
587
588function xpress_post_new_link($args ='')
589{
590        global $xoops_config;
591       
592        $defaults = array(
593                'link_title'=> 'Post New',
594                'echo' => 1
595        );
596        $r = wp_parse_args( $args, $defaults );
597
598        extract( $r );
599
600       
601        if (xpress_is_wp_version('>=','2.1')){
602                $output = '<a href="'. get_bloginfo('url') . '/wp-admin/post-new.php' . '">' . $link_title . '</a>';
603        } else {
604                $output = '<a href="'. get_bloginfo('url') . '/wp-admin/post.php' . '">' . $link_title . '</a>';
605        }       
606        if ($echo)
607                echo $output;
608        else
609                return $output;
610}
611
612function xpress_conditional_title($args ='')
613{
614        $defaults = array(
615                'echo' => 1
616        );
617        $r = wp_parse_args( $args, $defaults );
618
619        extract( $r );
620       
621        $selected_author = xpress_selected_author('echo=0');
622       
623        $output = __('Main', 'xpressme');
624        $output = '';
625        if (is_category())
626                $output = sprintf(__('Archive for the &#8216;%s&#8217; Category', 'xpressme'), single_cat_title('', false));
627        if (function_exists( 'is_tag' )){
628                if (is_tag())
629                        $output = sprintf(__('Posts Tagged &#8216;%s&#8217;', 'xpressme'), single_tag_title('', false) );
630        }
631        if (is_day())
632                $output = sprintf(__('Archive for %s|Daily archive page', 'xpressme'), get_the_time(__('F jS, Y', 'xpressme')));
633        if (is_month())
634                $output = sprintf(__('Archive for %s|Monthly archive page', 'xpressme'), get_the_time(__('F, Y', 'xpressme')));
635        if (is_year())
636                $output = sprintf(__('Archive for %s|Yearly archive page', 'xpressme'), get_the_time(__('Y', 'xpressme')));
637        if (is_author()){
638                if (empty($selected_author))
639                        $output = sprintf(__('Archive for the &#8216;%s&#8217; Author', 'xpressme'), get_author_name( get_query_var('author')));
640        }
641        if (is_search())
642                $output = sprintf(__('Search Results of word &#8216;%s&#8217;', 'xpressme'), get_search_query());
643       
644        if (!empty($selected_author)){
645                $selected_id = xpress_selected_author_id('echo=0');
646//              $output = get_avatar($selected_id,$size = '32') . sprintf(__('Article of %s', 'xpressme'), $selected_author) . ' - ' . $output;
647                if (empty($output))
648                        $output = sprintf(__('Article of %s', 'xpressme'), $selected_author) ;
649                else
650                        $output = sprintf(__('Article of %s', 'xpressme'), $selected_author) . ' - ' . $output;
651        }       
652        if ($echo)
653                echo $output;
654        else
655                return $output;
656}
657
658// The content of the trackback/pingback to the post is returned by the list.
659function xpress_pings_list($args =''){
660        $defaults = array(
661                'echo' => 1
662        );
663        $r = wp_parse_args( $args, $defaults );
664
665        extract( $r );
666       
667        $trackbacks = xpress_get_pings();
668        if (! empty($trackbacks)) {
669                $output = '<ol id="xpress_pingslist"> ';
670
671                foreach ($trackbacks as $trackback){
672                        $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" ;
673
674                        $output .=  '<li>';
675                        $output .=  $list ;
676                        $output .=  '</li>';
677
678                }
679                $output .= '</ol>' ;
680        } else {
681                $output = '';
682        }
683       
684        if ($echo)
685                echo $output;
686        else
687                return $output;
688}
689
690// The amount of the trackback/pingback to the post is returned.
691function xpress_pings_number( $args ='' ) {
692        $defaults = array(
693                'zero' => __('No Trackback/Pingback', 'xpressme'),
694                'one' => __('One Trackback/Pingback', 'xpressme'),
695                'more' => __('% TrackBack/Pingback', 'xpressme'),
696                'deprecated' => '',
697                'echo' => 1
698        );
699        $r = wp_parse_args( $args, $defaults );
700
701        extract( $r );
702
703        $pings = xpress_get_pings();
704        if (empty($pings)){
705                $number = 0;
706        }else {
707                $number = count($pings);
708        }
709        if ( $number > 1 )
710                $output = str_replace('%', number_format_i18n($number), $more);
711        elseif ( $number == 0 )
712                $output = $zero;
713        else // must be one
714                $output = $one;
715
716        if ($echo)
717                echo $output;
718        else
719                return $output;
720}
721
722// xpress_get_pings() is a subfunction used with xpress_pings_number() and xpress_pings_list().
723function xpress_get_pings()
724{
725        global $withcomments, $post, $wpdb, $id, $trackback, $user_login, $user_ID, $user_identity;
726
727        if ( ! (is_single() || is_page() || $withcomments) )
728                return;
729
730        /** @todo Use API instead of SELECTs. */
731        if ( $user_ID) {
732                $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));
733        } else if ( empty($trackback_author) ) {
734                $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));
735        } else {
736                $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));
737        }
738
739        if ($trackbacks){
740                $ret = array();
741                foreach ($trackbacks as $trackback){
742
743                        $pattern = '<strong>(.*)<\/strong>(.*)';
744                        if ( preg_match ( "/".$pattern."/i", $trackback->comment_content , $match ) ){
745                                $title = $match[1];
746                                $content = $match[2];
747                        }
748                        if (empty($title)) $title = $trackback->comment_author;
749
750
751                        $row_data = array(
752                                'ID'            => $trackback->comment_ID ,
753                                'post_ID'       => $trackback->comment_post_ID ,
754                                'site_name' => $trackback->comment_author ,
755                                'site_url' => $trackback->comment_author_url ,
756                                'title' => $title ,
757                                'content' => $content ,
758                                'date'          => $trackback->comment_timestamp ,
759                                'date_gmt'              => $trackback->comment_timestamp_gmt ,
760                                'agent'         => $trackback->comment_agent ,
761                                'type'          => $trackback->comment_type ,
762                                'IP'            => $trackback->comment_author_IP ,
763                        );
764                        array_push($ret,$row_data);
765                }
766                return $ret;
767        }
768                        return false;
769}
770
771function xpress_get_calendar($args = '') {
772        global $wpdb, $m, $monthnum, $year, $wp_locale, $posts , $xoops_config;
773
774        $defaults = array(
775                sun_color => '#DB0000',
776                sat_color => '#004D99',
777                initial => true
778        );
779        $r = wp_parse_args( $args, $defaults );
780
781        extract( $r );
782       
783        ob_start();
784                get_calendar(true);
785                $calendar = ob_get_contents();
786        ob_end_clean();
787        $calendar = preg_replace('/<th abbr=/', '<th align="center"  abbr=', $calendar); //week name align center
788        $calendar = preg_replace('/<td>/', '<td align="center">', $calendar); //days align center
789        $calendar = preg_replace('/<td id="today">/', '<td id="today" align="center">', $calendar); //today align center
790        $calendar = preg_replace('/<span style="color:[^>]*>/', '', $calendar); //wp2011 color delete
791        $calendar = preg_replace('/<\/span>/', '', $calendar); //wp2011 color delete
792
793        $week_begins = intval(get_option('start_of_week'));
794        $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>';
795        if(preg_match('/'. $head_pattrn . '/s' ,$calendar,$head_match)){
796                $sun_index = 1 - $week_begins;
797                if ($sun_index < 1) $sun_index = $sun_index +7;
798                $sat_index = 7 - $week_begins;
799                if ($sat_index < 1) $sat_index = $sat_index +7;
800               
801                $sun_head = $head_match[$sun_index];
802                $sat_head = $head_match[$sat_index];
803               
804                $pattrn = '(<th[^>]*>)(.*)(<\/th>)';
805                if(preg_match('/'. $pattrn . '/' ,$sun_head,$sun_match)){
806                        $sun_head_after = $sun_match[1] . '<span style="color: ' . $sun_color . '">' . $sun_match[2] . '</span>'. $sun_match[3];
807                        $calendar = str_replace($sun_head,$sun_head_after,$calendar);
808                }
809                if(preg_match('/'. $pattrn . '/' ,$sat_head,$sat_match)){
810                        $sat_head_after = $sat_match[1] . '<span style="color: ' . $sat_color . '">' . $sat_match[2] . '</span>'. $sat_match[3];
811                        $calendar = str_replace($sat_head,$sat_head_after,$calendar);
812                }
813        }
814        return $calendar;
815}
816?>
Note: See TracBrowser for help on using the repository browser.