Browse code

#8 #5 #4 #3 coauthors cleaning

Jimako authored on 2023/09/06 05:27:54
Showing 7 changed files
... ...
@@ -47,10 +47,11 @@ function deleteStory($story) {
47 47
 	dbquery("DELETE FROM ".TABLEPREFIX."fanfiction_reviews WHERE item = '$sid' AND type = 'ST'");
48 48
 	dbquery("DELETE FROM ".TABLEPREFIX."fanfiction_favorites WHERE item = '$sid' AND type = 'ST'");
49 49
 	// get the coauthors list before we delete the coauthors info.
50
+	$array_coauthors = array();
50 51
 	if($story['coauthors'] == 1) {
51 52
 		$coauth = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '$sid'");
52 53
 		while($c = dbassoc($coauth)) {
53
-			$coauthors[] = $c['uid'];
54
+			$array_coauthors[] = $c['uid'];
54 55
 			
55 56
 		}
56 57
 	}	
... ...
@@ -70,9 +71,9 @@ function deleteStory($story) {
70 71
 	}
71 72
 	if($story['validated'] > 0) {
72 73
 		dbquery("UPDATE ".TABLEPREFIX."fanfiction_stats SET stories = stories - 1");
73
-		if(!empty($coauthors)) {
74
-			$coauthors[] = $story['uid'];
75
-			dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = stories - 1 WHERE FIND_IN_SET(uid, '".implode(",", $coauthors)."') > 0");
74
+		if(!empty($array_coauthors)) {
75
+			$array_coauthors[] = $story['uid'];
76
+			dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = stories - 1 WHERE FIND_IN_SET(uid, '".implode(",", $array_coauthors)."') > 0");
76 77
 		}
77 78
 		else dbquery("UPDATE ".TABLEPREFIX."fanfiction_authorprefs SET stories = stories - 1 WHERE uid = '".$story['uid']."' LIMIT 1");
78 79
 		list($chapters, $words) = dbrow(dbquery("SELECT COUNT(chapid), SUM(wordcount) FROM ".TABLEPREFIX."fanfiction_chapters WHERE validated > 0"));
... ...
@@ -96,13 +97,14 @@ function deleteUser($uid) {
96 97
 				}
97 98
 				else { // Co-authors found...give the story a new author.
98 99
 					$cQuery = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '".$story['sid']."' LIMIT 1");
99
-					$newauthor = 0; $coauthors = array( );
100
+					$newauthor = 0; $coauthors = 0;
101
+					$array_coauthors = array();
100 102
 					while($cRes= dbassoc($cQuery)) {
101 103
 						if(!$newauthor) $newauthor = $cRes['uid'];
102
-						else $coauthors[] = $cRes['uid'];
104
+						else $array_coauthors[] = $cRes['uid'];
103 105
 					}			
104 106
 					if(!empty($newauthor)) {
105
-						$coauthors = count($coauthors) > 0 ? 1 : 0;
107
+						$coauthors = count($array_coauthors) > 0 ? 1 : 0;
106 108
 						dbquery("UPDATE ".TABLEPREFIX."fanfiction_stories SET uid = '$newauthor', coauthors = '$coauthors' WHERE sid = '".$story['sid']."' LIMIT 1");
107 109
 						$chapters = dbquery("SELECT chapid FROM ".TABLEPREFIX."fanfiction_chapters WHERE sid = '".$story['sid']."' AND uid = '$uid'");
108 110
 						while($chap = dbassoc($chapters)) {
... ...
@@ -26,13 +26,13 @@ if(!defined("_CHARSET")) exit( );
26 26
 	$tpl->assign("sid", $stories['sid']);
27 27
 	unset($challengelinks, $challengeadmin, $serieslinks, $categorylinks, $adminlinks, $authlink);
28 28
 	if($stories['coauthors'] == 1) {
29
-		$coauthors = array();
29
+		$array_coauthors = array();
30 30
 		$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']."'");
31 31
 		while($c = dbassoc($coauth)) {
32
-			$coauthors[$c['uid']] = $c['penname'];
32
+			$array_coauthors[$c['uid']] = $c['penname'];
33 33
 		}
34
-		$stories['coauthors'] = $coauthors;
35
-		unset($coauthors);
34
+		$stories['coauthors'] = $array_coauthors;
35
+		unset($array_coauthors);
36 36
 	}
37 37
 	else if(empty($stories['coauthors'])) $stories['coauthors'] = array( );	
38 38
 	$tpl->assign("title"   , stripslashes(title_link($stories)) );
... ...
@@ -164,10 +164,10 @@ else if($action == "edit" || $action == "add") {
164 164
 				$uidquery = dbquery("SELECT uid,title, coauthors FROM ".TABLEPREFIX."fanfiction_stories WHERE sid = '$item'");
165 165
 				list($author, $title, $coauthors) = dbrow($uidquery);
166 166
 				if($coauthors) {
167
-					$coauthors = array( );
167
+					$array_coauthors = array( );
168 168
 					$coQuery = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '$item'");
169 169
 					while($c = dbassoc($coQuery)) {
170
-						$coauthors[] = $c['uid'];
170
+						$array_coauthors[] = $c['uid'];
171 171
 					}
172 172
 				}
173 173
 			}
... ...
@@ -186,7 +186,7 @@ else if($action == "edit" || $action == "add") {
186 186
 				}
187 187
 			}
188 188
 			if($review != "No Review" && $action == "add") {
189
-				$mailquery= dbquery("SELECT ap.newreviews,"._EMAILFIELD." as email, "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." LEFT JOIN ".TABLEPREFIX."fanfiction_authorprefs as ap ON ap.uid = "._UIDFIELD." WHERE "._UIDFIELD." = '$author' ".(!empty($coauthors) ? " OR ".findclause(_UIDFIELD, $coauthors) : ""));
189
+				$mailquery= dbquery("SELECT ap.newreviews,"._EMAILFIELD." as email, "._PENNAMEFIELD." as penname FROM "._AUTHORTABLE." LEFT JOIN ".TABLEPREFIX."fanfiction_authorprefs as ap ON ap.uid = "._UIDFIELD." WHERE "._UIDFIELD." = '$author' ".(!empty($coauthors) ? " OR ".findclause(_UIDFIELD, $array_coauthors) : ""));
190 190
 				while($mail = dbassoc($mailquery)) {
191 191
 					if($mail['newreviews']) {
192 192
 						include_once("includes/emailer.php");
... ...
@@ -247,10 +247,11 @@ else {
247 247
 		$story = dbassoc($storyquery);
248 248
 		$title = title_link($story);
249 249
 		$authoruid = $story['uid'];
250
+		$array_coauthors = array();
250 251
 		if(!empty($story['coauthors'])) {
251 252
 			$colist = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '$item'");
252 253
 			while($c = dbassoc($colist)) {
253
-				$coauthors[] = $c['uid'];
254
+				$array_coauthors[] = $c['uid'];
254 255
 			}
255 256
 		}
256 257
 	}
... ...
@@ -379,7 +380,7 @@ else {
379 380
 			$reviewer = $reviews['reviewer'];
380 381
 			$member = _ANONYMOUS;
381 382
 		}
382
-		if(empty($reviews['respond']) && (USERUID == $authoruid || (isset($coauthors) && in_array(USERUID, $coauthors)))) $adminlink .= " [<a href=\"user.php?action=revres&amp;reviewid=".$reviews['reviewid']."\">"._RESPOND."</a>]";
383
+		if(empty($reviews['respond']) && (USERUID == $authoruid || (isset($array_coauthors) && in_array(USERUID, $array_coauthors)))) $adminlink .= " [<a href=\"user.php?action=revres&amp;reviewid=".$reviews['reviewid']."\">"._RESPOND."</a>]";
383 384
 		$tpl->newBlock("reviewsblock");
384 385
 		$tpl->assign("reviewer"   , $reviewer );
385 386
 		$tpl->assign("reportthis", "[<a href=\""._BASEDIR."contact.php?action=report&amp;url=reviews.php?reviewid=".$reviews['reviewid']."\">"._REPORTTHIS."</a>]");
... ...
@@ -48,16 +48,16 @@ include("includes/storyform.php");
48 48
 			if($result) list($sid, $author) = dbrow($result);
49 49
 		}
50 50
 		if(isset($sid)) {
51
-			$coauthors = array( );
51
+			$array_coauthors = array( );
52 52
 			$authorquery = dbquery("SELECT uid, rr, coauthors FROM ".TABLEPREFIX."fanfiction_stories WHERE sid='$sid' LIMIT 1");
53 53
 			$story = dbassoc($authorquery);
54 54
 			if($story['coauthors']) {
55 55
 				$cQuery = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '$sid'");
56 56
 				while($c = dbassoc($cQuery)) {
57
-					$coauthors[] = $c['uid'];
57
+					$array_coauthors[] = $c['uid'];
58 58
 				}
59 59
 			}
60
-			if($story['uid'] != USERUID && (is_array($coauthors) && !in_array(USERUID, $coauthors)) && !$story['rr']) accessDenied( );
60
+			if($story['uid'] != USERUID && (is_array($array_coauthors) && !in_array(USERUID, $array_coauthors)) && !$story['rr']) accessDenied( );
61 61
 		}
62 62
 	}
63 63
 	else if(isADMIN && uLEVEL < 4 && isset($_GET['admin'])) {
... ...
@@ -139,7 +139,7 @@ function newstory( ) {
139 139
 	$storynotes = isset($_POST['storynotes']) ? descript(strip_tags($_POST['storynotes'], $allowed_tags)) : "";
140 140
 	$catid = isset($_POST['catid']) ? array_filter(explode(",", $_POST['catid']), "isNumber") : array( );
141 141
 	$charid = isset($_POST['charid']) ? array_filter($_POST['charid'], "isNumber") : array( );
142
-	$coauthors = isset($_POST['coauthors']) ? array_filter(explode(",", $_POST['coauthors']), "isNumber") : array( );
142
+	$array_coauthors = isset($_POST['coauthors']) ? array_filter(explode(",", $_POST['coauthors']), "isNumber") : array( );
143 143
 	$classes = array( );
144 144
 	$classquery = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_classtypes");
145 145
 	while($type = dbassoc($classquery)) {
... ...
@@ -178,8 +178,8 @@ function newstory( ) {
178 178
 	$words_to_count = trim($words_to_count);
179 179
 	$wordcount = count(explode(" ",$words_to_count)); 
180 180
 	$au[] = $uid;
181
-	if(count($coauthors)) {
182
-		$au = array_merge($au, $coauthors);
181
+	if(count($array_coauthors)) {
182
+		$au = array_merge($au, $array_coauthors);
183 183
 		$coauthors = 1;
184 184
 	}
185 185
 	else $coauthors = 0;
... ...
@@ -273,7 +273,7 @@ function newstory( ) {
273 273
 			else $output .= write_error(_FATALERROR." "._TRYAGAIN);
274 274
 		}
275 275
 		if(!$newchapter) {
276
-			if(count($coauthors)) {
276
+			if(count($array_coauthors)) {
277 277
 				foreach($au AS $c) {
278 278
 					if($c == $uid) continue;
279 279
 					dbquery("INSERT INTO ".TABLEPREFIX."fanfiction_coauthors(`sid`, `uid`) VALUES('$sid', '$c')");
... ...
@@ -634,7 +634,7 @@ function editstory($sid) {
634 634
 		$rid = isset($_POST['rid']) && isNumber($_POST['rid']) ? $_POST['rid'] : 0;
635 635
 		$catid = isset($_POST['catid']) ? array_filter(explode(",", $_POST['catid']), "isNumber") : array( );
636 636
 		$charid = isset($_POST['charid']) ? array_filter($_POST['charid'], "isNumber") : array( );
637
-		$coauthors = isset($_POST['coauthors']) ? array_filter(explode(",", $_POST['coauthors']), "isNumber") : array( );
637
+		$array_coauthors = isset($_POST['coauthors']) ? array_filter(explode(",", $_POST['coauthors']), "isNumber") : array( );
638 638
 		if(isset($_POST['uid']) && isNumber($_POST['uid'])) $uid = $_POST['uid'];
639 639
 		else $uid = USERUID;
640 640
 		$classes = array( );
... ...
@@ -647,8 +647,8 @@ function editstory($sid) {
647 647
 		}
648 648
 		if(!$admin && $authorvalid && !$validated) $validated = 2;
649 649
 		$au[] = $uid;
650
-		if(count($coauthors)) {
651
-			$au = array_merge($au, $coauthors);
650
+		if(count($array_coauthors)) {
651
+			$au = array_merge($au, $array_coauthors);
652 652
 			$coauthors = 1;
653 653
 		}
654 654
 		else $coauthors = 0;
... ...
@@ -35,6 +35,7 @@ if(!empty($favorites) && isMEMBER && $userinfo['uid'] != USERUID) {
35 35
 	$fav = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_favorites WHERE uid = '".USERUID."' AND type = 'AU' AND item = '".$userinfo['uid']."'");
36 36
 	if(dbnumrows($fav) == 0) $nameinfo .= " [<a href=\"user.php?action=favau&amp;uid=".USERUID."&amp;add=".$userinfo['uid']."\">"._ADDAUTHOR2FAVES."</a>]";
37 37
 }
38
+ 
38 39
 $tpl->assign("userpenname", $userinfo['penname']." ".$nameinfo);
39 40
 $tpl->assign("membersince", date("$dateformat", $userinfo['date']));
40 41
 if($userinfo['realname'])
... ...
@@ -67,13 +67,14 @@ if(!defined("_CHARSET")) exit( );
67 67
 			}
68 68
 		}
69 69
 		$user = dbassoc(dbquery($query2));
70
+		$array_coauthors = array();
70 71
 		if(!empty($user['coauthors'])) {
71 72
 			$coQuery = dbquery("SELECT uid FROM ".TABLEPREFIX."fanfiction_coauthors WHERE sid = '".$reviews['item']."'");
72 73
 			while($c = dbassoc($coQuery)) {
73
-				$coauthors[] = $c['uid'];
74
+				$array_coauthors[] = $c['uid'];
74 75
 			}
75 76
 		}
76
-		if(USERUID == $user['uid'] || (!empty($user['coauthors']) && in_array(USERUID, $coauthors))) {
77
+		if(USERUID == $user['uid'] || (!empty($user['coauthors']) && in_array(USERUID, $array_coauthors))) {
77 78
 			if($type == "ST") {
78 79
 				$storyquery = dbquery("SELECT s.title, s.uid, r.rid, r.rating, r.ratingwarning, r.warningtext, s.sid FROM ".TABLEPREFIX."fanfiction_stories as s, ".TABLEPREFIX."fanfiction_ratings as r WHERE s.sid = '".$reviews['item']."' AND s.rid = r.rating LIMIT 1");
79 80
 				$story = dbassoc($storyquery);
... ...
@@ -35,13 +35,13 @@ if(empty($chapter)) $chapter = isset($_GET['chapter']) && isNumber($_GET['chapte
35 35
 	$storyquery = dbquery("SELECT "._PENNAMEFIELD." as penname, "._UIDFIELD." as uid, story.*, story.date as date, story.updated as updated, story.validated as valid FROM ".TABLEPREFIX."fanfiction_stories as story, "._AUTHORTABLE." WHERE story.sid = '".$sid."' AND story.uid = "._UIDFIELD);
36 36
 	$storyinfo = dbassoc($storyquery);
37 37
 	if($storyinfo['coauthors'] == 1) {
38
-		$coauthors = array();
38
+	$array_coauthors = array();
39 39
 		$coauth = dbquery("SELECT "._PENNAMEFIELD." as penname, co.uid FROM ".TABLEPREFIX."fanfiction_coauthors AS co LEFT JOIN "._AUTHORTABLE." ON co.uid = "._UIDFIELD." WHERE co.sid = '".$sid."'");
40 40
 		while($c = dbassoc($coauth)) {
41
-			$coauthors[$c['uid']] = $c['penname'];
41
+		$array_coauthors[$c['uid']] = $c['penname'];
42 42
 		}
43
-		$storyinfo['coauthors'] = $coauthors;
44
-		unset($coauthors);
43
+		$storyinfo['coauthors'] = $array_coauthors;
44
+		unset($array_coauthors);
45 45
 	}
46 46
 	else $storyinfo['coauthors'] = array();
47 47
 	//  Check that the story is valid and that the visitor has permissions to read this story