News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Interesting karma result

Started by Elmacik, December 15, 2005, 04:13:24 PM

Previous topic - Next topic

Elmacik

I commented this line in Karma.php :
// $dir = $_REQUEST['sa'] != 'applaud' ? -1 : 1;

Isnt this the line adding +1 or -1 to the total karma of the user? Although its commented, karma still works.
Although it is commented out and changed to +5 or -5, it still increases / decreases one by one..

Whats wrong with me? :-\
What do I know wrong? :D
Home of Elmacik

JayBachatero

Try decreasing the Karma to see if it decreases by 5.  "request[subaction] not equal to applaud ? -1 :1;"   I think that's what it means.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Elmacik

I tried already, nothing changes. If I change like:   -1 : 5
Then both [applaud] and [smite] decreases. If I change like:  -5 : 1
It just works the same as original...

Should I work with subactions then ?
Home of Elmacik

JayBachatero

I'm not reaslly sure.  I know that sa = subaction.  You need someone that understands this more than I do to help you out.  What is it that you are trying to do exactly?
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Elmacik

#4
I am trying to set if the karma changer is admin (or a moderator in the board that karma is being changed) then karma should increase / decrease 5 points (or something different) and when the karma changer is a standard user, then karma change should work normally.

Its easy for admins to click 5 times I know :P But not for moderators and not that easy when its set to higher than 5 ;)
Damn :P
Home of Elmacik

bloc

As i see this...
$dir = $_REQUEST['sa'] != 'applaud' ? -1 : 1;

...if the subaction is NOT 'applaud', then $dir is filled with -1 (false?). If it is then its filled with 1 (true). Maybe its just a test to see if the subaction is indeed "applaud" ?

Elmacik

#6
So you mean the "real" action that changes karma is NOT related with this line then?
Edit: It checks the result here: (if applaud -true- or not -false-)


// Change by one.
updateMemberData($_REQUEST['uid'], array($dir == 1 ? 'karmaGood' : 'karmaBad' => '+'));


Edit again: Changing that plus (+) doesnt work either.. Makes karma change stop.
Damn its really bad to be a n00b :P

Again edit:
It inserts the value of $dir into the log_karma table.

REPLACE INTO {$db_prefix}log_karma
(action, ID_TARGET, ID_EXECUTOR, logTime)
VALUES ($dir, $_REQUEST[uid], $ID_MEMBER, " . time() . ')', __FILE__, __LINE__);


I am really confused now :-\
Home of Elmacik

JayBachatero

I think its in this area. 

// They haven't, not before now, anyhow.
if (empty($action) || empty($modSettings['karmaWaitTime']))
{
// Put it in the log.
db_query("
REPLACE INTO {$db_prefix}log_karma
(action, ID_TARGET, ID_EXECUTOR, logTime)
VALUES ($dir, $_REQUEST[uid], $ID_MEMBER, " . time() . ')', __FILE__, __LINE__);

// Change by one.
updateMemberData($_REQUEST['uid'], array($dir == 1 ? 'karmaGood' : 'karmaBad' => '+'));
}
else
{
// If you are gonna try to repeat.... don't allow it.
if ($action == $dir)
fatal_error($txt['smf62'] . ' ' . $modSettings['karmaWaitTime'] . ' ' . $txt[578] . '.', false);

// You decided to go back on your previous choice?
db_query("
UPDATE {$db_prefix}log_karma
SET action = $dir, logTime = " . time() . "
WHERE ID_TARGET = $_REQUEST[uid]
AND ID_EXECUTOR = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);

// It was recently changed the OTHER way... so... reverse it!
if ($dir == 1)
updateMemberData($_REQUEST['uid'], array('karmaGood' => '+', 'karmaBad' => '-'));
else
updateMemberData($_REQUEST['uid'], array('karmaBad' => '+', 'karmaGood' => '-'));
}


I found something interesting while looking for this.  Scroll down and you will see a special function ;)  Old easter egg.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Elmacik

JayBachatero,
Yes, I knew its in that area. But cant find the thing :P
And what you gave is not the same as mine. I think those are from SMF 1.1 RC2 ? ;)
Because my codes doesnt have an "else" for updateMemberData (as you see above)
Home of Elmacik

JayBachatero

Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Elmacik

Any changes in that area is not affecting the karma change...
Home of Elmacik

bloc

I took a look at Karma.php to really se this...that line is as i thought just a check to see if its appluading or smiting. The insertion of the value is done here:
// Change by one.
updateMemberData($_REQUEST['uid'], array($dir == 1 ? 'karmaGood' : 'karmaBad' => '+'));
}

As you see..if $dir is 1 ( as the previous line checked) its applauding, and the function updateMemberData gets a "karmagood" item with value "+". if not it gets a "karmabad" with value "+". It then traverses this array in updateMemberData (in Subs.php) along with other things and simply add 1 to either karmagood or karmabad locations of the members table.

If you are going to modify how many karmapoints someone gets..I would rather write directly to the memberdata table - since this function seems to be assuming a value of 1 all the time.

Elmacik

#12
Bloc,
Thanks for the answer, if you see the 7th post of this topic, you will see that I already realised where it adds the changes to the database.

But I am not that wise, I cant do it :P
How should I write the data to table directly?
Home of Elmacik

JayBachatero

Or you can go to the members profile and change the Karma :P
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Elmacik

The best shot! :P
Well, if I am the admin, I can do it easly, but if thats a moderator, then? :)
Home of Elmacik

Advertisement: