Recently, one of our users had some problems implementing JComment in the HWDMediaShare gallery. Whilst investigating and resolving this issue we noticed that the HWDMediaShare plugin in the JComment package was slightly out of date. Although the plugin still worked, it resulted in the incorrect information displaying in the administrator when viewing comments that had been added to HWDMediaShare.

We updated the plugin, and would like to offer the code to any users who are interested.

The plugin file is located in the JComment component directory:

/components/com_jcomments/plugins/com_hwdmediashare.plugin.php

 

The updated plugin is included below, and we'll contact the JComment developer to see if we can get it included in their next release.

<?php
/**
* @package Joomla.site
* @subpackage Component.jcomments.plugin.com_hwdmediashare
*
* @copyright Copyright (C) 2015 Highwood Design Limited. All rights reserved.
* @license GNU General Public License http://www.gnu.org/copyleft/gpl.html
* @author Dave Horsfall
*/

defined('_JEXEC') or die;

class jc_com_hwdmediashare extends JCommentsPlugin
{
/**
* Method to get a JComment object's title.
*
* @access public
* @param integer $name The ID.
* @return string The title.
*/
public function getObjectTitle($id)
{
$isInstalled = file_exists(JPATH_SITE.'/components/com_hwdmediashare/helpers/route.php') ? true : false;
if ($isInstalled)
{
require_once(JPATH_SITE.'/components/com_hwdmediashare/helpers/route.php');

$db = JFactory::getDBO();
$db->setQuery('SELECT title FROM #__hwdms_media WHERE id = ' . $id);
return $db->loadResult();
}
}

/**
* Method to get a JComment object's link.
*
* @access public
* @param integer $name The ID.
* @return string The link.
*/
public function getObjectLink($id)
{
$isInstalled = file_exists(JPATH_SITE.'/components/com_hwdmediashare/helpers/route.php') ? true : false;
if ($isInstalled)
{
require_once(JPATH_SITE.'/components/com_hwdmediashare/helpers/route.php');

$db = JFactory::getDBO();
$db->setQuery('SELECT id, alias FROM #__hwdms_media WHERE id = ' . $id);
$row = $db->loadObject();

if ($row)
{
$slug = $row->alias ? ($row->id . ':' . $row->alias) : $row->id;
return JRoute::_(hwdMediaShareHelperRoute::getMediaItemRoute($slug));
}
}
}

/**
* Method to get a JComment object's author.
*
* @access public
* @param integer $name The ID.
* @return integer The author's user ID.
*/
public function getObjectOwner($id)
{
$isInstalled = file_exists(JPATH_SITE.'/components/com_hwdmediashare/helpers/route.php') ? true : false;
if ($isInstalled)
{
require_once(JPATH_SITE.'/components/com_hwdmediashare/helpers/route.php');

$db = JFactory::getDBO();
$db->setQuery('SELECT created_user_id FROM #__hwdms_media WHERE id = ' . $id);
return $db->loadResult();
}
}
}