Browse code

Number of Likes

Jimako authored on 2024/05/24 17:54:38
Showing 5 changed files
... ...
@@ -4,6 +4,7 @@
4 4
 - changed files: user/editbio.php and user/lostpassword.php 
5 5
 - chanded way for loading DB functions - moved from config file! 
6 6
 - fixed bug in install.php - script worked but in PHP 8.x it caused warnings
7
+- new ranking system - number of likes, used as {ratingpics} likes in tpl.
7 8
 
8 9
 
9 10
 # efiction v3.5.7
... ...
@@ -31,19 +31,42 @@ if($maint == "update") {
31 31
 }
32 32
 if($maint == "reviews") {
33 33
 	dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '0', reviews = '0'"); // Set them all to 0 before we re-insert.
34
-	$stories = dbquery("SELECT AVG(rating) as average, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY item");
35
-	while($s = dbassoc($stories)) {
36
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET rating = '".round($s['average'])."' WHERE sid = '".$s['item']."'");
34
+	if($ratings == "3") {
35
+		$stories = dbquery("SELECT COUNT(rating) as count, item FROM " . TABLEPREFIX . "fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY item");
36
+		while ($s = dbassoc($stories))
37
+		{
38
+			dbquery("UPDATE " . TABLEPREFIX . "fanfiction_stories SET rating = '" . round($s['count']) . "' WHERE sid = '" . $s['item'] . "'");
39
+		}
37 40
 	}
41
+	else {
42
+		$stories = dbquery("SELECT AVG(rating) as average, item FROM " . TABLEPREFIX . "fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY item");
43
+		while ($s = dbassoc($stories))
44
+		{
45
+			dbquery("UPDATE " . TABLEPREFIX . "fanfiction_stories SET rating = '" . round($s['average']) . "' WHERE sid = '" . $s['item'] . "'");
46
+		}
47
+	}
48
+ 
38 49
 	$stories = dbquery("SELECT COUNT(reviewid) as count, item FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND review != 'No Review' GROUP BY item");
39 50
 	while($s = dbassoc($stories)) {
40 51
 		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET reviews = '".$s['count']."' WHERE sid = '".$s['item']."'");
41 52
 	}
42 53
 	dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '0', reviews = '0'");
43
-	$chapters = dbquery("SELECT AVG(rating) as average, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY chapid");
44
-	while($c = dbassoc($chapters)) {
45
-		dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET rating = '".round($c['average'])."' WHERE chapid = '".$c['chapid']."'");
54
+	if ($ratings == "3")
55
+	{
56
+		$chapters = dbquery("SELECT COUNT(rating) as count, chapid FROM " . TABLEPREFIX . "fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY chapid");
57
+		while ($c = dbassoc($chapters))
58
+		{
59
+			dbquery("UPDATE " . TABLEPREFIX . "fanfiction_chapters SET rating = '" . round($c['count']) . "' WHERE chapid = '" . $c['chapid'] . "'");
60
+		}
61
+	}
62
+	else {
63
+		$chapters = dbquery("SELECT AVG(rating) as average, chapid FROM " . TABLEPREFIX . "fanfiction_reviews WHERE type = 'ST' AND rating != '-1' GROUP BY chapid");
64
+		while ($c = dbassoc($chapters))
65
+		{
66
+			dbquery("UPDATE " . TABLEPREFIX . "fanfiction_chapters SET rating = '" . round($c['average']) . "' WHERE chapid = '" . $c['chapid'] . "'");
67
+		}
46 68
 	}
69
+
47 70
 	$chapters = dbquery("SELECT COUNT(reviewid) as count, chapid FROM ".TABLEPREFIX."fanfiction_reviews WHERE type = 'ST' AND review != 'No Review' GROUP BY chapid");
48 71
 	while($c = dbassoc($chapters)) {
49 72
 		dbquery("UPDATE ".TABLEPREFIX."fanfiction_chapters SET reviews = '".$c['count']."' WHERE chapid = '".$c['chapid']."'");
... ...
@@ -431,7 +431,8 @@ if(isset($_POST['submit'])) {
431 431
 				</select> <a href='#' class='pophelp'>[?]<span>"._HELP_REVDELETE."</span></a></td>
432 432
 		</tr>
433 433
 		<tr>
434
-				<td><label for='newratings'>"._WHATRATINGS.":</label></td><td><select name='newratings'>
434
+				<td><label for='newratings'>"._WHATRATINGS. ":</label></td><td><select name='newratings'>
435
+				<option value='3'" . ($ratings == "3" ? " selected" : "") . ">" . _LIKES_NUMBER . "</option>
435 436
 				<option value='2'".($ratings == "2" ? " selected" : "").">"._LIKESYS."</option>
436 437
 				<option value='1'".($ratings == "1" ? " selected" : "").">"._STARS."</option>
437 438
 				<option value='0'".($ratings == "0" ? " selected" : "").">"._NONE."</option>
... ...
@@ -167,14 +167,26 @@ function subseriesList($thisseries) {
167 167
 
168 168
 function seriesreview($thisseries) {
169 169
 
170
+	global $ratings;
171
+
170 172
 	if(!isNumber($thisseries)) return;
171 173
 	$storylist = storiesInSeries($thisseries);
172 174
 	$serieslist = subseriesList($thisseries);
173
-$newrating = dbquery("SELECT AVG(rating) as totalreviews FROM ".TABLEPREFIX."fanfiction_reviews 
174
-	WHERE ((item = '$thisseries' AND type = 'SE')".
175
-	(count($storylist) > 0 ? " OR (FIND_IN_SET(item, '".(implode(",", $storylist))."') > 0 AND type = 'ST')" : "").
176
-	(count($serieslist) > 0 ? " OR (FIND_IN_SET(item, '".(implode(",", $serieslist))."') > 0 AND type = 'SE')" : "").
177
-	") AND rating != '-1'");
175
+	if($ratings == 3) {
176
+		$newrating = dbquery("SELECT COUNT(rating) as totalreviews FROM " . TABLEPREFIX . "fanfiction_reviews 
177
+		WHERE ((item = '$thisseries' AND type = 'SE')" .
178
+		(count($storylist) > 0 ? " OR (FIND_IN_SET(item, '" . (implode(",", $storylist)) . "') > 0 AND type = 'ST')" : "") .
179
+			(count($serieslist) > 0 ? " OR (FIND_IN_SET(item, '" . (implode(",", $serieslist)) . "') > 0 AND type = 'SE')" : "") .
180
+			") AND rating != '-1'");
181
+	}
182
+    else {
183
+		$newrating = dbquery("SELECT AVG(rating) as totalreviews FROM " . TABLEPREFIX . "fanfiction_reviews 
184
+	WHERE ((item = '$thisseries' AND type = 'SE')" .
185
+		(count($storylist) > 0 ? " OR (FIND_IN_SET(item, '" . (implode(",", $storylist)) . "') > 0 AND type = 'ST')" : "") .
186
+		(count($serieslist) > 0 ? " OR (FIND_IN_SET(item, '" . (implode(",", $serieslist)) . "') > 0 AND type = 'SE')" : "") .
187
+		") AND rating != '-1'");
188
+	}
189
+
178 190
 list($totalreviews) = dbrow($newrating);
179 191
 $newcount = dbquery("SELECT count(reviewid) as totalcount FROM ".TABLEPREFIX."fanfiction_reviews 
180 192
 	WHERE ((item = '$thisseries' AND type = 'SE')".
... ...
@@ -269,8 +281,7 @@ function author_link($stories) {
269 281
 	
270 282
 	$authlink[] = "<a href=\"" . _BASEDIR . "viewuser.php?uid=" . $stories['uid'] . "\">" . $stories['penname'] . "</a>";
271 283
 
272
-	if($stories['coauthors']) {
273
-		
284
+	if($stories['coauthors'] && $stories['coauthors_array'])  {	
274 285
 		//not needed, why is it there?
275 286
 		//$coauth = dbquery("SELECT "._PENNAMEFIELD." as penname, co.uid FROM ".TABLEPREFIX."fanfiction_coauthors AS co 
276 287
 		//LEFT JOIN "._AUTHORTABLE." ON co.uid = "._UIDFIELD." WHERE co.sid = '".$stories['sid']."'");
... ...
@@ -468,7 +479,11 @@ function build_pagelinks($url, $total, $offset = 0, $columns = 1) {
468 479
 function ratingpics($rating) {
469 480
 	global $ratings, $like, $dislike, $star, $halfstar;
470 481
 	$ratingpics = "";
471
-	if($ratings == "2") {
482
+
483
+	if($ratings == "3") { 
484
+		$ratingpics = "<span title=\""._LIKES_NUMBER. "\"><b>" . $rating . "</b></span>";
485
+	}	
486
+	elseif($ratings == "2") {
472 487
 		if($rating >= 0.5)
473 488
 			$ratingpics = ($like ? $like : "<img src=\""._BASEDIR."images/like.gif\" alt=\""._LIKED."\">");
474 489
 		else if(($rating < 0.5) && ($rating > 0))
... ...
@@ -575,4 +590,11 @@ function search($storyquery, $countquery, $pagelink = "search.php?", $pagetitle
575 590
 	$tpl->gotoBlock("_ROOT");
576 591
 	return $numrows;
577 592
 }
578
-?>
593
+
594
+
595
+// This function replaces escaped newlines with html <br /> tags
596
+function fixup_newlines($string)
597
+{
598
+	$string = str_replace(array("\\r\\n", "\\n\\r", "\\r", "\\n"), "<br />", $string);
599
+	return $string;
600
+}
... ...
@@ -132,6 +132,7 @@ define ("_INSTALLMODULE", "Install this module");
132 132
 define ("_LANGUAGE", "Language");
133 133
 define ("_LEVEL", "Level");
134 134
 define ("_LIKESYS", "Like/Dislike"); // Changed to avoid conflict with user _LIKE declaration
135
+define ("_LIKES_NUMBER", "Number of Likes");  
135 136
 define ("_LINKACCESS", "Link Access Level"); 
136 137
 define ("_LINKKEY", "Link Access Key");
137 138
 define ("_LINKRANGE", "Size of Range for Page Links");
... ...
@@ -369,4 +370,4 @@ define ("_LOG_RECALCREVIEWS", "<a href='viewuser.php?uid=%2\$d'>%1\$s</a> recalc
369 370
 define ("_LOG_CATCOUNTS", "<a href='viewuser.php?uid=%2\$d'>%1\$s</a> recalculated the category counts.");
370 371
 define ("_LOG_OPTIMIZE", "<a href='viewuser.php?uid=%2\$d'>%1\$s</a> optimized the database tables.");
371 372
 define ("_LOG_BACKUP", "<a href='viewuser.php?uid=%2\$d'>%1\$s</a> backed up the database tables.");
372
-?>
373 373
\ No newline at end of file
374
+?>