Changeset 15838 for trunk/wp-includes/post.php
- Timestamp:
- 10/18/2010 09:06:49 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r15831 r15838 3946 3946 * @since 0.71 3947 3947 * 3948 * @uses $wpdb3949 * @uses $blog_id3950 3948 * @uses apply_filters() Calls 'get_lastpostdate' filter 3951 *3952 * @global mixed $cache_lastpostdate Stores the last post date3953 * @global mixed $pagenow The current page being viewed3954 3949 * 3955 3950 * @param string $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'. … … 3957 3952 */ 3958 3953 function get_lastpostdate($timezone = 'server') { 3959 global $cache_lastpostdate, $wpdb, $blog_id; 3960 $add_seconds_server = date('Z'); 3961 if ( !isset($cache_lastpostdate[$blog_id][$timezone]) ) { 3962 switch(strtolower($timezone)) { 3963 case 'gmt': 3964 $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt DESC LIMIT 1"); 3965 break; 3966 case 'blog': 3967 $lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt DESC LIMIT 1"); 3968 break; 3969 case 'server': 3970 $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt DESC LIMIT 1"); 3971 break; 3972 } 3973 $cache_lastpostdate[$blog_id][$timezone] = $lastpostdate; 3974 } else { 3975 $lastpostdate = $cache_lastpostdate[$blog_id][$timezone]; 3976 } 3977 return apply_filters( 'get_lastpostdate', $lastpostdate, $timezone ); 3954 return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date' ), $timezone ); 3978 3955 } 3979 3956 … … 3986 3963 * 3987 3964 * @since 1.2.0 3988 * @uses $wpdb3989 * @uses $blog_id3990 3965 * @uses apply_filters() Calls 'get_lastpostmodified' filter 3991 3966 * … … 3994 3969 */ 3995 3970 function get_lastpostmodified($timezone = 'server') { 3996 global $wpdb; 3997 3998 $add_seconds_server = date('Z'); 3999 $timezone = strtolower( $timezone ); 4000 4001 $lastpostmodified = wp_cache_get( "lastpostmodified:$timezone", 'timeinfo' ); 4002 if ( $lastpostmodified ) 4003 return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone ); 4004 4005 switch ( strtolower($timezone) ) { 4006 case 'gmt': 4007 $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1"); 4008 break; 4009 case 'blog': 4010 $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1"); 4011 break; 4012 case 'server': 4013 $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1"); 4014 break; 4015 } 3971 $lastpostmodified = _get_last_post_time( $timezone, 'modified' ); 4016 3972 4017 3973 $lastpostdate = get_lastpostdate($timezone); … … 4019 3975 $lastpostmodified = $lastpostdate; 4020 3976 4021 if ( $lastpostmodified )4022 wp_cache_set( "lastpostmodified:$timezone", $lastpostmodified, 'timeinfo' );4023 4024 3977 return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone ); 3978 } 3979 3980 function _get_last_post_time( $timezone, $field ) { 3981 global $wpdb, $blog_id; 3982 3983 if ( !in_array( $field, array( 'date', 'modified' ) ) ) 3984 return false; 3985 3986 $post_types = get_query_var('post_type'); 3987 if ( empty($post_types) ) 3988 $post_types = 'post'; 3989 3990 $post_types = apply_filters( "get_lastpost{$field}_post_types", (array) $post_types ); 3991 3992 $key = "lastpost{$field}:$blog_id:$timezone:" . wp_cache_key( $post_types ); 3993 3994 $date = wp_cache_get( $key, 'timeinfo' ); 3995 3996 if ( !$date ) { 3997 $add_seconds_server = date('Z'); 3998 3999 array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) ); 4000 $post_types = "'" . implode( "', '", $post_types ) . "'"; 4001 4002 switch ( strtolower( $timezone ) ) { 4003 case 'gmt': 4004 $date = $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); 4005 break; 4006 case 'blog': 4007 $date = $wpdb->get_var("SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); 4008 break; 4009 case 'server': 4010 $date = $wpdb->get_var("SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1"); 4011 break; 4012 } 4013 4014 if ( $date ) 4015 wp_cache_set( $key, $date, 'timeinfo' ); 4016 } 4017 4018 return $date; 4025 4019 } 4026 4020
Note: See TracChangeset
for help on using the changeset viewer.