3.5.8.1 warnings, dbconnect, install changes
--- a/README.md
+++ b/README.md
@@ -2,6 +2,8 @@
- added notification module
- changed files: user/editbio.php and user/lostpassword.php
+- chanded way for loading DB functions - moved from config file!
+- fixed bug in install.php - script worked but in PHP 8.x it caused warnings
# efiction v3.5.7
--- a/header.php
+++ b/header.php
@@ -69,7 +69,12 @@
while (!file_exists($folder_level."header.php")) { $folder_level .= "../"; }
if(!defined("_BASEDIR")) define("_BASEDIR", $folder_level);
-@ include_once(_BASEDIR."config.php");
+if (file_exists(_BASEDIR . "config.php"))
+{
+ include_once(_BASEDIR . "config.php");
+ include_once(_BASEDIR . "includes/dbfunctions.php");
+}
+
if(empty($sitekey)) {
header("Location: install/install.php");
exit( );
--- a/includes/dbfunctions.php
+++ b/includes/dbfunctions.php
@@ -1,7 +1,12 @@
<?php
-if(function_exists("mysqli_connect")) include_once(_BASEDIR."includes/mysqli_functions.php");
-else {
+
+
+if(function_exists("mysqli_connect")) {
+
+ include_once(_BASEDIR."includes/mysqli_functions.php");
+ $dbconnect = @dbconnect($dbhost, $dbuser, $dbpass, $dbname);
+}else {
include(_BASEDIR."languages/en.php"); // Because we haven't selected a language setting yet
die(_FATALERROR._NODBFUNCTIONALITY);
}
--- a/includes/mysqli_functions.php
+++ b/includes/mysqli_functions.php
@@ -4,10 +4,11 @@
if(!function_exists("dbconnect")) { // just in case. Some people seemed to be having an issue and this was the easiest fix.
function dbconnect($dbhost, $dbuser, $dbpass, $dbname ) {
- $mysql_access = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
+ $mysqli_access = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
+
try
{
- $mysql_access = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
+ $mysqli_access = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
}
catch (mysqli_sql_exception $e)
{
@@ -18,9 +19,9 @@
}
}
//mysqli_query($mysql_access, "SET SESSION sql_mode = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION'");
- mysqli_query($mysql_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'");
- mysqli_query($mysql_access, "SET NAMES UTF8;");
- return $mysql_access;
+ mysqli_query($mysqli_access, "SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'");
+ mysqli_query($mysqli_access, "SET NAMES UTF8;");
+ return $mysqli_access;
}
@@ -92,3 +93,4 @@
}
?>
+
--- a/includes/storyblock.php
+++ b/includes/storyblock.php
@@ -100,7 +100,7 @@
$numchapsquery = dbquery("SELECT count(sid) FROM ".TABLEPREFIX."fanfiction_chapters WHERE sid = '".$stories['sid']."' AND validated > 0");
list($chapters) = dbrow($numchapsquery);
$tpl->assign("numchapters", $chapters );
-
+
$tpl->assign("updated" , date("$dateformat", $stories['updated']) );
$tpl->assign("published" , date("$dateformat", $stories['date']) );
if(!empty($recentdays)) {
--- a/install/install.php
+++ b/install/install.php
@@ -105,6 +105,8 @@
else
{
include("../config.php");
+ include("../includes/dbfunctions.php");
+
$dbconnect = dbconnect($dbhost, $dbuser, $dbpass, $dbname);
$settings = dbquery("SELECT tableprefix, language FROM " . $settingsprefix . "fanfiction_settings WHERE sitekey = '" . $sitekey . "'");
list($tableprefix, $language) = dbrow($settings);
@@ -824,9 +826,11 @@
case "2";
include("../config.php");
+ include("../includes/dbfunctions.php");
if (dbnumrows(dbquery("SHOW TABLES LIKE '" . $settingsprefix . "fanfiction_settings'")))
{
- include("../config.php");
+ //include("../config.php");
+ //include("../includes/dbfunctions.php");
$dbconnect = dbconnect($dbhost, $dbuser, $dbpass, $dbname);
$settings = dbquery("SELECT tableprefix, language FROM " . $settingsprefix . "fanfiction_settings WHERE sitekey = '" . $sitekey . "'");
list($tableprefix, $language) = dbrow($settings);
@@ -955,13 +959,14 @@
{
$test = dbquery("SHOW TABLES");
- if (!$test) $output .= write_message(_CONFIGFAILED);
+ if (!$test) $output .= write_message(_CONFIGFAILED. "(2)");
else $output .= write_message(_SETTINGSTABLESETUP . " <a href='install.php?step=2&install=automatic'>" . _AUTO . "</a> " . _OR . " <a href='install.php?step=2&install=manual'>" . _MANUAL2 . "</a>");
}
}
break;
default:
$output .= "<div id='pagetitle'>" . _CONFIGDATA . "</div>";
+
if (isset($_POST['submit']))
{
$dbhost = descript($_POST['dbhost']);
@@ -971,14 +976,16 @@
$language = $_POST['language'];
$sitekey = descript($_POST['sitekey']);
$settingsprefix = descript($_POST['settingsprefix']);
- $mysqli_access = mysqli_connect($dbhost, $dbuser, $dbpass);
+ $mysqli_access = @mysqli_connect($dbhost, $dbuser,$dbpass, $dbname);
+
if (!$mysqli_access)
{
- $output .= write_message(_CONFIGFAILED);
+ $output .= write_message(_CONFIGFAILED . "(1)");
}
}
if (isset($_POST['submit']) && $mysqli_access)
{
+
$handle = fopen("../config.php", 'w');
if (!$handle)
{
@@ -1003,10 +1010,13 @@
\$sitekey = \"$sitekey\";
\$settingsprefix = \"$settingsprefix\";
-include_once(\"includes/dbfunctions.php\");
+?>";
+
+/* removed in 3.5.8 and moved to file:
+include(\"includes/dbfunctions.php\");
if(!empty(\$sitekey)) \$dbconnect = dbconnect(\$dbhost, \$dbuser,\$dbpass, \$dbname);
-
-?>";
+*/
+
fwrite($handle, $text);
fclose($handle);
@chmod("../config.php", 0644);
@@ -1016,7 +1026,10 @@
}
else
{
- if (file_exists("../config.php") && !isset($mysqli_access)) include("../config.php");
+ if (file_exists("../config.php") && !isset($mysqli_access)) {
+ include("../config.php");
+ include("../includes/dbfunctions.php");
+ }
if (isset($tinyMCE)) $output .= write_message(_CONFIG2DETECTED);
else if (isset($sitename) && $sitename) $output .= write_message(_CONFIG1DETECTED);
else
--- a/rss.php
+++ b/rss.php
@@ -24,9 +24,10 @@
ini_set('display_startup_errors', 0);
error_reporting(-1);
-define("_BASEDIR", "");
- require_once("includes/dbfunctions.php");
- require_once("config.php");
+define("_BASEDIR", "");
+require_once("config.php");
+require_once("includes/dbfunctions.php");
+
$settingsresults = dbquery("SELECT sitename, url, siteemail, slogan, language, tableprefix, dateformat FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '$sitekey'");
$settings = dbassoc($settingsresults);
foreach($settings as $var => $val) {
--- a/stories.php
+++ b/stories.php
@@ -624,7 +624,7 @@
if(isset($_POST['submit'])) {
$title = isset($_POST['title']) ? strip_tags(descript($_POST['title']), $allowed_tags) : "";
$summary = isset($_POST['summary']) ? strip_tags(descript($_POST['summary']), $allowed_tags) : "";
- $storynotes = strip_tags(descript($_POST['storynotes']), $allowed_tags);
+ $storynotes = isset($_POST['storynotes']) ? strip_tags(descript($_POST['storynotes']), $allowed_tags) : "";
$rr = isset($_POST['rr']) && isNumber($_POST['rr']) ? $_POST['rr'] : 0;
$feat = isset($_POST['feature']) && isNumber($_POST['feature']) ? $_POST['feature'] : 0;
$complete = isset($_POST['complete']) && isNumber($_POST['complete']) ? $_POST['complete'] : 0;
--- a/update.php
+++ b/update.php
@@ -202,7 +202,7 @@
else $output .= write_message("Are you ready to update? <a href='update.php?confirm=yes'>" . _YES . "</a> " . _OR . " <a href='update.php?confirm=no'>" . _NO . "</a>");
}
}
-elseif ($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 7)) //3.5.6
+elseif ($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 8)) //3.5.6 + 3.5.7
{
if ($confirm == "yes")
{
@@ -261,6 +261,7 @@
}
}
+
else $output .= write_message(_ALREADYUPDATED);
/* until database is fully fixed, not update efiction version */
--- a/user/login.php
+++ b/user/login.php
@@ -26,6 +26,7 @@
if(!defined("_LOGINCHECK")) exit( );
define("_BASEDIR", "");
include_once("config.php");
+ include(_BASEDIR . "includes/dbfunctions.php");
$settings = dbquery("SELECT tableprefix, maintenance, sitekey, debug FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '".$sitekey."'");
list($tableprefix, $maintenance, $sitekey, $debug) = dbrow($settings);
$tempdebug = $debug;
@@ -110,7 +111,12 @@
if($link['link_access'] == 2 && !isADMIN) continue;
$pagelinks[$link['link_name']] = array("id" => $link['link_id'], "text" => $link['link_text'], "url" => _BASEDIR.$link['link_url'], "link" => "<a href=\"".$link['link_url']."\" title=\"".$link['link_text']."\"".($link['link_target'] ? " target=\"_blank\"" : "").($current == $link['link_name'] ? " id=\"current\"" : "").">".$link['link_text']."</a>");
}
- $output .= "<div style='text-align: center;'>".$pagelinks['register']['link']." | ".$pagelinks['lostpassword']['link']."</div>";
+ $output .= "<div style='text-align: center;'>";
+ if(isset($pagelinks['register'])) {
+ $output .= $pagelinks['register']['link']." | ";
+ }
+ $output .= $pagelinks['lostpassword']['link']."</div>";
+
}
}
?>
--- a/viewstory.php
+++ b/viewstory.php
@@ -34,7 +34,22 @@
// 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."' AND story.uid = "._UIDFIELD);
$storyinfo = dbassoc($storyquery);
- if($storyinfo['coauthors'] == 1) {
+
+ if(!$storyinfo) {
+ $current = "storyerror";
+ // load our template files to set up the page.
+ 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 . " is not in database";
+ include("includes/pagesetup.php");
+ $tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
+ $tpl->printToScreen();
+ dbclose();
+ exit();
+ }
+
+ if($storyinfo['coauthors'] > 0) {
$array_coauthors = array();
$coauth = dbquery("SELECT "._PENNAMEFIELD." as penname, co.uid FROM ".TABLEPREFIX."fanfiction_coauthors AS co LEFT JOIN "._AUTHORTABLE." ON co.uid = "._UIDFIELD." WHERE co.sid = '".$sid."'");
while($c = dbassoc($coauth)) {
@@ -295,12 +310,28 @@
// if the story has only one chapter this is what happens
else {
$chapter = dbassoc($chapterinfo);
+
+ if (!$chapter)
+ {
+ $current = "chaptererror";
+ // load our template files to set up the page.
+ if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
+ else $tpl = new TemplatePower("default_tpls/default.tpl");
+ $title = "Chapter was not found";
+ $text = "Missing chapter";
+ include("includes/pagesetup.php");
+ $tpl->assign("output", "<div id='pagetitle'>" . $title . "</div>" . write_error($text));
+ $tpl->printToScreen();
+ dbclose();
+ exit();
+ }
+
$chapterauthor = $chapter['uid'];
$chapterpenname = $chapter['penname'];
$chaptertitle = $chapter['title'];
$chapid = $chapter['chapid'];
- $title = stripslashes($chapter['title']);
- $inorder = $chapter['inorder'];
+ $title = stripslashes((string) $chapter['title']);
+ $inorder = $chapter['inorder'];
$notes = format_story($chapter['notes']);
$endnotes = format_story($chapter['endnotes']);
$story = $chapter['storytext'];