// Copyright: Copyright (C) 2004-2007 Pristine Communications // Set the include path if (!defined("INCPATH_SET")) { require_once dirname(__FILE__) . "/incpath.inc.php"; } // Referenced subroutines require_once "monica/cgiemu.inc.php"; require_once "monica/getlang.inc.php"; require_once "monica/gettext.inc.php"; require_once "monica/lninfo.inc.php"; require_once "monica/requri.inc.php"; require_once "monica/sql.inc.php"; require_once "monica/sqlconst.inc.php"; // not_modified: Check if we should send "HTTP/1.1 304 Not Modified" function not_modified($tables, $files, $this_file) { // HTTP/1.1 304 only works for GET or HEAD if (!in_array($_SERVER["REQUEST_METHOD"], array("GET", "HEAD"))) { return false; } // Find the last-modified time find_last_modified($tables, $files, $this_file); // If-Modified-Since not supplied. The client had not cached yet. if (!array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER)) { return false; } // Malformed If-Modified-Since value $cachemodf = strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]); if ($cachemodf == -1) { return false; } // We are newer than the cache if ($GLOBALS["LAST_MODIFIED"] > $cachemodf) { return false; } // Yes, use the cache return true; return; } // find_last_modified: Find the last-modified time function find_last_modified($tables, $files, $this_file) { // Checked before if (array_key_exists("LAST_MODIFIED", $GLOBALS)) { return; } // Remove duplicates $tables = array_values(array_unique($tables)); $files = array_values(array_unique($files)); // Start with EPOCH 1970-01-01 00:00:00 $GLOBALS["LAST_MODIFIED"] = 0; global $LAST_MODIFIED; // Check myself updmtime_file($this_file); // Check mtime from the included modules and gettext MO files check_inc(); // Check the supplied data files foreach ($files as $file) { if (file_exists($file)) { updmtime_file($file); } } // Check the supplied data tables updmtime_tables($tables); } // check_inc: Check mtime from the included modules and gettext MO files function check_inc() { // Check the included modules foreach (get_included_files() as $file) { updmtime_file($file); } // Check the header and footer $incdir = DOC_ROOT . "/admin/include"; $files = array(); $files[] = $incdir . "/header." . getlang(LN_FILENAME) . ".html"; $files[] = $incdir . "/footer." . getlang(LN_FILENAME) . ".html"; $files[] = $incdir . "/header.html"; $files[] = $incdir . "/footer.html"; foreach ($files as $file) { if (file_exists($file)) { updmtime_file($file); } } // Check the gettext mo files if (defined("PACKAGE") && is_dir(LOCALEDIR)) { $dh = opendir(LOCALEDIR); while (($ent = readdir($dh)) !== false) { $file = LOCALEDIR . "/$ent/LC_MESSAGES/" . PACKAGE . ".mo"; if (file_exists($file)) { updmtime_file($file); } } closedir($dh); } $dh = opendir(COMMONLOCALEDIR); while (($ent = readdir($dh)) !== false) { $file = COMMONLOCALEDIR . "/$ent/LC_MESSAGES/" . COMMONDOMAIN . ".mo"; if (file_exists($file)) { updmtime_file($file); } } closedir($dh); return; } // updmtime_tables: Update the $LAST_MODIFIED with the mtime of tables function updmtime_tables($tables) { // Only work when using database if ($GLOBALS["SQL_DBTYPE"] == SQL_NONE) { return; } $lastupd = sql_lastupd($tables); if (is_null($lastupd)) { return; } if (!is_numeric($lastupd)) { $lastupd = preg_replace("/\.\d+$/", "", $lastupd); $lastupd = strtotime($lastupd); } settype($lastupd, "integer"); if ($GLOBALS["LAST_MODIFIED"] < $lastupd) { $GLOBALS["LAST_MODIFIED"] = $lastupd; } return; } // updmtime_file: Update the $LAST_MODIFIED with the mtime of a file function updmtime_file($file) { $stat = stat($file); if ($GLOBALS["LAST_MODIFIED"] < $stat[9]) { $GLOBALS["LAST_MODIFIED"] = $stat[9]; } return; } ?>