Created
March 18, 2015 03:32
-
-
Save leevigraham/a20c5bf1784af4d59c23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'articles/details/:url_title' => function (\rsanchez\ResourceRouter\Router $router, $wildcard) { | |
$ee = ee(); | |
$ee->load->helper('date'); | |
$query = $ee->db->select('edit_date') | |
->from('channel_titles') | |
->join('channels', 'channel_titles.channel_id = channels.channel_id') | |
->where('url_title', (string) $wildcard) | |
->where('channel_name', 'articles') | |
->get(); | |
if(!$query->num_rows) { | |
$router->set404(); | |
} else { | |
$ee->config->set_item('send_headers', FALSE); | |
$ifModifiedSinceString = $ee->input->server('HTTP_IF_MODIFIED_SINCE'); | |
$entry = $query->row(); | |
$lastModifiedTimestamp = mysql_to_unix($entry->edit_date); | |
$lastModifiedString = sprintf("%s GMT", gmdate("D, d M Y H:i:s", $lastModifiedTimestamp)); | |
if($lastModifiedString === $ifModifiedSinceString) { | |
header(sprintf('Last-Modified: %s', $lastModifiedString), true, 304); | |
$router->output(false); | |
} else { | |
header(sprintf('Last-Modified: %s', $lastModifiedString), true, 200); | |
$router->setTemplate('articles/read'); | |
} | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment