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
--- a/admin/panels.php
+++ b/admin/panels.php
@@ -48,7 +48,7 @@
$oldinfo = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_panels WHERE panel_id = '".$_GET['edit']."'");
$panelinfo = dbassoc($oldinfo);
$nextorder = 0;
- if(($panelinfo['panel_hidden'] ?? null) || $_GET['edit'] == "new") {
+ if((isset($panelinfo['panel_hidden']) ? $panelinfo['panel_hidden'] : null) || $_GET['edit'] == "new") {
$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'" : ""));
list($nextorder) = dbrow($order);
$nextorder++;
@@ -74,7 +74,7 @@
<label for='panel_level'>"._LEVEL.":</label> <select name='panel_level' id='panel_level'>";
for($x = 0; $x < 5; $x++) { $output .= "<option".((isset($panelinfo['panel_level']) ? $panelinfo['panel_level'] : null) == $x ? " selected" : "").">$x</option>"; }
$output .= "</select><br />
- <label for='panel_hidden'>"._HIDDEN.":</label> <input type='checkbox' class='checkbox' name='panel_hidden' id='panel_hidden' ".(($panelinfo['panel_hidden'] ?? null) ? " checked" : "")."><br />
+ <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 />
<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 />
<div style='margin: 1em; text-align: center;'><INPUT type=\"submit\" class=\"button\" value=\""._SUBMIT."\" name=\"submit\"></div></form></div>";
}
@@ -100,7 +100,7 @@
$output .= "<option value=\"admin.php?action=panels\">"._ALL."</option>";
$paneltypelist = dbquery("SELECT DISTINCT panel_type FROM ".TABLEPREFIX."fanfiction_panels ORDER BY panel_type");
while($t = dbrow($paneltypelist)) {
- $output .= "<option value='admin.php?action=panels&type=$t[0]'".($type == $t[0] ? " selected" : "").">$t[0] - ".isset($paneltypes[$t[0]])."</option>";
+ $output .= "<option value='admin.php?action=panels&type=$t[0]'".($type == $t[0] ? " selected" : "").">$t[0] - ".(isset($paneltypes[$t[0]]) ? $paneltypes[$t[0]] : null)."</option>";
}
$output .= "</select>";
if($type == "A") {
@@ -120,7 +120,7 @@
if(!$panel['panel_hidden']) $count++;
else $num--;
$output .= "<tr><td class='tblborder'>".$panel['panel_title']."</td><td class='tblborder'>";
- if(!$type) $output .= ($panel['panel_type'] ?? null)." - ".($paneltypes[$panel['panel_type']] ?? null);
+ if(!$type) $output .= (isset($panel['panel_type']) ? $panel['panel_type'] : null)." - ".(isset($paneltypes[$panel['panel_type']]) ? $paneltypes[$panel['panel_type']] : null);
else if($type == "A" && empty($_GET['level'])) $output .= $panel['panel_hidden'] ? _HIDDEN : _LEVEL." ".$panel['panel_level'];
else {
if($panel['panel_hidden']) $output .= _HIDDEN;
--- a/browse/class.php
+++ b/browse/class.php
@@ -38,7 +38,8 @@
$searchVars['classin'] = array($classid);
}
else if(isset($type_id)) {
- $output .= "<div id='pagetitle'>".($classtypelist[$type_id]['title'] ?? null)."</div>";
+ if(empty($type_id)) $classtypelist[$type_id]['title'] = '';
+ $output .= "<div id='pagetitle'>".($classtypelist[$type_id]['title'])."</div>";
foreach($classlist as $c => $i) {
if($i['type'] == $type_id) $clist[] = "<a href='browse.php?type=class&type_id=$type_id&classid=$c'>".$i['name']."</a><br />";
else $clist[] = '';
--- a/browse/ratings.php
+++ b/browse/ratings.php
@@ -34,7 +34,7 @@
}
else {
$output .= "<div id='pagetitle'>"._RATINGS."</div>";
- $total = is_countable($ratingslist ?? null);
+ $total = is_countable(isset($ratingslist) ? $ratingslist : null);
$count = 0;
$column = 1;
$list = floor($total / $displaycolumns);
--- a/header.php
+++ b/header.php
@@ -216,7 +216,8 @@
$squery = dbquery("SELECT sid, inorder FROM ".TABLEPREFIX."fanfiction_chapters WHERE chapid = ".$chapid." LIMIT 1");
list($sid, $chapter) = dbrow($squery);
}
- $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");
+ if(empty($sid)) $sid = isset($_GET['sid']) && isNumber($_GET['sid']) ? $_GET['sid'] : false;
+ $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");
if($story = dbassoc($titlequery)) {
$authlink[] = $story['penname'];
if($story['coauthors']) {
@@ -233,7 +234,7 @@
//header("Content-Disposition: inline; filename=\"".$titleinfo."\"");
}
}
-if($current == "viewuser" && (isNumber($uid ?? null))) {
+if($current == "viewuser" && (isNumber(isset($uid) ? $uid : null))) {
$author = dbquery("SELECT "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." WHERE "._UIDFIELD." = '".$uid."'");
list($penname) = dbrow($author);
$titleinfo = "$sitename :: $penname";
--- a/reviews.php
+++ b/reviews.php
@@ -292,7 +292,7 @@
$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");
$story = dbassoc($storyquery);
$title = title_link($story);
- $authoruid = ($story['uid']) ?? null;
+ $authoruid = (isset($story['uid']) ? $story['uid'] : null);
if(empty($story)) accessDenied();
if(!empty($story['coauthors'])) {
$colist = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '$item'");
@@ -375,11 +375,11 @@
}
$jumpmenu = "<form name=\"jump\" action=\"\">";
$jumpmenu .= "<select name=\"sid\" onChange=\"window.location=this.options[this.selectedIndex].value\">";
- $jumpmenu .= "<option value=\"reviews.php?type=ST&item=".(($story['sid']) ?? null).(isset($_GET['unresponded']) ? "&unresponded=1" : "")."\"";
+ $jumpmenu .= "<option value=\"reviews.php?type=ST&item=".(isset($story['sid']) ? $story['sid'] : null).(isset($_GET['unresponded']) ? "&unresponded=1" : "")."\"";
if(!isset($chapid))
$jumpmenu .= " selected";
$jumpmenu .= ">"._VIEWALLREVIEWS."</option>";
- $chapquery = dbquery("SELECT inorder, title, chapid, sid FROM ".TABLEPREFIX."fanfiction_chapters WHERE sid = '".(($story['sid']) ?? null)."' ORDER BY inorder ASC");
+ $chapquery = dbquery("SELECT inorder, title, chapid, sid FROM ".TABLEPREFIX."fanfiction_chapters WHERE sid = '".(isset($story['sid']) ? $story['sid'] : null)."' ORDER BY inorder ASC");
while($chapters = dbassoc($chapquery)) {
$jumpmenu .= "<option value=\"reviews.php?chapid=".$chapters['chapid'].(isset($_GET['unresponded']) ? "&unresponded=1" : "")."&type=ST&item=$item\"";
--- a/viewstory.php
+++ b/viewstory.php
@@ -30,9 +30,10 @@
if(isset($_GET['textsize']) && isNumber($_GET['textsize'])) $textsize = $_GET['textsize'];
else $textsize = 0;
if(empty($chapter)) $chapter = isset($_GET['chapter']) && isNumber($_GET['chapter']) ? $_GET['chapter'] : false;
+if(empty($sid)) $sid = isset($_GET['sid']) && isNumber($_GET['sid']) ? $_GET['sid'] : false;
// Get the story information
- $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);
+ $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);
$storyinfo = dbassoc($storyquery);
if(!$storyinfo) {
@@ -41,7 +42,7 @@
if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
else $tpl = new TemplatePower("default_tpls/default.tpl");
$title = "Story was not found";
- $text = "Story with ID " . (($sid) ?? null) . " is not in database";
+ $text = "Story with ID " . $sid . " is not in database";
include("includes/pagesetup.php");
$tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
$tpl->printToScreen();
--- a/viewuser.php
+++ b/viewuser.php
@@ -47,7 +47,7 @@
if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
else $tpl = new TemplatePower("default_tpls/default.tpl");
$title = "User was not found";
- $text = "User with ID " . (($uid) ?? null) . " is not in database";
+ $text = "User with ID " . $uid . " is not in database";
include("includes/pagesetup.php");
$tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
$tpl->printToScreen();
@@ -75,7 +75,7 @@
if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
else $tpl = new TemplatePower("default_tpls/default.tpl");
$title = "User was not found";
- $text = "User with ID " . (($uid) ?? null) . " is not in database";
+ $text = "User with ID " . $uid . " is not in database";
include("includes/pagesetup.php");
$tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
$tpl->printToScreen();