XPressME Integration Kit

Trac

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

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

WordPressMU対応コードの削除 Fixes #294

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