Need help with my new Karma mod...

Discussion forum for MOD Writers regarding MOD Development.
iGuru
Registered User
Posts: 56
Joined: Sat May 05, 2007 10:37 pm
Location: New Zealand
Contact:

Need help with my new Karma mod...

Post by iGuru »

Last edited by iGuru on Thu May 31, 2007 9:31 am, edited 4 times in total.
PACraddock
Registered User
Posts: 32
Joined: Sun Sep 24, 2006 10:43 am

Post by PACraddock »

I'll take a look at your code later on, but given that I'm also half working on a karma MOD (but I might end up stealing some of your code if I can't get it to work), I'll share what I had before I lost some changes (due to my being stupid and not copying every single file to my new MacBook before letting my sister delete a bunch of stuff from my old iMac).

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Find out when voter last changed someone's karma
$sql = 'SELECT karma_time, user_id FROM ' . USERS_TABLE . " WHERE user_id = {$user->data['user_id']}";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$voter_id = $row['user_id'];
$last_change = $row['karma_time'];

// Get variables
$topic_id = request_var('t', '');
$user = request_var('u', '');
$vote = request_var('x', '');

$sql = 'SELECT karma FROM ' . USERS_TABLE . " WHERE user_id = $user";
$result = $db->sql_query($sql);
$karma = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

if ($voter_id == $user)
{
    trigger_error($user->lang['NO_SELF_KARMA'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=$topic_id") . '">', '</a>'));
}
else
{
    if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
    {
        trigger_error($user->lang['NO_USER_KARMA'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=$topic_id") . '">', '</a>'));
    }
    else
    {
        $time = time();
        $time_elapsed = $time - $last_change;
        // Stop voter from changing karma during a delay period, fixed in the "phpbb3_config" table's "karma_time_limit" row
        if ($time_elapsed >= 60 * $config['karma_time_limit'])
        {
            if ($vote == 'applaud')
            {
                if ($karma < 8)
                {
                    $sql = 'UPDATE ' . USERS_TABLE . " SET karma = karma + 1 WHERE user_id = $user";
                    $db->sql_query($sql);
                }
            }
            else
            {
                $sql = 'UPDATE ' . USERS_TABLE . " SET karma = karma - 1 WHERE user_id = $user";
                $db->sql_query($sql);        
                // Add bans on reaching -8 karma
                if ($karma <= -8)
                {
                    $sql = 'INSERT INTO ' . BANLIST_TABLE . " VALUES (0, $user, '', NULL)";
                    $db->sql_query($sql);
                }
            }
            // Update the database with the current time() for the voter
            $sql = 'UPDATE ' . USERS_TABLE . " SET karma_time = $time WHERE user_id = $voter_id";
            $db->sql_query($sql);
            $redirect = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=$topic_id");
        }
        else
        {
            trigger_error($user->lang['TOO_SOON'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t=$topic_id") . '">', '</a>'));
        }
    }
}

?>
As you can see, this method involves setting up a "karma_time" row in the USERS_TABLE, and then each time karma gets updated, so does karma_time, and then $config['karma_time_limit'] determines how many minutes are needed before a user's karma can be changed again (by a non admin).
Since doing that code, the concept of karma for my board changed a little, so it went from "-8 to 8" to "-20 to 100". Also, there are some errors in that code, but I can't remember which ones.

Now, about setting a user post count before they can change karma, just modify your code in the following way:

Code: Select all

    if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
    {
          some code about unlimited changes, but they also affect karma_time
    }
    else if [insert code about post count, something like "$post_count > 10" if you do an SQL query to call that up directly]
    {
          some code about changes limited in time
    }
    else
    {
          some error about not being able to change karma
    }
Changing the link between the two in the ACP is out of my league, haven't worked on the ACP (yet).


I was trying to apply labels to different karma levels (e.g. if karma is 88 to 99, it will show "Karma: Divine (93)"), and that's where I'm currently stuck, but hopefully your code will inspire me.
iGuru
Registered User
Posts: 56
Joined: Sat May 05, 2007 10:37 pm
Location: New Zealand
Contact:

Re:

Post by iGuru »

Thanks, I fixed the post count.

I edited my code up again :)

Now I mainly need:
Timer (not sure how to put that in my code)
Can't karma yourself (matching user id's?)
Change plus and minus image to become transparent
Add controls in the ACP
and more as I think of them.
iGuru
Registered User
Posts: 56
Joined: Sat May 05, 2007 10:37 pm
Location: New Zealand
Contact:

Re: Re:

Post by iGuru »

iGuru wrote:Thanks, I fixed the post count.

I edited my code up again :)

Now I mainly need:
Timer (not sure how to put that in my code)
Can't karma yourself (matching user id's?)
Change plus and minus image to become transparent
Add controls in the ACP
and more as I think of them.
AH no I had a post count check on the actual viewtopic.php page.
PACraddock
Registered User
Posts: 32
Joined: Sun Sep 24, 2006 10:43 am

Re: Re:

Post by PACraddock »

iGuru wrote:Timer (not sure how to put that in my code)
Can't karma yourself (matching user id's?)
Check my code ;)
iGuru
Registered User
Posts: 56
Joined: Sat May 05, 2007 10:37 pm
Location: New Zealand
Contact:

Re: Re:

Post by iGuru »

iGuru wrote:
iGuru wrote:Thanks, I fixed the post count.

I edited my code up again :)

Now I mainly need:
Timer (not sure how to put that in my code)
Can't karma yourself (matching user id's?)
Change plus and minus image to become transparent
Add controls in the ACP
and more as I think of them.
AH no I had a post count check on the actual viewtopic.php page.
Ah, I setup my mySQL database connection manually, ie. you enter in username, password and database yourself.
iGuru
Registered User
Posts: 56
Joined: Sat May 05, 2007 10:37 pm
Location: New Zealand
Contact:

Re: Re:

Post by iGuru »

iGuru wrote:
iGuru wrote:
iGuru wrote:Thanks, I fixed the post count.

I edited my code up again :)

Now I mainly need:
Timer (not sure how to put that in my code)
Can't karma yourself (matching user id's?)
Change plus and minus image to become transparent
Add controls in the ACP
and more as I think of them.
AH no I had a post count check on the actual viewtopic.php page.
Ah, I setup my mySQL database connection manually, ie. you enter in username, password and database yourself.
Ah - I'm not good at this :lol:

How would I add a timer into my code (i have the user being karmaed but not the logged in user)
iGuru
Registered User
Posts: 56
Joined: Sat May 05, 2007 10:37 pm
Location: New Zealand
Contact:

Re: Re:

Post by iGuru »

iGuru wrote:
iGuru wrote:
iGuru wrote:
iGuru wrote:Thanks, I fixed the post count.

I edited my code up again :)

Now I mainly need:
Timer (not sure how to put that in my code)
Can't karma yourself (matching user id's?)
Change plus and minus image to become transparent
Add controls in the ACP
and more as I think of them.
AH no I had a post count check on the actual viewtopic.php page.
Ah, I setup my mySQL database connection manually, ie. you enter in username, password and database yourself.
Ah - I'm not good at this :lol:

How would I add a timer into my code (i have the user being karmaed but not the logged in user)
And I didn't put anything in like define_inphpbb etc...
iGuru
Registered User
Posts: 56
Joined: Sat May 05, 2007 10:37 pm
Location: New Zealand
Contact:

Re: Re:

Post by iGuru »

iGuru wrote:
iGuru wrote:
iGuru wrote:
iGuru wrote:
iGuru wrote:Thanks, I fixed the post count.

I edited my code up again :)

Now I mainly need:
Timer (not sure how to put that in my code)
Can't karma yourself (matching user id's?)
Change plus and minus image to become transparent
Add controls in the ACP
and more as I think of them.
AH no I had a post count check on the actual viewtopic.php page.
Ah, I setup my mySQL database connection manually, ie. you enter in username, password and database yourself.
Ah - I'm not good at this :lol:

How would I add a timer into my code (i have the user being karmaed but not the logged in user)
And I didn't put anything in like define_inphpbb etc...
Ah, my code is so basic compared to yours - I'm only 13 years old... :geek:
PACraddock
Registered User
Posts: 32
Joined: Sun Sep 24, 2006 10:43 am

Post by PACraddock »

Create a second "karma_time" row ("karma_time_vote", or something like it) that applies to the voter instead of the "user getting karma". Then call it up as something like "$voter_time".

Apart from that, edit your posts rather than posting thrice in a row ;)

Don't worry about having a basic code: that's how you learn.
iGuru
Registered User
Posts: 56
Joined: Sat May 05, 2007 10:37 pm
Location: New Zealand
Contact:

Re:

Post by iGuru »

PACraddock wrote:Create a second "karma_time" row ("karma_time_vote", or something like it) that applies to the voter instead of the "user getting karma". Then call it up as something like "$voter_time".
I don't have anything in place yet for time between karmas, i would like it to be a one day wait though.

ie. I don't have a first karma_time row.

What I need first is how to call up the logged in user's ID.

Should I place these in my code?:
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
iGuru
Registered User
Posts: 56
Joined: Sat May 05, 2007 10:37 pm
Location: New Zealand
Contact:

Re: Need help with my new Karma mod...

Post by iGuru »

EDITED CODE AGAIN now it won't display the plus and minus if the userID is the same as your own.

It's good how my karma.php won't work unless it has a valid referrer. (ie. must have been linked to from somewhere)
azzurri
Registered User
Posts: 910
Joined: Fri Jul 21, 2006 7:48 pm

Re: Need help with my new Karma mod...

Post by azzurri »

I wrote this in a request thread...

In my old forum I had a Karma mod that was extremly popular. It really made the quality of the posts better since people were happy to receive karma points.

This is what it should be able to do:

Give karma point togheter with comment (to withdraw points is not needed since it is so negative)

There should be a statistic page in the profile where you can view users karma points and comments along with info about in what thread/post he got the karma

Maybe a statistics page with top 20 karma users
iGuru
Registered User
Posts: 56
Joined: Sat May 05, 2007 10:37 pm
Location: New Zealand
Contact:

Re: Need help with my new Karma mod...

Post by iGuru »

azzurri wrote:I wrote this in a request thread...

In my old forum I had a Karma mod that was extremly popular. It really made the quality of the posts better since people were happy to receive karma points.

This is what it should be able to do:

Give karma point togheter with comment (to withdraw points is not needed since it is so negative)

There should be a statistic page in the profile where you can view users karma points and comments along with info about in what thread/post he got the karma

Maybe a statistics page with top 20 karma users
Currently, you can remove the negative karma button. Comments are currently not used but karma points show on each user's profile. A statistics page with the top 20 karma users will be implemented at one of the later stages.
azzurri
Registered User
Posts: 910
Joined: Fri Jul 21, 2006 7:48 pm

Re: Need help with my new Karma mod...

Post by azzurri »

A comment function would make it more powerful. People like to get positive karma but they like more to know why they got it, some feedback you know? Otherwise it all loses its point a bit.

Also in my old karma mod I managed to implement so that people get a notification PM whenever they receive karma.

Anyhow...good luck to you!
Locked

Return to “[3.0.x] MOD Writers Discussion”