function aggregator_save_feed

Adds/edits/deletes an aggregator feed.

Parameters

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

Return value

The ID of the feed.

3 calls to aggregator_save_feed()
AggregatorRenderingTest::testBlockLinks in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php
Add a feed block to the page and checks its links.
aggregator_form_feed_submit in drupal/core/modules/aggregator/aggregator.admin.inc
Form submission handler for aggregator_form_feed().
CategorizeFeedTest::testCategorizeFeed in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/CategorizeFeedTest.php
Create a feed and make sure you can add more than one category to it.

File

drupal/core/modules/aggregator/aggregator.module, line 498
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.
    if (module_exists('block')) {
      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'],
      'link' => '',
      '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();
        }
      }
    }
  }
  return $edit['fid'];
}