09 Reputation System Add On By pdq

Started by Mindless, July 21, 2012, 08:55:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mindless


MelvinMeow

Line 111...
return "Rep: ".$posneg . "<br /><br /><a href='java script:;' onclick=\"PopUp('$TBDEV['baseurl']/reputation.php?pid={$user['id']}&amp;locale=".$mode."','Reputation',400,241,1,1);\"><img src='".$BASEURL."/pic/forumicons/giverep.jpg' border='0' alt='Add reputation:: {$user['username']}' title='Add reputation:: {$user['username']}' /></a>";

Of the last section of code in your post is reporting a error.
PHP Parse error:  syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Mindless

#1
Quote
'pdq'

This is an addition to the existing reputation system in 09 source,  :yahoo:
this mod/addon allows you to add rep to comments, torrent uploaders, and members profiles as well as forum posts.
Just made it last night so needs a good testing :P
if you use any anonymous mods, make sure to check the code and comment/uncomment accordingly :]

ok, we need to add some
SQL (could have used int field, but enums so easy =])
Code (sql) Select
ALTER TABLE `reputation` ADD `locale` ENUM('posts', 'comments', 'torrents', 'users') NOT NULL DEFAULT 'posts' AFTER `dateadd`, ADD INDEX (locale);

now do some edits
in reputation.php:

find:
Code (php) Select
$check = isset( $input['pid'] ) ? is_valid_id( $input['pid'] ) : FALSE;

if( ! $check )
{
rep_output( 'Incorrect Access' );
}

///////////////////////////////////////////////
// check the post actually exists!
///////////////////////////////////////////////
$forum = mysql_query( "SELECT posts.topicid, posts.userid, forums.minclassread,
users.username, users.reputation
FROM posts
LEFT JOIN topics ON topicid = topics.id
LEFT JOIN forums ON topics.forumid = forums.id
LEFT JOIN users ON posts.userid = users.id
WHERE posts.id ={$input['pid']}" );

// does it or don't it?
if( ! mysql_num_rows( $forum ) )
{
rep_output( 'Post Does Not Exist - Incorrect Access' );
}

///////////////////////////////////////////////
// ok, lets proceed
///////////////////////////////////////////////
$res = mysql_fetch_assoc( $forum ) or sqlerr(__LINE__,__FILE__);

if( $CURUSER['class'] < $res['minclassread'] ) // check permissions! Dun want sneaky pests lookin!
{
rep_output( 'Wrong Permissions' );
}


replace with:

Code (php) Select
/// weeeeeeeeee =]
$check = isset($input['pid']) ? is_valid_id($input['pid']) : false;

$locales = array('posts', 'comments', 'torrents', 'users');
if (isset($input['locale']) && (in_array($input['locale'], $locales)))
$rep_locale = isset($input['locale']) ? $input['locale'] : 'posts';


if (!$check)
{
rep_output('Incorrect Access');
}

if ($rep_locale == 'posts')
{
///////////////////////////////////////////////
// check the post actually exists!
///////////////////////////////////////////////
$forum = mysql_query("SELECT posts.topicid AS locale, posts.userid, forums.minclassread,
users.username, users.reputation
FROM posts
LEFT JOIN topics ON topicid = topics.id
LEFT JOIN forums ON topics.forumid = forums.id
LEFT JOIN users ON posts.userid = users.id
WHERE posts.id ={$input['pid']}");
}

if ($rep_locale == 'comments')
{
///////////////////////////////////////////////
// check the comment actually exists!
///////////////////////////////////////////////

$forum = mysql_query("SELECT comments.id, comments.user AS userid,
comments.torrent AS locale,
users.username, users.reputation
FROM comments
LEFT JOIN users ON comments.user = users.id
WHERE comments.id = {$input['pid']}");

//uncomment the following  if use comments.anonymous field
/**
* $forum = mysql_query("SELECT comments.id, comments.user AS userid, comments.anonymous AS anon,
* comments.torrent AS locale,
* users.username, users.reputation
* FROM comments
* LEFT JOIN users ON comments.user = users.id
* WHERE comments.id = {$input['pid']}");
**/
}

if ($rep_locale == 'torrents')
{
///////////////////////////////////////////////
// check the uploader actually exists!
///////////////////////////////////////////////
$forum = mysql_query("SELECT torrents.id as locale, torrents.owner AS userid,
users.username, users.reputation
FROM torrents
LEFT JOIN users ON torrents.owner = users.id
WHERE torrents.id ={$input['pid']}");

//uncomment the following  if use torrents.anonymous field
/**
* $forum = mysql_query("SELECT torrents.id as locale, torrents.owner AS userid, torrents.anonymous AS anon,
* users.username, users.reputation
* FROM torrents
* LEFT JOIN users ON torrents.owner = users.id
* WHERE torrents.id ={$input['pid']}");
**/
}
if ($rep_locale == 'users')
{
///////////////////////////////////////////////
// check the user actually exists!
///////////////////////////////////////////////
$forum = mysql_query("SELECT id AS userid, username, reputation
FROM users
WHERE id ={$input['pid']}");
} // end

// does it or don't it?
if (!mysql_num_rows($forum))
rep_output($this_rep.' Does Not Exist - Incorrect Access');

///////////////////////////////////////////////
// ok, lets proceed
///////////////////////////////////////////////
$res = mysql_fetch_assoc($forum) or sqlerr(__line__, __file__);

if (isset($res['minclassread'])) // 'post'

if ($CURUSER['class'] < $res['minclassread'])
// check permissions! Dun want sneaky pests lookin!

{
rep_output('Wrong Permissions');
}

switch ($rep_locale)
{
case 'comments':
$this_rep = 'Comment';
break;
case 'torrents':
$this_rep = 'Torrent';
break;
case 'users':
$this_rep = 'Profile';
break;
default:
$this_rep = 'Post';
}


If you want users to be allowed to rep a users profile as much as they wish, minus flood checking do the following edit [
find:
Code (php) Select
if( mysql_num_rows( $repeat) > 0 ) // blOOdy eedjit check!
{
rep_output( 'You have already added Rep to this entry!' ); // Is insane!
}


replace with:
Code (php) Select
if(mysql_num_rows($repeat) > 0 && $rep_locale != 'users') // blOOdy eedjit check!
{
rep_output('You have already added Rep to this '.$this_rep.'!'); // Is insane!
}

]

find:
Code (php) Select
$save = array( 'reputation' => $score,
   'whoadded'   => $CURUSER['id'],
   'reason' => sqlesc($reason),
   'dateadd'   => TIMENOW,
   'postid' => (int)$input['pid'],
   'userid' => $res['userid']
);


replace with:
Code (php) Select
$save = array( 'reputation' => $score,
   'whoadded'   => $CURUSER['id'],
   'reason' => sqlesc($reason),
   'dateadd'   => TIMENOW,
   'locale' => sqlesc($rep_locale),
   'postid' => (int)$input['pid'],
   'userid' => $res['userid']
);

find:
Code (php) Select
$query = mysql_query( "select r.*, leftby.id as leftby_id, leftby.username as leftby_name
from reputation r
left join users leftby on leftby.id=r.whoadded
where postid={$input['pid']}
order by dateadd DESC" );

replace with:
Code (php) Select
$query = mysql_query( "select r.*, leftby.id as leftby_id, leftby.username as leftby_name
from reputation r
left join users leftby on leftby.id=r.whoadded
where postid={$input['pid']}
AND r.locale = ".sqlesc($input['locale'])."
order by dateadd DESC" );



find:
Code (php) Select
else
{
$rep = 'Even'; //Ok, dunno what to do, so just make it quits!
}


below that add:
Code (php) Select
switch ($rep_locale)
{
case 'comments':
$rep_info = sprintf("Your reputation on <a href='".$BASEURL."/details.php?id=%d&amp;viewcomm=%d#comm%d' target='_blank'>this Comment</a> is %s<br/ >Total: %s points.", $res['locale'], $input['pid'], $input['pid'], $rep, $total);
break;
case 'torrents':
$rep_info = sprintf("Your reputation on <a href='".$BASEURL."/details.php?id=%d' target='_blank'>this Torrent</a> is %s<br/ >Total: %s points.", $input['pid'], $rep, $total);
break;
case 'users':
$rep_info = sprintf("Your reputation on <a href='".$BASEURL."/userdetails.php?id=%d' target='_blank'>your profile</a> is %s<br/ >Total: %s points.", $input['pid'], $rep, $total);
break;
default:
$rep_info = sprintf("Your reputation on <a href='".$BASEURL."/forums.php?action=viewtopic&amp;topicid=%d&amp;page=p%d#%d' target='_blank'>this Post</a> is %s<br/ >Total: %s points.", $res['locale'], $input['pid'], $input['pid'], $rep, $total);
}


find:
Code (php) Select
$rep_info = sprintf("Your reputation on <a href='$BASEURL/forums.php?action=viewtopic&amp;topicid=%d&amp;page=p%d#%d' target='_blank'>this post</a> is %s.", $res['topicid'], $input['pid'], $input['pid'], $rep );
change to:
Code (php) Select
//$rep_info = sprintf("Your reputation on <a href='$BASEURL/forums.php?action=viewtopic&amp;topicid=%d&amp;page=p%d#%d' target='_blank'>this post</a> is %s.", $res['topicid'], $input['pid'], $input['pid'], $rep );   
find:
Code (php) Select
$rep_text = sprintf("What do you think of %s's post?", $res['username']);
$negativerep = ( $is_mod || $GVARS['g_rep_negative'] ) ? TRUE : FALSE;

change to:
Code (php) Select
$res['anon'] = (isset($res['anon'])?$res['anon']:'no');
$rep_text = sprintf("What do you think of %s's ".$this_rep."?", ($res['anon'] == 'yes'?'Anonymous':$res['username']));
$negativerep = ($is_mod || $GVARS['g_rep_negative'] ) ? TRUE : FALSE;


find:
Code (php) Select
Your comments on this post:<br />

replace with:Your comments on this ".$this_rep.":<br />

find:
Code (php) Select
<input type='hidden' name='pid' value='{$input['pid']}' />

below that add:
Code (php) Select
<input type='hidden' name='locale' value='{$input['locale']}' />
         
                     
in /forums/forum_topicview.php:
find:
Code (php) Select
$member_reputation = $arr['username'] != '' ? get_reputation($arr) : '';
replace with:
Code (php) Select
$member_reputation = $arr['username'] != '' ? get_reputation($arr, 'posts') : '';

in bittorrent.php:
find:
Code (php) Select
$member_reputation = get_reputation($CURUSER, 1);
replace with:
Code (php) Select
$member_reputation = get_reputation($CURUSER);

in userdetails.php:
find:
Code (php) Select
<table width='100%' border='1' cellspacing='0' cellpadding='5'>

add this below:
Code (php) Select
$member_reputation = get_reputation($user, 'users');
$HTMLOUT .='<tr><td class="rowhead" valign="top" align="right" width='1%'>Reputation</td><td align='left' width='99%'>{$member_reputation}<br />
</td></tr>';

in details.php:
find the main query like:
Code (php) Select
$res = mysql_query("SELECT torrents.seeders, torrents.banned, torrents.leechers, torrents.info_hash, torrents.filename, LENGTH(torrents.nfo) AS nfosz, torrents.last_action AS lastseed, torrents.numratings, torrents.name, IF(torrents.numratings < $minvotes, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.owner, torrents.save_as, torrents.descr, torrents.visible, torrents.size, torrents.added, torrents.views, torrents.hits, torrents.times_completed, torrents.id, torrents.type, torrents.numfiles, categories.name AS cat_name, users.username FROM torrents LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE torrents.id = $id")
change it to like:
Code (php) Select
$res = mysql_query("SELECT torrents.seeders, torrents.banned, torrents.leechers, torrents.info_hash, torrents.filename, LENGTH(torrents.nfo) AS nfosz, torrents.last_action AS lastseed, torrents.numratings, torrents.name, IF(torrents.numratings < $minvotes, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.owner, torrents.save_as, torrents.descr, torrents.visible, torrents.size, torrents.added, torrents.views, torrents.hits, torrents.times_completed, torrents.id, torrents.type, torrents.numfiles, categories.name AS cat_name, users.username, users.reputation FROM torrents LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE torrents.id = $id")

we added ', users.reputation' to the query :P

still in details.php where you want it to show add:
Code (php) Select
$member_reputation = get_reputation($row, 'torrents');
$HTMLOUT .='<tr><td class="rowhead" valign="top" align="right" width='1%'>Torrent<br/>Reputation</td><td align='left' width='99%'>{$member_reputation} (counts towards uploaders Reputation)<br />
</td></tr>';


still in details.php find like:
Code (php) Select
$subres = mysql_query("SELECT comments.id, text, user, comments.added, editedby, editedat, avatar, warned, ".
  "username, title, class, donor FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = " .
  "$id ORDER BY comments.id ".$pager['limit']) or sqlerr(__FILE__, __LINE__);


add in ', reputation' like:
Code (php) Select
$subres = mysql_query("SELECT comments.id, text, user, comments.added, editedby, editedat, avatar, warned, ".
  "username, title, reputation, class, donor FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = " .
  "$id ORDER BY comments.id ".$pager['limit']) or sqlerr(__FILE__, __LINE__);
   
now in /include/torrenttable_functions.php:
find:
Code (php) Select
$htmlout .="<td align='center' width='150' style='padding: 0px'><img width='150' src=\"{$avatar}\" alt='' /></td>\n";
replace with: (style to your own liking :p)                
Code (php) Select
$htmlout .="<td align='center' width='150' style='padding: 0px'><img width='150' src=\"{$avatar}\" alt='' /><br />".get_reputation($row, 'comments')."</td>\n";

now replace your get_reputation function with:
Code (php) Select
function get_reputation($user, $mode = 0, $rep_is_on = TRUE)
{
global $TBDEV;
$member_reputation = "";
if( $rep_is_on )
{
@include 'cache/rep_cache.php';
// ok long winded file checking, but it's much better than file_exists
if( ! isset( $reputations ) || ! is_array( $reputations ) || count( $reputations ) < 1)
{
return '<span title="Cache doesn\'t exist or zero length">Reputation: Offline</span>';
}

$user['g_rep_hide'] = isset( $user['g_rep_hide'] ) ? $user['g_rep_hide'] : 0;
           
// uncomment if you use anymous mod(s)
//$user['username'] = ($user['anonymous'] != 'yes') ? $user['username'] : 'Anonymous';

// Hmmm...bit of jiggery-pokery here, couldn't think of a better way.
$max_rep = max(array_keys($reputations));
if($user['reputation'] >= $max_rep)
{
$user_reputation = $reputations[$max_rep];
}
else
foreach($reputations as $y => $x)
{
if( $y > $user['reputation'] ) { $user_reputation = $old; break; }
$old = $x;
}

//$rep_is_on = TRUE;
//$CURUSER['g_rep_hide'] = FALSE;

$rep_power = $user['reputation'];
$posneg = '';
if( $user['reputation'] == 0 )
{
$rep_img   = 'balance';
$rep_power = $user['reputation'] * -1;
}
elseif( $user['reputation'] < 0 )
{
$rep_img   = 'neg';
$rep_img_2 = 'highneg';
$rep_power = $user['reputation'] * -1;
}
else
{
$rep_img   = 'pos';
$rep_img_2 = 'highpos';
}
            /**
if( $rep_power > 500 )
{
// work out the bright green shiny bars, cos they cost 100 points, not the normal 100
$rep_power = ( $rep_power - ($rep_power - 500) ) + ( ($rep_power - 500) / 2 );
}
            **/
// shiny, shiny, shiny boots...
// ok, now we can work out the number of bars/pippy things
$pips = 12;
            switch ($mode)
            {
        case 'comments':
            $pips = 12;
            break;
        case 'torrents':
            $pips = 1003;
            break;
        case 'users':
            $pips = 970;
            break;
        case 'posts':
            $pips = 12;
            break;
         default:
            $pips = 12; // statusbar
            }

$rep_bar = intval($rep_power / 100);
if( $rep_bar > 10 )
{
$rep_bar = 10;
}

if( $user['g_rep_hide'] ) // can set this to a group option if required, via admin?
{
$posneg = 'off';
$rep_level = 'rep_off';
}
else
{ // it ain't off then, so get on with it! I wanna see shiny stuff!!
$rep_level = $user_reputation ? $user_reputation : 'rep_undefined';// just incase

for( $i = 0; $i <= $rep_bar; $i++ )
{
if( $i >= 5 )
{
$posneg .= "<img src='pic/rep/reputation_$rep_img_2.gif' border='0' alt=\"Reputation Power $rep_power\n{$user['username']} $rep_level\" title=\"Reputation Power $rep_power {$user['username']} $rep_level\" />";
}
else
{
$posneg .= "<img src='pic/rep/reputation_$rep_img.gif' border='0' alt=\"Reputation Power $rep_power\n{$user['username']} $rep_level\" title=\"Reputation Power $rep_power {$user['username']} $rep_level\" />";
}
}
}

// now decide the locale
            if($mode != '')
             return "Rep: ".$posneg . "<br /><br /><a href='java script:;' onclick=\"PopUp('{$TBDEV['baseurl']}/reputation.php?pid={$user['id']}&amp;locale=".$mode."','Reputation',400,241,1,1);\"><img src='{$TBDEV['baseurl']}/pic/forumicons/giverep.jpg' border='0' alt='Add reputation:: {$user['username']}' title='Add reputation:: {$user['username']}' /></a>";
            else
             return " ".$posneg;


} // END IF ONLINE

// default
return '<span title="Set offline by admin setting">Rep System Offline</span>';
}


^^ in the above function there are somethings you can edit, such as reputation image amounts, i think that's everything, feedback, tips welcome

=]