Topic: [Extension] "Thanks" feature aka Pun_Karma

I think that if punbb have this feature this would be perfect.

People always want to say thanks and love to hear it.

Thanks and Best Regards

Re: [Extension] "Thanks" feature aka Pun_Karma

Here's the pun_karma extension (beta for 1.4.1):
pun_karma (with large thumbs)

Works on a test forum I have...


This is an additional version with different icons;
pun_karma (smaller thumbs in green or red box)

http://keydogbb.info/img/thumbs.png

http://keydogbb.info/img/thumbs2.png

Re: [Extension] "Thanks" feature aka Pun_Karma

http://keydogbb.info/img/thumbsup.png

The extension pun_karma also lets you have only thumbs up (so as not to offend any posters) - in admin/settings/features....

Re: [Extension] "Thanks" feature aka Pun_Karma

thanks
this will complete my forum

Regards

Re: [Extension] "Thanks" feature aka Pun_Karma

I noticed a problem with this plugin. The coding for alt-text on mouse hover (for the thumb and cancel icons) was a bit off.  Around line 245 of the manifest.xml, there was an alt="..." tag on an image, but that image was being blocked by the link overlaying it (in Google Chrome at least). So, I moved the alt="..." tag to the link in the form of <a href="link here" TITLE="alt text here"> and deleted alt="..." tag from the image. 

This was done for the thumbs up, thumbs down, and cancel icons.  For the lazy, here's the full file for you to copy and paste.  I was going to use a spoiler tag, but I forgot they're not available without an extension. tongue  Anyway:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE extension SYSTEM "ext-1.0.dtd">

<!--
/**
 * Adds karma/reputation to posts.
 *
 * @copyright (C) 2008-2009 PunBB
 * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
 * @package pun_karma
 */
-->

<extension engine="1.0">
    <id>pun_karma</id>
    <title>Post karma</title>
    <version>1.1.3</version>
    <description>Adds karma/reputation to posts with additional Icons.</description>
    <author>PunBB Development Team</author>
    <minversion>1.3</minversion>
    <maxtestedon>1.4.1</maxtestedon>

    <install><![CDATA[
if (!$forum_db->table_exists('pun_karma'))
{
    $schema = array(
        'FIELDS'    => array(
            'user_id'    =>    array(
                'datatype'        => 'INT(10) UNSIGNED',
                'allow_null'    => false
            ),
            'post_id'    =>    array(
                'datatype'        => 'INT(10) UNSIGNED',
                'allow_null'    => false
            ),
            'mark' => array(
                'datatype'        => 'TINYINT(1)',
                'allow_null'    => false
            ),
            'updated_at'    =>    array(
                'datatype'        => 'INT(10) UNSIGNED',
                'allow_null'    => false
            )
        ),
        'PRIMARY KEY'    => array('user_id', 'post_id'),
        'INDEXES'        => array('karmapost_idx' => array('post_id'))
    );
    $forum_db->create_table('pun_karma', $schema);
}

$forum_db->add_field('posts', 'karma', 'INT(10)', TRUE);
$forum_db->add_field('users', 'karma', 'INT(10)', TRUE);

//Upgrading
if (defined('EXT_CUR_VERSION') && version_compare(EXT_CUR_VERSION, '1.0', '<='))
{
    @set_time_limit(0);
    $pun_karma_query = array(
        'SELECT'    =>    'poster_id, SUM(mark) AS user_karma',
        'FROM'        =>    $forum_db->prefix.'posts AS p, '.$forum_db->prefix.'pun_karma AS pk',
        'WHERE'        =>    'p.id = pk.post_id',
        'GROUP BY'    =>    'poster_id',
        'PARAMS'    =>    array(
            'NO_PREFIX'    =>    true
        )
    );
    $pun_karma_res = $forum_db->query_build($pun_karma_query) or error(__FILE__, __LINE__);

    if ($forum_db->num_rows($pun_karma_res) > 0)
    {
        while ($cur_karma = $forum_db->fetch_assoc($pun_karma_res))
        {
            $pun_karma_update_query = array(
                'UPDATE'    =>    'users',
                'SET'        =>    'karma = '.$cur_karma['user_karma'],
                'WHERE'        =>    'id = '.$cur_karma['poster_id']
            );
            $forum_db->query_build($pun_karma_update_query) or error(__FILE__, __LINE__);
        }
    }
}

// Add extension options to the config table
$pun_karma_config = array(
    'o_pun_karma_minus_cancel'            => '0',
    'o_pun_karma_minus_interval'        => '2',
    'o_pun_karma_plus_interval'            => '2'
);

foreach ($pun_karma_config as $conf_name => $conf_value)
{
    if (!array_key_exists($conf_name, $forum_config))
    {
        $query = array(
            'INSERT'    => 'conf_name, conf_value',
            'INTO'        => 'config',
            'VALUES'    => '\''.$conf_name.'\', \''.$conf_value.'\''
        );

        $forum_db->query_build($query) or error(__FILE__, __LINE__);
    }
}
    ]]></install>

    <uninstall><![CDATA[
$forum_db->drop_table('pun_karma');
$forum_db->drop_field('posts', 'karma');
$forum_db->drop_field('users', 'karma');
$query = array(
    'DELETE'    =>    'config',
    'WHERE'        =>    'conf_name IN (\'o_pun_karma_minus_cancel\', \'o_pun_karma_minus_interval\', \'o_pun_karma_plus_interval\')'
);
$forum_db->query_build($query) or error(__FILE__, __LINE__);
    ]]></uninstall>

    <hooks>
        <hook id="hd_head"><![CDATA[
if (FORUM_PAGE == 'viewtopic')
    $forum_head['style_karma'] = '<link rel="stylesheet" type="text/css" media="screen" href="'.$ext_info['url'].'/styles.css" />';
        ]]></hook>
        <hook id="re_rewrite_rules"><![CDATA[
$forum_rewrite_rules['/^post[\/_-]([0-9]+)[\/_-]karma(plus|minus|cancel)[\/_-]([a-z0-9]+)(\.html?|\/)?$/i'] = 'viewtopic.php?pid=$1&karma$2&csrf_token=$3';
        ]]></hook>
        <hook id="vt_qr_get_posts"><![CDATA[
$query['SELECT'] .= ', p.karma AS post_karma, u.karma AS user_karma';
$pun_karma_posts = array();
$pun_karma_authors = array();
        ]]></hook>
        <hook id="vt_row_pre_post_actions_merge"><![CDATA[
if (!is_null($cur_post['user_karma']) && !isset($user_data_cache[$cur_post['poster_id']]['author_info']))
    $forum_page['author_info']['karma'] = '<li><span>'.$lang_pun_karma['User Karma'].' <strong>'.forum_number_format($cur_post['user_karma']).'</strong></span></li>';
        ]]></hook>
        <hook id="vt_modify_topic_info"><![CDATA[
//Including lang file
if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php'))
    require $ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php';
else
    require $ext_info['path'].'/lang/English/'.$ext_info['id'].'.php';
require $ext_info['path'].'/url/'.$forum_config['o_sef'].'/forum_urls.php';
require $ext_info['path'].'/functions.php';
if (!$forum_user['is_guest'] && (isset($_GET['karmaplus']) || isset($_GET['karmaminus']) || isset($_GET['karmacancel'])))
{
    //Check if user tries to vote for his own post
    $pun_karma_query = array(
        'SELECT'    => '1',
        'FROM'        => 'posts',
        'WHERE'        => 'poster_id = '.$forum_user['id'].' AND id = '.$pid
    );
    $result = $forum_db->query_build($pun_karma_query) or error(__FILE__, __LINE__);
    if ($forum_db->num_rows($result) > 0)
        message($lang_pun_karma['Vote error']);

    if (isset($_GET['karmaplus']))
    {
        if (!isset($_GET['csrf_token']) || ($_GET['csrf_token'] != generate_form_token('karmaplus'.$pid)))
            csrf_confirm_form();
        $pun_karma_query = array(
            'SELECT'    =>    'MAX(updated_at)',
            'FROM'        =>    'pun_karma',
            'WHERE'        =>    'user_id = '.$forum_user['id'].' AND mark = 1'
        );
        $pun_karma_result = $forum_db->query_build($pun_karma_query) or error(__FILE__, __LINE__);
        if ($forum_db->num_rows($pun_karma_result) > 0)
        {
            list($updated_at) = $forum_db->fetch_row($pun_karma_result);
            if ((time() - $updated_at) < $forum_config['o_pun_karma_plus_interval'] * 60 && (time() - $updated_at) >= 0)
                message(sprintf($lang_pun_karma['Plus interval rest'], $forum_config['o_pun_karma_plus_interval']));
        }
        karma_plus($pid);
    }
    else if (isset($_GET['karmaminus']))
    {
        if (!isset($_GET['csrf_token']) || ($_GET['csrf_token'] != generate_form_token('karmaminus'.$pid)))
            csrf_confirm_form();
        $pun_karma_query = array(
            'SELECT'    =>    'MAX(updated_at)',
            'FROM'        =>    'pun_karma',
            'WHERE'        =>    'user_id = '.$forum_user['id'].' AND mark = -1'
        );
        $pun_karma_result = $forum_db->query_build($pun_karma_query) or error(__FILE__, __LINE__);
        if ($forum_db->num_rows($pun_karma_result) > 0)
        {
            list($updated_at) = $forum_db->fetch_row($pun_karma_result);
            if ((time() - $updated_at) < $forum_config['o_pun_karma_minus_interval'] * 60 && (time() - $updated_at) >= 0)
                message(sprintf($lang_pun_karma['Minus interval rest'], $forum_config['o_pun_karma_minus_interval']));
        }
        karma_minus($pid);
    }
    else if (isset($_GET['karmacancel']))
    {
        if (!isset($_GET['csrf_token']) || ($_GET['csrf_token'] != generate_form_token('karmacancel'.$pid)))
            csrf_confirm_form();
        karma_cancel($pid);
    }
}
        ]]></hook>
        <hook id="aop_features_pre_header_load"><![CDATA[
//Including lang file
if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php'))
    require $ext_info['path'].'/lang/'.$forum_user['language'].'/'.$ext_info['id'].'.php';
else
    require $ext_info['path'].'/lang/English/'.$ext_info['id'].'.php';
require $ext_info['path'].'/url/'.$forum_config['o_sef'].'/forum_urls.php';
        ]]></hook>
        <hook id="vt_post_loop_start"><![CDATA[
$pun_karma_posts[$cur_post['id']] = $cur_post['post_karma'];
$pun_karma_authors[$cur_post['id']] = $cur_post['poster_id'];
        ]]></hook>
        <hook id="vt_row_pre_display"><![CDATA[
$forum_page['post_options']['karma'] = '<p class="post-karma">'.$cur_post['id'].'</p>';
        ]]></hook>
        <hook id="vt_end"><![CDATA[
$pun_karma_query = array(
    'SELECT'    =>    'post_id',
    'FROM'        =>    'pun_karma',
    'WHERE'        =>    'user_id = '.$forum_user['id'].' AND post_id IN ('.implode(',', array_keys($pun_karma_posts)).')'
);
$pun_karma_result = $forum_db->query_build($pun_karma_query) or error(__FILE__, __LINE__);

$user_karma_posts = array();
if ($forum_db->num_rows($pun_karma_result) > 0)
{
    while ($cur_id = $forum_db->fetch_assoc($pun_karma_result))
        $user_karma_posts[] = $cur_id['post_id'];
}

$buffer = forum_trim(ob_get_contents());
$karma_matches = array();
preg_match_all('~<p class="post-karma">([0-9]+)</p>~', $buffer, $karma_matches);
foreach ($karma_matches[0] as $match_index => $match_string)
{
    $post_karma = '';
    if (!is_null($pun_karma_posts[$karma_matches[1][$match_index]]))
        $post_karma = '<strong>'.($pun_karma_posts[$karma_matches[1][$match_index]] === '0' ? '0' : ($pun_karma_posts[$karma_matches[1][$match_index]] > 0 ? '+' : '&minus;').abs($pun_karma_posts[$karma_matches[1][$match_index]])).'</strong>';
    //Is user author of post?
    if ($pun_karma_authors[$karma_matches[1][$match_index]] == $forum_user['id'])
        $post_karma = '<p class="post-karma">'.$post_karma.'</p>';
    else
    {
        //User vote for this post?
        if (in_array($karma_matches[1][$match_index], $user_karma_posts))
            $post_karma = '<p class="post-karma">'.$post_karma.' <a href="'.forum_link($forum_url['karmacancel'], array($karma_matches[1][$match_index], generate_form_token('karmacancel'.$karma_matches[1][$match_index]))).'" TITLE="'.$lang_pun_karma['Alt cancel'].'"><img src="'.$ext_info['url'].'/icons/cancel.png" /></a></p>';
        else
            $post_karma = '<p class="post-karma"><a href="'.forum_link($forum_url['karmaplus'], array($karma_matches[1][$match_index], generate_form_token('karmaplus'.$karma_matches[1][$match_index]))).'" TITLE="'.$lang_pun_karma['Alt thumbs up'].'" ><img src="'.$ext_info['url'].'/icons/rate_yes.png" /></a> '.$post_karma.($forum_config['o_pun_karma_minus_cancel'] == '0' ? ' <a href="'.forum_link($forum_url['karmaminus'], array($karma_matches[1][$match_index], generate_form_token('karmaminus'.$karma_matches[1][$match_index]))).'" TITLE="'.$lang_pun_karma['Alt thumbs down'].'" ><img src="'.$ext_info['url'].'/icons/rate_no.png" /></a>' : '').'</p>';
    }
    $buffer = str_replace($match_string, $post_karma, $buffer);
}
$tpl_main = str_replace('<!-- forum_main -->', $buffer, $tpl_main);
        ]]></hook>
        <hook id="aop_features_validation"><![CDATA[
if (!isset($form['pun_karma_minus_cancel']) || $form['pun_karma_minus_cancel'] != '1')
    $form['pun_karma_minus_cancel'] = '0';
if (!isset($form['pun_karma_plus_interval']))
    $form['pun_karma_plus_interval'] = 2;
else
    $form['pun_karma_plus_interval'] = intval($form['pun_karma_plus_interval']);
if (!isset($form['pun_karma_minus_interval']))
    $form['pun_karma_minus_interval'] = 2;
else
    $form['pun_karma_minus_interval'] = intval($form['pun_karma_minus_interval']);
        ]]></hook>
        <hook id="aop_features_avatars_fieldset_end"><![CDATA[

$forum_page['group_count'] = $forum_page['item_count'] = 0;

?>
<div class="content-head">
    <h2 class="hn"><span><?php echo $lang_pun_karma['Karma features'] ?></span></h2>
</div>
<fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
    <legend class="group-legend"><span><?php echo $lang_pun_karma['Karma legend'] ?></span></legend>
    <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
        <div class="sf-box checkbox">
            <span class="fld-input"><input type="checkbox" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="form[pun_karma_minus_cancel]" value="1"<?php if ($forum_config['o_pun_karma_minus_cancel'] == '1') echo ' checked="checked"' ?> /></span>
            <label for="fld<?php echo $forum_page['fld_count'] ?>"><span><?php echo $lang_pun_karma['Disable minus'] ?></span> <?php echo $lang_pun_karma['Disable minus info'] ?></label>
        </div>
    </div>
    <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
        <div class="sf-box text">
            <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_pun_karma['Plus interval'] ?></span><small><?php echo $lang_pun_karma['Plus interval info'] ?></small></label><br />
            <span class="fld-input"><input type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="form[pun_karma_plus_interval]" size="6" maxlength="6" value="<?php echo $forum_config['o_pun_karma_plus_interval'] ?>" /></span>
        </div>
    </div>
    <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
        <div class="sf-box text">
            <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_pun_karma['Minus interval'] ?></span><small><?php echo $lang_pun_karma['Minus interval info'] ?></small></label><br />
            <span class="fld-input"><input type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="form[pun_karma_minus_interval]" size="6" maxlength="6" value="<?php echo $forum_config['o_pun_karma_minus_interval'] ?>" /></span>
        </div>
    </div>
</fieldset>
<?php

        ]]></hook>
        <hook id="fn_delete_topic_end"><![CDATA[
if (!empty($post_ids))
{
    $query = array(
        'DELETE'    =>    'pun_karma',
        'WHERE'        =>    'post_id IN('.implode(',', $post_ids).')'
    );
    $forum_db->query_build($query) or error(__FILE__, __LINE__);
}
        ]]></hook>
        <hook id="fn_delete_post_end"><![CDATA[
$query = array(
    'DELETE'    =>    'pun_karma',
    'WHERE'        =>    'post_id = '.$post_id
);
$forum_db->query_build($query) or error(__FILE__, __LINE__);
        ]]></hook>
        <hook id="mr_confirm_delete_posts_pre_redirect"><![CDATA[
if (!empty($posts))
{
    $query = array(
        'DELETE'    =>    'pun_karma',
        'WHERE'        =>    'post_id IN('.implode(',', $posts).')'
    );
    $forum_db->query_build($query) or error(__FILE__, __LINE__);
}
        ]]></hook>
        <hook id="mr_confirm_delete_topics_pre_redirect"><![CDATA[
if (!empty($post_ids))
{
    $query = array(
        'DELETE'    =>    'pun_karma',
        'WHERE'        =>    'post_id IN('.implode(',', $post_ids).')'
    );
    $forum_db->query_build($query) or error(__FILE__, __LINE__);
}
        ]]></hook>
    </hooks>
</extension>

Re: [Extension] "Thanks" feature aka Pun_Karma

nice idea

7 (edited by Kushi 2012-06-27 16:52)

Re: [Extension] "Thanks" feature aka Pun_Karma

It seems to doesn't work with friendly url.
Well it doesn't work after all :<. On localhost everything goes all right, but on my forum while I'm trying to click + or - it redirect me to post without changing anything.

If any of my dropbox link fails with 404 error, change dl.dropbox.com/u/56038890/punbb/*.zip in address to 82283017.

Currently working on rPlus - responsive theme for developers to create their own themes basing on this one.

Re: [Extension] "Thanks" feature aka Pun_Karma

My edit doesn't work right, you mean? Or the extension overall?

9

Re: [Extension] "Thanks" feature aka Pun_Karma

How do I allow guest to see karma and post karma.

10

Re: [Extension] "Thanks" feature aka Pun_Karma

Can I stop guest on even clicking on karma option, cos it shows the karma icons to them as hyperlinks, i dont want that.

11

Re: [Extension] "Thanks" feature aka Pun_Karma

I get this warning in Version 1.4.4

Warning: number_format() expects parameter 1 to be double, string given in .. ../include/functions.php on line 420

Re: [Extension] "Thanks" feature aka Pun_Karma

Hello, any version of "pun karma" for punbb 1.4.4 ?

13

Re: [Extension] "Thanks" feature aka Pun_Karma

Try this Rating.

14 (edited by zetrader 2017-06-26 23:56)

Re: [Extension] "Thanks" feature aka Pun_Karma

Thank you, no way to put a little text to say why we like or dislike ?
I've seen http://punbb.ru uses something like that, what's the extension ?
An example we can see all +1 on the profile and reasons why :
http://punbb.ru/reputation_view-1560.html

15

Re: [Extension] "Thanks" feature aka Pun_Karma

This extension Reputation.