Kunena 7.0.4 Released

The Kunena team has announce the arrival of Kunena 7.0.4 [K 7.0.4] in stable which is now available for download as a native Joomla extension for J! 5.4.x/6.0.x. This version addresses most of the issues that were discovered in K 6.2 / K 6.3 / K 6.4 and issues discovered during the last development stages of K 7.0

Topics that are moved into this category are generally considered to be closed. Users may want to add additional information but these topics should not be resurrected in order to discuss new problems or unrelated matters.

Question Custom AUP Karma Rule not working properly in Kunena

More
16 years 4 months ago #35724 by Moutas
I am using:

Kunena 1.5.7
Alpha User Points 1.5.3

I have created a rule for AUP when a user applauds/smites another user's post in Kunena. Basically its +1 point for thumbs-up and -1 point for thumbs-down. I have created the XML files and they are working OK, but the problem is with my PHP code.

This is how my code in components/com_kunena/lib/kunena.karma.php looks like now:

if ($is_Moderator || $karma_time_diff >= $karma_min_seconds)
{
//construct a useable URL (for plaintext - so no & encoding!)
jimport('joomla.environment.uri');
$uri =& JURI::getInstance(JURI::base());
$LastPostUrl = $uri->toString(array('scheme', 'host', 'port')) . str_replace('&', '&', CKunenaLink::GetThreadPageURL($fbConfig, 'view', $catid, $querythread, $threadPages, $fbConfig->messages_per_page, $pid));
if ($do == "increase")
{
$kunena_db->setQuery('UPDATE #__fb_users SET karma_time=' . $time . ' WHERE userid=' . $kunena_my->id . '');
$kunena_db->query() or trigger_dberror("Unable to update karma.");
$kunena_db->setQuery('UPDATE #__fb_users SET karma=karma+1 WHERE userid=' . $userid . '');
$kunena_db->query() or trigger_dberror("Unable to update karma.");
echo _KARMA_INCREASED . '<br /> <a href="' . JRoute::_(KUNENA_LIVEURLREL . '&amp;func=view&amp;catid=' . $catid . '&amp;id=' . $pid) . '">' . _POST_CLICK . '</a>.';
if ($pid) {
echo CKunenaLink::GetAutoRedirectHTML(JRoute::_(KUNENA_LIVEURLREL.'&amp;func=view&amp;catid='.$catid.'&id='.$pid), 3500);
} else {
echo CKunenaLink::GetAutoRedirectHTML(JRoute::_(KUNENA_PROFILE_LINK_SUFFIX.$userid), 3500);
}
$api_AUP = JPATH_SITE.DS.'components'.DS.'com_alphauserpoints'.DS.'helper.php';
$datareference = '<a href="' . $LastPostUrl . '">' . $subject . '</a>';
if ( file_exists($api_AUP))
{
require_once ($api_AUP);
$aupid = AlphaUserPointsHelper::getAnyUserReferreID( $userID );
if ( $aupid ) AlphaUserPointsHelper::newpoints( 'plgaup_karma_up', $aupid, $pid, $datareference );
}
}
else if ($do == "decrease")
{
$kunena_db->setQuery('UPDATE #__fb_users SET karma_time=' . $time . ' WHERE userid=' . $kunena_my->id . '');
$kunena_db->query() or trigger_dberror("Unable to update karma.");
$kunena_db->setQuery('UPDATE #__fb_users SET karma=karma-1 WHERE userid=' . $userid . '');
$kunena_db->query() or trigger_dberror("Unable to update karma.");
echo _KARMA_DECREASED . '<br /> <a href="' . JRoute::_(KUNENA_LIVEURLREL. '&amp;func=view&amp;catid=' . $catid . '&amp;id=' . $pid) . '">' . _POST_CLICK . '</a>.';
if ($pid) {
echo CKunenaLink::GetAutoRedirectHTML(JRoute::_(KUNENA_LIVEURLREL.'&amp;func=view&amp;catid='.$catid.'&id='.$pid), 3500);
} else {
echo CKunenaLink::GetAutoRedirectHTML(JRoute::_(KUNENA_PROFILE_LINK_SUFFIX.$userid), 3500);
}
$api_AUP = JPATH_SITE.DS.'components'.DS.'com_alphauserpoints'.DS.'helper.php';
$datareference = '<a href="' . $LastPostUrl . '">' . $subject . '</a>';
if ( file_exists($api_AUP))
{
require_once ($api_AUP);
$aupid = AlphaUserPointsHelper::getAnyUserReferreID( $userID );
if ( $aupid ) AlphaUserPointsHelper::newpoints( 'plgaup_karma_down', $aupid, $pid, $datareference );
}
}
else
{ //you got me there... don't know what to $do
echo _USER_ERROR_A;
echo _USER_ERROR_B . "<br /><br />";
echo _USER_ERROR_C . "<br /><br />" . _USER_ERROR_D . ": <code>fb001-karma-02NoDO</code><br /><br />";
}
}


I tested it by giving a post a thumbs-up. The AUP Community points increased by 1 but no-one received the point. All users remained the same. I have enabled and published both new rules ("Karma Up" and "Karma Down") but I don't understand what the problem is. I'm guessing it has to do with the following code:

$aupid = AlphaUserPointsHelper::getAnyUserReferreID( $userID );
if ( $aupid ) AlphaUserPointsHelper::newpoints( 'plgaup_karma_down', $aupid, $pid, $datareference );


I read in the AUP Documentation that getAnyUserReferreID($userID); is used to detect the author in an article, however does this function work to figure out who the user is that made the forum post? If not, does anyone know what function I should call? Thanks in advance :)

Please Log in or Create an account to join the conversation.

More
16 years 3 months ago #36257 by Matias
We are not that familiar with AUP. Maybe you should ask how to use their API in Alpha forums?

Please Log in or Create an account to join the conversation.

Time to create page: 0.228 seconds