Ticket #16173: calendar.diff
File calendar.diff, 7.3 KB (added by , 14 years ago) |
---|
-
wp-includes/default-widgets.php
332 332 } 333 333 334 334 function widget( $args, $instance ) { 335 extract($args); 336 $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title'], $instance, $this->id_base); 335 extract( $args ); 336 337 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? ' ' : $instance['title'], $instance, $this->id_base ); 338 $current_post_type = $this->_get_current_post_type( $instance ); 339 337 340 echo $before_widget; 341 338 342 if ( $title ) 339 echo $before_title . $title . $after_title; 340 echo '<div id="calendar_wrap">'; 341 get_calendar(); 342 echo '</div>'; 343 echo $before_title . $title . $after_title; ?> 344 345 <div id="calendar_wrap"> 346 347 <?php get_calendar( true, true, $current_post_type ); ?> 348 349 </div> 350 351 <?php 352 343 353 echo $after_widget; 344 354 } 345 355 346 356 function update( $new_instance, $old_instance ) { 347 $instance = $old_instance; 348 $instance['title'] = strip_tags($new_instance['title']); 357 $instance = $old_instance; 358 $instance['title'] = strip_tags( $new_instance['title'] ); 359 $instance['post_type'] = stripslashes( $new_instance['post_type'] ); 349 360 350 361 return $instance; 351 362 } 352 363 353 364 function form( $instance ) { 354 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); 355 $title = strip_tags($instance['title']); 356 ?> 357 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> 358 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p> 359 <?php 365 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); 366 $title = strip_tags( $instance['title'] ); 367 $current_post_type = $this->_get_current_post_type( $instance ); 368 ?> 369 370 <p> 371 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 372 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> 373 </p> 374 375 <p> 376 <label for="<?php echo $this->get_field_id( 'post_type' ); ?>"><?php _e( 'Post Type:' ); ?></label> 377 <select class="widefat" id="<?php echo $this->get_field_id( 'post_type' ); ?>" name="<?php echo $this->get_field_name('post_type'); ?>"> 378 379 <?php foreach ( get_post_types( array(), 'objects' ) as $post_type ) : 380 if ( !post_type_supports( $post_type->name, 'calendar' ) ) 381 continue; 382 ?> 383 384 <option value="<?php echo esc_attr( $post_type->name ); ?>"<?php selected( $post_type->name, $current_post_type ); ?>><?php echo $post_type->label; ?></option> 385 386 <?php endforeach; ?> 387 388 </select> 389 </p> 390 391 <?php 360 392 } 393 394 function _get_current_post_type( $instance ) { 395 if ( !empty( $instance['post_type'] ) && post_type_exists( $instance['post_type'] ) ) 396 return $instance['post_type']; 397 398 return 'post'; 399 } 361 400 } 362 401 363 402 /** -
wp-includes/general-template.php
1071 1071 * 1072 1072 * @param bool $initial Optional, default is true. Use initial calendar names. 1073 1073 * @param bool $echo Optional, default is true. Set to false for return. 1074 * @param string $post_type Optional, default is 'post'. Use to get a calendar 1075 * of a custom post type 1074 1076 */ 1075 function get_calendar( $initial = true, $echo = true) {1077 function get_calendar( $initial = true, $echo = true, $post_type = 'post' ) { 1076 1078 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; 1077 1079 1080 // Check if the post type exists 1081 if ( empty( $post_type ) || !post_type_exists( 'post' ) ) 1082 return false; 1083 1078 1084 $cache = array(); 1079 1085 $key = md5( $m . $monthnum . $year ); 1080 1086 if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) { … … 1093 1099 1094 1100 // Quick check. If we have no posts at all, abort! 1095 1101 if ( !$posts ) { 1096 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = ' post' AND post_status = 'publish' LIMIT 1");1102 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = '$post_type' AND post_status = 'publish' LIMIT 1"); 1097 1103 if ( !$gotsome ) { 1098 1104 $cache[ $key ] = ''; 1099 1105 wp_cache_set( 'get_calendar', $cache, 'calendar' ); … … 1134 1140 $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 1135 1141 FROM $wpdb->posts 1136 1142 WHERE post_date < '$thisyear-$thismonth-01' 1137 AND post_type = ' post' AND post_status = 'publish'1143 AND post_type = '$post_type' AND post_status = 'publish' 1138 1144 ORDER BY post_date DESC 1139 1145 LIMIT 1"); 1140 1146 $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 1141 1147 FROM $wpdb->posts 1142 1148 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' 1143 AND post_type = ' post' AND post_status = 'publish'1149 AND post_type = '$post_type' AND post_status = 'publish' 1144 1150 ORDER BY post_date ASC 1145 1151 LIMIT 1"); 1146 1152 … … 1194 1200 // Get days with posts 1195 1201 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) 1196 1202 FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' 1197 AND post_type = ' post' AND post_status = 'publish'1203 AND post_type = '$post_type' AND post_status = 'publish' 1198 1204 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); 1199 1205 if ( $dayswithposts ) { 1200 1206 foreach ( (array) $dayswithposts as $daywith ) { … … 1214 1220 ."FROM $wpdb->posts " 1215 1221 ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " 1216 1222 ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " 1217 ."AND post_type = ' post' AND post_status = 'publish'"1223 ."AND post_type = '$post_type' AND post_status = 'publish'" 1218 1224 ); 1219 1225 if ( $ak_post_titles ) { 1220 1226 foreach ( (array) $ak_post_titles as $ak_post_title ) { -
wp-includes/post.php
26 26 'hierarchical' => false, 27 27 'rewrite' => false, 28 28 'query_var' => false, 29 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),29 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats', 'calendar' ), 30 30 ) ); 31 31 32 32 register_post_type( 'page', array( … … 1209 1209 * 1210 1210 * All features are directly associated with a functional area of the edit screen, such as the 1211 1211 * editor or a meta box: 'title', 'editor', 'comments', 'revisions', 'trackbacks', 'author', 1212 * 'excerpt', 'page-attributes', 'thumbnail', and 'custom-fields'.1212 * 'excerpt', 'page-attributes', 'thumbnail', 'calendar' and 'custom-fields'. 1213 1213 * 1214 1214 * Additionally, the 'revisions' feature dictates whether the post type will store revisions, 1215 * the 'calendar' feature will show the post type in the select box in the calendar widget, 1215 1216 * and the 'comments' feature dicates whether the comments count will show on the edit screen. 1216 1217 * 1217 1218 * @since 3.0.0