Wednesday, December 13, 2017 02:15 am EST

Enhanced Recent Comments Module

Bri's picture

The drupal core comes with a Recent Comments module, as you probably already know. This module doesn't allow for any configuration options, so I simply added to it. The core module is a block module that simply shows the 10 most recent comments. But what if you only want to show 5 posts, or perhaps only show comments from a particular content type? Below are the changes that i made. The majority of this code came directly from the drupal core comment.module file.

<?php
/**
* Display help and module information
* @param path which path of the site we're displaying help
* @param arg array that holds the current path as would be returned from arg() function
* @return help text for the path
*/
function enhancedrecentcomments_help($path, $arg)
{
$output = ''; //declare output variable

	switch ($path)
	{
		case "admin/help#enhancedrecentcomments":
			$output = '

'. t('Enhanced Recent comments is an enhanced version of the drupal core block. This one allows you to change the number of links displayed and which content types comments should be displayed.'). '

'; break; } return $output; } /** * Implementation of hook_block(). * * Generates a block with the most recent comments. */ function enhancedrecentcomments_block($op = 'list', $delta = 0) { if ($op == 'list') { $blocks[0]['info'] = t('Enhanced Recent Comments'); return $blocks; } else if ($op == 'view' && user_access('access comments')) { $block['subject'] = t('Recent comments'); //get the options set for which content types to show comments for $typeToShow = variable_get("enhancedrecentcomments_allowed", array()); //loop thru, and add it to a text variable if the value is not 0 foreach($typeToShow as $type) { if($type != "0") { $typeText .= "'".$type."', "; } } //if no content types are selected, don't display the block (optionally u can set teh string to "no comments" or something like that) if(empty($typeText)) { $block['content'] = ''; } else { $block['content'] = theme_enhancedrecentcomments_block(); } return $block; } } /** * Returns a formatted list of recent comments to be displayed in the comment block. * * @return * The comment list HTML. * @ingroup themeable */ function theme_enhancedrecentcomments_block() { $items = array(); $limitnum = variable_get("enhancedrecentcomments_maxdisp" , 5); foreach (enhancedrecentcomments_get_recent($limitnum) as $comment) { $items[] = l($comment->subject, 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid)) .'
'. t('@time ago', array('@time' => format_interval(time() - $comment->timestamp))). "
"; } if ($items) { return theme('item_list', $items); } } function enhancedrecentcomments_menu() { $items = array(); $items['admin/settings/enhancedrecentcomments'] = array( 'title' => 'Enhanced Recent Comments Settings', 'description' => 'Adjust the recent comments settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('enhancedrecentcomments_admin'), 'access arguments' => array('access administration pages'), 'type' => MENU_NORMAL_ITEM, ); return $items; } //create the form for the administration page function enhancedrecentcomments_admin() { $form = array(); $form['enhancedrecentcomments_maxdisp'] = array( '#type' => 'textfield', '#title' => t('Maximum number of comments'), '#default_value' => variable_get('enhancedrecentcomments_maxdisp', 5), '#size' => 2, '#maxlength' => 2, '#description' => t("The maximum number of comments to display in the block."), '#required' => TRUE, ); $form['enhancedrecentcomments_allowed'] = array( '#type' => 'checkboxes', '#title' => t('Include these content types'), '#default_value' => variable_get('enhancedrecentcomments_allowed', array()), '#options' => array_map('check_plain', node_get_types('names')), '#description' => t("Check the content types that you want to be included in the recent comments block"), ); return system_settings_form($form); } //validation for the aministrative form function enhancedrecentcomments_admin_validate($form, &$form_state) { $maxdisp = $form_state['values']['enhancedrecentcomments_maxdisp']; if(!is_numeric($maxdisp)) { form_set_error('enhancedrecentcomments_maxdisp', t("You must enter an integer for the maximum number of links")); } else if($maxdisp <= 0) { form_set_error('enhancedrecentcomments_maxdisp', t("Maximum number of links must be positive")); } } /** * Find a number of recent comments. This is done in two steps. * 1. Find the n (specified by $number) nodes that have the most recent * comments. This is done by querying node_comment_statistics which has * an index on last_comment_timestamp, and is thus a fast query. * 2. Loading the information from the comments table based on the nids found * in step 1. * * @param $number * (optional) The maximum number of comments to find. * @return * An array of comment objects each containing a nid, * subject, cid, and timestamp, or an empty array if there are no recent * comments visible to the current user. */ function enhancedrecentcomments_get_recent($number = 10) { // Select the $number nodes (visible to the current user) with the most // recent comments. This is efficient due to the index on // last_comment_timestamp. //get the options set for which content types to show comments for $typeToShow = variable_get("enhancedrecentcomments_allowed", array()); //loop thro, and add it to a text variable if the value is not 0 foreach($typeToShow as $type) { if($type != "0") { $typeText .= "'".$type."', "; } } // search for the last occurence of a comma $pos = strrpos($typeText, ","); //narrow the typetext down to where the last comma $typeText = substr($typeText, 0, $pos); $result = db_query_range(db_rewrite_sql("SELECT nc.nid FROM {node_comment_statistics} nc LEFT OUTER JOIN {node} n on n.nid = nc.nid WHERE nc.comment_count > 0 AND type IN (".$typeText.") ORDER BY nc.last_comment_timestamp DESC", 'nc'), 0, $number); $nids = array(); while ($row = db_fetch_object($result)) { $nids[] = $row->nid; } $comments = array(); if (!empty($nids)) { // From among the comments on the nodes selected in the first query, // find the $number most recent comments. $result = db_query_range('SELECT c.nid, c.subject, c.cid, c.timestamp FROM {comments} c INNER JOIN {node} n ON n.nid = c.nid WHERE c.nid IN ('. implode(',', $nids) .') AND n.status = 1 AND c.status = %d ORDER BY c.cid DESC', COMMENT_PUBLISHED, 0, $number); while ($comment = db_fetch_object($result)) { $comments[] = $comment; } } return $comments; }

Comments

Anonymous's picture

Enhancement of the content of

Enhancement of the content of the module has been implemented and account for the fulfillment of the goals for the people. The dynamic story has been shred online for the enhancement of the text for the success of the students.
Lіpozеnе Rеvіеws

Anonymous's picture

Enhancement of the recent

Enhancement of the recent comments has been done for the general welfare of the individuals. The quarterly successive plan is implemented assignment corner for the improvement of the plans of the humans for each other.

Anonymous's picture

женские письки писяющие в рот

секс с юнной лилипуткой

nm-hdadult download/170-9-samoe-kachestvennoe-foto-golyh-zhenschin html
софи ди порно больнице
молодое гей порно видео
megahdxxx download/199-9-popy-porn-foto html
порно бешеный минет
два девучка занимаетса секса
siska3g download/29-9-smotret-onlayn-porno-pervyy-raz html
голые телки ловят рыбу
порно комексы ком
hdseewin download/97-9-seks-houm-pati-video html
порно красивую жену в попку
смотреть голых беременных женщин
videohdsmotret download/48-9-pustili-etu-krasotku-po-krugu-horosho-otimeli html
девушка дрочит себе и парню рукой
помешала ночью трах онлайн

Anonymous's picture

Many thanks for the changes

Many thanks for the changes on this perfectwriter.co.uk review website. Yes, this really happens sometimes that we want to view only 5 or less than 5 posts but there is no option of configuration then we can’t do anything. But thanks to you that you have added some changes in the modules. Hope it will resolve the things.

Anonymous's picture

The site seems to be

The site seems to be good..!!Thanks for sharing..!!