Ejemplo n.º 1
0
function cache_check_messages()
{
    if (!($db = db::get())) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!cache_check_enabled()) {
        return false;
    }
    if (browser_check(BROWSER_AOL)) {
        return false;
    }
    if (headers_sent()) {
        return false;
    }
    // Disable cache on these URL queries.
    if (isset($_GET['delete_success'])) {
        return false;
    }
    if (isset($_GET['edit_success'])) {
        return false;
    }
    if (isset($_GET['font_resize'])) {
        return false;
    }
    if (isset($_GET['markasread'])) {
        return false;
    }
    if (isset($_GET['post_approve_success'])) {
        return false;
    }
    if (isset($_GET['relupdated'])) {
        return false;
    }
    if (isset($_GET['setinterest'])) {
        return false;
    }
    if (isset($_GET['setstats'])) {
        return false;
    }
    if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
        cache_disable();
        return false;
    }
    if (isset($_GET['msg']) && validate_msg($_GET['msg'])) {
        list($tid) = explode('.', $_GET['msg']);
        $sql = "SELECT * FROM (SELECT UNIX_TIMESTAMP(MAX(POST.CREATED)) AS CREATED, ";
        $sql .= "UNIX_TIMESTAMP(MAX(POST.VIEWED)) AS VIEWED, UNIX_TIMESTAMP(MAX(POST.APPROVED)) AS APPROVED, ";
        $sql .= "UNIX_TIMESTAMP(MAX(POST.EDITED)) AS EDITED FROM `{$table_prefix}POST` POST ";
        $sql .= "WHERE POST.TID = '{$tid}') AS POST_DATA, (SELECT UNIX_TIMESTAMP(MAX(USER_POLL_VOTES.VOTED)) ";
        $sql .= "AS POLL_VOTE FROM `{$table_prefix}USER_POLL_VOTES` USER_POLL_VOTES ";
        $sql .= "WHERE USER_POLL_VOTES.TID = '{$tid}') AS POLL_DATA";
    } else {
        $sql = "SELECT UNIX_TIMESTAMP(MAX(CREATED)) AS CREATED, ";
        $sql .= "0 AS VIEWED, 0 AS APPROVED, 0 AS EDITED, 0 AS POLL_VOTE ";
        $sql .= "FROM `{$table_prefix}POST`";
    }
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return true;
    }
    // Get the two modified dates from the query
    list($created, $viewed, $approved, $edited, $voted) = $result->fetch_row();
    // Work out which one is newer (higher).
    $local_cache_date = max($created, $viewed, $approved, $edited, $voted);
    // Last Modified Header for cache control
    $local_last_modified = gmdate("D, d M Y H:i:s", $local_cache_date) . " GMT";
    $local_cache_expires = gmdate("D, d M Y H:i:s", $local_cache_date) . " GMT";
    if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strlen(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) > 0) {
        $remote_last_modified = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
        if (strtotime($remote_last_modified) >= $local_cache_date) {
            header("Expires: {$local_cache_expires}", true);
            header("Last-Modified: {$remote_last_modified}", true);
            header('Cache-Control: private, must-revalidate', true);
            header_status(304, 'Not Modified');
            exit;
        }
    }
    header("Expires: {$local_cache_expires}", true);
    header("Last-Modified: {$local_last_modified}", true);
    header('Cache-Control: private, must-revalidate', true);
    return true;
}
Ejemplo n.º 2
0
function cache_check_messages()
{
    if (!($db = db::get())) {
        return false;
    }
    if (!($table_prefix = get_table_prefix())) {
        return false;
    }
    if (!cache_check_enabled()) {
        return false;
    }
    if (browser_check(BROWSER_AOL)) {
        return false;
    }
    if (headers_sent()) {
        return false;
    }
    if (isset($_GET['post_success'])) {
        return false;
    }
    if (isset($_GET['delete_success'])) {
        return false;
    }
    if (isset($_GET['edit_success'])) {
        return false;
    }
    if (isset($_GET['font_resize'])) {
        return false;
    }
    if (isset($_GET['markasread'])) {
        return false;
    }
    if (isset($_GET['post_approve_success'])) {
        return false;
    }
    if (isset($_GET['relupdated'])) {
        return false;
    }
    if (isset($_GET['setinterest'])) {
        return false;
    }
    if (isset($_GET['setstats'])) {
        return false;
    }
    if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
        cache_disable();
        return false;
    }
    if (isset($_GET['msg']) && validate_msg($_GET['msg'])) {
        list($tid) = explode('.', $_GET['msg']);
        $sql = "SELECT * FROM (SELECT UNIX_TIMESTAMP(MAX(POST.CREATED)) AS CREATED, ";
        $sql .= "UNIX_TIMESTAMP(MAX(POST_RECIPIENT.VIEWED)) AS VIEWED, UNIX_TIMESTAMP(MAX(POST.APPROVED)) AS APPROVED, ";
        $sql .= "UNIX_TIMESTAMP(MAX(POST.EDITED)) AS EDITED FROM `{$table_prefix}POST` POST ";
        $sql .= "LEFT JOIN `{$table_prefix}POST_RECIPIENT` POST_RECIPIENT ";
        $sql .= "ON (POST_RECIPIENT.TID = POST.TID AND POST_RECIPIENT.PID = POST.PID) ";
        $sql .= "WHERE POST.TID = '{$tid}') AS POST_DATA, (SELECT UNIX_TIMESTAMP(MAX(USER_POLL_VOTES.VOTED)) ";
        $sql .= "AS POLL_VOTE FROM `{$table_prefix}USER_POLL_VOTES` USER_POLL_VOTES ";
        $sql .= "WHERE USER_POLL_VOTES.TID = '{$tid}') AS POLL_DATA";
    } else {
        $sql = "SELECT UNIX_TIMESTAMP(MAX(CREATED)) AS CREATED, ";
        $sql .= "0 AS VIEWED, 0 AS APPROVED, 0 AS EDITED, 0 AS POLL_VOTE ";
        $sql .= "FROM `{$table_prefix}POST`";
    }
    if (!($result = $db->query($sql))) {
        return false;
    }
    if ($result->num_rows == 0) {
        return true;
    }
    list($created, $viewed, $approved, $edited, $voted) = $result->fetch_row();
    $last_modified = max($created, $viewed, $approved, $edited, $voted);
    $etag = md5($_SESSION['UID'] . $_SESSION['LOGON']);
    return cache_check_last_modified($last_modified, $etag);
}