if ( isUserLoggedIn() ) nocache_headers();
$site_start = $modx->config['site_start'];
switch ($modx->documentObject['id']) {
case $site_start: // ドキュメント以外にカウンタ、最新情報などを含むページ
case 2: // ブログ一覧が更新できないんだよ~~っ
$modx_last_modified = $modx->runSnippet('Ditto', array( 'parents'=>'0','display'=>'1', 'tpl'=>'@CODE:[+editedon+]','orderBy'=>'editedon DESC') );
$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
$client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0;
if ( ($client_last_modified) ? ($client_modified_timestamp >= $modx_last_modified) : 0 ) {
header("HTTP/1.1 304 Not Modified");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
exit;
}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate('r', $modx_last_modified) . " GMT");
break;
case 11: // RSS のページは常に 200 OK ETag は単なる飾りではない
$modx_last_modified = $modx->runSnippet('Ditto', array( 'parents'=>'2','display'=>'1', 'tpl'=>'@CODE:[+editedon+]','orderBy'=>'editedon DESC') );
$etag = '"' . md5($modx_last_modified) . '"';
header("Last-Modified: " . gmdate('r', $modx_last_modified) . " GMT");
header("ETag: $etag");
break;
default: // ドキュメント自身が最終更新日となるページ
$modx_last_modified = $modx->documentObject["editedon"];
// $modx_last_modified = $modx->runSnippet('Ditto', array( 'parents'=>'0','display'=>'1', 'tpl'=>'@CODE:[+editedon+]','orderBy'=>'editedon DESC') );
$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
$client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0;
if ( ($client_last_modified) ? ($client_modified_timestamp >= $modx_last_modified) : 0 ) {
header("HTTP/1.1 304 Not Modified");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
exit;
}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate('r', $modx_last_modified) . " GMT");
}
function isUserLoggedIn() {
global $modx;
$userdetails= array ();
if ($modx->isFrontend() && isset ($_SESSION['webValidated'])) {
// web user
$userdetails['loggedIn']= true;
$userdetails['id']= $_SESSION['webInternalKey'];
$userdetails['username']= $_SESSION['webShortname'];
$userdetails['usertype']= 'web'; // added by Raymond
return $userdetails;
}
if ($modx->isBackend() && isset ($_SESSION['mgrValidated'])) {
// manager user
$userdetails['loggedIn']= true;
$userdetails['id']= $_SESSION['mgrInternalKey'];
$userdetails['username']= $_SESSION['mgrShortname'];
$userdetails['usertype']= 'manager'; // added by Raymond
return $userdetails;
}
return false;
}
function nocache_headers() {
header ("content-type: text/html");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}case $site_start: // ドキュメント以外にカウンタ、最新情報などを含むページ実際のサンプルサイトの例ではすべてのページに news などが含まれているためこちらを default の処理にするのが正しいと思います。
case 2: // ブログ一覧が更新できないんだよ~~っ
$modx_last_modified = $modx->runSnippet(’Ditto’,
array (
’parents’ => ’0’,
’depth’ => ’2’,
’display’ => ’1’,
’tpl’ => ’@CODE:[+editedon+]’,
’orderBy’ => ’editedon DESC’)
);


if ( isUserLoggedIn() ) return; // ログイン中は Last-Modified を出力しない
$isBlog = array(2); // ブログ対象のドキュメントID 配列(複数の場合は array(2,55,77) のように追加
$docId = $modx->documentObject['id']; // 現在のドキュメントID
$parent = $modx->documentObject['parent']; // 親のドキュメントID
if (in_array($docId,$isBlog)) return; // blog 一覧ではコメント数カウントのため Last-Modified を出力しない
if (in_array($parent,$isBlog)) return; // blog 記事の場合はコメント表示更新のため Last-Modified を出力しない
$site_start = $modx->config['site_start'];
switch ($docId) {
case $site_start: // ドキュメント以外にカウンタ、最新情報などを含むページ
$modx_last_modified = $modx->runSnippet('Ditto', array( 'parents'=>'0', 'depth'=>'2', 'display'=>'1', 'tpl'=>'@CODE:[+editedon+]', 'orderBy'=>'editedon DESC') );
$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
$client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0;
if ( ($client_last_modified) ? ($client_modified_timestamp >= $modx_last_modified) : 0 ) {
header("HTTP/1.1 304 Not Modified");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
exit;
}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate('r', $modx_last_modified) . " GMT");
break;
case 11: // RSS のページは常に 200 OK ETag は単なる飾りではない
$modx_last_modified = $modx->runSnippet('Ditto', array( 'parents'=>'2','display'=>'1', 'tpl'=>'@CODE:[+editedon+]','orderBy'=>'editedon DESC') );
$etag = '"' . md5($modx_last_modified) . '"';
header("Last-Modified: " . gmdate('r', $modx_last_modified) . " GMT");
header("ETag: $etag");
break;
default: // ドキュメント自身が最終更新日となるページ
$modx_last_modified = $modx->documentObject["editedon"];
$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
$client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0;
if ( ($client_last_modified) ? ($client_modified_timestamp >= $modx_last_modified) : 0 ) {
header("HTTP/1.1 304 Not Modified");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
exit;
}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate('r', $modx_last_modified) . " GMT");
}
function isUserLoggedIn() {
global $modx;
$userdetails= array ();
if ($modx->isFrontend() && isset ($_SESSION['webValidated'])) {
// web user
$userdetails['loggedIn']= true;
$userdetails['id']= $_SESSION['webInternalKey'];
$userdetails['username']= $_SESSION['webShortname'];
$userdetails['usertype']= 'web'; // added by Raymond
return $userdetails;
}
if ($modx->isFrontend() && isset ($_SESSION['mgrValidated'])) {
// manager user
$userdetails['loggedIn']= true;
$userdetails['id']= $_SESSION['mgrInternalKey'];
$userdetails['username']= $_SESSION['mgrShortname'];
$userdetails['usertype']= 'manager'; // added by Raymond
return $userdetails;
}
return false;
}
if ( isUserLoggedIn() ) return; // ログイン中は Last-Modified を出力しない
$isBlog = array(2); // ブログ対象のドキュメントID 配列
$docId = $modx->documentObject['id']; // 現在のドキュメントID
$parent = $modx->documentObject['parent']; // 親のドキュメントID
if (in_array($docId,$isBlog)) return; // blog 一覧では Last-Modified を出力しない
// if (in_array($parent,$isBlog)) return; // blog 記事の場合は Last-Modified を出力しない
$site_start = $modx->config['site_start'];
switch ($docId) {
case $site_start: // ドキュメント以外にカウンタ、最新情報などを含むページ
case 2:
// $modx_last_modified = $modx->runSnippet('Ditto', array( 'parents'=>'0', 'depth'=>'2', 'display'=>'1', 'tpl'=>'@CODE:[+editedon+]', 'orderBy'=>'editedon DESC') );
$modx_last_modified = getLastModified('modx_site_content');
$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
$client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0;
if ( ($client_last_modified) ? ($client_modified_timestamp >= $modx_last_modified) : 0 ) {
header("HTTP/1.1 304 Not Modified");
header("Expires: Mon, 26 Jul 1997 05:00:01 GMT");
exit;
}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate('r', $modx_last_modified) . " GMT");
break;
case 11: // RSS のページは常に 200 OK ETag は単なる飾りではない
$modx_last_modified = $modx->runSnippet('Ditto', array( 'parents'=>'2','display'=>'1', 'tpl'=>'@CODE:[+editedon+]','orderBy'=>'editedon DESC') );
$etag = '"' . md5($modx_last_modified) . '"';
header("Last-Modified: " . gmdate('r', $modx_last_modified) . " GMT");
header("ETag: $etag");
break;
default: // ドキュメント自身が最終更新日となるページ
$modx_last_modified = $modx->documentObject["editedon"];
if (in_array($parent,$isBlog)) {
$comment_last_modified = getLastModified('modx_jot_content');
if ($comment_last_modified > $modx_last_modified) {
$modx_last_modified = $comment_last_modified;
}
}
$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
$client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0;
if ( ($client_last_modified) ? ($client_modified_timestamp >= $modx_last_modified) : 0 ) {
header("HTTP/1.1 304 Not Modified");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
exit;
}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate('r', $modx_last_modified) . " GMT");
}
function getLastModified($table) {
global $modx, $cash_last_modified;
if ( isset($cash_last_modified)) {
$etag = '"' . md5($cash_last_modified) . '"';
header("ETag: $etag"); // メモリキャッシュデバッグ用です
return $cash_last_modified;
}
$sql= "SHOW TABLE STATUS WHERE Name='".$table."'";
$result = $modx->dbQuery($sql);
$tmpRow = $modx->fetchRow($result);
$last_modified = $tmpRow['Update_time'];
$cash_last_modified = strtotime($last_modified);
return $cash_last_modified;
}
function isUserLoggedIn() {
global $modx;
$userdetails= array ();
if ($modx->isFrontend() && isset ($_SESSION['webValidated'])) {
// web user
$userdetails['loggedIn']= true;
$userdetails['id']= $_SESSION['webInternalKey'];
$userdetails['username']= $_SESSION['webShortname'];
$userdetails['usertype']= 'web'; // added by Raymond
return $userdetails;
}
if ($modx->isFrontend() && isset ($_SESSION['mgrValidated'])) {
// manager user
$userdetails['loggedIn']= true;
$userdetails['id']= $_SESSION['mgrInternalKey'];
$userdetails['username']= $_SESSION['mgrShortname'];
$userdetails['usertype']= 'manager'; // added by Raymond
return $userdetails;
}
return false;
}