| @@ -1,96 +1,79 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | -if ( ! class_exists( 'WP_Widget_Calendar' ) ) { | |
| 7 | - require_once ABSPATH . '/wp-includes/default-widgets.php'; | |
| 3 | +if(!class_exists('WP_Widget_Calendar')){ | |
| 4 | + require_once( ABSPATH . '/wp-includes/default-widgets.php' ); | |
| 8 | 5 | } |
| 9 | 6 | |
| 10 | -/** | |
| 11 | - * This classes rewrite the whole Calendar widget functionality as there is no filter on sql queries and only a filter on final output. | |
| 12 | - * Code last checked: WP 5.5. | |
| 7 | +/* | |
| 8 | + * obliged to rewrite the whole functionnality as there is no filter on sql queries and only a filter on final output | |
| 9 | + * code base last checked with WP 3.9.1 | |
| 10 | + * a request for making a filter on sql queries exists: http://core.trac.wordpress.org/ticket/15202 | |
| 11 | + * method used in 0.4.x: use of the get_calendar filter and overwrite the output of get_calendar function -> not very efficient (add 4 to 5 sql queries) | |
| 12 | + * method used since 0.5: remove the WP widget and replace it by our own -> our language filter will not work if get_calendar is called directly by a theme | |
| 13 | 13 | * |
| 14 | - * A request to add filters on sql queries exists: http://core.trac.wordpress.org/ticket/15202. | |
| 15 | - * Method used in 0.4.x: use of the get_calendar filter and overwrite the output of get_calendar function -> not very efficient (add 4 to 5 sql queries). | |
| 16 | - * Method used since 0.5: remove the WP widget and replace it by our own -> our language filter will not work if get_calendar is called directly by a theme. | |
| 17 | - * | |
| 18 | 14 | * @since 0.5 |
| 19 | 15 | */ |
| 20 | 16 | class PLL_Widget_Calendar extends WP_Widget_Calendar { |
| 21 | - protected static $pll_instance = 0; // Can't use $instance of WP_Widget_Calendar as it's private :/. | |
| 22 | 17 | |
| 23 | - /** | |
| 24 | - * Outputs the content for the current Calendar widget instance. | |
| 25 | - * Modified version of the parent function to call our own get_calendar() method. | |
| 18 | + /* | |
| 19 | + * displays the widget | |
| 20 | + * modified version of the parent function to call our own get_calendar function | |
| 26 | 21 | * |
| 27 | 22 | * @since 0.5 |
| 28 | 23 | * |
| 29 | - * @param array $args Display arguments including 'before_title', 'after_title', | |
| 30 | - * 'before_widget', and 'after_widget'. | |
| 31 | - * @param array $instance The settings for the particular instance of the widget. | |
| 24 | + * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. | |
| 25 | + * @param array $instance The settings for the particular instance of the widget | |
| 32 | 26 | */ |
| 33 | - public function widget( $args, $instance ) { | |
| 34 | - $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; | |
| 35 | - | |
| 36 | - /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ | |
| 37 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); | |
| 38 | - | |
| 39 | - echo $args['before_widget']; | |
| 40 | - if ( $title ) { | |
| 41 | - echo $args['before_title'] . $title . $args['after_title']; | |
| 42 | - } | |
| 43 | - if ( 0 === self::$pll_instance ) { #modified# | |
| 44 | - echo '<div id="calendar_wrap" class="calendar_wrap">'; | |
| 45 | - } else { | |
| 46 | - echo '<div class="calendar_wrap">'; | |
| 47 | - } | |
| 48 | - empty( PLL()->curlang ) ? get_calendar() : self::get_calendar(); #modified# | |
| 27 | + function widget( $args, $instance ) { | |
| 28 | + extract($args); | |
| 29 | + $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title'], $instance, $this->id_base); | |
| 30 | + echo $before_widget; | |
| 31 | + if ( $title ) | |
| 32 | + echo $before_title . $title . $after_title; | |
| 33 | + echo '<div id="calendar_wrap">'; | |
| 34 | + empty($GLOBALS['polylang']->curlang) ? get_calendar() : self::get_calendar(); #modified# | |
| 49 | 35 | echo '</div>'; |
| 50 | - echo $args['after_widget']; | |
| 51 | - | |
| 52 | - self::$pll_instance++; #modified# | |
| 36 | + echo $after_widget; | |
| 53 | 37 | } |
| 54 | 38 | |
| 55 | - /** | |
| 56 | - * Modified version of the WP get_calendar() function to filter the queries. | |
| 39 | + /* | |
| 40 | + * modified version of WP get_calendar function to filter the query | |
| 57 | 41 | * |
| 58 | 42 | * @since 0.5 |
| 59 | 43 | * |
| 60 | 44 | * @param bool $initial Optional, default is true. Use initial calendar names. |
| 61 | - * @param bool $echo Optional, default is true. Set to false for return. | |
| 62 | - * @return void|string Void if `$echo` argument is true, calendar HTML if `$echo` is false. | |
| 45 | + * @param bool $echo Optional, default is true. Set to false for return. | |
| 46 | + * @return string|null String when retrieving, null when displaying. | |
| 63 | 47 | */ |
| 64 | - static public function get_calendar( $initial = true, $echo = true ) { | |
| 65 | - global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; | |
| 48 | + static function get_calendar($initial = true, $echo = true) { | |
| 49 | + global $wpdb, $m, $monthnum, $year, $wp_locale, $posts, $polylang; #modified# | |
| 66 | 50 | |
| 67 | - $join_clause = PLL()->model->post->join_clause(); #added# | |
| 68 | - $where_clause = PLL()->model->post->where_clause( PLL()->curlang ); #added# | |
| 51 | + $join_clause = $polylang->model->join_clause('post'); #added# | |
| 52 | + $where_clause = $polylang->model->where_clause($polylang->curlang, 'post'); #added# | |
| 69 | 53 | |
| 70 | - $key = md5( PLL()->curlang->slug . $m . $monthnum . $year ); #modified# | |
| 71 | - $cache = wp_cache_get( 'get_calendar', 'calendar' ); | |
| 72 | - | |
| 73 | - if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) { | |
| 74 | - /** This filter is documented in wp-includes/general-template.php */ | |
| 75 | - $output = apply_filters( 'get_calendar', $cache[ $key ] ); | |
| 76 | - | |
| 77 | - if ( $echo ) { | |
| 78 | - echo $output; | |
| 79 | - return; | |
| 54 | + $cache = array(); | |
| 55 | + $key = md5( $polylang->curlang->slug . $m . $monthnum . $year ); #modified# | |
| 56 | + if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) { | |
| 57 | + if ( is_array($cache) && isset( $cache[ $key ] ) ) { | |
| 58 | + if ( $echo ) { | |
| 59 | + /** This filter is documented in wp-includes/general-template.php */ | |
| 60 | + echo apply_filters( 'get_calendar', $cache[$key] ); | |
| 61 | + return; | |
| 62 | + } else { | |
| 63 | + /** This filter is documented in wp-includes/general-template.php */ | |
| 64 | + return apply_filters( 'get_calendar', $cache[$key] ); | |
| 65 | + } | |
| 80 | 66 | } |
| 81 | - | |
| 82 | - return $output; | |
| 83 | 67 | } |
| 84 | 68 | |
| 85 | - if ( ! is_array( $cache ) ) { | |
| 69 | + if ( !is_array($cache) ) | |
| 86 | 70 | $cache = array(); |
| 87 | - } | |
| 88 | 71 | |
| 89 | 72 | // Quick check. If we have no posts at all, abort! |
| 90 | - if ( ! $posts ) { | |
| 91 | - $gotsome = $wpdb->get_var( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1" ); | |
| 92 | - if ( ! $gotsome ) { | |
| 73 | + if ( !$posts ) { | |
| 74 | + $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); | |
| 75 | + if ( !$gotsome ) { | |
| 93 | 76 | $cache[ $key ] = ''; |
| 94 | 77 | wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
| 95 | 78 | return; |
| 96 | 79 | } |
| @@ -95,77 +78,67 @@ | ||
| 95 | 78 | return; |
| 96 | 79 | } |
| 97 | 80 | } |
| 98 | 81 | |
| 99 | - if ( isset( $_GET['w'] ) ) { | |
| 100 | - $w = (int) $_GET['w']; | |
| 101 | - } | |
| 102 | - // week_begins = 0 stands for Sunday. | |
| 103 | - $week_begins = (int) get_option( 'start_of_week' ); | |
| 82 | + if ( isset($_GET['w']) ) | |
| 83 | + $w = ''.intval($_GET['w']); | |
| 104 | 84 | |
| 105 | - // Let's figure out when we are. | |
| 106 | - if ( ! empty( $monthnum ) && ! empty( $year ) ) { | |
| 107 | - $thismonth = zeroise( (int) $monthnum, 2 ); | |
| 108 | - $thisyear = (int) $year; | |
| 109 | - } elseif ( ! empty( $w ) ) { | |
| 110 | - // We need to get the month from MySQL. | |
| 111 | - $thisyear = (int) substr( $m, 0, 4 ); | |
| 112 | - // It seems MySQL's weeks disagree with PHP's. | |
| 113 | - $d = ( ( $w - 1 ) * 7 ) + 6; | |
| 114 | - $thismonth = $wpdb->get_var( "SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')" ); | |
| 115 | - } elseif ( ! empty( $m ) ) { | |
| 116 | - $thisyear = (int) substr( $m, 0, 4 ); | |
| 117 | - if ( strlen( $m ) < 6 ) { | |
| 85 | + // week_begins = 0 stands for Sunday | |
| 86 | + $week_begins = intval(get_option('start_of_week')); | |
| 87 | + | |
| 88 | + // Let's figure out when we are | |
| 89 | + if ( !empty($monthnum) && !empty($year) ) { | |
| 90 | + $thismonth = ''.zeroise(intval($monthnum), 2); | |
| 91 | + $thisyear = ''.intval($year); | |
| 92 | + } elseif ( !empty($w) ) { | |
| 93 | + // We need to get the month from MySQL | |
| 94 | + $thisyear = ''.intval(substr($m, 0, 4)); | |
| 95 | + $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's | |
| 96 | + $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')"); | |
| 97 | + } elseif ( !empty($m) ) { | |
| 98 | + $thisyear = ''.intval(substr($m, 0, 4)); | |
| 99 | + if ( strlen($m) < 6 ) | |
| 118 | 100 | $thismonth = '01'; |
| 119 | - } else { | |
| 120 | - $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 ); | |
| 121 | - } | |
| 101 | + else | |
| 102 | + $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2); | |
| 122 | 103 | } else { |
| 123 | - $thisyear = current_time( 'Y' ); | |
| 124 | - $thismonth = current_time( 'm' ); | |
| 104 | + $thisyear = gmdate('Y', current_time('timestamp')); | |
| 105 | + $thismonth = gmdate('m', current_time('timestamp')); | |
| 125 | 106 | } |
| 126 | 107 | |
| 127 | - $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear ); | |
| 128 | - $last_day = gmdate( 't', $unixmonth ); | |
| 108 | + $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); | |
| 109 | + $last_day = date('t', $unixmonth); | |
| 129 | 110 | |
| 130 | - // Get the next and previous month and year with at least one post. | |
| 131 | - $previous = $wpdb->get_row( | |
| 132 | - "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year | |
| 111 | + // Get the next and previous month and year with at least one post | |
| 112 | + $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year | |
| 133 | 113 | FROM $wpdb->posts $join_clause |
| 134 | 114 | WHERE post_date < '$thisyear-$thismonth-01' |
| 135 | 115 | AND post_type = 'post' AND post_status = 'publish' $where_clause |
| 136 | 116 | ORDER BY post_date DESC |
| 137 | - LIMIT 1" | |
| 138 | - ); #modified# | |
| 139 | - $next = $wpdb->get_row( | |
| 140 | - "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year | |
| 117 | + LIMIT 1"); #modified# | |
| 118 | + $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year | |
| 141 | 119 | FROM $wpdb->posts $join_clause |
| 142 | 120 | WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' |
| 143 | 121 | AND post_type = 'post' AND post_status = 'publish' $where_clause |
| 144 | 122 | ORDER BY post_date ASC |
| 145 | - LIMIT 1" | |
| 146 | - ); #modified# | |
| 123 | + LIMIT 1"); #modified# | |
| 147 | 124 | |
| 148 | - /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ | |
| 149 | - $calendar_caption = _x( '%1$s %2$s', 'calendar caption' ); | |
| 150 | - $calendar_output = '<table id="wp-calendar" class="wp-calendar-table"> | |
| 151 | - <caption>' . sprintf( | |
| 152 | - $calendar_caption, | |
| 153 | - $wp_locale->get_month( $thismonth ), | |
| 154 | - gmdate( 'Y', $unixmonth ) | |
| 155 | - ) . '</caption> | |
| 125 | + /* translators: Calendar caption: 1: month name, 2: 4-digit year */ | |
| 126 | + $calendar_caption = _x('%1$s %2$s', 'calendar caption'); | |
| 127 | + $calendar_output = '<table id="wp-calendar"> | |
| 128 | + <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption> | |
| 156 | 129 | <thead> |
| 157 | 130 | <tr>'; |
| 158 | 131 | |
| 159 | 132 | $myweek = array(); |
| 160 | 133 | |
| 161 | - for ( $wdcount = 0; $wdcount <= 6; $wdcount++ ) { | |
| 162 | - $myweek[] = $wp_locale->get_weekday( ( $wdcount + $week_begins ) % 7 ); | |
| 134 | + for ( $wdcount=0; $wdcount<=6; $wdcount++ ) { | |
| 135 | + $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7); | |
| 163 | 136 | } |
| 164 | 137 | |
| 165 | 138 | foreach ( $myweek as $wd ) { |
| 166 | - $day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); | |
| 167 | - $wd = esc_attr( $wd ); | |
| 139 | + $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd); | |
| 140 | + $wd = esc_attr($wd); | |
| 168 | 141 | $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>"; |
| 169 | 142 | } |
| 170 | 143 | |
| 171 | 144 | $calendar_output .= ' |
| @@ -170,113 +143,119 @@ | ||
| 170 | 143 | |
| 171 | 144 | $calendar_output .= ' |
| 172 | 145 | </tr> |
| 173 | 146 | </thead> |
| 174 | - <tbody> | |
| 147 | + | |
| 148 | + <tfoot> | |
| 175 | 149 | <tr>'; |
| 176 | 150 | |
| 177 | - $daywithpost = array(); | |
| 151 | + if ( $previous ) { | |
| 152 | + $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>'; | |
| 153 | + } else { | |
| 154 | + $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>'; | |
| 155 | + } | |
| 178 | 156 | |
| 179 | - // Get days with posts. | |
| 180 | - $dayswithposts = $wpdb->get_results( | |
| 181 | - "SELECT DISTINCT DAYOFMONTH(post_date) | |
| 182 | - FROM $wpdb->posts $join_clause WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' | |
| 183 | - AND post_type = 'post' AND post_status = 'publish' | |
| 184 | - AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' $where_clause", | |
| 185 | - ARRAY_N | |
| 186 | - ); #modified# | |
| 157 | + $calendar_output .= "\n\t\t".'<td class="pad"> </td>'; | |
| 187 | 158 | |
| 159 | + if ( $next ) { | |
| 160 | + $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>'; | |
| 161 | + } else { | |
| 162 | + $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>'; | |
| 163 | + } | |
| 164 | + | |
| 165 | + $calendar_output .= ' | |
| 166 | + </tr> | |
| 167 | + </tfoot> | |
| 168 | + | |
| 169 | + <tbody> | |
| 170 | + <tr>'; | |
| 171 | + | |
| 172 | + // Get days with posts | |
| 173 | + $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) | |
| 174 | + FROM $wpdb->posts $join_clause | |
| 175 | + WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' | |
| 176 | + AND post_type = 'post' AND post_status = 'publish' $where_clause | |
| 177 | + AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); #modified# | |
| 188 | 178 | if ( $dayswithposts ) { |
| 189 | 179 | foreach ( (array) $dayswithposts as $daywith ) { |
| 190 | - $daywithpost[] = (int) $daywith[0]; | |
| 180 | + $daywithpost[] = $daywith[0]; | |
| 191 | 181 | } |
| 182 | + } else { | |
| 183 | + $daywithpost = array(); | |
| 192 | 184 | } |
| 193 | 185 | |
| 194 | - // See how much we should pad in the beginning. | |
| 195 | - $pad = calendar_week_mod( gmdate( 'w', $unixmonth ) - $week_begins ); | |
| 196 | - if ( 0 != $pad ) { | |
| 197 | - $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad"> </td>'; | |
| 186 | + if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false) | |
| 187 | + $ak_title_separator = "\n"; | |
| 188 | + else | |
| 189 | + $ak_title_separator = ', '; | |
| 190 | + | |
| 191 | + $ak_titles_for_day = array(); | |
| 192 | + $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom " | |
| 193 | + ."FROM $wpdb->posts $join_clause " | |
| 194 | + ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " | |
| 195 | + ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " | |
| 196 | + ."AND post_type = 'post' AND post_status = 'publish' $where_clause" | |
| 197 | + ); #modified# | |
| 198 | + if ( $ak_post_titles ) { | |
| 199 | + foreach ( (array) $ak_post_titles as $ak_post_title ) { | |
| 200 | + | |
| 201 | + $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) ); | |
| 202 | + | |
| 203 | + if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) ) | |
| 204 | + $ak_titles_for_day['day_'.$ak_post_title->dom] = ''; | |
| 205 | + if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one | |
| 206 | + $ak_titles_for_day["$ak_post_title->dom"] = $post_title; | |
| 207 | + else | |
| 208 | + $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title; | |
| 209 | + } | |
| 198 | 210 | } |
| 199 | 211 | |
| 200 | - $newrow = false; | |
| 201 | - $daysinmonth = (int) gmdate( 't', $unixmonth ); | |
| 212 | + // See how much we should pad in the beginning | |
| 213 | + $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins); | |
| 214 | + if ( 0 != $pad ) | |
| 215 | + $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad"> </td>'; | |
| 202 | 216 | |
| 217 | + $daysinmonth = intval(date('t', $unixmonth)); | |
| 203 | 218 | for ( $day = 1; $day <= $daysinmonth; ++$day ) { |
| 204 | - if ( isset( $newrow ) && $newrow ) { | |
| 219 | + if ( isset($newrow) && $newrow ) | |
| 205 | 220 | $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t"; |
| 206 | - } | |
| 207 | 221 | $newrow = false; |
| 208 | 222 | |
| 209 | - if ( current_time( 'j' ) == $day && | |
| 210 | - current_time( 'm' ) == $thismonth && | |
| 211 | - current_time( 'Y' ) == $thisyear ) { | |
| 223 | + if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) ) | |
| 212 | 224 | $calendar_output .= '<td id="today">'; |
| 213 | - } else { | |
| 225 | + else | |
| 214 | 226 | $calendar_output .= '<td>'; |
| 215 | - } | |
| 216 | 227 | |
| 217 | - if ( in_array( $day, $daywithpost, true ) ) { | |
| 218 | - // Any posts today? | |
| 219 | - $date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); | |
| 220 | - /* translators: Post calendar label. %s: Date. */ | |
| 221 | - $label = sprintf( __( 'Posts published on %s' ), $date_format ); | |
| 222 | - $calendar_output .= sprintf( | |
| 223 | - '<a href="%s" aria-label="%s">%s</a>', | |
| 224 | - get_day_link( $thisyear, $thismonth, $day ), | |
| 225 | - esc_attr( $label ), | |
| 226 | - $day | |
| 227 | - ); | |
| 228 | - } else { | |
| 228 | + if ( in_array($day, $daywithpost) ) // any posts today? | |
| 229 | + $calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>"; | |
| 230 | + else | |
| 229 | 231 | $calendar_output .= $day; |
| 230 | - } | |
| 231 | - | |
| 232 | 232 | $calendar_output .= '</td>'; |
| 233 | 233 | |
| 234 | - if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { | |
| 234 | + if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) | |
| 235 | 235 | $newrow = true; |
| 236 | - } | |
| 237 | 236 | } |
| 238 | 237 | |
| 239 | - $pad = 7 - calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ); | |
| 240 | - if ( 0 != $pad && 7 != $pad ) { | |
| 241 | - $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '"> </td>'; | |
| 242 | - } | |
| 238 | + $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins); | |
| 239 | + if ( $pad != 0 && $pad != 7 ) | |
| 240 | + $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'"> </td>'; | |
| 243 | 241 | |
| 244 | - $calendar_output .= "\n\t</tr>\n\t</tbody>"; | |
| 242 | + $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>"; | |
| 245 | 243 | |
| 246 | - $calendar_output .= "\n\t</table>"; | |
| 247 | - | |
| 248 | - $calendar_output .= '<nav aria-label="' . __( 'Previous and next months' ) . '" class="wp-calendar-nav">'; | |
| 249 | - | |
| 250 | - if ( $previous ) { | |
| 251 | - $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"><a href="' . get_month_link( $previous->year, $previous->month ) . '">« ' . | |
| 252 | - $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) . | |
| 253 | - '</a></span>'; | |
| 254 | - } else { | |
| 255 | - $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"> </span>'; | |
| 256 | - } | |
| 257 | - | |
| 258 | - $calendar_output .= "\n\t\t" . '<span class="pad"> </span>'; | |
| 259 | - | |
| 260 | - if ( $next ) { | |
| 261 | - $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"><a href="' . get_month_link( $next->year, $next->month ) . '">' . | |
| 262 | - $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) . | |
| 263 | - ' »</a></span>'; | |
| 264 | - } else { | |
| 265 | - $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"> </span>'; | |
| 266 | - } | |
| 267 | - | |
| 268 | - $calendar_output .= ' | |
| 269 | - </nav>'; | |
| 270 | - | |
| 271 | 244 | $cache[ $key ] = $calendar_output; |
| 272 | 245 | wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
| 273 | 246 | |
| 274 | 247 | if ( $echo ) { |
| 248 | + /** | |
| 249 | + * Filter the HTML calendar output. | |
| 250 | + * | |
| 251 | + * @since 3.0.0 | |
| 252 | + * | |
| 253 | + * @param string $calendar_output HTML output of the calendar. | |
| 254 | + */ | |
| 255 | + echo apply_filters( 'get_calendar', $calendar_output ); | |
| 256 | + } else { | |
| 275 | 257 | /** This filter is documented in wp-includes/general-template.php */ |
| 276 | - echo apply_filters( 'get_calendar', $calendar_output ); | |
| 277 | - return; | |
| 258 | + return apply_filters( 'get_calendar', $calendar_output ); | |
| 278 | 259 | } |
| 279 | - /** This filter is documented in wp-includes/general-template.php */ | |
| 280 | - return apply_filters( 'get_calendar', $calendar_output ); | |
| 281 | 260 | } |
| 282 | 261 | } |