اكتير جربت بمود الكارمات المحدودة بس شكلو ما رح يظبط دائما عم يعطي خطأ رغم اني عدلت يدويا عليه بس ماعم يظبط
بتمنى حدا اجربلي ياه وشفلي المشكلة وين
./Sources/Karma.php
Find:
// The user ID _must_ be a number, no matter what.
$_REQUEST['uid'] = (int) $_REQUEST['uid'];
Add Before:
// Get the PM or Post that we have to record that this Karma has been given to...
if(!empty($_REQUEST['m'])
&& LimitKarma_message_exists((int) $_REQUEST['m'], 'm'))
{
$message_id = (int) $_REQUEST['m'];
$type = 'm';
}
elseif(!empty($_REQUEST['pm'])
&& LimitKarma_message_exists((int) $_REQUEST['pm'], 'pm'))
{
$message_id = (int) $_REQUEST['pm'];
$type = 'pm';
}
// Otherwise, show an error message.
else
fatal_lang_error('LimitKarma_error2', false);
Find:
// 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' => '-'));
}
Replace With:
// Is the user not limited by the Limit Karma Mod?
if(!is_LimitedByKarma($message_id, $type))
{
// 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' => '-'));
}
// Finally, increment the karma count.
increment_LimitKarmaCount($message_id, $type);
}
// Well, if they are limited then show the user an error message.
else
fatal_lang_error('LimitKarma_error', false);
Find (at the end of the file):
?>
Add Before:
// Function to work out, if the current user can give karma to a specific PM or Post.
// Assume that they are allowed to give karma normally, just find out if they are restricted by the Limit Karma Mod or not.
function is_LimitedByKarma($id, $type)
{
global $db_prefix, $user_info, $ID_MEMBER, $modSettings, $user_settings;
$max_count = 0;
// Go through and check this users membergroups for a higher max count.
foreach($user_info['groups'] as $group_id)
{
// Do we have a supergroup? With no max limit? And a valid group?
if(empty($modSettings['LimitKarma_'.$group_id]) && !(!empty($user_settings['ID_POST_GROUP']) && ($group_id == $user_settings['ID_POST_GROUP']) && empty($modSettings['permission_enable_postgroups'])))
return false;
// Otherwise, check to see if this group has a higher max limit, then previous groups.
elseif(!empty($modSettings['LimitKarma_'.$group_id])
&& ($modSettings['LimitKarma_'.$group_id] > $max_count))
$max_count = $modSettings['LimitKarma_'.$group_id];
}
$count = 0;
// Try to work out the current count of the karma for this post.
$request = db_query("
SELECT count
FROM {$db_prefix}limit_karma
WHERE ID_MSG = $id
AND ID_EXECUTOR = '$ID_MEMBER'
AND type = '$type'
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) > 0)
list ($count) = mysql_fetch_row($request);
// Don't forget to free the db request!
mysql_free_result($request);
// Is our count value more than our max count value? If so, then return true.
if($count >= $max_count)
return true;
// Otherwise, we have just let them add some more karma.
return false;
}
// Function to increment the count of Karma for a particular PM/Post.
function increment_LimitKarmaCount($id, $type)
{
global $db_prefix, $ID_MEMBER;
// Try to find an already existing value;
$request = db_query("
SELECT count
FROM {$db_prefix}limit_karma
WHERE ID_EXECUTOR = '$ID_MEMBER'
AND ID_MSG = '$id'
AND type = '$type'
LIMIT 1", __FILE__, __LINE__);
// Try to get the count value.
if (mysql_num_rows($request) > 0)
list ($count) = mysql_fetch_row($request);
// Don't forget to free the db request!
mysql_free_result($request);
// If we have no count value, then assume its 1.
if(empty($count))
$count = 1;
// Otherwise, we can increment the count value.
else
$count++;
// Finally save the new count value, and be happy!!! :D
db_query("
REPLACE INTO {$db_prefix}limit_karma
(ID_EXECUTOR, ID_MSG, count, type)
VALUES
('$ID_MEMBER', '$id', '$count', '$type')", __FILE__, __LINE__);
}
// Function to check if this message actually exists.
function LimitKarma_message_exists($msg_id, $type)
{
global $db_prefix;
if($type == 'pm')
{
$select_var = 'ID_PM';
$table = 'pm_recipients';
}
else
{
$select_var = 'ID_MSG';
$table = 'messages';
}
// Try to find an already existing value;
$request = db_query("
SELECT $select_var
FROM {$db_prefix}$table
WHERE $select_var = '$msg_id'", __FILE__, __LINE__);
// Try to get the count value.
if (mysql_num_rows($request) > 0)
list ($return) = mysql_fetch_row($request);
// Don't forget to free the db request!
mysql_free_result($request);
// If we have a valid message ID.
if(!empty($return))
return true;
// Otherwise, return false.
return false;
}