Changeset 59947
- Timestamp:
- 03/06/2025 09:19:10 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/general-template.php
r59939 r59947 2348 2348 // Quick check. If we have no posts at all, abort! 2349 2349 if ( ! $posts ) { 2350 $prepared_query = $wpdb->prepare( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = %s AND post_status = 'publish' LIMIT 1", $post_type ); 2351 $gotsome = $wpdb->get_var( $prepared_query ); 2350 $gotsome = $wpdb->get_var( 2351 $wpdb->prepare( 2352 "SELECT 1 as test 2353 FROM $wpdb->posts 2354 WHERE post_type = %s 2355 AND post_status = 'publish' 2356 LIMIT 1", 2357 $post_type 2358 ) 2359 ); 2360 2352 2361 if ( ! $gotsome ) { 2353 2362 $cache[ $key ] = ''; … … 2362 2371 // Let's figure out when we are. 2363 2372 if ( ! empty( $monthnum ) && ! empty( $year ) ) { 2364 $thismonth = zeroise( (int) $monthnum, 2 );2373 $thismonth = (int) $monthnum; 2365 2374 $thisyear = (int) $year; 2366 2375 } elseif ( ! empty( $w ) ) { … … 2369 2378 // It seems MySQL's weeks disagree with PHP's. 2370 2379 $d = ( ( $w - 1 ) * 7 ) + 6; 2371 $thismonth = $wpdb->get_var( "SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')" ); 2380 $thismonth = (int) $wpdb->get_var( 2381 $wpdb->prepare( 2382 "SELECT DATE_FORMAT((DATE_ADD('%d0101', INTERVAL %d DAY) ), '%%m')", 2383 $thisyear, 2384 $d 2385 ) 2386 ); 2372 2387 } elseif ( ! empty( $m ) ) { 2373 2388 $thisyear = (int) substr( $m, 0, 4 ); 2374 2389 if ( strlen( $m ) < 6 ) { 2375 $thismonth = '01';2390 $thismonth = 1; 2376 2391 } else { 2377 $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 );2392 $thismonth = (int) substr( $m, 4, 2 ); 2378 2393 } 2379 2394 } else { 2380 $thisyear = current_time( 'Y' );2381 $thismonth = current_time( 'm' );2395 $thisyear = (int) current_time( 'Y' ); 2396 $thismonth = (int) current_time( 'm' ); 2382 2397 } 2383 2398 … … 2386 2401 2387 2402 // Get the next and previous month and year with at least one post. 2388 $previous_prepared_query = $wpdb->prepare( 2389 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 2390 FROM $wpdb->posts 2391 WHERE post_date < '$thisyear-$thismonth-01' 2392 AND post_type = %s AND post_status = 'publish' 2393 ORDER BY post_date DESC 2394 LIMIT 1", 2395 $post_type 2403 $previous = $wpdb->get_row( 2404 $wpdb->prepare( 2405 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 2406 FROM $wpdb->posts 2407 WHERE post_date < '%d-%d-01' 2408 AND post_type = %s AND post_status = 'publish' 2409 ORDER BY post_date DESC 2410 LIMIT 1", 2411 $thisyear, 2412 zeroise( $thismonth, 2 ), 2413 $post_type 2414 ) 2396 2415 ); 2397 $previous = $wpdb->get_row( $previous_prepared_query ); 2398 2399 $next_prepared_query = $wpdb->prepare( 2400 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 2401 FROM $wpdb->posts 2402 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' 2403 AND post_type = %s AND post_status = 'publish' 2404 ORDER BY post_date ASC 2405 LIMIT 1", 2406 $post_type 2416 2417 $next = $wpdb->get_row( 2418 $wpdb->prepare( 2419 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 2420 FROM $wpdb->posts 2421 WHERE post_date > '%d-%d-%d 23:59:59' 2422 AND post_type = %s AND post_status = 'publish' 2423 ORDER BY post_date ASC 2424 LIMIT 1", 2425 $thisyear, 2426 zeroise( $thismonth, 2 ), 2427 $last_day, 2428 $post_type 2429 ) 2407 2430 ); 2408 $next = $wpdb->get_row( $next_prepared_query );2409 2431 2410 2432 /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ … … 2440 2462 2441 2463 // Get days with posts. 2442 $dayswithposts_prepared_query = $wpdb->prepare( 2443 "SELECT DISTINCT DAYOFMONTH(post_date) 2444 FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' 2445 AND post_type = %s AND post_status = 'publish' 2446 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", 2447 $post_type 2464 $dayswithposts = $wpdb->get_results( 2465 $wpdb->prepare( 2466 "SELECT DISTINCT DAYOFMONTH(post_date) 2467 FROM $wpdb->posts WHERE post_date >= '%d-%d-01 00:00:00' 2468 AND post_type = %s AND post_status = 'publish' 2469 AND post_date <= '%d-%d-%d 23:59:59'", 2470 $thisyear, 2471 zeroise( $thismonth, 2 ), 2472 $post_type, 2473 $thisyear, 2474 zeroise( $thismonth, 2 ), 2475 $last_day 2476 ), 2477 ARRAY_N 2448 2478 ); 2449 $dayswithposts = $wpdb->get_results( $dayswithposts_prepared_query, ARRAY_N );2450 2479 2451 2480 if ( $dayswithposts ) { … … 2457 2486 // See how much we should pad in the beginning. 2458 2487 $pad = calendar_week_mod( (int) gmdate( 'w', $unixmonth ) - $week_begins ); 2459 if ( 0 != $pad) {2488 if ( $pad > 0 ) { 2460 2489 $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad"> </td>'; 2461 2490 } … … 2470 2499 $newrow = false; 2471 2500 2472 if ( current_time( 'j' )== $day &&2473 current_time( 'm' )== $thismonth &&2474 current_time( 'Y' )== $thisyear ) {2501 if ( (int) current_time( 'j' ) === $day && 2502 (int) current_time( 'm' ) === $thismonth && 2503 (int) current_time( 'Y' ) === $thisyear ) { 2475 2504 $calendar_output .= '<td id="today">'; 2476 2505 } else { … … 2495 2524 $calendar_output .= '</td>'; 2496 2525 2497 if ( 6 == calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {2526 if ( 6 === (int) calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { 2498 2527 $newrow = true; 2499 2528 } … … 2501 2530 2502 2531 $pad = 7 - calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ); 2503 if ( 0 != $pad && 7 != $pad) {2532 if ( 0 < $pad && $pad < 7 ) { 2504 2533 $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '"> </td>'; 2505 2534 } … … 2512 2541 2513 2542 if ( $previous ) { 2514 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"><a href="' . get_month_link( $previous->year, $previous->month ) . '">« ' . 2515 $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) . 2516 '</a></span>'; 2543 $calendar_output .= "\n\t\t" . sprintf( 2544 '<span class="wp-calendar-nav-prev"><a href="%1$s">« %2$s</a></span>', 2545 get_month_link( $previous->year, $previous->month ), 2546 $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) 2547 ); 2517 2548 } else { 2518 2549 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"> </span>'; … … 2522 2553 2523 2554 if ( $next ) { 2524 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"><a href="' . get_month_link( $next->year, $next->month ) . '">' . 2525 $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) . 2526 ' »</a></span>'; 2555 $calendar_output .= "\n\t\t" . sprintf( 2556 '<span class="wp-calendar-nav-next"><a href="%1$s">%2$s »</a></span>', 2557 get_month_link( $next->year, $next->month ), 2558 $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) 2559 ); 2527 2560 } else { 2528 2561 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"> </span>';
Note: See TracChangeset
for help on using the changeset viewer.