start(); /* 必要なライブラリファイルの読み込み */ require_once("papersDBinclude.inc"); require_once("rss10.inc"); /* セッションスタート */ session_start(); /* 入力読み取り */ saveLastPage(); saveTransaction('/div-media/papersDB/papers.php'); $isRSS = (isset($_GET['rss']) && is_numeric($_GET['rss']) && $_GET['rss'] == 1) ? true : false; /* * 論文のソート順 (p 発表年月順がデフォルト, u 更新順) */ if (isset($_GET['sb']) && $_GET['sb'] == 'u') { $sortBy = 'u'; } elseif (isset($_GET['sb']) && $_GET['sb'] == 'pa') { $sortBy ='pa'; } else { $sortBy ='pd'; } // ページング 'p' 'n' $pageNum = $_GET['p']; // 現在のページ番号 - 1 if (! is_numeric($pageNum) or $pageNum <= 0) { $pageNum = 0; } $maxPapers = $_GET['n']; // 1ページあたりの論文数 if ($maxPapers != 'all' and (! is_numeric($maxPapers) or $maxPapers > MAX_PAPER_NUM or $maxPapers <= 1)) { $maxPapers = $_COOKIE["n"]; if ($maxPapers != "all" and ($maxPapers == NULL or (! is_numeric($maxPapers)) or $maxPapers <= 0)) { $maxPapers = DEFAULT_PAPER_NUM; } } setcookie("n", $maxPapers, time() + 60 * 60 * 24 * 365); if ($maxPapers != 'all') { $offset = $pageNum * $maxPapers; } else { $offset = ''; } if ($isRSS) { $offset = 0; } // 検索 'q' $q = trim($_GET['q']); if (get_magic_quotes_gpc()) { $q = stripslashes($q); } if (strlen($q) == 1) { addMessage("Search strings must be more than 2 characters."); } // 入力されたタグの読み取り $selectedTags = array('material' => array(), 'method' => array(), 'defect' => array()); // 材料タグ 'material', method タグ 'method', defect タグ 'defect' foreach (array('material', 'method', 'defect') as $tmpKey) { if (! isset($_GET[$tmpKey])) { continue; } $selectedTags[$tmpKey] = preg_split("/[\s]+/", $_GET[$tmpKey], -1, PREG_SPLIT_NO_EMPTY); if (get_magic_quotes_gpc()) { $selectedTags[$tmpKey] = array_map("stripslashes", $selectedTags[$tmpKey]); } } /* タグデータ取得 */ $db = new PapersDB(); if ($db->hasError()) { include("maintenance.view"); exit; } $tagInfo = new TagInfo($db); $tags = $tagInfo->tags; $tagNames = $tagInfo->tagNames; $tagNameList = $tagInfo->tagNameList; $bundles = $tagInfo->bundles; $bundleNames = $tagInfo->bundleNames; $bundleNameList = $tagInfo->bundleNameList; $tagNameListForDefect = $tagInfo->tagNameListForDefect; // 入力されたタグの処理 // DB 中にないタグは削除する $selectedTagIDs = array('material' => array(), 'method' => array(), 'defect' => array()); foreach (array("material", "method", "defect") as $tagSort) { $tmp = array(); foreach ($selectedTags[$tagSort] as $selectedTag) { if ($selectedTag != UNTAGGED_TAG and isset($tagNames[$tagSort][$selectedTag])) { array_push($tmp, $selectedTag); array_push($selectedTagIDs[$tagSort], $tagNames[$tagSort][$selectedTag]); } if ($selectedTag == UNTAGGED_TAG) { array_push($tmp, $selectedTag); array_push($selectedTagIDs[$tagSort], UNTAGGED_TAG_ID); } } $selectedTags[$tagSort] = $tmp; } /* 論文データ取得 */ $paperCount = $db->getPaperCount(); $lastUpdated = $db->getLastUpdatedPaperMtime(); $paperCountByTag = $db->getPaperCountByTag2(); $paperHits = 0; $isSearchResult = false; // 検索結果かどうか if (trim($q) == '') { /* タグによる絞りこみ表示の場合 */ $paperList = $db->getPapersByTagIDs($selectedTagIDs, $offset, $maxPapers, ($isRSS || ($sortBy == 'u')), ($sortBy != 'pa')); $paperHits = $db->count; $allTagStr = trim(join(" ", array(join(" ", $selectedTags["material"]), join(" ", $selectedTags["method"]), join(" ", $selectedTags["defect"])))); if (trim($allTagStr) == "") { $allTagStr = "All papers"; $h1title = "All papers"; $pageTitle = "Papers - " . htmlspecialchars($allTagStr); } else { //$h1title = 'Papers tagged "'. htmlspecialchars($allTagStr) . '"'; $h1title = htmlspecialchars($allTagStr); $pageTitle = "Papers - tagged '" . htmlspecialchars($allTagStr) . "'"; } $subTitle = ""; } else { /* 検索結果表示の場合 */ $isSearchResult = true; $paperList = $db->getPapersByKeyword($q, $offset, $maxPapers); $paperHits = $db->count; $h1title = 'Search results for “' . htmlspecialchars($q) . '”'; $pageTitle = "Papers - Search results for '" . htmlspecialchars($q) . "'"; $subTitle = htmlspecialchars($q); } $pageTitle .= " - " . PAPER_SITE_TITLE; /* ページング用リンク作成 (papersPageGuide.view 用) * * ■入力 * $pageNum = 現在のページ番号 * $maxPapers = ページあたりの論文数 * $paperHits = 全部の論文数 * * ■出力 * $currentGuidePage = 現在のガイドページ = (int)(現在のページ番号 / 10) * * 前のガイドページへのリンク * = 現在のガイドページ番号 - 1 ( <0 の場合 0) * * 1 = 現在のガイドページ * 10 * 2 = 現在のガイドページ * 10 + 1 * 3 = 現在のガイドページ * 10 + 2 * .... * * 次へのリンク 現在のガイドページ + 1 */ if (trim($q) == '') { $pageLinkBase = "papers.php?"; $isFirst = true; foreach (array("material", "method", "defect") as $tagSort) { if ($isFirst) { $isFirst = false; $ampStr = ""; } else { $ampStr = "&"; } $pageLinkBase .= $ampStr . $tagSort . "=" . urlencode(join(" ", $selectedTags[$tagSort])); } } else { $pageLinkBase = "papers.php?q=" . urlencode($q); } $currentGuidePage = (int)(floor($pageNum / 10)); if ($currentGuidePage <= 0) { $prevPageLink = ""; } else { $prevPageLink = $pageLinkBase . "&n=${maxPapers}&p=" . (($currentGuidePage - 1) * 10) . "&sb=" . $sortBy; } if (is_numeric($maxPapers) && (($currentGuidePage + 1) * 10 * $maxPapers) <= $paperHits) { $nextPageLink = $pageLinkBase . "&n=${maxPapers}&p=" . (($currentGuidePage + 1) * 10) . "&sb=" . $sortBy; } else { $nextPageLink = ""; } $pageGuideList = array(); for ($i = 0; is_numeric($maxPapers) && ($i < 10); $i++) { if (($currentGuidePage * 10 + $i) * $maxPapers > $paperHits) { break; } array_push($pageGuideList, array("url" => $pageLinkBase . "&n=${maxPapers}&p=" . ($currentGuidePage * 10 + $i) . "&sb=" . $sortBy, "text" => $currentGuidePage * 10 + $i + 1, "title" => ($currentGuidePage * 10 + $i + 1) . "/" . ($maxPapers == 'all' ? 1 : ((int)($paperHits / $maxPapers)) + 1) . " page", "isLink" => ($pageNum == $currentGuidePage * 10 + $i) ? False : True) ); } $alignPageLink = $pageLinkBase . "&sb=" . $sortBy . "&p=0&n="; $urlRoot = 'http://' . $_SERVER['SERVER_NAME'] . '/div-media/papersDB/'; $rssLink = $pageLinkBase . "&rss=1"; $rssList = array( array('url' => $urlRoot . $rssLink, 'title' => $pageTitle) ); /* 表示 */ if ($isRSS) { // RSSWriter のほうで、勝手に & とエスケープするので、 pageLinkBase の中身をもどす $unEscPageLinkBase = preg_replace('|&|', '&', $pageLinkBase); $rss = new RSSWriter($urlRoot . $unEscPageLinkBase . '&sb=u', $pageTitle, "Papers - " . SITE_TITLE, array("dc:date" => w3cTimeFormat($paperList[0]['m_time']))); $rssItemCounter = 0; foreach ($paperList as $paper) { $rssItemCounter++; if ($rssItemCounter > 25) { break; } $paperBibliography = strip_tags2($paper['journal']) . " "; if (trim($paper['vol']) != "") { $paperBibliography .= strip_tags2($paper['vol']) . ', '; } if (trim($paper['first_page']) != "") { $paperBibliography .= strip_tags2($paper['first_page']) . " "; } $paperBibliography .= (trim($paper['year']) != '' ? ' (' . strip_tags2($paper['year']) . ') ': ''); $paperBibliography .= ((trim($paper['publisher']) != '') ? ', ' . strip_tags2($paper['publisher']) : ''); $rss->addItem($urlRoot . $unEscPageLinkBase . '&sb=u&id=' . $paper['id'] . '#' . $paper['id'], strip_tags2($paper['title']), array("description" => $paperBibliography . ", " . strip_tags2($paper['authors']), "dc:date" => w3cTimeFormat($paper['m_time']))); } header("Content-Type: application/xml; charset=UTF-8"); $rss->serialize(); } else { printPapersHeader($pageTitle, $h1title, array("scriptaculous/effects.js", "scriptaculous/dragdrop.js", "scriptaculous/controls.js", "pdbutil.js", "paper.js"), "", $subTitle, "tags.js", array("tags", "rssList")); include("papers.view"); } ?>