Skip navigation
Help

aggregator_save_feed

6 aggregator.module aggregator_save_feed($edit)
7 aggregator.module aggregator_save_feed($edit)

Add/edit/delete an aggregator feed.

Parameters

$edit: An associative array describing the feed to be added/edited/deleted.

2 calls to aggregator_save_feed()

File

drupal/modules/aggregator/aggregator.module, line 482
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_delete('aggregator_category_feed')
      ->condition('fid', $edit['fid'])
      ->execute();
  }
  if (!empty($edit['fid']) && !empty($edit['title'])) {
    db_update('aggregator_feed')
      ->condition('fid', $edit['fid'])
      ->fields(array(
      'title' => $edit['title'], 
      'url' => $edit['url'], 
      'refresh' => $edit['refresh'], 
      'block' => $edit['block'],
    ))
      ->execute();
  }
  elseif (!empty($edit['fid'])) {
    $iids = db_query('SELECT iid FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $edit['fid']))->fetchCol();
    if ($iids) {
      db_delete('aggregator_category_item')
        ->condition('iid', $iids, 'IN')
        ->execute();
    }
    db_delete('aggregator_feed')->
      condition('fid', $edit['fid'])
      ->execute();
    db_delete('aggregator_item')
      ->condition('fid', $edit['fid'])
      ->execute();
    // Make sure there is no active block for this feed.
    db_delete('block')
      ->condition('module', 'aggregator')
      ->condition('delta', 'feed-' . $edit['fid'])
      ->execute();
  }
  elseif (!empty($edit['title'])) {
    $edit['fid'] = db_insert('aggregator_feed')
      ->fields(array(
      'title' => $edit['title'], 
      'url' => $edit['url'], 
      'refresh' => $edit['refresh'], 
      'block' => $edit['block'], 
      'description' => '', 
      'image' => '',
    ))
      ->execute();

  }
  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_insert('aggregator_category_feed')
            ->fields(array(
            'fid' => $edit['fid'], 
            'cid' => $cid,
          ))
            ->execute();
        }
      }
    }
  }
}