public function test_cache_is_cleared_when_comment_is_trashed() { $comment_1 = self::factory()->comment->create_and_get(array('comment_status' => 1, 'comment_date' => '1998-01-01 11:00:00', 'comment_date_gmt' => '1998-01-01 10:00:00')); $comment_2 = self::factory()->comment->create_and_get(array('comment_status' => 1, 'comment_date' => '2000-01-02 11:00:00', 'comment_date_gmt' => '2000-01-02 10:00:00')); get_lastcommentmodified(); $this->assertSame(strtotime('2000-01-02 10:00:00'), strtotime(wp_cache_get('lastcommentmodified:server', 'timeinfo'))); wp_trash_comment($comment_2->comment_ID); $this->assertFalse(wp_cache_get('lastcommentmodified:server', 'timeinfo')); $this->assertSame(strtotime('1998-01-01 10:00:00'), strtotime(get_lastcommentmodified())); $this->assertSame(strtotime('1998-01-01 10:00:00'), strtotime(wp_cache_get('lastcommentmodified:server', 'timeinfo'))); }
protected static function _find($app, $args) { $args = self::convert_request($args); $found = 0; $comments = array(); $model = self::model(); if ($lastModified = apply_filters('thermal_get_lastcommentmodified', get_lastcommentmodified('gmt'))) { $app->lastModified(strtotime($lastModified . ' GMT')); } $comments = $model->find($args, $found); array_walk($comments, array(__CLASS__, 'format'), 'read'); return empty($args['include_found']) ? compact('comments') : compact('comments', 'found'); }
function setLastModifiedHeader(array $headers, WP $wp) { global $wpdb; $this->lastModified = null; if (!is_user_logged_in() && empty($wp->query_vars['error']) && empty($wp->query_vars['feed'])) { // Retrieve last post modified, not depending on type (includes standard posts, pages, but also any future type of post) $wp_last_modified_date = $wpdb->get_var("SELECT GREATEST(post_modified_gmt, post_date_gmt) d FROM {$wpdb->posts} WHERE post_status = 'publish' ORDER BY d DESC LIMIT 1"); $wp_last_modified_date = max($wp_last_modified_date, get_lastcommentmodified('GMT')); if ($user_comment_date = $_COOKIE['comment_date_' . COOKIEHASH]) { $wp_last_modified_date = max($wp_last_modified_date, $user_comment_date); } $wp_last_modified = mysql2date('D, d M Y H:i:s', $wp_last_modified_date, 0) . ' GMT'; $headers['Last-Modified'] = $wp_last_modified; $headers['ETag'] = '"' . md5($wp_last_modified) . '"'; $this->headers = $headers; } return $headers; }
function wpjam_headers($headers, $wp) { if (!is_user_logged_in() && empty($wp->query_vars['feed'])) { $headers['Cache-Control'] = 'max-age:600'; $headers['Expires'] = gmdate('D, d M Y H:i:s', time() + 600) . " GMT"; $wpjam_timestamp = get_lastpostmodified('GMT') > get_lastcommentmodified('GMT') ? get_lastpostmodified('GMT') : get_lastcommentmodified('GMT'); $wp_last_modified = mysql2date('D, d M Y H:i:s', $wpjam_timestamp, 0) . ' GMT'; $wp_etag = '"' . md5($wp_last_modified) . '"'; $headers['Last-Modified'] = $wp_last_modified; $headers['ETag'] = $wp_etag; // Support for Conditional GET if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { $client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); } else { $client_etag = false; } $client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']); // If string is empty, return 0. If not, attempt to parse into a timestamp $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; // Make a timestamp for our most recent modification... $wp_modified_timestamp = strtotime($wp_last_modified); $exit_required = false; if ($client_last_modified && $client_etag ? $client_modified_timestamp >= $wp_modified_timestamp && $client_etag == $wp_etag : $client_modified_timestamp >= $wp_modified_timestamp || $client_etag == $wp_etag) { $status = 304; $exit_required = true; } if ($exit_required) { if (!empty($status)) { status_header($status); } foreach ((array) $headers as $name => $field_value) { @header("{$name}: {$field_value}"); } if (isset($headers['Last-Modified']) && empty($headers['Last-Modified']) && function_exists('header_remove')) { @header_remove('Last-Modified'); } exit; } } return $headers; }
/** * Send additional HTTP headers for caching, content type, etc. * * Sets the X-Pingback header, 404 status (if 404), Content-type. If showing * a feed, it will also send last-modified, etag, and 304 status if needed. * * @since 2.0.0 */ function send_headers() { $headers = array('X-Pingback' => get_bloginfo('pingback_url')); $status = null; $exit_required = false; if (is_user_logged_in()) { $headers = array_merge($headers, wp_get_nocache_headers()); } if (!empty($this->query_vars['error'])) { $status = (int) $this->query_vars['error']; if (404 === $status) { if (!is_user_logged_in()) { $headers = array_merge($headers, wp_get_nocache_headers()); } $headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset'); } elseif (in_array($status, array(403, 500, 502, 503))) { $exit_required = true; } } else { if (empty($this->query_vars['feed'])) { $headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset'); } else { // We're showing a feed, so WP is indeed the only thing that last changed if (!empty($this->query_vars['withcomments']) || false !== strpos($this->query_vars['feed'], 'comments-') || empty($this->query_vars['withoutcomments']) && (!empty($this->query_vars['p']) || !empty($this->query_vars['name']) || !empty($this->query_vars['page_id']) || !empty($this->query_vars['pagename']) || !empty($this->query_vars['attachment']) || !empty($this->query_vars['attachment_id']))) { $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0) . ' GMT'; } else { $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0) . ' GMT'; } $wp_etag = '"' . md5($wp_last_modified) . '"'; $headers['Last-Modified'] = $wp_last_modified; $headers['ETag'] = $wp_etag; // Support for Conditional GET if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { $client_etag = wp_unslash($_SERVER['HTTP_IF_NONE_MATCH']); } else { $client_etag = false; } $client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']); // If string is empty, return 0. If not, attempt to parse into a timestamp $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; // Make a timestamp for our most recent modification... $wp_modified_timestamp = strtotime($wp_last_modified); if ($client_last_modified && $client_etag ? $client_modified_timestamp >= $wp_modified_timestamp && $client_etag == $wp_etag : $client_modified_timestamp >= $wp_modified_timestamp || $client_etag == $wp_etag) { $status = 304; $exit_required = true; } } } /** * Filter the HTTP headers before they're sent to the browser. * * @since 2.8.0 * * @param array $headers The list of headers to be sent. * @param WP $this Current WordPress environment instance. */ $headers = apply_filters('wp_headers', $headers, $this); if (!empty($status)) { status_header($status); } // If Last-Modified is set to false, it should not be sent (no-cache situation). if (isset($headers['Last-Modified']) && false === $headers['Last-Modified']) { unset($headers['Last-Modified']); // In PHP 5.3+, make sure we are not sending a Last-Modified header. if (function_exists('header_remove')) { @header_remove('Last-Modified'); } else { // In PHP 5.2, send an empty Last-Modified header, but only as a // last resort to override a header already sent. #WP23021 foreach (headers_list() as $header) { if (0 === stripos($header, 'Last-Modified')) { $headers['Last-Modified'] = ''; break; } } } } foreach ((array) $headers as $name => $field_value) { @header("{$name}: {$field_value}"); } if ($exit_required) { exit; } /** * Fires once the requested HTTP headers for caching, content type, etc. have been sent. * * @since 2.1.0 * * @param WP &$this Current WordPress environment instance (passed by reference). */ do_action_ref_array('send_headers', array(&$this)); }
function send_headers() { @header('X-Pingback: ' . get_bloginfo('pingback_url')); if (is_user_logged_in()) { nocache_headers(); } if (!empty($this->query_vars['error']) && '404' == $this->query_vars['error']) { status_header(404); if (!is_user_logged_in()) { nocache_headers(); } @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); } else { if (empty($this->query_vars['feed'])) { @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); } else { // We're showing a feed, so WP is indeed the only thing that last changed if (!empty($this->query_vars['withcomments']) || empty($this->query_vars['withoutcomments']) && (!empty($this->query_vars['p']) || !empty($this->query_vars['name']) || !empty($this->query_vars['page_id']) || !empty($this->query_vars['pagename']) || !empty($this->query_vars['attachment']) || !empty($this->query_vars['attachment_id']))) { $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0) . ' GMT'; } else { $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0) . ' GMT'; } $wp_etag = '"' . md5($wp_last_modified) . '"'; @header("Last-Modified: {$wp_last_modified}"); @header("ETag: {$wp_etag}"); // Support for Conditional GET if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { $client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); } else { $client_etag = false; } $client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']); // If string is empty, return 0. If not, attempt to parse into a timestamp $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; // Make a timestamp for our most recent modification... $wp_modified_timestamp = strtotime($wp_last_modified); if ($client_last_modified && $client_etag ? $client_modified_timestamp >= $wp_modified_timestamp && $client_etag == $wp_etag : $client_modified_timestamp >= $wp_modified_timestamp || $client_etag == $wp_etag) { status_header(304); exit; } } } do_action_ref_array('send_headers', array(&$this)); }
if (is_singular()) { printf(ent2ncr(__('Comments on: %s')), get_the_title_rss()); } elseif (is_search()) { printf(ent2ncr(__('Comments for %1$s searching on %2$s')), get_bloginfo_rss('name'), attribute_escape(get_search_query())); } else { printf(ent2ncr(__('Comments for %s')), get_bloginfo_rss('name') . get_wp_title_rss()); } ?> </title> <subtitle type="text"><?php bloginfo_rss('description'); ?> </subtitle> <updated><?php echo mysql2date('Y-m-d\\TH:i:s\\Z', get_lastcommentmodified('GMT')); ?> </updated> <?php the_generator('atom'); ?> <?php if (is_singular()) { ?> <link rel="alternate" type="<?php bloginfo_rss('html_type'); ?> " href="<?php echo get_comments_link(); ?>
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" <?php do_action('rss2_ns'); do_action('rss2_comments_ns'); ?> > <channel> <title><?php if ( is_singular() ) printf(ent2ncr(__('Comments on: %s')), get_the_title_rss()); elseif ( is_search() ) printf(ent2ncr(__('Comments for %s searching on %s')), get_bloginfo_rss( 'name' ), esc_attr($wp_query->query_vars['s'])); else printf(ent2ncr(__('Comments for %s')), get_bloginfo_rss( 'name' ) . get_wp_title_rss()); ?></title> <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" /> <link><?php (is_single()) ? the_permalink_rss() : bloginfo_rss("url") ?></link> <description><?php bloginfo_rss("description") ?></description> <lastBuildDate><?php echo mysql2date('r', get_lastcommentmodified('GMT')); ?></lastBuildDate> <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod> <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency> <?php do_action('commentsrss2_head'); ?> <?php if ( have_comments() ) : while ( have_comments() ) : the_comment(); $comment_post = get_post($comment->comment_post_ID); get_post_custom($comment_post->ID); ?> <item> <title><?php if ( !is_singular() ) { $title = get_the_title($comment_post->ID); $title = apply_filters('the_title_rss', $title); printf(ent2ncr(__('Comment on %1$s by %2$s')), $title, get_comment_author_rss()); } else {
/** * Send additional HTTP headers for caching, content type, etc. * * Sets the X-Pingback header, 404 status (if 404), Content-type. If showing * a feed, it will also send last-modified, etag, and 304 status if needed. * * @since 2.0.0 */ function send_headers() { $headers = array('X-Pingback' => get_bloginfo('pingback_url')); $status = null; $exit_required = false; if (is_user_logged_in()) { $headers = array_merge($headers, wp_get_nocache_headers()); } if (!empty($this->query_vars['error'])) { $status = (int) $this->query_vars['error']; if (404 === $status) { if (!is_user_logged_in()) { $headers = array_merge($headers, wp_get_nocache_headers()); } $headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset'); } elseif (in_array($status, array(403, 500, 502, 503))) { $exit_required = true; } } else { if (empty($this->query_vars['feed'])) { $headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset'); } else { // We're showing a feed, so WP is indeed the only thing that last changed if (!empty($this->query_vars['withcomments']) || empty($this->query_vars['withoutcomments']) && (!empty($this->query_vars['p']) || !empty($this->query_vars['name']) || !empty($this->query_vars['page_id']) || !empty($this->query_vars['pagename']) || !empty($this->query_vars['attachment']) || !empty($this->query_vars['attachment_id']))) { $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0) . ' GMT'; } else { $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0) . ' GMT'; } $wp_etag = '"' . md5($wp_last_modified) . '"'; $headers['Last-Modified'] = $wp_last_modified; $headers['ETag'] = $wp_etag; // Support for Conditional GET if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { $client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); } else { $client_etag = false; } $client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']); // If string is empty, return 0. If not, attempt to parse into a timestamp $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; // Make a timestamp for our most recent modification... $wp_modified_timestamp = strtotime($wp_last_modified); if ($client_last_modified && $client_etag ? $client_modified_timestamp >= $wp_modified_timestamp && $client_etag == $wp_etag : $client_modified_timestamp >= $wp_modified_timestamp || $client_etag == $wp_etag) { $status = 304; $exit_required = true; } } } $headers = apply_filters('wp_headers', $headers, $this); if (!empty($status)) { status_header($status); } foreach ((array) $headers as $name => $field_value) { @header("{$name}: {$field_value}"); } if ($exit_required) { exit; } do_action_ref_array('send_headers', array(&$this)); }
?> </title> <atom:link href="<?php self_link(); ?> " rel="self" type="application/rss+xml" /> <link><?php is_single() ? the_permalink_rss() : bloginfo_rss("url"); ?> </link> <description><?php bloginfo_rss("description"); ?> </description> <lastBuildDate><?php $date = get_lastcommentmodified('GMT'); echo $date ? mysql2date('r', $date, false) : date('r'); ?> </lastBuildDate> <sy:updatePeriod><?php /** This filter is documented in wp-includes/feed-rss2.php */ echo apply_filters('rss_update_period', 'hourly'); ?> </sy:updatePeriod> <sy:updateFrequency><?php /** This filter is documented in wp-includes/feed-rss2.php */ echo apply_filters('rss_update_frequency', '1'); ?> </sy:updateFrequency> <?php /**
} // Sending HTTP headers if ( !empty($error) && '404' == $error ) { if ( preg_match('/cgi/', php_sapi_name()) ) @header('Status: 404 Not Found'); else @header('HTTP/1.x 404 Not Found'); } else if ( empty($feed) ) { @header('X-Pingback: '. get_bloginfo('pingback_url')); @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); } else { // We're showing a feed, so WP is indeed the only thing that last changed if ( $withcomments ) $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT'; else $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT'; $wp_etag = '"' . md5($wp_last_modified) . '"'; @header("Last-Modified: $wp_last_modified"); @header("ETag: $wp_etag"); @header('X-Pingback: ' . get_bloginfo('pingback_url')); // Support for Conditional GET if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) $client_last_modified = $_SERVER['HTTP_IF_MODIFIED_SINCE']; else $client_last_modified = false; if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); else $client_etag = false; if ( ($client_last_modified && $client_etag) ? ((strtotime($client_last_modified) >= strtotime($wp_last_modified)) && ($client_etag == $wp_etag)) :
?> </title> <atom:link href="<?php self_link(); ?> " rel="self" type="application/rss+xml" /> <link><?php is_single() ? the_permalink_rss() : bloginfo_rss("url"); ?> </link> <description><?php bloginfo_rss("description"); ?> </description> <lastBuildDate><?php echo mysql2date('r', get_lastcommentmodified('GMT')); ?> </lastBuildDate> <?php the_generator('rss2'); ?> <sy:updatePeriod><?php echo apply_filters('rss_update_period', 'hourly'); ?> </sy:updatePeriod> <sy:updateFrequency><?php echo apply_filters('rss_update_frequency', '1'); ?> </sy:updateFrequency> <?php do_action('commentsrss2_head');
function send_headers() { @header('X-Pingback: '. get_bloginfo('pingback_url')); if ( is_user_logged_in() ) nocache_headers(); if ( !empty($this->query_vars['error']) && '404' == $this->query_vars['error'] ) { status_header( 404 ); if ( !is_user_logged_in() ) nocache_headers(); @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); } else if ( empty($this->query_vars['feed']) ) { @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); } else { // We're showing a feed, so WP is indeed the only thing that last changed if ( $this->query_vars['withcomments'] ) $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT'; else $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT'; $wp_etag = '"' . md5($wp_last_modified) . '"'; @header("Last-Modified: $wp_last_modified"); @header("ETag: $wp_etag"); // Support for Conditional GET if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); else $client_etag = false; $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']); // If string is empty, return 0. If not, attempt to parse into a timestamp $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; // Make a timestamp for our most recent modification... $wp_modified_timestamp = strtotime($wp_last_modified); if ( ($client_last_modified && $client_etag) ? (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) : (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) { status_header( 304 ); exit; } } }
} $GLOBALS['doing_rss'] = 1; if (test_param('p') && $p != 'all' || test_param('name') || get_param('withcomments') == 1) { if (test_param('p')) { $_post_id = get_param('p'); $_post_name = ''; } else { if (test_param('name')) { $_post_id = -1; $_post_name = get_param('name'); } else { $_post_id = 0; $_post_name = ''; } } $lastcommentdate_s = mysql2date('Y-m-d H:i:s', get_lastcommentmodified($_post_id, $_post_name)); $lastcommentdate = mysql2date('U', $lastcommentdate_s); static_content_header($lastcommentdate); } else { $lastpostdate_s = mysql2date('Y-m-d H:i:s', get_lastpostmodified()); $lastpostdate = mysql2date('U', $lastpostdate_s); static_content_header($lastpostdate); } } } /* Getting settings from db */ if (!empty($GLOBALS['doing_rss'])) { $GLOBALS['posts_per_page'] = get_settings('posts_per_rss'); } if ($GLOBALS['pagenow'] == 'nkarchives.php' && !empty($GLOBALS['wp_arc_posts_per_page'])) { $GLOBALS['posts_per_page'] = $GLOBALS['wp_arc_posts_per_page'];
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="<?php echo get_option('rss_language'); ?>" <?php do_action('atom_ns'); ?> > <title type="text"><?php if ( is_singular() ) printf(ent2ncr(__('Comments on: %s')), get_the_title_rss()); elseif ( is_search() ) printf(ent2ncr(__('Comments for %1$s searching on %2$s')), get_bloginfo_rss( 'name' ), attribute_escape(get_search_query())); else printf(ent2ncr(__('Comments for %s')), get_bloginfo_rss( 'name' ) . get_wp_title_rss()); ?></title> <subtitle type="text"><?php bloginfo_rss('description'); ?></subtitle> <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastcommentmodified('GMT')); ?></updated> <?php the_generator( 'atom' ); ?> <?php if ( is_singular() ) { ?> <link rel="alternate" type="<?php bloginfo_rss('html_type'); ?>" href="<?php echo get_comments_link(); ?>" /> <link rel="self" type="application/atom+xml" href="<?php echo get_post_comments_feed_link('', 'atom'); ?>" /> <id><?php echo get_post_comments_feed_link('', 'atom'); ?></id> <?php } elseif(is_search()) { ?> <link rel="alternate" type="<?php bloginfo_rss('html_type'); ?>" href="<?php echo get_option('home') . '?s=' . attribute_escape(get_search_query()); ?>" /> <link rel="self" type="application/atom+xml" href="<?php echo get_search_comments_feed_link('', 'atom'); ?>" /> <id><?php echo get_search_comments_feed_link('', 'atom'); ?></id> <?php } else { ?> <link rel="alternate" type="<?php bloginfo_rss('html_type'); ?>" href="<?php bloginfo_rss('home'); ?>" /> <link rel="self" type="application/atom+xml" href="<?php bloginfo_rss('comments_atom_url'); ?>" /> <id><?php bloginfo_rss('comments_atom_url'); ?></id> <?php } ?>