| @@ -1,55 +1,45 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! class_exists( 'WP_Widget_Calendar' ) ) { |
| 4 | - require_once ABSPATH . '/wp-includes/default-widgets.php'; | |
| 4 | + require_once( ABSPATH . '/wp-includes/default-widgets.php' ); | |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | - * Obliged to rewrite the whole functionality as there is no filter on sql queries and only a filter on final output | |
| 9 | - * Code base last checked with WP 4.9.7 | |
| 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 | |
| 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 4.4.2 | |
| 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 | 14 | * @since 0.5 |
| 15 | 15 | */ |
| 16 | 16 | class PLL_Widget_Calendar extends WP_Widget_Calendar { |
| 17 | - protected static $pll_instance = 0; // Can't use $instance of WP_Widget_Calendar as it's private :/ | |
| 18 | 17 | |
| 19 | 18 | /** |
| 20 | - * Outputs the content for the current Calendar widget instance. | |
| 21 | - * Modified version of the parent function to call our own get_calendar function. | |
| 19 | + * displays the widget | |
| 20 | + * modified version of the parent function to call our own get_calendar function | |
| 22 | 21 | * |
| 23 | 22 | * @since 0.5 |
| 24 | 23 | * |
| 25 | 24 | * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. |
| 26 | - * @param array $instance The settings for the particular instance of the widget. | |
| 25 | + * @param array $instance The settings for the particular instance of the widget | |
| 27 | 26 | */ |
| 28 | - public function widget( $args, $instance ) { | |
| 29 | - $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; | |
| 30 | - | |
| 27 | + function widget( $args, $instance ) { | |
| 31 | 28 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
| 32 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); | |
| 33 | - | |
| 29 | + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? ' ' : $instance['title'], $instance, $this->id_base ); | |
| 34 | 30 | echo $args['before_widget']; |
| 35 | 31 | if ( $title ) { |
| 36 | 32 | echo $args['before_title'] . $title . $args['after_title']; |
| 37 | 33 | } |
| 38 | - if ( 0 === self::$pll_instance ) { #modified# | |
| 39 | - echo '<div id="calendar_wrap" class="calendar_wrap">'; | |
| 40 | - } else { | |
| 41 | - echo '<div class="calendar_wrap">'; | |
| 42 | - } | |
| 34 | + echo '<div id="calendar_wrap">'; | |
| 43 | 35 | empty( PLL()->curlang ) ? get_calendar() : self::get_calendar(); #modified# |
| 44 | 36 | echo '</div>'; |
| 45 | 37 | echo $args['after_widget']; |
| 46 | - | |
| 47 | - self::$pll_instance++; #modified# | |
| 48 | 38 | } |
| 49 | 39 | |
| 50 | 40 | /** |
| 51 | - * Modified version of WP get_calendar function to filter the query | |
| 41 | + * modified version of WP get_calendar function to filter the query | |
| 52 | 42 | * |
| 53 | 43 | * @since 0.5 |
| 54 | 44 | * |
| 55 | 45 | * @param bool $initial Optional, default is true. Use initial calendar names. |
| @@ -55,9 +45,9 @@ | ||
| 55 | 45 | * @param bool $initial Optional, default is true. Use initial calendar names. |
| 56 | 46 | * @param bool $echo Optional, default is true. Set to false for return. |
| 57 | 47 | * @return string|null String when retrieving, null when displaying. |
| 58 | 48 | */ |
| 59 | - static public function get_calendar( $initial = true, $echo = true ) { | |
| 49 | + static function get_calendar( $initial = true, $echo = true ) { | |
| 60 | 50 | global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; |
| 61 | 51 | |
| 62 | 52 | $join_clause = PLL()->model->post->join_clause(); #added# |
| 63 | 53 | $where_clause = PLL()->model->post->where_clause( PLL()->curlang ); #added# |
| @@ -231,9 +221,8 @@ | ||
| 231 | 221 | |
| 232 | 222 | if ( in_array( $day, $daywithpost ) ) { |
| 233 | 223 | // any posts today? |
| 234 | 224 | $date_format = date( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); |
| 235 | - /* translators: Post calendar label. 1: Date */ | |
| 236 | 225 | $label = sprintf( __( 'Posts published on %s' ), $date_format ); |
| 237 | 226 | $calendar_output .= sprintf( |
| 238 | 227 | '<a href="%s" aria-label="%s">%s</a>', |
| 239 | 228 | get_day_link( $thisyear, $thismonth, $day ), |
| @@ -260,9 +249,9 @@ | ||
| 260 | 249 | wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
| 261 | 250 | |
| 262 | 251 | if ( $echo ) { |
| 263 | 252 | /** |
| 264 | - * Filters the HTML calendar output. | |
| 253 | + * Filter the HTML calendar output. | |
| 265 | 254 | * |
| 266 | 255 | * @since 3.0.0 |
| 267 | 256 | * |
| 268 | 257 | * @param string $calendar_output HTML output of the calendar. |