Karma Log

Started by highlawn, December 02, 2009, 06:50:42 PM

Previous topic - Next topic

highlawn

I see that the karma.php file deletes all row from the karma log if they are older than the karma wait time. Firstly, is there any other way of finding out who is giving karma to whom - yeah, I think I've got a couple of children who are messing about!

If not, then looking at karma.php, I was thinking of commenting out the lines:

db_query("
DELETE FROM {$db_prefix}log_karma
WHERE " . time() . " - logTime > " . (int) ($modSettings['karmaWaitTime'] * 3600), __FILE__, __LINE__);


and the adding the predicate

WHERE " . time() . " - logTime > " . (int) ($modSettings['karmaWaitTime'] * 3600)

to the following

$request = db_query("
SELECT action
FROM {$db_prefix}log_karma
WHERE ID_TARGET = $_REQUEST[uid]
AND ID_EXECUTOR = $ID_MEMBER
LIMIT 1", __FILE__, __LINE__);


so that it reads

$request = db_query("
SELECT action
FROM {$db_prefix}log_karma
WHERE ID_TARGET = $_REQUEST[uid]
AND ID_EXECUTOR = $ID_MEMBER
            AND " . time() . " - logTime > " . (int) ($modSettings['karmaWaitTime'] * 3600)
LIMIT 1", __FILE__, __LINE__);


Would that work - so the logs is not pruned, and the check still works? Or is there more to it than that?

Alternatively, I guess I could create a table called smf_log_karma_copy and before the delete do something like:

db_query("INSERT INTO {$db_prefix}log_karma_copy (SELECT * FROM {$db_prefix}log_karma", __FILE__, __LINE__);

Is that the correct syntax for db_query?

Many Thanks

highlawn

Anyone got any thoughts on this please? Is it in the right place?

Many Thanks

Arantor

Removing the delete and updating the select to be:
$request = db_query("
SELECT action
FROM {$db_prefix}log_karma
WHERE ID_TARGET = $_REQUEST[uid]
AND ID_EXECUTOR = $ID_MEMBER
            AND " . time() . " - logTime > " . (int) ($modSettings['karmaWaitTime'] * 3600) . "
LIMIT 1", __FILE__, __LINE__);


would work (note the extra characters in the second to last line)

You would probably be better creating a duplicate table though if there isn't a mod that would suit this.

highlawn

Thanks for that. Yes, separate table may be best all round. I didn't see any suitable mods but I'll take a second look before I start.

Regards

Arantor


highlawn

Many thanks - I'll take a look at that.

Now, just out of idle curiosity as I was looking through karma.php I noticed there is a function at the end of it called BookOfUnknown() - what's that all about?

highlawn

Quote from: Arantor on December 04, 2009, 05:39:45 AM
http://custom.simplemachines.org/mods/index.php?mod=192 might be of interest.

Just taken a quick look at the instructions for 1.1.10 and I see that it requires some changes to Sources/ManageSettings.php  Sources/Profile-View.php and then  load of Russian language files.

I don't appear to have either ManageSetting or Profile_View and no Russian languages in site! I'm assuming I don't need to worry about the Russian stuff - but do I need any equivalent English stuff?

And what about the missing files? Are they v2.x stuff? The heading of the page clearly states for v1.1.10 but also says its mod ver 2.5 whereas in earlier narrative it suggested mod ver 2.3.1 for 1.1.10.

Should I just download the 2.3.1.zip?

Cheers

Arantor

You won't have ManageSettings.php or Profile-View.php, they are for SMF 2.0 only. As for the language stuff, the bottom most file is Russian only.

Select the little radio button next to Karma_Description_Mod_ver.2.3.1.zip before pressing Parse, which covers the English files for 1.1.10.


As for the Book of Unknown... [Unknown] was the original lead programmer of SMF.

highlawn

I seem to be getting an error in the PHP when making the amendments to the karma.php...

<operation>
<search position="before"><![CDATA[// They haven't, not before now, anyhow.
]]></search>
<add><![CDATA[
/*
]]></add>
</operation>
<operation>
<search position="after"><![CDATA[// It was recently changed the OTHER way... so... reverse it!
]]></search>
<add><![CDATA[
*/
/* They haven't, not before now, anyhow.
           If the key isn't in the array it will return.
           Or if it does exist and it's length is 0 then it will return.
           If Karma Description Mod disable then easy smite or applaud */
if (!empty($modSettings['karmadescmod']))
{
     if (!array_key_exists('Description',$_POST) || strlen($_POST["Description"]) == 0){return;}
}
else
{
        $_POST['Description']='';
}
{ if (empty($action) || empty($modSettings['karmaWaitTime']))
        {
global $func;
$_POST['Description'] = AddSlashes($func['htmlspecialchars']($_POST['Description'], ENT_QUOTES));
          if (!empty($modSettings['karmacensor']))
          censorText($_POST['Description']);
     
//Prepare link
    if (isset ($_REQUEST['topic'])) {
                         $link = ($_REQUEST['topic']).'.msg'.($_REQUEST['m']).'#'.'msg'.($_REQUEST['m']);
                         $link = AddSlashes($link);
                         }
                elseif (isset($_REQUEST['f'])) {
                         $link = 'PM';
                         }

// Put it in the log.
                db_query("
                        INSERT INTO {$db_prefix}log_karma
                                (action, ID_TARGET, Description, link, ID_EXECUTOR, logTime)
                        VALUES ($dir, $_REQUEST[uid], '$_POST[Description]', '$link', $ID_MEMBER, ". time()." )
                        ", __FILE__, __LINE__);
// Change by one.
updateMemberData($_REQUEST['uid'], array($dir == 1 ? 'karmaGood' : 'karmaBad' => '+'));
}
else
{
$request = db_query("
SELECT logTime
FROM {$db_prefix}log_karma
WHERE ID_TARGET=$_REQUEST[uid]
AND ID_EXECUTOR=$ID_MEMBER
ORDER BY logTime DESC
LIMIT 1
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($request);
mysql_free_result($request);

$restricttime = time() - $row['logTime'];
$timelog = (int) ($modSettings['karmaWaitTime'] * 3600);

// If you are gonna try to repeat.... don't allow it.
if ($restricttime < $timelog)
fatal_error($txt['smf62'] . ' ' . $modSettings['karmaWaitTime'] . ' ' . $txt[578] . '.', false);

//Prepare link
    if (isset ($_REQUEST['topic'])) {
                         $link = ($_REQUEST['topic']).'.msg'.($_REQUEST['m']).'#'.'msg'.($_REQUEST['m']);
                         $link = AddSlashes($link);
                         }
                elseif (isset($_REQUEST['f'])) {
                         $link = 'PM';
                         }

// You decided to go back on your previous choice?
db_query("
INSERT INTO {$db_prefix}log_karma
                                (action, ID_TARGET, Description, link, ID_EXECUTOR, logTime)
                        VALUES ($dir, $_REQUEST[uid], '$_POST[Description]', '$link', $ID_MEMBER, ". time()." )
                        ", __FILE__, __LINE__);

]]></add>
</operation>


Once you have applied the two above, then you get an unexpected end of file and the other changes don't appear to shift it.

I think the problem is with the following:

// 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' => '-'));
}


in that the commented bit leaves the final "}" present in the above section and that screws things.

Am I going wrong somewhere here?

Arantor

Please ask in the support thread for the mod in the first instance.

highlawn

OK - sorry about that.

Advertisement: