Browse code

header.php, reviews.php, viewstory.php, viewuser.php, admin/panels.php, browse/class.php, browse/ratings.php: PHP 7+ coalescing to PHP 5+ ternary and further defined variables - admin/panels.php: fix self-caused isset flaw displaying panel types in drop-down menu as 1

Clarissa Walker authored on 2026/10/28 23:47:30
Showing 7 changed files
... ...
@@ -48,7 +48,7 @@ if(!empty($_GET['edit'])) {
48 48
 			$oldinfo = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_id = '".$_GET['edit']."'");
49 49
 			$panelinfo = dbassoc($oldinfo);
50 50
 			$nextorder = 0;
51
-			if(($panelinfo['panel_hidden'] ?? null) || $_GET['edit'] == "new") {
51
+			if((isset($panelinfo['panel_hidden']) ? $panelinfo['panel_hidden'] : null) || $_GET['edit'] == "new") {
52 52
 				$order = dbquery("SELECT COUNT(panel_id) FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_type = '$panel_type' AND panel_hidden = 0".($panel_type == "A" ? " AND panel_level = '$panel_level'" : ""));
53 53
 				list($nextorder) = dbrow($order);
54 54
 				$nextorder++;
... ...
@@ -74,7 +74,7 @@ if(!empty($_GET['edit'])) {
74 74
 			<label for='panel_level'>"._LEVEL.":</label> <select name='panel_level' id='panel_level'>";
75 75
 		for($x = 0; $x < 5; $x++) { $output .= "<option".((isset($panelinfo['panel_level']) ? $panelinfo['panel_level'] : null) == $x ? " selected" : "").">$x</option>"; }
76 76
 		$output .= "</select><br />
77
-			<label for='panel_hidden'>"._HIDDEN.":</label> <input type='checkbox' class='checkbox' name='panel_hidden' id='panel_hidden' ".(($panelinfo['panel_hidden'] ?? null) ? " checked" : "")."><br />
77
+			<label for='panel_hidden'>"._HIDDEN.":</label> <input type='checkbox' class='checkbox' name='panel_hidden' id='panel_hidden' ".((isset($panelinfo['panel_hidden']) ? $panelinfo['panel_hidden'] : null) ? " checked" : "")."><br />
78 78
 			<label for='panel_type'>"._TYPE.":</label> <input type='text' class='textbox' name='panel_type' id='panel_type' value='".(isset($panelinfo['panel_type']) ? $panelinfo['panel_type'] : null)."' size='2'><br />
79 79
 			<div style='margin: 1em; text-align: center;'><INPUT type=\"submit\" class=\"button\" value=\""._SUBMIT."\" name=\"submit\"></div></form></div>";
80 80
 	}
... ...
@@ -100,7 +100,7 @@ else {
100 100
 	$output .= "<option value=\"admin.php?action=panels\">"._ALL."</option>";
101 101
 	$paneltypelist = dbquery("SELECT DISTINCT panel_type FROM ".TABLEPREFIX."fanfiction_panels ORDER BY panel_type");
102 102
 	while($t = dbrow($paneltypelist)) {
103
-		$output .= "<option value='admin.php?action=panels&amp;type=$t[0]'".($type == $t[0] ? " selected" : "").">$t[0] - ".isset($paneltypes[$t[0]])."</option>";
103
+		$output .= "<option value='admin.php?action=panels&amp;type=$t[0]'".($type == $t[0] ? " selected" : "").">$t[0] - ".(isset($paneltypes[$t[0]]) ? $paneltypes[$t[0]] : null)."</option>";
104 104
 	}
105 105
 	$output .= "</select>";
106 106
 	if($type == "A") {
... ...
@@ -120,7 +120,7 @@ else {
120 120
 		if(!$panel['panel_hidden']) $count++;
121 121
 		else $num--;
122 122
 		$output .= "<tr><td class='tblborder'>".$panel['panel_title']."</td><td class='tblborder'>";
123
-		if(!$type) $output .= ($panel['panel_type'] ?? null)." - ".($paneltypes[$panel['panel_type']] ?? null);
123
+		if(!$type) $output .= (isset($panel['panel_type']) ? $panel['panel_type'] : null)." - ".(isset($paneltypes[$panel['panel_type']]) ? $paneltypes[$panel['panel_type']] : null);
124 124
 		else if($type == "A" && empty($_GET['level'])) $output .= $panel['panel_hidden'] ? _HIDDEN :  _LEVEL." ".$panel['panel_level'];
125 125
 		else {
126 126
 			if($panel['panel_hidden']) $output .= _HIDDEN;
... ...
@@ -38,7 +38,8 @@ if(!empty($classid)) {
38 38
 	$searchVars['classin'] = array($classid);
39 39
 }
40 40
 else if(isset($type_id)) {
41
-	$output .= "<div id='pagetitle'>".($classtypelist[$type_id]['title'] ?? null)."</div>";
41
+	if(empty($type_id)) $classtypelist[$type_id]['title'] = '';
42
+	$output .= "<div id='pagetitle'>".($classtypelist[$type_id]['title'])."</div>";
42 43
 	foreach($classlist as $c => $i) {
43 44
 		if($i['type'] == $type_id) $clist[] = "<a href='browse.php?type=class&amp;type_id=$type_id&amp;classid=$c'>".$i['name']."</a><br />";
44 45
 		else $clist[] = '';
... ...
@@ -34,7 +34,7 @@ if($rating) {
34 34
 }
35 35
 else {
36 36
 	$output .= "<div id='pagetitle'>"._RATINGS."</div>";
37
-	$total = is_countable($ratingslist ?? null);
37
+	$total = is_countable(isset($ratingslist) ? $ratingslist : null);
38 38
 	$count = 0;
39 39
 	$column = 1;
40 40
 	$list = floor($total / $displaycolumns);
... ...
@@ -216,7 +216,8 @@ if($current == "viewstory"){
216 216
 		$squery = dbquery("SELECT sid, inorder FROM ".TABLEPREFIX."fanfiction_chapters WHERE chapid = ".$chapid." LIMIT 1");
217 217
 		list($sid, $chapter) = dbrow($squery);
218 218
 	}
219
-	$titlequery = dbquery("SELECT story.title, story.coauthors, "._PENNAMEFIELD." as penname, story.summary FROM ".TABLEPREFIX."fanfiction_stories as story, "._AUTHORTABLE." WHERE sid = '".(($sid) ?? null)."' AND "._UIDFIELD." = story.uid LIMIT 1");
219
+	if(empty($sid)) $sid = isset($_GET['sid']) && isNumber($_GET['sid']) ? $_GET['sid'] : false;
220
+	$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");
220 221
 	if($story = dbassoc($titlequery)) { 
221 222
 			$authlink[] = $story['penname'];
222 223
 		if($story['coauthors']) {
... ...
@@ -233,7 +234,7 @@ if($current == "viewstory"){
233 234
 		//header("Content-Disposition: inline; filename=\"".$titleinfo."\"");
234 235
  	}
235 236
 }
236
-if($current == "viewuser" && (isNumber($uid ?? null))) {
237
+if($current == "viewuser" && (isNumber(isset($uid) ? $uid : null))) {
237 238
 	$author = dbquery("SELECT "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." WHERE "._UIDFIELD." = '".$uid."'");
238 239
 	list($penname) = dbrow($author);
239 240
 	$titleinfo = "$sitename :: $penname";
... ...
@@ -292,7 +292,7 @@ else {
292 292
 		$storyquery = dbquery("SELECT s.title, s.uid, s.rid, s.sid, s.coauthors FROM ".TABLEPREFIX."fanfiction_stories as s WHERE s.sid = '$item' LIMIT 1");
293 293
 		$story = dbassoc($storyquery);
294 294
 		$title = title_link($story);
295
-		$authoruid = ($story['uid']) ?? null;
295
+		$authoruid = (isset($story['uid']) ? $story['uid'] : null);
296 296
 		if(empty($story)) accessDenied();
297 297
 		if(!empty($story['coauthors'])) {
298 298
 			$colist = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '$item'");
... ...
@@ -375,11 +375,11 @@ else {
375 375
 		}
376 376
 		$jumpmenu = "<form name=\"jump\" action=\"\">";
377 377
 		$jumpmenu .= "<select name=\"sid\" onChange=\"window.location=this.options[this.selectedIndex].value\">";
378
-		$jumpmenu .= "<option value=\"reviews.php?type=ST&amp;item=".(($story['sid']) ?? null).(isset($_GET['unresponded']) ? "&amp;unresponded=1" : "")."\"";
378
+		$jumpmenu .= "<option value=\"reviews.php?type=ST&amp;item=".(isset($story['sid']) ? $story['sid'] : null).(isset($_GET['unresponded']) ? "&amp;unresponded=1" : "")."\"";
379 379
 		if(!isset($chapid))
380 380
 			$jumpmenu .= " selected";
381 381
 		$jumpmenu .= ">"._VIEWALLREVIEWS."</option>";
382
-		$chapquery = dbquery("SELECT inorder, title, chapid, sid FROM ".TABLEPREFIX."fanfiction_chapters WHERE sid = '".(($story['sid']) ?? null)."' ORDER BY inorder ASC");
382
+		$chapquery = dbquery("SELECT inorder, title, chapid, sid FROM ".TABLEPREFIX."fanfiction_chapters WHERE sid = '".(isset($story['sid']) ? $story['sid'] : null)."' ORDER BY inorder ASC");
383 383
 		while($chapters = dbassoc($chapquery)) {
384 384
 			$jumpmenu .= "<option value=\"reviews.php?chapid=".$chapters['chapid'].(isset($_GET['unresponded']) ? "&amp;unresponded=1" : "")."&amp;type=ST&amp;item=$item\"";
385 385
 	
... ...
@@ -30,9 +30,10 @@ else $action = false;
30 30
 if(isset($_GET['textsize']) && isNumber($_GET['textsize'])) $textsize = $_GET['textsize'];
31 31
 else $textsize = 0;
32 32
 if(empty($chapter)) $chapter = isset($_GET['chapter']) && isNumber($_GET['chapter']) ? $_GET['chapter'] : false;
33
+if(empty($sid)) $sid = isset($_GET['sid']) && isNumber($_GET['sid']) ? $_GET['sid'] : false;
33 34
 
34 35
 	// Get the story information
35
-	$storyquery = dbquery("SELECT "._PENNAMEFIELD." as penname, "._UIDFIELD." as uid, story.*, story.date as date, story.updated as updated, story.validated as valid FROM ".TABLEPREFIX."fanfiction_stories as story, "._AUTHORTABLE." WHERE story.sid = '".(($sid) ?? null)."' AND story.uid = "._UIDFIELD);
36
+	$storyquery = dbquery("SELECT "._PENNAMEFIELD." as penname, "._UIDFIELD." as uid, story.*, story.date as date, story.updated as updated, story.validated as valid FROM ".TABLEPREFIX."fanfiction_stories as story, "._AUTHORTABLE." WHERE story.sid = '".$sid."' AND story.uid = "._UIDFIELD);
36 37
 	$storyinfo = dbassoc($storyquery);
37 38
  
38 39
 	if(!$storyinfo) {
... ...
@@ -41,7 +42,7 @@ if(empty($chapter)) $chapter = isset($_GET['chapter']) && isNumber($_GET['chapte
41 42
 		if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
42 43
 		else $tpl = new TemplatePower("default_tpls/default.tpl");
43 44
 		$title = "Story was not found";
44
-		$text  = "Story with ID " . (($sid) ?? null) . " is not in database";
45
+		$text  = "Story with ID " . $sid . " is not in database";
45 46
 		include("includes/pagesetup.php");
46 47
 		$tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
47 48
 		$tpl->printToScreen();
... ...
@@ -47,7 +47,7 @@ if(empty($uid)) {
47 47
 		if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
48 48
 		else $tpl = new TemplatePower("default_tpls/default.tpl");
49 49
 		$title = "User was not found";
50
-		$text  = "User with ID " . (($uid) ?? null) . " is not in database";
50
+		$text  = "User with ID " . $uid . " is not in database";
51 51
 		include("includes/pagesetup.php");
52 52
 		$tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
53 53
 		$tpl->printToScreen();
... ...
@@ -75,7 +75,7 @@ if(!$penname) {
75 75
 	if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
76 76
 	else $tpl = new TemplatePower("default_tpls/default.tpl");
77 77
 	$title = "User was not found";
78
-	$text  = "User with ID " . (($uid) ?? null) . " is not in database";
78
+	$text  = "User with ID " . $uid . " is not in database";
79 79
 	include("includes/pagesetup.php");
80 80
 	$tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
81 81
 	$tpl->printToScreen();