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,413 @@
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
+// Force the argument separator to be standards compliant
24
+@ ini_set('arg_separator.output','&amp;'); 
25
+if(isset($_GET['debug'])) @ error_reporting(E_ALL);
26
+if(isset($_GET['benchmark'])) {
27
+	list($usec, $sec) = explode(" ", microtime());
28
+	$start = ((float)$usec + (float)$sec);
29
+}
30
+$headerSent = false;
31
+if(get_magic_quotes_gpc()){
32
+	foreach($_POST as $var => $val) {
33
+		$_POST[$var] = is_array( $val ) ? array_map( 'stripslashes', $val ) : stripslashes( $val );
34
+	}
35
+	foreach($_GET as $var => $val) {
36
+		$_GET[$var] = is_array( $val ) ? array_map( 'stripslashes', $val ) : stripslashes( $val );
37
+	}
38
+}
39
+
40
+// Prevent possible XSS attacks via $_GET.
41
+foreach ($_GET as $v) {
42
+	if(preg_match('@<script[^>]*?>.*?</script>@si', $v) ||
43
+		preg_match("'@<iframe[^>]*?>.*?</script>@si'", $v) ||
44
+		preg_match("'@<applet[^>]*?>.*?</script>@si'", $v) ||
45
+		preg_match("'@<meta[^>]*?>.*?</script>@si'", $v) ||
46
+		preg_match('@<[\/\!]*?[^<>]*?>@si', $v) ||
47
+		preg_match('@<style[^>]*?>.*?</style>@siU', $v) ||
48
+		preg_match('@<![\s\S]*?--[ \t\n\r]*>@', $v)) {
49
+		include("languages/en.php"); // no language set yet, so default to English.	
50
+		die (_POSSIBLEHACK);
51
+	}
52
+}
53
+unset($v);
54
+
55
+if(!isset($_SESSION)) session_start();
56
+// clear the global variables if register globals is on.
57
+if(ini_get('register_globals')) {
58
+	$arrayList = array_merge($_SESSION, $_GET, $_POST, $_COOKIE);
59
+	foreach($arrayList as $k => $v) {
60
+		unset($GLOBALS[$k]);
61
+	}
62
+}
63
+
64
+Header('Cache-Control: private, no-cache, must-revalidate, max_age=0, post-check=0, pre-check=0');
65
+header ("Pragma: no-cache"); 
66
+header ("Expires: 0"); 
67
+header("Content-Type: text/html; charset="._CHARSET);
68
+
69
+// Locate config.php and set the basedir path
70
+$folder_level = "";
71
+while (!file_exists($folder_level."header.php")) { $folder_level .= "../"; }
72
+if(!defined("_BASEDIR")) define("_BASEDIR", $folder_level);
73
+
74
+@ include_once(_BASEDIR."config.php");
75
+if(empty($sitekey)) {
76
+	header("Location: install/install.php");
77
+	exit( );
78
+}
79
+if(isset($skin)) $globalskin = $skin; 
80
+$settingsresults = dbquery("SELECT * FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '".$sitekey."'");
81
+$settings = dbassoc($settingsresults);
82
+if(!defined("SITEKEY")) define("SITEKEY", $settings['sitekey']);
83
+unset($settings['sitekey']);
84
+if(!defined("TABLEPREFIX")) define("TABLEPREFIX", $settings['tableprefix']);
85
+unset($settings['tableprefix']);
86
+define("STORIESPATH", $settings['storiespath']);
87
+unset($settings['storiespath']);
88
+foreach($settings as $var => $val) {
89
+	$$var = stripslashes($val);
90
+	$settings[$var] = htmlspecialchars($val);
91
+}
92
+
93
+if(isset($_GET['debug'])) $debug = 1;
94
+if(!$displaycolumns) $displaycolumns = 1; // shouldn't happen, but just in case.
95
+if($words) $words = explode(", ", $words);
96
+else $words = array( );
97
+// Fix for sites with 2.0 or 1.1 running as well as 3.0 with register_globals on.
98
+$defaultskin = $skin;
99
+
100
+if(isset($globalskin)) $skin = $globalskin;
101
+
102
+if(isset($_GET['action'])) $action = strip_tags($_GET['action']);
103
+else $action = false;
104
+
105
+if(file_exists(_BASEDIR."languages/{$language}.php")) include (_BASEDIR."languages/{$language}.php");
106
+else include (_BASEDIR."languages/en.php");
107
+
108
+include_once(_BASEDIR."includes/queries.php");
109
+include_once(_BASEDIR."includes/corefunctions.php");
110
+
111
+// Check and/or set some variables used at various points throughout the script
112
+if(isset($_GET['offset'])) $offset = $_GET['offset'];
113
+if(!isset($offset) || !isNumber($offset)) $offset = 0;
114
+if(isset($_REQUEST["sid"])) $sid = $_REQUEST["sid"];
115
+if(isset($sid) && !isNumber($sid)) unset($sid);
116
+if(isset($_REQUEST['seriesid'])) $seriesid = $_REQUEST["seriesid"];
117
+if(isset($seriesid) && !isNumber($seriesid)) unset($seriesid);
118
+if(isset($_REQUEST['uid'])) $uid = $_REQUEST["uid"];
119
+if(isset($uid) && !isNumber($uid)) unset($uid);
120
+if(isset($_REQUEST['chapid'])) $chapid = $_REQUEST["chapid"];
121
+if(isset($chapid) && !isNumber($chapid)) unset($chapid);
122
+$let = false;
123
+if(isset($_GET['let'])) $let = $_GET['let'];
124
+if(isset($let) && !in_array($let, $alphabet)) $let = false;
125
+$output = "";
126
+
127
+// Cleans these two variables of possible XSS attacks.
128
+if(isset($_SERVER['PHP_SELF'])) $_SERVER['PHP_SELF'] = htmlspecialchars(descript($_SERVER['PHP_SELF']), ENT_QUOTES);
129
+if(isset($PHP_SELF)) $PHP_SELF = htmlspecialchars(descript($PHP_SELF), ENT_QUOTES);
130
+
131
+// Set these variables to start.
132
+$agecontsent = false; $viewed = false; 
133
+
134
+require_once("includes/get_session_vars.php");
135
+
136
+if(isset($_GET['skin'])) {
137
+	$siteskin = $_GET['skin'];
138
+	$_SESSION[SITEKEY."_skin"] = $siteskin;
139
+}
140
+
141
+$v = explode(".", $version);
142
+include("version.php");
143
+$newV = explode(".", $version);
144
+//if($v[0] == $newV[0] && ($v[1] < $newV[1] || (isset($newV[2]) && $v[2] < $newV[2]))) {
145
+foreach($newV AS $k => $l) {
146
+	if($newV[$k] > $v[$k] || (!empty($newV[$k]) && empty($v[$k]))) {
147
+		if(isADMIN && basename($_SERVER['PHP_SELF']) != "update.php") {
148
+			header("Location: update.php");
149
+			exit( );
150
+		}
151
+		else if(!isADMIN && basename($_SERVER['PHP_SELF']) != "maintenance.php" && !(isset($_GET['action']) && $_GET['action'] == "login")) {
152
+			header("Location: maintenance.php");
153
+			exit( );
154
+		}
155
+	}
156
+}
157
+
158
+if(!empty($_SESSION[SITEKEY."_skin"])) $siteskin = $_SESSION[SITEKEY."_skin"];
159
+if($maintenance && !isADMIN && basename($_SERVER['PHP_SELF']) != "maintenance.php" && !(isset($_GET['action']) && $_GET['action'] == "login")) {
160
+	header("Location: maintenance.php");
161
+	exit( );
162
+}
163
+
164
+$blockquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_blocks");
165
+while($block = dbassoc($blockquery)) {
166
+	$blocks[$block['block_name']] = unserialize($block['block_variables']);
167
+	$blocks[$block['block_name']]['title'] = $block['block_title'];
168
+	$blocks[$block['block_name']]['file'] = $block['block_file'];
169
+	$blocks[$block['block_name']]['status'] = $block['block_status'];
170
+}
171
+
172
+// This session variable is used to track the story views
173
+if(isset($_SESSION[SITEKEY."_viewed"])) $viewed = $_SESSION[SITEKEY."_viewed"];
174
+
175
+if(isset($_GET['ageconsent'])) $_SESSION[SITEKEY."_ageconsent"] = 1;
176
+if(isset($_GET['warning'])) $_SESSION[SITEKEY."_warned"][$_GET['warning']] = 1;
177
+
178
+if(file_exists("languages/{$language}.php")) require_once ("languages/{$language}.php");
179
+else require_once ("languages/en.php");
180
+if(is_dir(_BASEDIR."skins/$siteskin")) $skindir = _BASEDIR."skins/$siteskin";
181
+else if(is_dir(_BASEDIR."skins/".$settings['skin'])) $skindir = _BASEDIR."skins/".$defaultskin;
182
+else $skindir = _BASEDIR."default_tpls";
183
+if(USERUID) {
184
+	$prefs = dbquery("SELECT sortby, storyindex, tinyMCE FROM ".TABLEPREFIX."fanfiction_authorprefs WHERE uid = '".USERUID."'");
185
+	if(dbnumrows($prefs)) list($defaultsort, $displayindex, $tinyMCE) = dbrow($prefs);
186
+}
187
+if(isset($_REQUEST['sort'])) $defaultsort = $_REQUEST['sort'] == "update" ? 1 : 0;
188
+define("_ORDERBY", " ORDER BY ".($defaultsort == 1 ? "updated DESC" : "stories.title ASC"));
189
+if($current == "viewstory"){
190
+	if(isset($chapid)) {
191
+		$squery = dbquery("SELECT sid, inorder FROM ".TABLEPREFIX."fanfiction_chapters WHERE chapid = ".$chapid." LIMIT 1");
192
+		list($sid, $chapter) = dbrow($squery);
193
+	}
194
+	$titlequery = dbquery("SELECT story.title, story.coauthors, "._PENNAMEFIELD." as penname, story.summary FROM ".TABLEPREFIX."fanfiction_stories as story, "._AUTHORTABLE." WHERE sid = '$sid' AND "._UIDFIELD." = story.uid LIMIT 1");
195
+	if($story = dbassoc($titlequery)) { 
196
+			$authlink[] = $story['penname'];
197
+		if($story['coauthors']) {
198
+			$coquery = dbquery("SELECT "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors as ca ON "._UIDFIELD." = ca.uid WHERE ca.sid = '$sid'");
199
+			while($co = dbassoc($coquery)) {
200
+				$authlink[] = $co['penname'];
201
+			}
202
+		}
203
+		$titleinfo = stripslashes($story['title'])." "._BY." ".implode(", ", $authlink);
204
+		$metaDesc = htmlspecialchars(stripslashes($story['summary']));
205
+		$filename = basename($titleinfo.".html");
206
+		$ie = strpos("msie", strtolower($_SERVER['HTTP_USER_AGENT'])) !== false ? true : false;
207
+		if ($ie) $filename = rawurlencode($filename);
208
+		header("Content-Disposition: inline; filename=\"".$titleinfo."\"");
209
+ 	}
210
+}
211
+if($current == "viewuser" && isNumber($uid)) {
212
+	$author = dbquery("SELECT "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." WHERE "._UIDFIELD." = '".$uid."'");
213
+	list($penname) = dbrow($author);
214
+	$titleinfo = "$sitename :: $penname";
215
+}
216
+echo _DOCTYPE."<html><head>";
217
+if(!isset($titleinfo)) $titleinfo = "$sitename :: $slogan";
218
+if(isset($metaDesc)) echo "<meta name='description' content='$metaDesc'>";
219
+echo "<title>$titleinfo</title>
220
+<meta http-equiv=\"Content-Type\" content=\"text/html; charset="._CHARSET."\">";
221
+if(!isset($_GET['action']) || $_GET['action'] != "printable") {
222
+echo "<script language=\"javascript\" type=\"text/javascript\" src=\""._BASEDIR."includes/javascript.js\"></script>
223
+<link rel=\"alternate\" type=\"application/rss+xml\" title=\"$sitename RSS Feed\" href=\""._BASEDIR."rss.php\">";
224
+if(!empty($tinyMCE)) {
225
+	echo "<script language=\"javascript\" type=\"text/javascript\" src=\""._BASEDIR."tinymce/jscripts/tiny_mce/tiny_mce.js\"></script>
226
+	<script language=\"javascript\" type=\"text/javascript\"><!--";
227
+	$tinymessage = dbquery("SELECT message_text FROM ".TABLEPREFIX."fanfiction_messages WHERE message_name = 'tinyMCE' LIMIT 1");
228
+	list($tinysettings) = dbrow($tinymessage);
229
+	if(!empty($tinysettings) && $current != "adminarea") {
230
+		echo $tinysettings;
231
+	}
232
+	else {
233
+		echo "
234
+	tinyMCE.init({ 
235
+		theme: 'advanced',
236
+		height: '250',
237
+		language: '$language',
238
+		convert_urls: 'false',
239
+		mode: 'textareas',
240
+		extended_valid_elements: 'a[name|href|target|title]',
241
+		plugins: 'advhr,advimage,advlink,searchreplace,contextmenu,preview,fullscreen,paste".($current == "adminarea" ? ",codeprotect" : "")."',
242
+		theme_advanced_buttons1_add: 'fontsizeselect',
243
+		theme_advanced_buttons2_add: 'separator,pasteword,pastetext',
244
+		theme_advanced_buttons3_add_before: 'tablecontrols,separator',
245
+		theme_advanced_buttons3_add: 'advhr',
246
+		theme_advanced_toolbar_align: 'center',
247
+		theme_advanced_statusbar_location: 'bottom',
248
+		theme_advanced_path: 'false',
249
+		editor_deselector: 'mceNoEditor',
250
+";
251
+		if(USERUID) 
252
+			echo "		external_image_list_url : '".STORIESPATH."/".USERUID."/images/imagelist.js',";
253
+		echo "
254
+		theme_advanced_resizing: true,".($current == "adminarea" ? "\n\t\tentity_encoding: 'raw'" : "\n\t\tinvalid_elements: 'script,object,applet,iframe'")."
255
+   });
256
+";
257
+	}
258
+	echo "
259
+var tinyMCEmode = true;
260
+	function toogleEditorMode(id) {
261
+		var elm = document.getElementById(id);
262
+
263
+		if (tinyMCE.getInstanceById(id) == null)
264
+			tinyMCE.execCommand('mceAddControl', false, id);
265
+		else
266
+			tinyMCE.execCommand('mceRemoveControl', false, id);
267
+	}
268
+";
269
+echo " --></script>";
270
+}
271
+}
272
+if(isset($displayform) && $displayform == 1) {
273
+echo "<script language=\"javascript\" type=\"text/javascript\" src=\""._BASEDIR."includes/xmlhttp.js\"></script>";
274
+echo "<script language=\"javascript\" type=\"text/javascript\">
275
+lang = new Array( );
276
+
277
+lang['Back2Cats'] = '"._BACK2CATS."';
278
+lang['ChooseCat'] = '"._CHOOSECAT."';
279
+lang['Categories'] = '"._CATEGORIES."';
280
+lang['Characters'] = '"._CHARACTERS."';
281
+lang['MoveTop'] = '"._MOVETOP."';
282
+lang['TopLevel'] = '"._TOPLEVEL."';
283
+lang['CatLocked'] = '"._CATLOCKED."';
284
+basedir = '"._BASEDIR."';
285
+
286
+categories = new Array( );
287
+characters = new Array( );
288
+\n";
289
+/*
290
+	$result = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_categories ORDER BY leveldown, displayorder");
291
+$x = 0;
292
+	while($category = dbassoc($result)) {
293
+		echo "categories[$x] = new category(".$category['parentcatid'].", ".$category['catid'].", \"". str_replace('"', '\"', stripslashes($category['category']))."\", ".$category['locked'].", ".$category['displayorder'].");\r\n";
294
+		$catlist[$category['catid']] = array("name" => stripslashes($category['category']), "pid" => $category['parentcatid'], "locked" => (isADMIN ? 0 : $category['locked']), "order" => $category['displayorder'], "leveldown" => $category['leveldown']);
295
+		$x++;
296
+	}
297
+$x = 0;
298
+	$result = dbquery("SELECT charname, catid, charid FROM ".TABLEPREFIX."fanfiction_characters ORDER BY charname");
299
+	while($char = dbassoc($result)) {
300
+		echo "characters[$x] = new character(".$char['charid'].", ".$char['catid'].", \"".str_replace('"', '\"', stripslashes($char['charname']))."\");\r\n";
301
+		$charlist[$char['charid']] = array("name" => stripslashes($char['charname']), "catid" => $char['catid']);
302
+		$x++;
303
+	}
304
+*/
305
+echo "</script>";
306
+}
307
+if(file_exists("extra_header.php")) include_once("extra_header.php");
308
+if(file_exists("$skindir/extra_header.php")) include_once("$skindir/extra_header.php");
309
+if(!$displaycolumns) $displaycolumns = 1;
310
+$colwidth = floor(100/$displaycolumns);
311
+if(!empty($_GET['action']) && $_GET['action'] == "printable") {
312
+	if(file_exists("$skindir/printable.css")) echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$skindir/printable.css\">";
313
+	else echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"default_tpls/printable.css\">";
314
+	echo "<script type='text/javascript'>
315
+<!--
316
+if (window.print) {
317
+    window.print() ;  
318
+} else {
319
+    var WebBrowser = '<OBJECT ID=\"WebBrowser1\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"></OBJECT>';
320
+document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
321
+    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = \"\";  
322
+}
323
+-->
324
+</script>";
325
+}
326
+else {
327
+echo "<style type=\"text/css\">
328
+#columncontainer { margin: 1em auto; width: auto;}
329
+#browseblock, #memberblock { width: 100%; padding: 0; margin: 0; float: left; border: 0px solid transparent; }
330
+.column { float: left; width: ".($colwidth - 1)."%; }
331
+html>body .column { width: $colwidth%; }
332
+.cleaner { clear: both; height: 1px; font-size: 1px; margin: 0; padding: 0; background: transparent; }
333
+#settingsform { margin: 0; padding: 0; border: none; }
334
+#settingsform FORM { width: 100%; margin: 0 10%; }
335
+#settingsform LABEL { float: left; display: block; width: 30%; text-align: right; padding-right: 10px; clear: left; }
336
+#settingsform DIV { margin: 1ex auto; clear: both;}
337
+#settingsform .fieldset SPAN { float: left; display: block; width: 30%; text-align: right; padding-right: 10px; clear: left;}
338
+#settingsform .fieldset LABEL { float: none; width: auto; display: inline; text-align: left; clear: none; }
339
+#settingsform { float: left; margin: 1ex 10%; }
340
+#settingsform .tinytoggle { text-align: center; }
341
+#settingsform .tinytoggle LABEL { float: none; display: inline; width: auto; text-align: center; padding: 0; clear: none; }
342
+#settingsform #submitdiv { text-align: center; width: 100%;clear: both; height: 3em; }
343
+#settingsform #submitdiv #submit { position: absolute; z-index: 10001; margin: 1em; }
344
+a.pophelp{
345
+    position: relative; /* this is the key*/
346
+    vertical-align: super;
347
+}
348
+
349
+a.pophelp:hover{z-index:100; border: none; text-decoration: none;}
350
+
351
+a.pophelp span{display: none; position: absolute; top: -25em; left: 20em; }
352
+
353
+a.pophelp:hover span{ /*the span will display just on :hover state*/
354
+    display:block;
355
+    position: absolute;
356
+    top: -3em; left: 8em; width: 225px;
357
+    border:1px solid #000;
358
+    background-color:#CCC; color:#000;
359
+    text-decoration: none;
360
+    text-align: left;
361
+    padding: 5px;
362
+    font-weight: normal;
363
+    visibility: visible;
364
+}
365
+.required { color: red; }
366
+.shim {
367
+	position: absolute;
368
+	display: none;
369
+	height: 0;
370
+	width:0;
371
+	margin: 0;
372
+	padding: 0;
373
+	z-index: 100;
374
+}
375
+
376
+.ajaxOptList {
377
+	background: #CCC;
378
+	border: 1px solid #000;
379
+	margin: 0;
380
+	position: absolute;
381
+	padding: 0;
382
+	z-index: 1000;
383
+	text-align: left;
384
+}
385
+.ajaxListOptOver {
386
+	padding: 4px;
387
+	background: #CCC;
388
+	margin: 0;
389
+}
390
+.ajaxListOpt {
391
+	background: #EEE;
392
+	padding: 4px;
393
+	margin: 0;
394
+}
395
+.multiSelect {
396
+	width: 300px;
397
+}
398
+
399
+</style>
400
+<link rel='stylesheet' type='text/css' href='$skindir/style.css' /> \n
401
+<meta name='viewport' content='width=device-width, initial-scale=1.0' />
402
+";
403
+}
404
+echo "</head>";
405
+$headerSent = true;
406
+include (_BASEDIR."includes/class.TemplatePower.inc.php");
407
+if($debug == 1) {
408
+	@ error_reporting(E_ALL);
409
+	echo "\n<!-- \$_SESSION \n"; print_r($_SESSION); echo " -->";
410
+	echo "\n<!-- \$_COOKIE \n"; print_r($_COOKIE); echo " -->";
411
+	echo "\n<!-- \$_POST \n"; print_r($_POST); echo " -->";
412
+}
413
+?>