require_once('phplib/common.php'); require_once('phplib/template.php'); if(isset($_GET['id'])) { $id = addslashes($_GET['id']); if(! preg_match('/^\d+$/', $id)) ShowMsg("$id: 不正確的參數!"); mysql_open(); if(isset($_GET['session']) && sha1((int) $id * 21 + 7) == $_GET['session']) { $sql = "SELECT * FROM `teantertain` WHERE `id`='$id'"; } else { $sql = "SELECT * FROM `teantertain` WHERE `id`='$id' AND `enable`='1'"; } $article = mysql_fetch_one($sql, "$id: 不正確的參數"); if(!$article) { redirect($php_self); } $condition = array(); foreach(explode(',', $article['tag']) as $tag) { $condition[] = "FIND_IN_SET('$tag', `tag`)"; } if(count($condition) > 0) { $sql = "SELECT `id`, `title` FROM `teantertain` WHERE (" . implode(' OR ', $condition) . ") AND `id`!='$id' AND `enable`='1' ORDER BY `popular` DESC, `date` DESC"; $related_article = mysql_fetch_all($sql, '', '', true); shuffle($related_article); $related_article = array_slice($related_article, 0, 3); } else { $related_article = array(); } if(! isset($_COOKIE["teantertain"])) { $_COOKIE["teantertain"] = array(); } else { $_COOKIE["teantertain"] = json_decode($_COOKIE["teantertain"], "true"); } if(! in_array($id, $_COOKIE["teantertain"])) { array_push($_COOKIE["teantertain"], $id); setcookie("teantertain", json_encode($_COOKIE["teantertain"]), time() + 60 * 60); $sql = "UPDATE `teantertain` SET `popular`=`popular`+1 WHERE `id`='$id'"; mysql_query($sql); } mysql_close(); if(preg_match('/teantertain\.php/', @$_SERVER['HTTP_REFERER']) && isset($_SESSION['teantertain']['referer'])) { $referer = $_SESSION['teantertain']['referer']; } else { $referer = $php_self; } $og_title = $article['title']; //if($article['sub_title'] != '') $og_title .= " " . $article['sub_title']; if(isset($_GET['session'])) html_header_nocache(); html_header_1('', array('teantertain.js'), array('teantertain.css'), $og_title, mb_substr(preg_replace('/\n/', '', strip_tags($article['content'])), 0, 200)); ?> html_upstartdna(); html_header_2(array( $php_self => '茶特町', "{$php_self}?id={$id}" => $og_title )); ?>