Exemple #1
0
/**
 * Redirect 304 Not Modified
 *
 * @param string $timestamp
 * @return bool false (not attempted)
 */
function nc_attempt_last_modified_redirect($timestamp)
{
    // system superior object
    $nc_core = nc_Core::get_object();
    // format timestamp as GMT date
    $last_modified = nc_timestamp_to_gmt($timestamp);
    // get apache headers
    $request_headers = apache_request_headers();
    // check headers
    foreach ($request_headers as $key => $value) {
        if (nc_preg_match("/^If-Modified-Since\$/is", $key)) {
            if ($value && strtotime($value) >= strtotime($last_modified)) {
                if ($nc_core->PHP_TYPE != "cgi") {
                    header($_SERVER['SERVER_PROTOCOL'] . " 304 Not Modified");
                } else {
                    header("Status: 304 Not Modified");
                }
                exit;
            }
        }
    }
    // not attempted
    return false;
}
Exemple #2
0
     $file_path = $matches[1] . "/" . $matches[2];
 } else {
     $file_path = $matches[1] . "/";
 }
 $full_file_path = $nc_core->FILES_FOLDER . $file_path . $matches[3];
 if (file_exists($full_file_path)) {
     while (ob_get_level() && @ob_end_clean()) {
     }
     // sic (remove header)
     if ($use_gzip_compression) {
         header("Content-Encoding: ");
     }
     // get filetime
     $file_time = filemtime($full_file_path);
     // format timestamp as GMT date
     $last_modified = nc_timestamp_to_gmt($file_time);
     // check If-Modified-Since and REDIRECT 304, if needed
     nc_attempt_last_modified_redirect($file_time);
     $file_data = $db->get_row("SELECT f.`ID`, f.`Real_Name`, f.`File_Type`, f.`Content_Disposition`, fl.`Format`\n  \t\t         FROM `Filetable` as f, `Field` as `fl`\n  \t\t        WHERE `Virt_Name` = '" . $matches[3] . "'\n                AND `File_Path` = '/" . $file_path . "'\n                AND fl.`Field_ID` = f.`Field_ID`\n              LIMIT 1", ARRAY_N);
     if (!empty($file_data)) {
         list($file_id, $real_name, $file_type, $attachment, $format) = $file_data;
         $file_size = @filesize($full_file_path);
         if (!nc_strlen($file_type)) {
             $file_type = "application/octet-stream";
         }
         header($_SERVER['SERVER_PROTOCOL'] . " 200 OK");
         if ($nc_core->PHP_TYPE == "cgi") {
             header("Status: 200 OK");
         }
         header("Last-Modified: " . $last_modified);
         header("Content-type: " . $file_type);
Exemple #3
0
 /**
  * Метод посылает заголовок Last-Modified для текущего раздела
  * В зависимости от ncLastModifiedType заголовок может не посылаться,
  * посылаться текущее время или акутальное
  * Для титульной страницы посылается текущее время
  */
 public function send_lastmodified()
 {
     $current_sub = $this->core->subdivision->get_current();
     $title_sub_id = $this->core->catalogue->get_current('Title_Sub_ID');
     $lm = $this->get_field_name('last_modified');
     $lm_type = $this->get_field_name('last_modified_type');
     if ($current_sub[$lm_type] <= NC_LASTMODIFIED_NONE) {
         return 0;
     }
     $last_mod = false;
     if ($current_sub[$lm_type] == NC_LASTMODIFIED_CURRENT || $current_sub['Subdivision_ID'] == $title_sub_id) {
         $last_mod = time();
     } else {
         if ($current_sub[$lm_type] == NC_LASTMODIFIED_YESTERDAY) {
             $last_mod = time() - 86400;
         } else {
             if ($current_sub[$lm_type] == NC_LASTMODIFIED_HOUR) {
                 $last_mod = time() - 3600;
             } else {
                 if ($current_sub[$lm_type] == NC_LASTMODIFIED_ACTUAL && $current_sub[$lm]) {
                     $last_mod = strtotime($current_sub[$lm]);
                 }
             }
         }
     }
     if ($last_mod) {
         header("Last-Modified: " . nc_timestamp_to_gmt($last_mod));
     }
 }