You are here

function aggregator_save_feed in Drupal 5

Same name and namespace in other branches
  1. 4 modules/aggregator.module \aggregator_save_feed()
  2. 6 modules/aggregator/aggregator.module \aggregator_save_feed()
  3. 7 modules/aggregator/aggregator.module \aggregator_save_feed()

Add/edit/delete an aggregator feed.

1 call to aggregator_save_feed()
aggregator_form_feed_submit in modules/aggregator/aggregator.module
Process aggregator_form_feed form submissions. @todo Add delete confirmation dialog.

File

modules/aggregator/aggregator.module, line 536
Used to aggregate syndicated content (RSS, RDF, and Atom).

Code

function aggregator_save_feed($edit) {
  if ($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 ($edit['fid'] && $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 ($edit['fid']) {
      $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $edit['fid']);
      while ($item = db_fetch_object($result)) {
        $items[] = "iid = {$item->iid}";
      }
      if ($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']);
    }
    else {
      if ($edit['title']) {

        // A single unique id for bundles and feeds, to use in blocks.
        $edit['fid'] = db_next_id('{aggregator_feed}_fid');
        db_query("INSERT INTO {aggregator_feed} (fid, title, url, refresh, block) VALUES (%d, '%s', '%s', %d, 5)", $edit['fid'], $edit['title'], $edit['url'], $edit['refresh']);
      }
    }
  }
  if ($edit['title']) {

    // The feed is being saved, save the categories as well.
    if ($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);
        }
      }
    }
  }
}