aggregator2-4.6.x-1.x-dev/aggregator2_logo.module

aggregator2_logo.module
<?php

/*
 * Aggregator2 Logo filter
 *
 * @file
 * Adds Aggregator2 logo link to feed and it's items body.
 * @author ahwayakchih <ahwayakchih@gmail.com>
 */


/**
* Implementation of hook_help().
*/
function aggregator2_logo_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Adds logo image to feed and it\'s items body.');

    case 'admin/settings/aggregator2_logo':
      return '<p>' . t('If the %url include %image or %logo tag information,
      then this module will automatically add link with image (generated by aggregator2 module)
      to text content of feed and/or it\'s items.<br />Image link will be shown only if "Show full article/source site link" option of feed allows that.', array('%url' => l('RSS feeds you are aggregating', 'admin/aggregator2'), '%image' => theme('placeholder', '<image>'), '%logo' => theme('placeholder', '<logo>'))). '</p>';
  }
}

/**
* Implementation of hook_nodeapi().
*/
function aggregator2_logo_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if ($node->type == 'aggregator2-item' && $op == 'load' && !$node->image) {
    // 'Cache' logos, so we don't run SQL query for each item when they have are from the same feed
    global $aggregator2_feed_logos;
    if (!$aggregator2_feed_logos[$node->fid]) {
      $aggregator2_feed_logos[$node->fid] = db_result(db_query('SELECT image FROM {aggregator2_feed} WHERE nid = %d', $node->fid));
    }
    $node->image = $aggregator2_feed_logos[$node->fid];
  }

  if (($node->type != 'aggregator2-item' && $node->type != 'aggregator2-feed') || $op != 'view' || !$node->image) {
    return;
  }

  if (($node->type == 'aggregator2-item' && !variable_get('aggregator2_logo_items', 0))
    || ($node->type == 'aggregator2-feed' && !variable_get('aggregator2_logo_feed', 0))) {
    return;
  }

  if (($node->item_show_link == AGGREGATOR2_SHOW_LINK_ALWAYS) ||
    ($teaser && $node->item_show_link == AGGREGATOR2_SHOW_LINK_TEASER_ONLY) ||
    (!$teaser && $node->item_show_link == AGGREGATOR2_SHOW_LINK_PAGE_ONLY)) {
      if ($teaser) {
        $node->teaser = theme('feed_logo', $node) . $node->teaser;
      }
      else {
        $node->body = theme('feed_logo', $node) . $node->body;
      }
  }
}

/**
 * Implementation of hook_settings().
 */
function aggregator2_logo_settings() {
  $output = '';

  $output .= form_checkbox(t('Add image to feed description'), 'aggregator2_logo_feed', 1, variable_get('aggregator2_logo_feed', 0), t('If enabled, feed nodes will be shown with feed logo link added to their description.'));
  $output .= form_checkbox(t('Add image to feed items description'), 'aggregator2_logo_items', 1, variable_get('aggregator2_logo_items', 0), t('If enabled, feed items will be shown with feed logo link added to their description.'));

  return $output;
}

/**
 * Theme feed logo/link.
 */
function theme_feed_logo(&$node) {
	if (strlen($node->image) < 1) {
		return '';
	}

	$pos = strpos($node->image, 'http://');
	if ($pos !== false && $pos == 0) {
		return '<div class="feed_logo"><a href="'. ($node->feed_link ? $node->feed_link : $node->link) .'" class="aggregator2_logo_link"><img src="'. $node->image .'" class="aggregator2_logo" alt="'. ($node->feed_title ? $node->feed_title : $node->title) .'" /></a></div>';
	}
	else {
	  return '<div class="feed_logo">'.$node->image.'</div>';
	}
}
?>

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc