Community & Support

"Blog-it" button on all posts

Hello

I was wondering if anyone has a customized the xxxx module (?) to achieve the following:

1. "Blog it"-button/link, appearing below all nodes (like "add comment") not only in the aggregator-block. It should copy the text into a new post just like the Blog-it button does from the block. If "perfect" it should ask which node type to "blog it as": Blog, Forum post, Book page, etc, but that can be a later variant, most important is to be able to blog any posts easily at all.

2. Blog-it button beside each item in the news aggregator listing where the teasers are shown.

Not being a PHP programmer myself, I'm looking for a bit of advice on how to customize to have this functionality.

Any help/advice is highly appreciated.

Comments

Modified this piece of code, is it correct?

Hi

I've been trying to achieve something similar.

So far I've done the some changes to the piece of code that appears in the aggregator.module-file, but I still didnt manage to see "Blog it"-button anywhere.

Could someone please review what I've done, and help me out?

***************************

/**
* Format an individual feed item for display on the aggregator page.
*
* @ingroup themeable
*/
function theme_aggregator_page_item($item) {
  static $last;

  $date = format_date($item->timestamp, 'custom', 'Ymd');
  if ($date != $last) {
    $last = $date;
    $output .= '<h3>'. format_date($item->timestamp, 'custom', 'F j, Y') ."</h3>\n";
  }

  $output .= "<div class=\"news-item\">\n";
  $output .= ' <div class="date">'. format_date($item->timestamp, 'custom', 'H:i') ."</div>\n";
  $output .= " <div class=\"body\">\n";
  $output .= '  <div class="title"><a href="/'. check_url($item->link) .'">'. check_plain($item->title) ."</a></div>\n";
  if ($item->description) {
    $output .= '  <div class="description">'. $item->description ."</div>\n";
  }

/**
* I customized from here
*
*
*/
  if ($user->uid && module_exist('blog') && user_access('edit own blog')) {
    if ($image = theme('image', 'misc/blog.png', t('blog it'), t('blog it'))) {
      $output .= '<div class="icon">'. l($image, 'node/add/blog', array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), "iid=$item->iid", NULL, FALSE, TRUE) .'</div>';
    }
  }
    if ($item->ftitle && $item->fid)

/**
* I customized to here
*
*
*/
{
    $output .= '  <div class="source">'. t('Source') .': '. l($item->ftitle, "aggregator/sources/$item->fid") ."</div>\n";
  }

  $result = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = %d ORDER BY c.title', $item->iid);
  $categories = array();
  while ($category = db_fetch_object($result)) {
    $categories[] = l($category->title, 'aggregator/categories/'. $category->cid);
  }
  if ($categories) {
    $output .= '  <div class="categories">'. t('Categories') .': '. implode(', ', $categories) ."</div>\n";
  }

  $output .= " </div>\n";
  $output .= "</div>\n";

  return $output;
}

**********************************************

This Solution Worked For Me

I just copied and pasted the "blog it" lines from the block section of the module to the page_item section. I think you did the same, the difference for me is where I pasted. See below.

I tried this out in Drupal 5 first; what's pasted below is what I ended up with in 4.7. The difference between 5 and 4.7? 5 used a function called module_exists(), while 4.7 used module_exist().

Hope this helps :-)

/**
* Format an individual feed item for display on the aggregator page.
*
* @ingroup themeable
*/
function theme_aggregator_page_item($item) {

  $source = '';
  if ($item->ftitle && $item->fid) {
    $source = l($item->ftitle, "aggregator/sources/$item->fid", array('class' => 'feed-item-source')) . ' -';
  }

  if (date('Ymd', $item->timestamp) == date('Ymd')) {
    $source_date = t('%ago ago', array('%ago' => format_interval(time() - $item->timestamp)));
  }
  else {
    $source_date = format_date($item->timestamp, 'custom', variable_get('date_format_medium', 'D, Y-m-d H:i'));
  }

  $output .= "<div class=\"feed-item\">\n";
  $output .= '<h3 class="feed-item-title"><a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a></h3>\n";
  $output .= "<div class=\"feed-item-meta\">$source <span class=\"feed-item-date\">$source_date</span></div>\n";

  if ($item->description) {
    $output .= '<div class="feed-item-body">'. aggregator_filter_xss($item->description) ."</div>\n";
  }

  $result = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = %d ORDER BY c.title', $item->iid);
  $categories = array();
  while ($category = db_fetch_object($result)) {
    $categories[] = l($category->title, 'aggregator/categories/'. $category->cid);
  }
  if ($categories) {
    $output .= '<div class="feed-item-categories">'. t('Categories') .': '. implode(', ', $categories) ."</div>\n";
  }
 
# add the "blog it" button to the feed page, not just blocks!
 
  global $user;

  if ($user->uid && module_exist('blog') && user_access('edit own blog')) {
    if ($image = theme('image', 'misc/blog.png', t('blog it'), t('blog it'))) {
      $output .= '<div class="links">'. l('Blog This', 'node/add/blog', array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), "iid=$item->iid", NULL, FALSE, TRUE) .'</div>';
    }
  }
  $output .= "</div>\n";

  return $output;
}

Adding "Blog It" to the Aggregator page itself

I needed the "Blog It" link/button to show up on each item on the actual aggregator PAGE not just the block. This is how I accomplished this:

  1. First copy the file aggregator-item.tpl.php from /modules/aggregator/aggregator-item.tpl.php to /sites/all/themes/YOUR_THEME_NAME/aggregator-item.tpl.php
  2. Then, edit the template.php of your theme (/sites/all/themes/YOUR_THEME_NAME/template.php)
  3. Paste the following into your template.php file (changing YOUR_THEME_NAME to the actual name of your theme):
    function YOUR_THEME_NAME_preprocess_aggregator_item(&$variables){
      $item = $variables['item'];
      global $user;
      $output = '';
      if ($user->uid && module_exists('blog') && user_access('create blog entries')) {
        if ($image = theme('image', 'misc/blog.png', t('blog it'), t('blog it'))) {
          $output .= '<div class="icon">'. l($image, 'node/add/blog', array('attributes' => array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), 'query' => "iid=$item->iid", 'html' => TRUE)) .'</div>';
        }
      }
      $variables['blog_button'] = $output;
    }
  4. Now, let's edit the aggregator-item.tpl.php file we copied earlier. (It should now reside at /sites/all/themes/YOUR_THEME_NAME/aggregator-item.tpl.php). I wanted the "Blog It" button to appear right below the title of each aggregator item, so I changed the following from:
    <h3 class="feed-item-title">
        <a href="<?php print $feed_url; ?>"><?php print $feed_title; ?></a>
      </h3>

    to:
    <h3 class="feed-item-title">
        <a href="<?php print $feed_url; ?>"><?php print $feed_title; ?></a>
      </h3>
      <?php print $blog_button; ?>
  5. That's it! Hope this helps :)

nobody click here