version 3.5.7
version 3.5.7

file:a/.gitignore -> file:b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -396,4 +396,7 @@
 
 # JetBrains Rider
 *.sln.iml
-
+languages/sk.php
+languages/sk_admin.php
+/modules/storybanner
+

file:a/README.md -> file:b/README.md
--- a/README.md
+++ b/README.md
@@ -1,3 +1,21 @@
+# efiction v3.5.7
+
+minimum requirements:  MySQL 5.6.3  or MariaDB 10.5.0 
+
+
+### Database changes:
+
+- all IP adress fields - from integer to 46 chars
+
+### Other changes:
+
+- tinymce4 settings fix
+- INET6 support needed
+- file uploading fixed for PHP 8.1
+- national characters fix in search form 
+
+
+
 # efiction v3.5.6
 
 non official version of 3.5.x efiction software

--- a/admin/backup.php
+++ b/admin/backup.php
@@ -78,7 +78,8 @@
 			datadump(current($table));
 	}
 
- 	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_BACKUP, USERPENNAME, USERUID))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM', " . time() . ")");
+ 	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_BACKUP, USERPENNAME, USERUID))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM', " . time() . ")");
 	exit( );
 
 ?>
+

--- a/admin/backup_utf8.php
+++ b/admin/backup_utf8.php
@@ -80,7 +80,8 @@
 			datadump(current($table));
 	}
 
- 	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_BACKUP, USERPENNAME, USERUID))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM', " . time() . ")");
+ 	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_BACKUP, USERPENNAME, USERUID))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM', " . time() . ")");
 	exit( );
 
 ?>
+

--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -59,7 +59,7 @@
 	while($code = dbassoc($codequery)) {
 		$eval($code['code_text']);
 	}
-	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_RECALCREVIEWS, USERPENNAME, USERUID))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM', " . time() . ")");
+	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_RECALCREVIEWS, USERPENNAME, USERUID))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM', " . time() . ")");
 	$output .= write_message(_ACTIONSUCCESSFUL);
 }
 else if($maint == "stories") {
@@ -97,7 +97,7 @@
 		list($count) = dbrow($countquery);
 		dbquery("UPDATE ".TABLEPREFIX."fanfiction_categories SET numitems = $count WHERE catid = $cat[0]");
 	}
-	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_CATCOUNTS, USERPENNAME, USERUID))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM', " . time() . ")");
+	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_CATCOUNTS, USERPENNAME, USERUID))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM', " . time() . ")");
 	$output .= write_message(_CATCOUNTSUPDATED);
 }
 else if($maint == "categories2") {
@@ -192,7 +192,7 @@
 			dbquery("OPTIMIZE TABLE `".$tablename."`");
 		}
 	}
- 	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_OPTIMIZE, USERPENNAME, USERUID))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM', " . time() . ")");
+ 	if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_OPTIMIZE, USERPENNAME, USERUID))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'AM', " . time() . ")");
 	$output .= write_message(_ACTIONSUCCESSFUL);
 }
 else if($maint == "backup") {
@@ -213,3 +213,4 @@
 </ul>";
 }
 ?>
+

--- a/admin/members.php
+++ b/admin/members.php
@@ -168,7 +168,7 @@
 			if(preg_match("!^[a-z0-9_ ]{3,30}$!i", $_POST['penname'])) {
 				dbquery("INSERT INTO ".substr(_AUTHORTABLE, 0, strpos(_AUTHORTABLE, "as author"))."(penname, realname, email, admincreated, date) VALUES ('".escapestring(descript($_POST['penname']))."', '".escapestring(descript($_POST['realname']))."', '".escapestring(descript($_POST['email']))."', '1', now())");
 				$newuid = dbinsertid( );
-				if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_REG, descript($_POST['penname']), $newuid, USERPENNAME, USERUID, $_SERVER['REMOTE_ADDR']))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RG', " . time() . ")");
+				if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_REG, descript($_POST['penname']), $newuid, USERPENNAME, USERUID, $_SERVER['REMOTE_ADDR']))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RG', " . time() . ")");
 				if(!$skin) {
 					$skinquery = dbquery("SELECT skin FROM ".$settingsprefix."fanfiction_settings WHERE sitekey ='".SITEKEY."'");
 					list($skin) = dbrow($skinquery);
@@ -270,3 +270,4 @@
 		if(isset($message)) $output .= $message;
 	}
 ?>
+

--- a/admin/noletter.php
+++ b/admin/noletter.php
@@ -42,7 +42,7 @@
 		if($logging) {
 			$storyquery = dbquery("SELECT story.title, chapter.title as chapter, author.email, author.penname, chapter.uid, chapter.inorder FROM ".TABLEPREFIX."fanfiction_stories as story, ".TABLEPREFIX."fanfiction_chapters as chapter, ".TABLEPREFIX."fanfiction_authors as author WHERE chapter.uid = author.uid AND chapter.chapid = '$chapid' AND chapter.sid = story.sid LIMIT 1");
 			$story = dbassoc($storyquery);
-			dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_REJECTION, USERPENNAME, USERUID, $title, $sid, $uid, $penname, $inorder, $letter))."', '".USERUID."', INET_ATON('".$_ENV['REMOTE_ADDR']."'), 'RJ', ". time() . ")");
+			dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_REJECTION, USERPENNAME, USERUID, $title, $sid, $uid, $penname, $inorder, $letter))."', '".USERUID. "', INET6_ATON('".$_ENV['REMOTE_ADDR']."'), 'RJ', ". time() . ")");
 		}
 
 	}
@@ -65,3 +65,4 @@
 		exit( );
 	}
 ?>
+

--- a/admin/validate.php
+++ b/admin/validate.php
@@ -108,7 +108,7 @@
 						sendemail($favuser['penname'], $favuser['email'], $sitename, $siteemail, $subject, $mailtext, "html");
 					}				
 				}
-				if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_VALIDATE_STORY, USERPENNAME, USERUID, $title, $sid, $author, $authoruid))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'VS', " . time() . ")");
+				if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_VALIDATE_STORY, USERPENNAME, USERUID, $title, $sid, $author, $authoruid))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'VS', " . time() . ")");
 				dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET stories = stories + 1");
 			}
 			else if($alertson) {
@@ -122,7 +122,7 @@
 				while($favuser = dbassoc($favorites)) { 
 					sendemail($favuser['penname'], $favuser['email'], $sitename, $siteemail, $subject, $mailtext, "html");
 				}
-				if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_VALIDATE_CHAPTER, USERPENNAME, USERUID, $title, $sid, $author, $authoruid, $inorder))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'VS', " . time() . ")");
+				if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_VALIDATE_CHAPTER, USERPENNAME, USERUID, $title, $sid, $author, $authoruid, $inorder))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'VS', " . time() . ")");
 			}
 			dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET validated = '1' WHERE chapid = '$_GET[chapid]'");
 			dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET updated = '" . time() . "' WHERE sid = '$sid'");
@@ -149,3 +149,4 @@
 		}
 	}
 ?>
+

--- a/admin/viewlog.php
+++ b/admin/viewlog.php
@@ -46,7 +46,7 @@
 $countquery = dbquery("SELECT COUNT(log_id) FROM ".TABLEPREFIX."fanfiction_log".($type ? " WHERE log_type = '$type'" : ""));
 list($count) = dbrow($countquery);
 if($count > 0) {
-	$result = dbquery("SELECT log_action, INET_NTOA(log_ip) as log_ip,  log_timestamp as log_timestamp FROM ".TABLEPREFIX."fanfiction_log".($type ? " WHERE log_type = '$type'" : "")." ORDER BY log_timestamp DESC LIMIT $offset, $itemsperpage");
+	$result = dbquery("SELECT log_action, INET6_NTOA(log_ip) as log_ip,  log_timestamp as log_timestamp FROM ".TABLEPREFIX."fanfiction_log".($type ? " WHERE log_type = '$type'" : "")." ORDER BY log_timestamp DESC LIMIT $offset, $itemsperpage");
 	$output .= "<table class=\"tblborder\" cellspacing=\"0\" cellpadding=\"3\" style=\"width: 90%; margin: 0 auto;\"><tr class=\"tblborder\"><th>"._ACTION."</th><th>"._IP."</th><th>"._DATE."</th></tr>";
 	while ($item = dbassoc($result)) {
 			$output .= "<tr class=\"tblborder\">
@@ -62,3 +62,4 @@
 else $output .= write_message(_NORESULTS);
 $output .= write_message("<a href='admin.php?action=viewlog&amp;purge=1'>"._PURGELOG."</a>");
 ?>
+

--- a/blocks/online/init.php
+++ b/blocks/online/init.php
@@ -27,9 +27,10 @@
 
 
 dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_blocks(`block_name`, `block_title`, `block_status`, `block_file`, `block_variables`) VALUES('online', 'Who\'s Online', '0', 'online/online.php', '');");
-dbquery("CREATE TABLE IF NOT EXISTS `".TABLEPREFIX."fanfiction_online` (
+dbquery("CREATE TABLE IF NOT EXISTS `".TABLEPREFIX. "fanfiction_online` (
   `online_uid` int(11) NOT NULL default '0',
-  `online_ip` int(11) NOT NULL default '0',
+  `online_ip` VARBINARY(16) NOT NULL default '0',
   `online_timestamp` int(11) NOT NULL default '0'
 ) ENGINE=MyISAM;");
 ?>
+

--- a/blocks/online/online.php
+++ b/blocks/online/online.php
@@ -5,7 +5,7 @@
 	if(file_exists(_BASEDIR."blocks/online/{$language}.php")) include(_BASEDIR."blocks/online/{$language}.php");
 	else include(_BASEDIR."blocks/online/en.php");
 
-	$where = "online_uid=" . (USERUID ? USERUID : "0 AND online_ip = INET_ATON('" . $_SERVER['REMOTE_ADDR'] . "')");
+	$where = "online_uid=" . (USERUID ? USERUID : "0 AND online_ip = INET6_ATON('" . $_SERVER['REMOTE_ADDR'] . "')");
  
 	$result = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_online WHERE $where");
  
@@ -24,7 +24,7 @@
 		}
 		
 		dbquery("INSERT INTO " . TABLEPREFIX . "fanfiction_online(online_uid, online_ip, online_timestamp)
-		 VALUES('" . (USERUID ? USERUID : 0) . "', INET_ATON('" . $ip . "'), '" . time() . "')");
+		 VALUES('" . (USERUID ? USERUID : 0) . "', INET6_ATON('" . $ip . "'), '" . time() . "')");
 	} 
  
 	$result = dbquery("DELETE FROM ".TABLEPREFIX."fanfiction_online WHERE online_timestamp < ".(time()-60));
@@ -41,3 +41,4 @@
 	$content = "<div id='who_online'><span class='label'>"._GUESTS.":</span> ".($guests ? $guests : 0)."<br />\n
 		<span class='label'>"._MEMBERS.":</span> ".(count($omlist) ? implode(", ", $omlist) : "")."</div>";
 ?>
+

--- a/default_tpls/listings.tpl
+++ b/default_tpls/listings.tpl
@@ -3,7 +3,7 @@
 <!-- START BLOCK : seriesblock -->
 <div class="listbox {oddeven}">
 <div class="title">{title} by {author}{score} [{reviews} - {numreviews}]</div>
-<div class="content"><span class="label">Summary: </span>{summary}<br />
+<div class="content listing"><span class="label">Summary: </span>{summary}<br />
 <span class="label">Parent Series:</span> {parentseries}<br />
 <span class="label">Categories:</span> {category}<br />
  <span class="label">Characters: </span>{characters}<br />
@@ -33,3 +33,4 @@
 <!-- END BLOCK : storyblock -->
 {pagelinks}
 <!-- END BLOCK : listings -->
+

--- a/default_tpls/printstory.tpl
+++ b/default_tpls/printstory.tpl
@@ -27,3 +27,4 @@
 <!-- END BLOCK : chapterblock -->
 <div id="copyright">{copyright}</div>
 <div id="archivedat">{archivedat}</div>
+

file:a/header.php -> file:b/header.php
--- a/header.php
+++ b/header.php
@@ -32,6 +32,9 @@
 // Defines the character set for your language/location
 define ("_CHARSET", "utf-8");
 
+//default values to avoid ajax issue when notice error are on
+$allowed_tags = '';
+
 // Prevent possible XSS attacks via $_GET.
 foreach ($_GET as $v) {
 	if(preg_match('@<script[^>]*?>.*?</script>@si', $v) ||
@@ -101,10 +104,10 @@
 
 if(isset($_GET['action'])) $action = strip_tags($_GET['action']);
 else $action = false;
-
+ 
 if(file_exists(_BASEDIR."languages/{$language}.php")) include (_BASEDIR."languages/{$language}.php");
 else include (_BASEDIR."languages/en.php");
-
+ 
 include_once(_BASEDIR."includes/queries.php");
 include_once(_BASEDIR."includes/corefunctions.php");
 
@@ -189,8 +192,7 @@
 if(isset($_GET['ageconsent'])) $_SESSION[SITEKEY."_ageconsent"] = 1;
 if(isset($_GET['warning'])) $_SESSION[SITEKEY."_warned"][$_GET['warning']] = 1;
 
-if(file_exists("languages/{$language}.php")) require_once ("languages/{$language}.php");
-else require_once ("languages/en.php");
+
 if(is_dir(_BASEDIR."skins/$siteskin")) $skindir = _BASEDIR."skins/$siteskin";
 else if(is_dir(_BASEDIR."skins/".$settings['skin'])) $skindir = _BASEDIR."skins/".$defaultskin;
 else $skindir = _BASEDIR."default_tpls";
@@ -228,7 +230,7 @@
 	list($penname) = dbrow($author);
 	$titleinfo = "$sitename :: $penname";
 }
-echo _DOCTYPE."<html><head>";
+echo _DOCTYPE."<html lang={$language}><head>";
 echo "<meta charset='utf-8' />";
 if(!isset($titleinfo)) $titleinfo = "$sitename :: $slogan";
 if(isset($metaDesc)) echo "<meta name='description' content='$metaDesc'>";
@@ -240,10 +242,11 @@
 	echo "<link rel='icon' href='"._BASEDIR."favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='"._BASEDIR."favicon.ico' type='image/xicon' />\n";
 }
  
-echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset="._CHARSET."\">";
+//A document must not include both a “meta” element with an “http-equiv” attribute whose value is “content-type”, and a “meta” element with a “charset” attribute.
+//echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset="._CHARSET."\">";
 if (!isset($_GET['action']) || $_GET['action'] != "printable")
 {
-	echo "<script language=\"javascript\" type=\"text/javascript\" src=\"" . _BASEDIR . "includes/javascript.js\"></script>
+	echo "<script  src=\"" . _BASEDIR . "includes/javascript.js\"></script>
 <link rel=\"alternate\" type=\"application/rss+xml\" title=\"$sitename RSS Feed\" href=\"" . _BASEDIR . "rss.php\">";
 }
 
@@ -252,18 +255,18 @@
 	if (!empty($tinyMCE))
 	{
 		if($tinyMCE == 1) {
-			echo "<script language=\"javascript\" type=\"text/javascript\" src=\"" . _BASEDIR . "tinymce/jscripts/tiny_mce/tiny_mce.js\"></script>";
+			echo "<script src=\"" . _BASEDIR . "tinymce/jscripts/tiny_mce/tiny_mce.js\"></script>";
 			include(_BASEDIR . "tinymce/init.php");
 		}
 		else {
-			echo "<script language=\"javascript\" type=\"text/javascript\" src=\"" . _BASEDIR . "tinymce4/js/tinymce/tinymce.min.js\"></script>";
+			echo "<script src=\"" . _BASEDIR . "tinymce4/js/tinymce/tinymce.min.js\"></script>";
 			include(_BASEDIR . "tinymce4/init.php");		
 		}
 	}
 }
 if(isset($displayform) && $displayform == 1) {
-echo "<script language=\"javascript\" type=\"text/javascript\" src=\""._BASEDIR."includes/xmlhttp.js\"></script>";
-echo "<script language=\"javascript\" type=\"text/javascript\">
+echo "<script src=\""._BASEDIR."includes/xmlhttp.js\"></script>";
+echo "<script>
 lang = new Array( );
 
 lang['Back2Cats'] = '"._BACK2CATS."';
@@ -301,9 +304,9 @@
 if(!$displaycolumns) $displaycolumns = 1;
 $colwidth = floor(100/$displaycolumns);
 if(!empty($_GET['action']) && $_GET['action'] == "printable") {
-	if(file_exists("$skindir/printable.css")) echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$skindir/printable.css\">";
-	else echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"default_tpls/printable.css\">";
-	echo "<script type='text/javascript'>
+	if(file_exists("$skindir/printable.css")) echo "<link rel=\"stylesheet\"  href=\"$skindir/printable.css\">";
+	else echo "<link rel=\"stylesheet\"  href=\"default_tpls/printable.css\">";
+	echo "<script>
 <!--
 if (window.print) {
     window.print() ;  
@@ -316,7 +319,7 @@
 </script>";
 }
 else {
-echo "<style type=\"text/css\">
+echo "<style>
 #columncontainer { margin: 1em auto; width: auto; padding: 5%;}
 #browseblock, #memberblock { width: 100%; padding: 0; margin: 0; float: left; border: 0px solid transparent; }
 .column { float: left; width: ".($colwidth - 1)."%; }

--- a/includes/categories.php
+++ b/includes/categories.php
@@ -28,6 +28,7 @@
 if(!isset($catid)) $catid = array( );
 
 $output .= "<div style='width: 99.9%; float: left;'>\r\n
+<div style=\"text-align: center;\"><b>"._MULTIPLESELECT."</b></div>\r\n
 		<div style='width: 40%; float: left;'><label for='catoptions'>"._CATOPTIONS."</label> <br />
 		<select name='catoptions' id='catoptions' multiple='multiple' size='8' onchange='resetCats(\"catoptions\");' style='width: 100%;'>";
 $selectedCats = "";
@@ -52,3 +53,4 @@
 		</div>
 		<input type='hidden' name='catid' id='catid' value='".(isset($cats) ? implode(",", $cats) : "")."'>";
 ?>
+

--- a/includes/categorylist.php
+++ b/includes/categorylist.php
@@ -1,10 +1,14 @@
 <?php
 define("_BASEDIR", "../");
+define("_CHARSET", "utf-8");
+
 include("../config.php");
 include("../includes/dbfunctions.php");
+ 
+
 list($tableprefix, $lang) = dbrow(dbquery("SELECT tableprefix, language FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '$sitekey'"));
 define("TABLEPREFIX", $tableprefix);
-include(_BASEDIR."languages/$lang.php");
+ 
 header("Content-Type: text/javascript; charset="._CHARSET,true);
 include("../includes/queries.php");
 
@@ -15,7 +19,8 @@
 $find = array ('"', chr(150), chr(147), chr(148), chr(146));
 $replace = array ('\"', "-", "\"", "\"", "'");
 while($category = dbassoc($cats)) {
-	echo "categories[$x] = new category(".$category['parentcatid'].", ".$category['catid'].", \"".urlencode(str_replace($find, $replace, stripslashes($category['category'])))."\", ".$category['locked'].", ".$category['displayorder'].");\r\n";
+	echo "categories[$x] = new category(".$category['parentcatid'].", ".$category['catid'].", \"". str_replace($find, $replace, stripslashes($category['category']))."\", ".$category['locked'].", ".$category['displayorder'].");\r\n";
 	$x++;
 }
 ?>
+

--- a/includes/characterlist.php
+++ b/includes/characterlist.php
@@ -21,7 +21,8 @@
 $find = array ('"', chr(150), chr(147), chr(148), chr(146));
 $replace = array ('\"', "-", "\"", "\"", "'");
 while($char = dbassoc($characters)) {
-	echo "characters[$x] = new Array(".$char['charid'].", \"".urlencode(str_replace($find, $replace, stripslashes($char['charname'])))."\");\r\n";
+	echo "characters[$x] = new Array(".$char['charid'].", \"". str_replace($find, $replace, stripslashes($char['charname'])) ."\");\r\n";
 	$x++;
 }
 ?>
+

--- a/includes/deletefunctions.php
+++ b/includes/deletefunctions.php
@@ -42,7 +42,7 @@
 	if($logging) {
 		$authorquery = dbquery("SELECT "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." WHERE "._UIDFIELD." = '".$story['uid']."' LIMIT 1");
 		list($penname) = dbrow($authorquery);
-		dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_DEL, USERPENNAME, USERUID, $story['title'], $sid, $penname, $story['uid']))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR'].
+		dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_DEL, USERPENNAME, USERUID, $story['title'], $sid, $penname, $story['uid']))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR'].
 		"'), 'DL', " . time() . ")");
 	}
 	dbquery("DELETE FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '$sid' LIMIT 1");
@@ -193,7 +193,8 @@
 			eval($code['code_text']);
 	}
 	if($logging && isADMIN) {
-		if($uid != USERUID) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_DEL_SERIES, USERPENNAME, USERUID, $title))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'DL', " . time() . ")");
+		if($uid != USERUID) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_DEL_SERIES, USERPENNAME, USERUID, $title))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'DL', " . time() . ")");
 	}
 }
 ?>
+

--- a/includes/javascript.js
+++ b/includes/javascript.js
@@ -307,4 +307,3 @@
 	if(window.tinyMCE) tinyMCE.execCommand('mceResetDesignMode'); 
 }
 
-

--- a/includes/storyblock.php
+++ b/includes/storyblock.php
@@ -34,11 +34,12 @@
 		$stories['coauthors'] = $array_coauthors;
 		unset($array_coauthors);
 	}
-	else if(empty($stories['coauthors'])) $stories['coauthors'] = array( );	
+	else  $stories['coauthors'] = array( );	
+ 
 	$tpl->assign("title"   , stripslashes(title_link($stories)) );
 	$tpl->assign("author"   , author_link($stories));
 	$tpl->assign("summary", stripslashes($stories['summary']) );
-	$tpl->assign("rating"   , !empty($ratingslist) ? $ratingslist[$stories['rid']]['name'] : "");
+    $tpl->assign("rating"   , !empty($ratingslist) &&  !empty($stories['rid'] && key_exists('name', $ratingslist) )  ? $ratingslist[$stories['rid']]['name'] : "");
 	$tpl->assign("score", ratingpics($stories['rating']) );
 	$tpl->assign("count", $stories['count'] ? $stories['count'] : "0");
 	$allclasslist = "";
@@ -129,3 +130,4 @@
 	else if(isMEMBER && (USERUID == $stories['uid'] || array_key_exists(USERUID, $stories['coauthors']))) $tpl->assign("adminlinks", "<div class=\"adminoptions\"><span class='label'>"._OPTIONS.":</span> ".$adminlinks."</div>");
 	$count++;
 ?>
+

--- a/includes/upload_class.php
+++ b/includes/upload_class.php
@@ -38,7 +38,7 @@
 	var $message = array();
 	var $create_directory = true;
 	
-	function file_upload() {
+	function __construct() {
 		$this->language = "en"; // choice of en, nl, es
 		$this->rename_file = false;
 		$this->ext_string = "";
@@ -234,3 +234,4 @@
 	}
 }
 ?>
+

--- a/install/install.php
+++ b/install/install.php
@@ -650,7 +650,7 @@
   `log_id` int(11) NOT NULL auto_increment,
   `log_action` varchar(255) default NULL,
   `log_uid` int(11) NOT NULL,
-  `log_ip` int(11) UNSIGNED default NULL,
+  `log_ip` VARBINARY(16) NOT NULL,
   `log_timestamp` int(10) unsigned NOT NULL default '0',
   `log_type` varchar(2) NOT NULL,
   PRIMARY KEY  (`log_id`)

--- a/reviews.php
+++ b/reviews.php
@@ -219,8 +219,8 @@
 					}
 				}
 				$reviewname = $reviewer."(".$_SERVER['REMOTE_ADDR'].")";
-				if($action == "add") dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_REVIEW, $reviewname, truncate_text($review), $title))."', '0', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RE', " . time() . ")");
-				else dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_EDIT_REVIEW, USERPENNAME, USERUID, $title, $reviewid))."', '0', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RE', " . time() . ")");
+				if($action == "add") dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_REVIEW, $reviewname, truncate_text($review), $title)). "', '0', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RE', " . time() . ")");
+				else dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_EDIT_REVIEW, USERPENNAME, USERUID, $title, $reviewid)). "', '0', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RE', " . time() . ")");
 			}
 		}
 	}
@@ -419,3 +419,4 @@
 $tpl->assign("output", $output);
 $tpl->printToScreen( );
 ?>
+

file:a/search.php -> file:b/search.php
--- a/search.php
+++ b/search.php
@@ -265,7 +265,7 @@
 		<div style=\"font-size: 8pt; text-align: right;\"><a href=\"search.php?searchtype=advanced\">"._ADVANCED."</a></div></div></form></div>";
 	}
 	else {
-		$output .= "<div id=\"pagetitle\">"._ADVANCED."</div><div>
+		$output .= "<div id=\"pagetitle\">"._ADVANCED. "</div><div>
 			<form method=\"POST\" name=\"form\" enctype=\"multipart/form-data\" action=\"search.php?searchtype=advanced\">
 			<div class=\"tblborder\" style=\"width: 90%; margin: 0 auto; padding: 10px;\">";
 		if($multiplecats) {
@@ -292,7 +292,6 @@
 			$output .= "</select></div>";
 		}
 		$output .= "<div style=\"clear: both;\">&nbsp;</div>";
-		$output .= " <div style=\"text-align: center;\">"._MULTIPLESELECT."</div>";
 		$result = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_classtypes ORDER BY classtype_name");
 		while($type = dbassoc($result)) {
 			$result2 = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_classes WHERE class_type = '".$type['classtype_id']."' ORDER BY class_name");
@@ -337,3 +336,4 @@
 $tpl->printToScreen();
 dbclose( );
 ?>
+

file:a/series.php -> file:b/series.php
--- a/series.php
+++ b/series.php
@@ -121,7 +121,7 @@
 				if($logging && $admin) {
 					$seriesinfo = dbquery("SELECT title, uid FROM ".TABLEPREFIX."fanfiction_series WHERE seriesid = '$seriesid'");
 					list($title, $uid) = dbrow($seriesinfo);
-					if($uid != USERUID) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_EDIT_SERIES, USERPENNAME, USERUID, $title, $seriesid))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'ED', " . time() . ")");
+					if($uid != USERUID) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_EDIT_SERIES, USERPENNAME, USERUID, $title, $seriesid))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'ED', " . time() . ")");
 				}
 				$output = write_message(_ACTIONSUCCESSFUL."<br />"._BACK2ACCT);
 			}
@@ -376,3 +376,4 @@
 $tpl->assign("output", $output);
 $tpl->printToScreen( );
 ?>
+

--- a/stories.php
+++ b/stories.php
@@ -281,6 +281,7 @@
 			}
 			$codequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'addstory'");
 			while($code = dbassoc($codequery)) {
+				
 				eval($code['code_text']);
 			}
 		}
@@ -412,7 +413,7 @@
 
 	$submit = isset($_POST['submit']) ? $_POST['submit'] : false;
 	if(!$submit) $submit = _PREVIEW;
-	$output .= "<div class=\"tblborder\" style=\"width: 500px; padding: 10px; margin: 1em auto;\">
+	$output .= "<div class=\"tblborder\" style=\" padding: 10px; margin: 1em auto;\">
 	<form METHOD=\"POST\" name=\"form\" enctype=\"multipart/form-data\" action='stories.php?action=$action".($newchapter ? "&amp;sid=$sid&amp;inorder=$inorder" : "").($admin == 1 ? "&amp;admin=1&amp;uid=$uid" : "")."'>";
 	if(!$newchapter) $output .= storyform($stories, $submit);
 	$output .= chapterform($inorder, $notes, $endnotes, $storytext, $chaptertitle, $uid);
@@ -558,7 +559,7 @@
 			if($admin && $logging && USERUID != $uid) {
 				$storyinfo = dbquery("SELECT story.title, story.sid, chapter.uid, chapter.inorder, "._PENNAMEFIELD." as penname FROM ".TABLEPREFIX."fanfiction_stories as story, ".TABLEPREFIX."fanfiction_chapters as chapter, "._AUTHORTABLE." WHERE "._UIDFIELD." = chapter.uid AND story.sid = chapter.sid AND chapter.chapid = $chapid");
 				list($title, $sid, $chapuid, $inorder, $chappenname) = dbrow($storyinfo);
-				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_EDIT_CHAPTER, USERPENNAME, USERUID, $title, $sid, $chappenname, $chapuid, $inorder))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'ED', " . time() . ")");
+				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_EDIT_CHAPTER, USERPENNAME, USERUID, $title, $sid, $chappenname, $chapuid, $inorder))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'ED', " . time() . ")");
 			}
 			unset($_POST['submit']);
 			$output = write_message(_STORYUPDATED).editstory($sid);
@@ -568,7 +569,7 @@
 			exit( );
 		}
 	}
-	$output .= "<div class=\"tblborder\" style=\"width: 550px; margin: 0 auto; padding: 5px;\">
+	$output .= "<div class=\"tblborder\" style=\"margin: 0 auto; padding: 5px;\">
 		<form METHOD=\"POST\"  enctype=\"multipart/form-data\" name=\"form\" action=\"stories.php?action=editchapter&amp;chapid=$chapid".($admin ? "&amp;admin=1" : "")."\">";
 	if(!isset($_POST['submit']) || $_POST['submit'] != _PREVIEW) {
 		$storyquery = dbquery("SELECT title, inorder, notes, endnotes, uid, storytext, sid FROM ".TABLEPREFIX."fanfiction_chapters WHERE chapid = '$chapid' LIMIT 1");
@@ -698,7 +699,7 @@
 						list($oldpenname) = dbrow($authorquery);
 						$author2query = dbquery("SELECT "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." WHERE "._UIDFIELD." = '$uid' LIMIT 1");
 						list($newpenname) = dbrow($author2query);
-						dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_EDIT_AUTHOR, USERPENNAME, USERUID, $title, $sid, $newpenname, $uid, $oldpenname, $olduid))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'ED', " . time() . ")");
+						dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_EDIT_AUTHOR, USERPENNAME, USERUID, $title, $sid, $newpenname, $uid, $oldpenname, $olduid))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'ED', " . time() . ")");
 					}
 				}
 
@@ -812,14 +813,16 @@
 				}		
 			}
 			$codequery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_codeblocks WHERE code_type = 'editstory'");
+
 			while($code = dbassoc($codequery)) {
+			 
 				eval($code['code_text']);
 			}
 			if($logging && $admin) {
 				if(USERUID != $uid) { // If you're editing your own story, don't log it.
 					$authorquery = dbquery("SELECT "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." WHERE "._UIDFIELD." = '$uid' LIMIT 1");
 					list($penname) = dbrow($authorquery);
-					dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_EDIT, USERPENNAME, USERUID, $title, $sid, $penname, $uid))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'ED', " . time() . ")");
+					dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_EDIT, USERPENNAME, USERUID, $title, $sid, $penname, $uid))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'ED', " . time() . ")");
 				}
 			}
 			$output .= write_message(_STORYUPDATED."  ".($admin ? _BACK2ADMIN : _BACK2ACCT));
@@ -831,7 +834,7 @@
 	}
 	$query = dbquery("SELECT DATE_FORMAT(FROM_UNIXTIME(date), '$dateformat') as date, wordcount, uid FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '$sid' LIMIT 1");
 	list($published, $wordcount, $storyuid) = dbrow($query);
-	$formbegin = "<div class=\"tblborder\" style=\"margin: 10px auto; width: 550px; padding: 10px;\">
+	$formbegin = "<div class=\"tblborder\" style=\"margin: 10px auto; padding: 10px;\">
 		<form METHOD=\"POST\" name=\"form\" action=\"stories.php?action=editstory".($admin ? "&amp;admin=1" : "")."&amp;sid=$sid\">";
 
 	if(isset($_POST['submit']) && $_POST['submit'] != _PREVIEW) {
@@ -875,7 +878,7 @@
 	$chapquery = dbquery("SELECT chapid, title, inorder, rating, reviews, validated, uid FROM ".TABLEPREFIX."fanfiction_chapters WHERE sid = '$sid' ORDER BY inorder");
 	$chapters = dbnumrows($chapquery);
 	$output .= "<p><input type=\"submit\" class=\"button\" value=\"$submit\" name=\"submit\">&nbsp; <input type=\"submit\" class=\"button\" value=\""._ADDSTORY."\" name=\"submit\"></p></form></div>";
-	$output .= "<br><table class=\"tblborder\" style=\"margin: 0 auto; width: 500px;\"><tr><th>"._CHAPTER."</th>".($chapters > 1 ? "<th>"._MOVE."</th>" : "")."<th>"._OPTIONS."</th></tr>";
+	$output .= "<br><table class=\"tblborder\" style=\"margin: 0 auto;  \"><tr><th>"._CHAPTER."</th>".($chapters > 1 ? "<th>"._MOVE."</th>" : "")."<th>"._OPTIONS."</th></tr>";
 			while($chapter = dbassoc($chapquery)) {
 				$output .="<tr><td class=\"tblborder\"><a href=\"viewstory.php?sid=$sid&amp;chapter=".$chapter['inorder']."\">".$chapter['title']."</a></td>";
 				if($chapters > 1) $output .= "<td align=\"center\" class=\"tblborder\">".($chapter['inorder'] == 1 ? "" : "<a href=\"stories.php?action=viewstories&amp;go=up&amp;sid=$sid&amp;chapid=".$chapter['chapid']."&amp;inorder=".$chapter['inorder']."\">$up</a>").
@@ -931,7 +934,7 @@
 			if($logging && $admin) {
 				$authorquery = dbquery("SELECT "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." WHERE "._UIDFIELD." = '$uid' LIMIT 1");
 				list($penname) = dbrow($authorquery);
-				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_DEL_CHAPTER, USERPENNAME, USERUID, $story['title'], $sid, $penname, $uid, $inorder))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'DL', " . time() . ")");
+				dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_ADMIN_DEL_CHAPTER, USERPENNAME, USERUID, $story['title'], $sid, $penname, $uid, $inorder))."', '".USERUID. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'DL', " . time() . ")");
 			}
 			return "<center>"._ACTIONSUCCESSFUL."</center>".editstory( $sid );
 		}
@@ -983,3 +986,4 @@
 	$tpl->printToScreen();
 	dbclose( );
 ?>
+

--- a/tinymce4/init.php
+++ b/tinymce4/init.php
@@ -1,5 +1,12 @@
 <?php
-
+$image_list_path = STORIESPATH . "/" . USERUID . "/images/imagelist.js";
+$image_list_exists = file_exists($image_list_path); 
+ 
+if (USERUID && $image_list_exists)
+{
+echo "
+<script src='".STORIESPATH . "/" . USERUID . "/images/imagelist.js"."'></script>";
+} 
 echo "
 	<script language=\"javascript\" type=\"text/javascript\"><!--";
 	$tinylanguage = $language;
@@ -19,30 +26,28 @@
   		menubar: false,
 		language: '$tinylanguage',
   		theme: 'modern',
+		invalid_styles: 'color,font-size,margin,line-height,font-family,margin-top,margin-bottom',
+		plugins: 'wordcount emoticons fullscreen anchor code hr image link paste ',
 		skin: 'lightgray',
 		min_height: 200,
-		plugins: [
-		    'autolink lists link image charmap paste preview hr anchor pagebreak',
-		    'searchreplace wordcount visualblocks visualchars code fullscreen',
-		    'insertdatetime media nonbreaking save table contextmenu directionality',
-		    'emoticons template textcolor colorpicker textpattern imagetools toc textcolor table'
-		],
+	    browser_spellcheck: true,
+		relative_urls: false,
+		remove_script_host: false,
+    	convert_urls: true,
 		paste_word_valid_elements: 'b,strong,i,em,h1,h2,u,p,ol,ul,li,a[href],span,color,font-size,font-color,font-family,mark,table,tr,td',
-		paste_retain_style_properties : 'all',
-		paste_strip_class_attributes: 'none',
-		toolbar1: 'undo redo | insert styleselect | bold italic underline strikethrough | link image | alignleft aligncenter alignright alignjustify code pastetext',
-		toolbar2: 'preview | bullist numlist | forecolor backcolor emoticons | fontselect |  fontsizeselect wordcount', 
-		image_advtab: true,
-		templates: [
-		    { title: 'Test template 1', content: 'Test 1' },
-		    { title: 'Test template 2', content: 'Test 2' }
-		],
-		content_css: [
-		    '//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
-		    '//www.tinymce.com/css/codepen.min.css'
-		],";
-		if(USERUID) 
-			echo "		external_image_list_url : '".STORIESPATH."/".USERUID."/images/imagelist.js',";
+		toolbar1: 'bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist | undo redo | fullscreen code | link unlink | emoticons image anchor hr ',	image_advtab: true,
+     	paste_word_valid_elements: 'b,strong,i,em,p,span,u,strike,br',
+    	paste_retain_style_properties: 'text-decoration,text-align',
+	    menu: {
+			file: { title: 'File', items: 'newdocument' },
+			edit: { title: 'Edit', items: 'undo redo | cut copy paste pastetext | selectall' },
+			insert: { title: 'Insert', items: 'link media | template hr' },
+			view: { title: 'View', items: 'visualaid' },
+			table: { title: 'Table', items: 'inserttable tableprops deletetable | cell row column' },
+			tools: { title: 'Tools', items: '' }
+    	},";
+		if (USERUID && $image_list_exists)
+			echo "	image_list: tinyMCE4ImageList ,";
 		echo "
 		theme_modern_resizing: true,".($current == "adminarea" ? "\n\t\tentity_encoding: 'raw'" : "\n\t\tinvalid_elements: 'script,object,applet,iframe'")."
    });

--- a/tinymce4/js/tinymce/plugins/image/plugin.min.js
+++ b/tinymce4/js/tinymce/plugins/image/plugin.min.js
@@ -1,1 +1,299 @@
-tinymce.PluginManager.add("image",function(e){function t(e,t){function n(e,n){r.parentNode&&r.parentNode.removeChild(r),t({width:e,height:n})}var r=document.createElement("img");r.onload=function(){n(Math.max(r.width,r.clientWidth),Math.max(r.height,r.clientHeight))},r.onerror=function(){n()};var i=r.style;i.visibility="hidden",i.position="fixed",i.bottom=i.left=0,i.width=i.height="auto",document.body.appendChild(r),r.src=e}function n(e,t,n){function r(e,n){return n=n||[],tinymce.each(e,function(e){var i={text:e.text||e.title};e.menu?i.menu=r(e.menu):(i.value=e.value,t(i)),n.push(i)}),n}return r(e,n||[])}function r(t){return function(){var n=e.settings.image_list;"string"==typeof n?tinymce.util.XHR.send({url:n,success:function(e){t(tinymce.util.JSON.parse(e))}}):"function"==typeof n?n(t):t(n)}}function i(r){function i(){var e,t,n,r;e=f.find("#width")[0],t=f.find("#height")[0],e&&t&&(n=e.value(),r=t.value(),f.find("#constrain")[0].checked()&&h&&g&&n&&r&&(h!=n?(r=Math.round(n/h*r),isNaN(r)||t.value(r)):(n=Math.round(r/g*n),isNaN(n)||e.value(n))),h=n,g=r)}function o(){function t(t){function n(){t.onload=t.onerror=null,e.selection&&(e.selection.select(t),e.nodeChanged())}t.onload=function(){y.width||y.height||!x||C.setAttribs(t,{width:t.clientWidth,height:t.clientHeight}),n()},t.onerror=n}var n,r;u(),i(),y=tinymce.extend(y,f.toJSON()),y.alt||(y.alt=""),y.title||(y.title=""),""===y.width&&(y.width=null),""===y.height&&(y.height=null),y.style||(y.style=null),y={src:y.src,alt:y.alt,title:y.title,width:y.width,height:y.height,style:y.style,caption:y.caption,"class":y["class"]},e.undoManager.transact(function(){function i(t){return e.schema.getTextBlockElements()[t.nodeName]}if(!y.src)return void(p&&(C.remove(p),e.focus(),e.nodeChanged()));if(""===y.title&&(y.title=null),p?C.setAttribs(p,y):(y.id="__mcenew",e.focus(),e.selection.setContent(C.createHTML("img",y)),p=C.get("__mcenew"),C.setAttrib(p,"id",null)),e.editorUpload.uploadImagesAuto(),y.caption===!1&&C.is(p.parentNode,"figure.image")&&(n=p.parentNode,C.insertAfter(p,n),C.remove(n)),y.caption!==!0)t(p);else if(!C.is(p.parentNode,"figure.image")){r=p,p=p.cloneNode(!0),n=C.create("figure",{"class":"image"}),n.appendChild(p),n.appendChild(C.create("figcaption",{contentEditable:!0},"Caption")),n.contentEditable=!1;var o=C.getParent(r,i);o?C.split(o,r,n):C.replace(n,r),e.selection.select(n)}})}function a(e){return e&&(e=e.replace(/px$/,"")),e}function s(n){var r,i,o,a=n.meta||{};v&&v.value(e.convertURL(this.value(),"src")),tinymce.each(a,function(e,t){f.find("#"+t).value(e)}),a.width||a.height||(r=e.convertURL(this.value(),"src"),i=e.settings.image_prepend_url,o=new RegExp("^(?:[a-z]+:)?//","i"),i&&!o.test(r)&&r.substring(0,i.length)!==i&&(r=i+r),this.value(r),t(e.documentBaseURI.toAbsolute(this.value()),function(e){e.width&&e.height&&x&&(h=e.width,g=e.height,f.find("#width").value(h),f.find("#height").value(g))}))}function l(e){e.meta=f.toJSON()}function c(e){if(e.margin){var t=e.margin.split(" ");switch(t.length){case 1:e["margin-top"]=e["margin-top"]||t[0],e["margin-right"]=e["margin-right"]||t[0],e["margin-bottom"]=e["margin-bottom"]||t[0],e["margin-left"]=e["margin-left"]||t[0];break;case 2:e["margin-top"]=e["margin-top"]||t[0],e["margin-right"]=e["margin-right"]||t[1],e["margin-bottom"]=e["margin-bottom"]||t[0],e["margin-left"]=e["margin-left"]||t[1];break;case 3:e["margin-top"]=e["margin-top"]||t[0],e["margin-right"]=e["margin-right"]||t[1],e["margin-bottom"]=e["margin-bottom"]||t[2],e["margin-left"]=e["margin-left"]||t[1];break;case 4:e["margin-top"]=e["margin-top"]||t[0],e["margin-right"]=e["margin-right"]||t[1],e["margin-bottom"]=e["margin-bottom"]||t[2],e["margin-left"]=e["margin-left"]||t[3]}delete e.margin}return e}function u(){function t(e){return e.length>0&&/^[0-9]+$/.test(e)&&(e+="px"),e}if(e.settings.image_advtab){var n=f.toJSON(),r=C.parseStyle(n.style);r=c(r),n.vspace&&(r["margin-top"]=r["margin-bottom"]=t(n.vspace)),n.hspace&&(r["margin-left"]=r["margin-right"]=t(n.hspace)),n.border&&(r["border-width"]=t(n.border)),f.find("#style").value(C.serializeStyle(C.parseStyle(C.serializeStyle(r))))}}function d(){if(e.settings.image_advtab){var t=f.toJSON(),n=C.parseStyle(t.style);f.find("#vspace").value(""),f.find("#hspace").value(""),n=c(n),(n["margin-top"]&&n["margin-bottom"]||n["margin-right"]&&n["margin-left"])&&(n["margin-top"]===n["margin-bottom"]?f.find("#vspace").value(a(n["margin-top"])):f.find("#vspace").value(""),n["margin-right"]===n["margin-left"]?f.find("#hspace").value(a(n["margin-right"])):f.find("#hspace").value("")),n["border-width"]&&f.find("#border").value(a(n["border-width"])),f.find("#style").value(C.serializeStyle(C.parseStyle(C.serializeStyle(n))))}}var f,p,m,h,g,v,b,y={},C=e.dom,x=e.settings.image_dimensions!==!1;p=e.selection.getNode(),m=C.getParent(p,"figure.image"),m&&(p=C.select("img",m)[0]),p&&("IMG"!=p.nodeName||p.getAttribute("data-mce-object")||p.getAttribute("data-mce-placeholder"))&&(p=null),p&&(h=C.getAttrib(p,"width"),g=C.getAttrib(p,"height"),y={src:C.getAttrib(p,"src"),alt:C.getAttrib(p,"alt"),title:C.getAttrib(p,"title"),"class":C.getAttrib(p,"class"),width:h,height:g,caption:!!m}),r&&(v={type:"listbox",label:"Image list",values:n(r,function(t){t.value=e.convertURL(t.value||t.url,"src")},[{text:"None",value:""}]),value:y.src&&e.convertURL(y.src,"src"),onselect:function(e){var t=f.find("#alt");(!t.value()||e.lastControl&&t.value()==e.lastControl.text())&&t.value(e.control.text()),f.find("#src").value(e.control.value()).fire("change")},onPostRender:function(){v=this}}),e.settings.image_class_list&&(b={name:"class",type:"listbox",label:"Class",values:n(e.settings.image_class_list,function(t){t.value&&(t.textStyle=function(){return e.formatter.getCssText({inline:"img",classes:[t.value]})})})});var w=[{name:"src",type:"filepicker",filetype:"image",label:"Source",autofocus:!0,onchange:s,onbeforecall:l},v];e.settings.image_description!==!1&&w.push({name:"alt",type:"textbox",label:"Image description"}),e.settings.image_title&&w.push({name:"title",type:"textbox",label:"Image Title"}),x&&w.push({type:"container",label:"Dimensions",layout:"flex",direction:"row",align:"center",spacing:5,items:[{name:"width",type:"textbox",maxLength:5,size:3,onchange:i,ariaLabel:"Width"},{type:"label",text:"x"},{name:"height",type:"textbox",maxLength:5,size:3,onchange:i,ariaLabel:"Height"},{name:"constrain",type:"checkbox",checked:!0,text:"Constrain proportions"}]}),w.push(b),e.settings.image_caption&&tinymce.Env.ceFalse&&w.push({name:"caption",type:"checkbox",label:"Caption"}),e.settings.image_advtab?(p&&(p.style.marginLeft&&p.style.marginRight&&p.style.marginLeft===p.style.marginRight&&(y.hspace=a(p.style.marginLeft)),p.style.marginTop&&p.style.marginBottom&&p.style.marginTop===p.style.marginBottom&&(y.vspace=a(p.style.marginTop)),p.style.borderWidth&&(y.border=a(p.style.borderWidth)),y.style=e.dom.serializeStyle(e.dom.parseStyle(e.dom.getAttrib(p,"style")))),f=e.windowManager.open({title:"Insert/edit image",data:y,bodyType:"tabpanel",body:[{title:"General",type:"form",items:w},{title:"Advanced",type:"form",pack:"start",items:[{label:"Style",name:"style",type:"textbox",onchange:d},{type:"form",layout:"grid",packV:"start",columns:2,padding:0,alignH:["left","right"],defaults:{type:"textbox",maxWidth:50,onchange:u},items:[{label:"Vertical space",name:"vspace"},{label:"Horizontal space",name:"hspace"},{label:"Border",name:"border"}]}]}],onSubmit:o})):f=e.windowManager.open({title:"Insert/edit image",data:y,body:w,onSubmit:o})}e.on("preInit",function(){function t(e){var t=e.attr("class");return t&&/\bimage\b/.test(t)}function n(e){return function(n){function r(t){t.attr("contenteditable",e?"true":null)}for(var i,o=n.length;o--;)i=n[o],t(i)&&(i.attr("contenteditable",e?"false":null),tinymce.each(i.getAll("figcaption"),r))}}e.parser.addNodeFilter("figure",n(!0)),e.serializer.addNodeFilter("figure",n(!1))}),e.addButton("image",{icon:"image",tooltip:"Insert/edit image",onclick:r(i),stateSelector:"img:not([data-mce-object],[data-mce-placeholder]),figure.image"}),e.addMenuItem("image",{icon:"image",text:"Image",onclick:r(i),context:"insert",prependToContext:!0}),e.addCommand("mceImage",r(i))});
+tinymce.PluginManager.add("image", function (e) {
+    function t(e, t) {
+        function n(e, n) {
+            r.parentNode && r.parentNode.removeChild(r), t({ width: e, height: n });
+        }
+        var r = document.createElement("img");
+        (r.onload = function () {
+            n(Math.max(r.width, r.clientWidth), Math.max(r.height, r.clientHeight));
+        }),
+            (r.onerror = function () {
+                n();
+            });
+        var i = r.style;
+        (i.visibility = "hidden"), (i.position = "fixed"), (i.bottom = i.left = 0), (i.width = i.height = "auto"), document.body.appendChild(r), (r.src = e);
+    }
+    function n(e, t, n) {
+        function r(e, n) {
+            return (
+                (n = n || []),
+                tinymce.each(e, function (e) {
+                    var i = { text: e.text || e.title };
+                    e.menu ? (i.menu = r(e.menu)) : ((i.value = e.value), t(i)), n.push(i);
+                }),
+                n
+            );
+        }
+        return r(e, n || []);
+    }
+    function r(t) {
+        return function () {
+            var n = e.settings.image_list;
+            "string" == typeof n
+                ? tinymce.util.XHR.send({
+                    url: n,
+                    success: function (e) {
+                        t(tinymce.util.JSON.parse(e));
+                    },
+                })
+                : "function" == typeof n
+                    ? n(t)
+                    : t(n);
+        };
+    }
+    function i(r) {
+        function i() {
+            var e, t, n, r;
+            (e = f.find("#width")[0]),
+                (t = f.find("#height")[0]),
+                e &&
+                t &&
+                ((n = e.value()),
+                    (r = t.value()),
+                    f.find("#constrain")[0].checked() && h && g && n && r && (h != n ? ((r = Math.round((n / h) * r)), isNaN(r) || t.value(r)) : ((n = Math.round((r / g) * n)), isNaN(n) || e.value(n))),
+                    (h = n),
+                    (g = r));
+        }
+        function o() {
+            function t(t) {
+                function n() {
+                    (t.onload = t.onerror = null), e.selection && (e.selection.select(t), e.nodeChanged());
+                }
+                (t.onload = function () {
+                    y.width || y.height || !x || C.setAttribs(t, { width: t.clientWidth, height: t.clientHeight }), n();
+                }),
+                    (t.onerror = n);
+            }
+            var n, r;
+            u(),
+                i(),
+                (y = tinymce.extend(y, f.toJSON())),
+                y.alt || (y.alt = ""),
+                y.title || (y.title = ""),
+                "" === y.width && (y.width = null),
+                "" === y.height && (y.height = null),
+                y.style || (y.style = null),
+                (y = { src: y.src, alt: y.alt, title: y.title, width: y.width, height: y.height, style: y.style, caption: y.caption, class: y["class"] }),
+                e.undoManager.transact(function () {
+                    function i(t) {
+                        return e.schema.getTextBlockElements()[t.nodeName];
+                    }
+                    if (!y.src) return void (p && (C.remove(p), e.focus(), e.nodeChanged()));
+                    if (
+                        ("" === y.title && (y.title = null),
+                            p ? C.setAttribs(p, y) : ((y.id = "__mcenew"), e.focus(), e.selection.setContent(C.createHTML("img", y)), (p = C.get("__mcenew")), C.setAttrib(p, "id", null)),
+                            e.editorUpload.uploadImagesAuto(),
+                            y.caption === !1 && C.is(p.parentNode, "figure.image") && ((n = p.parentNode), C.insertAfter(p, n), C.remove(n)),
+                            y.caption !== !0)
+                    )
+                        t(p);
+                    else if (!C.is(p.parentNode, "figure.image")) {
+                        (r = p), (p = p.cloneNode(!0)), (n = C.create("figure", { class: "image" })), n.appendChild(p), n.appendChild(C.create("figcaption", { contentEditable: !0 }, "Caption")), (n.contentEditable = !1);
+                        var o = C.getParent(r, i);
+                        o ? C.split(o, r, n) : C.replace(n, r), e.selection.select(n);
+                    }
+                });
+        }
+        function a(e) {
+            return e && (e = e.replace(/px$/, "")), e;
+        }
+        function s(n) {
+            var r,
+                i,
+                o,
+                a = n.meta || {};
+            v && v.value(e.convertURL(this.value(), "src")),
+                tinymce.each(a, function (e, t) {
+                    f.find("#" + t).value(e);
+                }),
+                a.width ||
+                a.height ||
+                ((r = e.convertURL(this.value(), "src")),
+                    (i = e.settings.image_prepend_url),
+                    (o = new RegExp("^(?:[a-z]+:)?//", "i")),
+                    i && !o.test(r) && r.substring(0, i.length) !== i && (r = i + r),
+                    this.value(r),
+                    t(e.documentBaseURI.toAbsolute(this.value()), function (e) {
+                        e.width && e.height && x && ((h = e.width), (g = e.height), f.find("#width").value(h), f.find("#height").value(g));
+                    }));
+        }
+        function l(e) {
+            e.meta = f.toJSON();
+        }
+        function c(e) {
+            if (e.margin) {
+                var t = e.margin.split(" ");
+                switch (t.length) {
+                    case 1:
+                        (e["margin-top"] = e["margin-top"] || t[0]), (e["margin-right"] = e["margin-right"] || t[0]), (e["margin-bottom"] = e["margin-bottom"] || t[0]), (e["margin-left"] = e["margin-left"] || t[0]);
+                        break;
+                    case 2:
+                        (e["margin-top"] = e["margin-top"] || t[0]), (e["margin-right"] = e["margin-right"] || t[1]), (e["margin-bottom"] = e["margin-bottom"] || t[0]), (e["margin-left"] = e["margin-left"] || t[1]);
+                        break;
+                    case 3:
+                        (e["margin-top"] = e["margin-top"] || t[0]), (e["margin-right"] = e["margin-right"] || t[1]), (e["margin-bottom"] = e["margin-bottom"] || t[2]), (e["margin-left"] = e["margin-left"] || t[1]);
+                        break;
+                    case 4:
+                        (e["margin-top"] = e["margin-top"] || t[0]), (e["margin-right"] = e["margin-right"] || t[1]), (e["margin-bottom"] = e["margin-bottom"] || t[2]), (e["margin-left"] = e["margin-left"] || t[3]);
+                }
+                delete e.margin;
+            }
+            return e;
+        }
+        function u() {
+            function t(e) {
+                return e.length > 0 && /^[0-9]+$/.test(e) && (e += "px"), e;
+            }
+            if (e.settings.image_advtab) {
+                var n = f.toJSON(),
+                    r = C.parseStyle(n.style);
+                (r = c(r)),
+                    n.vspace && (r["margin-top"] = r["margin-bottom"] = t(n.vspace)),
+                    n.hspace && (r["margin-left"] = r["margin-right"] = t(n.hspace)),
+                    n.border && (r["border-width"] = t(n.border)),
+                    f.find("#style").value(C.serializeStyle(C.parseStyle(C.serializeStyle(r))));
+            }
+        }
+        function d() {
+            if (e.settings.image_advtab) {
+                var t = f.toJSON(),
+                    n = C.parseStyle(t.style);
+                f.find("#vspace").value(""),
+                    f.find("#hspace").value(""),
+                    (n = c(n)),
+                    ((n["margin-top"] && n["margin-bottom"]) || (n["margin-right"] && n["margin-left"])) &&
+                    (n["margin-top"] === n["margin-bottom"] ? f.find("#vspace").value(a(n["margin-top"])) : f.find("#vspace").value(""),
+                        n["margin-right"] === n["margin-left"] ? f.find("#hspace").value(a(n["margin-right"])) : f.find("#hspace").value("")),
+                    n["border-width"] && f.find("#border").value(a(n["border-width"])),
+                    f.find("#style").value(C.serializeStyle(C.parseStyle(C.serializeStyle(n))));
+            }
+        }
+        var f,
+            p,
+            m,
+            h,
+            g,
+            v,
+            b,
+            y = {},
+            C = e.dom,
+            x = e.settings.image_dimensions !== !1;
+        (p = e.selection.getNode()),
+            (m = C.getParent(p, "figure.image")),
+            m && (p = C.select("img", m)[0]),
+            p && ("IMG" != p.nodeName || p.getAttribute("data-mce-object") || p.getAttribute("data-mce-placeholder")) && (p = null),
+            p &&
+            ((h = C.getAttrib(p, "width")),
+                (g = C.getAttrib(p, "height")),
+                (y = { src: C.getAttrib(p, "src"), alt: C.getAttrib(p, "alt"), title: C.getAttrib(p, "title"), class: C.getAttrib(p, "class"), width: h, height: g, caption: !!m })),
+            r &&
+            (v = {
+                type: "listbox",
+                label: "Image list",
+                values: n(
+                    r,
+                    function (t) {
+                        t.value = e.convertURL(t.value || t.url, "src");
+                    },
+                    [{ text: "None", value: "" }]
+                ),
+                value: y.src && e.convertURL(y.src, "src"),
+                onselect: function (e) {
+                    var t = f.find("#alt");
+                    (!t.value() || (e.lastControl && t.value() == e.lastControl.text())) && t.value(e.control.text()), f.find("#src").value(e.control.value()).fire("change");
+                },
+                onPostRender: function () {
+                    v = this;
+                },
+            }),
+            e.settings.image_class_list &&
+            (b = {
+                name: "class",
+                type: "listbox",
+                label: "Class",
+                values: n(e.settings.image_class_list, function (t) {
+                    t.value &&
+                        (t.textStyle = function () {
+                            return e.formatter.getCssText({ inline: "img", classes: [t.value] });
+                        });
+                }),
+            });
+        var w = [{ name: "src", type: "filepicker", filetype: "image", label: "Source", autofocus: !0, onchange: s, onbeforecall: l }, v];
+        e.settings.image_description !== !1 && w.push({ name: "alt", type: "textbox", label: "Image description" }),
+            e.settings.image_title && w.push({ name: "title", type: "textbox", label: "Image Title" }),
+            x &&
+            w.push({
+                type: "container",
+                label: "Dimensions",
+                layout: "flex",
+                direction: "row",
+                align: "center",
+                spacing: 5,
+                items: [
+                    { name: "width", type: "textbox", maxLength: 5, size: 3, onchange: i, ariaLabel: "Width" },
+                    { type: "label", text: "x" },
+                    { name: "height", type: "textbox", maxLength: 5, size: 3, onchange: i, ariaLabel: "Height" },
+                    { name: "constrain", type: "checkbox", checked: !0, text: "Constrain proportions" },
+                ],
+            }),
+            w.push(b),
+            e.settings.image_caption && tinymce.Env.ceFalse && w.push({ name: "caption", type: "checkbox", label: "Caption" }),
+            e.settings.image_advtab
+                ? (p &&
+                    (p.style.marginLeft && p.style.marginRight && p.style.marginLeft === p.style.marginRight && (y.hspace = a(p.style.marginLeft)),
+                        p.style.marginTop && p.style.marginBottom && p.style.marginTop === p.style.marginBottom && (y.vspace = a(p.style.marginTop)),
+                        p.style.borderWidth && (y.border = a(p.style.borderWidth)),
+                        (y.style = e.dom.serializeStyle(e.dom.parseStyle(e.dom.getAttrib(p, "style"))))),
+                    (f = e.windowManager.open({
+                        title: "Insert/edit image",
+                        data: y,
+                        bodyType: "tabpanel",
+                        body: [
+                            { title: "General", type: "form", items: w },
+                            {
+                                title: "Advanced",
+                                type: "form",
+                                pack: "start",
+                                items: [
+                                    { label: "Style", name: "style", type: "textbox", onchange: d },
+                                    {
+                                        type: "form",
+                                        layout: "grid",
+                                        packV: "start",
+                                        columns: 2,
+                                        padding: 0,
+                                        alignH: ["left", "right"],
+                                        defaults: { type: "textbox", maxWidth: 50, onchange: u },
+                                        items: [
+                                            { label: "Vertical space", name: "vspace" },
+                                            { label: "Horizontal space", name: "hspace" },
+                                            { label: "Border", name: "border" },
+                                        ],
+                                    },
+                                ],
+                            },
+                        ],
+                        onSubmit: o,
+                    })))
+                : (f = e.windowManager.open({ title: "Insert/edit image", data: y, body: w, onSubmit: o }));
+    }
+    e.on("preInit", function () {
+        function t(e) {
+            var t = e.attr("class");
+            return t && /\bimage\b/.test(t);
+        }
+        function n(e) {
+            return function (n) {
+                function r(t) {
+                    t.attr("contenteditable", e ? "true" : null);
+                }
+                for (var i, o = n.length; o--;) (i = n[o]), t(i) && (i.attr("contenteditable", e ? "false" : null), tinymce.each(i.getAll("figcaption"), r));
+            };
+        }
+        e.parser.addNodeFilter("figure", n(!0)), e.serializer.addNodeFilter("figure", n(!1));
+    }),
+        e.addButton("image", { icon: "image", tooltip: "Insert/edit image", onclick: r(i), stateSelector: "img:not([data-mce-object],[data-mce-placeholder]),figure.image" }),
+        e.addMenuItem("image", { icon: "image", text: "Image", onclick: r(i), context: "insert", prependToContext: !0 }),
+        e.addCommand("mceImage", r(i));
+});
+

file:a/update.php -> file:b/update.php
--- a/update.php
+++ b/update.php
@@ -47,61 +47,93 @@
 	exit();
 }
 $oldVersion = explode(".", $settings['version']);
-
+ 
 if ($oldVersion[0] <= 3 && $oldVersion[1] <= 5 && $oldVersion[2] < 5)
 {
 	header("Location: update355.php");
 	exit();
 }
-
-$fanfiction_poll_exists = 0;  /* poll tables maybe be not installed */
-$fanfiction_poll_table = TABLEPREFIX . "fanfiction_poll";
-$fanfiction_poll_exists =  dbassoc(dbquery("
-			SELECT *
-			FROM information_schema.tables
-			WHERE table_schema = '{$dbname}'
-				AND table_name = '{$fanfiction_poll_table}'
-			;"));
-
+$set_355 = false;
+ 
 $set_355 = do_version_check_355();
+ 
 if($set_355) {
+	$output .= write_message("Table <b>" . $set_355 . "</b> needs a update.");
+
 	dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '3.5.5' WHERE sitekey = '" . SITEKEY . "'");
+
 	$settings['version'] = '3.5.5';
 }
+else {
+	$set_356 = do_version_check_356();
+ 
+	if ($set_356)
+	{
+		$output .= write_message("Table <b>" . $set_356 . "</b> needs a update.");
+		dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '3.5.6' WHERE sitekey = '" . SITEKEY . "'");
+		$settings['version'] = '3.5.6';
+	}
+}
+
 $oldVersion = explode(".", $settings['version']);
-
+ 
 $confirm = isset($_GET['confirm']) ? $_GET['confirm'] : false;
-$oldconfirm = isset($_GET['oldconfirm']) ? $_GET['oldconfirm'] : false;
-
+ 
 if ($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 3))
 {
 	write_message("This version is working only for 3.5.5 database. If you have only database, there is way how to do it.");
 	exit;
 }
-
-
-
+ 
+ 
 if ($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 6))  //3.5.5
 {
 	if ($confirm == "yes")
 	{
 		if ($oldVersion[0] == 3 &&  $oldVersion[1] == 5 && $oldVersion[2] < 6)
 		{
-			/****************************************************************************************************************/
-			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_authors LIKE 'date'"));
-			if ($tmp['Type'] == "datetime")
-			{ 
-				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_authors LIKE 'date_tmp'"));
-				if (!$updated)
-				{
-					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_authors` ADD `date_tmp` int(10) unsigned NOT NULL default '0' ");
-				}
-
-				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_authors` SET `date_tmp` = UNIX_TIMESTAMP( `date` )");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_authors` CHANGE `date` `date` INT NOT NULL");
-				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_authors` set date = date_tmp");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_authors` DROP `date_tmp`");
-			}
+
+			// List of DB tables (key) and field (value) which need changing to accommodate datetime field
+			$date_upgrade = array(
+				'fanfiction_authors' => 'date',
+				'fanfiction_comments'  => 'time',
+				'fanfiction_reviews' => 'date',
+				'fanfiction_stories'  => 'date',
+				'fanfiction_stories' => 'updated',
+				'fanfiction_news' => 'time',
+				'fanfiction_poll' => 'poll_start',
+				'fanfiction_poll' => 'poll_end',
+			);
+
+			// Tables where IP address field needs updating to accommodate IPV6
+			// Set to varchar(45) - just in case something uses the IPV4 subnet (see http://en.wikipedia.org/wiki/IPV6#Notation)
+			foreach ($date_upgrade as $t => $f)
+			{
+				if (isTable($t))
+				{
+
+					// Check for table - might add some core plugin tables in here
+					if ($field_info =  dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . $t . " LIKE '{$f}'")))
+					{ 
+						if (strtolower($field_info['Type']) == 'datetime')
+						{
+
+							$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . $t . " LIKE '{$f}_tmp'"));
+							if (!$updated)
+							{
+								dbquery("ALTER TABLE `" . TABLEPREFIX . $t .  "` ADD `{$f}_tmp` int(10) unsigned NOT NULL default '0' ");
+							}
+
+							dbquery("UPDATE `" . TABLEPREFIX . $t .  "` SET `{$f}_tmp` = UNIX_TIMESTAMP( `{$f}` )");
+							dbquery("ALTER TABLE `" . TABLEPREFIX . $t .  "` CHANGE `{$f}` `{$f}` INT NOT NULL"); 
+							dbquery("UPDATE  `" . TABLEPREFIX . $t .  "` set {$f} = {$f}_tmp");
+							dbquery("ALTER TABLE  `" . TABLEPREFIX . $t .  "` DROP `{$f}_tmp`");
+						}
+					}
+				}
+			}	
+
+ 
 			/****************************************************************************************************************/
 			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_log LIKE 'log_timestamp'"));
 
@@ -118,131 +150,20 @@
 				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_log` set log_timestamp = log_timestamp_tmp");
 				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_log` DROP `log_timestamp_tmp`");
 			}
-			/****************************************************************************************************************/
-			/* fanfiction_comments   `time` datetime NOT NULL default '0000-00-00 00:00:00'  */
-			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_comments LIKE 'time'"));
-			if ($tmp['Type'] == "datetime")
-			{
-				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_comments LIKE 'time_tmp'"));
-				if (!$updated)
-				{
-					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_comments` ADD `time_tmp` int(10) unsigned NOT NULL default '0' ");
-				}
-
-				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_comments` SET `time_tmp` = UNIX_TIMESTAMP( `time` )");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_comments` CHANGE `time` `time` INT NOT NULL");
-				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_comments` set time = time_tmp");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_comments` DROP `time_tmp`");
-			}
-			/****************************************************************************************************************/
-			/* fanfiction_reviews   `date` datetime NOT NULL default '0000-00-00 00:00:00', */
-			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_reviews LIKE 'date'"));
-			if ($tmp['Type'] == "datetime")
-			{
-				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_reviews LIKE 'date_tmp'"));
-				if (!$updated)
-				{
-					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_reviews` ADD `date_tmp` int(10) unsigned NOT NULL default '0' ");
-				}
-
-				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_reviews` SET `date_tmp` = UNIX_TIMESTAMP( `date` )");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_reviews` CHANGE `date` `date` INT NOT NULL");
-				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_reviews` set date = date_tmp");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_reviews` DROP `date_tmp`");
-			}
-			/****************************************************************************************************************/
-			/* fanfiction_stories `date` datetime NOT NULL default '0000-00-00 00:00:00',   */
-			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'date'"));
-			if($tmp['Type'] == "datetime") {
-				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'date_tmp'"));
-				if (!$updated)
-				{
-					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_stories` ADD `date_tmp` int(10) unsigned NOT NULL default '0' ");
-				}
-
-				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_stories` SET `date_tmp` = UNIX_TIMESTAMP( `date` )");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` CHANGE `date` `date` INT NOT NULL");
-				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_stories` set date = date_tmp");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` DROP `date_tmp`");
-			}
-
-			/****************************************************************************************************************/
-			/* fanfiction_stories `updated` datetime NOT NULL default '0000-00-00 00:00:00', */
-			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'updated'"));
-			if ($tmp['Type'] == "datetime")
-			{				
-				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'updated_tmp'"));
-				if (!$updated)
-				{
-					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_stories` ADD `updated_tmp` int(10) unsigned NOT NULL default '0' ");
-				}
-
-				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_stories` SET `updated_tmp` = UNIX_TIMESTAMP( `updated` )");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` CHANGE `updated` `updated` INT NOT NULL");
-				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_stories` set updated = updated_tmp");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_stories` DROP `updated_tmp`");
-			}
-
-			/****************************************************************************************************************/
-			/* fanfiction_news `time` datetime default NULL,  */
-			$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_news LIKE 'time'"));
-			
-			if ($tmp['Type'] == "datetime")
-			{		
-				$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_news LIKE 'time_tmp'"));
-				if (!$updated)
-				{
-					dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_news` ADD `time_tmp` int(10) unsigned NOT NULL default '0' ");
-				}
-
-				dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_news` SET `time_tmp` = UNIX_TIMESTAMP( `time` )");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_news` CHANGE `time` `time` INT NOT NULL");
-				dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_news` set time = time_tmp");
-				dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_news` DROP `time_tmp`");
-			}
-
-			/****************************************************************************************************************/
-			if ($fanfiction_poll_exists)
-			{
-				$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_poll LIKE 'poll_start'"));
-
-				if ($tmp['Type'] == "datetime")
-				{
-					$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_poll LIKE 'poll_start_tmp'"));
-					if (!$updated)
-					{
-						dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_poll` ADD `poll_start_tmp` int(10) unsigned NOT NULL default '0' ");
-					}
-
-					dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_poll` SET `poll_start_tmp` = UNIX_TIMESTAMP( `poll_start` )");
-					dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_poll` CHANGE `poll_start` `poll_start` INT NOT NULL");
-					dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_poll` set poll_start = poll_start_tmp");
-					dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_poll` DROP `poll_start_tmp`");
-				}
-
-				$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_poll LIKE 'poll_end'"));
-
-				if ($tmp['Type'] == "datetime")
-				{
-					$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_poll LIKE 'poll_end_tmp'"));
-					if (!$updated)
-					{
-						dbquery("ALTER TABLE 	`" . TABLEPREFIX . "fanfiction_poll` ADD `poll_end_tmp` int(10) unsigned NOT NULL default '0' ");
-					}
-
-					dbquery("UPDATE 		`" . TABLEPREFIX . "fanfiction_poll` SET `poll_end_tmp` = UNIX_TIMESTAMP( `poll_end` )");
-					dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_poll` CHANGE `poll_end` `poll_end` INT NOT NULL");
-					dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_poll` set poll_end = poll_end_tmp");
-					dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_poll` DROP `poll_end_tmp`");
-				}
-
-			}	
-
+
+			$set_355 = false;
+			$set_355 = do_version_check_355();
+			if($set_355) {
+				$output .= write_error(_ERROR);
+			}
+			else {
+				$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '" . $version . "' WHERE sitekey = '" . SITEKEY . "'");
+				if ($update) $output .= write_message(_ACTIONSUCCESSFUL);
+			}
+ 
 		}
 	
-		$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '" . $version . "' WHERE sitekey = '" . SITEKEY . "'");
-		if ($update) $output .= write_message(_ACTIONSUCCESSFUL);
-		else $output .= write_error(_ERROR);
+
 	}
 	else if ($confirm == "no")
 	{
@@ -255,6 +176,65 @@
 		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
+{
+	if ($confirm == "yes")
+	{
+		if ($oldVersion[0] == 3 &&  $oldVersion[1] == 5 && $oldVersion[2] < 7)
+		{
+			// List of DB tables (key) and field (value) which need changing to accommodate IPV6 addresses
+			$ip_upgrade = array(
+				'fanfiction_log' 	=> 'log_ip',
+				'fanfiction_online' => 'online_ip'
+			);
+
+			// Tables where IP address field needs updating to accommodate IPV6
+			// Set to varchar(45) - just in case something uses the IPV4 subnet (see http://en.wikipedia.org/wiki/IPV6#Notation)
+			foreach ($ip_upgrade as $t => $f)
+			{
+				if (isTable($t))
+				{
+			 
+					// Check for table - might add some core plugin tables in here
+					if ($field_info =  dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . $t . " LIKE '{$f}'")))
+					{
+						//print_r($field_info);
+						if (strtolower($field_info['Type']) != 'VARBINARY(16)')
+						{
+
+							dbquery("ALTER TABLE `" . TABLEPREFIX . $t .  "` MODIFY `$f` VARBINARY(16) NOT NULL DEFAULT '';");
+ 
+						}
+					}
+
+				}
+			}	 
+		}
+
+		$set_356 = false;
+		$set_356 = do_version_check_356();
+		if ($set_356)
+		{
+			$output .= write_error(_ERROR);
+		}
+		else
+		{
+			$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '" . $version . "' WHERE sitekey = '" . SITEKEY . "'");
+			if ($update) $output .= write_message(_ACTIONSUCCESSFUL);
+		}
+	}
+	else if ($confirm == "no")
+	{
+		$output .= write_message(_ACTIONCANCELLED);
+	}
+	else
+	{
+		if ($oldVersion[0] == 3 && ($oldVersion[1] < 4 || $oldVersion[1] == 4 && (!isset($oldVersion[2]) || $oldVersion[2] < 7)))
+		$output .= write_message(_CONFIRMUPDATE . "<br /> <a href='update.php?confirm=yes'>" . _YES . "</a> " . _OR . " <a href='update.php?confirm=no'>" . _NO . "</a>");
+		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>");
+	}
+
+}
 else $output .= write_message(_ALREADYUPDATED);
 
 /* until database is fully fixed, not update efiction version */
@@ -262,83 +242,116 @@
 	global $fanfiction_poll_exists;
 
 	$check_355 = false;
- 
-	/* do double check or return version back if it is needed */
-	$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_authors LIKE 'date'"));
-	if ($tmp['Type'] == "datetime")
-	{
-		$check_355 = true;
+
+	// List of DB tables (key) and field (value) which need changing date from datetime/timestamp to int
+	$date_upgrade = array(
+		'fanfiction_authors' => 'date',
+		'fanfiction_comments'  => 'time',
+		'fanfiction_reviews' => 'date',
+		'fanfiction_stories'  => 'date',
+		'fanfiction_stories' => 'updated',
+		'fanfiction_news' => 'time',
+		'fanfiction_poll' => 'poll_start',
+		'fanfiction_poll' => 'poll_end',
+	);
+
+	foreach ($date_upgrade as $t => $f)
+	{
+
+		if (isTable($t))
+		{
+
+			// Check for table - might add some core plugin tables in here
+			if ($field_info =  dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . $t . " LIKE '{$f}'")))
+			{
+
+				if (strtolower($field_info['Type']) != 'int' 
+				&& strtolower($field_info['Type']) != 'int(10)'
+				&& strtolower($field_info['Type']) != 'int(11)' 
+				&& strtolower($field_info['Type']) != 'int unsigned'
+				&& strtolower($field_info['Type']) != 'int(10) unsigned')
+				{
+					// echo "<pre>"; print_r($field_info); echo "</pre>";
+					$check_355 = $t . " - field:  " . $f;
+					return $check_355;
+				}
+			}
+		}
+		
+	}
+
+	$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_log LIKE 'log_timestamp'"));
+
+	if ($tmp['Type'] == "timestamp")
+	{
+		$check_355 = $t . " - field:  " . $f;;
 		return $check_355;
 	}
-	$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_log LIKE 'log_timestamp'"));
-
-	if ($tmp['Type'] == "timestamp")
-	{
-		$check_355 = true;
-		return $check_355;
-	}
-
-	$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_comments LIKE 'time'"));
-	if ($tmp['Type'] == "datetime")
-	{
-		$check_355 = true;
-		return $check_355;
-	}
-
-	$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_reviews LIKE 'date'"));
-	if ($tmp['Type'] == "datetime")
-	{
-		$check_355 = true;
-		return $check_355;
-	}
-
-	$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'date'"));
-	if ($tmp['Type'] == "datetime")
-	{
-		$check_355 = true;
-		return $check_355;
-	}
-
-	$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'updated'"));
-	if ($tmp['Type'] == "datetime")
-	{
-		$check_355 = true;
-		return $check_355;
-	}
-
-	$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_news LIKE 'time'"));
-
-	if ($tmp['Type'] == "datetime")
-	{
-			$check_355 = true;
-			return $check_355;
-	}
-
-	if ($fanfiction_poll_exists)
-	{
-		$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_poll LIKE 'poll_start'"));
-
-		if ($tmp['Type'] == "datetime")
-		{
-			$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '3.5.5' WHERE sitekey = '" . SITEKEY . "'");
-		}
-
-
-		$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_poll LIKE 'poll_end'"));
-
-		if ($tmp['Type'] == "datetime")
-		{
-			$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '3.5.5' WHERE sitekey = '" . SITEKEY . "'");
-		}
-	}
-	
 
 	return $check_355;
 }
- 
-
+
+function do_version_check_356()
+{
+	$check_356 = false;
+ 
+	// List of DB tables (key) and field (value) which need changing to accommodate IPV6 addresses
+	$ip_upgrade = array(
+		'fanfiction_log' 	=> 'log_ip',
+		'fanfiction_online' => 'online_ip'
+	);
+
+	foreach ($ip_upgrade as $t => $f)
+	{
+ 
+		if (isTable($t))
+		{
+			// Check for table - might add some core plugin tables in here
+			if ($field_info =  dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . $t ." LIKE '{$f}'")) )
+			{
+
+			
+				if (strtolower($field_info['Type']) != 'varbinary(16)')
+				{
+					$check_356 = $t . " - field:  " . $f;;
+			 
+					return $check_356;	 
+				}
+			}
+	 
+		}
+		
+	}
+ 
+	return $check_356;
+}
 
 $tpl->assign("output", $output);
 $tpl->printToScreen();
 dbclose();
 
+
+// new functions for easier db manipulation 3.6. 
+function db_mySQLtableList()
+{
+	global  $debug, $dbconnect, $dbname, $settingsprefix;
+
+	$table = array();
+
+	if ($res = dbquery("SHOW TABLES FROM " . $dbname . " LIKE '" . $settingsprefix . "%' "))
+
+		$length = strlen($settingsprefix);
+	while ($rows = dbrow($res))
+	{
+		$t = substr($rows[0], $length);
+		$table[] = $t;
+	}
+	return  $table;
+}
+
+function isTable($table)
+{
+	$mySQLtableList = db_mySQLtableList();
+	return in_array($table, $mySQLtableList);
+}
+

--- a/user/editbio.php
+++ b/user/editbio.php
@@ -82,7 +82,7 @@
 					}
 					dbquery("INSERT INTO ".substr(_AUTHORTABLE, 0, strpos(_AUTHORTABLE, "as author"))." (penname, realname, bio, email, date, password) VALUES ('".escapestring($penname)."', '".escapestring(strip_tags($_POST['realname']))."', '".strip_tags(escapestring($_POST['bio']), $allowed_tags)."', '$email', now(), '$encryppass')");
 					$useruid = dbinsertid();
-					if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_REGISTER, $penname, $useruid, $_SERVER['REMOTE_ADDR']))."', '".$useruid."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RG', " . time() . ")");
+					if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_REGISTER, $penname, $useruid, $_SERVER['REMOTE_ADDR']))."', '".$useruid. "', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'RG', " . time() . ")");
 					if(empty($siteskin)) {
 						$skinquery = dbquery("SELECT skin FROM ".$settingsprefix."fanfiction_settings WHERE sitekey = '".SITEKEY."'");
 						list($skin) = dbrow($skinquery);
@@ -132,7 +132,7 @@
 				}
 				else {
 					dbquery("UPDATE "._AUTHORTABLE." SET penname = '".escapestring($penname)."' WHERE uid = '$_POST[uid]'");
-					if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_NEWPEN, USERPENNAME, USERUID, $_POST[oldpenname], $uid, $penname))."', '".USERUID."', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'EB', " . time() . ")");
+					if($logging) dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_NEWPEN, USERPENNAME, USERUID, $_POST[oldpenname], $uid, $penname))."', '".USERUID."', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'EB', " . time() . ")");
 				}
 			}
 /* The section adds fields from the authorfields table to the authorinfo table allowing dynamic additions to the bio/registration page */
@@ -213,3 +213,4 @@
 	 	$output .= "</div></form></div>".write_message("<font color=\"red\">*</font> "._REQUIREDFIELDS);
 	}
 ?>
+

--- a/user/lostpassword.php
+++ b/user/lostpassword.php
@@ -66,7 +66,7 @@
 				}
 				else $output .=  write_message(_EMAILFAILED);
 				if($logging) 
-					dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_LOST_PASSWORD, $penname, $uid, ($result ? _YES : _NO)))."', '$uid', INET_ATON('".$_SERVER['REMOTE_ADDR']."'), 'LP', " . time() . ")");
+					dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_log (`log_action`, `log_uid`, `log_ip`, `log_type`, `log_timestamp`) VALUES('".escapestring(sprintf(_LOG_LOST_PASSWORD, $penname, $uid, ($result ? _YES : _NO)))."', '$uid', INET6_ATON('".$_SERVER['REMOTE_ADDR']."'), 'LP', " . time() . ")");
 			}
 
 		}
@@ -81,3 +81,4 @@
 	}
 
 ?>
+

--- a/user/manageimages.php
+++ b/user/manageimages.php
@@ -30,7 +30,11 @@
 		$dir = opendir(STORIESPATH."/".USERUID."/images/");
 		while($file = readdir($dir)) {
 			if(!in_array($file, array(".", "..", "/", "index.php", "imagelist.js"))) {
-				$image_files[] = "[\"".STORIESPATH."/".USERUID."/images/$file\", \"".STORIESPATH."/".USERUID."/images/$file\"]";
+				$path =  STORIESPATH . "/" . USERUID . "/images/".$file;
+				$image_files[] = "[\"" . STORIESPATH . "/" . USERUID . "/images/$file\", \"" . STORIESPATH . "/" . USERUID . "/images/$file\"]";
+
+				$image4_files[] = '{ "title": "'. $file. '", "value": "'.$path.'" }';
+		 
 			}
 		}
 		if(isset($image_files)) {
@@ -39,6 +43,12 @@
 			$text .= implode(", \n", $image_files);
 			$text .= ");\n\n";
 			fwrite($handle, $text);
+
+			$text = "var tinyMCE4ImageList = [\n";
+			$text .= implode(", \n", $image4_files);
+			$text .= "];\n\n";
+			fwrite($handle, $text);
+
 			fclose($handle);
 		}
 }
@@ -219,3 +229,4 @@
 	$output .= write_message(_NOTAUTHORIZED);
 }
 ?>
+

--- a/version.php
+++ b/version.php
@@ -1,6 +1,6 @@
 <?php
 if(!defined("_CHARSET")) exit( );
-$version = "3.5.6";
+$version = "3.5.7";
 
 /* shortcut 
 $tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_stories LIKE 'date'"));
@@ -17,3 +17,4 @@
 }
 
 */
+