XPressME Integration Kit

Trac

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

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

カレンダブロックの曜日色が正常に表示されないバグ修正 Fixes #245

File size: 23.2 KB
RevLine 
[32]1<?php
[273]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
[360]18function xpress_is_wp_version($operator='==',$comp_version){
[273]19        global $xoops_config;
[360]20        return version_compare($xoops_config->wp_version, $comp_version, $operator);
[273]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
[272]40function xpress_the_title($args = '')
[165]41{
[272]42        $defaults = array(
43                'echo' => 1
44        );
45        $r = wp_parse_args( $args, $defaults );
46
47        extract( $r );
48
[165]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();
[262]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        }
[165]72                                               
73        $output .= '" rel="bookmark" title="';
[262]74        $output .= sprintf(__('Permanent Link to %s', 'xpress'), $title);
[165]75        $output .= '">';
[262]76        $output .= $title;
[165]77        $output .= '</a></h2>' . "\n";
78        $output .= '</div>' . "\n";
79        $output .= '</div>' . "\n";
80       
[272]81        if ($echo)
82                echo $output;
83        else
[165]84                return $output;
85
86}
87
[272]88function xpress_selected_author($args ='' ) {
89        $defaults = array(
90                'echo' => 1
91        );
92        $r = wp_parse_args( $args, $defaults );
93
94        extract( $r );
95
[155]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        }
[272]103        if ($echo)
104                echo $output;
105        else
[155]106                return $output;
107               
108}
[272]109function xpress_selected_author_id($args ='' ) {
110        $defaults = array(
111                'echo' => 1
112        );
113        $r = wp_parse_args( $args, $defaults );
114
115        extract( $r );
[157]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        }
[272]123        if ($echo)
124                echo $output;
[157]125        else
[272]126                return $output;         
[157]127}
[164]128
[272]129function xpress_now_user_level($args ='' ) {
[164]130        global $current_user;
[272]131        $defaults = array(
132                'echo' => 1
133        );
134        $r = wp_parse_args( $args, $defaults );
135
136        extract( $r );
137       
[164]138        $output = @$current_user->user_level;
[272]139        if ($echo)
140                echo $output;
141        else
[164]142                return $output;
143}
[147]144       
[272]145function xpress_credit($args ='')
[32]146{
[113]147        global $wp_version , $xoops_config;
[214]148        if ($xoops_config->is_wpmu) {
149                global $wpmu_version;
150        }
[32]151       
[272]152        $defaults = array(
[317]153                'echo' => 1,
154                'no_link' => 0
[272]155        );
156        $r = wp_parse_args( $args, $defaults );
157
158        extract( $r );
159       
[113]160        $xpress_version = $xoops_config->module_version;
161        $xpress_codename = $xoops_config->module_codename;
[317]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                }
[32]173        } else {
[317]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>)';
[214]177                } else {
[317]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                        }
[214]183                }
[317]184        }               
[272]185        if ($echo)
186                echo $output;
[32]187        else
[272]188                return $output;
[32]189}
190
[272]191function xpress_convert_time($args ='')
[32]192{
[272]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;
[32]204        else
[272]205                return $output;
[32]206}
207
[272]208function xpress_left_arrow_post_link($args ='')
[32]209{
[144]210        global $xpress_config;
[272]211        $defaults = array(
212                'echo' => 1
213        );
214        $r = wp_parse_args( $args, $defaults );
215
216        extract( $r );
217       
[33]218        $ret = '';
219               
[144]220        if($xpress_config->is_left_postnavi_old){
221                $link_title = $xpress_config->old_post_link_text;
[32]222                ob_start();
[144]223                if ($xpress_config->is_postnavi_title_disp)
[32]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();
[164]229                ob_start();
230                        previous_post_link('%link',$link_title);
231                        $GLOBALS['left_arrow_post_link'] = ob_get_contents();
232                ob_end_clean();
233
[32]234        } else {
[144]235                $link_title = $xpress_config->newer_post_link_text;
[32]236                ob_start();
[144]237                if ($xpress_config->is_postnavi_title_disp)
[32]238                        next_post_link('&laquo; %link');
239                else
[223]240                        next_post_link('&laquo; %link',$link_title);
[32]241                $ret = ob_get_contents();
242                ob_end_clean();
[164]243                ob_start();
244                        next_post_link('%link',$link_title);
245                        $GLOBALS['left_arrow_post_link'] = ob_get_contents();
246                ob_end_clean();
247
[32]248        }
[33]249       
[144]250        if ($xpress_config->is_postnavi_title_disp){
[33]251                $on_mouse_show = $link_title;
252        } else  {
[144]253                if($xpress_config->is_left_postnavi_old){
[33]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        }
[272]268        $output = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
[32]269
[272]270        if ($echo)
271                echo $output;
[32]272        else
[272]273                return $output;
[32]274}
275
[272]276function xpress_right_arrow_post_link($args ='')
[32]277{
[144]278        global $xpress_config;
[272]279        $defaults = array(
280                'echo' => 1
281        );
282        $r = wp_parse_args( $args, $defaults );
283
284        extract( $r );
285
[32]286        $ret = '';             
287       
[144]288        if($xpress_config->is_left_postnavi_old){
289                $link_title = $xpress_config->newer_post_link_text;
[32]290                ob_start();
[144]291                if ($xpress_config->is_postnavi_title_disp)
[32]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();
[164]297                ob_start();
298                        next_post_link('%link',$link_title);
299                        $GLOBALS['right_arrow_post_link'] = ob_get_contents();
300                ob_end_clean();
301
[32]302        } else {
[144]303                $link_title = $xpress_config->old_post_link_text;
[32]304                ob_start();
[144]305                if ($xpress_config->is_postnavi_title_disp)
[32]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();
[164]311                ob_start();
312                        previous_post_link('%link',$link_title);
313                        $GLOBALS['right_arrow_post_link'] = ob_get_contents();
314                ob_end_clean();
315
[32]316        }
[33]317       
[144]318        if ($xpress_config->is_postnavi_title_disp){
[33]319                $on_mouse_show = $link_title;
320        } else  {
[144]321                if($xpress_config->is_left_postnavi_old){
[33]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        }
[272]336        $output = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
[32]337
[272]338        if ($echo)
339                echo $output;
[32]340        else
[272]341                return $output;
[32]342}
[143]343// page link
[272]344function xpress_left_arrow_posts_link($args ='')
[143]345{
[144]346        global $xpress_config;
[272]347        $defaults = array(
348                'echo' => 1
349        );
350        $r = wp_parse_args( $args, $defaults );
351
352        extract( $r );
353
354        $output = '';
[143]355               
[144]356        if($xpress_config->is_left_page_navi_old){
357                $link_title = $xpress_config->old_page_link_text;
[143]358                ob_start();
359                next_posts_link("&laquo; $link_title");
[272]360                $output = ob_get_contents();
[143]361                ob_end_clean();
362        } else {
[144]363                $link_title = $xpress_config->newer_page_link_text;
[143]364                ob_start();
365                previous_posts_link("&laquo; $link_title");
[272]366                $output = ob_get_contents();
[143]367                ob_end_clean();
368        }
[51]369
[272]370        if ($echo)
371                echo $output;
[143]372        else
[272]373                return $output;
[143]374}
375
[272]376function xpress_right_arrow_posts_link($args ='')
[143]377{
[144]378        global $xpress_config;
[272]379        $defaults = array(
380                'echo' => 1
381        );
382        $r = wp_parse_args( $args, $defaults );
383
384        extract( $r );
385
386        $output = '';           
[143]387       
[144]388        if($xpress_config->is_left_page_navi_old){
389                $link_title = $xpress_config->newer_page_link_text;
[143]390                ob_start();
391                previous_posts_link("$link_title &raquo;");
[272]392                $output = ob_get_contents();
[143]393                ob_end_clean();
394        } else {
[144]395                $link_title = $xpress_config->old_page_link_text;
[143]396                ob_start();
397                next_posts_link("$link_title &raquo;");
[272]398                $output = ob_get_contents();
[143]399                ob_end_clean();
400        }
401
[272]402        if ($echo)
403                echo $output;
[143]404        else
[272]405                return $output;
[143]406}
407
[46]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
[51]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.
[272]422function xpress_post_views_count($args ='') {
[56]423        global $xoops_db,$wpdb;
[428]424        global $blog_id;
[51]425        static $post_cache_views;
426
[272]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
[51]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])){
[428]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);
[54]451        if (!$post_views) {
[51]452                $post_cache_views[$post_id] = 0;
453        }else{
[54]454                $post_cache_views[$post_id] = $post_views;
[51]455        }
456        }
457        $v_count = intval($post_cache_views[$post_id]);
458       
459        if (empty($format)) $format = __('views :%d','xpressme');
460       
[272]461        $output = sprintf($format,$v_count);
[51]462
[272]463        if ($echo)
464                echo $output;
465        else
466                return $output;
[51]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) {
[96]478        global $xoops_db,$wpdb;
[51]479        global $table_prefix;
[428]480        global $blog_id;
[51]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
[96]488        $views_db = get_wp_prefix() . 'views';
[428]489        if (is_null($blog_id)) $blog_id = 0;
[51]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        }
[428]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;
[96]504        $post_views_found = $xoops_db->get_var($sql);
505        if($post_views_found){
[428]506        $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id" . $blog_where;
[51]507    }else{
[428]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                }
[51]513    }
[96]514    $xoops_db->query($sql);
[51]515        return true;
516}
517
[145]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('');
[252]523        if (function_exists('strip_shortcodes')){ //@since WP2.5
524                $text = strip_shortcodes( $text );
525        }
[145]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);
[51]532
[145]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>';
[57]538
539                }
540        }
[145]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
[274]549function xpress_the_content($args ='')
[145]550{
551        global $post,$xpress_config;
552       
[274]553        $defaults = array(
[350]554                'more_link_text'=> $xpress_config->more_link_text,
[274]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 ,
[350]561                'excerpt_more_link_text' => $xpress_config->excerpt_more_link_text ,
[274]562                'echo' => 1
563        );
564        $r = wp_parse_args( $args, $defaults );
565
566        extract( $r );
[145]567       
[274]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);
[145]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        }       
[274]582        if ($echo)
583                echo $content;
584        else
585                return $content;
[57]586}
587
[272]588function xpress_post_new_link($args ='')
[140]589{
[252]590        global $xoops_config;
591       
[272]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       
[363]601        if (xpress_is_wp_version('>=','2.1')){
[400]602                $output = '<a href="'. get_bloginfo('url') . '/wp-admin/post-new.php' . '">' . $link_title . '</a>';
[252]603        } else {
[400]604                $output = '<a href="'. get_bloginfo('url') . '/wp-admin/post.php' . '">' . $link_title . '</a>';
[252]605        }       
[272]606        if ($echo)
[140]607                echo $output;
608        else
609                return $output;
610}
611
[272]612function xpress_conditional_title($args ='')
[140]613{
[272]614        $defaults = array(
615                'echo' => 1
616        );
617        $r = wp_parse_args( $args, $defaults );
618
619        extract( $r );
[155]620       
[272]621        $selected_author = xpress_selected_author('echo=0');
622       
[141]623        $output = __('Main', 'xpressme');
[163]624        $output = '';
[140]625        if (is_category())
[141]626                $output = sprintf(__('Archive for the &#8216;%s&#8217; Category', 'xpressme'), single_cat_title('', false));
[252]627        if (function_exists( 'is_tag' )){
628                if (is_tag())
629                        $output = sprintf(__('Posts Tagged &#8216;%s&#8217;', 'xpressme'), single_tag_title('', false) );
630        }
[140]631        if (is_day())
[141]632                $output = sprintf(__('Archive for %s|Daily archive page', 'xpressme'), get_the_time(__('F jS, Y', 'xpressme')));
[140]633        if (is_month())
[141]634                $output = sprintf(__('Archive for %s|Monthly archive page', 'xpressme'), get_the_time(__('F, Y', 'xpressme')));
[140]635        if (is_year())
[141]636                $output = sprintf(__('Archive for %s|Yearly archive page', 'xpressme'), get_the_time(__('Y', 'xpressme')));
[155]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        }
[140]641        if (is_search())
[143]642                $output = sprintf(__('Search Results of word &#8216;%s&#8217;', 'xpressme'), get_search_query());
[155]643       
[163]644        if (!empty($selected_author)){
[272]645                $selected_id = xpress_selected_author_id('echo=0');
[163]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        }       
[272]652        if ($echo)
[140]653                echo $output;
654        else
655                return $output;
656}
657
[273]658// The content of the trackback/pingback to the post is returned by the list.
[272]659function xpress_pings_list($args =''){
660        $defaults = array(
661                'echo' => 1
662        );
663        $r = wp_parse_args( $args, $defaults );
664
665        extract( $r );
[150]666       
667        $trackbacks = xpress_get_pings();
[154]668        if (! empty($trackbacks)) {
669                $output = '<ol id="xpress_pingslist"> ';
[150]670
[154]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" ;
[150]673
[154]674                        $output .=  '<li>';
675                        $output .=  $list ;
676                        $output .=  '</li>';
[150]677
[154]678                }
679                $output .= '</ol>' ;
680        } else {
681                $output = '';
[150]682        }
[154]683       
[272]684        if ($echo)
685                echo $output;
686        else
687                return $output;
[150]688}
689
[273]690// The amount of the trackback/pingback to the post is returned.
[272]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
[150]703        $pings = xpress_get_pings();
704        if (empty($pings)){
705                $number = 0;
706        }else {
707                $number = count($pings);
708        }
709        if ( $number > 1 )
[272]710                $output = str_replace('%', number_format_i18n($number), $more);
[150]711        elseif ( $number == 0 )
[272]712                $output = $zero;
[150]713        else // must be one
[272]714                $output = $one;
[150]715
[272]716        if ($echo)
717                echo $output;
718        else
719                return $output;
[150]720}
721
[273]722// xpress_get_pings() is a subfunction used with xpress_pings_number() and xpress_pings_list().
[150]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) {
[225]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));
[150]733        } else if ( empty($trackback_author) ) {
[225]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));
[150]735        } else {
[225]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));
[150]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 ,
[225]758                                'date'          => $trackback->comment_timestamp ,
759                                'date_gmt'              => $trackback->comment_timestamp_gmt ,
[150]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}
[198]770
[272]771function xpress_get_calendar($args = '') {
[252]772        global $wpdb, $m, $monthnum, $year, $wp_locale, $posts , $xoops_config;
[198]773
[272]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 );
[338]782       
[198]783        ob_start();
[338]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
[198]792
793        $week_begins = intval(get_option('start_of_week'));
[444]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>';
[338]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;
[198]800               
[338]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);
[198]808                }
[338]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);
[198]812                }
813        }
[338]814        return $calendar;
[198]815}
[252]816?>
Note: See TracBrowser for help on using the repository browser.