You are here

function _feedapi_aggregator_update in FeedAPI 5

Update news items data

File

feedapi_aggregator/feedapi_aggregator.module, line 451

Code

function _feedapi_aggregator_update($feed_item, $feed_nid, $settings = array()) {
  if ($feed_item->options->guid) {
    $feed_item->fiid = db_result(db_query("SELECT iid FROM {feedapi_aggregator_item} WHERE feed_nid = %d AND guid = '%s'", $feed_nid, $feed_item->options->guid));
  }
  else {
    if ($feed_item->options->original_url) {
      $feed_item->fiid = db_result(db_query("SELECT iid FROM {feedapi_aggregator_item} WHERE feed_nid = %d AND link = '%s'", $feed_nid, $feed_item->options->original_url));
    }
    else {
      $feed_item->fiid = db_result(db_query("SELECT iid FROM {feedapi_aggregator_item} WHERE feed_nid = %d AND title = '%s'", $feed_nid, $feed_item->title));
    }
  }
  if (is_numeric($feed_item->fiid) && isset($feed_item->title)) {
    db_query("UPDATE {feedapi_aggregator_item} SET title = '%s', link = '%s', author = '%s', description = '%s', guid = '%s', timestamp = %d WHERE iid = %d", $feed_item->title, $feed_item->options->original_url, is_object($feed_item->options->original_author) ? $feed_item->options->original_author->name : $feed_item->options->original_author, $feed_item->description, $feed_item->options->guid, $feed_item->options->timestamp, $feed_item->fiid);
    $categories = db_query('SELECT cid FROM {feedapi_aggregator_category_feed} WHERE feed_nid = %d', $feed_nid);
    while ($category = db_fetch_object($categories)) {
      if (0 == db_result(db_query("SELECT COUNT(*) FROM {feedapi_aggregator_category_item} WHERE cid = %d AND iid = %d", $category->cid, $feed_item->fiid))) {
        db_query('INSERT INTO {feedapi_aggregator_category_item} (cid, iid) VALUES (%d, %d)', $category->cid, $feed_item->fiid);
      }
    }
  }
  return $feed_item;
}