3895 | | global $cache_lastpostdate, $wpdb, $blog_id; |
3896 | | $add_seconds_server = date('Z'); |
3897 | | if ( !isset($cache_lastpostdate[$blog_id][$timezone]) ) { |
3898 | | switch(strtolower($timezone)) { |
3899 | | case 'gmt': |
3900 | | $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"); |
3901 | | break; |
3902 | | case 'blog': |
3903 | | $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"); |
3904 | | break; |
3905 | | case 'server': |
3906 | | $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"); |
3907 | | break; |
3908 | | } |
3909 | | $cache_lastpostdate[$blog_id][$timezone] = $lastpostdate; |
3910 | | } else { |
3911 | | $lastpostdate = $cache_lastpostdate[$blog_id][$timezone]; |
3912 | | } |
3913 | | return apply_filters( 'get_lastpostdate', $lastpostdate, $timezone ); |
| 3890 | return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date' ), $timezone ); |
3934 | | $add_seconds_server = date('Z'); |
3935 | | $timezone = strtolower( $timezone ); |
3936 | | |
3937 | | $lastpostmodified = wp_cache_get( "lastpostmodified:$timezone", 'timeinfo' ); |
3938 | | if ( $lastpostmodified ) |
3939 | | return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone ); |
3940 | | |
3941 | | switch ( strtolower($timezone) ) { |
3942 | | case 'gmt': |
3943 | | $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"); |
3944 | | break; |
3945 | | case 'blog': |
3946 | | $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"); |
3947 | | break; |
3948 | | case 'server': |
3949 | | $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"); |
3950 | | break; |
3951 | | } |
3952 | | |
| 3916 | function _get_last_post_time( $timezone, $field ) { |
| 3917 | global $wpdb, $blog_id; |
| 3918 | |
| 3919 | if ( !in_array( $field, array( 'date', 'modified' ) ) ) |
| 3920 | return false; |
| 3921 | |
| 3922 | $post_types = get_query_var('post_type'); |
| 3923 | if ( empty($post_types) ) |
| 3924 | $post_types = 'post'; |
| 3925 | |
| 3926 | $post_types = apply_filters( "get_lastpost{$field}_post_types", (array) $post_types ); |
| 3927 | |
| 3928 | $key = "lastpost{$field}:$blog_id:$timezone:" . wp_cache_key( $post_types ); |
| 3929 | |
| 3930 | $date = wp_cache_get( $key, 'timeinfo' ); |
| 3931 | |
| 3932 | if ( !$date ) { |
| 3933 | $add_seconds_server = date('Z'); |
| 3934 | |
| 3935 | array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) ); |
| 3936 | $post_types = "'" . implode( "', '", $post_types ) . "'"; |
| 3937 | |
| 3938 | switch ( strtolower( $timezone ) ) { |
| 3939 | case 'gmt': |
| 3940 | $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"); |
| 3941 | break; |
| 3942 | case 'blog': |
| 3943 | $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"); |
| 3944 | break; |
| 3945 | case 'server': |
| 3946 | $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"); |
| 3947 | break; |
| 3948 | } |
| 3949 | |
| 3950 | if ( $date ) |
| 3951 | wp_cache_set( $key, $date, 'timeinfo' ); |
| 3952 | } |
| 3953 | |
| 3954 | return $date; |
| 3955 | } |
| 3956 | |