Browse code

search/searching file

Jimako authored on 2023/09/07 15:30:42
Showing 1 changed files
... ...
@@ -21,330 +21,293 @@
21 21
 // To read the license please visit http://www.gnu.org/copyleft/gpl.html
22 22
 // ----------------------------------------------------------------------
23 23
 
24
+
24 25
 // Page Setup
25 26
 // Set the current page id.  Because search does multiple things there are multiple possibilities
26
-if (isset($_POST['submit']) || isset($_GET['offset'])) {
27
-    $current = 'searchresults';
28
-} else {
29
-    $current = 'search';
30
-}
31
-if (isset($_GET['action']) && $_GET['action'] == 'advanced') {
32
-    $displayform = 1;
33
-}
27
+if(isset($_POST['submit']) || isset($_GET['offset'])) $current = "searchresults";
28
+else $current = "search";
29
+if(isset($_GET['action']) && $_GET['action'] == "advanced") $displayform = 1;
34 30
 // Now set up the page
35 31
 
36 32
 $displayform = 1;
37 33
 
38
-include 'header.php';
39 34
 
40
-if (file_exists("$skindir/browse.tpl")) {
41
-    $tpl = new TemplatePower("$skindir/browse.tpl");
42
-} else {
43
-    $tpl = new TemplatePower('default_tpls/browse.tpl');
44
-}
45
-if (file_exists("$skindir/listings.tpl")) {
46
-    $tpl->assignInclude('listings', "./$skindir/listings.tpl");
47
-} else {
48
-    $tpl->assignInclude('listings', './default_tpls/listings.tpl');
49
-}
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" );
50 41
 
51
-include 'includes/pagesetup.php';
42
+include("includes/pagesetup.php");
52 43
 
53
-$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : 'simple');
54
-$searchterm = (isset($_REQUEST['searchterm']) ? escapestring($_REQUEST['searchterm']) : false);
55 44
 
56
-if (isset($_POST['submit']) || isset($_GET['offset'])) {
57
-    $output .= '<div id="pagetitle">'._RESULTS.'</div>';
58
-    $query = array();
59
-    $countquery = array();
60
-    $scountquery = array();
61
-    if ($searchtype == 'fulltext') {
62
-        $query = 'SELECT stories.*, '._PENNAMEFIELD.' as penname, UNIX_TIMESTAMP(stories.date) as date, UNIX_TIMESTAMP(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;
63
-        $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";
64
-        $query .= ' '._ORDERBY;
65
-        search($query, $countquery);
66
-        $tpl->assign('output', $output);
67
-        $tpl->printToScreen();
68
-        dbclose();
69
-        exit();
70
-    }
71
-    if ($searchterm && strlen($searchterm) < 3) {
72
-        errorExit(_SEARCHTERMTOOSHORT);
73
-    }
74
-    if ($searchterm) {
75
-        if ($searchtype == 'title') {
76
-            $query[] = "stories.title LIKE '%$searchterm%'";
77
-            $countquery[] = "stories.title LIKE '%$searchterm%'";
78
-            $scountquery[] = "series.title LIKE '%$searchterm%'";
79
-        }
80
-        if ($searchtype == 'summary') {
81
-            $query[] = "stories.summary LIKE '%$searchterm%'";
82
-            $countquery[] = "stories.summary LIKE '%$searchterm%'";
83
-            $scountquery[] = "series.summary LIKE '%$searchterm%'";
84
-        }
85
-        if ($searchtype == 'penname') {
86
-            $authorquery = dbquery(_MEMBERLIST.' WHERE '._PENNAMEFIELD." LIKE '%$searchterm%' GROUP BY "._UIDFIELD);
87
-            $authorlist = array();
88
-            while ($auth = dbassoc($authorquery)) {
89
-                $authorlist[] = $auth['uid'];
90
-            }
91
-            if (count($authorlist) > 0) {
92
-                $authors = implode(',', $authorlist);
93
-                $query = 'SELECT stories.*, '._PENNAMEFIELD.' as penname, UNIX_TIMESTAMP(stories.date) as date, UNIX_TIMESTAMP(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) ";
94
-                $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)";
95
-                search($query, $countquery);
96
-                $tpl->assign('output', $output);
97
-                $tpl->printToScreen();
98
-                dbclose();
99
-                exit();
100
-            } else {
101
-                $query[] = '1 = 0';
102
-                $countquery[] = '1 = 0';
103
-                $scountquery[] = '1 = 0';
104
-            }
105
-        }
106
-        if ($searchtype == 'advanced') {
107
-            $query[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') ";
108
-            $countquery[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') ";
109
-            $scountquery[] = "(summary LIKE '%$searchterm%' OR title LIKE '%$searchterm%') ";
110
-        }
111
-    }
112
-    if (isset($_REQUEST['authors'])) {
113
-        $authors = isarray($_REQUEST['authors']) ? $_REQUEST['authors'] : explode(',', $_REQUEST['authors']);
114
-        $authors = array_filter($authors, 'isNumber');
115
-        if ($authors) {
116
-            $authors = implode(',', $authors);
117
-            $query[] = "FIND_IN_SET(stories.uid, '$authors') > 0";
118
-            $countquery[] = "FIND_IN_SET(stories.uid, '$authors') > 0";
119
-            $scountquery[] = "FIND_IN_SET(series.uid, '$authors') > 0";
120
-        } else {
121
-            $query[] = '1 = 0';
122
-            $countquery[] = '1 = 0';
123
-            $scountquery[] = '1 = 0';
124
-        }
125
-    }
126
-    if (isset($_REQUEST['catid'])) {
127
-        $catid = is_array($_REQUEST['catid']) ? $_REQUEST['catid'] : explode(',', $_REQUEST['catid']);
128
-        $catid = array_filter($catid, 'isNumber');
129
-    }
130
-    if (!isset($catid)) {
131
-        $catid = array('false');
132
-    }
133
-    $categories = array();
134
-    // Get the recursive list.
135
-    foreach ($catid as $cat) {
136
-        if ($cat == 'false' || empty($cat)) {
137
-            continue;
138
-        }
139
-        $categories = array_merge($categories, recurseCategories($cat));
140
-    }
141
-    // Now format the SQL
142
-    foreach ($categories as $cat) {
143
-        $catstories[] = "FIND_IN_SET($cat, stories.catid) > 0 ";
144
-        $catseries[] = "FIND_IN_SET($cat, series.catid) > 0 ";
145
-    }
146
-    // Now implode the SQL list
147
-    if (!empty($catstories)) {
148
-        $query[] = '('.implode(' OR ', $catstories).')';
149
-        $countquery[] = '('.implode(' OR ', $catstories).')';
150
-        $scountquery[] = '('.implode(' OR ', $catseries).')';
151
-    }
152
-    if (isset($_REQUEST['charid'])) {
153
-        $charid = is_array($_REQUEST['charid']) ? $_REQUEST['charid'] : explode(',', $_REQUEST['charid']);
154
-    } else {
155
-        $charid = array();
156
-    }
157
-    if (isset($_REQUEST['charlist1'])) {
158
-        $charid[] = $_REQUEST['charlist1'];
159
-    }
160
-    if (isset($_REQUEST['charlist2'])) {
161
-        $charid[] = $_REQUEST['charlist2'];
162
-    }
163
-    $charid = array_filter($charid, 'isNumber');
164
-    if (count($charid) > 0) {
165
-        foreach ($charid as $c) {
166
-            if (!empty($c)) {
167
-                $charstories[] = "FIND_IN_SET($c, stories.charid) > 0 ";
168
-                $charseries[] = "FIND_IN_SET($c, series.characters) > 0 ";
169
-            }
170
-        }
171
-        if (count($charstories) > 0) {
172
-            $query[] = '('.implode(' AND ', $charstories).')';
173
-            $countquery[] = '('.implode(' AND ', $charstories).')';
174
-        }
175
-        if (count($charseries) > 0) {
176
-            $scountquery[] = '('.implode(' AND ', $charseries).')';
177
-        }
178
-    }
45
+$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple");
46
+$searchterm =  (isset($_REQUEST['searchterm']) ? escapestring($_REQUEST['searchterm']) : false);
179 47
 
180
-    if (isset($_REQUEST['rid'])) {
181
-        $rid = is_array($_REQUEST['rid']) ? $_REQUEST['rid'] : explode(',', $_REQUEST['rid']);
182
-    } else {
183
-        $rid = array();
184
-    }
185
-    if (count($rid) > 0) {
186
-        $rid = array_filter($rid, 'isNumber');
187
-        $query[] = findclause('rid', $rid);
188
-        $countquery[] = findclause('rid', $rid);
189
-    }
190
-    if (isset($_REQUEST['complete'])) {
191
-        $query[] = "stories.completed = '1'";
192
-        $countquery[] = "stories.completed = '1'";
193
-    }
194
-    $classin = array();
195
-    $classex = array();
196
-    foreach ($classtypelist as $id => $vars) {
197
-        $opts = array();
198
-        $exopts = array();
199
-        if (isset($_POST['class_'.$id])) {
200
-            $opts = array_filter($_POST['class_'.$id], 'isNumber');
201
-        } elseif (isset($_GET['class_'.$id])) {
202
-            $opts = array_merge($opts, explode(',', $_GET['class_'.$id]));
203
-            $opts = array_filter($opts, 'isNumber');
204
-        } elseif (isset($_REQUEST[$vars['name']])) {
205
-            $opts[] = array($_REQUEST[$vars['name']]);
206
-        }
207
-        $classin = array_merge($classin, $opts);
208
-        if (isset($_POST['exclass_'.$id])) {
209
-            $exopts = array_filter($_POST['exclass_'.$id], 'isNumber');
210
-        } elseif (isset($_GET['exclass_'.$id])) {
211
-            $exopts = array_merge($exopts, explode(',', $_GET['exclass_'.$id]));
212
-            $exopts = array_filter($exopts, 'isNumber');
213
-        }
214
-        $classex = array_merge($classex, $exopts);
215
-        unset($opts, $exopts);
216
-    }
217
-    if ($classin) {
218
-        foreach ($classin as $class) {
219
-            $query[] = "FIND_IN_SET($class, stories.classes) > 0";
220
-            $countquery[] = "FIND_IN_SET($class, stories.classes) > 0";
221
-            $scountquery[] = "FIND_IN_SET($class, series.classes) > 0";
222
-        }
223
-    }
224
-    if ($classex) {
225
-        foreach ($classex as $class) {
226
-            $query[] = "FIND_IN_SET($class, stories.classes) = 0";
227
-            $countquery[] = "FIND_IN_SET($class, stories.classes) = 0";
228
-            $scountquery[] = "FIND_IN_SET($class, series.classes) = 0";
229
-        }
230
-    }
231
-    // Begin story length
232
-    unset($wordcount);
233
-    $wordlow = isset($_REQUEST['wordlow']) && isNumber($_REQUEST['wordlow']) ? $_REQUEST['wordlow'] : '-500';
234
-    $wordhigh = isset($_REQUEST['wordhigh']) && isNumber($_REQUEST['wordhigh']) ? $_REQUEST['wordhigh'] : '1000000';
235
-    if ($wordlow != '-500') {
236
-        $wordcount = 'stories.wordcount > '.$wordlow;
237
-    }
238
-    if ($wordhigh != '1000000') {
239
-        if ($wordcount) {
240
-            $wordcount .= ' AND stories.wordcount < '.$wordhigh;
241
-        } else {
242
-            $wordcount = 'stories.wordcount < '.$wordhigh;
243
-        }
244
-    }
245
-    if ($wordhigh < $wordlow) {
246
-        $wordcount = 'stories.wordcount < '.$wordlow;
247
-    }
248
-    if (!empty($wordcount)) {
249
-        $query[] = "($wordcount)";
250
-        $countquery[] = "($wordcount)";
251
-    }
252
-    // End wordcount
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
+	}
253 162
 
254
-    $codeblocks = dbquery('SELECT * FROM '.TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browseterms'");
255
-    while ($code = dbassoc($codeblocks)) {
256
-        eval($code['code_text']);
257
-    }
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
258 224
 
259
-    $query = (count($query) > 0 ? ' AND '.implode(' AND ', $query) : '').' '._ORDERBY;
260
-    $countquery = count($countquery) > 0 ? ' AND '.implode(' AND ', $countquery) : '';
261
-    if (count($scountquery) > 0) {
262
-        $scountquery = ' WHERE '.implode(' AND ', $scountquery);
263
-    }
264
-    search(_STORYQUERY.$query, _STORYCOUNT.$countquery);
265
-    $otherresults = array();
266
-    $termArray = array_merge($_GET, $_POST);
267
-    $termsList = array();
268
-    foreach ($termArray as $term => $value) {
269
-        if ($term == 'submit' || $term == 'wordhigh' || $term == 'wordlow' || empty($value) || $term == 'formname' || $term == 'searchtype') {
270
-            continue;
271
-        }
272
-        $termsList[$term] = "$term=".(is_array($value) ? implode(',', $value) : $value);
273
-    }
274
-    $terms = implode('&amp;', $termsList);
275
-    if (!empty($scountquery)) {
276
-        $seriesresults = dbquery(_SERIESCOUNT.$scountquery);
277
-        list($scount) = dbrow($seriesresults);
278
-        if ($scount > 0) {
279
-            $otherresults[] = "<a href='browse.php?type=series$terms'>$scount "._SERIES.'</a>';
280
-        }
281
-    }
282
-    $codeblocks = dbquery('SELECT * FROM '.TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
283
-    while ($code = dbassoc($codeblocks)) {
284
-        eval($code['code_text']);
285
-    }
286
-    if (count($otherresults) > 0) {
287
-        $tpl->assign('otherresults', "<div id='otherresults'><span class='label'>"._OTHERRESULTS.':</span> '.implode(', ', $otherresults).'</div>');
288
-    }
289
-} else {
290
-    if ($searchtype == 'simple') {
291
-        $output .= '<div id="pagetitle">'._SIMPLE."</div><div style='text-align: center;'><form method=\"post\" enctype=\"multipart/form-data\" action=\"searching.php\">
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("&amp;", $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\">
292 256
 		<div class=\"tblborder\" style=\"width: 320px; padding: 5px; margin: 0 auto;\">
293 257
 		<select name=\"searchtype\">
294
-		<option value=\"penname\">"._PENNAME.'</option>
295
-		<option value="title">'._TITLE.'</option>
296
-		<option value="summary">'._SUMMARY.'</option>';
297
-        if ($store == 'mysql') {
298
-            $output .= '<option value="fulltext">'._FULLTEXT.'</option>';
299
-        }
300
-        $output .= '</select> <INPUT type="text" class="textbox" name="searchterm" size="20"> ';
301
-        $output .= '<INPUT type="submit" class="button" name="submit" value="'._SUBMIT.'" size="20">
302
-		<div style="font-size: 8pt; text-align: right;"><a href="searching.php?searchtype=advanced">'._ADVANCED.'</a></div></div></form></div>';
303
-    } else {
304
-        $output .= '<div id="pagetitle">'._ADVANCED.'</div><div>
305
-			<form method="POST" name="form" enctype="multipart/form-data" action="searching.php?searchtype=advanced">
306
-			<div class="tblborder" style="width: 90%; margin: 0 auto; padding: 10px;">';
307
-        if ($multiplecats) {
308
-            include 'includes/categories.php';
309
-            $output .= '<input type="hidden" name="formname" value="search">';
310
-        }
311
-        $output .= "<div style='float: left; width: 99%;'>";
312
-        if (count($charlist) > 0) {
313
-            $output .= '<div style="float: left; width: 49%;"><label for="charname">'._CHARACTERS.": </label><br />\n";
314
-            $output .= '<select name="charid[]"  style="width: 90%;" multiple size="5" id="charid">';
315
-            foreach ($charlist as $charid => $info) {
316
-                if ($info['catid'] != -1) {
317
-                    continue;
318
-                }
319
-                $output .= '<option value="'.$charid.'">'.stripslashes($info['name'])."</option>\n";
320
-            }
321
-            $output .= '</select></div>';
322
-        }
323
-        $result = dbquery('SELECT rid, rating FROM '.TABLEPREFIX.'fanfiction_ratings ORDER BY rating');
324
-        if (dbnumrows($result)) {
325
-            $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>';
326
-            while ($ratingresults = dbassoc($result)) {
327
-                $output .= '<option value="'.$ratingresults['rid'].'">'.$ratingresults['rating']."</option>\n";
328
-            }
329
-            $output .= '</select></div>';
330
-        }
331
-        $output .= '<div style="clear: both;">&nbsp;</div>';
332
-        $output .= ' <div style="text-align: center;">'._MULTIPLESELECT.'</div>';
333
-        $result = dbquery('SELECT * FROM '.TABLEPREFIX.'fanfiction_classtypes ORDER BY classtype_name');
334
-        while ($type = dbassoc($result)) {
335
-            $result2 = dbquery('SELECT * FROM '.TABLEPREFIX."fanfiction_classes WHERE class_type = '".$type['classtype_id']."' ORDER BY class_name");
336
-            $select = '';
337
-            while ($class = dbassoc($result2)) {
338
-                $select .= '<option value="'.$class['class_id'].'">'.$class['class_name'].'</option>';
339
-            }
340
-            $output .= '<div>
341
-				<div style="float: left; width: 49%; margin-bottom: 1em;"><label for="class_'.$type['classtype_id'].'">'.$type['classtype_title'].' '._INCLUDE.':</label><br />
342
-					 <select name="class_'.$type['classtype_id'].'[]" id="class_'.$type['classtype_id']."\"  style=\"width: 95%;\" multiple size=\"5\">$select</select></div>
343
-				<div style=\"float: left; width: 49%; margin-bottom: 1em;\"><label for=\"exclass_".$type['classtype_id'].'">'.$type['classtype_title'].' '._EXCLUDE.':</label><br />
344
-					 <select name="exclass_'.$type['classtype_id'].'[]"  id="exclass_'.$type['classtype_id']."\"  style=\"width: 95%;\" multiple size=\"5\">$select</select></div>
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;\">&nbsp;</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>
345 308
 				</div>";
346
-        }
347
-        $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\">
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\">
348 311
   <option value='-500'>&lt; 500</option>
349 312
   <option>1000</option>
350 313
   <option>5000</option>
... ...
@@ -360,16 +323,17 @@ if (isset($_POST['submit']) || isset($_GET['offset'])) {
360 323
   <option>5000</option>
361 324
   <option>1000</option>
362 325
   <option value='-500'>&lt; 500</option>
363
-  </select><br /><br /><label for=\"searchterm\">"._SEARCHTERM.': </label><INPUT type="text" class="textbox" name="searchterm" id="searchterm" size="20">
326
+  </select><br /><br /><label for=\"searchterm\">"._SEARCHTERM.": </label><INPUT type=\"text\" class=\"textbox\" name=\"searchterm\" id=\"searchterm\" size=\"20\">
364 327
   
365
-  <label for="sortorder">'._SORT.':</label> <select name="sortorder" id="sortorder"><option value="alpha">'._ALPHA.'</option><option value="update">'._MOSTRECENT.'</option></select>';
366
-        $codequery = dbquery('SELECT * FROM '.TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'searchform'");
367
-        while ($code = dbassoc($codequery)) {
368
-            eval($code['code_text']);
369
-        }
370
-        $output .= "<div id='submitdiv'><input name=\"submit\" id=\"submit\" value=\""._SUBMIT.'" type="submit" class="button"></div></div></form></div>';
371
-    }
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
+	}
372 335
 }
373
-$tpl->assign('output', $output);
336
+$tpl->assign("output", $output);
374 337
 $tpl->printToScreen();
375
-dbclose();
338
+dbclose( );
339
+?>
376 340
\ No newline at end of file