Browse code

browse.php, search.php: revert changes, as it breaks ePubVerstion support at this time

Clarissa Walker authored on 2026/11/02 11:28:07
Showing 1 changed files
... ...
@@ -1,377 +1,354 @@
1
-<?php
2
-// ----------------------------------------------------------------------
3
-// Copyright (c) 2007 by Tammy Keefer
4
-// Based on eFiction 1.1
5
-// Copyright (C) 2003 by Rebecca Smallwood.
6
-// http://efiction.sourceforge.net/
7
-// ----------------------------------------------------------------------
8
-// LICENSE
9
-//
10
-// This program is free software; you can redistribute it and/or
11
-// modify it under the terms of the GNU General Public License (GPL)
12
-// as published by the Free Software Foundation; either version 2
13
-// of the License, or (at your option) any later version.
14
-//
15
-// This program is distributed in the hope that it will be useful,
16
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
-// GNU General Public License for more details.
19
-//
20
-// To read the license please visit http://www.gnu.org/copyleft/gpl.html
21
-// ---------------------------------------------------------------------
22
-
23
-$current = "browse";
24
-$displayform = 1;
25
-
26
-include ("header.php");
27
-
28
-if(file_exists("$skindir/browse.tpl")) $tpl = new TemplatePower( "$skindir/browse.tpl" );
29
-else $tpl = new TemplatePower("default_tpls/browse.tpl");
30
-if(file_exists("$skindir/listings.tpl")) $tpl->assignInclude("listings", "./$skindir/listings.tpl");
31
-else $tpl->assignInclude( "listings", "./default_tpls/listings.tpl" );
32
-$tpl->assignInclude( "header", "./$skindir/header.tpl" );
33
-$tpl->assignInclude( "footer", "./$skindir/footer.tpl" );
34
-
35
-include("includes/pagesetup.php");
36
-if(isset($_GET['type']) && is_string($_GET['type']) && preg_match('/^[a-z0-9_]{1,40}$/i', $_GET['type'])) $type = $_GET['type'];
37
-else $type = false;
38
-
39
-if($type) {
40
-	$query = array();
41
-	$countquery = array();
42
-	$scountquery = array();
43
-	$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple");
44
-	//if(!is_string($searchtype) || (isset($_REQUEST['searchterm']) && !is_string($_REQUEST['searchterm']))) errorExit(_ERROR); // this crashes the series results.
45
-	//if(!in_array($searchtype, array("simple", "title", "summary", "penname", "advanced", "fulltext"), true)) errorExit(_ERROR); // this crashes the series results.
46
-	$searchterm = isset($_REQUEST['searchterm']) && $_REQUEST['searchterm'] !== "" ? $_REQUEST['searchterm'] : false;
47
-	//if($searchtype == "fulltext" || ($searchtype == "simple" && $searchterm !== false)) errorExit(_ERROR); // this crashes the series results.
48
-	if(($searchtype != "simple" && $searchtype != "advanced" && ($searchterm === false || trim($searchterm) === "")) || ($searchterm !== false && strlen($searchterm) < 3)) errorExit(_SEARCHTERMTOOSHORT);
49
-	if($searchterm !== false) $searchterm = escapestring(strtr($searchterm, array("!" => "!!", "%" => "!%", "_" => "!_")));
50
-	$disablesorts = array( );
51
-	if($searchterm !== false) {
52
-		if($searchtype == "title") {
53
-			$query[] = "stories.title LIKE '%$searchterm%' ESCAPE '!'";
54
-			$countquery[] = "stories.title LIKE '%$searchterm%' ESCAPE '!'";
55
-			$scountquery[] = "series.title LIKE '%$searchterm%' ESCAPE '!'";
56
-		}
57
-		if($searchtype == "summary") {
58
-			$query[] = "stories.summary LIKE '%$searchterm%' ESCAPE '!'";
59
-			$countquery[] = "stories.summary LIKE '%$searchterm%' ESCAPE '!'";
60
-			$scountquery[] = "series.summary LIKE '%$searchterm%' ESCAPE '!'";
61
-		}
62
-		if($searchtype == "penname") {
63
-			$authorquery = dbquery(_MEMBERLIST." WHERE "._PENNAMEFIELD." LIKE '%$searchterm%' ESCAPE '!' GROUP BY "._UIDFIELD);
64
-			$authorlist = array();
65
-			while($auth = dbassoc($authorquery)) {
66
-				$authorlist[] = $auth['uid'];
67
-			}
68
-			if(count($authorlist) > 0) {
69
-				$query[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
70
-				$countquery[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
71
-				$scountquery[] = "FIND_IN_SET(series.uid, '".implode(",",$authorlist)."') > 0";
72
-			}
73
-			else {
74
-				$query[] = "1 = 0"; $countquery[] = "1 = 0"; $scountquery[] = "1 = 0";
75
-			}
76
-		}
77
-		if($searchtype == "advanced" || !$searchtype) {
78
-			$query[] = "(stories.summary LIKE '%$searchterm%' ESCAPE '!' OR stories.title LIKE '%$searchterm%' ESCAPE '!') ";
79
-			$countquery[] = "(stories.summary LIKE '%$searchterm%' ESCAPE '!' OR stories.title LIKE '%$searchterm%' ESCAPE '!') ";
80
-			$scountquery[] = "(summary LIKE '%$searchterm%' ESCAPE '!' OR title LIKE '%$searchterm%' ESCAPE '!') ";
81
-		}
82
-	}
83
-	$ef_authors = isset($_REQUEST['authors']) ? array_filter(array_map('trim', is_array($_REQUEST['authors']) ? $_REQUEST['authors'] : explode(",", (string)$_REQUEST['authors'])), "isNumber") : array( );
84
-	if($ef_authors) {
85
-		$ef_authors = implode(",", array_map('intval', $ef_authors));
86
-		$query[] = "FIND_IN_SET(stories.uid, '".$ef_authors."') > 0";
87
-		$countquery[] = "FIND_IN_SET(stories.uid, '".$ef_authors."') > 0";
88
-		$scountquery[] = "FIND_IN_SET(series.uid, '".$ef_authors."') > 0";
89
-	}
90
-	if(isset($_REQUEST['catid'])) {
91
-		$catid = is_array($_REQUEST['catid']) ? $_REQUEST['catid'] : explode(",", $_REQUEST['catid']);
92
-		$catid = array_filter($catid, "isNumber");
93
-	}
94
-	if(!isset($catid)) $catid = array();
95
-	if($type == "categories" && isset($_GET['id']) && isNumber($_GET['id'])) {
96
-		$catid[] =  $_GET['id'];
97
-	}
98
-	$categories = array( );
99
-	// Get the recursive list.
100
-	if($type == "categories") $categories = $catid;
101
-	else {
102
-		foreach($catid as $cat) {
103
-			if($cat == "false" || empty($cat)) continue;
104
-			$categories = array_merge($categories, recurseCategories($cat));
105
-		}
106
-	}
107
-	// Now format the SQL
108
-	foreach($categories as $cat) {
109
-		$catstories[] = "FIND_IN_SET($cat, stories.catid) > 0 ";
110
-		$catseries[] = "FIND_IN_SET($cat, series.catid) > 0 ";
111
-	}
112
-	// Now implode the SQL list
113
-	if(!empty($catstories)) {
114
-		$query[] = "(".implode(" OR ", $catstories).")";
115
-		$countquery[] = "(".implode(" OR ", $catstories).")";
116
-		$scountquery[] = "(".implode(" OR ", $catseries).")";
117
-	}
118
-	if(empty($charid)) $charid = array( );
119
-	if(isset($_REQUEST['charid'])) {
120
-		$charid = is_array($_REQUEST['charid']) ? $_REQUEST['charid'] : explode(",", $_REQUEST['charid']);
121
-		$charid = array_filter($charid, "isNumber");
122
-	}
123
-	if(!empty($_REQUEST['charlist1']) && isNumber($_REQUEST['charlist1']) && !in_array($_REQUEST['charlist1'], $charid)) $charid[] = $_REQUEST['charlist1'];
124
-	if(!empty($_REQUEST['charlist2']) && isNumber($_REQUEST['charlist2']) && !in_array($_REQUEST['charlist2'], $charid)) $charid[] = $_REQUEST['charlist2'];
125
-	if($charid) {
126
-		foreach($charid as $c) {
127
-			if(!empty($c)) {
128
-				$charstories[] = "FIND_IN_SET($c, stories.charid) > 0 ";
129
-				$charseries[] = "FIND_IN_SET($c, series.characters) > 0 ";
130
-			}
131
-		}
132
-		if(!empty($charstories)) {
133
-			$query[] = "(".implode(" AND ", $charstories).")";
134
-			$countquery[] = "(".implode(" AND ", $charstories).")";
135
-		}
136
-		if(!empty($charseries)) $scountquery[] = "(".implode(" AND ", $charseries).")";
137
-	}
138
-	$rid = array( ); $rating = array( );
139
-	if(!empty($_REQUEST['rid'])) $rid = is_array($_REQUEST['rid']) ? $_REQUEST['rid'] : explode(",", (string)$_REQUEST['rid']);
140
-	if(!empty($_REQUEST['rating'])) $rating = is_array($_REQUEST['rating']) ? $_REQUEST['rating'] : explode(",", (string)$_REQUEST['rating']);
141
-	$rid = array_values(array_filter(array_merge((array)$rid, (array)$rating), "isNumber")); // eFiction 4: numbers only
142
-	if(!empty($rid)) {
143
-		$query[] = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
144
-		$countquery[]  = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
145
-	}
146
-	$complete = "all";
147
-	if(isset($_REQUEST['complete'])) {
148
-		if($_REQUEST['complete'] == 1) {
149
-			$query[] = "stories.completed = '1'";
150
-			$countquery[] = "stories.completed = '1'";
151
-			$complete = 1;
152
-		} 
153
-		else if(empty($_REQUEST['complete'])) {
154
-			$query[] = "stories.completed = '0'";
155
-			$countquery[] = "stories.completed = '0'";
156
-			$complete = 0;
157
-		} 
158
-	}
159
-	if(isset($_REQUEST['classin'])) $classin = ef_browse_ids($_REQUEST['classin']);
160
-	else $classin = array( );
161
-	if(isset($_REQUEST['classex'])) $classex = ef_browse_ids($_REQUEST['classex']);
162
-	else $classex = array( );
163
-	$opts = array();
164
-	$exopts = array( );
165
-	foreach($classtypelist as $id => $vars) {
166
-		$opts = array(); $exopts = array();
167
-		if(isset($_REQUEST["class_".$id])) $opts = ef_browse_ids($_REQUEST["class_".$id]);
168
-		else if(isset($_REQUEST[$vars["name"]])) $opts = ef_browse_ids($_REQUEST[$vars["name"]]);
169
-		if(!empty($opts)) $classin = array_merge($classin, $opts);
170
-		if(isset($_REQUEST["exclass_".$id])) $exopts = ef_browse_ids($_REQUEST["exclass_".$id]);
171
-		if(!empty($exopts)) $classex = array_merge($classex, $exopts);
172
-		unset($opts, $exopts);
173
-	}
174
-	$classin = array_filter($classin, "isNumber");
175
-	$classex = array_filter($classex, "isNumber");
176
-	if($classin) {
177
-		foreach($classin as $class) {
178
-			if(empty($class)) continue;
179
-			$query[] = "FIND_IN_SET($class, stories.classes) > 0";
180
-			$countquery[] = "FIND_IN_SET($class, stories.classes) > 0";
181
-			$scountquery[] = "FIND_IN_SET($class, series.classes) > 0";
182
-		}
183
-	}
184
-	if($classex) {
185
-		foreach($classex as $class) {
186
-			$query[] = "FIND_IN_SET($class, stories.classes) = 0";
187
-			$countquery[] = "FIND_IN_SET($class, stories.classes) = 0";
188
-			$scountquery[] = "FIND_IN_SET($class, series.classes) = 0";
189
-		}
190
-	}
191
-	// Begin story length
192
-	unset($wordcount);
193
-	$wordlow = isset($_REQUEST['wordlow']) && preg_match('/^-?[0-9]{1,9}$/', (string)$_REQUEST['wordlow']) ? $_REQUEST['wordlow'] : "-500";
194
-	$wordhigh = isset($_REQUEST['wordhigh']) && preg_match('/^[0-9]{1,9}$/', (string)$_REQUEST['wordhigh']) ? $_REQUEST['wordhigh'] : "1000000";
195
-	if($wordlow != "-500") $wordcount = "stories.wordcount > ".$wordlow;
196
-	if($wordhigh != "1000000") 
197
-	{
198
-		if($wordcount) $wordcount .= " AND stories.wordcount < ".$wordhigh;
199
-		else $wordcount = "stories.wordcount < ".$wordhigh;
200
-	}
201
-	if($wordhigh < $wordlow) $wordcount = "stories.wordcount < ".$wordlow;
202
-	if($wordlow != "-500" && $wordhigh != "1000000" && isset($_POST['submit'])) {
203
-		$query[] = "($wordcount)";
204
-		$countquery[] = "($wordcount)";
205
-	}
206
-	// End wordcount
207
-	$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browseterms'");
208
-	while($code = dbassoc($codeblocks)) {
209
-		eval($code['code_text']);
210
-	}
211
-	$storyquery = count($query) > 0 ? " AND ".implode(" AND ", $query) : "";
212
-	$countquery = count($countquery) > 0 ? " AND ".implode(" AND ", $countquery) : "";
213
-	$seriesquery = count($scountquery) > 0 ? implode(" AND ", $scountquery) : false;
214
-	$termArray = array_merge($_GET, $_POST);
215
-	$termsList = array();
216
-	foreach($termArray as $term => $value) {
217
-		if($term == "submit" || $term == "go" || $term == "offset" || $term == "type" || ($term != "complete" && empty($value))) continue;
218
-		$termsList[$term] = ef_term($term, $value);
219
-	}
220
-	$terms = ef_term("type", $type).(count($termsList) ? "&amp;" : "").implode("&amp;", $termsList);
221
-// End query strings
222
-	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_name = '$type' AND panel_type = 'B' LIMIT 1");
223
-	if(dbnumrows($panelquery)) {
224
-		$numrows = 0;
225
-		$panel = dbassoc($panelquery);
226
-		if($panel['panel_url'] && file_exists(_BASEDIR.$panel['panel_url'])) include($panel['panel_url']);
227
-		else if(file_exists("browse/{$type}.php")) include("browse/{$type}.php");
228
-		else $output .= write_error(_ERROR);
229
-	}
230
-	else $output .= write_error(_ERROR);
231
-	$terms = implode("&amp;", $termsList);
232
-// Other results
233
-	$otherresults = array( );
234
-	$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
235
-	while($code = dbassoc($codeblocks)) {
236
-		eval($code['code_text']);
237
-	}
238
-	if($type != "series" && !empty($seriesquery)) {
239
-		$seriesresults = dbquery(_SERIESCOUNT." WHERE ".$seriesquery);
240
-		list($scount) = dbrow($seriesresults);
241
-		if($scount > 0) $otherresults[] = "<a href='browse.php?type=series&amp;$terms'>$scount "._SERIES."</a>";
242
-	}
243
-	if(count($otherresults) > 0 && $type != "titles") $tpl->assign("otherresults", "<div id='otherresults'><span class='label'>"._OTHERRESULTS.":</span> ".implode(", ", $otherresults)."</div>");
244
-// build our sort menus. if there aren't any stories don't bother with these since they won't be used
245
-	if(!empty($numrows) || isset($_POST['go'])) {
246
-		$tpl->newBlock("sortform");
247
-		$tpl->assign("sortbegin", "<form style=\"margin:0\" method=\"POST\" id=\"form\" enctype=\"multipart/form-data\" action=\"browse.php?type=$type&amp;$terms\">");
248
-		if($catlist && !in_array("categories", $disablesorts)) {
249
-			if(count($catid) > 0) $thiscat = $catid[0];
250
-			else $thiscat = -1;
251
-			$catmenu = "<select class=\"textbox\" name=\"catid\" id=\"catid\" onChange=\"browseCategories('catid')\"><option value=\"-1\">".($thiscat > 0 ? _BACK2CATS : _CATEGORIES)."</option>\n";
252
-			foreach($catlist as $cat => $info) {
253
-				if($info['pid'] == $thiscat || $cat == $thiscat) $catmenu .= "<option value=\"$cat\"".($thiscat == $cat ? " selected" : "").">".$info['name']."</option>\n";
254
-			}
255
-			$catmenu .= "</select>\n";
256
-			$tpl->assign("categorymenu", $catmenu);
257
-		}
258
-		if(count($charlist) > 0 && !in_array("characters", $disablesorts)) {
259
-			$charactermenu1 = "<select class=\"textbox\" name=\"charlist1\" id=\"charlist1\">\n";
260
-			$charactermenu1 .= "<option value=\"0\">"._CHARACTERS."</option>\n";
261
-			$charactermenu2 = "<select class=\"textbox\" name=\"charlist2\" id=\"charlist2\">\n";
262
-			$charactermenu2 .= "<option value=\"0\">"._CHARACTERS."</option>\n";
263
-			$categories[] = -1;
264
-			$categories = array_merge($categories, $catid);
265
-			foreach($charlist as $char => $info) {
266
-				if(is_array($categories) && in_array($info['catid'], $categories)) {
267
-					$charactermenu1 .= "<option value=\"$char\"";
268
-					if(isset($charid[0]) && $charid[0] == $char)
269
-						$charactermenu1 .= " selected";
270
-					$charactermenu1 .= ">".$info['name']."</option>\n";
271
-					$charactermenu2 .= "<option value=\"$char\"";
272
-					if(isset($charid[1]) && $charid[1] == $char)
273
-						$charactermenu2 .= " selected";
274
-					$charactermenu2 .= ">".$info['name']."</option>\n";
275
-				}
276
-			}
277
-			$charactermenu1 .= "</select>";
278
-			$charactermenu2 .= "</select>";
279
-			if($type != "characters") $tpl->assign("charactermenu1"   , $charactermenu1 );
280
-			$tpl->assign("charactermenu2"   , $charactermenu2 );
281
-		}
282
-		// To avoid throwing warnings we need to define $classopts and tell it how many elements it should have.
283
-		if(!in_array("classes", $disablesorts)) {
284
-			$classopts = array();
285
-			foreach($classlist as $id => $vars) {
286
-				if(empty($classopts[$vars['type']])) $classopts[$vars['type']] = "";
287
-				$classopts[$vars['type']] = $classopts[$vars['type']]."<option value=\"$id\"".(isset($classin) && is_array($classin) && in_array($id, $classin) ? " selected" : "").">".$vars['name']."</option>\n";
288
-			}
289
-			$allclasses = "";
290
-			foreach($classopts as $type => $opts) {
291
-				if(empty($type) || in_array($classtypelist[$type]['name'], $disablesorts)) continue; // Because of the way we defined $classopts we need to skip the empty first element.
292
-				$opts = "<option value=\"\">".$classtypelist[$type]['title']."</option>$opts";
293
-				$tpl->assign($classtypelist[$type]['name']."menu", "<select name=\"".$classtypelist["$type"]['name']."\">\n$opts</select>\n");
294
-				$allclasses .= "<select class=\"textbox\" name=\"".$classtypelist["$type"]['name']."\">\n$opts</select>\n ";
295
-			}
296
-			$tpl->assign("classmenu", $allclasses);
297
-		}
298
-		if(!in_array("ratings", $disablesorts)) {
299
-			$ratingmenu = "<select class=\"textbox\" name=\"rating\">\n";
300
-			$ratingmenu .= "<option value=\"0\">"._RATINGS."</option>\n";
301
-			if(!isset($ratingslist)) $ratingslist = array( );
302
-			foreach($ratingslist as $r => $rinfo) {
303
-				$ratingmenu .= "<option value=\"".$r."\"";
304
-				if(isset($rid) && in_array($r, $rid))
305
-					$ratingmenu .= " selected";
306
-				$ratingmenu .= ">".$rinfo['name']."</option>\n";
307
-			}
308
-			$ratingmenu .= "</select>\n";
309
-			$tpl->assign("ratingmenu"   , $ratingmenu );
310
-		}
311
-		if(!in_array("sorts", $disablesorts)) $tpl->assign("sortmenu", "<select class=\"textbox\" name=\"sort\">\n<option value=''>"._SORT."</option><option value=\"alpha\"".(!$defaultsort ? " selected" : "").">"._ALPHA."</option>\n<option value=\"update\"".($defaultsort == 1 ? " selected" : "").">"._MOSTRECENT."</option>\n</select>\n");
312
-		if(!in_array("complete", $disablesorts)) $tpl->assign("completemenu", "<select class=\"textbox\" name=\"complete\">\n<option value=\"all\"".($complete == "all" ? " selected" : "").">"._ALLSTORIES."</option>\n<option value=\"1\"".($complete == 1 ? " selected" : "").">"._COMPLETEONLY."</option>\n<option value=\"0\"".($complete && $complete != "all" && $complete != 1 ? " selected" : "").">"._WIP."</option>\n</select>\n");
313
-		$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browsesorts'");
314
-		while($code = dbassoc($codeblocks)) {
315
-			eval($code['code_text']);
316
-		}
317
-		$tpl->assign("sortend"   , "<INPUT type=\"submit\" class=\"button\" name=\"go\" value=\""._GO."\"></form>");
318
-		$tpl->gotoBlock("_ROOT");
319
-	}
320
-}
321
-else  {
322
-	$output = "<div id='pagetitle'>"._BROWSE."</div>";
323
-	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_hidden != '1' AND panel_level ".(isMEMBER ? " < 2" : "= '0'")." AND panel_type = 'B' ORDER BY panel_type DESC, panel_order ASC, panel_title ASC");
324
-	while($panel = dbassoc($panelquery)) {
325
-		$browsetypes[$panel['panel_title']] =  "<a href=\"browse.php?type=".$panel['panel_name']."\">".$panel['panel_title']."</a><br />\n";
326
-	}
327
-	
328
-	foreach($classtypelist as $type => $info) {
329
-		$browsetypes[$info['title']] = "<a href='browse.php?type=class&amp;type_id=$type'>".$info['title']."</a><br />\n";
330
-	}
331
-	ksort($browsetypes);
332
-	$total = count($browsetypes);
333
-	$count = 0;
334
-	$column = 1;
335
-	$list = floor($total / $displaycolumns);
336
-	if($total % $displaycolumns != 0) $list++;
337
-	$output .= "<div id=\"columncontainer\"><div id=\"browseblock\">".($displaycolumns ? "<div class=\"column\">" : "");
338
-	foreach($browsetypes as $link) {
339
-		$count++;
340
-		$output .= $link;
341
-		if( $count >= $list && $column != $displaycolumns) {
342
-			$output .= "</div><div class=\"column\">";
343
-			if($total % $displaycolumns == $column) $list--;
344
-			$column++;
345
-			$count = 0;
346
-		}
347
-	}
348
-	$output .= "</div>".($displaycolumns ? "</div>" : "")."<div class='cleaner'>&nbsp;</div></div>";
349
-}
350
-$tpl->assign("output", $output);
351
-$tpl->printToScreen( );
352
-
353
-function ef_browse_ids($value) {
354
-	$values = is_array($value) ? $value : explode(",", $value);
355
-	foreach($values as $v) {
356
-		if(!is_string($v) || ($v !== "" && !isNumber($v))) errorExit(_ERROR);
357
-	}
358
-	return array_values(array_filter($values, "isNumber"));
359
-}
360
-
361
-// Normally, this section would be in the includes/corefunctions.php file, but that is not getting updated for a while.
362
-
363
-// Function to format a URL into a clickable link
364
-// One "name=value" pair for a link that repeats the visitor's search or browse terms.
365
-// Names and values are URL-encoded and the result is safe inside an HTML attribute; arrays become a comma list.
366
-function ef_term($name, $value) {
367
-	if(is_array($value)) $value = implode(",", array_map(function($v) { return is_array($v) ? "" : (string)$v; }, $value));
368
-	return htmlspecialchars(rawurlencode((string)$name)."=".rawurlencode((string)$value), ENT_QUOTES);
369
-}
370
-
371
-// The current query string, minus the given keys, as "&amp;a=b&amp;c=d" (empty when nothing is left).
372
-function ef_query_terms($skip = array()) {
373
-	$out = "";
374
-	foreach($_GET as $k => $v) if(!in_array((string)$k, $skip, true)) $out .= "&amp;".ef_term($k, $v);
375
-	return $out;
376
-}
377
-?>
1
+<?php
2
+// ----------------------------------------------------------------------
3
+// Copyright (c) 2007 by Tammy Keefer
4
+// Based on eFiction 1.1
5
+// Copyright (C) 2003 by Rebecca Smallwood.
6
+// http://efiction.sourceforge.net/
7
+// ----------------------------------------------------------------------
8
+// LICENSE
9
+//
10
+// This program is free software; you can redistribute it and/or
11
+// modify it under the terms of the GNU General Public License (GPL)
12
+// as published by the Free Software Foundation; either version 2
13
+// of the License, or (at your option) any later version.
14
+//
15
+// This program is distributed in the hope that it will be useful,
16
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+// GNU General Public License for more details.
19
+//
20
+// To read the license please visit http://www.gnu.org/copyleft/gpl.html
21
+// ---------------------------------------------------------------------
22
+
23
+$current = "browse";
24
+$displayform = 1;
25
+
26
+include ("header.php");
27
+
28
+if(file_exists("$skindir/browse.tpl")) $tpl = new TemplatePower( "$skindir/browse.tpl" );
29
+else $tpl = new TemplatePower("default_tpls/browse.tpl");
30
+if(file_exists("$skindir/listings.tpl")) $tpl->assignInclude("listings", "./$skindir/listings.tpl");
31
+else $tpl->assignInclude( "listings", "./default_tpls/listings.tpl" );
32
+$tpl->assignInclude( "header", "./$skindir/header.tpl" );
33
+$tpl->assignInclude( "footer", "./$skindir/footer.tpl" );
34
+
35
+include("includes/pagesetup.php");
36
+if(isset($_GET['type'])) $type = descript($_GET['type']);
37
+else $type = false;
38
+
39
+if($type) {
40
+	$query = array();
41
+	$countquery = array();
42
+	$scountquery = array();
43
+	$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple");
44
+	$searchterm =  (isset($_REQUEST['searchterm']) ? escapestring(descript($_REQUEST['searchterm'])) : false);
45
+	if($searchterm !== false) $searchterm = str_replace(array('%', '_'), array('\\%', '\\_'), escapestring($searchterm));
46
+	$disablesorts = array( );
47
+	if($searchterm) {
48
+		if($searchtype == "title") {
49
+			$query[] = "stories.title LIKE '%$searchterm%'";
50
+			$countquery[] = "stories.title LIKE '%$searchterm%'";
51
+			$scountquery[] = "series.title LIKE '%$searchterm%'";
52
+		}
53
+		if($searchtype == "summary") {
54
+			$query[] = "stories.summary LIKE '%$searchterm%'";
55
+			$countquery[] = "stories.summary LIKE '%$searchterm%'";
56
+			$scountquery[] = "series.summary LIKE '%$searchterm%'";
57
+		}
58
+		if($searchtype == "penname") {
59
+			$authorquery = dbquery(_MEMBERLIST." WHERE "._PENNAMEFIELD." LIKE '%$searchterm%' GROUP BY "._UIDFIELD);
60
+			$authorlist = array();
61
+			while($auth = dbassoc($authorquery)) {
62
+				$authorlist[] = $auth['uid'];
63
+			}
64
+			if(count($authorlist) > 0) {
65
+				$query[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
66
+				$countquery[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
67
+				$scountquery[] = "FIND_IN_SET(series.uid, '".implode(",",$authorlist)."') > 0";
68
+			}
69
+			else {
70
+				$query[] = "1 = 0"; $countquery[] = "1 = 0"; $scountquery[] = "1 = 0";
71
+			}
72
+		}
73
+		if($searchtype == "advanced" || !$searchtype) {
74
+			$query[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') ";
75
+			$countquery[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') ";
76
+			$scountquery[] = "(summary LIKE '%$searchterm%' OR title LIKE '%$searchterm%') ";
77
+		}
78
+	}
79
+	$ef_authors = isset($_REQUEST['authors']) ? array_filter(array_map('trim', is_array($_REQUEST['authors']) ? $_REQUEST['authors'] : explode(",", (string)$_REQUEST['authors'])), "isNumber") : array( );
80
+	if($ef_authors) {
81
+		$ef_authors = implode(",", array_map('intval', $ef_authors));
82
+		$query[] = "FIND_IN_SET(stories.uid, '".$ef_authors."') > 0";
83
+		$countquery[] = "FIND_IN_SET(stories.uid, '".$ef_authors."') > 0";
84
+		$scountquery[] = "FIND_IN_SET(series.uid, '".$ef_authors."') > 0";
85
+	}
86
+	if(isset($_REQUEST['catid'])) {
87
+		$catid = is_array($_REQUEST['catid']) ? $_REQUEST['catid'] : explode(",", $_REQUEST['catid']);
88
+		$catid = array_filter($catid, "isNumber");
89
+	}
90
+	if(!isset($catid)) $catid = array();
91
+	if($type == "categories" && isset($_GET['id']) && isNumber($_GET['id'])) {
92
+		$catid[] =  $_GET['id'];
93
+	}
94
+	$categories = array( );
95
+	// Get the recursive list.
96
+	if($type == "categories") $categories = $catid;
97
+	else {
98
+		foreach($catid as $cat) {
99
+			if($cat == "false" || empty($cat)) continue;
100
+			$categories = array_merge($categories, recurseCategories($cat));
101
+		}
102
+	}
103
+	// Now format the SQL
104
+	foreach($categories as $cat) {
105
+		$catstories[] = "FIND_IN_SET($cat, stories.catid) > 0 ";
106
+		$catseries[] = "FIND_IN_SET($cat, series.catid) > 0 ";
107
+	}
108
+	// Now implode the SQL list
109
+	if(!empty($catstories)) {
110
+		$query[] = "(".implode(" OR ", $catstories).")";
111
+		$countquery[] = "(".implode(" OR ", $catstories).")";
112
+		$scountquery[] = "(".implode(" OR ", $catseries).")";
113
+	}
114
+	if(empty($charid)) $charid = array( );
115
+	if(isset($_REQUEST['charid'])) {
116
+		$charid = is_array($_REQUEST['charid']) ? $_REQUEST['charid'] : explode(",", $_REQUEST['charid']);
117
+		$charid = array_filter($charid, "isNumber");
118
+	}
119
+	if(!empty($_REQUEST['charlist1']) && !in_array($_REQUEST['charlist1'], $charid)) $charid[] = $_REQUEST['charlist1'];
120
+	if(!empty($_REQUEST['charlist2']) && !in_array($_REQUEST['charlist2'], $charid)) $charid[] = $_REQUEST['charlist2'];
121
+	$charid = array_filter($charid, "isNumber");
122
+	if($charid) {
123
+		foreach($charid as $c) {
124
+			if(!empty($c)) {
125
+				$charstories[] = "FIND_IN_SET($c, stories.charid) > 0 ";
126
+				$charseries[] = "FIND_IN_SET($c, series.characters) > 0 ";
127
+			}
128
+		}
129
+		if(count($charstories) > 0) {
130
+			$query[] = "(".implode(" AND ", $charstories).")";
131
+			$countquery[] = "(".implode(" AND ", $charstories).")";
132
+		}
133
+		if(count($charseries) > 0) $scountquery[] = "(".implode(" AND ", $charseries).")";
134
+	}
135
+	$rid = array( ); $rating = array( );
136
+	if(!empty($_REQUEST['rid'])) $rid = is_array($_REQUEST['rid']) ? $_REQUEST['rid'] : explode(",", $_REQUEST['rid']);
137
+	if(!empty($_REQUEST['rating'])) $rating = is_array($_REQUEST['rating']) ? $_REQUEST['rating'] : explode(",", $_REQUEST['rating']);
138
+	$rid = array_filter(array_merge($rid, $rating), "isNumber");
139
+	if(!empty($rid)) {
140
+		$query[] = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
141
+		$countquery[]  = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
142
+	}
143
+	$complete = "all";
144
+	if(isset($_REQUEST['complete'])) {
145
+		if($_REQUEST['complete'] == 1) {
146
+			$query[] = "stories.completed = '1'";
147
+			$countquery[] = "stories.completed = '1'";
148
+			$complete = 1;
149
+		} 
150
+		else if(empty($_REQUEST['complete'])) {
151
+			$query[] = "stories.completed = '0'";
152
+			$countquery[] = "stories.completed = '0'";
153
+			$complete = 0;
154
+		} 
155
+	}
156
+	if(isset($_REQUEST['classin'])) $classin = is_array($_REQUEST['classin']) ? $_REQUEST['classin'] : array($_REQUEST['classin']);
157
+	else $classin = array( );
158
+	if(isset($_REQUEST['classex'])) $classex = is_array($_REQUEST['classex']) ? $_REQUEST['classex'] : array($_REQUEST['classex']);
159
+	else $classex = array( );
160
+	$opts = array();
161
+	$exopts = array( );
162
+	foreach($classtypelist as $id => $vars) {
163
+		if(!empty($_POST[$vars['name']])) $opts[] = $_POST[$vars['name']];
164
+		else if(isset($_GET["class_".$id])) {
165
+			$opts = !empty($opts) ? array_merge($opts, explode(",", $_GET["class_".$id])) : array($_GET["class_".$id]);
166
+		}
167
+		else if(!empty($_REQUEST[$vars["name"]])) $opts = is_array($_REQUEST[$vars["name"]]) ? $_REQUEST[$vars["name"]] : array($_REQUEST[$vars["name"]]);
168
+		if(!empty($opts)) $classin = array_merge($classin, $opts);
169
+		if(isset($_POST["exclass_".$id])) $exopts = $_POST["exclass_".$id];
170
+		else if(isset($_GET["exclass_".$id])) {
171
+			$exopts = !empty($exopts) ? array_merge($exopts, explode(",", $_GET["exclass_".$id])) : array($_GET["exclass_".$id]);
172
+		}
173
+		if(!empty($exopts)) $classex = array_merge($classex, $exopts);
174
+		unset($opts, $exopts);
175
+	}
176
+	$classin = array_filter($classin, "isNumber");
177
+	$classex = array_filter($classex, "isNumber");
178
+	if($classin) {
179
+		foreach($classin as $class) {
180
+			if(empty($class)) continue;
181
+			$query[] = "FIND_IN_SET($class, stories.classes) > 0";
182
+			$countquery[] = "FIND_IN_SET($class, stories.classes) > 0";
183
+			$scountquery[] = "FIND_IN_SET($class, series.classes) > 0";
184
+		}
185
+	}
186
+	if($classex) {
187
+		foreach($classex as $class) {
188
+			$query[] = "FIND_IN_SET($class, stories.classes) = 0";
189
+			$countquery[] = "FIND_IN_SET($class, stories.classes) = 0";
190
+			$scountquery[] = "FIND_IN_SET($class, series.classes) = 0";
191
+		}
192
+	}
193
+	// Begin story length
194
+	unset($wordcount);
195
+	$wordlow = isset($_REQUEST['wordlow']) && isNumber($_REQUEST['wordlow']) ? $_REQUEST['wordlow'] : "-500";
196
+	$wordhigh = isset($_REQUEST['wordhigh']) && isNumber($_REQUEST['wordhigh']) ? $_REQUEST['wordhigh'] : "1000000";
197
+	if($wordlow != "-500") $wordcount = "stories.wordcount > ".$wordlow;
198
+	if($wordhigh != "1000000") 
199
+	{
200
+		if($wordcount) $wordcount .= " AND stories.wordcount < ".$wordhigh;
201
+		else $wordcount = "stories.wordcount < ".$wordhigh;
202
+	}
203
+	if($wordhigh < $wordlow) $wordcount = "stories.wordcount < ".$wordlow;
204
+	if($wordlow != "-500" && $wordhigh != "1000000" && isset($_POST['submit'])) {
205
+		$query[] = "($wordcount)";
206
+		$countquery[] = "($wordcount)";
207
+	}
208
+	// End wordcount
209
+	$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browseterms'");
210
+	while($code = dbassoc($codeblocks)) {
211
+		eval($code['code_text']);
212
+	}
213
+	$storyquery = count($query) > 0 ? " AND ".implode(" AND ", $query) : "";
214
+	$countquery = count($countquery) > 0 ? " AND ".implode(" AND ", $countquery) : "";
215
+	$seriesquery = count($scountquery) > 0 ? implode(" AND ", $scountquery) : false;
216
+	$termArray = array_merge($_GET, $_POST);
217
+	$termsList = array();
218
+	foreach($termArray as $term => $value) {
219
+		if($term == "submit" || $term == "go" || $term == "offset" || $term == "type" || ($term != "complete" && empty($value))) continue;
220
+		$termsList[$term] = "$term=".(is_array($value) ? implode(",", array_map(function($v) { return htmlspecialchars($v, ENT_QUOTES); }, $value)) : htmlspecialchars($value, ENT_QUOTES));
221
+	}
222
+	$terms = "type=$type".(count($termsList) ? "&amp;" : "").implode("&amp;", $termsList);
223
+// End query strings
224
+	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_name = '".escapestring($type)."' AND panel_type = 'B' LIMIT 1");
225
+	if(dbnumrows($panelquery)) {
226
+		$numrows = 0;
227
+		$panel = dbassoc($panelquery);
228
+		if($panel['panel_url'] && file_exists(_BASEDIR.$panel['panel_url'])) include($panel['panel_url']);
229
+		else if(file_exists("browse/{$type}.php")) include("browse/{$type}.php");
230
+		else $output .= write_error(_ERROR);
231
+	}
232
+	else $output .= write_error(_ERROR);
233
+	$terms = implode("&amp;", $termsList);
234
+// Other results
235
+	$otherresults = array( );
236
+	$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
237
+	while($code = dbassoc($codeblocks)) {
238
+		eval($code['code_text']);
239
+	}
240
+	if($type != "series" && !empty($seriesquery)) {
241
+		$seriesresults = dbquery(_SERIESCOUNT." WHERE ".$seriesquery);
242
+		list($scount) = dbrow($seriesresults);
243
+		if($scount > 0) $otherresults[] = "<a href='browse.php?type=series&amp;$terms'>$scount "._SERIES."</a>";
244
+	}
245
+	if(count($otherresults) > 0 && $type != "titles") $tpl->assign("otherresults", "<div id='otherresults'><span class='label'>"._OTHERRESULTS.":</span> ".implode(", ", $otherresults)."</div>");
246
+// build our sort menus. if there aren't any stories don't bother with these since they won't be used
247
+	if(!empty($numrows) || isset($_POST['go'])) {
248
+		$tpl->newBlock("sortform");
249
+		$tpl->assign("sortbegin", "<form style=\"margin:0\" method=\"POST\" id=\"form\" enctype=\"multipart/form-data\" action=\"browse.php?type=$type&amp;$terms\">");
250
+		if($catlist && !in_array("categories", $disablesorts)) {
251
+			if(count($catid) > 0) $thiscat = $catid[0];
252
+			else $thiscat = -1;
253
+			$catmenu = "<select class=\"textbox\" name=\"catid\" id=\"catid\" onChange=\"browseCategories('catid')\"><option value=\"-1\">".($thiscat > 0 ? _BACK2CATS : _CATEGORIES)."</option>\n";
254
+			foreach($catlist as $cat => $info) {
255
+				if($info['pid'] == $thiscat || $cat == $thiscat) $catmenu .= "<option value=\"$cat\"".($thiscat == $cat ? " selected" : "").">".$info['name']."</option>\n";
256
+			}
257
+			$catmenu .= "</select>\n";
258
+			$tpl->assign("categorymenu", $catmenu);
259
+		}
260
+		if(count($charlist) > 0 && !in_array("characters", $disablesorts)) {
261
+			$charactermenu1 = "<select class=\"textbox\" name=\"charlist1\" id=\"charlist1\">\n";
262
+			$charactermenu1 .= "<option value=\"0\">"._CHARACTERS."</option>\n";
263
+			$charactermenu2 = "<select class=\"textbox\" name=\"charlist2\" id=\"charlist2\">\n";
264
+			$charactermenu2 .= "<option value=\"0\">"._CHARACTERS."</option>\n";
265
+			$categories[] = -1;
266
+			$categories = array_merge($categories, $catid);
267
+			foreach($charlist as $char => $info) {
268
+				if(is_array($categories) && in_array($info['catid'], $categories)) {
269
+					$charactermenu1 .= "<option value=\"$char\"";
270
+					if(isset($charid[0]) && $charid[0] == $char)
271
+						$charactermenu1 .= " selected";
272
+					$charactermenu1 .= ">".$info['name']."</option>\n";
273
+					$charactermenu2 .= "<option value=\"$char\"";
274
+					if(isset($charid[1]) && $charid[1] == $char)
275
+						$charactermenu2 .= " selected";
276
+					$charactermenu2 .= ">".$info['name']."</option>\n";
277
+				}
278
+			}
279
+			$charactermenu1 .= "</select>";
280
+			$charactermenu2 .= "</select>";
281
+			if($type != "characters") $tpl->assign("charactermenu1"   , $charactermenu1 );
282
+			$tpl->assign("charactermenu2"   , $charactermenu2 );
283
+		}
284
+		// To avoid throwing warnings we need to define $classopts and tell it how many elements it should have.
285
+		if(!in_array("classes", $disablesorts)) {
286
+			$classopts = array();
287
+			foreach($classlist as $id => $vars) {
288
+				if(empty($classopts[$vars['type']])) $classopts[$vars['type']] = "";
289
+				$classopts[$vars['type']] = $classopts[$vars['type']]."<option value=\"$id\"".(isset($classin) && is_array($classin) && in_array($id, $classin) ? " selected" : "").">".$vars['name']."</option>\n";
290
+			}
291
+			$allclasses = "";
292
+			foreach($classopts as $type => $opts) {
293
+				if(empty($type) || in_array($classtypelist[$type]['name'], $disablesorts)) continue; // Because of the way we defined $classopts we need to skip the empty first element.
294
+				$opts = "<option value=\"\">".$classtypelist[$type]['title']."</option>$opts";
295
+				$tpl->assign($classtypelist[$type]['name']."menu", "<select name=\"".$classtypelist["$type"]['name']."\">\n$opts</select>\n");
296
+				$allclasses .= "<select class=\"textbox\" name=\"".$classtypelist["$type"]['name']."\">\n$opts</select>\n ";
297
+			}
298
+			$tpl->assign("classmenu", $allclasses);
299
+		}
300
+		if(!in_array("ratings", $disablesorts)) {
301
+			$ratingmenu = "<select class=\"textbox\" name=\"rating\">\n";
302
+			$ratingmenu .= "<option value=\"0\">"._RATINGS."</option>\n";
303
+			if(!isset($ratingslist)) $ratingslist = array( );
304
+			foreach($ratingslist as $r => $rinfo) {
305
+				$ratingmenu .= "<option value=\"".$r."\"";
306
+				if(isset($rid) && in_array($r, $rid))
307
+					$ratingmenu .= " selected";
308
+				$ratingmenu .= ">".$rinfo['name']."</option>\n";
309
+			}
310
+			$ratingmenu .= "</select>\n";
311
+			$tpl->assign("ratingmenu"   , $ratingmenu );
312
+		}
313
+		if(!in_array("sorts", $disablesorts)) $tpl->assign("sortmenu", "<select class=\"textbox\" name=\"sort\">\n<option value=''>"._SORT."</option><option value=\"alpha\"".(!$defaultsort ? " selected" : "").">"._ALPHA."</option>\n<option value=\"update\"".($defaultsort == 1 ? " selected" : "").">"._MOSTRECENT."</option>\n</select>\n");
314
+		if(!in_array("complete", $disablesorts)) $tpl->assign("completemenu", "<select class=\"textbox\" name=\"complete\">\n<option value=\"all\"".($complete == "all" ? " selected" : "").">"._ALLSTORIES."</option>\n<option value=\"1\"".($complete == 1 ? " selected" : "").">"._COMPLETEONLY."</option>\n<option value=\"0\"".($complete && $complete != "all" && $complete != 1 ? " selected" : "").">"._WIP."</option>\n</select>\n");
315
+		$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browsesorts'");
316
+		while($code = dbassoc($codeblocks)) {
317
+			eval($code['code_text']);
318
+		}
319
+		$tpl->assign("sortend"   , "<INPUT type=\"submit\" class=\"button\" name=\"go\" value=\""._GO."\"></form>");
320
+		$tpl->gotoBlock("_ROOT");
321
+	}
322
+}
323
+else  {
324
+	$output = "<div id='pagetitle'>"._BROWSE."</div>";
325
+	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_hidden != '1' AND panel_level ".(isMEMBER ? " < 2" : "= '0'")." AND panel_type = 'B' ORDER BY panel_type DESC, panel_order ASC, panel_title ASC");
326
+	while($panel = dbassoc($panelquery)) {
327
+		$browsetypes[$panel['panel_title']] =  "<a href=\"browse.php?type=".$panel['panel_name']."\">".$panel['panel_title']."</a><br />\n";
328
+	}
329
+	
330
+	foreach($classtypelist as $type => $info) {
331
+		$browsetypes[$info['title']] = "<a href='browse.php?type=class&amp;type_id=$type'>".$info['title']."</a><br />\n";
332
+	}
333
+	ksort($browsetypes);
334
+	$total = count($browsetypes);
335
+	$count = 0;
336
+	$column = 1;
337
+	$list = floor($total / $displaycolumns);
338
+	if($total % $displaycolumns != 0) $list++;
339
+	$output .= "<div id=\"columncontainer\"><div id=\"browseblock\">".($displaycolumns ? "<div class=\"column\">" : "");
340
+	foreach($browsetypes as $link) {
341
+		$count++;
342
+		$output .= $link;
343
+		if( $count >= $list && $column != $displaycolumns) {
344
+			$output .= "</div><div class=\"column\">";
345
+			if($total % $displaycolumns == $column) $list--;
346
+			$column++;
347
+			$count = 0;
348
+		}
349
+	}
350
+	$output .= "</div>".($displaycolumns ? "</div>" : "")."<div class='cleaner'>&nbsp;</div></div>";
351
+}
352
+$tpl->assign("output", $output);
353
+$tpl->printToScreen( );
354
+?>
Browse code

browse.php, search.php, includes/categorylist.php: patches from upstream, with some exceptions - search.php needs Ami-fixed old behavior in the penname results due to new upstream version bugging out in MySQL strict error reporting mode; browse.php has searchtype errorExit() behavior commented out as it crashes series results, other results are fine

Clarissa Walker authored on 2026/11/02 08:39:49
Showing 1 changed files
... ...
@@ -1,354 +1,377 @@
1
-<?php
2
-// ----------------------------------------------------------------------
3
-// Copyright (c) 2007 by Tammy Keefer
4
-// Based on eFiction 1.1
5
-// Copyright (C) 2003 by Rebecca Smallwood.
6
-// http://efiction.sourceforge.net/
7
-// ----------------------------------------------------------------------
8
-// LICENSE
9
-//
10
-// This program is free software; you can redistribute it and/or
11
-// modify it under the terms of the GNU General Public License (GPL)
12
-// as published by the Free Software Foundation; either version 2
13
-// of the License, or (at your option) any later version.
14
-//
15
-// This program is distributed in the hope that it will be useful,
16
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
-// GNU General Public License for more details.
19
-//
20
-// To read the license please visit http://www.gnu.org/copyleft/gpl.html
21
-// ---------------------------------------------------------------------
22
-
23
-$current = "browse";
24
-$displayform = 1;
25
-
26
-include ("header.php");
27
-
28
-if(file_exists("$skindir/browse.tpl")) $tpl = new TemplatePower( "$skindir/browse.tpl" );
29
-else $tpl = new TemplatePower("default_tpls/browse.tpl");
30
-if(file_exists("$skindir/listings.tpl")) $tpl->assignInclude("listings", "./$skindir/listings.tpl");
31
-else $tpl->assignInclude( "listings", "./default_tpls/listings.tpl" );
32
-$tpl->assignInclude( "header", "./$skindir/header.tpl" );
33
-$tpl->assignInclude( "footer", "./$skindir/footer.tpl" );
34
-
35
-include("includes/pagesetup.php");
36
-if(isset($_GET['type'])) $type = descript($_GET['type']);
37
-else $type = false;
38
-
39
-if($type) {
40
-	$query = array();
41
-	$countquery = array();
42
-	$scountquery = array();
43
-	$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple");
44
-	$searchterm =  (isset($_REQUEST['searchterm']) ? escapestring(descript($_REQUEST['searchterm'])) : false);
45
-	if($searchterm !== false) $searchterm = str_replace(array('%', '_'), array('\\%', '\\_'), escapestring($searchterm));
46
-	$disablesorts = array( );
47
-	if($searchterm) {
48
-		if($searchtype == "title") {
49
-			$query[] = "stories.title LIKE '%$searchterm%'";
50
-			$countquery[] = "stories.title LIKE '%$searchterm%'";
51
-			$scountquery[] = "series.title LIKE '%$searchterm%'";
52
-		}
53
-		if($searchtype == "summary") {
54
-			$query[] = "stories.summary LIKE '%$searchterm%'";
55
-			$countquery[] = "stories.summary LIKE '%$searchterm%'";
56
-			$scountquery[] = "series.summary LIKE '%$searchterm%'";
57
-		}
58
-		if($searchtype == "penname") {
59
-			$authorquery = dbquery(_MEMBERLIST." WHERE "._PENNAMEFIELD." LIKE '%$searchterm%' GROUP BY "._UIDFIELD);
60
-			$authorlist = array();
61
-			while($auth = dbassoc($authorquery)) {
62
-				$authorlist[] = $auth['uid'];
63
-			}
64
-			if(count($authorlist) > 0) {
65
-				$query[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
66
-				$countquery[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
67
-				$scountquery[] = "FIND_IN_SET(series.uid, '".implode(",",$authorlist)."') > 0";
68
-			}
69
-			else {
70
-				$query[] = "1 = 0"; $countquery[] = "1 = 0"; $scountquery[] = "1 = 0";
71
-			}
72
-		}
73
-		if($searchtype == "advanced" || !$searchtype) {
74
-			$query[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') ";
75
-			$countquery[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') ";
76
-			$scountquery[] = "(summary LIKE '%$searchterm%' OR title LIKE '%$searchterm%') ";
77
-		}
78
-	}
79
-	$ef_authors = isset($_REQUEST['authors']) ? array_filter(array_map('trim', is_array($_REQUEST['authors']) ? $_REQUEST['authors'] : explode(",", (string)$_REQUEST['authors'])), "isNumber") : array( );
80
-	if($ef_authors) {
81
-		$ef_authors = implode(",", array_map('intval', $ef_authors));
82
-		$query[] = "FIND_IN_SET(stories.uid, '".$ef_authors."') > 0";
83
-		$countquery[] = "FIND_IN_SET(stories.uid, '".$ef_authors."') > 0";
84
-		$scountquery[] = "FIND_IN_SET(series.uid, '".$ef_authors."') > 0";
85
-	}
86
-	if(isset($_REQUEST['catid'])) {
87
-		$catid = is_array($_REQUEST['catid']) ? $_REQUEST['catid'] : explode(",", $_REQUEST['catid']);
88
-		$catid = array_filter($catid, "isNumber");
89
-	}
90
-	if(!isset($catid)) $catid = array();
91
-	if($type == "categories" && isset($_GET['id']) && isNumber($_GET['id'])) {
92
-		$catid[] =  $_GET['id'];
93
-	}
94
-	$categories = array( );
95
-	// Get the recursive list.
96
-	if($type == "categories") $categories = $catid;
97
-	else {
98
-		foreach($catid as $cat) {
99
-			if($cat == "false" || empty($cat)) continue;
100
-			$categories = array_merge($categories, recurseCategories($cat));
101
-		}
102
-	}
103
-	// Now format the SQL
104
-	foreach($categories as $cat) {
105
-		$catstories[] = "FIND_IN_SET($cat, stories.catid) > 0 ";
106
-		$catseries[] = "FIND_IN_SET($cat, series.catid) > 0 ";
107
-	}
108
-	// Now implode the SQL list
109
-	if(!empty($catstories)) {
110
-		$query[] = "(".implode(" OR ", $catstories).")";
111
-		$countquery[] = "(".implode(" OR ", $catstories).")";
112
-		$scountquery[] = "(".implode(" OR ", $catseries).")";
113
-	}
114
-	if(empty($charid)) $charid = array( );
115
-	if(isset($_REQUEST['charid'])) {
116
-		$charid = is_array($_REQUEST['charid']) ? $_REQUEST['charid'] : explode(",", $_REQUEST['charid']);
117
-		$charid = array_filter($charid, "isNumber");
118
-	}
119
-	if(!empty($_REQUEST['charlist1']) && !in_array($_REQUEST['charlist1'], $charid)) $charid[] = $_REQUEST['charlist1'];
120
-	if(!empty($_REQUEST['charlist2']) && !in_array($_REQUEST['charlist2'], $charid)) $charid[] = $_REQUEST['charlist2'];
121
-	$charid = array_filter($charid, "isNumber");
122
-	if($charid) {
123
-		foreach($charid as $c) {
124
-			if(!empty($c)) {
125
-				$charstories[] = "FIND_IN_SET($c, stories.charid) > 0 ";
126
-				$charseries[] = "FIND_IN_SET($c, series.characters) > 0 ";
127
-			}
128
-		}
129
-		if(count($charstories) > 0) {
130
-			$query[] = "(".implode(" AND ", $charstories).")";
131
-			$countquery[] = "(".implode(" AND ", $charstories).")";
132
-		}
133
-		if(count($charseries) > 0) $scountquery[] = "(".implode(" AND ", $charseries).")";
134
-	}
135
-	$rid = array( ); $rating = array( );
136
-	if(!empty($_REQUEST['rid'])) $rid = is_array($_REQUEST['rid']) ? $_REQUEST['rid'] : explode(",", $_REQUEST['rid']);
137
-	if(!empty($_REQUEST['rating'])) $rating = is_array($_REQUEST['rating']) ? $_REQUEST['rating'] : explode(",", $_REQUEST['rating']);
138
-	$rid = array_filter(array_merge($rid, $rating), "isNumber");
139
-	if(!empty($rid)) {
140
-		$query[] = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
141
-		$countquery[]  = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
142
-	}
143
-	$complete = "all";
144
-	if(isset($_REQUEST['complete'])) {
145
-		if($_REQUEST['complete'] == 1) {
146
-			$query[] = "stories.completed = '1'";
147
-			$countquery[] = "stories.completed = '1'";
148
-			$complete = 1;
149
-		} 
150
-		else if(empty($_REQUEST['complete'])) {
151
-			$query[] = "stories.completed = '0'";
152
-			$countquery[] = "stories.completed = '0'";
153
-			$complete = 0;
154
-		} 
155
-	}
156
-	if(isset($_REQUEST['classin'])) $classin = is_array($_REQUEST['classin']) ? $_REQUEST['classin'] : array($_REQUEST['classin']);
157
-	else $classin = array( );
158
-	if(isset($_REQUEST['classex'])) $classex = is_array($_REQUEST['classex']) ? $_REQUEST['classex'] : array($_REQUEST['classex']);
159
-	else $classex = array( );
160
-	$opts = array();
161
-	$exopts = array( );
162
-	foreach($classtypelist as $id => $vars) {
163
-		if(!empty($_POST[$vars['name']])) $opts[] = $_POST[$vars['name']];
164
-		else if(isset($_GET["class_".$id])) {
165
-			$opts = !empty($opts) ? array_merge($opts, explode(",", $_GET["class_".$id])) : array($_GET["class_".$id]);
166
-		}
167
-		else if(!empty($_REQUEST[$vars["name"]])) $opts = is_array($_REQUEST[$vars["name"]]) ? $_REQUEST[$vars["name"]] : array($_REQUEST[$vars["name"]]);
168
-		if(!empty($opts)) $classin = array_merge($classin, $opts);
169
-		if(isset($_POST["exclass_".$id])) $exopts = $_POST["exclass_".$id];
170
-		else if(isset($_GET["exclass_".$id])) {
171
-			$exopts = !empty($exopts) ? array_merge($exopts, explode(",", $_GET["exclass_".$id])) : array($_GET["exclass_".$id]);
172
-		}
173
-		if(!empty($exopts)) $classex = array_merge($classex, $exopts);
174
-		unset($opts, $exopts);
175
-	}
176
-	$classin = array_filter($classin, "isNumber");
177
-	$classex = array_filter($classex, "isNumber");
178
-	if($classin) {
179
-		foreach($classin as $class) {
180
-			if(empty($class)) continue;
181
-			$query[] = "FIND_IN_SET($class, stories.classes) > 0";
182
-			$countquery[] = "FIND_IN_SET($class, stories.classes) > 0";
183
-			$scountquery[] = "FIND_IN_SET($class, series.classes) > 0";
184
-		}
185
-	}
186
-	if($classex) {
187
-		foreach($classex as $class) {
188
-			$query[] = "FIND_IN_SET($class, stories.classes) = 0";
189
-			$countquery[] = "FIND_IN_SET($class, stories.classes) = 0";
190
-			$scountquery[] = "FIND_IN_SET($class, series.classes) = 0";
191
-		}
192
-	}
193
-	// Begin story length
194
-	unset($wordcount);
195
-	$wordlow = isset($_REQUEST['wordlow']) && isNumber($_REQUEST['wordlow']) ? $_REQUEST['wordlow'] : "-500";
196
-	$wordhigh = isset($_REQUEST['wordhigh']) && isNumber($_REQUEST['wordhigh']) ? $_REQUEST['wordhigh'] : "1000000";
197
-	if($wordlow != "-500") $wordcount = "stories.wordcount > ".$wordlow;
198
-	if($wordhigh != "1000000") 
199
-	{
200
-		if($wordcount) $wordcount .= " AND stories.wordcount < ".$wordhigh;
201
-		else $wordcount = "stories.wordcount < ".$wordhigh;
202
-	}
203
-	if($wordhigh < $wordlow) $wordcount = "stories.wordcount < ".$wordlow;
204
-	if($wordlow != "-500" && $wordhigh != "1000000" && isset($_POST['submit'])) {
205
-		$query[] = "($wordcount)";
206
-		$countquery[] = "($wordcount)";
207
-	}
208
-	// End wordcount
209
-	$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browseterms'");
210
-	while($code = dbassoc($codeblocks)) {
211
-		eval($code['code_text']);
212
-	}
213
-	$storyquery = count($query) > 0 ? " AND ".implode(" AND ", $query) : "";
214
-	$countquery = count($countquery) > 0 ? " AND ".implode(" AND ", $countquery) : "";
215
-	$seriesquery = count($scountquery) > 0 ? implode(" AND ", $scountquery) : false;
216
-	$termArray = array_merge($_GET, $_POST);
217
-	$termsList = array();
218
-	foreach($termArray as $term => $value) {
219
-		if($term == "submit" || $term == "go" || $term == "offset" || $term == "type" || ($term != "complete" && empty($value))) continue;
220
-		$termsList[$term] = "$term=".(is_array($value) ? implode(",", array_map(function($v) { return htmlspecialchars($v, ENT_QUOTES); }, $value)) : htmlspecialchars($value, ENT_QUOTES));
221
-	}
222
-	$terms = "type=$type".(count($termsList) ? "&amp;" : "").implode("&amp;", $termsList);
223
-// End query strings
224
-	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_name = '".escapestring($type)."' AND panel_type = 'B' LIMIT 1");
225
-	if(dbnumrows($panelquery)) {
226
-		$numrows = 0;
227
-		$panel = dbassoc($panelquery);
228
-		if($panel['panel_url'] && file_exists(_BASEDIR.$panel['panel_url'])) include($panel['panel_url']);
229
-		else if(file_exists("browse/{$type}.php")) include("browse/{$type}.php");
230
-		else $output .= write_error(_ERROR);
231
-	}
232
-	else $output .= write_error(_ERROR);
233
-	$terms = implode("&amp;", $termsList);
234
-// Other results
235
-	$otherresults = array( );
236
-	$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
237
-	while($code = dbassoc($codeblocks)) {
238
-		eval($code['code_text']);
239
-	}
240
-	if($type != "series" && !empty($seriesquery)) {
241
-		$seriesresults = dbquery(_SERIESCOUNT." WHERE ".$seriesquery);
242
-		list($scount) = dbrow($seriesresults);
243
-		if($scount > 0) $otherresults[] = "<a href='browse.php?type=series&amp;$terms'>$scount "._SERIES."</a>";
244
-	}
245
-	if(count($otherresults) > 0 && $type != "titles") $tpl->assign("otherresults", "<div id='otherresults'><span class='label'>"._OTHERRESULTS.":</span> ".implode(", ", $otherresults)."</div>");
246
-// build our sort menus. if there aren't any stories don't bother with these since they won't be used
247
-	if(!empty($numrows) || isset($_POST['go'])) {
248
-		$tpl->newBlock("sortform");
249
-		$tpl->assign("sortbegin", "<form style=\"margin:0\" method=\"POST\" id=\"form\" enctype=\"multipart/form-data\" action=\"browse.php?type=$type&amp;$terms\">");
250
-		if($catlist && !in_array("categories", $disablesorts)) {
251
-			if(count($catid) > 0) $thiscat = $catid[0];
252
-			else $thiscat = -1;
253
-			$catmenu = "<select class=\"textbox\" name=\"catid\" id=\"catid\" onChange=\"browseCategories('catid')\"><option value=\"-1\">".($thiscat > 0 ? _BACK2CATS : _CATEGORIES)."</option>\n";
254
-			foreach($catlist as $cat => $info) {
255
-				if($info['pid'] == $thiscat || $cat == $thiscat) $catmenu .= "<option value=\"$cat\"".($thiscat == $cat ? " selected" : "").">".$info['name']."</option>\n";
256
-			}
257
-			$catmenu .= "</select>\n";
258
-			$tpl->assign("categorymenu", $catmenu);
259
-		}
260
-		if(count($charlist) > 0 && !in_array("characters", $disablesorts)) {
261
-			$charactermenu1 = "<select class=\"textbox\" name=\"charlist1\" id=\"charlist1\">\n";
262
-			$charactermenu1 .= "<option value=\"0\">"._CHARACTERS."</option>\n";
263
-			$charactermenu2 = "<select class=\"textbox\" name=\"charlist2\" id=\"charlist2\">\n";
264
-			$charactermenu2 .= "<option value=\"0\">"._CHARACTERS."</option>\n";
265
-			$categories[] = -1;
266
-			$categories = array_merge($categories, $catid);
267
-			foreach($charlist as $char => $info) {
268
-				if(is_array($categories) && in_array($info['catid'], $categories)) {
269
-					$charactermenu1 .= "<option value=\"$char\"";
270
-					if(isset($charid[0]) && $charid[0] == $char)
271
-						$charactermenu1 .= " selected";
272
-					$charactermenu1 .= ">".$info['name']."</option>\n";
273
-					$charactermenu2 .= "<option value=\"$char\"";
274
-					if(isset($charid[1]) && $charid[1] == $char)
275
-						$charactermenu2 .= " selected";
276
-					$charactermenu2 .= ">".$info['name']."</option>\n";
277
-				}
278
-			}
279
-			$charactermenu1 .= "</select>";
280
-			$charactermenu2 .= "</select>";
281
-			if($type != "characters") $tpl->assign("charactermenu1"   , $charactermenu1 );
282
-			$tpl->assign("charactermenu2"   , $charactermenu2 );
283
-		}
284
-		// To avoid throwing warnings we need to define $classopts and tell it how many elements it should have.
285
-		if(!in_array("classes", $disablesorts)) {
286
-			$classopts = array();
287
-			foreach($classlist as $id => $vars) {
288
-				if(empty($classopts[$vars['type']])) $classopts[$vars['type']] = "";
289
-				$classopts[$vars['type']] = $classopts[$vars['type']]."<option value=\"$id\"".(isset($classin) && is_array($classin) && in_array($id, $classin) ? " selected" : "").">".$vars['name']."</option>\n";
290
-			}
291
-			$allclasses = "";
292
-			foreach($classopts as $type => $opts) {
293
-				if(empty($type) || in_array($classtypelist[$type]['name'], $disablesorts)) continue; // Because of the way we defined $classopts we need to skip the empty first element.
294
-				$opts = "<option value=\"\">".$classtypelist[$type]['title']."</option>$opts";
295
-				$tpl->assign($classtypelist[$type]['name']."menu", "<select name=\"".$classtypelist["$type"]['name']."\">\n$opts</select>\n");
296
-				$allclasses .= "<select class=\"textbox\" name=\"".$classtypelist["$type"]['name']."\">\n$opts</select>\n ";
297
-			}
298
-			$tpl->assign("classmenu", $allclasses);
299
-		}
300
-		if(!in_array("ratings", $disablesorts)) {
301
-			$ratingmenu = "<select class=\"textbox\" name=\"rating\">\n";
302
-			$ratingmenu .= "<option value=\"0\">"._RATINGS."</option>\n";
303
-			if(!isset($ratingslist)) $ratingslist = array( );
304
-			foreach($ratingslist as $r => $rinfo) {
305
-				$ratingmenu .= "<option value=\"".$r."\"";
306
-				if(isset($rid) && in_array($r, $rid))
307
-					$ratingmenu .= " selected";
308
-				$ratingmenu .= ">".$rinfo['name']."</option>\n";
309
-			}
310
-			$ratingmenu .= "</select>\n";
311
-			$tpl->assign("ratingmenu"   , $ratingmenu );
312
-		}
313
-		if(!in_array("sorts", $disablesorts)) $tpl->assign("sortmenu", "<select class=\"textbox\" name=\"sort\">\n<option value=''>"._SORT."</option><option value=\"alpha\"".(!$defaultsort ? " selected" : "").">"._ALPHA."</option>\n<option value=\"update\"".($defaultsort == 1 ? " selected" : "").">"._MOSTRECENT."</option>\n</select>\n");
314
-		if(!in_array("complete", $disablesorts)) $tpl->assign("completemenu", "<select class=\"textbox\" name=\"complete\">\n<option value=\"all\"".($complete == "all" ? " selected" : "").">"._ALLSTORIES."</option>\n<option value=\"1\"".($complete == 1 ? " selected" : "").">"._COMPLETEONLY."</option>\n<option value=\"0\"".($complete && $complete != "all" && $complete != 1 ? " selected" : "").">"._WIP."</option>\n</select>\n");
315
-		$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browsesorts'");
316
-		while($code = dbassoc($codeblocks)) {
317
-			eval($code['code_text']);
318
-		}
319
-		$tpl->assign("sortend"   , "<INPUT type=\"submit\" class=\"button\" name=\"go\" value=\""._GO."\"></form>");
320
-		$tpl->gotoBlock("_ROOT");
321
-	}
322
-}
323
-else  {
324
-	$output = "<div id='pagetitle'>"._BROWSE."</div>";
325
-	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_hidden != '1' AND panel_level ".(isMEMBER ? " < 2" : "= '0'")." AND panel_type = 'B' ORDER BY panel_type DESC, panel_order ASC, panel_title ASC");
326
-	while($panel = dbassoc($panelquery)) {
327
-		$browsetypes[$panel['panel_title']] =  "<a href=\"browse.php?type=".$panel['panel_name']."\">".$panel['panel_title']."</a><br />\n";
328
-	}
329
-	
330
-	foreach($classtypelist as $type => $info) {
331
-		$browsetypes[$info['title']] = "<a href='browse.php?type=class&amp;type_id=$type'>".$info['title']."</a><br />\n";
332
-	}
333
-	ksort($browsetypes);
334
-	$total = count($browsetypes);
335
-	$count = 0;
336
-	$column = 1;
337
-	$list = floor($total / $displaycolumns);
338
-	if($total % $displaycolumns != 0) $list++;
339
-	$output .= "<div id=\"columncontainer\"><div id=\"browseblock\">".($displaycolumns ? "<div class=\"column\">" : "");
340
-	foreach($browsetypes as $link) {
341
-		$count++;
342
-		$output .= $link;
343
-		if( $count >= $list && $column != $displaycolumns) {
344
-			$output .= "</div><div class=\"column\">";
345
-			if($total % $displaycolumns == $column) $list--;
346
-			$column++;
347
-			$count = 0;
348
-		}
349
-	}
350
-	$output .= "</div>".($displaycolumns ? "</div>" : "")."<div class='cleaner'>&nbsp;</div></div>";
351
-}
352
-$tpl->assign("output", $output);
353
-$tpl->printToScreen( );
354
-?>
1
+<?php
2
+// ----------------------------------------------------------------------
3
+// Copyright (c) 2007 by Tammy Keefer
4
+// Based on eFiction 1.1
5
+// Copyright (C) 2003 by Rebecca Smallwood.
6
+// http://efiction.sourceforge.net/
7
+// ----------------------------------------------------------------------
8
+// LICENSE
9
+//
10
+// This program is free software; you can redistribute it and/or
11
+// modify it under the terms of the GNU General Public License (GPL)
12
+// as published by the Free Software Foundation; either version 2
13
+// of the License, or (at your option) any later version.
14
+//
15
+// This program is distributed in the hope that it will be useful,
16
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+// GNU General Public License for more details.
19
+//
20
+// To read the license please visit http://www.gnu.org/copyleft/gpl.html
21
+// ---------------------------------------------------------------------
22
+
23
+$current = "browse";
24
+$displayform = 1;
25
+
26
+include ("header.php");
27
+
28
+if(file_exists("$skindir/browse.tpl")) $tpl = new TemplatePower( "$skindir/browse.tpl" );
29
+else $tpl = new TemplatePower("default_tpls/browse.tpl");
30
+if(file_exists("$skindir/listings.tpl")) $tpl->assignInclude("listings", "./$skindir/listings.tpl");
31
+else $tpl->assignInclude( "listings", "./default_tpls/listings.tpl" );
32
+$tpl->assignInclude( "header", "./$skindir/header.tpl" );
33
+$tpl->assignInclude( "footer", "./$skindir/footer.tpl" );
34
+
35
+include("includes/pagesetup.php");
36
+if(isset($_GET['type']) && is_string($_GET['type']) && preg_match('/^[a-z0-9_]{1,40}$/i', $_GET['type'])) $type = $_GET['type'];
37
+else $type = false;
38
+
39
+if($type) {
40
+	$query = array();
41
+	$countquery = array();
42
+	$scountquery = array();
43
+	$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple");
44
+	//if(!is_string($searchtype) || (isset($_REQUEST['searchterm']) && !is_string($_REQUEST['searchterm']))) errorExit(_ERROR); // this crashes the series results.
45
+	//if(!in_array($searchtype, array("simple", "title", "summary", "penname", "advanced", "fulltext"), true)) errorExit(_ERROR); // this crashes the series results.
46
+	$searchterm = isset($_REQUEST['searchterm']) && $_REQUEST['searchterm'] !== "" ? $_REQUEST['searchterm'] : false;
47
+	//if($searchtype == "fulltext" || ($searchtype == "simple" && $searchterm !== false)) errorExit(_ERROR); // this crashes the series results.
48
+	if(($searchtype != "simple" && $searchtype != "advanced" && ($searchterm === false || trim($searchterm) === "")) || ($searchterm !== false && strlen($searchterm) < 3)) errorExit(_SEARCHTERMTOOSHORT);
49
+	if($searchterm !== false) $searchterm = escapestring(strtr($searchterm, array("!" => "!!", "%" => "!%", "_" => "!_")));
50
+	$disablesorts = array( );
51
+	if($searchterm !== false) {
52
+		if($searchtype == "title") {
53
+			$query[] = "stories.title LIKE '%$searchterm%' ESCAPE '!'";
54
+			$countquery[] = "stories.title LIKE '%$searchterm%' ESCAPE '!'";
55
+			$scountquery[] = "series.title LIKE '%$searchterm%' ESCAPE '!'";
56
+		}
57
+		if($searchtype == "summary") {
58
+			$query[] = "stories.summary LIKE '%$searchterm%' ESCAPE '!'";
59
+			$countquery[] = "stories.summary LIKE '%$searchterm%' ESCAPE '!'";
60
+			$scountquery[] = "series.summary LIKE '%$searchterm%' ESCAPE '!'";
61
+		}
62
+		if($searchtype == "penname") {
63
+			$authorquery = dbquery(_MEMBERLIST." WHERE "._PENNAMEFIELD." LIKE '%$searchterm%' ESCAPE '!' GROUP BY "._UIDFIELD);
64
+			$authorlist = array();
65
+			while($auth = dbassoc($authorquery)) {
66
+				$authorlist[] = $auth['uid'];
67
+			}
68
+			if(count($authorlist) > 0) {
69
+				$query[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
70
+				$countquery[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
71
+				$scountquery[] = "FIND_IN_SET(series.uid, '".implode(",",$authorlist)."') > 0";
72
+			}
73
+			else {
74
+				$query[] = "1 = 0"; $countquery[] = "1 = 0"; $scountquery[] = "1 = 0";
75
+			}
76
+		}
77
+		if($searchtype == "advanced" || !$searchtype) {
78
+			$query[] = "(stories.summary LIKE '%$searchterm%' ESCAPE '!' OR stories.title LIKE '%$searchterm%' ESCAPE '!') ";
79
+			$countquery[] = "(stories.summary LIKE '%$searchterm%' ESCAPE '!' OR stories.title LIKE '%$searchterm%' ESCAPE '!') ";
80
+			$scountquery[] = "(summary LIKE '%$searchterm%' ESCAPE '!' OR title LIKE '%$searchterm%' ESCAPE '!') ";
81
+		}
82
+	}
83
+	$ef_authors = isset($_REQUEST['authors']) ? array_filter(array_map('trim', is_array($_REQUEST['authors']) ? $_REQUEST['authors'] : explode(",", (string)$_REQUEST['authors'])), "isNumber") : array( );
84
+	if($ef_authors) {
85
+		$ef_authors = implode(",", array_map('intval', $ef_authors));
86
+		$query[] = "FIND_IN_SET(stories.uid, '".$ef_authors."') > 0";
87
+		$countquery[] = "FIND_IN_SET(stories.uid, '".$ef_authors."') > 0";
88
+		$scountquery[] = "FIND_IN_SET(series.uid, '".$ef_authors."') > 0";
89
+	}
90
+	if(isset($_REQUEST['catid'])) {
91
+		$catid = is_array($_REQUEST['catid']) ? $_REQUEST['catid'] : explode(",", $_REQUEST['catid']);
92
+		$catid = array_filter($catid, "isNumber");
93
+	}
94
+	if(!isset($catid)) $catid = array();
95
+	if($type == "categories" && isset($_GET['id']) && isNumber($_GET['id'])) {
96
+		$catid[] =  $_GET['id'];
97
+	}
98
+	$categories = array( );
99
+	// Get the recursive list.
100
+	if($type == "categories") $categories = $catid;
101
+	else {
102
+		foreach($catid as $cat) {
103
+			if($cat == "false" || empty($cat)) continue;
104
+			$categories = array_merge($categories, recurseCategories($cat));
105
+		}
106
+	}
107
+	// Now format the SQL
108
+	foreach($categories as $cat) {
109
+		$catstories[] = "FIND_IN_SET($cat, stories.catid) > 0 ";
110
+		$catseries[] = "FIND_IN_SET($cat, series.catid) > 0 ";
111
+	}
112
+	// Now implode the SQL list
113
+	if(!empty($catstories)) {
114
+		$query[] = "(".implode(" OR ", $catstories).")";
115
+		$countquery[] = "(".implode(" OR ", $catstories).")";
116
+		$scountquery[] = "(".implode(" OR ", $catseries).")";
117
+	}
118
+	if(empty($charid)) $charid = array( );
119
+	if(isset($_REQUEST['charid'])) {
120
+		$charid = is_array($_REQUEST['charid']) ? $_REQUEST['charid'] : explode(",", $_REQUEST['charid']);
121
+		$charid = array_filter($charid, "isNumber");
122
+	}
123
+	if(!empty($_REQUEST['charlist1']) && isNumber($_REQUEST['charlist1']) && !in_array($_REQUEST['charlist1'], $charid)) $charid[] = $_REQUEST['charlist1'];
124
+	if(!empty($_REQUEST['charlist2']) && isNumber($_REQUEST['charlist2']) && !in_array($_REQUEST['charlist2'], $charid)) $charid[] = $_REQUEST['charlist2'];
125
+	if($charid) {
126
+		foreach($charid as $c) {
127
+			if(!empty($c)) {
128
+				$charstories[] = "FIND_IN_SET($c, stories.charid) > 0 ";
129
+				$charseries[] = "FIND_IN_SET($c, series.characters) > 0 ";
130
+			}
131
+		}
132
+		if(!empty($charstories)) {
133
+			$query[] = "(".implode(" AND ", $charstories).")";
134
+			$countquery[] = "(".implode(" AND ", $charstories).")";
135
+		}
136
+		if(!empty($charseries)) $scountquery[] = "(".implode(" AND ", $charseries).")";
137
+	}
138
+	$rid = array( ); $rating = array( );
139
+	if(!empty($_REQUEST['rid'])) $rid = is_array($_REQUEST['rid']) ? $_REQUEST['rid'] : explode(",", (string)$_REQUEST['rid']);
140
+	if(!empty($_REQUEST['rating'])) $rating = is_array($_REQUEST['rating']) ? $_REQUEST['rating'] : explode(",", (string)$_REQUEST['rating']);
141
+	$rid = array_values(array_filter(array_merge((array)$rid, (array)$rating), "isNumber")); // eFiction 4: numbers only
142
+	if(!empty($rid)) {
143
+		$query[] = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
144
+		$countquery[]  = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
145
+	}
146
+	$complete = "all";
147
+	if(isset($_REQUEST['complete'])) {
148
+		if($_REQUEST['complete'] == 1) {
149
+			$query[] = "stories.completed = '1'";
150
+			$countquery[] = "stories.completed = '1'";
151
+			$complete = 1;
152
+		} 
153
+		else if(empty($_REQUEST['complete'])) {
154
+			$query[] = "stories.completed = '0'";
155
+			$countquery[] = "stories.completed = '0'";
156
+			$complete = 0;
157
+		} 
158
+	}
159
+	if(isset($_REQUEST['classin'])) $classin = ef_browse_ids($_REQUEST['classin']);
160
+	else $classin = array( );
161
+	if(isset($_REQUEST['classex'])) $classex = ef_browse_ids($_REQUEST['classex']);
162
+	else $classex = array( );
163
+	$opts = array();
164
+	$exopts = array( );
165
+	foreach($classtypelist as $id => $vars) {
166
+		$opts = array(); $exopts = array();
167
+		if(isset($_REQUEST["class_".$id])) $opts = ef_browse_ids($_REQUEST["class_".$id]);
168
+		else if(isset($_REQUEST[$vars["name"]])) $opts = ef_browse_ids($_REQUEST[$vars["name"]]);
169
+		if(!empty($opts)) $classin = array_merge($classin, $opts);
170
+		if(isset($_REQUEST["exclass_".$id])) $exopts = ef_browse_ids($_REQUEST["exclass_".$id]);
171
+		if(!empty($exopts)) $classex = array_merge($classex, $exopts);
172
+		unset($opts, $exopts);
173
+	}
174
+	$classin = array_filter($classin, "isNumber");
175
+	$classex = array_filter($classex, "isNumber");
176
+	if($classin) {
177
+		foreach($classin as $class) {
178
+			if(empty($class)) continue;
179
+			$query[] = "FIND_IN_SET($class, stories.classes) > 0";
180
+			$countquery[] = "FIND_IN_SET($class, stories.classes) > 0";
181
+			$scountquery[] = "FIND_IN_SET($class, series.classes) > 0";
182
+		}
183
+	}
184
+	if($classex) {
185
+		foreach($classex as $class) {
186
+			$query[] = "FIND_IN_SET($class, stories.classes) = 0";
187
+			$countquery[] = "FIND_IN_SET($class, stories.classes) = 0";
188
+			$scountquery[] = "FIND_IN_SET($class, series.classes) = 0";
189
+		}
190
+	}
191
+	// Begin story length
192
+	unset($wordcount);
193
+	$wordlow = isset($_REQUEST['wordlow']) && preg_match('/^-?[0-9]{1,9}$/', (string)$_REQUEST['wordlow']) ? $_REQUEST['wordlow'] : "-500";
194
+	$wordhigh = isset($_REQUEST['wordhigh']) && preg_match('/^[0-9]{1,9}$/', (string)$_REQUEST['wordhigh']) ? $_REQUEST['wordhigh'] : "1000000";
195
+	if($wordlow != "-500") $wordcount = "stories.wordcount > ".$wordlow;
196
+	if($wordhigh != "1000000") 
197
+	{
198
+		if($wordcount) $wordcount .= " AND stories.wordcount < ".$wordhigh;
199
+		else $wordcount = "stories.wordcount < ".$wordhigh;
200
+	}
201
+	if($wordhigh < $wordlow) $wordcount = "stories.wordcount < ".$wordlow;
202
+	if($wordlow != "-500" && $wordhigh != "1000000" && isset($_POST['submit'])) {
203
+		$query[] = "($wordcount)";
204
+		$countquery[] = "($wordcount)";
205
+	}
206
+	// End wordcount
207
+	$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browseterms'");
208
+	while($code = dbassoc($codeblocks)) {
209
+		eval($code['code_text']);
210
+	}
211
+	$storyquery = count($query) > 0 ? " AND ".implode(" AND ", $query) : "";
212
+	$countquery = count($countquery) > 0 ? " AND ".implode(" AND ", $countquery) : "";
213
+	$seriesquery = count($scountquery) > 0 ? implode(" AND ", $scountquery) : false;
214
+	$termArray = array_merge($_GET, $_POST);
215
+	$termsList = array();
216
+	foreach($termArray as $term => $value) {
217
+		if($term == "submit" || $term == "go" || $term == "offset" || $term == "type" || ($term != "complete" && empty($value))) continue;
218
+		$termsList[$term] = ef_term($term, $value);
219
+	}
220
+	$terms = ef_term("type", $type).(count($termsList) ? "&amp;" : "").implode("&amp;", $termsList);
221
+// End query strings
222
+	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_name = '$type' AND panel_type = 'B' LIMIT 1");
223
+	if(dbnumrows($panelquery)) {
224
+		$numrows = 0;
225
+		$panel = dbassoc($panelquery);
226
+		if($panel['panel_url'] && file_exists(_BASEDIR.$panel['panel_url'])) include($panel['panel_url']);
227
+		else if(file_exists("browse/{$type}.php")) include("browse/{$type}.php");
228
+		else $output .= write_error(_ERROR);
229
+	}
230
+	else $output .= write_error(_ERROR);
231
+	$terms = implode("&amp;", $termsList);
232
+// Other results
233
+	$otherresults = array( );
234
+	$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
235
+	while($code = dbassoc($codeblocks)) {
236
+		eval($code['code_text']);
237
+	}
238
+	if($type != "series" && !empty($seriesquery)) {
239
+		$seriesresults = dbquery(_SERIESCOUNT." WHERE ".$seriesquery);
240
+		list($scount) = dbrow($seriesresults);
241
+		if($scount > 0) $otherresults[] = "<a href='browse.php?type=series&amp;$terms'>$scount "._SERIES."</a>";
242
+	}
243
+	if(count($otherresults) > 0 && $type != "titles") $tpl->assign("otherresults", "<div id='otherresults'><span class='label'>"._OTHERRESULTS.":</span> ".implode(", ", $otherresults)."</div>");
244
+// build our sort menus. if there aren't any stories don't bother with these since they won't be used
245
+	if(!empty($numrows) || isset($_POST['go'])) {
246
+		$tpl->newBlock("sortform");
247
+		$tpl->assign("sortbegin", "<form style=\"margin:0\" method=\"POST\" id=\"form\" enctype=\"multipart/form-data\" action=\"browse.php?type=$type&amp;$terms\">");
248
+		if($catlist && !in_array("categories", $disablesorts)) {
249
+			if(count($catid) > 0) $thiscat = $catid[0];
250
+			else $thiscat = -1;
251
+			$catmenu = "<select class=\"textbox\" name=\"catid\" id=\"catid\" onChange=\"browseCategories('catid')\"><option value=\"-1\">".($thiscat > 0 ? _BACK2CATS : _CATEGORIES)."</option>\n";
252
+			foreach($catlist as $cat => $info) {
253
+				if($info['pid'] == $thiscat || $cat == $thiscat) $catmenu .= "<option value=\"$cat\"".($thiscat == $cat ? " selected" : "").">".$info['name']."</option>\n";
254
+			}
255
+			$catmenu .= "</select>\n";
256
+			$tpl->assign("categorymenu", $catmenu);
257
+		}
258
+		if(count($charlist) > 0 && !in_array("characters", $disablesorts)) {
259
+			$charactermenu1 = "<select class=\"textbox\" name=\"charlist1\" id=\"charlist1\">\n";
260
+			$charactermenu1 .= "<option value=\"0\">"._CHARACTERS."</option>\n";
261
+			$charactermenu2 = "<select class=\"textbox\" name=\"charlist2\" id=\"charlist2\">\n";
262
+			$charactermenu2 .= "<option value=\"0\">"._CHARACTERS."</option>\n";
263
+			$categories[] = -1;
264
+			$categories = array_merge($categories, $catid);
265
+			foreach($charlist as $char => $info) {
266
+				if(is_array($categories) && in_array($info['catid'], $categories)) {
267
+					$charactermenu1 .= "<option value=\"$char\"";
268
+					if(isset($charid[0]) && $charid[0] == $char)
269
+						$charactermenu1 .= " selected";
270
+					$charactermenu1 .= ">".$info['name']."</option>\n";
271
+					$charactermenu2 .= "<option value=\"$char\"";
272
+					if(isset($charid[1]) && $charid[1] == $char)
273
+						$charactermenu2 .= " selected";
274
+					$charactermenu2 .= ">".$info['name']."</option>\n";
275
+				}
276
+			}
277
+			$charactermenu1 .= "</select>";
278
+			$charactermenu2 .= "</select>";
279
+			if($type != "characters") $tpl->assign("charactermenu1"   , $charactermenu1 );
280
+			$tpl->assign("charactermenu2"   , $charactermenu2 );
281
+		}
282
+		// To avoid throwing warnings we need to define $classopts and tell it how many elements it should have.
283
+		if(!in_array("classes", $disablesorts)) {
284
+			$classopts = array();
285
+			foreach($classlist as $id => $vars) {
286
+				if(empty($classopts[$vars['type']])) $classopts[$vars['type']] = "";
287
+				$classopts[$vars['type']] = $classopts[$vars['type']]."<option value=\"$id\"".(isset($classin) && is_array($classin) && in_array($id, $classin) ? " selected" : "").">".$vars['name']."</option>\n";
288
+			}
289
+			$allclasses = "";
290
+			foreach($classopts as $type => $opts) {
291
+				if(empty($type) || in_array($classtypelist[$type]['name'], $disablesorts)) continue; // Because of the way we defined $classopts we need to skip the empty first element.
292
+				$opts = "<option value=\"\">".$classtypelist[$type]['title']."</option>$opts";
293
+				$tpl->assign($classtypelist[$type]['name']."menu", "<select name=\"".$classtypelist["$type"]['name']."\">\n$opts</select>\n");
294
+				$allclasses .= "<select class=\"textbox\" name=\"".$classtypelist["$type"]['name']."\">\n$opts</select>\n ";
295
+			}
296
+			$tpl->assign("classmenu", $allclasses);
297
+		}
298
+		if(!in_array("ratings", $disablesorts)) {
299
+			$ratingmenu = "<select class=\"textbox\" name=\"rating\">\n";
300
+			$ratingmenu .= "<option value=\"0\">"._RATINGS."</option>\n";
301
+			if(!isset($ratingslist)) $ratingslist = array( );
302
+			foreach($ratingslist as $r => $rinfo) {
303
+				$ratingmenu .= "<option value=\"".$r."\"";
304
+				if(isset($rid) && in_array($r, $rid))
305
+					$ratingmenu .= " selected";
306
+				$ratingmenu .= ">".$rinfo['name']."</option>\n";
307
+			}
308
+			$ratingmenu .= "</select>\n";
309
+			$tpl->assign("ratingmenu"   , $ratingmenu );
310
+		}
311
+		if(!in_array("sorts", $disablesorts)) $tpl->assign("sortmenu", "<select class=\"textbox\" name=\"sort\">\n<option value=''>"._SORT."</option><option value=\"alpha\"".(!$defaultsort ? " selected" : "").">"._ALPHA."</option>\n<option value=\"update\"".($defaultsort == 1 ? " selected" : "").">"._MOSTRECENT."</option>\n</select>\n");
312
+		if(!in_array("complete", $disablesorts)) $tpl->assign("completemenu", "<select class=\"textbox\" name=\"complete\">\n<option value=\"all\"".($complete == "all" ? " selected" : "").">"._ALLSTORIES."</option>\n<option value=\"1\"".($complete == 1 ? " selected" : "").">"._COMPLETEONLY."</option>\n<option value=\"0\"".($complete && $complete != "all" && $complete != 1 ? " selected" : "").">"._WIP."</option>\n</select>\n");
313
+		$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browsesorts'");
314
+		while($code = dbassoc($codeblocks)) {
315
+			eval($code['code_text']);
316
+		}
317
+		$tpl->assign("sortend"   , "<INPUT type=\"submit\" class=\"button\" name=\"go\" value=\""._GO."\"></form>");
318
+		$tpl->gotoBlock("_ROOT");
319
+	}
320
+}
321
+else  {
322
+	$output = "<div id='pagetitle'>"._BROWSE."</div>";
323
+	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_hidden != '1' AND panel_level ".(isMEMBER ? " < 2" : "= '0'")." AND panel_type = 'B' ORDER BY panel_type DESC, panel_order ASC, panel_title ASC");
324
+	while($panel = dbassoc($panelquery)) {
325
+		$browsetypes[$panel['panel_title']] =  "<a href=\"browse.php?type=".$panel['panel_name']."\">".$panel['panel_title']."</a><br />\n";
326
+	}
327
+	
328
+	foreach($classtypelist as $type => $info) {
329
+		$browsetypes[$info['title']] = "<a href='browse.php?type=class&amp;type_id=$type'>".$info['title']."</a><br />\n";
330
+	}
331
+	ksort($browsetypes);
332
+	$total = count($browsetypes);
333
+	$count = 0;
334
+	$column = 1;
335
+	$list = floor($total / $displaycolumns);
336
+	if($total % $displaycolumns != 0) $list++;
337
+	$output .= "<div id=\"columncontainer\"><div id=\"browseblock\">".($displaycolumns ? "<div class=\"column\">" : "");
338
+	foreach($browsetypes as $link) {
339
+		$count++;
340
+		$output .= $link;
341
+		if( $count >= $list && $column != $displaycolumns) {
342
+			$output .= "</div><div class=\"column\">";
343
+			if($total % $displaycolumns == $column) $list--;
344
+			$column++;
345
+			$count = 0;
346
+		}
347
+	}
348
+	$output .= "</div>".($displaycolumns ? "</div>" : "")."<div class='cleaner'>&nbsp;</div></div>";
349
+}
350
+$tpl->assign("output", $output);
351
+$tpl->printToScreen( );
352
+
353
+function ef_browse_ids($value) {
354
+	$values = is_array($value) ? $value : explode(",", $value);
355
+	foreach($values as $v) {
356
+		if(!is_string($v) || ($v !== "" && !isNumber($v))) errorExit(_ERROR);
357
+	}
358
+	return array_values(array_filter($values, "isNumber"));
359
+}
360
+
361
+// Normally, this section would be in the includes/corefunctions.php file, but that is not getting updated for a while.
362
+
363
+// Function to format a URL into a clickable link
364
+// One "name=value" pair for a link that repeats the visitor's search or browse terms.
365
+// Names and values are URL-encoded and the result is safe inside an HTML attribute; arrays become a comma list.
366
+function ef_term($name, $value) {
367
+	if(is_array($value)) $value = implode(",", array_map(function($v) { return is_array($v) ? "" : (string)$v; }, $value));
368
+	return htmlspecialchars(rawurlencode((string)$name)."=".rawurlencode((string)$value), ENT_QUOTES);
369
+}
370
+
371
+// The current query string, minus the given keys, as "&amp;a=b&amp;c=d" (empty when nothing is left).
372
+function ef_query_terms($skip = array()) {
373
+	$out = "";
374
+	foreach($_GET as $k => $v) if(!in_array((string)$k, $skip, true)) $out .= "&amp;".ef_term($k, $v);
375
+	return $out;
376
+}
377
+?>
Browse code

Bugfix patches from upstream - and general cleanup of old hacks

Clarissa Walker authored on 2026/10/31 20:15:56
Showing 1 changed files
... ...
@@ -42,6 +42,7 @@ if($type) {
42 42
 	$scountquery = array();
43 43
 	$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple");
44 44
 	$searchterm =  (isset($_REQUEST['searchterm']) ? escapestring(descript($_REQUEST['searchterm'])) : false);
45
+	if($searchterm !== false) $searchterm = str_replace(array('%', '_'), array('\\%', '\\_'), escapestring($searchterm));
45 46
 	$disablesorts = array( );
46 47
 	if($searchterm) {
47 48
 		if($searchtype == "title") {
... ...
@@ -65,6 +66,9 @@ if($type) {
65 66
 				$countquery[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
66 67
 				$scountquery[] = "FIND_IN_SET(series.uid, '".implode(",",$authorlist)."') > 0";
67 68
 			}
69
+			else {
70
+				$query[] = "1 = 0"; $countquery[] = "1 = 0"; $scountquery[] = "1 = 0";
71
+			}
68 72
 		}
69 73
 		if($searchtype == "advanced" || !$searchtype) {
70 74
 			$query[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') ";
... ...
@@ -72,10 +76,12 @@ if($type) {
72 76
 			$scountquery[] = "(summary LIKE '%$searchterm%' OR title LIKE '%$searchterm%') ";
73 77
 		}
74 78
 	}
75
-	if(isset($_REQUEST['authors'])) {
76
-		$query[] = "FIND_IN_SET(stories.uid, '".implode(",",$searchVars['authors'])."') > 0";
77
-		$countquery[] = "FIND_IN_SET(stories.uid, '".implode(",",$searchVars['authors'])."') > 0";
78
-		$scountquery[] = "FIND_IN_SET(series.uid, '".implode(",",$searchVars['authors'])."') > 0";
79
+	$ef_authors = isset($_REQUEST['authors']) ? array_filter(array_map('trim', is_array($_REQUEST['authors']) ? $_REQUEST['authors'] : explode(",", (string)$_REQUEST['authors'])), "isNumber") : array( );
80
+	if($ef_authors) {
81
+		$ef_authors = implode(",", array_map('intval', $ef_authors));
82
+		$query[] = "FIND_IN_SET(stories.uid, '".$ef_authors."') > 0";
83
+		$countquery[] = "FIND_IN_SET(stories.uid, '".$ef_authors."') > 0";
84
+		$scountquery[] = "FIND_IN_SET(series.uid, '".$ef_authors."') > 0";
79 85
 	}
80 86
 	if(isset($_REQUEST['catid'])) {
81 87
 		$catid = is_array($_REQUEST['catid']) ? $_REQUEST['catid'] : explode(",", $_REQUEST['catid']);
Browse code

browse.php, search.php, includes/corefunctions.php: further security patches...

Clarissa Walker authored on 2026/10/28 21:09:19
Showing 1 changed files
... ...
@@ -211,7 +211,7 @@ if($type) {
211 211
 	$termsList = array();
212 212
 	foreach($termArray as $term => $value) {
213 213
 		if($term == "submit" || $term == "go" || $term == "offset" || $term == "type" || ($term != "complete" && empty($value))) continue;
214
-		$termsList[$term] = "$term=".(is_array($value) ? implode(",", array_map('htmlspecialchars', $value)) : htmlspecialchars($value, ENT_QUOTES));
214
+		$termsList[$term] = "$term=".(is_array($value) ? implode(",", array_map(function($v) { return htmlspecialchars($v, ENT_QUOTES); }, $value)) : htmlspecialchars($value, ENT_QUOTES));
215 215
 	}
216 216
 	$terms = "type=$type".(count($termsList) ? "&amp;" : "").implode("&amp;", $termsList);
217 217
 // End query strings
Browse code

admin.php, browse.php, user.php, includes/get_session_vars.php: Security - SQL injection patches - from @ariadoss

Clarissa Walker authored on 2026/10/26 13:11:20
Showing 1 changed files
... ...
@@ -41,7 +41,7 @@ if($type) {
41 41
 	$countquery = array();
42 42
 	$scountquery = array();
43 43
 	$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple");
44
-	$searchterm =  (isset($_REQUEST['searchterm']) ? descript($_REQUEST['searchterm']) : false);
44
+	$searchterm =  (isset($_REQUEST['searchterm']) ? escapestring(descript($_REQUEST['searchterm'])) : false);
45 45
 	$disablesorts = array( );
46 46
 	if($searchterm) {
47 47
 		if($searchtype == "title") {
... ...
@@ -112,6 +112,7 @@ if($type) {
112 112
 	}
113 113
 	if(!empty($_REQUEST['charlist1']) && !in_array($_REQUEST['charlist1'], $charid)) $charid[] = $_REQUEST['charlist1'];
114 114
 	if(!empty($_REQUEST['charlist2']) && !in_array($_REQUEST['charlist2'], $charid)) $charid[] = $_REQUEST['charlist2'];
115
+	$charid = array_filter($charid, "isNumber");
115 116
 	if($charid) {
116 117
 		foreach($charid as $c) {
117 118
 			if(!empty($c)) {
... ...
@@ -126,9 +127,9 @@ if($type) {
126 127
 		if(count($charseries) > 0) $scountquery[] = "(".implode(" AND ", $charseries).")";
127 128
 	}
128 129
 	$rid = array( ); $rating = array( );
129
-	if(!empty($_REQUEST['rid'])) $rid = is_array($_REQUEST['rid']) ? implode(",", $_REQUEST['rid']) : array($_REQUEST['rid']);
130
-	if(!empty($_REQUEST['rating'])) $rating = is_array($_REQUEST['rating']) ? implode(",", $_REQUEST['rating']) : array($_REQUEST['rating']);
131
-	$rid = array_merge($rid, $rating);
130
+	if(!empty($_REQUEST['rid'])) $rid = is_array($_REQUEST['rid']) ? $_REQUEST['rid'] : explode(",", $_REQUEST['rid']);
131
+	if(!empty($_REQUEST['rating'])) $rating = is_array($_REQUEST['rating']) ? $_REQUEST['rating'] : explode(",", $_REQUEST['rating']);
132
+	$rid = array_filter(array_merge($rid, $rating), "isNumber");
132 133
 	if(!empty($rid)) {
133 134
 		$query[] = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
134 135
 		$countquery[]  = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
... ...
@@ -185,8 +186,8 @@ if($type) {
185 186
 	}
186 187
 	// Begin story length
187 188
 	unset($wordcount);
188
-	$wordlow = isset($_REQUEST['wordlow']) ? $_REQUEST['wordlow'] : "-500";
189
-	$wordhigh = isset($_REQUEST['wordhigh']) ? $_REQUEST['wordhigh'] : "1000000";
189
+	$wordlow = isset($_REQUEST['wordlow']) && isNumber($_REQUEST['wordlow']) ? $_REQUEST['wordlow'] : "-500";
190
+	$wordhigh = isset($_REQUEST['wordhigh']) && isNumber($_REQUEST['wordhigh']) ? $_REQUEST['wordhigh'] : "1000000";
190 191
 	if($wordlow != "-500") $wordcount = "stories.wordcount > ".$wordlow;
191 192
 	if($wordhigh != "1000000") 
192 193
 	{
... ...
@@ -210,11 +211,11 @@ if($type) {
210 211
 	$termsList = array();
211 212
 	foreach($termArray as $term => $value) {
212 213
 		if($term == "submit" || $term == "go" || $term == "offset" || $term == "type" || ($term != "complete" && empty($value))) continue;
213
-		$termsList[$term] = "$term=".(is_array($value) ? implode(",", $value) : $value);
214
+		$termsList[$term] = "$term=".(is_array($value) ? implode(",", array_map('htmlspecialchars', $value)) : htmlspecialchars($value, ENT_QUOTES));
214 215
 	}
215 216
 	$terms = "type=$type".(count($termsList) ? "&amp;" : "").implode("&amp;", $termsList);
216 217
 // End query strings
217
-	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_name = '$type' AND panel_type = 'B' LIMIT 1");
218
+	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_name = '".escapestring($type)."' AND panel_type = 'B' LIMIT 1");
218 219
 	if(dbnumrows($panelquery)) {
219 220
 		$numrows = 0;
220 221
 		$panel = dbassoc($panelquery);
Browse code

3.5.6 efiction version

Jimako authored on 2024/03/09 16:09:42
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,347 @@
1
+<?php
2
+// ----------------------------------------------------------------------
3
+// Copyright (c) 2007 by Tammy Keefer
4
+// Based on eFiction 1.1
5
+// Copyright (C) 2003 by Rebecca Smallwood.
6
+// http://efiction.sourceforge.net/
7
+// ----------------------------------------------------------------------
8
+// LICENSE
9
+//
10
+// This program is free software; you can redistribute it and/or
11
+// modify it under the terms of the GNU General Public License (GPL)
12
+// as published by the Free Software Foundation; either version 2
13
+// of the License, or (at your option) any later version.
14
+//
15
+// This program is distributed in the hope that it will be useful,
16
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+// GNU General Public License for more details.
19
+//
20
+// To read the license please visit http://www.gnu.org/copyleft/gpl.html
21
+// ---------------------------------------------------------------------
22
+
23
+$current = "browse";
24
+$displayform = 1;
25
+
26
+include ("header.php");
27
+
28
+if(file_exists("$skindir/browse.tpl")) $tpl = new TemplatePower( "$skindir/browse.tpl" );
29
+else $tpl = new TemplatePower("default_tpls/browse.tpl");
30
+if(file_exists("$skindir/listings.tpl")) $tpl->assignInclude("listings", "./$skindir/listings.tpl");
31
+else $tpl->assignInclude( "listings", "./default_tpls/listings.tpl" );
32
+$tpl->assignInclude( "header", "./$skindir/header.tpl" );
33
+$tpl->assignInclude( "footer", "./$skindir/footer.tpl" );
34
+
35
+include("includes/pagesetup.php");
36
+if(isset($_GET['type'])) $type = descript($_GET['type']);
37
+else $type = false;
38
+
39
+if($type) {
40
+	$query = array();
41
+	$countquery = array();
42
+	$scountquery = array();
43
+	$searchtype = (isset($_REQUEST['searchtype']) ? $_REQUEST['searchtype'] : "simple");
44
+	$searchterm =  (isset($_REQUEST['searchterm']) ? descript($_REQUEST['searchterm']) : false);
45
+	$disablesorts = array( );
46
+	if($searchterm) {
47
+		if($searchtype == "title") {
48
+			$query[] = "stories.title LIKE '%$searchterm%'";
49
+			$countquery[] = "stories.title LIKE '%$searchterm%'";
50
+			$scountquery[] = "series.title LIKE '%$searchterm%'";
51
+		}
52
+		if($searchtype == "summary") {
53
+			$query[] = "stories.summary LIKE '%$searchterm%'";
54
+			$countquery[] = "stories.summary LIKE '%$searchterm%'";
55
+			$scountquery[] = "series.summary LIKE '%$searchterm%'";
56
+		}
57
+		if($searchtype == "penname") {
58
+			$authorquery = dbquery(_MEMBERLIST." WHERE "._PENNAMEFIELD." LIKE '%$searchterm%' GROUP BY "._UIDFIELD);
59
+			$authorlist = array();
60
+			while($auth = dbassoc($authorquery)) {
61
+				$authorlist[] = $auth['uid'];
62
+			}
63
+			if(count($authorlist) > 0) {
64
+				$query[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
65
+				$countquery[] = "FIND_IN_SET(stories.uid, '".implode(",",$authorlist)."') > 0";
66
+				$scountquery[] = "FIND_IN_SET(series.uid, '".implode(",",$authorlist)."') > 0";
67
+			}
68
+		}
69
+		if($searchtype == "advanced" || !$searchtype) {
70
+			$query[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') ";
71
+			$countquery[] = "(stories.summary LIKE '%$searchterm%' OR stories.title LIKE '%$searchterm%') ";
72
+			$scountquery[] = "(summary LIKE '%$searchterm%' OR title LIKE '%$searchterm%') ";
73
+		}
74
+	}
75
+	if(isset($_REQUEST['authors'])) {
76
+		$query[] = "FIND_IN_SET(stories.uid, '".implode(",",$searchVars['authors'])."') > 0";
77
+		$countquery[] = "FIND_IN_SET(stories.uid, '".implode(",",$searchVars['authors'])."') > 0";
78
+		$scountquery[] = "FIND_IN_SET(series.uid, '".implode(",",$searchVars['authors'])."') > 0";
79
+	}
80
+	if(isset($_REQUEST['catid'])) {
81
+		$catid = is_array($_REQUEST['catid']) ? $_REQUEST['catid'] : explode(",", $_REQUEST['catid']);
82
+		$catid = array_filter($catid, "isNumber");
83
+	}
84
+	if(!isset($catid)) $catid = array();
85
+	if($type == "categories" && isset($_GET['id']) && isNumber($_GET['id'])) {
86
+		$catid[] =  $_GET['id'];
87
+	}
88
+	$categories = array( );
89
+	// Get the recursive list.
90
+	if($type == "categories") $categories = $catid;
91
+	else {
92
+		foreach($catid as $cat) {
93
+			if($cat == "false" || empty($cat)) continue;
94
+			$categories = array_merge($categories, recurseCategories($cat));
95
+		}
96
+	}
97
+	// Now format the SQL
98
+	foreach($categories as $cat) {
99
+		$catstories[] = "FIND_IN_SET($cat, stories.catid) > 0 ";
100
+		$catseries[] = "FIND_IN_SET($cat, series.catid) > 0 ";
101
+	}
102
+	// Now implode the SQL list
103
+	if(!empty($catstories)) {
104
+		$query[] = "(".implode(" OR ", $catstories).")";
105
+		$countquery[] = "(".implode(" OR ", $catstories).")";
106
+		$scountquery[] = "(".implode(" OR ", $catseries).")";
107
+	}
108
+	if(empty($charid)) $charid = array( );
109
+	if(isset($_REQUEST['charid'])) {
110
+		$charid = is_array($_REQUEST['charid']) ? $_REQUEST['charid'] : explode(",", $_REQUEST['charid']);
111
+		$charid = array_filter($charid, "isNumber");
112
+	}
113
+	if(!empty($_REQUEST['charlist1']) && !in_array($_REQUEST['charlist1'], $charid)) $charid[] = $_REQUEST['charlist1'];
114
+	if(!empty($_REQUEST['charlist2']) && !in_array($_REQUEST['charlist2'], $charid)) $charid[] = $_REQUEST['charlist2'];
115
+	if($charid) {
116
+		foreach($charid as $c) {
117
+			if(!empty($c)) {
118
+				$charstories[] = "FIND_IN_SET($c, stories.charid) > 0 ";
119
+				$charseries[] = "FIND_IN_SET($c, series.characters) > 0 ";
120
+			}
121
+		}
122
+		if(count($charstories) > 0) {
123
+			$query[] = "(".implode(" AND ", $charstories).")";
124
+			$countquery[] = "(".implode(" AND ", $charstories).")";
125
+		}
126
+		if(count($charseries) > 0) $scountquery[] = "(".implode(" AND ", $charseries).")";
127
+	}
128
+	$rid = array( ); $rating = array( );
129
+	if(!empty($_REQUEST['rid'])) $rid = is_array($_REQUEST['rid']) ? implode(",", $_REQUEST['rid']) : array($_REQUEST['rid']);
130
+	if(!empty($_REQUEST['rating'])) $rating = is_array($_REQUEST['rating']) ? implode(",", $_REQUEST['rating']) : array($_REQUEST['rating']);
131
+	$rid = array_merge($rid, $rating);
132
+	if(!empty($rid)) {
133
+		$query[] = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
134
+		$countquery[]  = "FIND_IN_SET(stories.rid, '".(implode(",", $rid))."') > 0";
135
+	}
136
+	$complete = "all";
137
+	if(isset($_REQUEST['complete'])) {
138
+		if($_REQUEST['complete'] == 1) {
139
+			$query[] = "stories.completed = '1'";
140
+			$countquery[] = "stories.completed = '1'";
141
+			$complete = 1;
142
+		} 
143
+		else if(empty($_REQUEST['complete'])) {
144
+			$query[] = "stories.completed = '0'";
145
+			$countquery[] = "stories.completed = '0'";
146
+			$complete = 0;
147
+		} 
148
+	}
149
+	if(isset($_REQUEST['classin'])) $classin = is_array($_REQUEST['classin']) ? $_REQUEST['classin'] : array($_REQUEST['classin']);
150
+	else $classin = array( );
151
+	if(isset($_REQUEST['classex'])) $classex = is_array($_REQUEST['classex']) ? $_REQUEST['classex'] : array($_REQUEST['classex']);
152
+	else $classex = array( );
153
+	$opts = array();
154
+	$exopts = array( );
155
+	foreach($classtypelist as $id => $vars) {
156
+		if(!empty($_POST[$vars['name']])) $opts[] = $_POST[$vars['name']];
157
+		else if(isset($_GET["class_".$id])) {
158
+			$opts = !empty($opts) ? array_merge($opts, explode(",", $_GET["class_".$id])) : array($_GET["class_".$id]);
159
+		}
160
+		else if(!empty($_REQUEST[$vars["name"]])) $opts = is_array($_REQUEST[$vars["name"]]) ? $_REQUEST[$vars["name"]] : array($_REQUEST[$vars["name"]]);
161
+		if(!empty($opts)) $classin = array_merge($classin, $opts);
162
+		if(isset($_POST["exclass_".$id])) $exopts = $_POST["exclass_".$id];
163
+		else if(isset($_GET["exclass_".$id])) {
164
+			$exopts = !empty($exopts) ? array_merge($exopts, explode(",", $_GET["exclass_".$id])) : array($_GET["exclass_".$id]);
165
+		}
166
+		if(!empty($exopts)) $classex = array_merge($classex, $exopts);
167
+		unset($opts, $exopts);
168
+	}
169
+	$classin = array_filter($classin, "isNumber");
170
+	$classex = array_filter($classex, "isNumber");
171
+	if($classin) {
172
+		foreach($classin as $class) {
173
+			if(empty($class)) continue;
174
+			$query[] = "FIND_IN_SET($class, stories.classes) > 0";
175
+			$countquery[] = "FIND_IN_SET($class, stories.classes) > 0";
176
+			$scountquery[] = "FIND_IN_SET($class, series.classes) > 0";
177
+		}
178
+	}
179
+	if($classex) {
180
+		foreach($classex as $class) {
181
+			$query[] = "FIND_IN_SET($class, stories.classes) = 0";
182
+			$countquery[] = "FIND_IN_SET($class, stories.classes) = 0";
183
+			$scountquery[] = "FIND_IN_SET($class, series.classes) = 0";
184
+		}
185
+	}
186
+	// Begin story length
187
+	unset($wordcount);
188
+	$wordlow = isset($_REQUEST['wordlow']) ? $_REQUEST['wordlow'] : "-500";
189
+	$wordhigh = isset($_REQUEST['wordhigh']) ? $_REQUEST['wordhigh'] : "1000000";
190
+	if($wordlow != "-500") $wordcount = "stories.wordcount > ".$wordlow;
191
+	if($wordhigh != "1000000") 
192
+	{
193
+		if($wordcount) $wordcount .= " AND stories.wordcount < ".$wordhigh;
194
+		else $wordcount = "stories.wordcount < ".$wordhigh;
195
+	}
196
+	if($wordhigh < $wordlow) $wordcount = "stories.wordcount < ".$wordlow;
197
+	if($wordlow != "-500" && $wordhigh != "1000000" && isset($_POST['submit'])) {
198
+		$query[] = "($wordcount)";
199
+		$countquery[] = "($wordcount)";
200
+	}
201
+	// End wordcount
202
+	$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browseterms'");
203
+	while($code = dbassoc($codeblocks)) {
204
+		eval($code['code_text']);
205
+	}
206
+	$storyquery = count($query) > 0 ? " AND ".implode(" AND ", $query) : "";
207
+	$countquery = count($countquery) > 0 ? " AND ".implode(" AND ", $countquery) : "";
208
+	$seriesquery = count($scountquery) > 0 ? implode(" AND ", $scountquery) : false;
209
+	$termArray = array_merge($_GET, $_POST);
210
+	$termsList = array();
211
+	foreach($termArray as $term => $value) {
212
+		if($term == "submit" || $term == "go" || $term == "offset" || $term == "type" || ($term != "complete" && empty($value))) continue;
213
+		$termsList[$term] = "$term=".(is_array($value) ? implode(",", $value) : $value);
214
+	}
215
+	$terms = "type=$type".(count($termsList) ? "&amp;" : "").implode("&amp;", $termsList);
216
+// End query strings
217
+	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_name = '$type' AND panel_type = 'B' LIMIT 1");
218
+	if(dbnumrows($panelquery)) {
219
+		$numrows = 0;
220
+		$panel = dbassoc($panelquery);
221
+		if($panel['panel_url'] && file_exists(_BASEDIR.$panel['panel_url'])) include($panel['panel_url']);
222
+		else if(file_exists("browse/{$type}.php")) include("browse/{$type}.php");
223
+		else $output .= write_error(_ERROR);
224
+	}
225
+	else $output .= write_error(_ERROR);
226
+	$terms = implode("&amp;", $termsList);
227
+// Other results
228
+	$otherresults = array( );
229
+	$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'otherresults'");
230
+	while($code = dbassoc($codeblocks)) {
231
+		eval($code['code_text']);
232
+	}
233
+	if($type != "series" && !empty($seriesquery)) {
234
+		$seriesresults = dbquery(_SERIESCOUNT." WHERE ".$seriesquery);
235
+		list($scount) = dbrow($seriesresults);
236
+		if($scount > 0) $otherresults[] = "<a href='browse.php?type=series&amp;$terms'>$scount "._SERIES."</a>";
237
+	}
238
+	if(count($otherresults) > 0 && $type != "titles") $tpl->assign("otherresults", "<div id='otherresults'><span class='label'>"._OTHERRESULTS.":</span> ".implode(", ", $otherresults)."</div>");
239
+// build our sort menus. if there aren't any stories don't bother with these since they won't be used
240
+	if(!empty($numrows) || isset($_POST['go'])) {
241
+		$tpl->newBlock("sortform");
242
+		$tpl->assign("sortbegin", "<form style=\"margin:0\" method=\"POST\" id=\"form\" enctype=\"multipart/form-data\" action=\"browse.php?type=$type&amp;$terms\">");
243
+		if($catlist && !in_array("categories", $disablesorts)) {
244
+			if(count($catid) > 0) $thiscat = $catid[0];
245
+			else $thiscat = -1;
246
+			$catmenu = "<select class=\"textbox\" name=\"catid\" id=\"catid\" onChange=\"browseCategories('catid')\"><option value=\"-1\">".($thiscat > 0 ? _BACK2CATS : _CATEGORIES)."</option>\n";
247
+			foreach($catlist as $cat => $info) {
248
+				if($info['pid'] == $thiscat || $cat == $thiscat) $catmenu .= "<option value=\"$cat\"".($thiscat == $cat ? " selected" : "").">".$info['name']."</option>\n";
249
+			}
250
+			$catmenu .= "</select>\n";
251
+			$tpl->assign("categorymenu", $catmenu);
252
+		}
253
+		if(count($charlist) > 0 && !in_array("characters", $disablesorts)) {
254
+			$charactermenu1 = "<select class=\"textbox\" name=\"charlist1\" id=\"charlist1\">\n";
255
+			$charactermenu1 .= "<option value=\"0\">"._CHARACTERS."</option>\n";
256
+			$charactermenu2 = "<select class=\"textbox\" name=\"charlist2\" id=\"charlist2\">\n";
257
+			$charactermenu2 .= "<option value=\"0\">"._CHARACTERS."</option>\n";
258
+			$categories[] = -1;
259
+			$categories = array_merge($categories, $catid);
260
+			foreach($charlist as $char => $info) {
261
+				if(is_array($categories) && in_array($info['catid'], $categories)) {
262
+					$charactermenu1 .= "<option value=\"$char\"";
263
+					if(isset($charid[0]) && $charid[0] == $char)
264
+						$charactermenu1 .= " selected";
265
+					$charactermenu1 .= ">".$info['name']."</option>\n";
266
+					$charactermenu2 .= "<option value=\"$char\"";
267
+					if(isset($charid[1]) && $charid[1] == $char)
268
+						$charactermenu2 .= " selected";
269
+					$charactermenu2 .= ">".$info['name']."</option>\n";
270
+				}
271
+			}
272
+			$charactermenu1 .= "</select>";
273
+			$charactermenu2 .= "</select>";
274
+			if($type != "characters") $tpl->assign("charactermenu1"   , $charactermenu1 );
275
+			$tpl->assign("charactermenu2"   , $charactermenu2 );
276
+		}
277
+		// To avoid throwing warnings we need to define $classopts and tell it how many elements it should have.
278
+		if(!in_array("classes", $disablesorts)) {
279
+			$classopts = array();
280
+			foreach($classlist as $id => $vars) {
281
+				if(empty($classopts[$vars['type']])) $classopts[$vars['type']] = "";
282
+				$classopts[$vars['type']] = $classopts[$vars['type']]."<option value=\"$id\"".(isset($classin) && is_array($classin) && in_array($id, $classin) ? " selected" : "").">".$vars['name']."</option>\n";
283
+			}
284
+			$allclasses = "";
285
+			foreach($classopts as $type => $opts) {
286
+				if(empty($type) || in_array($classtypelist[$type]['name'], $disablesorts)) continue; // Because of the way we defined $classopts we need to skip the empty first element.
287
+				$opts = "<option value=\"\">".$classtypelist[$type]['title']."</option>$opts";
288
+				$tpl->assign($classtypelist[$type]['name']."menu", "<select name=\"".$classtypelist["$type"]['name']."\">\n$opts</select>\n");
289
+				$allclasses .= "<select class=\"textbox\" name=\"".$classtypelist["$type"]['name']."\">\n$opts</select>\n ";
290
+			}
291
+			$tpl->assign("classmenu", $allclasses);
292
+		}
293
+		if(!in_array("ratings", $disablesorts)) {
294
+			$ratingmenu = "<select class=\"textbox\" name=\"rating\">\n";
295
+			$ratingmenu .= "<option value=\"0\">"._RATINGS."</option>\n";
296
+			if(!isset($ratingslist)) $ratingslist = array( );
297
+			foreach($ratingslist as $r => $rinfo) {
298
+				$ratingmenu .= "<option value=\"".$r."\"";
299
+				if(isset($rid) && in_array($r, $rid))
300
+					$ratingmenu .= " selected";
301
+				$ratingmenu .= ">".$rinfo['name']."</option>\n";
302
+			}
303
+			$ratingmenu .= "</select>\n";
304
+			$tpl->assign("ratingmenu"   , $ratingmenu );
305
+		}
306
+		if(!in_array("sorts", $disablesorts)) $tpl->assign("sortmenu", "<select class=\"textbox\" name=\"sort\">\n<option value=''>"._SORT."</option><option value=\"alpha\"".(!$defaultsort ? " selected" : "").">"._ALPHA."</option>\n<option value=\"update\"".($defaultsort == 1 ? " selected" : "").">"._MOSTRECENT."</option>\n</select>\n");
307
+		if(!in_array("complete", $disablesorts)) $tpl->assign("completemenu", "<select class=\"textbox\" name=\"complete\">\n<option value=\"all\"".($complete == "all" ? " selected" : "").">"._ALLSTORIES."</option>\n<option value=\"1\"".($complete == 1 ? " selected" : "").">"._COMPLETEONLY."</option>\n<option value=\"0\"".($complete && $complete != "all" && $complete != 1 ? " selected" : "").">"._WIP."</option>\n</select>\n");
308
+		$codeblocks = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'browsesorts'");
309
+		while($code = dbassoc($codeblocks)) {
310
+			eval($code['code_text']);
311
+		}
312
+		$tpl->assign("sortend"   , "<INPUT type=\"submit\" class=\"button\" name=\"go\" value=\""._GO."\"></form>");
313
+		$tpl->gotoBlock("_ROOT");
314
+	}
315
+}
316
+else  {
317
+	$output = "<div id='pagetitle'>"._BROWSE."</div>";
318
+	$panelquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_hidden != '1' AND panel_level ".(isMEMBER ? " < 2" : "= '0'")." AND panel_type = 'B' ORDER BY panel_type DESC, panel_order ASC, panel_title ASC");
319
+	while($panel = dbassoc($panelquery)) {
320
+		$browsetypes[$panel['panel_title']] =  "<a href=\"browse.php?type=".$panel['panel_name']."\">".$panel['panel_title']."</a><br />\n";
321
+	}
322
+	
323
+	foreach($classtypelist as $type => $info) {
324
+		$browsetypes[$info['title']] = "<a href='browse.php?type=class&amp;type_id=$type'>".$info['title']."</a><br />\n";
325
+	}
326
+	ksort($browsetypes);
327
+	$total = count($browsetypes);
328
+	$count = 0;
329
+	$column = 1;
330
+	$list = floor($total / $displaycolumns);
331
+	if($total % $displaycolumns != 0) $list++;
332
+	$output .= "<div id=\"columncontainer\"><div id=\"browseblock\">".($displaycolumns ? "<div class=\"column\">" : "");
333
+	foreach($browsetypes as $link) {
334
+		$count++;
335
+		$output .= $link;
336
+		if( $count >= $list && $column != $displaycolumns) {
337
+			$output .= "</div><div class=\"column\">";
338
+			if($total % $displaycolumns == $column) $list--;
339
+			$column++;
340
+			$count = 0;
341
+		}
342
+	}
343
+	$output .= "</div>".($displaycolumns ? "</div>" : "")."<div class='cleaner'>&nbsp;</div></div>";
344
+}
345
+$tpl->assign("output", $output);
346
+$tpl->printToScreen( );
347
+?>