| ... | ... |
@@ -252,7 +252,6 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 252 | 252 |
if(count($otherresults) > 0) $tpl->assign("otherresults", "<div id='otherresults'><span class='label'>"._OTHERRESULTS.":</span> ".implode(", ", $otherresults)."</div>");
|
| 253 | 253 |
} |
| 254 | 254 |
else {
|
| 255 |
- $disablesorts = array( ); |
|
| 256 | 255 |
if($searchtype == "simple") {
|
| 257 | 256 |
$output .= "<div id=\"pagetitle\">"._SIMPLE."</div><div style='text-align: center;'><form method=\"post\" enctype=\"multipart/form-data\" action=\"search.php\"> |
| 258 | 257 |
<div class=\"tblborder\" style=\"width: 320px; padding: 5px; margin: 0 auto;\"> |
| ... | ... |
@@ -325,10 +324,8 @@ else {
|
| 325 | 324 |
<option>1000</option> |
| 326 | 325 |
<option value='-500'>< 500</option> |
| 327 | 326 |
</select><br /><br /><label for=\"searchterm\">"._SEARCHTERM.": </label><INPUT type=\"text\" class=\"textbox\" name=\"searchterm\" id=\"searchterm\" size=\"20\"> |
| 328 |
- "; |
|
| 329 |
- |
|
| 330 |
- if(!in_array("sorts", $disablesorts)) $output .= "<label for=\"sortorder\">"._SORT.":</label> <select class=\"textbox\" name=\"sort\"><option value=\"alpha\"".(!$defaultsort ? " selected" : "").">"._ALPHA."</option><option value=\"update\"".($defaultsort == 1 ? " selected" : "").">"._MOSTRECENT."</option></select>";
|
|
| 331 | 327 |
|
| 328 |
+ <label for=\"sortorder\">"._SORT.":</label> <select name=\"sort\" id=\"sortorder\"><option value=\"alpha\">"._ALPHA."</option><option value=\"update\">"._MOSTRECENT."</option></select>"; |
|
| 332 | 329 |
$codequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'searchform'");
|
| 333 | 330 |
while($code = dbassoc($codequery)) {
|
| 334 | 331 |
eval($code['code_text']); |
| ... | ... |
@@ -263,7 +263,7 @@ else {
|
| 263 | 263 |
if($store == "mysql") |
| 264 | 264 |
$output .= "<option value=\"fulltext\">"._FULLTEXT."</option>"; |
| 265 | 265 |
$output .= "</select> <INPUT type=\"text\" class=\"textbox\" name=\"searchterm\" size=\"20\"> "; |
| 266 |
- $output .= "<INPUT type=\"submit\" class=\"button\" name=\"submit\" value=\""._SUBMIT."\" size=\"20\"> |
|
| 266 |
+ $output .= "<INPUT style=\"margin-top: 0.5em;\" type=\"submit\" class=\"button\" name=\"submit\" value=\""._SUBMIT."\" size=\"20\"> |
|
| 267 | 267 |
<div style=\"font-size: 8pt; text-align: right;\"><a href=\"search.php?searchtype=advanced\">"._ADVANCED."</a></div></div></form></div>"; |
| 268 | 268 |
} |
| 269 | 269 |
else {
|
| ... | ... |
@@ -49,7 +49,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 49 | 49 |
$output .= "<div id=\"pagetitle\">"._RESULTS."</div>"; |
| 50 | 50 |
$query = array(); |
| 51 | 51 |
$countquery = array(); |
| 52 |
- $scountquery = array(); |
|
| 52 |
+ $scountquery = array(); |
|
| 53 | 53 |
if($searchtype == "fulltext") {
|
| 54 | 54 |
$query = "SELECT DISTINCT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM "._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid AND stories.uid = "._UIDFIELD; |
| 55 | 55 |
$countquery = "SELECT count(DISTINCT stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid GROUP BY stories.sid"; |
| ... | ... |
@@ -252,6 +252,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 252 | 252 |
if(count($otherresults) > 0) $tpl->assign("otherresults", "<div id='otherresults'><span class='label'>"._OTHERRESULTS.":</span> ".implode(", ", $otherresults)."</div>");
|
| 253 | 253 |
} |
| 254 | 254 |
else {
|
| 255 |
+ $disablesorts = array( ); |
|
| 255 | 256 |
if($searchtype == "simple") {
|
| 256 | 257 |
$output .= "<div id=\"pagetitle\">"._SIMPLE."</div><div style='text-align: center;'><form method=\"post\" enctype=\"multipart/form-data\" action=\"search.php\"> |
| 257 | 258 |
<div class=\"tblborder\" style=\"width: 320px; padding: 5px; margin: 0 auto;\"> |
| ... | ... |
@@ -324,8 +325,10 @@ else {
|
| 324 | 325 |
<option>1000</option> |
| 325 | 326 |
<option value='-500'>< 500</option> |
| 326 | 327 |
</select><br /><br /><label for=\"searchterm\">"._SEARCHTERM.": </label><INPUT type=\"text\" class=\"textbox\" name=\"searchterm\" id=\"searchterm\" size=\"20\"> |
| 328 |
+ "; |
|
| 329 |
+ |
|
| 330 |
+ if(!in_array("sorts", $disablesorts)) $output .= "<label for=\"sortorder\">"._SORT.":</label> <select class=\"textbox\" name=\"sort\"><option value=\"alpha\"".(!$defaultsort ? " selected" : "").">"._ALPHA."</option><option value=\"update\"".($defaultsort == 1 ? " selected" : "").">"._MOSTRECENT."</option></select>";
|
|
| 327 | 331 |
|
| 328 |
- <label for=\"sortorder\">"._SORT.":</label> <select name=\"sortorder\" id=\"sortorder\"><option value=\"alpha\">"._ALPHA."</option><option value=\"update\">"._MOSTRECENT."</option></select>"; |
|
| 329 | 332 |
$codequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'searchform'");
|
| 330 | 333 |
while($code = dbassoc($codequery)) {
|
| 331 | 334 |
eval($code['code_text']); |
| ... | ... |
@@ -52,7 +52,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 52 | 52 |
$scountquery = array(); |
| 53 | 53 |
if($searchtype == "fulltext") {
|
| 54 | 54 |
$query = "SELECT DISTINCT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM "._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid AND stories.uid = "._UIDFIELD; |
| 55 |
- $countquery = "SELECT DISTINCT count(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid GROUP BY stories.sid"; |
|
| 55 |
+ $countquery = "SELECT count(DISTINCT stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid GROUP BY stories.sid"; |
|
| 56 | 56 |
$query .= " "._ORDERBY; |
| 57 | 57 |
search($query, $countquery); |
| 58 | 58 |
$tpl->assign("output", $output);
|
| ... | ... |
@@ -84,7 +84,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 84 | 84 |
if(count(array($authorlist)) > 0) {
|
| 85 | 85 |
$authors = implode(",",$authorlist);
|
| 86 | 86 |
$query = "SELECT DISTINCT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0) ";
|
| 87 |
- $countquery = "SELECT DISTINCT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0)"; |
|
| 87 |
+ $countquery = "SELECT COUNT(DISTINCT stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0)"; |
|
| 88 | 88 |
search($query, $countquery); |
| 89 | 89 |
$tpl->assign("output", $output);
|
| 90 | 90 |
$tpl->printToScreen(); |
| ... | ... |
@@ -51,8 +51,8 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 51 | 51 |
$countquery = array(); |
| 52 | 52 |
$scountquery = array(); |
| 53 | 53 |
if($searchtype == "fulltext") {
|
| 54 |
- $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM "._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid AND stories.uid = "._UIDFIELD; |
|
| 55 |
- $countquery = "SELECT count(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid GROUP BY stories.sid"; |
|
| 54 |
+ $query = "SELECT DISTINCT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM "._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid AND stories.uid = "._UIDFIELD; |
|
| 55 |
+ $countquery = "SELECT DISTINCT count(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid GROUP BY stories.sid"; |
|
| 56 | 56 |
$query .= " "._ORDERBY; |
| 57 | 57 |
search($query, $countquery); |
| 58 | 58 |
$tpl->assign("output", $output);
|
| ... | ... |
@@ -84,7 +84,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 84 | 84 |
if(count(array($authorlist)) > 0) {
|
| 85 | 85 |
$authors = implode(",",$authorlist);
|
| 86 | 86 |
$query = "SELECT DISTINCT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0) ";
|
| 87 |
- $countquery = "SELECT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0)"; |
|
| 87 |
+ $countquery = "SELECT DISTINCT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0)"; |
|
| 88 | 88 |
search($query, $countquery); |
| 89 | 89 |
$tpl->assign("output", $output);
|
| 90 | 90 |
$tpl->printToScreen(); |
| ... | ... |
@@ -51,8 +51,8 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 51 | 51 |
$countquery = array(); |
| 52 | 52 |
$scountquery = array(); |
| 53 | 53 |
if($searchtype == "fulltext") {
|
| 54 |
- $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM "._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext LIKE '%$searchterm%' AND chapter.sid = stories.sid AND stories.uid = "._UIDFIELD; |
|
| 55 |
- $countquery = "SELECT count(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext LIKE '%$searchterm%' AND chapter.sid = stories.sid GROUP BY stories.sid"; |
|
| 54 |
+ $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM "._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid AND stories.uid = "._UIDFIELD; |
|
| 55 |
+ $countquery = "SELECT count(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext AND chapter.validated > 0 LIKE '%$searchterm%' AND chapter.sid = stories.sid GROUP BY stories.sid"; |
|
| 56 | 56 |
$query .= " "._ORDERBY; |
| 57 | 57 |
search($query, $countquery); |
| 58 | 58 |
$tpl->assign("output", $output);
|
| ... | ... |
@@ -83,7 +83,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 83 | 83 |
} |
| 84 | 84 |
if(count(array($authorlist)) > 0) {
|
| 85 | 85 |
$authors = implode(",",$authorlist);
|
| 86 |
- $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0) ";
|
|
| 86 |
+ $query = "SELECT DISTINCT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0) ";
|
|
| 87 | 87 |
$countquery = "SELECT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0)"; |
| 88 | 88 |
search($query, $countquery); |
| 89 | 89 |
$tpl->assign("output", $output);
|
| ... | ... |
@@ -243,7 +243,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 243 | 243 |
if(!empty($scountquery)) {
|
| 244 | 244 |
$seriesresults = dbquery(_SERIESCOUNT.$scountquery); |
| 245 | 245 |
list($scount) = dbrow($seriesresults); |
| 246 |
- if($scount > 0) $otherresults[] = "<a href='browse.php?type=series&$terms'>$scount "._SERIES."</a>"; |
|
| 246 |
+ if($scount > 0) $otherresults[] = "<a href='browse.php?type=series&searchtype=$searchtype&$terms'>$scount "._SERIES."</a>"; |
|
| 247 | 247 |
} |
| 248 | 248 |
$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
|
| 249 | 249 |
while($code = dbassoc($codeblocks)) {
|
| ... | ... |
@@ -43,50 +43,49 @@ include("includes/pagesetup.php");
|
| 43 | 43 |
|
| 44 | 44 |
|
| 45 | 45 |
$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple"); |
| 46 |
-$rawterm = (isset($_REQUEST['searchterm']) ? $_REQUEST['searchterm'] : ""); |
|
| 47 |
-$searchterm = $rawterm !== "" ? escapestring("%".strtr($rawterm, array("!" => "!!", "%" => "!%", "_" => "!_"))."%") : false;
|
|
| 46 |
+$searchterm = (isset($_REQUEST['searchterm']) ? escapestring($_REQUEST['searchterm']) : false); |
|
| 48 | 47 |
|
| 49 | 48 |
if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 50 | 49 |
$output .= "<div id=\"pagetitle\">"._RESULTS."</div>"; |
| 51 | 50 |
$query = array(); |
| 52 | 51 |
$countquery = array(); |
| 53 | 52 |
$scountquery = array(); |
| 54 |
- if(!in_array($searchtype, array("title", "summary", "penname", "advanced", "fulltext"), true)) errorExit(_ERROR);
|
|
| 55 |
- if($searchtype == "fulltext" && $store != "mysql") errorExit(_ERROR); |
|
| 56 |
- if(($searchtype != "advanced" && trim($rawterm) === "") || ($searchterm !== false && strlen($rawterm) < 3)) {
|
|
| 57 |
- errorExit(_SEARCHTERMTOOSHORT); |
|
| 58 |
- } |
|
| 59 | 53 |
if($searchtype == "fulltext") {
|
| 60 |
- // EXISTS keeps both rows and counts distinct, and all common filters apply. |
|
| 61 |
- $fulltext = "EXISTS (SELECT 1 FROM ".TABLEPREFIX."fanfiction_chapters AS chapter WHERE chapter.sid = stories.sid AND chapter.validated > 0 AND chapter.storytext LIKE '$searchterm' ESCAPE '!')"; |
|
| 62 |
- $query[] = $fulltext; |
|
| 63 |
- $countquery[] = $fulltext; |
|
| 64 |
- $scountquery[] = "1 = 0"; // Series have no chapter text. |
|
| 54 |
+ $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM "._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext LIKE '%$searchterm%' AND chapter.sid = stories.sid AND stories.uid = "._UIDFIELD; |
|
| 55 |
+ $countquery = "SELECT count(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext LIKE '%$searchterm%' AND chapter.sid = stories.sid GROUP BY stories.sid"; |
|
| 56 |
+ $query .= " "._ORDERBY; |
|
| 57 |
+ search($query, $countquery); |
|
| 58 |
+ $tpl->assign("output", $output);
|
|
| 59 |
+ $tpl->printToScreen(); |
|
| 60 |
+ dbclose( ); |
|
| 61 |
+ exit( ); |
|
| 65 | 62 |
} |
| 63 |
+ if($searchterm && strlen($searchterm) < 3) {
|
|
| 64 |
+ errorExit(_SEARCHTERMTOOSHORT); |
|
| 65 |
+ } |
|
| 66 |
+ if($searchterm !== false) $searchterm = str_replace(array('%', '_'), array('\\%', '\\_'), escapestring($searchterm));
|
|
| 66 | 67 |
if($searchterm) {
|
| 67 | 68 |
if($searchtype == "title") {
|
| 68 |
- $query[] = "stories.title LIKE '$searchterm' ESCAPE '!'"; |
|
| 69 |
- $countquery[] = "stories.title LIKE '$searchterm' ESCAPE '!'"; |
|
| 70 |
- $scountquery[] = "series.title LIKE '$searchterm' ESCAPE '!'"; |
|
| 69 |
+ $query[] = "stories.title LIKE '%$searchterm%'"; |
|
| 70 |
+ $countquery[] = "stories.title LIKE '%$searchterm%'"; |
|
| 71 |
+ $scountquery[] = "series.title LIKE '%$searchterm%'"; |
|
| 71 | 72 |
} |
| 72 | 73 |
if($searchtype == "summary") {
|
| 73 |
- $query[] = "stories.summary LIKE '$searchterm' ESCAPE '!'"; |
|
| 74 |
- $countquery[] = "stories.summary LIKE '$searchterm' ESCAPE '!'"; |
|
| 75 |
- $scountquery[] = "series.summary LIKE '$searchterm' ESCAPE '!'"; |
|
| 74 |
+ $query[] = "stories.summary LIKE '%$searchterm%'"; |
|
| 75 |
+ $countquery[] = "stories.summary LIKE '%$searchterm%'"; |
|
| 76 |
+ $scountquery[] = "series.summary LIKE '%$searchterm%'"; |
|
| 76 | 77 |
} |
| 77 | 78 |
if($searchtype == "penname") {
|
| 78 |
- $authorquery = dbquery(_MEMBERLIST." WHERE "._PENNAMEFIELD." LIKE '$searchterm' ESCAPE '!' GROUP BY "._UIDFIELD); |
|
| 79 |
+ $authorquery = dbquery(_MEMBERLIST." WHERE "._PENNAMEFIELD." LIKE '%$searchterm%' GROUP BY "._UIDFIELD); |
|
| 79 | 80 |
$authorlist = array(); |
| 80 | 81 |
while($auth = dbassoc($authorquery)) {
|
| 81 | 82 |
$authorlist[] = $auth['uid']; |
| 82 | 83 |
} |
| 83 |
- // old behavior stays as new upstream behavior breaks MySQL strict error reporting mode - tweaked |
|
| 84 | 84 |
if(count(array($authorlist)) > 0) {
|
| 85 | 85 |
$authors = implode(",",$authorlist);
|
| 86 |
- $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR EXISTS (SELECT 1 FROM ".TABLEPREFIX."fanfiction_coauthors AS coauth WHERE coauth.sid = stories.sid AND FIND_IN_SET(coauth.uid, '$authors') > 0))";
|
|
| 87 |
- $countquery = "SELECT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR EXISTS (SELECT 1 FROM ".TABLEPREFIX."fanfiction_coauthors AS coauth WHERE coauth.sid = stories.sid AND FIND_IN_SET(coauth.uid, '$authors') > 0))"; |
|
| 88 |
- $scountquery = "SELECT COUNT(series.sid) FROM ".TABLEPREFIX."fanfiction_series as series AND (FIND_IN_SET(series.uid, '$authors') > 0)"; |
|
| 89 |
- search($query, $countquery, $scountquery); |
|
| 86 |
+ $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0) ";
|
|
| 87 |
+ $countquery = "SELECT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0)"; |
|
| 88 |
+ search($query, $countquery); |
|
| 90 | 89 |
$tpl->assign("output", $output);
|
| 91 | 90 |
$tpl->printToScreen(); |
| 92 | 91 |
dbclose( ); |
| ... | ... |
@@ -99,9 +98,9 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 99 | 98 |
} |
| 100 | 99 |
} |
| 101 | 100 |
if($searchtype == "advanced") {
|
| 102 |
- $query[] = "(stories.summary LIKE '$searchterm' ESCAPE '!' OR stories.title LIKE '$searchterm' ESCAPE '!') "; |
|
| 103 |
- $countquery[] = "(stories.summary LIKE '$searchterm' ESCAPE '!' OR stories.title LIKE '$searchterm' ESCAPE '!') "; |
|
| 104 |
- $scountquery[] = "(summary LIKE '$searchterm' ESCAPE '!' OR title LIKE '$searchterm' ESCAPE '!') "; |
|
| 101 |
+ $query[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') "; |
|
| 102 |
+ $countquery[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') "; |
|
| 103 |
+ $scountquery[] = "(summary LIKE '%$searchterm%' OR title LIKE '%$searchterm%') "; |
|
| 105 | 104 |
} |
| 106 | 105 |
} |
| 107 | 106 |
if(isset($_REQUEST['authors'])) {
|
| ... | ... |
@@ -178,10 +177,18 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 178 | 177 |
foreach($classtypelist as $id => $vars) {
|
| 179 | 178 |
$opts = array( ); |
| 180 | 179 |
$exopts = array( ); |
| 181 |
- if(isset($_REQUEST["class_".$id])) $opts = ef_search_ids($_REQUEST["class_".$id]); |
|
| 182 |
- else if(isset($_REQUEST[$vars["name"]])) $opts = ef_search_ids($_REQUEST[$vars["name"]]); |
|
| 180 |
+ if(isset($_POST["class_".$id])) $opts = array_filter($_POST["class_".$id], "isNumber"); |
|
| 181 |
+ else if(isset($_GET["class_".$id])) {
|
|
| 182 |
+ $opts = array_merge($opts, explode(",", $_GET["class_".$id]));
|
|
| 183 |
+ $opts = array_filter($opts, "isNumber"); |
|
| 184 |
+ } |
|
| 185 |
+ else if(isset($_REQUEST[$vars["name"]])) $opts[] = array($_REQUEST[$vars["name"]]); |
|
| 183 | 186 |
$classin = array_merge($classin, $opts); |
| 184 |
- if(isset($_REQUEST["exclass_".$id])) $exopts = ef_search_ids($_REQUEST["exclass_".$id]); |
|
| 187 |
+ if(isset($_POST["exclass_".$id])) $exopts = array_filter($_POST["exclass_".$id], "isNumber"); |
|
| 188 |
+ else if(isset($_GET["exclass_".$id])) {
|
|
| 189 |
+ $exopts = array_merge($exopts, explode(",", $_GET["exclass_".$id]));
|
|
| 190 |
+ $exopts = array_filter($exopts, "isNumber"); |
|
| 191 |
+ } |
|
| 185 | 192 |
$classex = array_merge($classex, $exopts); |
| 186 | 193 |
unset($opts, $exopts); |
| 187 | 194 |
} |
| ... | ... |
@@ -224,7 +231,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 224 | 231 |
$query = (count($query) > 0 ? " AND ".implode(" AND ", $query) : "")." "._ORDERBY;
|
| 225 | 232 |
$countquery = count($countquery) > 0 ? " AND ".implode(" AND ", $countquery) : "";
|
| 226 | 233 |
if(count($scountquery) > 0) $scountquery = " WHERE ".implode(" AND ", $scountquery);
|
| 227 |
- search(preg_replace('/^SELECT /i', 'SELECT DISTINCT ', _STORYQUERY).$query, str_ireplace('count(sid)', 'COUNT(DISTINCT stories.sid)', _STORYCOUNT).$countquery);
|
|
| 234 |
+ search(_STORYQUERY.$query, _STORYCOUNT.$countquery); |
|
| 228 | 235 |
$otherresults = array( ); |
| 229 | 236 |
$termArray = array_merge($_GET, $_POST); |
| 230 | 237 |
$termsList = array(); |
| ... | ... |
@@ -236,7 +243,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 236 | 243 |
if(!empty($scountquery)) {
|
| 237 | 244 |
$seriesresults = dbquery(_SERIESCOUNT.$scountquery); |
| 238 | 245 |
list($scount) = dbrow($seriesresults); |
| 239 |
- if($scount > 0) $otherresults[] = "<a href='browse.php?type=series".($terms !== "" ? "&".$terms : "")."'>$scount "._SERIES."</a>"; |
|
| 246 |
+ if($scount > 0) $otherresults[] = "<a href='browse.php?type=series&$terms'>$scount "._SERIES."</a>"; |
|
| 240 | 247 |
} |
| 241 | 248 |
$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
|
| 242 | 249 |
while($code = dbassoc($codeblocks)) {
|
| ... | ... |
@@ -329,14 +336,4 @@ $output .= "<div id='submitdiv'><input name=\"submit\" id=\"submit\" value=\""._ |
| 329 | 336 |
$tpl->assign("output", $output);
|
| 330 | 337 |
$tpl->printToScreen(); |
| 331 | 338 |
dbclose( ); |
| 332 |
- |
|
| 333 |
-// Accept form lists and comma-separated continuation values, but never silently |
|
| 334 |
-// discard an invalid/nested classification and broaden the search. |
|
| 335 |
-function ef_search_ids($value) {
|
|
| 336 |
- $values = is_array($value) ? $value : explode(",", $value);
|
|
| 337 |
- foreach($values as $v) {
|
|
| 338 |
- if(!is_string($v) || ($v !== "" && !isNumber($v))) errorExit(_ERROR); |
|
| 339 |
- } |
|
| 340 |
- return array_values(array_filter($values, "isNumber")); |
|
| 341 |
-} |
|
| 342 | 339 |
?> |
| ... | ... |
@@ -43,49 +43,50 @@ include("includes/pagesetup.php");
|
| 43 | 43 |
|
| 44 | 44 |
|
| 45 | 45 |
$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple"); |
| 46 |
-$searchterm = (isset($_REQUEST['searchterm']) ? escapestring($_REQUEST['searchterm']) : false); |
|
| 46 |
+$rawterm = (isset($_REQUEST['searchterm']) ? $_REQUEST['searchterm'] : ""); |
|
| 47 |
+$searchterm = $rawterm !== "" ? escapestring("%".strtr($rawterm, array("!" => "!!", "%" => "!%", "_" => "!_"))."%") : false;
|
|
| 47 | 48 |
|
| 48 | 49 |
if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 49 | 50 |
$output .= "<div id=\"pagetitle\">"._RESULTS."</div>"; |
| 50 | 51 |
$query = array(); |
| 51 | 52 |
$countquery = array(); |
| 52 | 53 |
$scountquery = array(); |
| 53 |
- if($searchtype == "fulltext") {
|
|
| 54 |
- $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM "._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext LIKE '%$searchterm%' AND chapter.sid = stories.sid AND stories.uid = "._UIDFIELD; |
|
| 55 |
- $countquery = "SELECT count(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext LIKE '%$searchterm%' AND chapter.sid = stories.sid GROUP BY stories.sid"; |
|
| 56 |
- $query .= " "._ORDERBY; |
|
| 57 |
- search($query, $countquery); |
|
| 58 |
- $tpl->assign("output", $output);
|
|
| 59 |
- $tpl->printToScreen(); |
|
| 60 |
- dbclose( ); |
|
| 61 |
- exit( ); |
|
| 62 |
- } |
|
| 63 |
- if($searchterm && strlen($searchterm) < 3) {
|
|
| 54 |
+ if(!in_array($searchtype, array("title", "summary", "penname", "advanced", "fulltext"), true)) errorExit(_ERROR);
|
|
| 55 |
+ if($searchtype == "fulltext" && $store != "mysql") errorExit(_ERROR); |
|
| 56 |
+ if(($searchtype != "advanced" && trim($rawterm) === "") || ($searchterm !== false && strlen($rawterm) < 3)) {
|
|
| 64 | 57 |
errorExit(_SEARCHTERMTOOSHORT); |
| 65 | 58 |
} |
| 66 |
- if($searchterm !== false) $searchterm = str_replace(array('%', '_'), array('\\%', '\\_'), escapestring($searchterm));
|
|
| 59 |
+ if($searchtype == "fulltext") {
|
|
| 60 |
+ // EXISTS keeps both rows and counts distinct, and all common filters apply. |
|
| 61 |
+ $fulltext = "EXISTS (SELECT 1 FROM ".TABLEPREFIX."fanfiction_chapters AS chapter WHERE chapter.sid = stories.sid AND chapter.validated > 0 AND chapter.storytext LIKE '$searchterm' ESCAPE '!')"; |
|
| 62 |
+ $query[] = $fulltext; |
|
| 63 |
+ $countquery[] = $fulltext; |
|
| 64 |
+ $scountquery[] = "1 = 0"; // Series have no chapter text. |
|
| 65 |
+ } |
|
| 67 | 66 |
if($searchterm) {
|
| 68 | 67 |
if($searchtype == "title") {
|
| 69 |
- $query[] = "stories.title LIKE '%$searchterm%'"; |
|
| 70 |
- $countquery[] = "stories.title LIKE '%$searchterm%'"; |
|
| 71 |
- $scountquery[] = "series.title LIKE '%$searchterm%'"; |
|
| 68 |
+ $query[] = "stories.title LIKE '$searchterm' ESCAPE '!'"; |
|
| 69 |
+ $countquery[] = "stories.title LIKE '$searchterm' ESCAPE '!'"; |
|
| 70 |
+ $scountquery[] = "series.title LIKE '$searchterm' ESCAPE '!'"; |
|
| 72 | 71 |
} |
| 73 | 72 |
if($searchtype == "summary") {
|
| 74 |
- $query[] = "stories.summary LIKE '%$searchterm%'"; |
|
| 75 |
- $countquery[] = "stories.summary LIKE '%$searchterm%'"; |
|
| 76 |
- $scountquery[] = "series.summary LIKE '%$searchterm%'"; |
|
| 73 |
+ $query[] = "stories.summary LIKE '$searchterm' ESCAPE '!'"; |
|
| 74 |
+ $countquery[] = "stories.summary LIKE '$searchterm' ESCAPE '!'"; |
|
| 75 |
+ $scountquery[] = "series.summary LIKE '$searchterm' ESCAPE '!'"; |
|
| 77 | 76 |
} |
| 78 | 77 |
if($searchtype == "penname") {
|
| 79 |
- $authorquery = dbquery(_MEMBERLIST." WHERE "._PENNAMEFIELD." LIKE '%$searchterm%' GROUP BY "._UIDFIELD); |
|
| 78 |
+ $authorquery = dbquery(_MEMBERLIST." WHERE "._PENNAMEFIELD." LIKE '$searchterm' ESCAPE '!' GROUP BY "._UIDFIELD); |
|
| 80 | 79 |
$authorlist = array(); |
| 81 | 80 |
while($auth = dbassoc($authorquery)) {
|
| 82 | 81 |
$authorlist[] = $auth['uid']; |
| 83 | 82 |
} |
| 83 |
+ // old behavior stays as new upstream behavior breaks MySQL strict error reporting mode - tweaked |
|
| 84 | 84 |
if(count(array($authorlist)) > 0) {
|
| 85 | 85 |
$authors = implode(",",$authorlist);
|
| 86 |
- $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0) ";
|
|
| 87 |
- $countquery = "SELECT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0)"; |
|
| 88 |
- search($query, $countquery); |
|
| 86 |
+ $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR EXISTS (SELECT 1 FROM ".TABLEPREFIX."fanfiction_coauthors AS coauth WHERE coauth.sid = stories.sid AND FIND_IN_SET(coauth.uid, '$authors') > 0))";
|
|
| 87 |
+ $countquery = "SELECT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR EXISTS (SELECT 1 FROM ".TABLEPREFIX."fanfiction_coauthors AS coauth WHERE coauth.sid = stories.sid AND FIND_IN_SET(coauth.uid, '$authors') > 0))"; |
|
| 88 |
+ $scountquery = "SELECT COUNT(series.sid) FROM ".TABLEPREFIX."fanfiction_series as series AND (FIND_IN_SET(series.uid, '$authors') > 0)"; |
|
| 89 |
+ search($query, $countquery, $scountquery); |
|
| 89 | 90 |
$tpl->assign("output", $output);
|
| 90 | 91 |
$tpl->printToScreen(); |
| 91 | 92 |
dbclose( ); |
| ... | ... |
@@ -98,9 +99,9 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 98 | 99 |
} |
| 99 | 100 |
} |
| 100 | 101 |
if($searchtype == "advanced") {
|
| 101 |
- $query[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') "; |
|
| 102 |
- $countquery[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') "; |
|
| 103 |
- $scountquery[] = "(summary LIKE '%$searchterm%' OR title LIKE '%$searchterm%') "; |
|
| 102 |
+ $query[] = "(stories.summary LIKE '$searchterm' ESCAPE '!' OR stories.title LIKE '$searchterm' ESCAPE '!') "; |
|
| 103 |
+ $countquery[] = "(stories.summary LIKE '$searchterm' ESCAPE '!' OR stories.title LIKE '$searchterm' ESCAPE '!') "; |
|
| 104 |
+ $scountquery[] = "(summary LIKE '$searchterm' ESCAPE '!' OR title LIKE '$searchterm' ESCAPE '!') "; |
|
| 104 | 105 |
} |
| 105 | 106 |
} |
| 106 | 107 |
if(isset($_REQUEST['authors'])) {
|
| ... | ... |
@@ -177,18 +178,10 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 177 | 178 |
foreach($classtypelist as $id => $vars) {
|
| 178 | 179 |
$opts = array( ); |
| 179 | 180 |
$exopts = array( ); |
| 180 |
- if(isset($_POST["class_".$id])) $opts = array_filter($_POST["class_".$id], "isNumber"); |
|
| 181 |
- else if(isset($_GET["class_".$id])) {
|
|
| 182 |
- $opts = array_merge($opts, explode(",", $_GET["class_".$id]));
|
|
| 183 |
- $opts = array_filter($opts, "isNumber"); |
|
| 184 |
- } |
|
| 185 |
- else if(isset($_REQUEST[$vars["name"]])) $opts[] = array($_REQUEST[$vars["name"]]); |
|
| 181 |
+ if(isset($_REQUEST["class_".$id])) $opts = ef_search_ids($_REQUEST["class_".$id]); |
|
| 182 |
+ else if(isset($_REQUEST[$vars["name"]])) $opts = ef_search_ids($_REQUEST[$vars["name"]]); |
|
| 186 | 183 |
$classin = array_merge($classin, $opts); |
| 187 |
- if(isset($_POST["exclass_".$id])) $exopts = array_filter($_POST["exclass_".$id], "isNumber"); |
|
| 188 |
- else if(isset($_GET["exclass_".$id])) {
|
|
| 189 |
- $exopts = array_merge($exopts, explode(",", $_GET["exclass_".$id]));
|
|
| 190 |
- $exopts = array_filter($exopts, "isNumber"); |
|
| 191 |
- } |
|
| 184 |
+ if(isset($_REQUEST["exclass_".$id])) $exopts = ef_search_ids($_REQUEST["exclass_".$id]); |
|
| 192 | 185 |
$classex = array_merge($classex, $exopts); |
| 193 | 186 |
unset($opts, $exopts); |
| 194 | 187 |
} |
| ... | ... |
@@ -231,7 +224,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 231 | 224 |
$query = (count($query) > 0 ? " AND ".implode(" AND ", $query) : "")." "._ORDERBY;
|
| 232 | 225 |
$countquery = count($countquery) > 0 ? " AND ".implode(" AND ", $countquery) : "";
|
| 233 | 226 |
if(count($scountquery) > 0) $scountquery = " WHERE ".implode(" AND ", $scountquery);
|
| 234 |
- search(_STORYQUERY.$query, _STORYCOUNT.$countquery); |
|
| 227 |
+ search(preg_replace('/^SELECT /i', 'SELECT DISTINCT ', _STORYQUERY).$query, str_ireplace('count(sid)', 'COUNT(DISTINCT stories.sid)', _STORYCOUNT).$countquery);
|
|
| 235 | 228 |
$otherresults = array( ); |
| 236 | 229 |
$termArray = array_merge($_GET, $_POST); |
| 237 | 230 |
$termsList = array(); |
| ... | ... |
@@ -243,7 +236,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 243 | 236 |
if(!empty($scountquery)) {
|
| 244 | 237 |
$seriesresults = dbquery(_SERIESCOUNT.$scountquery); |
| 245 | 238 |
list($scount) = dbrow($seriesresults); |
| 246 |
- if($scount > 0) $otherresults[] = "<a href='browse.php?type=series&$terms'>$scount "._SERIES."</a>"; |
|
| 239 |
+ if($scount > 0) $otherresults[] = "<a href='browse.php?type=series".($terms !== "" ? "&".$terms : "")."'>$scount "._SERIES."</a>"; |
|
| 247 | 240 |
} |
| 248 | 241 |
$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
|
| 249 | 242 |
while($code = dbassoc($codeblocks)) {
|
| ... | ... |
@@ -336,4 +329,14 @@ $output .= "<div id='submitdiv'><input name=\"submit\" id=\"submit\" value=\""._ |
| 336 | 329 |
$tpl->assign("output", $output);
|
| 337 | 330 |
$tpl->printToScreen(); |
| 338 | 331 |
dbclose( ); |
| 332 |
+ |
|
| 333 |
+// Accept form lists and comma-separated continuation values, but never silently |
|
| 334 |
+// discard an invalid/nested classification and broaden the search. |
|
| 335 |
+function ef_search_ids($value) {
|
|
| 336 |
+ $values = is_array($value) ? $value : explode(",", $value);
|
|
| 337 |
+ foreach($values as $v) {
|
|
| 338 |
+ if(!is_string($v) || ($v !== "" && !isNumber($v))) errorExit(_ERROR); |
|
| 339 |
+ } |
|
| 340 |
+ return array_values(array_filter($values, "isNumber")); |
|
| 341 |
+} |
|
| 339 | 342 |
?> |
| ... | ... |
@@ -243,7 +243,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 243 | 243 |
if(!empty($scountquery)) {
|
| 244 | 244 |
$seriesresults = dbquery(_SERIESCOUNT.$scountquery); |
| 245 | 245 |
list($scount) = dbrow($seriesresults); |
| 246 |
- if($scount > 0) $otherresults[] = "<a href='browse.php?type=series$terms'>$scount "._SERIES."</a>"; |
|
| 246 |
+ if($scount > 0) $otherresults[] = "<a href='browse.php?type=series&$terms'>$scount "._SERIES."</a>"; |
|
| 247 | 247 |
} |
| 248 | 248 |
$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
|
| 249 | 249 |
while($code = dbassoc($codeblocks)) {
|
| ... | ... |
@@ -81,7 +81,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 81 | 81 |
while($auth = dbassoc($authorquery)) {
|
| 82 | 82 |
$authorlist[] = $auth['uid']; |
| 83 | 83 |
} |
| 84 |
- if(is_countable($authorlist) > 0) {
|
|
| 84 |
+ if(count(array($authorlist)) > 0) {
|
|
| 85 | 85 |
$authors = implode(",",$authorlist);
|
| 86 | 86 |
$query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0) ";
|
| 87 | 87 |
$countquery = "SELECT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0)"; |
| ... | ... |
@@ -63,6 +63,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 63 | 63 |
if($searchterm && strlen($searchterm) < 3) {
|
| 64 | 64 |
errorExit(_SEARCHTERMTOOSHORT); |
| 65 | 65 |
} |
| 66 |
+ if($searchterm !== false) $searchterm = str_replace(array('%', '_'), array('\\%', '\\_'), escapestring($searchterm));
|
|
| 66 | 67 |
if($searchterm) {
|
| 67 | 68 |
if($searchtype == "title") {
|
| 68 | 69 |
$query[] = "stories.title LIKE '%$searchterm%'"; |
| ... | ... |
@@ -162,12 +162,12 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 162 | 162 |
|
| 163 | 163 |
if(isset($_REQUEST['rid'])) $rid = is_array($_REQUEST['rid']) ? $_REQUEST['rid'] : explode(",", $_REQUEST['rid']);
|
| 164 | 164 |
else $rid = array(); |
| 165 |
+ $rid = array_filter((array)$rid, function($r) { return is_string($r) && isNumber($r); });
|
|
| 165 | 166 |
if(count($rid) > 0) {
|
| 166 |
- $rid = array_filter($rid, "isNumber"); |
|
| 167 | 167 |
$query[] = findclause('rid', $rid);
|
| 168 | 168 |
$countquery[] = findclause('rid', $rid);
|
| 169 | 169 |
} |
| 170 |
- if(isset($_REQUEST['complete'])) {
|
|
| 170 |
+ if(isset($_REQUEST['complete']) || isset($_REQUEST['completed'])) {
|
|
| 171 | 171 |
$query[] = "stories.completed = '1'"; |
| 172 | 172 |
$countquery[] = "stories.completed = '1'"; |
| 173 | 173 |
} |
| ... | ... |
@@ -236,7 +236,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 236 | 236 |
$termsList = array(); |
| 237 | 237 |
foreach($termArray as $term => $value) {
|
| 238 | 238 |
if($term == "submit" || $term == "wordhigh" || $term == "wordlow" || empty($value) || $term == "formname" || $term == "searchtype") continue; |
| 239 |
- $termsList[$term] = "$term=".(is_array($value) ? implode(",", array_map('htmlspecialchars', $value)) : htmlspecialchars($value, ENT_QUOTES));
|
|
| 239 |
+ $termsList[$term] = "$term=".(is_array($value) ? implode(",", array_map(function($v) { return htmlspecialchars($v, ENT_QUOTES); }, $value)) : htmlspecialchars($value, ENT_QUOTES));
|
|
| 240 | 240 |
} |
| 241 | 241 |
$terms = implode("&", $termsList);
|
| 242 | 242 |
if(!empty($scountquery)) {
|
| ... | ... |
@@ -236,7 +236,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 236 | 236 |
$termsList = array(); |
| 237 | 237 |
foreach($termArray as $term => $value) {
|
| 238 | 238 |
if($term == "submit" || $term == "wordhigh" || $term == "wordlow" || empty($value) || $term == "formname" || $term == "searchtype") continue; |
| 239 |
- $termsList[$term] = "$term=".(is_array($value) ? implode(",", $value) : $value);
|
|
| 239 |
+ $termsList[$term] = "$term=".(is_array($value) ? implode(",", array_map('htmlspecialchars', $value)) : htmlspecialchars($value, ENT_QUOTES));
|
|
| 240 | 240 |
} |
| 241 | 241 |
$terms = implode("&", $termsList);
|
| 242 | 242 |
if(!empty($scountquery)) {
|
| ... | ... |
@@ -21,18 +21,6 @@ |
| 21 | 21 |
// To read the license please visit http://www.gnu.org/copyleft/gpl.html |
| 22 | 22 |
// ---------------------------------------------------------------------- |
| 23 | 23 |
|
| 24 |
-// 'temp' error suppression for MySQL/MariaDB behavior in PHP 8 starting with 8.1 |
|
| 25 |
-// |
|
| 26 |
-// script works right to an extent, but... |
|
| 27 |
-// mysqli STRICT enabled - shows a MYSQL error message in place of the Search Results header (not ideal) |
|
| 28 |
-// mysqli STRICT disabled - brings up a PHP warning regarding accessing num_rows on false in another script |
|
| 29 |
-// |
|
| 30 |
-// this only affects searching a penname that is confirmed not to exist |
|
| 31 |
- |
|
| 32 |
-ini_set('display_errors', 0);
|
|
| 33 |
-ini_set('display_startup_errors', 0);
|
|
| 34 |
-error_reporting(0); |
|
| 35 |
-mysqli_report(MYSQLI_REPORT_OFF); |
|
| 36 | 24 |
|
| 37 | 25 |
// Page Setup |
| 38 | 26 |
// Set the current page id. Because search does multiple things there are multiple possibilities |
| ... | ... |
@@ -92,7 +80,7 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
| 92 | 80 |
while($auth = dbassoc($authorquery)) {
|
| 93 | 81 |
$authorlist[] = $auth['uid']; |
| 94 | 82 |
} |
| 95 |
- if(count($authorlist) > 0) {
|
|
| 83 |
+ if(is_countable($authorlist) > 0) {
|
|
| 96 | 84 |
$authors = implode(",",$authorlist);
|
| 97 | 85 |
$query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0) ";
|
| 98 | 86 |
$countquery = "SELECT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0)"; |
| ... | ... |
@@ -21,6 +21,18 @@ |
| 21 | 21 |
// To read the license please visit http://www.gnu.org/copyleft/gpl.html |
| 22 | 22 |
// ---------------------------------------------------------------------- |
| 23 | 23 |
|
| 24 |
+// 'temp' error suppression for MySQL/MariaDB behavior in PHP 8 starting with 8.1 |
|
| 25 |
+// |
|
| 26 |
+// script works right to an extent, but... |
|
| 27 |
+// mysqli STRICT enabled - shows a MYSQL error message in place of the Search Results header (not ideal) |
|
| 28 |
+// mysqli STRICT disabled - brings up a PHP warning regarding accessing num_rows on false in another script |
|
| 29 |
+// |
|
| 30 |
+// this only affects searching a penname that is confirmed not to exist |
|
| 31 |
+ |
|
| 32 |
+ini_set('display_errors', 0);
|
|
| 33 |
+ini_set('display_startup_errors', 0);
|
|
| 34 |
+error_reporting(0); |
|
| 35 |
+mysqli_report(MYSQLI_REPORT_OFF); |
|
| 24 | 36 |
|
| 25 | 37 |
// Page Setup |
| 26 | 38 |
// Set the current page id. Because search does multiple things there are multiple possibilities |
| ... | ... |
@@ -265,7 +265,7 @@ else {
|
| 265 | 265 |
<div style=\"font-size: 8pt; text-align: right;\"><a href=\"search.php?searchtype=advanced\">"._ADVANCED."</a></div></div></form></div>"; |
| 266 | 266 |
} |
| 267 | 267 |
else {
|
| 268 |
- $output .= "<div id=\"pagetitle\">"._ADVANCED."</div><div> |
|
| 268 |
+ $output .= "<div id=\"pagetitle\">"._ADVANCED. "</div><div> |
|
| 269 | 269 |
<form method=\"POST\" name=\"form\" enctype=\"multipart/form-data\" action=\"search.php?searchtype=advanced\"> |
| 270 | 270 |
<div class=\"tblborder\" style=\"width: 90%; margin: 0 auto; padding: 10px;\">"; |
| 271 | 271 |
if($multiplecats) {
|
| ... | ... |
@@ -292,7 +292,6 @@ else {
|
| 292 | 292 |
$output .= "</select></div>"; |
| 293 | 293 |
} |
| 294 | 294 |
$output .= "<div style=\"clear: both;\"> </div>"; |
| 295 |
- $output .= " <div style=\"text-align: center;\">"._MULTIPLESELECT."</div>"; |
|
| 296 | 295 |
$result = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_classtypes ORDER BY classtype_name");
|
| 297 | 296 |
while($type = dbassoc($result)) {
|
| 298 | 297 |
$result2 = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_classes WHERE class_type = '".$type['classtype_id']."' ORDER BY class_name");
|
| ... | ... |
@@ -336,4 +335,4 @@ $output .= "<div id='submitdiv'><input name=\"submit\" id=\"submit\" value=\""._ |
| 336 | 335 |
$tpl->assign("output", $output);
|
| 337 | 336 |
$tpl->printToScreen(); |
| 338 | 337 |
dbclose( ); |
| 339 |
-?> |
|
| 340 | 338 |
\ No newline at end of file |
| 339 |
+?> |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,339 @@ |
| 1 |
+<?php |
|
| 2 |
+// ---------------------------------------------------------------------- |
|
| 3 |
+// Copyright (c) 2007 by Tammy Keefer |
|
| 4 |
+// Valid HTML 4.01 Transitional |
|
| 5 |
+// Based on eFiction 1.1 |
|
| 6 |
+// Copyright (C) 2003 by Rebecca Smallwood. |
|
| 7 |
+// http://efiction.sourceforge.net/ |
|
| 8 |
+// ---------------------------------------------------------------------- |
|
| 9 |
+// LICENSE |
|
| 10 |
+// |
|
| 11 |
+// This program is free software; you can redistribute it and/or |
|
| 12 |
+// modify it under the terms of the GNU General Public License (GPL) |
|
| 13 |
+// as published by the Free Software Foundation; either version 2 |
|
| 14 |
+// of the License, or (at your option) any later version. |
|
| 15 |
+// |
|
| 16 |
+// This program is distributed in the hope that it will be useful, |
|
| 17 |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 18 |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 19 |
+// GNU General Public License for more details. |
|
| 20 |
+// |
|
| 21 |
+// To read the license please visit http://www.gnu.org/copyleft/gpl.html |
|
| 22 |
+// ---------------------------------------------------------------------- |
|
| 23 |
+ |
|
| 24 |
+ |
|
| 25 |
+// Page Setup |
|
| 26 |
+// Set the current page id. Because search does multiple things there are multiple possibilities |
|
| 27 |
+if(isset($_POST['submit']) || isset($_GET['offset'])) $current = "searchresults"; |
|
| 28 |
+else $current = "search"; |
|
| 29 |
+if(isset($_GET['action']) && $_GET['action'] == "advanced") $displayform = 1; |
|
| 30 |
+// Now set up the page |
|
| 31 |
+ |
|
| 32 |
+$displayform = 1; |
|
| 33 |
+ |
|
| 34 |
+ |
|
| 35 |
+include ("header.php");
|
|
| 36 |
+ |
|
| 37 |
+if(file_exists("$skindir/browse.tpl")) $tpl = new TemplatePower( "$skindir/browse.tpl" );
|
|
| 38 |
+else $tpl = new TemplatePower("default_tpls/browse.tpl");
|
|
| 39 |
+if(file_exists("$skindir/listings.tpl")) $tpl->assignInclude( "listings", "./$skindir/listings.tpl" );
|
|
| 40 |
+else $tpl->assignInclude( "listings", "./default_tpls/listings.tpl" ); |
|
| 41 |
+ |
|
| 42 |
+include("includes/pagesetup.php");
|
|
| 43 |
+ |
|
| 44 |
+ |
|
| 45 |
+$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple"); |
|
| 46 |
+$searchterm = (isset($_REQUEST['searchterm']) ? escapestring($_REQUEST['searchterm']) : false); |
|
| 47 |
+ |
|
| 48 |
+if(isset($_POST['submit']) || isset($_GET['offset'])) {
|
|
| 49 |
+ $output .= "<div id=\"pagetitle\">"._RESULTS."</div>"; |
|
| 50 |
+ $query = array(); |
|
| 51 |
+ $countquery = array(); |
|
| 52 |
+ $scountquery = array(); |
|
| 53 |
+ if($searchtype == "fulltext") {
|
|
| 54 |
+ $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM "._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext LIKE '%$searchterm%' AND chapter.sid = stories.sid AND stories.uid = "._UIDFIELD; |
|
| 55 |
+ $countquery = "SELECT count(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories, ".TABLEPREFIX."fanfiction_chapters as chapter WHERE chapter.storytext LIKE '%$searchterm%' AND chapter.sid = stories.sid GROUP BY stories.sid"; |
|
| 56 |
+ $query .= " "._ORDERBY; |
|
| 57 |
+ search($query, $countquery); |
|
| 58 |
+ $tpl->assign("output", $output);
|
|
| 59 |
+ $tpl->printToScreen(); |
|
| 60 |
+ dbclose( ); |
|
| 61 |
+ exit( ); |
|
| 62 |
+ } |
|
| 63 |
+ if($searchterm && strlen($searchterm) < 3) {
|
|
| 64 |
+ errorExit(_SEARCHTERMTOOSHORT); |
|
| 65 |
+ } |
|
| 66 |
+ if($searchterm) {
|
|
| 67 |
+ if($searchtype == "title") {
|
|
| 68 |
+ $query[] = "stories.title LIKE '%$searchterm%'"; |
|
| 69 |
+ $countquery[] = "stories.title LIKE '%$searchterm%'"; |
|
| 70 |
+ $scountquery[] = "series.title LIKE '%$searchterm%'"; |
|
| 71 |
+ } |
|
| 72 |
+ if($searchtype == "summary") {
|
|
| 73 |
+ $query[] = "stories.summary LIKE '%$searchterm%'"; |
|
| 74 |
+ $countquery[] = "stories.summary LIKE '%$searchterm%'"; |
|
| 75 |
+ $scountquery[] = "series.summary LIKE '%$searchterm%'"; |
|
| 76 |
+ } |
|
| 77 |
+ if($searchtype == "penname") {
|
|
| 78 |
+ $authorquery = dbquery(_MEMBERLIST." WHERE "._PENNAMEFIELD." LIKE '%$searchterm%' GROUP BY "._UIDFIELD); |
|
| 79 |
+ $authorlist = array(); |
|
| 80 |
+ while($auth = dbassoc($authorquery)) {
|
|
| 81 |
+ $authorlist[] = $auth['uid']; |
|
| 82 |
+ } |
|
| 83 |
+ if(count($authorlist) > 0) {
|
|
| 84 |
+ $authors = implode(",",$authorlist);
|
|
| 85 |
+ $query = "SELECT stories.*, "._PENNAMEFIELD." as penname, stories.date as date, stories.updated as updated FROM ("._AUTHORTABLE.", ".TABLEPREFIX."fanfiction_stories as stories) LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE "._UIDFIELD." = stories.uid AND stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0) ";
|
|
| 86 |
+ $countquery = "SELECT COUNT(stories.sid) FROM ".TABLEPREFIX."fanfiction_stories as stories LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as coauth ON coauth.sid = stories.sid WHERE stories.validated > 0 AND (FIND_IN_SET(stories.uid, '$authors') > 0 OR FIND_IN_SET(coauth.uid, '$authors') > 0)"; |
|
| 87 |
+ search($query, $countquery); |
|
| 88 |
+ $tpl->assign("output", $output);
|
|
| 89 |
+ $tpl->printToScreen(); |
|
| 90 |
+ dbclose( ); |
|
| 91 |
+ exit( ); |
|
| 92 |
+ } |
|
| 93 |
+ else {
|
|
| 94 |
+ $query[] = "1 = 0"; |
|
| 95 |
+ $countquery[] = "1 = 0"; |
|
| 96 |
+ $scountquery[] = "1 = 0"; |
|
| 97 |
+ } |
|
| 98 |
+ } |
|
| 99 |
+ if($searchtype == "advanced") {
|
|
| 100 |
+ $query[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') "; |
|
| 101 |
+ $countquery[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') "; |
|
| 102 |
+ $scountquery[] = "(summary LIKE '%$searchterm%' OR title LIKE '%$searchterm%') "; |
|
| 103 |
+ } |
|
| 104 |
+ } |
|
| 105 |
+ if(isset($_REQUEST['authors'])) {
|
|
| 106 |
+ $authors = isarray($_REQUEST['authors']) ? $_REQUEST['authors'] : explode(",", $_REQUEST['authors']);
|
|
| 107 |
+ $authors = array_filter($authors, "isNumber"); |
|
| 108 |
+ if($authors) {
|
|
| 109 |
+ $authors = implode(",", $authors);
|
|
| 110 |
+ $query[] = "FIND_IN_SET(stories.uid, '$authors') > 0"; |
|
| 111 |
+ $countquery[] = "FIND_IN_SET(stories.uid, '$authors') > 0"; |
|
| 112 |
+ $scountquery[] = "FIND_IN_SET(series.uid, '$authors') > 0"; |
|
| 113 |
+ } |
|
| 114 |
+ else {
|
|
| 115 |
+ $query[] = "1 = 0"; |
|
| 116 |
+ $countquery[] = "1 = 0"; |
|
| 117 |
+ $scountquery[] = "1 = 0"; |
|
| 118 |
+ } |
|
| 119 |
+ } |
|
| 120 |
+ if(isset($_REQUEST['catid'])) {
|
|
| 121 |
+ $catid = is_array($_REQUEST['catid']) ? $_REQUEST['catid'] : explode(",", $_REQUEST['catid']);
|
|
| 122 |
+ $catid = array_filter($catid, "isNumber"); |
|
| 123 |
+ } |
|
| 124 |
+ if(!isset($catid)) $catid = array("false");
|
|
| 125 |
+ $categories = array( ); |
|
| 126 |
+ // Get the recursive list. |
|
| 127 |
+ foreach($catid as $cat) {
|
|
| 128 |
+ if($cat == "false" || empty($cat)) continue; |
|
| 129 |
+ $categories = array_merge($categories, recurseCategories($cat)); |
|
| 130 |
+ } |
|
| 131 |
+ // Now format the SQL |
|
| 132 |
+ foreach($categories as $cat) {
|
|
| 133 |
+ $catstories[] = "FIND_IN_SET($cat, stories.catid) > 0 "; |
|
| 134 |
+ $catseries[] = "FIND_IN_SET($cat, series.catid) > 0 "; |
|
| 135 |
+ } |
|
| 136 |
+ // Now implode the SQL list |
|
| 137 |
+ if(!empty($catstories)) {
|
|
| 138 |
+ $query[] = "(".implode(" OR ", $catstories).")";
|
|
| 139 |
+ $countquery[] = "(".implode(" OR ", $catstories).")";
|
|
| 140 |
+ $scountquery[] = "(".implode(" OR ", $catseries).")";
|
|
| 141 |
+ } |
|
| 142 |
+ if(isset($_REQUEST['charid'])) {
|
|
| 143 |
+ $charid = is_array($_REQUEST['charid']) ? $_REQUEST['charid'] : explode(",", $_REQUEST['charid']);
|
|
| 144 |
+ } |
|
| 145 |
+ else $charid = array( ); |
|
| 146 |
+ if(isset($_REQUEST['charlist1'])) $charid[] = $_REQUEST['charlist1']; |
|
| 147 |
+ if(isset($_REQUEST['charlist2'])) $charid[] = $_REQUEST['charlist2']; |
|
| 148 |
+ $charid = array_filter($charid, "isNumber"); |
|
| 149 |
+ if(count($charid) > 0) {
|
|
| 150 |
+ foreach($charid as $c) {
|
|
| 151 |
+ if(!empty($c)) {
|
|
| 152 |
+ $charstories[] = "FIND_IN_SET($c, stories.charid) > 0 "; |
|
| 153 |
+ $charseries[] = "FIND_IN_SET($c, series.characters) > 0 "; |
|
| 154 |
+ } |
|
| 155 |
+ } |
|
| 156 |
+ if(count($charstories) > 0) {
|
|
| 157 |
+ $query[] = "(".implode(" AND ", $charstories).")";
|
|
| 158 |
+ $countquery[] = "(".implode(" AND ", $charstories).")";
|
|
| 159 |
+ } |
|
| 160 |
+ if(count($charseries) > 0) $scountquery[] = "(".implode(" AND ", $charseries).")";
|
|
| 161 |
+ } |
|
| 162 |
+ |
|
| 163 |
+ if(isset($_REQUEST['rid'])) $rid = is_array($_REQUEST['rid']) ? $_REQUEST['rid'] : explode(",", $_REQUEST['rid']);
|
|
| 164 |
+ else $rid = array(); |
|
| 165 |
+ if(count($rid) > 0) {
|
|
| 166 |
+ $rid = array_filter($rid, "isNumber"); |
|
| 167 |
+ $query[] = findclause('rid', $rid);
|
|
| 168 |
+ $countquery[] = findclause('rid', $rid);
|
|
| 169 |
+ } |
|
| 170 |
+ if(isset($_REQUEST['complete'])) {
|
|
| 171 |
+ $query[] = "stories.completed = '1'"; |
|
| 172 |
+ $countquery[] = "stories.completed = '1'"; |
|
| 173 |
+ } |
|
| 174 |
+ $classin = array( ); |
|
| 175 |
+ $classex = array( ); |
|
| 176 |
+ foreach($classtypelist as $id => $vars) {
|
|
| 177 |
+ $opts = array( ); |
|
| 178 |
+ $exopts = array( ); |
|
| 179 |
+ if(isset($_POST["class_".$id])) $opts = array_filter($_POST["class_".$id], "isNumber"); |
|
| 180 |
+ else if(isset($_GET["class_".$id])) {
|
|
| 181 |
+ $opts = array_merge($opts, explode(",", $_GET["class_".$id]));
|
|
| 182 |
+ $opts = array_filter($opts, "isNumber"); |
|
| 183 |
+ } |
|
| 184 |
+ else if(isset($_REQUEST[$vars["name"]])) $opts[] = array($_REQUEST[$vars["name"]]); |
|
| 185 |
+ $classin = array_merge($classin, $opts); |
|
| 186 |
+ if(isset($_POST["exclass_".$id])) $exopts = array_filter($_POST["exclass_".$id], "isNumber"); |
|
| 187 |
+ else if(isset($_GET["exclass_".$id])) {
|
|
| 188 |
+ $exopts = array_merge($exopts, explode(",", $_GET["exclass_".$id]));
|
|
| 189 |
+ $exopts = array_filter($exopts, "isNumber"); |
|
| 190 |
+ } |
|
| 191 |
+ $classex = array_merge($classex, $exopts); |
|
| 192 |
+ unset($opts, $exopts); |
|
| 193 |
+ } |
|
| 194 |
+ if($classin) {
|
|
| 195 |
+ foreach($classin as $class) {
|
|
| 196 |
+ $query[] = "FIND_IN_SET($class, stories.classes) > 0"; |
|
| 197 |
+ $countquery[] = "FIND_IN_SET($class, stories.classes) > 0"; |
|
| 198 |
+ $scountquery[] = "FIND_IN_SET($class, series.classes) > 0"; |
|
| 199 |
+ } |
|
| 200 |
+ } |
|
| 201 |
+ if($classex) {
|
|
| 202 |
+ foreach($classex as $class) {
|
|
| 203 |
+ $query[] = "FIND_IN_SET($class, stories.classes) = 0"; |
|
| 204 |
+ $countquery[] = "FIND_IN_SET($class, stories.classes) = 0"; |
|
| 205 |
+ $scountquery[] = "FIND_IN_SET($class, series.classes) = 0"; |
|
| 206 |
+ } |
|
| 207 |
+ } |
|
| 208 |
+ // Begin story length |
|
| 209 |
+ unset($wordcount); |
|
| 210 |
+ $wordlow = isset($_REQUEST['wordlow']) && isNumber($_REQUEST['wordlow']) ? $_REQUEST['wordlow'] : "-500"; |
|
| 211 |
+ $wordhigh = isset($_REQUEST['wordhigh']) && isNumber($_REQUEST['wordhigh']) ? $_REQUEST['wordhigh'] : "1000000"; |
|
| 212 |
+ if($wordlow != "-500") $wordcount = "stories.wordcount > ".$wordlow; |
|
| 213 |
+ if($wordhigh != "1000000") |
|
| 214 |
+ {
|
|
| 215 |
+ if($wordcount) $wordcount .= " AND stories.wordcount < ".$wordhigh; |
|
| 216 |
+ else $wordcount = "stories.wordcount < ".$wordhigh; |
|
| 217 |
+ } |
|
| 218 |
+ if($wordhigh < $wordlow) $wordcount = "stories.wordcount < ".$wordlow; |
|
| 219 |
+ if(!empty($wordcount)) {
|
|
| 220 |
+ $query[] = "($wordcount)"; |
|
| 221 |
+ $countquery[] = "($wordcount)"; |
|
| 222 |
+ } |
|
| 223 |
+ // End wordcount |
|
| 224 |
+ |
|
| 225 |
+ $codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browseterms'");
|
|
| 226 |
+ while($code = dbassoc($codeblocks)) {
|
|
| 227 |
+ eval($code['code_text']); |
|
| 228 |
+ } |
|
| 229 |
+ |
|
| 230 |
+ $query = (count($query) > 0 ? " AND ".implode(" AND ", $query) : "")." "._ORDERBY;
|
|
| 231 |
+ $countquery = count($countquery) > 0 ? " AND ".implode(" AND ", $countquery) : "";
|
|
| 232 |
+ if(count($scountquery) > 0) $scountquery = " WHERE ".implode(" AND ", $scountquery);
|
|
| 233 |
+ search(_STORYQUERY.$query, _STORYCOUNT.$countquery); |
|
| 234 |
+ $otherresults = array( ); |
|
| 235 |
+ $termArray = array_merge($_GET, $_POST); |
|
| 236 |
+ $termsList = array(); |
|
| 237 |
+ foreach($termArray as $term => $value) {
|
|
| 238 |
+ if($term == "submit" || $term == "wordhigh" || $term == "wordlow" || empty($value) || $term == "formname" || $term == "searchtype") continue; |
|
| 239 |
+ $termsList[$term] = "$term=".(is_array($value) ? implode(",", $value) : $value);
|
|
| 240 |
+ } |
|
| 241 |
+ $terms = implode("&", $termsList);
|
|
| 242 |
+ if(!empty($scountquery)) {
|
|
| 243 |
+ $seriesresults = dbquery(_SERIESCOUNT.$scountquery); |
|
| 244 |
+ list($scount) = dbrow($seriesresults); |
|
| 245 |
+ if($scount > 0) $otherresults[] = "<a href='browse.php?type=series$terms'>$scount "._SERIES."</a>"; |
|
| 246 |
+ } |
|
| 247 |
+ $codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
|
|
| 248 |
+ while($code = dbassoc($codeblocks)) {
|
|
| 249 |
+ eval($code['code_text']); |
|
| 250 |
+ } |
|
| 251 |
+ if(count($otherresults) > 0) $tpl->assign("otherresults", "<div id='otherresults'><span class='label'>"._OTHERRESULTS.":</span> ".implode(", ", $otherresults)."</div>");
|
|
| 252 |
+} |
|
| 253 |
+else {
|
|
| 254 |
+ if($searchtype == "simple") {
|
|
| 255 |
+ $output .= "<div id=\"pagetitle\">"._SIMPLE."</div><div style='text-align: center;'><form method=\"post\" enctype=\"multipart/form-data\" action=\"search.php\"> |
|
| 256 |
+ <div class=\"tblborder\" style=\"width: 320px; padding: 5px; margin: 0 auto;\"> |
|
| 257 |
+ <select name=\"searchtype\"> |
|
| 258 |
+ <option value=\"penname\">"._PENNAME."</option> |
|
| 259 |
+ <option value=\"title\">"._TITLE."</option> |
|
| 260 |
+ <option value=\"summary\">"._SUMMARY."</option>"; |
|
| 261 |
+ if($store == "mysql") |
|
| 262 |
+ $output .= "<option value=\"fulltext\">"._FULLTEXT."</option>"; |
|
| 263 |
+ $output .= "</select> <INPUT type=\"text\" class=\"textbox\" name=\"searchterm\" size=\"20\"> "; |
|
| 264 |
+ $output .= "<INPUT type=\"submit\" class=\"button\" name=\"submit\" value=\""._SUBMIT."\" size=\"20\"> |
|
| 265 |
+ <div style=\"font-size: 8pt; text-align: right;\"><a href=\"search.php?searchtype=advanced\">"._ADVANCED."</a></div></div></form></div>"; |
|
| 266 |
+ } |
|
| 267 |
+ else {
|
|
| 268 |
+ $output .= "<div id=\"pagetitle\">"._ADVANCED."</div><div> |
|
| 269 |
+ <form method=\"POST\" name=\"form\" enctype=\"multipart/form-data\" action=\"search.php?searchtype=advanced\"> |
|
| 270 |
+ <div class=\"tblborder\" style=\"width: 90%; margin: 0 auto; padding: 10px;\">"; |
|
| 271 |
+ if($multiplecats) {
|
|
| 272 |
+ include("includes/categories.php");
|
|
| 273 |
+ $output .= "<input type=\"hidden\" name=\"formname\" value=\"search\">"; |
|
| 274 |
+ } |
|
| 275 |
+ $output .= "<div style='float: left; width: 99%;'>"; |
|
| 276 |
+ if(count($charlist) > 0) {
|
|
| 277 |
+ $output .= "<div style=\"float: left; width: 49%;\"><label for=\"charname\">"._CHARACTERS.": </label><br />\n"; |
|
| 278 |
+ $output .= "<select name=\"charid[]\" style=\"width: 90%;\" multiple size=\"5\" id=\"charid\">"; |
|
| 279 |
+ foreach($charlist as $charid => $info) {
|
|
| 280 |
+ if($info['catid'] != -1) continue; |
|
| 281 |
+ $output .= "<option value=\"".$charid."\">" .stripslashes($info['name'] ). "</option>\n"; |
|
| 282 |
+ } |
|
| 283 |
+ $output .= "</select></div>"; |
|
| 284 |
+ } |
|
| 285 |
+ $result = dbquery("SELECT rid, rating FROM ".TABLEPREFIX."fanfiction_ratings ORDER BY rating");
|
|
| 286 |
+ if(dbnumrows($result)) {
|
|
| 287 |
+ $output .= "<div style=\"float: left; width: 49%;\"><label for=\"rid\">"._RATINGS.":</label><br /><select id=\"rid\" style=\"width: 90%;\" multiple size=\"5\"name=\"rid[]\"><option value=\"-1\">"._ALL."</option>"; |
|
| 288 |
+ while ($ratingresults = dbassoc($result)) |
|
| 289 |
+ {
|
|
| 290 |
+ $output .= "<option value=\"".$ratingresults['rid']."\">".$ratingresults['rating']."</option>\n"; |
|
| 291 |
+ } |
|
| 292 |
+ $output .= "</select></div>"; |
|
| 293 |
+ } |
|
| 294 |
+ $output .= "<div style=\"clear: both;\"> </div>"; |
|
| 295 |
+ $output .= " <div style=\"text-align: center;\">"._MULTIPLESELECT."</div>"; |
|
| 296 |
+ $result = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_classtypes ORDER BY classtype_name");
|
|
| 297 |
+ while($type = dbassoc($result)) {
|
|
| 298 |
+ $result2 = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_classes WHERE class_type = '".$type['classtype_id']."' ORDER BY class_name");
|
|
| 299 |
+ $select = ""; |
|
| 300 |
+ while ($class = dbassoc($result2)) {
|
|
| 301 |
+ $select .= "<option value=\"".$class['class_id']."\">".$class['class_name']."</option>"; |
|
| 302 |
+ } |
|
| 303 |
+ $output .= "<div> |
|
| 304 |
+ <div style=\"float: left; width: 49%; margin-bottom: 1em;\"><label for=\"class_".$type['classtype_id']."\">".$type['classtype_title']." "._INCLUDE.":</label><br /> |
|
| 305 |
+ <select name=\"class_".$type['classtype_id']."[]\" id=\"class_".$type['classtype_id']."\" style=\"width: 95%;\" multiple size=\"5\">$select</select></div> |
|
| 306 |
+ <div style=\"float: left; width: 49%; margin-bottom: 1em;\"><label for=\"exclass_".$type['classtype_id']."\">".$type['classtype_title']." "._EXCLUDE.":</label><br /> |
|
| 307 |
+ <select name=\"exclass_".$type['classtype_id']."[]\" id=\"exclass_".$type['classtype_id']."\" style=\"width: 95%;\" multiple size=\"5\">$select</select></div> |
|
| 308 |
+ </div>"; |
|
| 309 |
+ } |
|
| 310 |
+ $output .= "</div><label for=\"completed\">"._COMPLETEONLY.":</label> <input type=\"checkbox\" class=\"checkbox\" id=\"completed\" name=\"completed\" value=\"ON\"><label for=\"wordlow\">"._WORDCOUNT.":</label> <select size=\"1\" id=\"wordlow\" name=\"wordlow\"> |
|
| 311 |
+ <option value='-500'>< 500</option> |
|
| 312 |
+ <option>1000</option> |
|
| 313 |
+ <option>5000</option> |
|
| 314 |
+ <option>10000</option> |
|
| 315 |
+ <option>50000</option> |
|
| 316 |
+ <option>100000</option> |
|
| 317 |
+ <option value='1000000'>100000+</option> |
|
| 318 |
+ </select> - <select size=\"1\" name=\"wordhigh\"> |
|
| 319 |
+ <option value='1000000'>100000+</option> |
|
| 320 |
+ <option>100000</option> |
|
| 321 |
+ <option>50000</option> |
|
| 322 |
+ <option>10000</option> |
|
| 323 |
+ <option>5000</option> |
|
| 324 |
+ <option>1000</option> |
|
| 325 |
+ <option value='-500'>< 500</option> |
|
| 326 |
+ </select><br /><br /><label for=\"searchterm\">"._SEARCHTERM.": </label><INPUT type=\"text\" class=\"textbox\" name=\"searchterm\" id=\"searchterm\" size=\"20\"> |
|
| 327 |
+ |
|
| 328 |
+ <label for=\"sortorder\">"._SORT.":</label> <select name=\"sortorder\" id=\"sortorder\"><option value=\"alpha\">"._ALPHA."</option><option value=\"update\">"._MOSTRECENT."</option></select>"; |
|
| 329 |
+ $codequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'searchform'");
|
|
| 330 |
+ while($code = dbassoc($codequery)) {
|
|
| 331 |
+ eval($code['code_text']); |
|
| 332 |
+ } |
|
| 333 |
+$output .= "<div id='submitdiv'><input name=\"submit\" id=\"submit\" value=\""._SUBMIT."\" type=\"submit\" class=\"button\"></div></div></form></div>"; |
|
| 334 |
+ } |
|
| 335 |
+} |
|
| 336 |
+$tpl->assign("output", $output);
|
|
| 337 |
+$tpl->printToScreen(); |
|
| 338 |
+dbclose( ); |
|
| 339 |
+?> |
|
| 0 | 340 |
\ No newline at end of file |