0) $file["category_dir"] .= "/";
header( "HTTP/1.1 301 Moved Permanently" );
header ("Location: ".$config["SITE_URL"].$file["category_dir"].$file["file_name"]);
exit();
}
// 拡張子が該当しなければエラー
if (!preg_match('/\.html$/', $file["file_name"]) && $file["file_name"] != "index.rdf" && $file["file_name"] != "rss.xml") {
bossDispError("お探しのページは存在しません。");
}
$_GET["q"] = mb_convert_encoding($file["file_name"], "SJIS" , $OUTPUT_ENCODE);
// ファイル情報取得
list ($file["file_basename"], $file["file_extension"]) = explode('.', $file["file_name"]);
// アンダーバー+数字があればページを取得
$page_exists = false;
if (preg_match('/.+_[0-9]+$/', $file["file_basename"])) {
list ($file["file_basename"], $file["page"]) = explode('_', $file["file_basename"]);
$page_exists = true;
}
$page = intval($file["page"]);
if ($page == 0) {
$page = 1;
}
// RSS1.0
if ($file["file_name"] == "index.rdf") {
// RSS表示
include "./rss10.php";
exit();
}
// RSS2.0
if ($file["file_name"] == "rss.xml") {
// RSS表示
include "./rss20.php";
exit();
}
// DBと照合してなければエラー
$in_category = false;
$content_type = "";
$param = array();
if (strlen($file["category_dir"]) == 0 && (strlen($file["file_basename"]) == 0 || $file["file_basename"] == "index")) {
// TOPページ
$content_type = "top";
$param["title"] = $config["SITE_TITLE"];
$param["site_title"] = $config["SITE_TITLE"];
$param["keywords"] = $config["SITE_KEYWORDS"];
$param["description"] = $config["SITE_DESCRIPTION"];
$param["content"] = $config["TOP_TEXT"];
$param["auto_br"] = $config["TOP_AUTO_BR"];
$param["url"] = $config["SITE_URL"];
$param["site_url"] = $config["SITE_URL"];
$param["category_id"] = 0;
$param["category_name"] = "";
$param["category_dir"] = "";
$param["template"] = "TEMP_TOP";
$param["fb_app_id"] = $config["FB_APP_ID"];
} else if (strlen($file["category_dir"]) == 0 && strlen($file["file_basename"]) > 0 && $file["file_basename"] != "index") {
// カテゴリなしページ
$content_type = "entry";
$sql = "select * from ".DB_PREFIX."entry where entry_category_id = 0 and entry_status = 1 and entry_basename = '".urlencode($file["file_basename"])."' and entry_created_on < datetime('now', 'localtime') ";
$data = bossDbGetRow($sql);
if (!empty($data)) {
$param["entry_id"] = $data["entry_id"];
$param["entry_allow_comments"] = $data["entry_allow_comments"];
// $param["title"] = decode($data["entry_title"]);
list($param["title"], $param["sub_title"]) = explode(DELIMITER, decode($data["entry_title"]));
if (empty($param["sub_title"])) $param["sub_title"] = $param["title"];
$param["site_title"] = $config["SITE_TITLE"];
$param["keywords"] = decode($data["entry_keywords"]);
$param["description"] = decode($data["entry_description"]);
$entry_day = substr($data["entry_modified_on"], 0, strpos($data["entry_modified_on"] , " "));
list($year, $month, $day) = explode("-", $entry_day);
$param["entry_day"] = $year . "年" . $month . "月" . $day . "日";
$param["entry_date"] = $param["entry_day"];
$param["entry_datetime"] = $data["entry_modified_on"];
$param["content"] = decode($data["entry_text"]);
$param["content_mobile"] = explode("", $param["content"]);
$param["mobile_page"] = count($param["content_mobile"]);
$param["comment_count"] = $data["entry_comment_count"];
$param["auto_br"] = $data["entry_auto_br"];
$param["url"] = $config["SITE_URL"] . urlencode($file["file_basename"]) . ".html";
$param["site_url"] = $config["SITE_URL"];
$param["category_id"] = 0;
$param["category_name"] = "";
$param["category_dir"] = "";
$param["template"] = "TEMP_ENT";
$param["fb_app_id"] = $config["FB_APP_ID"];
}
} else if (strlen($file["category_dir"]) > 0 && (strlen($file["file_basename"]) == 0 || $file["file_basename"] == "index")) {
// カテゴリTOP
$in_category = true;
$content_type = "category";
if ($file["category_dir"] == "search") {
$where = '';
if (strlen($_GET['q']) > 0) {
$where .= " and (
entry_text like '%".encode($_GET["q"])."%' or
entry_title like '%".encode($_GET["q"])."%' or
entry_keywords like '%".encode($_GET["q"])."%' or
entry_description like '%".encode($_GET["q"])."%'
) ";
$sql = "select count(entry_id) as cnt from ".DB_PREFIX."entry where entry_status = 1 and entry_created_on < datetime('now', 'localtime') $where ";
$param["entry_count"] = intval(bossDbGetOne($sql));
if ($param["entry_count"] > 0) {
$param["content"] = "";
} else {
$param["content"] = "・該当する結果はありませんでした";
}
} else {
$param["content"] = "・該当する結果はありませんでした";
$param["entry_count"] = 0;
}
$param["category_id"] = 0;
$param["title"] = "サイト内検索の結果";
$param["site_title"] = $config["SITE_TITLE"];
$param["keywords"] = "サイト内,検索";
$param["description"] = "サイト内検索の結果を表示します";
$param["auto_br"] = 0;
$param["url"] = $config["SITE_URL"] . "search/";
$param["site_url"] = $config["SITE_URL"];
$param["category_id"] = 0;
$param["category_name"] = "サイト内検索の結果";
$param["category_dir"] = "search";
$param["template"] = "TEMP_CAT";
$param["fb_app_id"] = $config["FB_APP_ID"];
} else {
$data = dbGetCategoryFromCategoryDir(urlencode($file["category_dir"]));
if (!empty($data)) {
$param["category_id"] = $data["category_id"];
//$param["title"] = decode($data["category_name"]);
list($param["title"], $param["sub_title"]) = explode(DELIMITER, decode($data["category_name"]));
if (empty($param["sub_title"])) $param["sub_title"] = $param["title"];
$param["site_title"] = $config["SITE_TITLE"];
$param["keywords"] = decode($data["category_keywords"]);
$param["description"] = decode($data["category_description"]);
$param["content"] = decode($data["category_text"]);
$param["entry_count"] = $data["category_entry_count"];
$param["auto_br"] = $data["category_auto_br"];
$param["url"] = $config["SITE_URL"] .urlencode($file["category_dir"]) . "/";
$param["site_url"] = $config["SITE_URL"];
$param["category_id"] = $data["category_id"];
list($param["category_name"], $param["sub_category_name"]) = explode(DELIMITER, decode($data["category_name"]));
if (empty($param["sub_category_name"])) $param["sub_category_name"] = $param["category_name"];
//$param["category_name"] = decode($data["category_name"]);
$param["category_dir"] = decode($data["category_dir"]);
$param["template"] = "TEMP_CAT";
$param["fb_app_id"] = $config["FB_APP_ID"];
}
}
} else if (strlen($file["category_dir"]) > 0 && strlen($file["file_basename"]) > 0 && $file["file_basename"] != "index") {
// カテゴリ子ページ
$in_category = true;
$content_type = "entry";
$category = dbGetCategoryFromCategoryDir(urlencode($file["category_dir"]));
if (!empty($category)) {
$sql = "select * from ".DB_PREFIX."entry where entry_category_id = ".$category["category_id"]." and entry_status = 1 and entry_basename = '".urlencode($file["file_basename"])."' and entry_created_on < datetime('now', 'localtime') ";
$data = array();
$data = bossDbGetRow($sql);
if (!empty($data)) {
$param["entry_id"] = $data["entry_id"];
$param["entry_allow_comments"] = $data["entry_allow_comments"];
//$param["title"] = decode($data["entry_title"]);
list($param["title"], $param["sub_title"]) = explode(DELIMITER, decode($data["entry_title"]));
if (empty($param["sub_title"])) $param["sub_title"] = $param["title"];
$param["site_title"] = $config["SITE_TITLE"];
$param["keywords"] = decode($data["entry_keywords"]);
$param["description"] = decode($data["entry_description"]);
$entry_day = substr($data["entry_modified_on"], 0, strpos($data["entry_modified_on"] , " "));
list($year, $month, $day) = explode("-", $entry_day);
$param["entry_day"] = $year . "年" . $month . "月" . $day . "日";
$param["entry_date"] = $param["entry_day"];
$param["entry_datetime"] = $data["entry_modified_on"];
$param["content"] = decode($data["entry_text"]);
$param["content_mobile"] = explode("", $param["content"]);
$param["mobile_page"] = count($param["content_mobile"]);
$param["comment_count"] = $data["entry_comment_count"];
$param["auto_br"] = $data["entry_auto_br"];
$param["url"] = $config["SITE_URL"] .urlencode($file["category_dir"]) . "/" . urlencode($file["file_basename"]) . ".html";
$param["site_url"] = $config["SITE_URL"];
$param["category_id"] = $category["category_id"];
list($param["category_name"], $param["sub_category_name"]) = explode(DELIMITER, decode($category["category_name"]));
if (empty($param["sub_category_name"])) $param["sub_category_name"] = $param["category_name"];
//$param["category_name"] = decode($category["category_name"]);
$param["category_dir"] = $category["category_dir"];
$param["template"] = "TEMP_ENT";
$param["fb_app_id"] = $config["FB_APP_ID"];
$param["entry_related_keyword"] = decode($data["entry_related_keyword"]);
}
}
}
// 携帯サイトのページング
if ($content_type == "entry" ) {
// 携帯以外のアクセスでページがある場合
if (CARRIER_BY_USERAGENT != MOBILE_PHONE && $page_exists) {
header ("Location: ".$param["url"]."\n");
exit();
}
// 携帯からのアクセス
if (CARRIER_BY_USERAGENT == MOBILE_PHONE) {
// 改ページがなくページがある場合
if ($param["mobile_page"] == 0 && $page_exists) {
header ("Location: ".$param["url"]."\n");
exit();
}
// 改ページがあり、ページがある場合
if ($param["mobile_page"] > 0) {
if ($page_exists) {
// 改ページ数よりページ数が多い場合
if ($param["mobile_page"] < $page) {
header ("Location: ".$param["url"]."\n");
exit();
} else {
// 改ページ数がページ数以内(正常)
$param["content"] = $param["content_mobile"][$page - 1];
}
} else {
// 改ページがあり、ページがない場合(正常)
$param["content"] = $param["content_mobile"][0];
}
}
}
}
//人気記事アクセスログ
$now = bossDbGetNow();
$today = substr($now, 0, 10);
$yesterday = date('Y-m-d', strtotime($now) - (60*60*24));
$tomorrow = date('Y-m-d', strtotime($now) + (60*60*24));
if ($content_type == "entry" && !isRobot()) {
if (strlen($_SERVER['REMOTE_ADDR']) > 0) {
$sql = "SELECT ipcache_data_id FROM ".DB_PREFIX."ipcache WHERE ipcache_ip = '".$_SERVER['REMOTE_ADDR']."' AND ipcache_data_id = '".$param["entry_id"]."' AND ipcache_day_no_time = '{$today}'";
$res = bossDbGetOne($sql);
if ($res != $param["entry_id"]) {
// IP書き込み
$sql = "INSERT INTO ".DB_PREFIX."ipcache
(
ipcache_ip,
ipcache_data_id,
ipcache_day_no_time
) VALUES (
'".$_SERVER['REMOTE_ADDR']."',
'".$param["entry_id"]."',
'{$today}'
)";
bossDbQuery($sql);
// 人気ランキングデータ
$sql ="INSERT OR IGNORE INTO ".DB_PREFIX."ppdatecache
(
ppdatecache_id,
ppdatecache_day,
ppdatecache_day_no_time,
ppdatecache_pageviews
) VALUES (
'".$param["entry_id"]."',
'".$now."',
'".$today."',
'0'
)";
bossDbQuery($sql);
$sql = "UPDATE
".DB_PREFIX."ppdatecache
SET
ppdatecache_day = '{$now}',
ppdatecache_pageviews = ppdatecache_pageviews + 1
WHERE
ppdatecache_id = '".$param["entry_id"]."' AND ppdatecache_day_no_time = '{$today}'";
bossDbQuery($sql);
}
}
}
if (empty($param)) {
$content_type = "none";
$param["title"] = $config["SITE_TITLE"];
$param["site_title"] = $config["SITE_TITLE"];
$param["keywords"] = $config["SITE_KEYWORDS"];
$param["description"] = $config["SITE_DESCRIPTION"];
$param["content"] = "この記事は削除されているか、または未来の公開予定記事のため表示できません。";
$param["auto_br"] = $config["TOP_AUTO_BR"];
$param["url"] = $config["SITE_URL"];
$param["site_url"] = $config["SITE_URL"];
$param["category_id"] = 0;
$param["category_name"] = "";
$param["category_dir"] = "";
if ($in_category) {
$param["template"] = "TEMP_CAT";
} else {
$param["template"] = "TEMP_TOP";
}
}
// 広告非表示
$ad_none = false;
if (strpos($param["content"], "") !== false ) {
$ad_none = true;
}
if (empty($config["PRINT_TYPE"])) {
$config["PRINT_TYPE"] = "pcspmo";
}
$print_type["pc"] = substr($config["PRINT_TYPE"],0,2);
$print_type["sp"] = substr($config["PRINT_TYPE"],2,2);
$print_type["mo"] = substr($config["PRINT_TYPE"],4,2);
// テンプレート呼出
$view_is_smart_phone = false;
$smart_phone = bossGetCookie("smart_phone");
if (CARRIER_BY_USERAGENT == PC || (CARRIER_BY_USERAGENT == SMART_PHONE && $smart_phone == PC) || (CARRIER_BY_USERAGENT == SMART_PHONE && $print_type["sp"] == "pc")) { // PCサイト
$html = $config[PC."_".$param["template"]];
if (CARRIER_BY_USERAGENT == SMART_PHONE && $print_type["sp"] != "pc") {
$html = preg_replace('/<(\/CSM2|CSM2)SmartPhone>/i', '', $html);
} else {
$html = cutTagSpan($html, "CSM2SmartPhone");
}
$viewer = PC;
if (!$ad_none) {
if (CARRIER_BY_USERAGENT == SMART_PHONE) {
$ad = AdRand(SMART_PHONE);
} else {
$ad = AdRand(PC);
}
//var_dump($ad);
foreach ($ad as $k => $v) {
if (strlen($v[0]["ad_text"]) > 0) {
if ($k == "AD_DISPLAY_FIXED") {
$html = str_ireplace("", '
'.decode($v[0]["ad_text"]).'
', $html);
} else {
$html = str_ireplace("", ''.decode($v[0]["ad_text"]).'
', $html);
}
} else {
$html = str_ireplace("", "", $html);
}
}
}
$html = str_ireplace("", $config["COMMENT_SRC"], $html);
$html = str_ireplace("", $config["ACCESS_PC"], $html);
} else if (CARRIER_BY_USERAGENT == SMART_PHONE) { // スマートフォン
$view_is_smart_phone = true;
$html = $config[SMART_PHONE."_".$param["template"]];
$viewer = SMART_PHONE;
if (!$ad_none) {
$ad = AdRand(SMART_PHONE);
foreach ($ad as $k => $v) {
if (strlen($v[0]["ad_text"]) > 0) {
if ($k == "AD_DISPLAY_FIXED") {
$html = str_ireplace("", ''.decode($v[0]["ad_text"]).'
', $html);
} else {
$html = str_ireplace("", ''.decode($v[0]["ad_text"]).'
', $html);
}
} else {
$html = str_ireplace("", "", $html);
}
}
}
$html = str_ireplace("", $config["ACCESS_PC"], $html);
$html = str_ireplace("", $config["COMMENT_SRC"], $html);
} else { // 携帯
$html = $config[MOBILE_PHONE."_".$param["template"]];
$viewer = MOBILE_PHONE;
if (!$ad_none) {
$ad = AdRand(MOBILE_PHONE);
foreach ($ad as $k => $v) {
if (strlen($v[0]["ad_text"]) > 0) {
$html = str_ireplace("", ''.decode($v[0]["ad_text"]).'
', $html);
} else {
$html = str_ireplace("", "", $html);
}
}
}
$html = str_ireplace("", $config["COMMENT_SRC"], $html);
$html = str_ireplace("", $config["ACCESS_MOBILE"], $html);
}
$k = NULL;
$v = NULL;
// スマートフォン用デバッグ
//$html = $config[SMART_PHONE."_".$param["template"]];
// 携帯用デバッグ
//$html = $config[MOBILE_PHONE."_".$param["template"]];
//// カテゴリリスト作成
//$html = makeCategoryList($html);
//// 新着エントリーリスト作成
//$html = makeNewEntryList($html);
//// 人気記事リスト作成
//$html = makePopularEntryList($html);
//// 新着コメントリスト作成
//$html = makeNewCommentList($html);
//
//// 前処理
//if ($in_category) {
// $html = preg_replace('/<(\/CSM2|CSM2)InCategory>/i', '', $html);
//} else {
// $html = cutTagSpan($html, "CSM2InCategory");
//}
if ($content_type == "entry") {
// ページング
// コメントリスト作成
if ($param["comment_count"] > 0 && $page == 1) {
$html = preg_replace('/<(\/CSM2|CSM2)CommentExists>/i', '', $html);
} else {
$html = cutTagSpan($html, "CSM2CommentExists");
}
$html = makeEntryNaviLink($html, $param["entry_id"], $view_is_smart_phone);
$html = makeRelatedArticleList($html, $param["entry_id"], $param["category_id"], $param["entry_related_keyword"]);
$html = makeCommentList($html, $param["entry_id"]);
if ($param["entry_allow_comments"] == 1 && $config["COMMENT_STOP"] != 1) {
$html = preg_replace('/<(\/CSM2|CSM2)Comment>/i', '', $html);
} else {
$html = cutTagSpan($html, "CSM2Comment");
}
} else if ($content_type == "category"){
// ページング
// 記事リスト作成
if ($param["entry_count"] > 0) {
$html = preg_replace('/<(\/CSM2|CSM2)EntryExists>/i', '', $html);
} else {
$html = cutTagSpan($html, "CSM2EntryExists");
}
$html = preg_replace('/<\$PAGE\$>/i', $page, $html);
$html = makeCategoryNaviLink($html, $param["category_id"], $page, $view_is_smart_phone);
$html = makeEntryList($html, $param["category_id"], $page);
} else if ($content_type == "none") {
$html = cutTagSpan($html, "CSM2EntryExists");
$html = cutTagSpan($html, "CSM2CommentExists");
}
// 自動改行
if ($param["auto_br"] == 1) {
$param["content"] = nl2br($param["content"]);
}
$html = preg_replace('/<\$CONTENT\$>/i', $param["content"], $html);
unset($param["content"]);
if (file_exists("myproc2.php")) {
require_once 'myproc2.php';
}
// カテゴリリスト作成
$html = makeCategoryList($html);
// 新着エントリーリスト作成
$html = makeNewEntryList($html);
// 人気記事リスト作成
$html = makePopularEntryList($html);
// 新着コメントリスト作成
$html = makeNewCommentList($html);
// 前処理
if ($in_category) {
$html = preg_replace('/<(\/CSM2|CSM2)InCategory>/i', '', $html);
} else {
$html = cutTagSpan($html, "CSM2InCategory");
}
// 表示ブラウザごとに処理
if (CARRIER_BY_USERAGENT == PC) {
$html = preg_replace('/<(\/pc|pc)>/i', '', $html);
$html = preg_replace('/<(\/opc|opc)>/i', '', $html);
$html = cutTagSpan($html, "mobile");
$html = cutTagSpan($html, "omo");
$html = cutTagSpan($html, "osp");
$html = cutTagSpan($html, "mo");
$html = preg_replace('//i', '', $html);
} else if (CARRIER_BY_USERAGENT == SMART_PHONE) {
$html = preg_replace('/<(\/pc|pc)>/i', '', $html);
$html = preg_replace('/<(\/osp|osp)>/i', '', $html);
$html = preg_replace('/<(\/mo|mo)>/i', '', $html);
$html = cutTagSpan($html, "mobile");
$html = cutTagSpan($html, "omo");
$html = cutTagSpan($html, "opc");
$html = preg_replace('//i', '', $html);
} else if (CARRIER_BY_USERAGENT == MOBILE_PHONE) {
// 画像置換
$html = preg_replace('/img\/usr\/m\/([-_0-9a-zA-Z]+\.)(jpg|jpeg|gif|png)/i', 'img/usr/s/\\1\\2', $html);
$html = preg_replace('/img\/usr\/([-_0-9a-zA-Z]+\.)(jpg|jpeg|gif|png)/i', 'img/usr/m/\\1\\2', $html);
$html = preg_replace('/<(\/mobile|mobile)>/i', '', $html);
$html = preg_replace('/<(\/omo|omo)>/i', '', $html);
$html = preg_replace('/<(\/mo|mo)>/i', '', $html);
$html = cutTagSpan($html, "pc");
$html = cutTagSpan($html, "opc");
$html = cutTagSpan($html, "osp");
// 携帯前後リンク作成
if ($param["mobile_page"] > 0) {
// 前のページ?
if ($page > 2) {
$pos1 = strrpos($param["url"], ".");
$html = str_ireplace("", '', $html);
$html = str_ireplace("", '', $html);
} else if ($page == 2) {
$html = str_ireplace("", '', $html);
$html = str_ireplace("", '', $html);
} else {
$html = cutTagSpan($html, "CSM2EntryBackLink");
}
// 次のページ?
if ($page < $param["mobile_page"]) {
$pos1 = strrpos($param["url"], ".");
$html = str_ireplace("", '', $html);
$html = str_ireplace("", '', $html);
} else {
$html = cutTagSpan($html, "CSM2EntryNextLink");
}
}
}
// 置換
$html = preg_replace('/<\$output_encode\$>/i', $OUTPUT_ENCODE, $html);
foreach ($param as $key => $value) {
$html = preg_replace('/<\$'.$key.'\$>/i', @htmlspecialchars($value, ENT_COMPAT | ENT_HTML401, 'SJIS'), $html);
}
if (file_exists("myproc3.php")) {
require_once 'myproc3.php';
}
// HTML出力
header("Content-Type: text/html; charset=".$OUTPUT_ENCODE."\n");
$filename = writePHPInWorkDir($html, $OUTPUT_ENCODE);
include_once $filename;
unlink($filename);
// 1日1回キャッシュメンテ
if ($config["LAST_ACCESS_DAY"] != $today) {
// 人気記事キャッシュメンテナンス
$sql = "DELETE FROM ".DB_PREFIX."ppdatecache WHERE date(ppdatecache_day) < date('now', '-30 days')";
bossDbQuery($sql);
// IPアドレスキャッシュメンテナンス
$sql = "DELETE FROM ".DB_PREFIX."ipcache WHERE date(ipcache_day_no_time) < date('now')";
bossDbQuery($sql);
setConfig("LAST_ACCESS_DAY", $today);
}
// 一定の確率で
if (rand(0,20) == 0) {
// DB最適化
bossDbVaccum();
// WORKフォルダのクリア
$result = glob(WORK_DIR . "*.php");
if (is_array($result)) {
foreach ($result as $value) {
@unlink($value);
}
}
}
exit();
?>