Browse code

Initial uplad w/ php7 fixes

Rainer Volkrodt authored on 2016/03/12 15:54:02
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
+?>