| 1 |
<?php
|
| 2 |
// $Id: aggregator2_logo.module,v 1.4 2006/07/20 10:15:14 ahwayakchih Exp $
|
| 3 |
|
| 4 |
/*
|
| 5 |
* Aggregator2 Logo filter
|
| 6 |
*
|
| 7 |
* @file
|
| 8 |
* Adds Aggregator2 logo link to feed and it's items body.
|
| 9 |
* @author ahwayakchih <ahwayakchih@gmail.com>
|
| 10 |
*/
|
| 11 |
|
| 12 |
|
| 13 |
/**
|
| 14 |
* Implementation of hook_help().
|
| 15 |
*/
|
| 16 |
function aggregator2_logo_help($section) {
|
| 17 |
switch ($section) {
|
| 18 |
case 'admin/modules#description':
|
| 19 |
return t('Adds logo image to feed and its items body.');
|
| 20 |
|
| 21 |
case 'admin/settings/aggregator2_logo':
|
| 22 |
return '<p>' . t('If the %url include %image or %logo tag information,
|
| 23 |
then this module will automatically add link with image (generated by aggregator2 module)
|
| 24 |
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>';
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Implementation of hook_nodeapi().
|
| 30 |
*/
|
| 31 |
function aggregator2_logo_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
|
| 32 |
if ($node->type == 'aggregator2_item' && $op == 'load' && !$node->image) {
|
| 33 |
// 'Cache' logos, so we don't run SQL query for each item when they have are from the same feed
|
| 34 |
global $aggregator2_feed_logos;
|
| 35 |
if (!$aggregator2_feed_logos[$node->fid]) {
|
| 36 |
$aggregator2_feed_logos[$node->fid] = db_result(db_query('SELECT image FROM {aggregator2_feed} WHERE nid = %d', $node->fid));
|
| 37 |
}
|
| 38 |
$node->image = $aggregator2_feed_logos[$node->fid];
|
| 39 |
}
|
| 40 |
|
| 41 |
if (($node->type != 'aggregator2_item' && $node->type != 'aggregator2-feed') || $op != 'view' || !$node->image) {
|
| 42 |
return;
|
| 43 |
}
|
| 44 |
|
| 45 |
if (($node->type == 'aggregator2_item' && !variable_get('aggregator2_logo_items', 0))
|
| 46 |
|| ($node->type == 'aggregator2_feed' && !variable_get('aggregator2_logo_feed', 0))) {
|
| 47 |
return;
|
| 48 |
}
|
| 49 |
|
| 50 |
if (($node->item_show_link == AGGREGATOR2_SHOW_LINK_ALWAYS) ||
|
| 51 |
($teaser && $node->item_show_link == AGGREGATOR2_SHOW_LINK_TEASER_ONLY) ||
|
| 52 |
(!$teaser && $node->item_show_link == AGGREGATOR2_SHOW_LINK_PAGE_ONLY)) {
|
| 53 |
if ($teaser) {
|
| 54 |
$node->teaser = theme('feed_logo', $node->image).$node->teaser;
|
| 55 |
}
|
| 56 |
else {
|
| 57 |
$node->body = theme('feed_logo', $node->image).$node->body;
|
| 58 |
}
|
| 59 |
}
|
| 60 |
}
|
| 61 |
|
| 62 |
/**
|
| 63 |
* Implementation of hook_settings().
|
| 64 |
*/
|
| 65 |
function aggregator2_logo_settings() {
|
| 66 |
$form['aggregator2_logo_feed'] = array(
|
| 67 |
'#type' => 'checkbox',
|
| 68 |
'#title' => t('Add image to feed description'),
|
| 69 |
'#default_value' => variable_get('aggregator2_logo_feed', 0),
|
| 70 |
'#description' => t('If enabled, feed nodes will be shown with feed logo link added to their description.'),
|
| 71 |
);
|
| 72 |
|
| 73 |
$form['aggregator2_logo_items'] = array(
|
| 74 |
'#type' => 'checkbox',
|
| 75 |
'#title' => t('Add image to feed items description'),
|
| 76 |
'#default_value' => variable_get('aggregator2_logo_items', 0),
|
| 77 |
'#description' => t('If enabled, feed items will be shown with feed logo link added to their description.'),
|
| 78 |
);
|
| 79 |
|
| 80 |
return $form;
|
| 81 |
}
|
| 82 |
|
| 83 |
/**
|
| 84 |
* Theme feed logo/link.
|
| 85 |
*/
|
| 86 |
function theme_feed_logo(&$image) {
|
| 87 |
return '<div class="feed_logo">'.$image.'</div>';
|
| 88 |
}
|