XPressME Integration Kit

Trac

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

Last change on this file since 214 was 214, checked in by toemon, 15 years ago

Bump r214 WordPressMU時のクレジットをWordPress MU になるように修正

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