Browse code

viewstory.php: Undefined variable warnings while trying to access a nonexistent chapter for an existing story final dirty fix for PHP 8 users

Clarissa Walker authored on 2026/10/26 18:29:36
Showing 1 changed files
... ...
@@ -346,7 +346,7 @@ else {
346 346
 		$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>";
347 347
 	}
348 348
 	// if the *CHAPTER* hasn't been validated and the viewer isn't an admin or the author throw them a warning.  
349
-	if(!isset($valid) && !isADMIN && USERUID != isset($chapterauthor) && !in_array(isset($chapterauthor), isset($storyinfo['coauthors']))) {
349
+	if(!(isset($valid)) && !isADMIN && USERUID != isset($chapterauthor) && !in_array($chapterauthor, $storyinfo['coauthors'])) {
350 350
 		$warning = accessDenied( );
351 351
 	}
352 352
 	$stories = $storyinfo;
... ...
@@ -366,8 +366,8 @@ else {
366 366
 		}
367 367
 		else $reviewslink = write_message(sprintf(_LOGINTOREVIEW, strtolower($pagelinks['login']['link']), strtolower($pagelinks['register']['link'])));
368 368
 	}
369
-	$tpl->assign("reportthis", "[<a href=\""._BASEDIR."contact.php?action=report&amp;url=viewstory.php?chapid=$chapid\">"._REPORTTHIS."</a>]");
370
-	$jumpmenu2 .= "<option value=\"contact.php?action=report&amp;url=viewstory.php?chapid=$chapid\">"._REPORTTHIS."</option>";
369
+	$tpl->assign("reportthis", "[<a href=\""._BASEDIR."contact.php?action=report&amp;url=viewstory.php?chapid=".isset($chapid)."\">"._REPORTTHIS."</a>]");
370
+	$jumpmenu2 .= "<option value=\"contact.php?action=report&amp;url=viewstory.php?chapid=".isset($chapid)."\">"._REPORTTHIS."</option>";
371 371
 	if($stories['rr']) {
372 372
 		$rr = "[<a href=\"stories.php?action=newchapter&amp;sid=".$sid."\">"._CONTRIBUTE2RR."</a>]";
373 373
 		$jumpmenu2 .= "<option value=\"stories.php?action=newchapter&amp;sid=".$sid."\">"._CONTRIBUTE2RR."</option>";
... ...
@@ -381,19 +381,19 @@ else {
381 381
 		}
382 382
 		else $form = write_message(sprintf(_LOGINTOREVIEW, strtolower($pagelinks['login']['link']), strtolower($pagelinks['register']['link'])));
383 383
 	}
384
-	$textsizer = "<a href=\"viewstory.php?sid=$sid".($inorder ? "&amp;chapter=$inorder" : "")."&amp;textsize=".($textsize - 1)."\">-</a> <strong>". _TEXTSIZE. "</strong> <a href=\"viewstory.php?sid=$sid".($inorder ? "&amp;chapter=$inorder" : "")."&amp;textsize=".($textsize + 1)."\">+</a> ";
384
+	$textsizer = "<a href=\"viewstory.php?sid=$sid".(isset($inorder) ? "&amp;chapter=$inorder" : "")."&amp;textsize=".($textsize - 1)."\">-</a> <strong>". _TEXTSIZE. "</strong> <a href=\"viewstory.php?sid=$sid".(isset($inorder) ? "&amp;chapter=$inorder" : "")."&amp;textsize=".($textsize + 1)."\">+</a> ";
385 385
 	// okay now that we know they can see the story and the chapter add 1 to the story and chapter counts;
386 386
 	if(empty($viewed) || (is_array($viewed) && !in_array($sid, $viewed))) {
387 387
 		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET count = count + 1 WHERE sid = '$sid'  LIMIT 1");
388 388
 		$viewed[] = $sid;
389 389
 		$_SESSION[SITEKEY."_viewed"] = $viewed;
390 390
 	}
391
-	dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET count = count + 1 WHERE chapid = '$chapid' LIMIT 1");
391
+	dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET count = count + 1 WHERE chapid = '".isset($chapid)."' LIMIT 1");
392 392
 	// end counters
393 393
 	// if the text of the chapters is being stored in files we need to get that text here
394 394
 	if($store == "files") {
395 395
 		//shouldn't happen, but somehow has on occasion. :(
396
-		if(!$chapterauthor) {
396
+		if(!(isset($chapterauthor))) {
397 397
 			errorExit(_ERROR);
398 398
 		}
399 399
 		$file = STORIESPATH."/$chapterauthor/$chapid.txt";