예제 #1
0
/**
 * Sets the headers to prevent caching for the different browsers.
 *
 * Different browsers support different nocache headers, so several headers must
 * be sent so that all of them get the point that no caching should occur.
 *
 * @since 2.0.0
 * @uses nxt_get_nocache_headers()
 */
function nocache_headers()
{
    $headers = nxt_get_nocache_headers();
    foreach ($headers as $name => $field_value) {
        @header("{$name}: {$field_value}");
    }
}
예제 #2
0
 /**
  * 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, nxt_get_nocache_headers());
     }
     if (!empty($this->query_vars['error']) && '404' == $this->query_vars['error']) {
         $status = 404;
         if (!is_user_logged_in()) {
             $headers = array_merge($headers, nxt_get_nocache_headers());
         }
         $headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
     } 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 nxt 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']))) {
                 $nxt_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0) . ' GMT';
             } else {
                 $nxt_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0) . ' GMT';
             }
             $nxt_etag = '"' . md5($nxt_last_modified) . '"';
             $headers['Last-Modified'] = $nxt_last_modified;
             $headers['ETag'] = $nxt_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...
             $nxt_modified_timestamp = strtotime($nxt_last_modified);
             if ($client_last_modified && $client_etag ? $client_modified_timestamp >= $nxt_modified_timestamp && $client_etag == $nxt_etag : $client_modified_timestamp >= $nxt_modified_timestamp || $client_etag == $nxt_etag) {
                 $status = 304;
                 $exit_required = true;
             }
         }
     }
     $headers = apply_filters('nxt_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));
 }