Browse code

coauthors fix

Jimako authored on 2024/05/12 17:29:23
Showing 3 changed files
... ...
@@ -266,14 +266,21 @@ function title_link($stories) {
266 266
 
267 267
 // Same with the author list
268 268
 function author_link($stories) {
269
-	if(is_array($stories['coauthors'])) {
270
-		$authlink[] = "<a href=\""._BASEDIR."viewuser.php?uid=".$stories['uid']."\">".$stories['penname']."</a>";
271
-		$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']."'");
272
-		foreach($stories['coauthors'] AS $k => $v) {
269
+	
270
+	$authlink[] = "<a href=\"" . _BASEDIR . "viewuser.php?uid=" . $stories['uid'] . "\">" . $stories['penname'] . "</a>";
271
+
272
+	if($stories['coauthors']) {
273
+		
274
+		//not needed, why is it there?
275
+		//$coauth = dbquery("SELECT "._PENNAMEFIELD." as penname, co.uid FROM ".TABLEPREFIX."fanfiction_coauthors AS co 
276
+		//LEFT JOIN "._AUTHORTABLE." ON co.uid = "._UIDFIELD." WHERE co.sid = '".$stories['sid']."'");
277
+
278
+		foreach($stories['coauthors_array'] AS $k => $v) {
273 279
 			$authlink[] = "<a href=\""._BASEDIR."viewuser.php?uid=".$k."\">".$v."</a>";
274 280
 		}
275 281
 	}
276
-	return isset($authlink) ? implode(", ", $authlink) : "<a href=\""._BASEDIR."viewuser.php?uid=".$stories['uid']."\">".$stories['penname']."</a>";
282
+ 
283
+	return  implode(", ", $authlink) ;
277 284
 }
278 285
 
279 286
 // Used to truncate text (summaries in blocks for example) to a set length.  An improvement on the old version as this keeps words intact
... ...
@@ -568,4 +575,4 @@ function search($storyquery, $countquery, $pagelink = "search.php?", $pagetitle
568 575
 	$tpl->gotoBlock("_ROOT");
569 576
 	return $numrows;
570 577
 }
571
-?>
572 578
\ No newline at end of file
579
+?>
... ...
@@ -31,10 +31,10 @@ if(!defined("_CHARSET")) exit( );
31 31
 		while($c = dbassoc($coauth)) {
32 32
 			$array_coauthors[$c['uid']] = $c['penname'];
33 33
 		}
34
-		$stories['coauthors'] = $array_coauthors;
34
+		$stories['coauthors_array'] = $array_coauthors;
35 35
 		unset($array_coauthors);
36 36
 	}
37
-	else  $stories['coauthors'] = array( );	
37
+	else  $stories['coauthors_array'] = array( );	
38 38
  
39 39
 	$tpl->assign("title"   , stripslashes(title_link($stories)) );
40 40
 	$tpl->assign("author"   , author_link($stories));
... ...
@@ -95,7 +95,7 @@ if(!defined("_CHARSET")) exit( );
95 95
 	$tpl->assign("ratingpics"   , ratingpics($stories['rating']) );
96 96
 	$tpl->assign("reviews"   , ($reviewsallowed ? "<a href=\""._BASEDIR."reviews.php?type=ST&amp;item=".$stories['sid']."\">"._REVIEWS."</a>" : "") );
97 97
 	if(isMEMBER && !empty($favorites)) 
98
-		$tpl->assign("addtofaves", "[<a href=\""._BASEDIR."user.php?action=favst&amp;add=1&amp;sid=".$stories['sid']."\">"._ADDSTORY2FAVES."</a>] [<a href=\""._BASEDIR."user.php?action=favau&amp;add=".$stories['uid'].(count($stories['coauthors']) ? ",".implode(",", array_keys($stories['coauthors'])) : "")."\">"._ADDAUTHOR2FAVES."</a>]");
98
+		$tpl->assign("addtofaves", "[<a href=\""._BASEDIR."user.php?action=favst&amp;add=1&amp;sid=".$stories['sid']."\">"._ADDSTORY2FAVES."</a>] [<a href=\""._BASEDIR."user.php?action=favau&amp;add=".$stories['uid'].(count($stories['coauthors_array']) ? ",".implode(",", array_keys($stories['coauthors_array'])) : "")."\">"._ADDAUTHOR2FAVES."</a>]");
99 99
 	
100 100
 	$numchapsquery = dbquery("SELECT count(sid) FROM ".TABLEPREFIX."fanfiction_chapters WHERE sid = '".$stories['sid']."' AND validated > 0");
101 101
 	list($chapters) = dbrow($numchapsquery);
... ...
@@ -109,7 +109,7 @@ if(!defined("_CHARSET")) exit( );
109 109
 	}
110 110
 	$tpl->assign("wordcount"   , $stories['wordcount'] ? $stories['wordcount'] : "0" );
111 111
 	$tpl->assign("numreviews"   , ($reviewsallowed == "1" ? "<a href=\""._BASEDIR."reviews.php?type=ST&amp;item=".$stories['sid']."\">".$stories['reviews']."</a>" : "") );
112
-	if((isADMIN && uLEVEL < 4) || USERUID == $stories['uid'] || (is_array($stories['coauthors']) && array_key_exists(USERUID, $stories['coauthors'])))
112
+	if((isADMIN && uLEVEL < 4) || USERUID == $stories['uid'] || (is_array($stories['coauthors']) && array_key_exists(USERUID, $stories['coauthors_array'])))
113 113
 		$adminlinks .= "[<a href=\""._BASEDIR."stories.php?action=editstory&amp;sid=".$stories['sid'].(isADMIN ? "&amp;admin=1" : "")."\">"._EDIT."</a>] [<a href=\""._BASEDIR."stories.php?action=delete&amp;sid=".$stories['sid'].(isADMIN ? "&amp;admin=1" : "")."\">"._DELETE."</a>]";
114 114
 	global $featured;
115 115
 	if($stories['featured'] == 1) {
... ...
@@ -127,6 +127,6 @@ if(!defined("_CHARSET")) exit( );
127 127
 	$tpl->assign("oddeven", ($count % 2 ? "odd" : "even"));
128 128
 	$tpl->assign("reportthis", "[<a href=\""._BASEDIR."contact.php?action=report&amp;url=viewstory.php?sid=".$stories['sid']."\">"._REPORTTHIS."</a>]");
129 129
 	if(isADMIN && uLEVEL < 4) $tpl->assign("adminlinks", "<div class=\"adminoptions\"><span class='label'>"._ADMINOPTIONS.":</span> ".$adminlinks."</div>");
130
-	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>");
130
+	else if(isMEMBER && (USERUID == $stories['uid'] || array_key_exists(USERUID, $stories['coauthors_array']))) $tpl->assign("adminlinks", "<div class=\"adminoptions\"><span class='label'>"._OPTIONS.":</span> ".$adminlinks."</div>");
131 131
 	$count++;
132 132
 ?>
... ...
@@ -48,21 +48,23 @@ if(empty($chapter)) $chapter = isset($_GET['chapter']) && isNumber($_GET['chapte
48 48
 		dbclose();
49 49
 		exit();
50 50
 	}
51
-	
51
+	 
52 52
 	if($storyinfo['coauthors'] > 0) {
53 53
 	$array_coauthors = array();
54 54
 		$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."'");
55 55
 		while($c = dbassoc($coauth)) {
56 56
 		$array_coauthors[$c['uid']] = $c['penname'];
57 57
 		}
58
-		$storyinfo['coauthors'] = $array_coauthors;
58
+		$storyinfo['coauthors_array'] = $array_coauthors;
59 59
 		unset($array_coauthors);
60 60
 	}
61
-	else $storyinfo['coauthors'] = array();
61
+	else $storyinfo['coauthors_array'] = array();
62
+	 
63
+
62 64
 	//  Check that the story is valid and that the visitor has permissions to read this story
63 65
 	$warning = "";
64 66
 	if(!$storyinfo) $warning = _INVALIDSTORY;
65
-	if(!$storyinfo['valid'] && !isADMIN && ($storyinfo['uid'] != USERUID || !in_array(USERUID, $storyinfo['coauthors']))) $warning = _ACCESSDENIED;
67
+	if(!$storyinfo['valid'] && !isADMIN && ($storyinfo['uid'] != USERUID || !in_array(USERUID, $storyinfo['coauthors_array']))) $warning = _ACCESSDENIED;
66 68
 	if ($storyinfo['rid']  != 0 ) {
67 69
 		$ratingquery = dbquery("SELECT ratingwarning, warningtext FROM " . TABLEPREFIX . "fanfiction_ratings WHERE rid = '" . $storyinfo['rid'] . "' LIMIT 1");
68 70
 		$rating = dbassoc($ratingquery);
... ...
@@ -158,7 +160,7 @@ if($action == "printable") {
158 160
 		$chapterinfo = dbquery("SELECT *, "._PENNAMEFIELD." as penname FROM (".TABLEPREFIX."fanfiction_chapters as c, "._AUTHORTABLE.") WHERE sid = '$sid' AND inorder = '$chapter' AND c.uid = "._UIDFIELD." LIMIT 1");
159 161
 		$c = dbassoc($chapterinfo);
160 162
 		// if the *CHAPTER* hasn't been validated and the viewer isn't an admin or the author throw them a warning.  
161
-		if(empty($c['validated']) && !isADMIN && USERUID != $c['uid'] && !in_array(USERUID, $stories['coauthors'])) {
163
+		if(empty($c['validated']) && !isADMIN && USERUID != $c['uid'] && !in_array(USERUID, $stories['coauthors_array'])) {
162 164
 			$warning = write_error(_ACCESSDENIED);
163 165
 			$tpl->assign("archivedat", $warning);
164 166
 			$tpl->printToScreen( );
... ...
@@ -344,7 +346,7 @@ else {
344 346
 		$printicon = "<a href=\"viewstory.php?action=printable&amp;sid=$sid&amp;textsize=$textsize&amp;chapter=1\" target=\"_blank\"><img src='".(isset($printer) ? $priner : "images/print.gif")."' border='0' alt='"._PRINTER."'></a>";
345 347
 	}
346 348
 	// if the *CHAPTER* hasn't been validated and the viewer isn't an admin or the author throw them a warning.  
347
-	if(!$valid && !isADMIN && USERUID != $chapterauthor && !in_array($chapterauthor, $storyinfo['coauthors'])) {
349
+	if(!$valid && !isADMIN && USERUID != $chapterauthor && !in_array($chapterauthor, $storyinfo['coauthors_array'])) {
348 350
 		$warning = accessDenied( );
349 351
 	}
350 352
 	$stories = $storyinfo;
... ...
@@ -355,7 +357,7 @@ else {
355 357
 	if(isADMIN && uLEVEL < 3) 
356 358
 		$adminlinks = "<div class=\"adminoptions\"><span class='label'>"._ADMINOPTIONS.":</span> "._EDIT." - <a href=\"stories.php?action=editstory&amp;sid=$sid&amp;admin=1\">"._STORY."</a> "._OR." <a href=\"stories.php?action=editchapter&amp;chapid=$chapid&amp;admin=1\">"._CHAPTER."</a> | "._DELETE." - <a href=\"stories.php?action=delete&amp;sid=$sid&amp;admin=1\">"._STORY."</a> "._OR." <a href=\"stories.php?action=delete&amp;chapid=$chapid&amp;sid=$sid&amp;admin=1\">"._CHAPTER."</a></div>";
357 359
 	if(isMEMBER && $favorites) {
358
-		$jumpmenu2 .= "<option value=\"user.php?action=favst&amp;add=1&amp;sid=$sid\">"._ADDSTORY2FAVES."</option><option value=\"user.php?action=favau&amp;add=1&amp;author=".$stories['uid'].(count($storyinfo['coauthors']) ? ",".implode(",", array_keys($storyinfo['coauthors'])) : "")."\">"._ADDAUTHOR2FAVES."</option>";
360
+		$jumpmenu2 .= "<option value=\"user.php?action=favst&amp;add=1&amp;sid=$sid\">"._ADDSTORY2FAVES."</option><option value=\"user.php?action=favau&amp;add=1&amp;author=".$stories['uid'].(count($storyinfo['coauthors_array']) ? ",".implode(",", array_keys($storyinfo['coauthors_array'])) : "")."\">"._ADDAUTHOR2FAVES."</option>";
359 361
 	}
360 362
 	if($reviewsallowed ) {
361 363
 		if(isMEMBER || $anonreviews) {