Karma Description Mod

Started by Grek.Kamchatka, September 11, 2005, 11:48:26 PM

Previous topic - Next topic

rsarwar

I have installed this mod perfectly with no problems and enabled it. However when I go to the main page it doesnt show me [karma stat] .. I am using Bloc's theme Black22 (hxxp:www.o-yaar.com/covers [nonactive]) and it wont show. If I switch to SMF Default it shows up. Can anyone please tell me what coding needs to be copied from the Default template over to the black22 theme?

BTW Excellent Mod cant wait to get it working! :D

rsarwar

If I change the below:


        <install>
                <readme type="inline">Karma Description Mod (ver. 1.1)
Tested with SMF 1.1 Beta 3 Public and now with SMF 1.0.5

Use it at your own risk. Don't forget to BACKUP!!!</readme>
                <modification>Karma_Description_Mod.xml</modification>
              <code>db_change.php</code>
                <require-file name="Viewkarma.php" destination="$sourcedir" />
                <require-file name="Viewkarma.template.php" destination="$boarddir/Themes/default" />
                <require-file name="DescriptionKarma.template.php" destination="$boarddir/Themes/default" />
        </install>


To this .. would it install it for the Black22 theme?:


        <install>
                <readme type="inline">Karma Description Mod (ver. 1.1)
Tested with SMF 1.1 Beta 3 Public and now with SMF 1.0.5

Use it at your own risk. Don't forget to BACKUP!!!</readme>
                <modification>Karma_Description_Mod.xml</modification>
              <code>db_change.php</code>
                <require-file name="Viewkarma.php" destination="$sourcedir" />
                <require-file name="Viewkarma.template.php" destination="$boarddir/Themes/black22" />
                <require-file name="DescriptionKarma.template.php" destination="$boarddir/Themes/black22" />
        </install>


I have the changed the desitination to point to the Black22 theme ..

m00h

great job! thanks for the new release!

my users only want to write an opinion if the karma is neg., so could you modify this feature? ;)

Grek.Kamchatka

Hi m00h. If you want your users write only negative Karma Description, you must do next:
First, BackUp your Karma.php
Second, open Karma.php and find code:

//Loading Template of Description
if (!empty($modSettings['karmadescmod'])){
        loadTemplate('DescriptionKarma');}

Replace it with this code:

//Loading Template of Description
if (!empty($modSettings['karmadescmod']) && ($_REQUEST['sa'] == "smite"))
        loadTemplate('DescriptionKarma');


Then, find this:

if (!empty($modSettings['karmadescmod'])){
if (!array_key_exists('Description',$_POST) || strlen($_POST["Description"]) == 0){return;}}

And replace with this:

if (!empty($modSettings['karmadescmod']) && ($_REQUEST['sa'] == "smite")){
if (!array_key_exists('Description',$_POST) || strlen($_POST["Description"]) == 0){return;}}

if (!empty($modSettings['karmadescmod']) && ($_REQUEST['sa'] == "applaud"))
$_POST['Description'] = "applaud";


And last, find this code:

{ if ( empty($action) || empty($modSettings['karmaWaitTime']))
        { $_POST['Description'] = AddSlashes($_POST['Description']);
                // Put it in the log.

Replace with:

{ if ( empty($action) || empty($modSettings['karmaWaitTime']))
        { if (empty($modSettings['karmadescmod'])) $_POST['Description'] = "Mod was disable";
                // Put it in the log.


That's all, enjoy =)

Woops, sorry, just remember=) if you want your users look ONLY negative karma in Karma log, you must do next...
First, BackUp your Viewkarma.php
Second, open Viewkarma.php and find this code in function Viewkarma():

$request = db_query("
SELECT COUNT(action)
FROM {$db_prefix}log_karma
", __FILE__, __LINE__);

Replace it with this:

$request = db_query("
SELECT COUNT(action)
FROM {$db_prefix}log_karma
WHERE action = -1
", __FILE__, __LINE__);


Then, find:

$result = db_query("
                             SELECT lk.ID_TARGET, lk.ID_EXECUTOR, lk.logTime, lk.action, lk.Description, memt.realName AS targetName, meme.realName AS executorName
                             FROM {$db_prefix}log_karma AS lk, {$db_prefix}members AS memt, {$db_prefix}members AS meme                             
                             WHERE memt.ID_MEMBER = lk.ID_TARGET
                             AND meme.ID_MEMBER = lk.ID_EXECUTOR
                             ORDER BY $_REQUEST[sort] " . (isset($_REQUEST['asc']) ? 'ASC' : 'DESC') . "
                             LIMIT $context[start], $modSettings[karmamaxmembers]", __FILE__, __LINE__);

And replace it with:

$result = db_query("
                             SELECT lk.ID_TARGET, lk.ID_EXECUTOR, lk.logTime, lk.action, lk.Description, memt.realName AS targetName, meme.realName AS executorName
                             FROM {$db_prefix}log_karma AS lk, {$db_prefix}members AS memt, {$db_prefix}members AS meme                             
                             WHERE memt.ID_MEMBER = lk.ID_TARGET
                             AND meme.ID_MEMBER = lk.ID_EXECUTOR
                             AND lk.action = -1
                             ORDER BY $_REQUEST[sort] " . (isset($_REQUEST['asc']) ? 'ASC' : 'DESC') . "
                             LIMIT $context[start], $modSettings[karmamaxmembers]", __FILE__, __LINE__);
                                                 

And last...if you want your users can see only negative karma in their profiles (I mean own karma), you must do next:
In Viewkarma.php function OwnKarma() find:


$request = db_query("
SELECT COUNT(action)
FROM {$db_prefix}log_karma
WHERE ID_TARGET=".$_REQUEST['u']."
", __FILE__, __LINE__);

Replace with:

$request = db_query("
SELECT COUNT(action)
FROM {$db_prefix}log_karma
WHERE ID_TARGET=".$_REQUEST['u']."
AND action = -1
", __FILE__, __LINE__);


Then:

$result = db_query("
                             SELECT lk.ID_TARGET, lk.ID_EXECUTOR, lk.logTime, lk.action, lk.Description, memt.realName AS targetName, meme.realName AS executorName
                             FROM {$db_prefix}log_karma AS lk, {$db_prefix}members AS memt, {$db_prefix}members AS meme                             
                             WHERE memt.ID_MEMBER = lk.ID_TARGET
                             AND meme.ID_MEMBER = lk.ID_EXECUTOR
                             AND lk.ID_TARGET = ".$_REQUEST['u']."
                             ORDER BY $_REQUEST[sort] " . (isset($_REQUEST['asc']) ? 'ASC' : 'DESC') . "
                             LIMIT $context[start], $modSettings[karmamaxmembers]", __FILE__, __LINE__);

Replace with

$result = db_query("
                             SELECT lk.ID_TARGET, lk.ID_EXECUTOR, lk.logTime, lk.action, lk.Description, memt.realName AS targetName, meme.realName AS executorName
                             FROM {$db_prefix}log_karma AS lk, {$db_prefix}members AS memt, {$db_prefix}members AS meme                             
                             WHERE memt.ID_MEMBER = lk.ID_TARGET
                             AND meme.ID_MEMBER = lk.ID_EXECUTOR
                             AND lk.ID_TARGET = ".$_REQUEST['u']."
                             AND lk.action = -1
                             ORDER BY $_REQUEST[sort] " . (isset($_REQUEST['asc']) ? 'ASC' : 'DESC') . "
                             LIMIT $context[start], $modSettings[karmamaxmembers]", __FILE__, __LINE__);
                                                                                  

And in the function OtherKarma()
Find:

$request = db_query("
SELECT COUNT(action)
FROM {$db_prefix}log_karma
WHERE ID_EXECUTOR=".$_REQUEST['u']."
", __FILE__, __LINE__);

And replace with:

$request = db_query("
SELECT COUNT(action)
FROM {$db_prefix}log_karma
WHERE ID_EXECUTOR=".$_REQUEST['u']."
AND action = -1
", __FILE__, __LINE__);

Then find:

$result = db_query("
                             SELECT lk.ID_TARGET, lk.ID_EXECUTOR, lk.logTime, lk.action, lk.Description, memt.realName AS targetName, meme.realName AS executorName
                             FROM {$db_prefix}log_karma AS lk, {$db_prefix}members AS memt, {$db_prefix}members AS meme                             
                             WHERE memt.ID_MEMBER = lk.ID_TARGET
                             AND meme.ID_MEMBER = lk.ID_EXECUTOR
                             AND lk.ID_EXECUTOR = ".$_REQUEST['u']."
                             ORDER BY $_REQUEST[sort] " . (isset($_REQUEST['asc']) ? 'ASC' : 'DESC') . "
                             LIMIT $context[start], $modSettings[karmamaxmembers]", __FILE__, __LINE__);

And replace it with:

$result = db_query("
                             SELECT lk.ID_TARGET, lk.ID_EXECUTOR, lk.logTime, lk.action, lk.Description, memt.realName AS targetName, meme.realName AS executorName
                             FROM {$db_prefix}log_karma AS lk, {$db_prefix}members AS memt, {$db_prefix}members AS meme                             
                             WHERE memt.ID_MEMBER = lk.ID_TARGET
                             AND meme.ID_MEMBER = lk.ID_EXECUTOR
                             AND lk.ID_EXECUTOR = ".$_REQUEST['u']."
                             AND lk.action = -1
                             ORDER BY $_REQUEST[sort] " . (isset($_REQUEST['asc']) ? 'ASC' : 'DESC') . "
                             LIMIT $context[start], $modSettings[karmamaxmembers]", __FILE__, __LINE__);


Now that's all =)

Grek.Kamchatka

Look at new version(1.3) of my mod. It include all you wanted functions.

m00h

Grek_Kamchatka, YOU'RE  G R E A T !!

Big thanks! :-* :-* :-*

Your newest release: Can I set the permissions, that the user can view only the own karma ( Who change my karma? + Whom I change karma? ) and not the whole list?

rsarwar

What about my request to this working in another theme other than the default? :( :'( :(

xenovanis

"Insanity: doing the same thing over and over again and expecting different results."

Grek.Kamchatka

#48
Sorry, but it is very easy...i think you'll made it yourself.
After installing the Karma Description Mod, open /Themes/black22/BoardIndex.template.php and find this code:

<a href="', $scripturl, '?action=recent">', $txt[234], '</a>', $context['show_stats'] ? '<br />
<a href="' . $scripturl . '?action=stats">' . $txt['smf223'] . '</a>' : '', '


After it, add this code:

';
if (!empty($modSettings['karmadescmod']))/*{echo'   <a href="'.$scripturl.'?action=viewkarma">' . $txt['statkarma'].'</a>',' ';}*/
{  if ($context['show_karmastat'])
                echo '
                        <a href="', $scripturl, '?action=viewkarma">'. $txt['statkarma'].'</a>',' ';
}
echo'


Then, open /Themes/black22/languages/index.english.php and add this code at the end of the file.

//Karma Description Mod
$txt['karmaview'] = 'The survey of a change in the reputation of users';
$txt['whykarmamod'] = 'Karma change';
$txt['Description'] = 'No Description';
$txt['karmamoder'] = 'Please, write here for what you change karma for this user';
$txt['karmarequare'] = '(Require field)';
$txt['karmawho'] = 'Who';
$txt['karmawhos'] = 'Whom';
$txt['karmawhat'] = 'What (+/-)';
$txt['karmadesc'] = 'For What';
$txt['karmatime'] = 'When';
$txt['karmanumb'] = 'Values: ';
$txt['statkarma'] = '[Karma Stat]';
$txt['viewkarma_title'] = 'Karmachange description';
$txt['karma_back'] = '< Back';
$txt['karma_continue'] = 'Continue >';
$txt['karmadescappl'] = ' (Applaud)';
$txt['karmadescsmi'] = ' (Smite)';


That's all. Easy, isn't it? =)
Anything else?

m00h

QuoteAnything else?

Hmmm yep! ;D

QuoteYour newest release: Can I set the permissions, that the user can view only the own karma ( Who change my karma? + Whom I change karma? ) and not the whole list?

Grek.Kamchatka

I'll think about it. It's easy to.

Grek.Kamchatka

So, for you, m00h.

Do you want the separate rights? (View whole list right and view own&other right)
If not, you must do this.
In Sources/Profile.php find

// Set the profile layer to be displayed.
        $context['template_layers'][] = 'profile';


After it add this code:

$context['show_karmastat'] = allowedTo('karmalog_view') && empty($modsettings['karmapermiss']);


And then, in Profile.template.php
find:

// If karma enabled show the members karma.
        if ($modSettings['karmaMode'] == '1')
        {        echo '
                                <tr>
                                        <td>
                                                <b>', $modSettings['karmaLabel'], ' </b>
                                        </td><td>
                                                ', ($context['member']['karma']['good'] - $context['member']['karma']['bad']), '
                                        </td>
                                </tr>';
        if (!empty($modSettings['karmadescmod']) && !empty($modSettings['karmalinks']))
        {        echo'
                                <tr>
                                        <td><a href="'. $scripturl . '?action=ownkarma;u=' . $context['member']['id']. '">'.$txt['who_change_my_karma'].'</a></td>
                                        <td><a href="'. $scripturl . '?action=otherkarma;u=' . $context['member']['id'] . '">'.$txt['whom_i_change_karma'].'</a></td>
                                </tr>'
                                ;}
         }
                               
        elseif ($modSettings['karmaMode'] == '2')
        {        echo '
                                <tr>
                                        <td>
                                                <b>', $modSettings['karmaLabel'], ' </b>
                                        </td><td>
                                                +', $context['member']['karma']['good'], '/-', $context['member']['karma']['bad'], '
                                        </td>
                                </tr>';
        if (!empty($modSettings['karmadescmod']) && !empty($modSettings['karmalinks']))
        {        echo'
                                <tr>
                                        <td><a href="'. $scripturl . '?action=ownkarma;u=' . $context['member']['id'] . '">'.$txt['who_change_my_karma'].'</a></td>
                                        <td><a href="'. $scripturl . '?action=otherkarma;u=' . $context['member']['id'] . '">'.$txt['whom_i_change_karma'].'</a></td>
                                </tr>
                                '
                                ;}
        }
        echo '
                                <tr>
                                        <td><b>', $txt[233], ': </b></td>
                                        <td>', $context['member']['registered'], '</td>
                                </tr><tr>
                                        <td><b>', $txt['lastLoggedIn'], ': </b></td>
                                        <td>', $context['member']['last_login'], '</td>
                                </tr>';

        // If the person looking at the summary is an admin the the account isn't activated, give the admin the ability to do it themselves.
        if ($user_info['is_admin'] && !$context['member']['is_activated'])
                echo '
                                <tr>
                                        <td colspan="2"><hr size="1" width="100%" class="hrcolor" /></td>
                                </tr><tr>
                                        <td colspan="2">
                                                <span style="color: red;">' . $txt['account_not_activated'] . '</span>&nbsp;(<a href="' . $scripturl . '?action=profile2;sa=activateAccount;userID=' . $context['member']['id'] . ';sesc=' . $context['session_id'] . '">' . $txt['account_activate'] . '</a>)
                                        </td>
                                </tr>';

        // Messenger type information.


And replace it with this code:

// If karma enabled show the members karma.
        if ($modSettings['karmaMode'] == '1')
        {        echo '
                                <tr>
                                        <td>
                                                <b>', $modSettings['karmaLabel'], ' </b>
                                        </td><td>
                                                ', ($context['member']['karma']['good'] - $context['member']['karma']['bad']), '
                                        </td>
                                </tr>';
        if (!empty($modSettings['karmadescmod']) && !empty($modSettings['karmalinks']))
        {   if ($context['show_karmastat'])     echo'
                                <tr>
                                        <td><a href="'. $scripturl . '?action=ownkarma;u=' . $context['member']['id']. '">'.$txt['who_change_my_karma'].'</a></td>
                                        <td><a href="'. $scripturl . '?action=otherkarma;u=' . $context['member']['id'] . '">'.$txt['whom_i_change_karma'].'</a></td>
                                </tr>'
                                ;}
         }
                               
        elseif ($modSettings['karmaMode'] == '2')
        {        echo '
                                <tr>
                                        <td>
                                                <b>', $modSettings['karmaLabel'], ' </b>
                                        </td><td>
                                                +', $context['member']['karma']['good'], '/-', $context['member']['karma']['bad'], '
                                        </td>
                                </tr>';
        if (!empty($modSettings['karmadescmod']) && !empty($modSettings['karmalinks']))
        {   if ($context['show_karmastat'])     echo'
                                <tr>
                                        <td><a href="'. $scripturl . '?action=ownkarma;u=' . $context['member']['id'] . '">'.$txt['who_change_my_karma'].'</a></td>
                                        <td><a href="'. $scripturl . '?action=otherkarma;u=' . $context['member']['id'] . '">'.$txt['whom_i_change_karma'].'</a></td>
                                </tr>
                                '
                                ;}
        }
        echo '
                                <tr>
                                        <td><b>', $txt[233], ': </b></td>
                                        <td>', $context['member']['registered'], '</td>
                                </tr><tr>
                                        <td><b>', $txt['lastLoggedIn'], ': </b></td>
                                        <td>', $context['member']['last_login'], '</td>
                                </tr>';

        // If the person looking at the summary is an admin the the account isn't activated, give the admin the ability to do it themselves.
        if ($user_info['is_admin'] && !$context['member']['is_activated'])
                echo '
                                <tr>
                                        <td colspan="2"><hr size="1" width="100%" class="hrcolor" /></td>
                                </tr><tr>
                                        <td colspan="2">
                                                <span style="color: red;">' . $txt['account_not_activated'] . '</span>&nbsp;(<a href="' . $scripturl . '?action=profile2;sa=activateAccount;userID=' . $context['member']['id'] . ';sesc=' . $context['session_id'] . '">' . $txt['account_activate'] . '</a>)
                                        </td>
                                </tr>';

        // Messenger type information.


In KDM ver.1.4 it fixed.

Grek.Kamchatka

New version 1.5
Now you can display users karma in Karma log opposit the usernames.

m00h

And new version 1.6

You are unbelieveable!

m00h

#54
Could you make this http://www.simplemachines.org/community/index.php?topic=49088.msg363510#msg363510 to a default function? Otherwise I have to change the code every time :(

And what about a german Translation? :)

Big Thanks for this mod!!!

Grek.Kamchatka

Quote from: m00h on October 07, 2005, 01:18:41 PM
Could you make this http://www.simplemachines.org/community/index.php?topic=49088.msg363510#msg363510 to a default function? Otherwise I have to change the code every time :(
I'll think about it.

Quote from: m00h on October 07, 2005, 01:18:41 PM
And what about a german Translation? :)
I don't know german language) But, if you need it, you can use a translator))

Grek.Kamchatka

In new version of the mod, you can remove any log messages. (Only for admin)
See screenshot:
http://www.pkforum.ru/index.php?action=dlattach;topic=6046.0;id=15723

Gwion

I couldn't get this to work.
My board is SMF 1.0.5

I installed via package manager, all fine.
I switched to SMF default template to see the mod.
Nothing. No new stats link etc.
The only difference which might be due to the mod was that it tells me I have to wait 1 hour before I can applaud/smite an user again. This might be forum default however, I have not tried it out before.

So, my questions are:
1. Is there anything else to do apart from running the package manager? Would I have to log in/out before I can see changes? Reload pages?
Not that I have not tried this already ..

2. In case the mod would work - I am using a different theme than default. Would I have to change all the files in my theme by hand?
I am not that keen on doing so especially since the mod seems not to be working for me.

Would it be possible to rename my theme to "default"? If so, would this make changing template files by hand for future mods still necessary?






Grek.Kamchatka

You must enable it in Admin Panel -> Edit Features and Options -> Karma -> Enable Karma Description Mod

Version 1.7 now available.

Gwion

Ah! Thank you ..

Seems to be ok now but if you click on applaud/smite you get this:

Parse error: parse error, unexpected '}' in /home/XXX/public_html/board/Sources/Karma.php on line 246

As mentioned in another post - how to I find this bit?
In notepad you have no lines, Word counts them only per page ..

And even if I find that line, do I just remove the } ?
I have just installed the mod and enabled it, so is that a mod bug or have I made a mistake?

I guess my webhost's system might cause a problem but of course I would like to learn why this happened and how to prevent it in future.

Advertisement: