function phpblock_recentcomments() { global $_CONF, $_TABLES, $LANG01; $recentcomments = '<div id="recentcomments">'; // Set the number of comments to show $limits = 5; $sql = "SELECT DISTINCT COUNT(*) AS dups, type, st.title as title, c.comment as comment, c.cid as cid, c.uid as uid, st.sid as sid, max(c.date) AS lastdate " . "FROM c, st " . "WHERE st.sid = c.sid AND st.draft_flag = 0 AND st.commentcode >= 0 " . COM_getPermSQL('AND', 0, 2,'st') // notice we can use st here. . $topicsql . COM_getLangSQL('sid', 'AND','st') . "GROUP BY c.sid,type, c.comment, st.title, st.sid, c.cid, c.uid " . "ORDER BY 5 DESC LIMIT " . $limits; $result = DB_query( $sql ); $nrows = DB_numRows( $result ); if( $nrows > 0 ) { $newcomments = array(); for( $x = 0; $x < $nrows; $x++ ) { $A = DB_fetchArray( $result ); if(( $A['type'] == 'article' ) || empty( $A['type'] )) { $url = COM_buildUrl( $_CONF['site_url'] . '/article.php?story=' . $A['sid'] ) . '#comments'; } $username = COM_getDisplayName( $A['uid'] ); $lastcomment = $A['comment']; $title = COM_undoSpecialChars( stripslashes( strip_tags( $lastcomment ))); $titletouse = COM_truncate( $title, 80, '...' ); $acomment = str_replace( '$', '$', $titletouse ); $newcomments[] = '<strong>' . $username .'</strong> ' . COM_createLink($acomment, $url); } $recentcomments .= COM_makeList( $newcomments, 'recentcomments' ); } else { $recentcomments .= $LANG01[86] . '<br' . XHTML . '>' . LB; } $recentcomments .='</div>'; return $recentcomments;