function aggregator_save_feed in Drupal 6
Same name and namespace in other branches
- 4 modules/aggregator.module \aggregator_save_feed()
- 5 modules/aggregator/aggregator.module \aggregator_save_feed()
- 7 modules/aggregator/aggregator.module \aggregator_save_feed()
Add/edit/delete an aggregator feed.
Parameters
$edit: An associative array describing the feed to be added/edited/deleted.
1 call to aggregator_save_feed()
- aggregator_form_feed_submit in modules/
aggregator/ aggregator.admin.inc - Process aggregator_form_feed form submissions.
File
- modules/
aggregator/ aggregator.module, line 406 - Used to aggregate syndicated content (RSS, RDF, and Atom).
Code
function aggregator_save_feed($edit) {
if (!empty($edit['fid'])) {
// An existing feed is being modified, delete the category listings.
db_query('DELETE FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']);
}
if (!empty($edit['fid']) && !empty($edit['title'])) {
db_query("UPDATE {aggregator_feed} SET title = '%s', url = '%s', refresh = %d WHERE fid = %d", $edit['title'], $edit['url'], $edit['refresh'], $edit['fid']);
}
else {
if (!empty($edit['fid'])) {
$items = array();
$result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $edit['fid']);
while ($item = db_fetch_object($result)) {
$items[] = "iid = {$item->iid}";
}
if (!empty($items)) {
db_query('DELETE FROM {aggregator_category_item} WHERE ' . implode(' OR ', $items));
}
db_query('DELETE FROM {aggregator_feed} WHERE fid = %d', $edit['fid']);
db_query('DELETE FROM {aggregator_item} WHERE fid = %d', $edit['fid']);
// Make sure there is no active block for this feed.
db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'aggregator', 'feed-' . $edit['fid']);
}
else {
if (!empty($edit['title'])) {
db_query("INSERT INTO {aggregator_feed} (title, url, refresh, block, description, image) VALUES ('%s', '%s', %d, 5, '', '')", $edit['title'], $edit['url'], $edit['refresh']);
// A single unique id for bundles and feeds, to use in blocks.
$edit['fid'] = db_last_insert_id('aggregator_feed', 'fid');
}
}
}
if (!empty($edit['title'])) {
// The feed is being saved, save the categories as well.
if (!empty($edit['category'])) {
foreach ($edit['category'] as $cid => $value) {
if ($value) {
db_query('INSERT INTO {aggregator_category_feed} (fid, cid) VALUES (%d, %d)', $edit['fid'], $cid);
}
}
}
}
}