CComment docs

The JPlugin

If you don't know what a Joomla plugin is then make sure to read the joomla wikiover here.

Basically Joomla plugins allow developers to hook into the execution of an extension and execute some code. Let us look at an example. The Content extension in joomla (Article manager or com_content) is triggering an onContentAfterDisplay event. Our plugin joscomment is hooking to this event, decides if it has to start the component or not.

public function onContentAfterDisplay($context, & $row, & $params, $page = 0)
    {
        $input = JFactory::getApplication()->input;
        if ($input->getCmd('option') != 'com_content')
        {
            return false;
        }

//        don't display comments if we are in print mode and the user doesn't want
//        the comments there
        if ($input->getCmd('print') && !$this->params->get('printView', 0))
        {
            return false;
        }

        JLoader::discover('ccommentHelper', JPATH_SITE . '/components/com_comment/helpers');
        return ccommentHelperUtils::commentInit('com_content', $row, $params);
    }

The first lines of this code actually decide if we should initialise the CComment component or not. We don't need to show the component, if the plugin is executed in another component for example (that is why we check the option). Then we check if print option is set and if we should show the component in printview.

The most important lines are those here:

JLoader::discover('ccommentHelper', JPATH_SITE . '/components/com_comment/helpers');
return ccommentHelperUtils::commentInit('com_content', $row, $params);

The first line tells Joomla where it can find the ccommentHelper classes and the second line actually initialises our component. As you can see we pass a $row & $params object. The $row contains information about the current item (in this case an article, but depending on the component it can be a photo or video etc). The row will be passed directly to our ccomment plugin (more on ccomment plugins in the next section). The $params object contains configuration information for the current item. If the component that you are writing the plugin for doesn't have a $params object you can pass a null.

Not all components support Plugin events. If you are integrating CComment with an extension that doesn't support plugin events you'll just need to echo the initialisation of CComment directly in the view file. For example like this:<?phpJLoader::discover('ccommentHelper', JPATH_SITE . '/components/com_comment/helpers');echo ccommentHelperUtils::commentInit('com_content', $row, $params);?>replace com_content with the name of the component that you are integrating.