NP_MemberScore.php Code

<?
 
/*
NP_MemberScore:
 
Depends on NP_ModComments (which needs to be installed first)
Allows you to show the global member score (based on the comment moderation scores)
 
You are free to use this code but it is provided as is. I will try to support it but
I'm a student and I often just don't have the time.
 
When you find a bug or have a certain feature request you can always contact me at 
sirtim@fuckhedz.com or (till MS closes down their IM network to GAIM users) on MSN (sirpsycho@fuckhedz.com)
 
** Usage **
 
In comment template part:
 
<%MemberScore%>
 
In member skin:
 
<%MemberScore%>
 
** Tweaking **
 
If you added more options to NP_ModComments you'll have to change $choises in the calculate function
to represent the change.
 
If you use only positive scores I think you'll have to set base to 0 and change this line:
 
$total = $base + (($average * $base) / ($choises/2));
 
to:
 
$total = $base + (($average * $base) / ($choises));
 
But I didn't test it so play around with it.
 
 
*/
 
class NP_MemberScore extends NucleusPlugin {
 
	function getName() {
		return 'Memberscore'; 
	}
 
	function getAuthor()  { 
		return 'Tim Broddin'; 
	}
 
	function getURL()	{
		return 'http://www.fuckhedz.com/'; 
	}
 
	function getVersion() {
		return '1.0a'; 
	}
 
	function getDescription() { 
		return 'A plugin that calculates a score for a member based on comment moderations';
	}
 
	function NP_MembersScore() {
 
	}
 
	function doTemplateCommentsVar(&$item, &$comment) {
		$memberid = $comment['memberid'];
		$user = $comment['user'];
 
		$choises = 8;
		$base = 50;
 
		if ($memberid > 0) {
			$result = sql_query("SELECT sum(m.score) as total FROM nucleus_plugin_modcomments m, nucleus_comment c WHERE m.commentid = c.cnumber AND c.cmember = $memberid");
			$result2 = sql_query("SELECT count(m.score) as total FROM nucleus_plugin_modcomments m, nucleus_comment c WHERE m.commentid = c.cnumber AND c.cmember = $memberid");
		} else {
			$result = sql_query("SELECT sum(m.score) as total FROM nucleus_plugin_modcomments m, nucleus_comment c WHERE m.commentid = c.cnumber AND c.cuser = '$user'");
			$result2 = sql_query("SELECT count(m.score) as total FROM nucleus_plugin_modcomments m, nucleus_comment c WHERE m.commentid = c.cnumber AND c.cuser = '$user'");	
		}
 
		if (mysql_num_rows($result) > 0) {
				$total = mysql_result($result,'total');
		}
 
 
		$votes = mysql_result($result2, 'total');
		if ($votes == 0) { 
			$votes = 1;
		} else {
 
		}
 
		$this->calculate($total,$votes);
 
	}
 
	function doSkinVar($skinType) {
		global $memberid;
 
		$result = sql_query("SELECT sum(m.score) as total FROM nucleus_plugin_modcomments m, nucleus_comment c WHERE m.commentid = c.cnumber AND c.cmember = $memberid");
		$result2 = sql_query("SELECT count(m.score) as total FROM nucleus_plugin_modcomments m, nucleus_comment c WHERE m.commentid = c.cnumber AND c.cmember = $memberid");
 
		if (mysql_num_rows($result) > 0) {
				$total = mysql_result($result,'total');
		}
 
 
		$votes = mysql_result($result2, 'total');
		if ($votes == 0) { 
			$votes = 1;
		} else {
 
		}
 
		$this->calculate($total,$votes);	
 
	}
 
	function calculate($subtotal,$votes) {
		$choises = 8;
		$base = 50;	
 
		$average = $subtotal / $votes;
		$total = $base + (($average * $base) / ($choises/2));
 
		echo $total;
	}
}
?>
memberscorecode.txt · Last modified: 2007/11/17 22:24 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki