Browse code

Start Point - version 3.5.5 + fixes

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