Advertisement:

Author Topic: Last-Modified Reworking the plug under osclass  (Read 669 times)

monah

  • Full Member
  • ***
  • Posts: 223
Last-Modified Reworking the plug under osclass
« on: May 27, 2015, 08:08:01 pm »
Can anyone make a osclass?
Code: [Select]
add_filter('wp_headers','wpitsprite_headers',10,2);
function wpitsprite_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";

$wpitsprite_timestamp = get_lastpostmodified('GMT')>get_lastcommentmodified('GMT')?get_lastpostmodified('GMT'):get_lastcommentmodified('GMT');
$wp_last_modified = mysql2date('D, d M Y H:i:s', $wpitsprite_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;
}