Number of Likes
Number of Likes

file:a/README.md -> file:b/README.md
--- a/README.md
+++ b/README.md
@@ -4,6 +4,7 @@
 - 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
+- new ranking system - number of likes, used as {ratingpics} likes in tpl.
 
 
 # efiction v3.5.7

--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -31,19 +31,42 @@
 }
 if($maint == "reviews") {
 	dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '0', reviews = '0'"); // Set them all to 0 before we re-insert.
-	$stories = dbquery("SELECT AVG(rating) as average, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY item");
-	while($s = dbassoc($stories)) {
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($s['average'])."' WHERE sid = '".$s['item']."'");
-	}
+	if($ratings == "3") {
+		$stories = dbquery("SELECT COUNT(rating) as count, item FROM " . TABLEPREFIX . "fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY item");
+		while ($s = dbassoc($stories))
+		{
+			dbquery("UPDATE " . TABLEPREFIX . "fanfiction_stories SET rating = '" . round($s['count']) . "' WHERE sid = '" . $s['item'] . "'");
+		}
+	}
+	else {
+		$stories = dbquery("SELECT AVG(rating) as average, item FROM " . TABLEPREFIX . "fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY item");
+		while ($s = dbassoc($stories))
+		{
+			dbquery("UPDATE " . TABLEPREFIX . "fanfiction_stories SET rating = '" . round($s['average']) . "' WHERE sid = '" . $s['item'] . "'");
+		}
+	}
+ 
 	$stories = dbquery("SELECT COUNT(reviewid) as count, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND review != 'No Review' GROUP BY item");
 	while($s = dbassoc($stories)) {
 		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET reviews = '".$s['count']."' WHERE sid = '".$s['item']."'");
 	}
 	dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '0', reviews = '0'");
-	$chapters = dbquery("SELECT AVG(rating) as average, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY chapid");
-	while($c = dbassoc($chapters)) {
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($c['average'])."' WHERE chapid = '".$c['chapid']."'");
-	}
+	if ($ratings == "3")
+	{
+		$chapters = dbquery("SELECT COUNT(rating) as count, chapid FROM " . TABLEPREFIX . "fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY chapid");
+		while ($c = dbassoc($chapters))
+		{
+			dbquery("UPDATE " . TABLEPREFIX . "fanfiction_chapters SET rating = '" . round($c['count']) . "' WHERE chapid = '" . $c['chapid'] . "'");
+		}
+	}
+	else {
+		$chapters = dbquery("SELECT AVG(rating) as average, chapid FROM " . TABLEPREFIX . "fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY chapid");
+		while ($c = dbassoc($chapters))
+		{
+			dbquery("UPDATE " . TABLEPREFIX . "fanfiction_chapters SET rating = '" . round($c['average']) . "' WHERE chapid = '" . $c['chapid'] . "'");
+		}
+	}
+
 	$chapters = dbquery("SELECT COUNT(reviewid) as count, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND review != 'No Review' GROUP BY chapid");
 	while($c = dbassoc($chapters)) {
 		dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET reviews = '".$c['count']."' WHERE chapid = '".$c['chapid']."'");

--- a/admin/settings.php
+++ b/admin/settings.php
@@ -431,7 +431,8 @@
 				</select> <a href='#' class='pophelp'>[?]<span>"._HELP_REVDELETE."</span></a></td>
 		</tr>
 		<tr>
-				<td><label for='newratings'>"._WHATRATINGS.":</label></td><td><select name='newratings'>
+				<td><label for='newratings'>"._WHATRATINGS. ":</label></td><td><select name='newratings'>
+				<option value='3'" . ($ratings == "3" ? " selected" : "") . ">" . _LIKES_NUMBER . "</option>
 				<option value='2'".($ratings == "2" ? " selected" : "").">"._LIKESYS."</option>
 				<option value='1'".($ratings == "1" ? " selected" : "").">"._STARS."</option>
 				<option value='0'".($ratings == "0" ? " selected" : "").">"._NONE."</option>

--- a/includes/corefunctions.php
+++ b/includes/corefunctions.php
@@ -167,14 +167,26 @@
 
 function seriesreview($thisseries) {
 
+	global $ratings;
+
 	if(!isNumber($thisseries)) return;
 	$storylist = storiesInSeries($thisseries);
 	$serieslist = subseriesList($thisseries);
-$newrating = dbquery("SELECT AVG(rating) as totalreviews FROM ".TABLEPREFIX."fanfiction_reviews 
-	WHERE ((item = '$thisseries' AND type = 'SE')".
-	(count($storylist) > 0 ? " OR (FIND_IN_SET(item, '".(implode(",", $storylist))."') > 0 AND type = 'ST')" : "").
-	(count($serieslist) > 0 ? " OR (FIND_IN_SET(item, '".(implode(",", $serieslist))."') > 0 AND type = 'SE')" : "").
-	") AND rating != '-1'");
+	if($ratings == 3) {
+		$newrating = dbquery("SELECT COUNT(rating) as totalreviews FROM " . TABLEPREFIX . "fanfiction_reviews 
+		WHERE ((item = '$thisseries' AND type = 'SE')" .
+		(count($storylist) > 0 ? " OR (FIND_IN_SET(item, '" . (implode(",", $storylist)) . "') > 0 AND type = 'ST')" : "") .
+			(count($serieslist) > 0 ? " OR (FIND_IN_SET(item, '" . (implode(",", $serieslist)) . "') > 0 AND type = 'SE')" : "") .
+			") AND rating != '-1'");
+	}
+    else {
+		$newrating = dbquery("SELECT AVG(rating) as totalreviews FROM " . TABLEPREFIX . "fanfiction_reviews 
+	WHERE ((item = '$thisseries' AND type = 'SE')" .
+		(count($storylist) > 0 ? " OR (FIND_IN_SET(item, '" . (implode(",", $storylist)) . "') > 0 AND type = 'ST')" : "") .
+		(count($serieslist) > 0 ? " OR (FIND_IN_SET(item, '" . (implode(",", $serieslist)) . "') > 0 AND type = 'SE')" : "") .
+		") AND rating != '-1'");
+	}
+
 list($totalreviews) = dbrow($newrating);
 $newcount = dbquery("SELECT count(reviewid) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews 
 	WHERE ((item = '$thisseries' AND type = 'SE')".
@@ -269,8 +281,7 @@
 	
 	$authlink[] = "<a href=\"" . _BASEDIR . "viewuser.php?uid=" . $stories['uid'] . "\">" . $stories['penname'] . "</a>";
 
-	if($stories['coauthors']) {
-		
+	if($stories['coauthors'] && $stories['coauthors_array'])  {	
 		//not needed, why is it there?
 		//$coauth = dbquery("SELECT "._PENNAMEFIELD." as penname, co.uid FROM ".TABLEPREFIX."fanfiction_coauthors AS co 
 		//LEFT JOIN "._AUTHORTABLE." ON co.uid = "._UIDFIELD." WHERE co.sid = '".$stories['sid']."'");
@@ -468,7 +479,11 @@
 function ratingpics($rating) {
 	global $ratings, $like, $dislike, $star, $halfstar;
 	$ratingpics = "";
-	if($ratings == "2") {
+
+	if($ratings == "3") { 
+		$ratingpics = "<span title=\""._LIKES_NUMBER. "\"><b>" . $rating . "</b></span>";
+	}	
+	elseif($ratings == "2") {
 		if($rating >= 0.5)
 			$ratingpics = ($like ? $like : "<img src=\""._BASEDIR."images/like.gif\" alt=\""._LIKED."\">");
 		else if(($rating < 0.5) && ($rating > 0))
@@ -575,5 +590,12 @@
 	$tpl->gotoBlock("_ROOT");
 	return $numrows;
 }
-?>
-
+
+
+// This function replaces escaped newlines with html <br /> tags
+function fixup_newlines($string)
+{
+	$string = str_replace(array("\\r\\n", "\\n\\r", "\\r", "\\n"), "<br />", $string);
+	return $string;
+}
+

--- a/languages/en_admin.php
+++ b/languages/en_admin.php
@@ -132,6 +132,7 @@
 define ("_LANGUAGE", "Language");
 define ("_LEVEL", "Level");
 define ("_LIKESYS", "Like/Dislike"); // Changed to avoid conflict with user _LIKE declaration
+define ("_LIKES_NUMBER", "Number of Likes");  
 define ("_LINKACCESS", "Link Access Level"); 
 define ("_LINKKEY", "Link Access Key");
 define ("_LINKRANGE", "Size of Range for Page Links");
@@ -370,3 +371,4 @@
 define ("_LOG_OPTIMIZE", "<a href='viewuser.php?uid=%2\$d'>%1\$s</a> optimized the database tables.");
 define ("_LOG_BACKUP", "<a href='viewuser.php?uid=%2\$d'>%1\$s</a> backed up the database tables.");
 ?>
+