You are here

function _feedapi_node_unique in FeedAPI 5

Same name and namespace in other branches
  1. 6 feedapi_node/feedapi_node.module \_feedapi_node_unique()

Tell if the feed item was seen before or not at the feed

Parameters

$feed_item: Feed item object

$feed_nid: Feed ID

Return value

TRUE if the item is new, FALSE if the item is a duplicated one

File

feedapi_node/feedapi_node.module, line 386
Handle how the feed items are represented as a content Handle the processing of the feed items

Code

function _feedapi_node_unique($feed_item, $feed_nid, $settings) {

  // Feed item is duplicate, if URL or GUID are duplicate or if they are both missing.
  if (isset($feed_item->options->original_url)) {
    $count = db_result(db_query("SELECT fni.nid FROM {feedapi_node_item} fni JOIN {feedapi_node_item_feed} ff ON ff.feed_item_nid = fni.nid WHERE fni.url = '%s' AND ff.feed_nid = %d", $feed_item->options->original_url, $feed_nid));
    if ($count) {
      return FALSE;
    }
  }
  if (isset($feed_item->options->guid)) {
    $count = db_result(db_query("SELECT fni.nid FROM {feedapi_node_item} fni JOIN {feedapi_node_item_feed} ff ON ff.feed_item_nid = fni.nid WHERE fni.guid = '%s' AND ff.feed_nid = %d", $feed_item->options->guid, $feed_nid));
    if ($count) {
      return FALSE;
    }
  }

  // If cross feed de-dupeing is enabled, check now whether there is a duplicate item on other feeds.
  // If so, store duplicates in array.
  // There is *usually* only one. However, there might be more than one.
  // Todo: don't link to feed items whose feed is not x_dedupe enabled.
  if ($settings['x_dedupe']) {
    if (isset($feed_item->options->original_url)) {
      $result = db_query("SELECT fni.nid, ff.feed_nid FROM {feedapi_node_item} fni JOIN {feedapi_node_item_feed} ff ON ff.feed_item_nid = fni.nid WHERE ff.feed_nid <> %d AND fni.url = '%s'", $feed_nid, $feed_item->options->original_url);
      while ($existing_feed_item = db_fetch_object($result)) {
        $feed_item->feedapi_node->duplicates[$existing_feed_item->nid][] = $existing_feed_item->feed_nid;
      }
    }
    if (!isset($feed_item->feedapi_node->duplicates) && isset($feed_item->options->guid)) {
      $result = db_query("SELECT fni.nid, ff.feed_nid FROM {feedapi_node_item} fni JOIN {feedapi_node_item_feed} ff ON ff.feed_item_nid = fni.nid WHERE ff.feed_nid <> %d AND fni.guid = '%s'", $feed_nid, $feed_item->options->guid);
      while ($existing_feed_item = db_fetch_object($result)) {
        $feed_item->feedapi_node->duplicates[$existing_feed_item->nid][] = $existing_feed_item->feed_nid;
      }
    }
  }
  if (isset($feed_item->options->original_url) || isset($feed_item->options->guid)) {
    return TRUE;
  }

  // Neither GUID, nor URL present: no unique item.
  return FALSE;
}