| 1 |
<?php
|
| 2 |
// $Id: feedenclosure.module,v 1.6 2006/11/19 23:27:28 budda Exp $
|
| 3 |
|
| 4 |
/*
|
| 5 |
* Feed Enclosure
|
| 6 |
* @description: Stores RSS enclosures and provides a way to access them when browsing aggregated node content
|
| 7 |
*
|
| 8 |
* @author: Mike Carter < mike @ www.ixis.co.uk/contact >
|
| 9 |
*/
|
| 10 |
|
| 11 |
function feedenclosure_help($section) {
|
| 12 |
switch ($section) {
|
| 13 |
case 'admin/help#feedenclosure':
|
| 14 |
return t('To be written.');
|
| 15 |
case 'admin/modules#description':
|
| 16 |
return t('Handle RSS feed enclosures.');
|
| 17 |
}
|
| 18 |
}
|
| 19 |
|
| 20 |
|
| 21 |
function feedenclosure_feedapi($feed, $op, $item = NULL) {
|
| 22 |
switch($op) {
|
| 23 |
case 'item_save':
|
| 24 |
$iid = $item->data['iid'];
|
| 25 |
$enclosures = $item->get_enclosures();
|
| 26 |
|
| 27 |
if($enclosures) {
|
| 28 |
foreach($enclosures as $enclosure) {
|
| 29 |
$eid = db_next_id('aggregator_enclosure');
|
| 30 |
db_query("INSERT INTO {aggregator_enclosure} SET eid = %d, iid = %d, link = '%s', fid = '%d', length = %d, type = '%s'", $eid, $iid, $enclosure->get_link(), $feed['fid'], $enclosure->get_length(), $enclosure->get_type());
|
| 31 |
}
|
| 32 |
}
|
| 33 |
break;
|
| 34 |
|
| 35 |
case 'remove':
|
| 36 |
db_query('DELETE FROM {aggregator_enclosure} WHERE fid = %d', $feed['fid']);
|
| 37 |
break;
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
| 41 |
function feedenclosure_link($type, $node = NULL, $teaser = FALSE) {
|
| 42 |
if($type == 'node' && isset($node->fid) && isset($node->iid)) {
|
| 43 |
$enclosure = db_fetch_array(db_query("SELECT * FROM {aggregator_enclosure} WHERE fid = %d AND iid = %d", $node->fid, $node->iid));
|
| 44 |
if($enclosure) {
|
| 45 |
|
| 46 |
if (!empty($enclosure['length'])) {
|
| 47 |
$size = ' (' . round($enclosure['length']/1048576, 2) . ' MB)';
|
| 48 |
}
|
| 49 |
|
| 50 |
$links['feedenclosure'] = l(
|
| 51 |
t('download attachment %size', array('%size' => $size)),
|
| 52 |
$enclosure['link']
|
| 53 |
);
|
| 54 |
return $links;
|
| 55 |
}
|
| 56 |
}
|
| 57 |
}
|