Hi,

I was very grateful to find your module, which I used in a site for which the client wanted to pull in the most recent post they had made to their blogger site and display the details on the front page of their new drupal site (via an RSS feed from blogger (via feedburner)).

The only problem was that they wanted to display some additional info that wasn't covered by the Feedblock module. So, I added in a few extra options to the feedblock menu and wonder if they would be of interest to the general project?

In feed_block.module in 6.x-1.3 I have added the following:

In the function feed_block_settings() at line 88 I have added:

  $form['feedblock_showexcerpt'] = array(
  '#type' => 'checkbox',
  '#title' => t('Show Excerpt'),
  '#description' => t('Show a 350 character excerpt from the feed item.'),
  '#default_value' => variable_get('feedblock_showexcerpt', 0),
  '#required' => FALSE,
  );
  
  $form['feedblock_showfeedtitle'] = array(
  '#type' => 'checkbox',
  '#title' => t('Show Feed Title'),
  '#description' => t('Show the source of the feed.'),
  '#default_value' => variable_get('feedblock_showfeedtitle', 1),
  '#required' => FALSE,
  );
  
  $form['feedblock_showdate'] = array(
  '#type' => 'checkbox',
  '#title' => t('Show feed date'),
  '#description' => t("Show the date of the feed, in the format 'Posted @ 11:47 AM Sep 9th'."),
  '#default_value' => variable_get('feedblock_showdate', 0),
  '#required' => FALSE,
  );

Then in the function feed_block_content(), between lines 10 to 23 where it said

while ($fq = db_fetch_object($q)) {
    $fid = $fq->fid;
    $feedtitle = check_plain($fq->feedtitle);
    $query = db_query('SELECT ai.title, ai.link FROM {aggregator_item} AS ai WHERE ai.fid = "%d" ORDER BY ai.timestamp DESC', $fid);
    $fquery = db_fetch_object($query);
    
    $title = check_plain($fquery->title);
    $link = $fquery->link;
    $line = '<div class="fb-title">' . $title . '</div><div class="fb-feed">' . variable_get('feedblock_prefix', '~') . $feedtitle . '</div>';
    
    $list .= '<li>' . l($line, $link, array('html' => TRUE, 'absolute' => TRUE)) . '</li>';
  }

I've changed it to read:

  $show_excerpt = variable_get('feedblock_showexcerpt', 0);
  $show_title = variable_get('feedblock_showfeedtitle', 1);
  $show_date = variable_get('feedblock_showdate', 0);
  
  while ($fq = db_fetch_object($q)) {
    $fid = $fq->fid;
    $feedtitle = check_plain($fq->feedtitle);
	$sql = 'SELECT ai.title, ';
	
	if ($show_excerpt) {
	  $sql .= 'ai.description, ';
	}
	
	if ($show_date) {
	  $sql .= 'ai.timestamp, ';
	}
	
	$sql .= 'ai.link FROM {aggregator_item} AS ai WHERE ai.fid = "%d" ORDER BY ai.timestamp DESC';
    $query = db_query($sql, $fid);
    $fquery = db_fetch_object($query);
    
    $title = check_plain($fquery->title);
    $link = $fquery->link;
	
    $line = '<div class="fb-title">' . $title . '</div>';
	if ($show_title) {
	  $line .= '<div class="fb-feed">' . variable_get('feedblock_prefix', '~') . $feedtitle . '</div>';
    }
    $list .= '<li>' . l($line, $link, array('html' => TRUE, 'absolute' => TRUE));
	
	if ($show_excerpt) {
	  $description = trim(substr(check_plain($fquery->description), 0, 350)) . '...';
	  $list .= $description;
	}
	
	if ($show_date) {
	  $posteddate = date('h:i A M jS', $fquery->timestamp);
	  $list .= '<br /><br /><span>Posted @ ' . $posteddate .'</span>';
	}
	
	$list .= '</li>';
  }

So this lets people show a 350 character excerpt from the feed item, show the source of the feed and show the date of the feed in the format 'Posted @ 11:47 AM Sep 9th', whilst the default settings remain as the original functionality of the feedblock module.

I hope this is of use, although perhaps it needs a bit more flexibility in terms of date format and number of characters?

Thanks again for the module,

David

Comments

Anonymous’s picture

Im not using this module a long time but I may update it sometime and add some new features.

DaveyM’s picture

Hi Ivan,

I made some further changes recently so that the number of characters in the excerpt could be specified. They include:

In the function feed_block_settings() where I had added:

  $form['feedblock_showexcerpt'] = array(
  '#type' => 'checkbox',
  '#title' => t('Show Excerpt'),
  '#description' => t('Show a 350 character excerpt from the feed item.'),
  '#default_value' => variable_get('feedblock_showexcerpt', 0),
  '#required' => FALSE,
  );

I have changed it to

$form['feedblock_showexcerpt'] = array(
  '#type' => 'checkbox',
  '#title' => t('Show Excerpt'),
  '#description' => t('Show an excerpt from the feed item.'),
  '#default_value' => variable_get('feedblock_showexcerpt', 0),
  '#required' => FALSE,
  );
  
  $form['feedblock_excerptlength'] = array(
  '#type' => 'textfield',
  '#title' => t('Excerpt Length'),
  '#description' => t('How many characters to show in the excerpt from the feed item.'),
  '#default_value' => variable_get('feedblock_excerptlength', 350),
  '#required' => FALSE,
  '#element_validate' => array('feed_block_feedblock_excerptlength_validate')
  );

I have added the following new validation function:

/* Check the value is a non-negative integer */
function feed_block_feedblock_excerptlength_validate($element,$form_state) {
	$excerpt_length = $form_state['values']['feedblock_excerptlength'];

	if(!is_numeric($excerpt_length) || $excerpt_length < 0 || $excerpt_length != intval($excerpt_length) ) {
		form_error($element, t('You must provide a positive whole number for the excerpt length.'));
	}
}

And finallly the while loop I expanded in the feed_block_content function has been further expanded to

$show_excerpt = variable_get('feedblock_showexcerpt', 0);
  $show_title = variable_get('feedblock_showfeedtitle', 1);
  $show_date = variable_get('feedblock_showdate', 0);
  $excerpt_length = variable_get('feedblock_excerptlength', 0);
  
  while ($fq = db_fetch_object($q)) {
    $fid = $fq->fid;
    $feedtitle = check_plain($fq->feedtitle);
	$sql = 'SELECT ai.title, ';
	
	if ($show_excerpt) {
	  $sql .= 'ai.description, ';
	}
	
	if ($show_date) {
	  $sql .= 'ai.timestamp, ';
	}
	
	$sql .= 'ai.link FROM {aggregator_item} AS ai WHERE ai.fid = "%d" ORDER BY ai.timestamp DESC';
    $query = db_query($sql, $fid);
    $fquery = db_fetch_object($query);
    
    $title = check_plain($fquery->title);
    $link = $fquery->link;
	
    $line = '<div class="fb-title">' . $title . '</div>';
	if ($show_title) {
	  $line .= '<div class="fb-feed">' . variable_get('feedblock_prefix', '~') . $feedtitle . '</div>';
    }
    $list .= '<li>' . l($line, $link, array('html' => TRUE, 'absolute' => TRUE));
	
	if ($show_excerpt && $excerpt_length > 0) {
	  $description = trim(substr(check_plain($fquery->description), 0, $excerpt_length)) . '...';
	  $list .= $description;
	}
	
	if ($show_date) {
	  $posteddate = date('h:i A M jS', $fquery->timestamp);
	  $list .= '<br /><br /><span>Posted @ ' . $posteddate .'</span>';
	}
	
	$list .= '</li>';
  }

(all I have added to that is the use of $excerpt_length).

I see there has been an update to 6.x-1.x-dev since I first posted, so I apologise for straying from that - I've just been adding pieces to 6.x-1.3 as my client requested them

Thanks again for the module Ivan,

David

mark_fullmer’s picture

Status: Needs work » Closed (outdated)