1 (edited by tj9991 2006-01-20 01:51)

Topic: Karma Mod 1.0.3

##
##
##        Mod title:  Karma Mod
##
##      Mod version:  1.0.3
##   Works on PunBB:  1.2.*
##     Release date:  2006-01-15
##           Author:  Trevor Slocum (tslocum@gmail.com)
##
##      Description:  Adds the ability for your users to praise/smite each other.
##
##   Affected files:  viewtopic.php
##                    userlist.php
##                    profile.php
##
##       Affects DB:  Yes
##
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##

This mod lets users give/take away karma from each other.

Right now it's extremely basic, since I'm brand new to the PunBB modding community, but I am working on it as an ongoing project.

Download it at http://punres.org/files.php?pid=166

I have a demo set up at http://karmaforum.pun.tj9991.com/

And, I am using it on my main forum at http://www.mkdsc.com/

I started this because I was looking for a karma mod, but when I found one, it looked like it was abandoned.

Hope you guys like it smile

Re: Karma Mod 1.0.3

I tried it on your test forum, it looks nice!

Looking for a certain modification for your forum? Please take a look here before posting.

Re: Karma Mod 1.0.3

tj9991
I like it mod!

I want to have mod of rating of karma. How do it?

That here wrong:

<?php
$result = $db->query ('SELECT id, username, karmavotes FROM'.$db->
prefix.'users ORDER BY karmavotes DESC LIMIT 10') 
or error('Unable to fetch user data', __FILE__, __LINE__, $db->error());
while ($data = $db->fetch_assoc($result))
{
echo "".'<a href="profile.php?id='.$data['id'].'">'.pun_htmlspecialchars($data['username']).'</a> ('.$data['karmavotes'].') '."\n";
}
?>
ERROR - MIRROR

4

Re: Karma Mod 1.0.3

Nice mod.  What is the Golden Coins thing on your site?

t2

Re: Karma Mod 1.0.3

The golden coins are the alias I set as cash, for the cashmod.

@HitMan

Try this...

<?php
$result = $db->query ('SELECT id, username, karma FROM'.$db->
prefix.'users ORDER BY karma DESC LIMIT 10') 
or error('Unable to fetch user data', __FILE__, __LINE__, $db->error());
while ($data = $db->fetch_assoc($result))
{
echo "".'<a href="profile.php?id='.$data['id'].'">'.pun_htmlspecialchars($data['username']).'</a> ('.$data['karma'].') '."\n";
}
?>

Re: Karma Mod 1.0.3

tj9991

I have Error:
Error: Unable to fetch user data.

Warning: ob_start(): output handler 'ob_gzhandler' cannot be used twice in /home/y/s/public_html/include/functions.php on line 977

sad

ERROR - MIRROR

7 (edited by tj9991 2006-01-18 07:31)

Re: Karma Mod 1.0.3

And you're positive you ran the install_mod.php file?

Edit:  Oops, derp.  I know the problem.

<?php
$result = $db->query ('SELECT id, username, karma FROM '.$db->
prefix.'users ORDER BY karma DESC LIMIT 10') 
or error('Unable to fetch user data', __FILE__, __LINE__, $db->error());
while ($data = $db->fetch_assoc($result))
{
echo "".'<a href="profile.php?id='.$data['id'].'">'.pun_htmlspecialchars($data['username']).'</a> ('.$data['karma'].') '."\n";
}
?>

Replace it with that.

Re: Karma Mod 1.0.3

tj9991

Cool!!!
Thanks smile

ERROR - MIRROR

Re: Karma Mod 1.0.3

I installed this but it doesn't show the "Praise" and "Smite" links in the posts? I ran the install file. I copied all the code in. It doesn't give me any errors at all. It does show "Karma: 0" in everyones posts, but the links don't show up to actually praise or smite people.

What did I do wrong? Can Admins not see the links?

http://www.jasoco.net/geekpub/viewtopic.php?id=13

10 (edited by Dr.Jeckyl 2006-01-19 15:57)

Re: Karma Mod 1.0.3

i checked your source and it's not there. i have the mod installed and this is what i get when i view my source:

<li class="postedit">
Karma: 

    <a href="karma.php?post=1&vote=1" _base_href="http://www.domain.com/"> Props </a>

 - 

    <a href="karma.php?post=1&vote=0" _base_href="http://www.domain.com/"> Clown </a>

 | 
</li>

this may not solve your issue but it's a start. good luck.

note: i changed the outputted links from smite/praise to clown/props respectively on my boards.

~James
FluxBB - Less is more

11 (edited by Jasoco 2006-01-19 19:02)

Re: Karma Mod 1.0.3

There's supposed to be some code in the ViewTopic.php file that adds those two links.

I checked and yes I did put the code in. For some reason it's not accepting it. sad

I tried installing again and it says it was already installed so it's there but it's not working.

So it definitely has something to do with th part starting:

if ($cur_post['poster_id'] > 1&&!$pun_user['is_guest'])

Can you check your php file (The actual file, not the source of the page in your browser) and tell me what that's supposed to be? It's not validating the user as a user. As if it is thinking everyone's a guest.

12 (edited by Jasoco 2006-01-20 00:32)

Re: Karma Mod 1.0.3

I think I got it working. Fortunately I'm able to understand code and see it in my head most of the time. The Readme has the code placement in the wrong place! That last part should be put inside the { } brackets that have the comment of "// If the poster is a registered user.". The Readme has the placement on line ~266 after a part of the code that is inside the "Guest" Ie...Else statement.

I reuploaded, refreshed the page and tested the links. They're working now.

FYI to the author to make that last part more clear.

Edit: I have also added a simple modification to display the users Karma on the User List page.

It's pretty easy. Open Userlist.php and do the following.

Find the line:

                <th class="tc2" scope="col"><?php echo $lang_common['Title'] ?></th>

And add the following after it:

                <th class="tc3" scope="col">Karma</th>

Find the following:

                    <td class="tc2"><?php echo $user_title_field ?></td>

And add the following after it:

                    <td class="tc3"><?php echo $user_data['karma'] ?></td>

Then lastly find the line that begins:

$result = $db->query('SELECT u.id, u.username,

And modify it to include "u.karma, " before the "u.id" so it looks like this:

$result = $db->query('SELECT u.karma, u.id, u.username,

You will now have a Karma column in the User List.

13

Re: Karma Mod 1.0.3

No no, it's placed in the right spot.  Or at least, it will work where it's at.

    // If the poster is a guest (or a user that has been deleted)
    else
    {
        $username = pun_htmlspecialchars($cur_post['username']);
        $user_title = get_title($cur_post);

        if ($pun_user['g_id'] < PUN_GUEST)
            $user_info[] = '<dd>IP: <a href="moderate.php?get_host='.$cur_post['id'].'">'.$cur_post['poster_ip'].'</a>';

        if ($pun_config['o_show_user_info'] == '1' && $cur_post['poster_email'] != '' && !$pun_user['is_guest'])
            $user_contacts[] = '<a href="mailto:'.$cur_post['poster_email'].'">'.$lang_common['E-mail'].'</a>';
    }
    
    if ($cur_post['poster_id'] > 1&&!$pun_user['is_guest'])    
        $post_actions[] = '<li class="postedit">Karma: <a href="karma.php?post='.$cur_post['id'].'&vote=1">'.'Praise user'.'</a> - <a href="karma.php?post='.$cur_post['id'].'&vote=0">'.'Smite user'.'</a>';

    // Generation post action array (quote, edit, delete etc.)

That's how it should look.

The Readme has the placement on line ~266 after a part of the code that is inside the "Guest" Ie...Else statement.

Here's part of the readme.txt:

#
#---------[ 10. FIND (line: 266) ]--------------------------------------------
#

        if ($pun_config['o_show_user_info'] == '1' && $cur_post['poster_email'] != '' && !$pun_user['is_guest'])
            $user_contacts[] = '<a href="mailto:'.$cur_post['poster_email'].'">'.$lang_common['E-mail'].'</a>';
    }

It has the bracket in the part where you should be searching for, so you should place it after that.

If you guys are still having problems and this doesnt fix it, let me know.

14 (edited by Jasoco 2006-01-20 00:41)

Re: Karma Mod 1.0.3

No, I figured it out. Except that I put it inside the Is User part. I'll move it though.

Also check out my above User List modification. Feel free to use it for the MOD.

Check it out!
http://www.jasoco.net/geekpub/userlist.php

I think next I'm going to see if I can add the Karma value to the users profile. As well as an editable box for the Admins.

15 (edited by tj9991 2006-01-20 00:55)

Re: Karma Mod 1.0.3

I've released 1.0.2, to include Jasoco's userlist.php modification, thanks Jasoco smile

I was going to get around to it, really tongue

The demo forum has been upgraded to 1.0.2

16 (edited by Jasoco 2006-01-20 01:06)

Re: Karma Mod 1.0.3

"..and I helped!"

You are welcome!

Edit: A neat suggestion I can think of would be to make it so Admins and Moderators can give users Karma without a 24 hour limit while the other users would have the limit.

17 (edited by tj9991 2006-01-20 01:49)

Re: Karma Mod 1.0.3

Hmm, that sounds like a good idea.

Since they are going to be able to modify the karma manually, they might as well be able to praise/smite relatively without having to go into the users' profile.

I'm working on modding profile.php to have karma in the administration section of the menu.

Edit:
Okay, that was harder than I thought.

I've released 1.0.3, which features adminstrators able to manually change the users' karma from the profile menu.

Also, don't forget to reupload karma.php, I've changed it to allow administrators to praise/smite users without the time restriction.

More suggestions are appreciated smile

18

Re: Karma Mod 1.0.3

Installed! Works great. big_smile

19 (edited by Jasoco 2006-01-20 11:29)

Re: Karma Mod 1.0.3

Here's another MOD for the User List. Sorting by Karma.

This one was tricky for someone like me who is still learning PHP, but here goes:

First find line ~46. Change it from:

$sort_by = (!isset($_GET['sort_by']) || $_GET['sort_by'] != 'username' && $_GET['sort_by'] != 'registered' && ($_GET['sort_by'] != 'num_posts' || !$show_post_count)) ? 'username' : $_GET['sort_by'];

To:

$sort_by = (!isset($_GET['sort_by']) || $_GET['sort_by'] != 'username' && $_GET['sort_by'] != 'registered' && $_GET['sort_by'] != 'karma' && ($_GET['sort_by'] != 'num_posts' || !$show_post_count)) ? 'username' : $_GET['sort_by'];

Next simply add:

<option value="karma"<?php if ($sort_by == 'karma') echo ' selected="selected"' ?>>Karma</option>

Below the:

<?php if ($show_post_count): ?>                        <option value="num_posts"<?php if ($sort_by == 'num_posts') echo ' selected="selected"' ?>><?php echo $lang_ul['No of posts'] ?></option>

Line. (This line should be ~89. So the added line will end up being 90.)

Congratulations, now you can sort the User List by how much Karma they have.