XPressME Integration Kit

Trac

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

Last change on this file since 762 was 757, checked in by toemon, 13 years ago

ConfigFromXoopsクラスを廃止し、modInfoクラスを使用するように変更
WP2.2以下で使用するテンプレートold_templateの廃止

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