2
This would likely be a good enhancement to the recent comments block. There are likely a few methods you could use to do this.
For instance, you could change the php for the block so that it keeps track of whether or not a specific module item has already displayed a comment for it or not before it gets added to the displayed comments. You'd need to initialize an array for this purpose, then in the foreach loop check to see if a comment already exists for this item or not and if so skip it, and if not then add it to the comments and then add the info (probably moduleID and then itemID) to the array for the next time to check. This would be done in the /modules/system/blocks/system_blocks.php in the function b_system_comments_show.
For example, this code MIGHT work (I haven't tested it, but it should be close). Replace:
foreach (array_keys($comments) as $i) {
$mid = $comments[$i]->getVar('com_modid');
$com['module'] = '<a href="'.XOOPS_URL.'/modules/'.$modules[$mid]->getVar('dirname').'/">'.$modules[$mid]->getVar('name').'</a>';
if (!isset($comment_config[$mid])) {
$comment_config[$mid] = $modules[$mid]->getInfo('comments');
}
$com['id'] = $i;
$com['title'] = '<a href="'.XOOPS_URL.'/modules/'.$modules[$mid]->getVar('dirname').'/'.$comment_config[$mid]['pageName'].'?'.$comment_config[$mid]['itemName'].'='.$comments[$i]->getVar('com_itemid').'&com_id='.$i.'&com_rootid='.$comments[$i]->getVar('com_rootid').'&'.htmlspecialchars($comments[$i]->getVar('com_exparams')).'#comment'.$i.'">'.$comments[$i]->getVar('com_title').'</a>';
$com['icon'] = htmlspecialchars( $comments[$i]->getVar('com_icon'), ENT_QUOTES );
$com['icon'] = ($com['icon'] != '') ? $com['icon'] : 'icon1.gif';
$com['time'] = formatTimestamp($comments[$i]->getVar('com_created'),'m');
if ($comments[$i]->getVar('com_uid') > 0) {
$poster =& $member_handler->getUser($comments[$i]->getVar('com_uid'));
if (is_object($poster)) {
$com['poster'] = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$comments[$i]->getVar('com_uid').'">'.$poster->getVar('uname').'</a>';
} else {
$com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
}
} else {
$com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
}
$block['comments'][] =& $com;
unset($com);
}
with:
$trackedItems = array();
foreach (array_keys($comments) as $i) {
$mid = $comments[$i]->getVar('com_modid');
$com['module'] = '<a href="'.XOOPS_URL.'/modules/'.$modules[$mid]->getVar('dirname').'/">'.$modules[$mid]->getVar('name').'</a>';
if (!isset($comment_config[$mid])) {
$comment_config[$mid] = $modules[$mid]->getInfo('comments');
}
$com['id'] = $i;
$com['title'] = '<a href="'.XOOPS_URL.'/modules/'.$modules[$mid]->getVar('dirname').'/'.$comment_config[$mid]['pageName'].'?'.$comment_config[$mid]['itemName'].'='.$comments[$i]->getVar('com_itemid').'&com_id='.$i.'&com_rootid='.$comments[$i]->getVar('com_rootid').'&'.htmlspecialchars($comments[$i]->getVar('com_exparams')).'#comment'.$i.'">'.$comments[$i]->getVar('com_title').'</a>';
$com['icon'] = htmlspecialchars( $comments[$i]->getVar('com_icon'), ENT_QUOTES );
$com['icon'] = ($com['icon'] != '') ? $com['icon'] : 'icon1.gif';
$com['time'] = formatTimestamp($comments[$i]->getVar('com_created'),'m');
if ($comments[$i]->getVar('com_uid') > 0) {
$poster =& $member_handler->getUser($comments[$i]->getVar('com_uid'));
if (is_object($poster)) {
$com['poster'] = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$comments[$i]->getVar('com_uid').'">'.$poster->getVar('uname').'</a>';
} else {
$com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
}
} else {
$com['poster'] = $GLOBALS['xoopsConfig']['anonymous'];
}
if (count($trackedItems) > 0) {
$itemMatch = false;
foreach (array_keys($trackedItems) as $j) {
if ($comments[$i]->getVar('com_modid') == $trackedItems[$j]['modid'] && $comments[$i]->getVar('com_itemid') == $trackedItems[$j]['itemid']) {
$itemMatch = true;
}
}
if ($itemMatch) {
$block['comments'][] =& $com;
$trackedItems[] = array('modid' => $comments[$i]->getVar('com_modid'), 'itemid' => $comments[$i]->getVar('com_itemid') );
}
} else {
$block['comments'][] =& $com;
$trackedItems[] = array('modid' => $comments[$i]->getVar('com_modid'), 'itemid' => $comments[$i]->getVar('com_itemid') );
}
unset($com);
}
BTW, I'm sure the code can be made more elegant, and as presented above, it may not work, but this hack should get you closer.