CComment docs

Nameofcomponent.php (content.php, k2.php, docman.php etc)

Unfortunatly or fortunatly components are developed by different developers all with different skill sets. Some of them are following the joomla conventions, others are not. Sometimes the joomla conventions are not clear enough and it is up to the developer to create code that he likes. This leads us with a problem - how to integrate a comment system with each joomla component? It is not an easy task and it currently cannot be 100% automated. For example there are components that use the variable id to identify a resource, but there are other components that use article_id to identify a resource. Because of the we need a way to internally deal with different kinds of component. This is where the nameofcomponent.php (content.php, k2.php etc) file comes into play. The file contains a class that should be named as follows ccommentComponent NAMEOFCOMPONENT Plugin. This class should extend the ccommentComponentPlugin class. For example if we are creating a plugin for com_content this is how our class should look like:

class ccommentComponentContentPlugin extends ccommentComponentPlugin
{

}

The ccommentComponentPlugin is an abstract class that defines the structure for your CComment plugin. It is located in administrator/components/com_comment/library/component

abstract class ccommentComponentPlugin {

    /**
     * @param $row
     * @param null $params - JRegistry object with config information for the item
     */
    public function __construct($row = null, $params = null)
    {
        if($row) {
            $this->row = $row;
        }
        if($params) {
            $this->params = $params;
        }
    }

    /**
     * With this function we determine if the comment system should be executed for this
     * content Item
     * @return bool
     */
    public abstract function isEnabled();

    /**
     * This function decides whether to show the comments
     * in an article/item or to show the readmore link
     *
     * If it returns true - the comments are shown
     * If it returns false - the showReadon function will be called
     * @param int - the content/item id
     * @return boolean
     */
    public abstract function isSingleView();

    /**
     * This function determines whether to show the comment count or not
     * @return bool
     */
    public abstract function showReadOn();

    /**
     * @param int  $contentId
     * @param int  $commentId
     *
     * @param bool $xhtml
     *
     * @return string - the URL to the comment/item
     */
    public abstract function getLink($contentId, $commentId = 0, $xhtml = true);

    /**
     * @param $ids - the ids of the items that we look for title
     *
     * @return mixed - array with objects (id, title) sorted by id
     */
    public abstract function getItemTitles($ids);

    /**
     * Different component have different names for the id (id, article_id, video_id etc)
     * That is why we need a function that can reliably return the ID of the item in question
     *
     * @return - id of content Item
     */
    public function getPageId()
    {
        return $this->row->id;
    }

    /**
     * Returns the id of the author of an item
     *
     * @param int $contentId
     *
     * @return mixed
     */
    public abstract function getAuthorId($contentId);

}

The __construct function expects a $row and $params object. As you can see from the code however -> we cannot rely on the $row object beeing present at all times.

The isEnabled function will determine if CComment should be initialised for the current item (article, video etc) depending on the user configuration (selected category, disabled for specific item etc)

The isSingleView function will determine if we are currently in single view for the specific item. If we are, then we will show the comment form together with all comment. If we aren't the showReadOn() function will be called and it will determine if CComment needs to show a "write comment" button or not.

The getLink function is called whenever we need to know the link to a specific item or comment. Generally the links that CComment generate look like this: index.php?option=com_comment&task=comment.goToComment&id=10 (10 is the id of the comment). When the user clicks on this link CComment is going to load the necessary plugin and execute the getLink function by passing to it the contentid, commentid & boolean xhml (the xhtml parameter will determine if the link generated should have the & replaced by &). You should make sure that the link that you generate in the getLink function is the same as the one the component generates. This means if the component generates a link with a category id and alias in it, you should also have the category id and alias in it.

For example the link to com_content look like this:

index.php?option=com_content&view=article&id=1:article-alias&catid=1:category-alias&Itemid=435

The link that the getLink function generates should be exactly the same only with the addition of an anchor for example:

index.php?option=com_content&view=article&id=29121:new-article&catid=972:uncategorized&Itemid=435#ccomment-comment=325

Having the anchor tag will tell CComment that it has to show comment 325 (if you use pagination, then ccomment will be loaded on the page where comment 325 is and will center on it)

Creating the same link as the component that we integrate CComment with will guarantee that when the user enables SEF CComment will generate correct links.

The getItemTitles is returning an array with objects each with id & title for the item that the comment belongs to. For example this function is used in the backend on the comments list view - the Content Item column. This function expects an array with content ids.

The getPageId function returns the id of the row object. Depending on the component you will most probably won't need to override this function, but if you are integrating with a component that doesn't use the variable name id for the row, but for example article_id, you'll need to override this function and return the correct id there.

The getAuthorId function return the id of the user that has created the content item we are commenting in. Used to determine if the currently logged in user is the author of the content item and if the "content creator moderator" function is set to yes, then this user will have moderator privileges in this item.