Code snippets, tech tricks and other bits and bobs

Socialcode Activity Comment 2.2 plugin for Jomsocial - Like activity error 505 fix

I’ve got a lot of unpleasant things to say about 3rd party Joomla developers. And this is an example of why.

In Socialcode’s Activity Comment plugin for JomSocial (plg_activitycomment), when you unlike an activity, it appears to work. However, what it does is remove the likes-holder div immediately with Javascript (jQuery in fact), delete the like item from the database, then throw a 505 Internal Server Error. At this point you are supposed to get a response with the new string of likes, as other people may still like the activity, but these won’t be displayed until you refresh the page.

Most people probably don’t even realise it’s broken, as unless you have FireBugs console or net panels open, you get no notification of the error.

The problem occurs because the likeitem() function requires helper functions from a separate file, which the coders failed to include. So it’s remarkably easy to fix, once you work this out, simply add the line

require_once( JPATH_PLUGINS.DS.'community'.DS.'activitycomment'.DS.'helper.php');

to the function in /plugins/community/activitycomment.php, which will now look like this:

function unlikeitem($response, $id , $userid )
{
    $my=& CFactory::getUser();
    JPlugin::loadLanguage( 'plg_activitycomment', JPATH_ADMINISTRATOR );
    if($my->id == $userid )
    {
        $db =& JFactory::getDBO();
        $query ='delete from #__activitylikes where userid=' .$db->Quote($my->id) . ' and activityid=' . $db->Quote($id);
        $db->setQuery($query);
        $db->query();

        // Check if there are other likes
        $query = 'select count(*) from #__activitylikes where activityid=' . $db->Quote($id);
        $db->setQuery($query);
        $rows = $db->loadResult();

        require_once( JPATH_PLUGINS.DS.'community'.DS.'activitycomment'.DS.'helper.php');

        if( $rows == 0 )
        {
            $response->addScriptCall(ActivityComments::getjs() ."('#likes-holder-" . $id . "').removeClass('likes-content');");
        }
        $response->addScriptCall(ActivityComments::getjs() ."('#likes-holder-" . $id . "').children().remove();");

        $text = $this->rebuildItemString( $id );
        $response->addScriptCall('activityInsertLike', $id , $text);

        return $response->sendResponse();
    }
}

I discovered this problem while updating my hacks to include a dislike button at the request of a client who’s community members wanted it. If you are interested in having the hack for your own JomSocial site, leave a comment and I’ll get in touch.

Filed under  //   Activity Comment Plugin   JomSocial   Joomla!   PHP   Socialcode