- Timestamp:
- Apr 30, 2009, 11:00:43 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-content/plugins/xpressme/include/custom_functions.php
r193 r198 573 573 return false; 574 574 } 575 576 function get_xpress_calendar($sun_color = '#DB0000' ,$sat_color = '#004D99' ,$initial = true) { 577 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; 578 579 580 581 ob_start(); 582 // Quick check. If we have no posts at all, abort! 583 if ( !$posts ) { 584 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); 585 if ( !$gotsome ) 586 return; 587 } 588 589 if ( isset($_GET['w']) ) 590 $w = ''.intval($_GET['w']); 591 592 // week_begins = 0 stands for Sunday 593 $week_begins = intval(get_option('start_of_week')); 594 595 // Let's figure out when we are 596 if ( !empty($monthnum) && !empty($year) ) { 597 $thismonth = ''.zeroise(intval($monthnum), 2); 598 $thisyear = ''.intval($year); 599 } elseif ( !empty($w) ) { 600 // We need to get the month from MySQL 601 $thisyear = ''.intval(substr($m, 0, 4)); 602 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's 603 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')"); 604 } elseif ( !empty($m) ) { 605 $thisyear = ''.intval(substr($m, 0, 4)); 606 if ( strlen($m) < 6 ) 607 $thismonth = '01'; 608 else 609 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2); 610 } else { 611 $thisyear = gmdate('Y', current_time('timestamp')); 612 $thismonth = gmdate('m', current_time('timestamp')); 613 } 614 615 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); 616 617 // Get the next and previous month and year with at least one post 618 $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year 619 FROM $wpdb->posts 620 WHERE post_date < '$thisyear-$thismonth-01' 621 AND post_type = 'post' AND post_status = 'publish' 622 ORDER BY post_date DESC 623 LIMIT 1"); 624 $next = $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 MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) 628 AND post_type = 'post' AND post_status = 'publish' 629 ORDER BY post_date ASC 630 LIMIT 1"); 631 632 echo '<table summary="' . __('Calendar') . '"> 633 <caption>' . sprintf(_c('%1$s %2$s|Used as a calendar caption'), $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption> 634 <thead> 635 <tr>'; 636 637 $myweek = array(); 638 639 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) { 640 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7); 641 } 642 643 foreach ( $myweek as $wd ) { 644 645 for($week_num=0;$week_num<=6;$week_num++){ 646 $week_name = $wp_locale->get_weekday($week_num); 647 if ($week_name === $wd) break; 648 } 649 650 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd); 651 if ($week_num ==0) $day_name = '<span style="color: ' . $sun_color . '">' . $day_name . '</span>'; 652 if ($week_num ==6) $day_name = '<span style="color: ' . $sat_color . '">' . $day_name . '</span>'; 653 echo "\n\t\t<th align=\"center\" abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>"; 654 } 655 656 echo ' 657 </tr> 658 </thead> 659 660 <tfoot> 661 <tr>'; 662 663 if ( $previous ) { 664 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' . 665 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), 666 date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>'; 667 } else { 668 echo "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>'; 669 } 670 671 echo "\n\t\t".'<td class="pad"> </td>'; 672 673 if ( $next ) { 674 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' . 675 get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), 676 date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>'; 677 } else { 678 echo "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>'; 679 } 680 681 echo ' 682 </tr> 683 </tfoot> 684 685 <tbody> 686 <tr>'; 687 688 // Get days with posts 689 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) 690 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth' 691 AND YEAR(post_date) = '$thisyear' 692 AND post_type = 'post' AND post_status = 'publish' 693 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N); 694 if ( $dayswithposts ) { 695 foreach ( (array) $dayswithposts as $daywith ) { 696 $daywithpost[] = $daywith[0]; 697 } 698 } else { 699 $daywithpost = array(); 700 } 701 702 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') !== false) 703 $ak_title_separator = "\n"; 704 else 705 $ak_title_separator = ', '; 706 707 $ak_titles_for_day = array(); 708 $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom " 709 ."FROM $wpdb->posts " 710 ."WHERE YEAR(post_date) = '$thisyear' " 711 ."AND MONTH(post_date) = '$thismonth' " 712 ."AND post_date < '".current_time('mysql')."' " 713 ."AND post_type = 'post' AND post_status = 'publish'" 714 ); 715 if ( $ak_post_titles ) { 716 foreach ( (array) $ak_post_titles as $ak_post_title ) { 717 718 $post_title = apply_filters( "the_title", $ak_post_title->post_title ); 719 $post_title = str_replace('"', '"', wptexturize( $post_title )); 720 721 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) ) 722 $ak_titles_for_day['day_'.$ak_post_title->dom] = ''; 723 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one 724 $ak_titles_for_day["$ak_post_title->dom"] = $post_title; 725 else 726 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title; 727 } 728 } 729 730 731 // See how much we should pad in the beginning 732 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins); 733 if ( 0 != $pad ) 734 echo "\n\t\t".'<td colspan="'.$pad.'" class="pad"> </td>'; 735 736 $daysinmonth = intval(date('t', $unixmonth)); 737 for ( $day = 1; $day <= $daysinmonth; ++$day ) { 738 if ( isset($newrow) && $newrow ) 739 echo "\n\t</tr>\n\t<tr>\n\t\t"; 740 $newrow = false; 741 742 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)) ) 743 echo '<td id="today" align="center">'; 744 else 745 echo '<td align="center">'; 746 747 if ( in_array($day, $daywithpost) ) // any posts today? 748 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>"; 749 else 750 echo $day; 751 echo '</td>'; 752 753 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) 754 $newrow = true; 755 } 756 757 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins); 758 if ( $pad != 0 && $pad != 7 ) 759 echo "\n\t\t".'<td class="pad" colspan="'.$pad.'"> </td>'; 760 761 echo "\n\t</tr>\n\t</tbody>\n\t</table>"; 762 763 $output = ob_get_contents(); 764 ob_end_clean(); 765 // echo $output; 766 // $cache[ $key ] = $output; 767 // wp_cache_set( 'get_calendar', $cache, 'calendar' ); 768 return $output; 769 } 575 770 ?>
Note: See TracChangeset
for help on using the changeset viewer.