Page 1 of 5 123 ... LastLast
Results 1 to 10 of 47

Thread: phpBB karma mod

  1. #1

    phpBB karma mod

    I am attempting to code a karma mod for phpBB that acts similar to the one we have here, but only returns one number
    example : -20
    instead of : +100 / -120

    For some reason, I always returns the code that generates an HTML page of
    Foo
    return to index

    I'm probably missing something really obvious and stupid
    so here goes
    Code:
    <?php
    #
    #Karma mod- 
    #
    $x = $_GET['x']; // applaud or smite
    if($x == "applaud")
    {
       $x = 1;
    }
    else
    {
       $x = -1;
    }
    $user = $_GET['u']; //Username of victim
    define('IN_PHPBB', true);
    $phpbb_root_path = './';
    include($phpbb_root_path . 'extension.inc');
    include($phpbb_root_path . 'common.'.$phpEx);
    global $db;
    $sql = "select karma_time from " . USERS_TABLE . " where user_id='$userdata['user_id']'"; //get last time user tried a karma vote
    $result = $db->sql_query($sql);
    $time_old = mysql_fetch_array($result);
    $time = time();
    $diff = $time - $time_old;
    if($diff >= 3600) //make sure they haven't voted in the last hour
       {
          $sql = "select karma from " . USERS_TABLE . " where username='$user'"; //find the victim
          $result = $db->sql_query($sql); 
          $array = mysql_fetch_array($result);
           $karma = $array[0];
          $karma += $x; //change the karma based on appluad or smite.
    
          //update the database with current time() for voter
          $karma_update = "update" . USERS_TABLE . " set karma = '$karma' where username= '$user'";      
          $time_update = "update" . USERS_TABLE . " set karma_time = '$time' where user_id = '$userdata['user_id']'";
          $result = $db->sql_query($karma_update);
          $time_result = $db->sql_query($time_update);    
          if(!$result || !$time_result) //Both gotta happen...
             {
                     echo "<HTML>";
                echo "<p>Foo</p>";
                echo "<a href=index.php>Return to index</a>";
                echo "</HTML>";
                return;
             }
          else
             {
                echo "<HTML>";
                echo "<a href=index.php>Return to index</a>";
                echo "</HTML>";
                return;
             }
       }
    else
       {
          echo "<HTML>";
          echo "Too soon from last karma vote, <a href=index.php>Return to forums</a>";
          echo "</HTML>";
       }
    ?>
    also, i can get the number to show up in the user's profile but when i put this:
    Code:
    Karma: {KARMA}<br /><a href="../../../karma.php?x=applaud&u={postrow.POSTER_NAME}">appluad</a>  /  <a href="../../../karma.php?x=smite&u={postrow.POSTER_NAME}">smite</a><br />
    in the same line after this:
    {postrow.POSTER_POSTS}<br />


    in
    templates/x/viewtopic_body.tpl

    where KARMA is something i defined in includes/usercp_viewprofile.php:
    Code:
     $sql = "select karma from " . USERS_TABLE . " where username='$profiledata[username]'"; 
     $result = $db->sql_query($sql); 
     $array = mysql_fetch_array($result);
     $karma = $array[0];
    then I have
    Code:
    'KARMA' => $karma,
    after
    Code:
    'JOINED' => create_date($lang['DATE_FORMAT'], $profiledata['user_regdate'], $board_config['board_timezone']),
    Thanks for your help and bearing with my stupidity

    :P

    PS
    I'm also going to add something to make sure the "victim" and voter aren't the same person

  2. #2

    Re:phpBB karma mod

    Code:
     if(!$result || !$time_result) //Both gotta happen...
    I thought || was or. For a 0 or smaller value for both $result and $time_result try:

    Code:
     if(!$result and !$time_result) //Both gotta happen...

  3. #3

    Re:phpBB karma mod

    || is or, I'm saying if result or time_result return false, print the error page...

  4. #4

    Re:phpBB karma mod

    Try printing both result and timeresult to find out which variable is causing the problem.

  5. #5

    Re:phpBB karma mod

    nothing prints... but both isset() and empty() return 1 for $result and $time_result...

  6. #6

    Re:phpBB karma mod

    Code:
    $time_update = "update" . USERS_TABLE . " set karma_time = '$time' where user_id = '$userdata['user_id']'";
    when in quotes $userdata['user_id'] should be written as $userdata[user_id]

  7. #7

    Re:phpBB karma mod

    Thanks gorn, also while retyping part of the query, I noticed the problem:
    Code:
    "update"
    should have been
    Code:
    "update "
    It works now, If anybody wants the working code, just pm me

  8. #8

    Re:phpBB karma mod

    Okay, I finally wrote a README for how to install it, http://countach44.mine.nu/projects/karma.tar.gz

  9. #9

    Re:phpBB karma mod

    [quote author=countach44 link=board=9;threadid=8472;start=0#msg78610 date=1076952997]
    Okay, I finally wrote a README for how to install it, http://countach44.mine.nu/projects/karma.tar.gz
    [/quote]

    Nice job countach44 on writing the Karma mod!

  10. #10

    Re:phpBB karma mod

    ??? Thanks ???

Similar Threads

  1. Forums now upgraded to vBulletin from phpBB
    By peter in forum Announcements and Suggestions
    Replies: 1
    Last Post: 01-17-2006, 04:40 PM
  2. phpBB installation problem
    By imported_root in forum Linux - Software, Applications & Programming
    Replies: 9
    Last Post: 09-13-2004, 01:10 AM
  3. Welcome to phpBB 2
    By in forum General Chat
    Replies: 1
    Last Post: 04-19-2004, 10:53 PM
  4. phpbb
    By elovkoff in forum Linux - Hardware, Networking & Security
    Replies: 2
    Last Post: 05-30-2003, 03:27 PM
  5. YaBB vs. phpBB
    By airhead in forum General Chat
    Replies: 3
    Last Post: 06-24-2002, 03:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •