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 . '&func=view&catid=' . $catid . '&id=' . $pid) . '">' . _POST_CLICK . '</a>.';
if ($pid) {
echo CKunenaLink::GetAutoRedirectHTML(JRoute::_(KUNENA_LIVEURLREL.'&func=view&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. '&func=view&catid=' . $catid . '&id=' . $pid) . '">' . _POST_CLICK . '</a>.';
if ($pid) {
echo CKunenaLink::GetAutoRedirectHTML(JRoute::_(KUNENA_LIVEURLREL.'&func=view&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