Browse code

Bugfix patches from upstream - and general cleanup of old hacks

Clarissa Walker authored on 2026/10/31 20:15:56
Showing 9 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']);
... ...
@@ -34,7 +34,8 @@ if($rating) {
34 34
 }
35 35
 else {
36 36
 	$output .= "<div id='pagetitle'>"._RATINGS."</div>";
37
-	if ($ratingslist) $total = count(isset($ratingslist) ? $ratingslist : null);
37
+	if(empty($ratingslist) || !is_array($ratingslist)) $ratingslist = array( );
38
+	$total = count($ratingslist);
38 39
 	$count = 0;
39 40
 	$column = 1;
40 41
 	$list = floor($total / $displaycolumns);
... ...
@@ -162,12 +162,12 @@ if(isset($_POST['submit']) || isset($_GET['offset'])) {
162 162
 
163 163
 	if(isset($_REQUEST['rid'])) $rid = is_array($_REQUEST['rid']) ? $_REQUEST['rid'] : explode(",", $_REQUEST['rid']);
164 164
 	else $rid = array();
165
+	$rid = array_filter((array)$rid, function($r) { return is_string($r) && isNumber($r); });
165 166
 	if(count($rid) > 0) {
166
-		$rid = array_filter($rid, "isNumber");
167 167
 		$query[] = findclause('rid', $rid);
168 168
 		$countquery[] = findclause('rid', $rid);
169 169
 	}
170
-	if(isset($_REQUEST['complete'])) {
170
+	if(isset($_REQUEST['complete']) || isset($_REQUEST['completed'])) {
171 171
 		$query[] = "stories.completed = '1'";
172 172
 		$countquery[] = "stories.completed = '1'";
173 173
 	}
... ...
@@ -61,6 +61,18 @@ if(isADMIN && uLEVEL == 3) {
61 61
 	}
62 62
 }
63 63
 if(!$allowseries && !$admin) accessDenied( );
64
+$ef_sid_post = isset($_POST['seriesid']) ? $_POST['seriesid'] : null;
65
+if($ef_sid_post !== null && !isNumber($ef_sid_post)) accessDenied( );
66
+$ef_target = $seriesid ? $seriesid : ($ef_sid_post !== null ? (int)$ef_sid_post : false);
67
+$ef_changes = $action == "edit" || $action == "validate" || ($action == "delete" && isset($_GET['confirmed']) && $_GET['confirmed'] == "yes") || !empty($_GET['go']);
68
+if($ef_changes && $ef_target && !$admin) {
69
+	$ef_owner = dbq_value("SELECT uid FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = ? LIMIT 1", (int)$ef_target);
70
+	$ef_story_owner = false;
71
+	// a story's author may take their own story out of someone else's series
72
+	if($action == "delete" && !empty($inorder))
73
+		$ef_story_owner = (int)dbq_value("SELECT s.uid FROM ".TABLEPREFIX."fanfiction_inseries AS i JOIN ".TABLEPREFIX."fanfiction_stories AS s ON s.sid = i.sid WHERE i.seriesid = ? AND i.inorder = ? LIMIT 1", (int)$ef_target, (int)$inorder) === (int)USERUID;
74
+	if($ef_owner === null || ((int)$ef_owner !== (int)USERUID && !$ef_story_owner)) accessDenied( );
75
+}
64 76
 if($allowseries == 1 && !$admin) {
65 77
 	list($count) = dbrow(dbquery("SELECT COUNT(sid) FROM ".TABLEPREFIX."fanfiction_stories WHERE uid = '".USERUID."'"));
66 78
 	if($count == 0) accessDenied( );
... ...
@@ -83,6 +95,7 @@ if($add == "series" || ($action == "add" && !$add) || $action == "edit") {
83 95
 	if(isset($_POST['submit'])) {
84 96
 		$title = addslashes(escapestring(strip_tags($_POST['title'], $allowed_tags)));
85 97
 		$summary = addslashes(escapestring(descript(strip_tags($_POST["summary"], $allowed_tags))));
98
+		#$category = isset($_POST['catid']) ? explode(",", $_POST['catid']) : array();
86 99
 		if ($multiplecats) $category = isset($_POST['catid']) ? explode(",", $_POST['catid']) : array();
87 100
 		else $category = isset($_POST['catid']) ? $_POST['catid'] : array();
88 101
 		$category = array_filter($category, "isNumber");
... ...
@@ -144,7 +157,7 @@ if($add == "series" || ($action == "add" && !$add) || $action == "edit") {
144 157
 	}
145 158
 	else {
146 159
 	$output = "<div id=\"pagetitle\">".($action == "edit" ? _EDITSERIES : ($add == "stories" ? _ADD2SERIES : _ADDSERIES))."</div>
147
-<form METHOD=\"POST\" style='width: 75%; margin: 0 auto;' name=\"form\" action=\"series.php?action=$action&amp;add=".(!empty($add) ? $add : "series").(!empty($seriesid) ? "&amp;seriesid=$seriesid" : "")."\">";
160
+<form METHOD=\"POST\" class='tblborder' style='width: 75%; margin: 0 auto; padding: 10px;' name=\"form\" action=\"series.php?action=$action&amp;add=".(!empty($add) ? $add : "series").(!empty($seriesid) ? "&amp;seriesid=$seriesid" : "")."\">";
148 161
 	if($action == "edit" && !isset($POST['submit'])) {
149 162
 		$seriesquery = dbquery(_SERIESQUERY." AND seriesid = '$seriesid' LIMIT 1");
150 163
 		$series = dbassoc($seriesquery);
... ...
@@ -217,6 +230,8 @@ if($add == "stories") {
217 230
 			if($item['sid']) $items[] = $item['sid'];
218 231
 			if($item['subseriesid']) $subs[] = $item['subseriesid'];
219 232
 		}
233
+		if(!$owner || (!$admin && USERUID != $owner && !$isopen)) accessDenied( );
234
+		$ef_mine = !$admin && USERUID != $owner;
220 235
 		if($admin || USERUID == $owner || $isopen == 2 ) $confirmed = 1;
221 236
 		else {
222 237
 			$confirmed = 0;
... ...
@@ -229,6 +244,7 @@ if($add == "stories") {
229 244
 		if(!empty($_POST["sid"])) {
230 245
 			foreach($_POST["sid"] as $story) {
231 246
 				if(!isNumber($story)) continue;
247
+				if($ef_mine && !dbnumrows(dbquery("SELECT s.sid FROM ".TABLEPREFIX."fanfiction_stories AS s LEFT JOIN ".TABLEPREFIX."fanfiction_coauthors AS c ON c.sid = s.sid AND c.uid = '".(int)USERUID."' WHERE s.sid = '".(int)$story."' AND (s.uid = '".(int)USERUID."' OR c.uid IS NOT NULL) LIMIT 1"))) continue;
232 248
 				if(!isset($items) || !is_array($items) || !in_array($story, $items)) {
233 249
 					$count++;
234 250
 					$validate = dbquery("SELECT validated FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '$story' LIMIT 1");
... ...
@@ -57,8 +57,18 @@ include("includes/storyform.php");
57 57
 					$coauthors[] = $c['uid'];
58 58
 				}
59 59
 			}
60
-			if($story['uid'] != USERUID && (is_array($coauthors) && !in_array(USERUID, $coauthors)) && !$story['rr']) accessDenied( );
61
-		}
60
+			if(!$story) accessDenied( );
61
+			$ef_own = $story['uid'] == USERUID || in_array(USERUID, $coauthors);
62
+			if(!$ef_own) {
63
+				// A round robin lets other members add chapters, and edit or delete the
64
+				// chapters they wrote. The story itself stays with its authors.
65
+				// (Before 3.5.74 any member could edit or delete a round robin story.)
66
+				if(!$story['rr']) accessDenied( );
67
+				$ef_rr_ok = $action == "newchapter" || (isset($chapid) && isset($author) && $author == USERUID && in_array($action, array("editchapter", "delete")));
68
+				if(!$ef_rr_ok) accessDenied( );
69
+			}
70
+		}
71
+		else if(isset($chapid)) accessDenied( );
62 72
 	}
63 73
 	else if(isADMIN && uLEVEL < 4 && isset($_GET['admin'])) {
64 74
 		$admin = 1;
... ...
@@ -34,7 +34,7 @@ if(!defined("_CHARSET")) exit( );
34 34
 		$storyindex = isset($_POST['storyindex']) && $_POST['storyindex'] == "on" ? 1 : 0;
35 35
 		$sortby = isset($_POST['sortby']) && $_POST['sortby'] == 1 ? 1 : 0;
36 36
 		$skinnew = descript(strip_tags($_POST['skinnew']));
37
-		if(($skinnew) != $skin || ($skinnew) == $skin) $_SESSION[$sitekey."_skin"] = $skinnew;
37
+		$_SESSION[$sitekey."_skin"] = $skinnew;
38 38
 		dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET alertson = '$useralertson', newreviews = '$newreviews', newrespond = '$newrespond', ageconsent = '$ageconsent', tinyMCE ='$tinyMCE', userskin = '$skinnew', storyindex = '$storyindex', sortby = '$sortby' WHERE uid = '".USERUID."'");
39 39
 		$output .= write_message(_ACTIONSUCCESSFUL." "._BACK2ACCT);
40 40
 	}
... ...
@@ -29,9 +29,9 @@ if(empty($favorites)) accessDenied( );
29 29
 		$uid = USERUID;
30 30
 		$output .= "<div id='pagetitle'>"._YOURSTATS."</div>";
31 31
 	}
32
-	$add = isset($_GET['add']) ? $_GET['add'] : false;
33
-	$edit = isset($_GET['edit']) ? $_GET['edit'] : false;
34
-	$delete = isset($_GET['delete']) ? $_GET['delete'] : false;
32
+	$add = isset($_GET['add']) && isNumber($_GET['add']) ? $_GET['add'] : false;
33
+	$edit = isset($_GET['edit']) && isNumber($_GET['edit']) ? $_GET['edit'] : false;
34
+	$delete = isset($_GET['delete']) && isNumber($_GET['delete']) ? $_GET['delete'] : false;
35 35
 	if($add) $output .= "<div class='sectionheader'>"._ADDTOFAVORITES."</div>";
36 36
 	else if($edit) $output .= "<div class='sectionheader'>"._EDITFAVORITES."</div>";
37 37
 	else $output .= "<div class='sectionheader'>"._FAVORITESTORIES."</div>";
... ...
@@ -49,7 +49,7 @@ if(empty($favorites)) accessDenied( );
49 49
 		if($result) $output .= write_message(_ACTIONSUCCESSFUL." "._BACK2ACCT);
50 50
 	}
51 51
 	if($edit && isset($_POST['submit'])) {
52
-		$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_favorites SET comments = '".escapestring(descript(strip_tags(replace_naughty($_POST['comments']), $allowed_tags)))."' WHERE uid = '$uid' AND item = '$edit' AND type = 'ST'");
52
+		$result = dbquery("UPDATE ".TABLEPREFIX."fanfiction_favorites SET comments = '".escapestring(descript(strip_tags(replace_naughty($_POST['comments']), $allowed_tags)))."' WHERE uid = '".USERUID."' AND item = '".(int)$edit."' AND type = 'ST'");
53 53
 		if($result) $output .= write_message(_ACTIONSUCCESSFUL." "._BACK2ACCT);
54 54
 		else $output .= write_error(_ERROR);
55 55
 	}
... ...
@@ -28,8 +28,25 @@ if(!defined("_CHARSET")) exit( );
28 28
 	if(isset($_POST['submit'])) {
29 29
 		$reviewid = isset($_POST['rid']) && isNumber($_POST['rid']) ? $_POST['rid'] : false;
30 30
 		if(!$reviewid) accessDenied( );
31
-		$result = dbquery("SELECT review, reviewid, item, type, chapid, uid FROM ".TABLEPREFIX."fanfiction_reviews WHERE reviewid = '$reviewid' LIMIT 1");
31
+		$result = dbquery("SELECT review, reviewid, item, type, chapid, uid FROM ".TABLEPREFIX."fanfiction_reviews WHERE reviewid = '".(isset($_POST['rid']) && isNumber($_POST['rid']) ? $_POST['rid'] : 0)."' LIMIT 1");
32 32
 		list($review, $reviewid, $item, $type, $chapid, $uid) = dbrow($result);
33
+		$ef_owner = false;
34
+		if($reviewid && $type == "ST") {
35
+			$ef_o = dbassoc(dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '".(int)$item."' LIMIT 1"));
36
+			$ef_owner = ($ef_o && $ef_o['uid'] == USERUID) || dbnumrows(dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '".(int)$item."' AND uid = '".(int)USERUID."'"));
37
+		}
38
+		else if($reviewid && $type == "SE") {
39
+			$ef_o = dbassoc(dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '".(int)$item."' LIMIT 1"));
40
+			$ef_owner = $ef_o && $ef_o['uid'] == USERUID;
41
+		}
42
+		else if($reviewid) $ef_owner = isADMIN;   // reviews of module items: admins only
43
+		if(!$ef_owner) accessDenied( );
44
+		if(dbnumrows(dbquery("SELECT reviewid FROM ".TABLEPREFIX."fanfiction_reviews WHERE reviewid = '".(int)$reviewid."' AND respond = '1'"))) {
45
+			$tpl->assign("output", write_message(_ALREADYRESPONDED));
46
+			$tpl->printToScreen( );
47
+			dbclose( );
48
+			exit( );
49
+		}
33 50
 		$updated = escapestring($review . "<br><br><i>"._AUTHORSRESPONSE.": " .replace_naughty(descript(strip_tags($_POST['response'], $allowed_tags)))."</i>");
34 51
 		$success = dbquery("UPDATE ".TABLEPREFIX."fanfiction_reviews SET review = '$updated', respond = '1' WHERE reviewid = '$reviewid'");
35 52
 		if($uid) {
... ...
@@ -64,8 +64,8 @@ if(empty($sid)) $sid = isset($_GET['sid']) && isNumber($_GET['sid']) ? $_GET['si
64 64
 
65 65
 	//  Check that the story is valid and that the visitor has permissions to read this story
66 66
 	$warning = "";
67
-	if(!$storyinfo) $warning = _INVALIDSTORY;
68
-	if(!$storyinfo['valid'] && !isADMIN && ($storyinfo['uid'] != USERUID || !in_array(USERUID, $storyinfo['coauthors']))) $warning = _ACCESSDENIED;
67
+	$ef_ownview = isADMIN || (USERUID && ($storyinfo['uid'] == USERUID || isset($storyinfo['coauthors'][USERUID])));
68
+	if(!$storyinfo['valid'] && !$ef_ownview) $warning = _ACCESSDENIED;
69 69
 	if ($storyinfo['rid']  != 0 ) {
70 70
 		$ratingquery = dbquery("SELECT ratingwarning, warningtext FROM " . TABLEPREFIX . "fanfiction_ratings WHERE rid = '" . $storyinfo['rid'] . "' LIMIT 1");
71 71
 		$rating = dbassoc($ratingquery);
... ...
@@ -160,6 +160,19 @@ if($action == "printable") {
160 160
 	else {
161 161
 		$chapterinfo = dbquery("SELECT *, "._PENNAMEFIELD." as penname FROM (".TABLEPREFIX."fanfiction_chapters as c, "._AUTHORTABLE.") WHERE sid = '$sid' AND inorder = '$chapter' AND c.uid = "._UIDFIELD." LIMIT 1");
162 162
 		$c = dbassoc($chapterinfo);
163
+		if(!$c) {
164
+			$current = "chaptererror";
165
+			// load our template files to set up the page.
166
+			if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
167
+			else $tpl = new TemplatePower("default_tpls/default.tpl");
168
+			$title = "Chapter was not found";
169
+			$text  = "Missing chapter";
170
+			include("includes/pagesetup.php");
171
+			$tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
172
+			$tpl->printToScreen();
173
+			dbclose();
174
+			exit();
175
+		}
163 176
 		// if the *CHAPTER* hasn't been validated and the viewer isn't an admin or the author throw them a warning.  
164 177
 		if(empty($c['validated']) && !isADMIN && USERUID != $c['uid'] && !in_array(USERUID, $stories['coauthors'])) {
165 178
 			$warning = write_error(_ACCESSDENIED);
... ...
@@ -227,7 +240,7 @@ else if(($displayindex && empty($chapter)) || !empty($_GET['index'])) {
227 240
 		eval($code['code_text']);
228 241
 	}
229 242
 	include("includes/storyblock.php");
230
-	$printicon = "<a href=\"viewstory.php?action=printable&amp;textsize=$textsize&amp;sid=$sid&amp;chapter=all\" target=\"_blank\"><img src='".(isset($printer) ? $printer : "images/print.gif")."' border='0' alt='"._PRINTER."'></a>";
243
+	$printicon = "<img src='".(isset($printer) ? $printer : "images/print.gif")."' border='0' alt='"._PRINTER."'> <a href=\"viewstory.php?action=printable&amp;textsize=$textsize&amp;sid=$sid&amp;chapter=all\" target=\"_blank\">"._STORY."</a>";
231 244
 	if($reviewsallowed && (isMEMBER || $anonreviews))
232 245
 			$reviewslink = "<a href=\"reviews.php?action=add&amp;item=$sid&amp;next=2&amptype=ST\">"._SUBMITREVIEW."</a>";
233 246
 	$tpl->assign( "reviewslink", $reviewslink );
... ...
@@ -249,7 +262,7 @@ else if(($displayindex && empty($chapter)) || !empty($_GET['index'])) {
249 262
 		$tpl->assign("chapternumber", $chap['inorder']);
250 263
 		$tpl->assign("title", "<a href=\"viewstory.php?sid=$sid&amp;chapter=".$chap['inorder']."\">".$chap['title']."</a>");
251 264
 		$tpl->assign("author", "<a href='viewuser.php?uid=".$chap['uid']."'>".$chap['penname']."</a>");
252
-		$tpl->assign("printicon", "<a href=\"viewstory.php?action=printable&amp;textsize=$textsize&amp;sid=$sid&amp;chapter=".$chap['inorder']."\" target=\"_blank\"><img src='".(isset($printer) ? $printer : "images/print.gif")."' border='0' alt='"._PRINTER."'></a>");
265
+		$tpl->assign("printicon", "<img src='".(isset($printer) ? $printer : "images/print.gif")."' border='0' alt='"._PRINTER."'> <a href=\"viewstory.php?action=printable&amp;textsize=$textsize&amp;sid=$sid&amp;chapter=".$chap['inorder']."\" target=\"_blank\">"._STORY."</a>");
253 266
 		$tpl->assign("ratingpics", ratingpics($chap['rating']));
254 267
 		if($reviewsallowed) {
255 268
 			$tpl->assign("reviews", "<a href=\"reviews.php?type=ST&amp;item=$sid&amp;chapid=".$chap['chapid']."\">"._REVIEWS."</a>");
... ...
@@ -296,6 +309,19 @@ else {
296 309
 			}
297 310
 		}
298 311
 		$jumpmenu .= "</select>";
312
+		if(!isset($inorder)) {
313
+			$current = "chaptererror";
314
+			// load our template files to set up the page.
315
+			if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
316
+			else $tpl = new TemplatePower("default_tpls/default.tpl");
317
+			$title = "Chapter was not found";
318
+			$text  = "Missing chapter";
319
+			include("includes/pagesetup.php");
320
+			$tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
321
+			$tpl->printToScreen();
322
+			dbclose();
323
+			exit();
324
+		}
299 325
 		if($chapter < $chapters) {
300 326
 			$nextchapter = $chapter + 1;
301 327
 			$next = "<a href=\"viewstory.php?sid=$sid&amp;textsize=$textsize&amp;chapter=".($chapter+1)."\" class=\"next\">"._NEXT."</a>";
... ...
@@ -313,22 +339,6 @@ else {
313 339
 	// if the story has only one chapter this is what happens
314 340
 	else {
315 341
 		$chapter = dbassoc($chapterinfo);
316
-
317
-		if (!$chapter)
318
-		{
319
-			$current = "chaptererror";
320
-			// load our template files to set up the page.
321
-			if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
322
-			else $tpl = new TemplatePower("default_tpls/default.tpl");
323
-			$title = "Chapter was not found";
324
-			$text  = "Missing chapter";
325
-			include("includes/pagesetup.php");
326
-			$tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
327
-			$tpl->printToScreen();
328
-			dbclose();
329
-			exit();
330
-		}
331
-
332 342
 		$chapterauthor = $chapter['uid'];
333 343
 		$chapterpenname = $chapter['penname'];
334 344
 		$chaptertitle = $chapter['title'];
... ...
@@ -344,26 +354,24 @@ else {
344 354
 		while($code = dbassoc($codeblocks)) {
345 355
 			eval($code['code_text']);
346 356
 		}
347
-		$printicon = "<a href=\"viewstory.php?action=printable&amp;sid=$sid&amp;textsize=$textsize&amp;chapter=1\" target=\"_blank\"><img src='".(isset($printer) ? $printer : "images/print.gif")."' border='0' alt='"._PRINTER."'></a>";
357
+		$printicon = "<img src='".(isset($printer) ? $printer : "images/print.gif")."' border='0' alt='"._PRINTER."'> <a href=\"viewstory.php?action=printable&amp;sid=$sid&amp;textsize=$textsize&amp;chapter=1\" target=\"_blank\">"._STORY."</a>";
348 358
 	}
349 359
 	// if the *CHAPTER* hasn't been validated and the viewer isn't an admin or the author throw them a warning.  
350
-	if(!(isset($valid)) && !isADMIN && USERUID != isset($chapterauthor) && !in_array($chapterauthor, $storyinfo['coauthors'])) {
351
-		$warning = accessDenied( );
352
-	}
360
+	if(!$valid && !$ef_ownview && USERUID != $chapterauthor) ef_story_error(_ACCESSDENIED, $title);
353 361
 	$stories = $storyinfo;
354 362
 	$tpl->gotoBlock("_ROOT");
355 363
 	$jumpmenu2 = ""; 
356 364
 	include("includes/storyblock.php");
357 365
 	unset($adminlinks);
358 366
 	if(isADMIN && uLEVEL < 3) 
359
-		$adminlinks = "<div class=\"adminoptions\"><span class='label'>"._ADMINOPTIONS.":</span> "._EDIT." - <a href=\"stories.php?action=editstory&amp;sid=$sid&amp;admin=1\">"._STORY."</a> "._OR." <a href=\"stories.php?action=editchapter&amp;chapid=".(isset($chapid) ? $chapid : null)."&amp;admin=1\">"._CHAPTER."</a> | "._DELETE." - <a href=\"stories.php?action=delete&amp;sid=$sid&amp;admin=1\">"._STORY."</a> "._OR." <a href=\"stories.php?action=delete&amp;chapid=".(isset($chapid) ? $chapid : null)."&amp;sid=$sid&amp;admin=1\">"._CHAPTER."</a></div>";
367
+		$adminlinks = "<div class=\"adminoptions\"><span class='label'>"._ADMINOPTIONS.":</span> "._EDIT." - <a href=\"stories.php?action=editstory&amp;sid=$sid&amp;admin=1\">"._STORY."</a> "._OR." <a href=\"stories.php?action=editchapter&amp;chapid=".$chapid."&amp;admin=1\">"._CHAPTER."</a> | "._DELETE." - <a href=\"stories.php?action=delete&amp;sid=$sid&amp;admin=1\">"._STORY."</a> "._OR." <a href=\"stories.php?action=delete&amp;chapid=".$chapid."&amp;sid=$sid&amp;admin=1\">"._CHAPTER."</a></div>";
360 368
 	if(isMEMBER && $favorites) {
361 369
 		$jumpmenu2 .= "<option value=\"user.php?action=favst&amp;add=1&amp;sid=$sid\">"._ADDSTORY2FAVES."</option><option value=\"user.php?action=favau&amp;add=1&amp;author=".$stories['uid'].(count($storyinfo['coauthors']) ? ",".implode(",", array_keys($storyinfo['coauthors'])) : "")."\">"._ADDAUTHOR2FAVES."</option>";
362 370
 	}
363 371
 	if($reviewsallowed ) {
364 372
 		if(isMEMBER || $anonreviews) {
365
-			$reviewslink = "<a href=\"reviews.php?action=add&amp;type=ST&amp;item=$sid&amp;chapid=".(isset($chapid) ? $chapid : null)."&amp;next=$nextchapter\">"._SUBMITREVIEW."</a>";
366
-			$jumpmenu2 .= "<option value=\"reviews.php?action=add&amp;type=ST&amp;item=$sid&amp;chapid=".(isset($chapid) ? $chapid : null)."&amp;next=$nextchapter\">"._SUBMITREVIEW."</option>";
373
+			$reviewslink = "<a href=\"reviews.php?action=add&amp;type=ST&amp;item=$sid&amp;chapid=".$chapid."&amp;next=$nextchapter\">"._SUBMITREVIEW."</a>";
374
+			$jumpmenu2 .= "<option value=\"reviews.php?action=add&amp;type=ST&amp;item=$sid&amp;chapid=".$chapid."&amp;next=$nextchapter\">"._SUBMITREVIEW."</option>";
367 375
 		}
368 376
 		else $reviewslink = write_message(sprintf(_LOGINTOREVIEW, strtolower($pagelinks['login']['link']), strtolower($pagelinks['register']['link'])));
369 377
 	}