XPressME Integration Kit

Trac


Ignore:
Timestamp:
Jul 13, 2009, 4:24:31 PM (15 years ago)
Author:
toemon
Message:

xpress_get_calendarの取得方法変更 fixed #185

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/custom_functions.php

    r317 r338  
    766766 
    767767        extract( $r ); 
    768         if ($xoops_config->is_wp20){ 
    769                 ob_start(); 
    770                         get_calendar(true); 
    771                         $output = ob_get_contents(); 
    772                 ob_end_clean(); 
    773                 $output = preg_replace('/<th abbr=/', '<th align="center"  abbr=', $output); //week name align center 
    774                 $output = preg_replace('/<td>/', '<td align="center">', $output); //days align center 
    775                 $output = preg_replace('/<td id="today">/', '<td id="today" align="center">', $output); //today align center 
    776  
    777                 return $output; 
    778         } 
    779  
     768         
    780769        ob_start(); 
    781         // Quick check. If we have no posts at all, abort! 
    782         if ( !$posts ) { 
    783 //              $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); 
    784                 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); //WP2.8 
    785                 if ( !$gotsome ) 
    786                         return; 
    787         } 
    788  
    789         if ( isset($_GET['w']) ) 
    790                 $w = ''.intval($_GET['w']); 
    791  
    792         // week_begins = 0 stands for Sunday 
     770                get_calendar(true); 
     771                $calendar = ob_get_contents(); 
     772        ob_end_clean(); 
     773        $calendar = preg_replace('/<th abbr=/', '<th align="center"  abbr=', $calendar); //week name align center 
     774        $calendar = preg_replace('/<td>/', '<td align="center">', $calendar); //days align center 
     775        $calendar = preg_replace('/<td id="today">/', '<td id="today" align="center">', $calendar); //today align center 
     776        $calendar = preg_replace('/<span style="color:[^>]*>/', '', $calendar); //wp2011 color delete 
     777        $calendar = preg_replace('/<\/span>/', '', $calendar); //wp2011 color delete 
     778 
    793779        $week_begins = intval(get_option('start_of_week')); 
    794  
    795         // Let's figure out when we are 
    796         if ( !empty($monthnum) && !empty($year) ) { 
    797                 $thismonth = ''.zeroise(intval($monthnum), 2); 
    798                 $thisyear = ''.intval($year); 
    799         } elseif ( !empty($w) ) { 
    800                 // We need to get the month from MySQL 
    801                 $thisyear = ''.intval(substr($m, 0, 4)); 
    802                 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's 
    803                 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')"); 
    804         } elseif ( !empty($m) ) { 
    805                 $thisyear = ''.intval(substr($m, 0, 4)); 
    806                 if ( strlen($m) < 6 ) 
    807                                 $thismonth = '01'; 
    808                 else 
    809                                 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2); 
    810         } else { 
    811                 $thisyear = gmdate('Y', current_time('timestamp')); 
    812                 $thismonth = gmdate('m', current_time('timestamp')); 
    813         } 
    814  
    815         $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); 
    816  
    817         // Get the next and previous month and year with at least one post 
    818         $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year 
    819                 FROM $wpdb->posts 
    820                 WHERE post_date < '$thisyear-$thismonth-01' 
    821                 AND post_type = 'post' AND post_status = 'publish' 
    822                         ORDER BY post_date DESC 
    823                         LIMIT 1"); 
    824         $next = $wpdb->get_row("SELECT  DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year 
    825                 FROM $wpdb->posts 
    826                 WHERE post_date >       '$thisyear-$thismonth-01' 
    827                 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) 
    828                 AND post_type = 'post' AND post_status = 'publish' 
    829                         ORDER   BY post_date ASC 
    830                         LIMIT 1"); 
    831  
    832         echo '<table  summary="' . __('Calendar') . '"> 
    833         <caption>' . sprintf(_c('%1$s %2$s|Used as a calendar caption'), $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption> 
    834         <thead> 
    835         <tr>'; 
    836  
    837         $myweek = array(); 
    838  
    839         for ( $wdcount=0; $wdcount<=6; $wdcount++ ) { 
    840                 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7); 
    841         } 
    842  
    843         foreach ( $myweek as $wd ) { 
    844  
    845                 for($week_num=0;$week_num<=6;$week_num++){ 
    846                         $week_name = $wp_locale->get_weekday($week_num); 
    847                         if ($week_name === $wd) break; 
     780        $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>'; 
     781        if(preg_match('/'. $head_pattrn . '/s' ,$calendar,$head_match)){ 
     782                $sun_index = 1 - $week_begins; 
     783                if ($sun_index < 1) $sun_index = $sun_index +7; 
     784                $sat_index = 7 - $week_begins; 
     785                if ($sat_index < 1) $sat_index = $sat_index +7; 
     786                 
     787                $sun_head = $head_match[$sun_index]; 
     788                $sat_head = $head_match[$sat_index]; 
     789                 
     790                $pattrn = '(<th[^>]*>)(.*)(<\/th>)'; 
     791                if(preg_match('/'. $pattrn . '/' ,$sun_head,$sun_match)){ 
     792                        $sun_head_after = $sun_match[1] . '<span style="color: ' . $sun_color . '">' . $sun_match[2] . '</span>'. $sun_match[3]; 
     793                        $calendar = str_replace($sun_head,$sun_head_after,$calendar); 
    848794                } 
    849                  
    850                 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd); 
    851                 if ($week_num ==0) $day_name = '<span style="color: ' . $sun_color . '">' . $day_name . '</span>'; 
    852                 if ($week_num ==6) $day_name = '<span style="color: ' . $sat_color . '">' . $day_name . '</span>'; 
    853                 echo "\n\t\t<th align=\"center\" abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>"; 
    854         } 
    855  
    856         echo ' 
    857         </tr> 
    858         </thead> 
    859  
    860         <tfoot> 
    861         <tr>'; 
    862  
    863         if ( $previous ) { 
    864                 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' . 
    865                 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), 
    866                         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>'; 
    867         } else { 
    868                 echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>'; 
    869         } 
    870  
    871         echo "\n\t\t".'<td class="pad">&nbsp;</td>'; 
    872  
    873         if ( $next ) { 
    874                 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' . 
    875                 get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), 
    876                         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>'; 
    877         } else { 
    878                 echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>'; 
    879         } 
    880  
    881         echo ' 
    882         </tr> 
    883         </tfoot> 
    884  
    885         <tbody> 
    886         <tr>'; 
    887  
    888         // Get days with posts 
    889         $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) 
    890                 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth' 
    891                 AND YEAR(post_date) = '$thisyear' 
    892                 AND post_type = 'post' AND post_status = 'publish' 
    893                 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N); 
    894         if ( $dayswithposts ) { 
    895                 foreach ( (array) $dayswithposts as $daywith ) { 
    896                         $daywithpost[] = $daywith[0]; 
     795                if(preg_match('/'. $pattrn . '/' ,$sat_head,$sat_match)){ 
     796                        $sat_head_after = $sat_match[1] . '<span style="color: ' . $sat_color . '">' . $sat_match[2] . '</span>'. $sat_match[3]; 
     797                        $calendar = str_replace($sat_head,$sat_head_after,$calendar); 
    897798                } 
    898         } else { 
    899                 $daywithpost = array(); 
    900         } 
    901  
    902         if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') !== false) 
    903                 $ak_title_separator = "\n"; 
    904         else 
    905                 $ak_title_separator = ', '; 
    906  
    907         $ak_titles_for_day = array(); 
    908         $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom " 
    909                 ."FROM $wpdb->posts " 
    910                 ."WHERE YEAR(post_date) = '$thisyear' " 
    911                 ."AND MONTH(post_date) = '$thismonth' " 
    912                 ."AND post_date < '".current_time('mysql')."' " 
    913                 ."AND post_type = 'post' AND post_status = 'publish'" 
    914         ); 
    915         if ( $ak_post_titles ) { 
    916                 foreach ( (array) $ak_post_titles as $ak_post_title ) { 
    917  
    918                                 $post_title = apply_filters( "the_title", $ak_post_title->post_title ); 
    919                                 $post_title = str_replace('"', '&quot;', wptexturize( $post_title )); 
    920  
    921                                 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) ) 
    922                                         $ak_titles_for_day['day_'.$ak_post_title->dom] = ''; 
    923                                 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one 
    924                                         $ak_titles_for_day["$ak_post_title->dom"] = $post_title; 
    925                                 else 
    926                                         $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title; 
    927                 } 
    928         } 
    929  
    930  
    931         // See how much we should pad in the beginning 
    932         $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins); 
    933         if ( 0 != $pad ) 
    934                 echo "\n\t\t".'<td colspan="'.$pad.'" class="pad">&nbsp;</td>'; 
    935  
    936         $daysinmonth = intval(date('t', $unixmonth)); 
    937         for ( $day = 1; $day <= $daysinmonth; ++$day ) { 
    938                 if ( isset($newrow) && $newrow ) 
    939                         echo "\n\t</tr>\n\t<tr>\n\t\t"; 
    940                 $newrow = false; 
    941  
    942                 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)) ) 
    943                         echo '<td id="today" align="center">'; 
    944                 else 
    945                         echo '<td align="center">'; 
    946  
    947                 if ( in_array($day, $daywithpost) ) // any posts today? 
    948                                 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>"; 
    949                 else 
    950                         echo $day; 
    951                 echo '</td>'; 
    952  
    953                 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) 
    954                         $newrow = true; 
    955         } 
    956  
    957         $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins); 
    958         if ( $pad != 0 && $pad != 7 ) 
    959                 echo "\n\t\t".'<td class="pad" colspan="'.$pad.'">&nbsp;</td>'; 
    960  
    961         echo "\n\t</tr>\n\t</tbody>\n\t</table>"; 
    962  
    963         $output = ob_get_contents(); 
    964         ob_end_clean(); 
    965 //      echo $output; 
    966 //      $cache[ $key ] = $output; 
    967 //      wp_cache_set( 'get_calendar', $cache, 'calendar' ); 
    968         return $output; 
     799        } 
     800        return $calendar; 
    969801} 
    970802?> 
Note: See TracChangeset for help on using the changeset viewer.