You are here

function _feedapi_insert in FeedAPI 6

Same name and namespace in other branches
  1. 5 feedapi.module \_feedapi_insert()

Insert feedapi data to the DB when it's a new for for FeedAPI

2 calls to _feedapi_insert()
feedapi_nodeapi in ./feedapi.module
Implementation of hook_nodeapi().
_feedapi_update in ./feedapi.module
Update feed data of an existing feed

File

./feedapi.module, line 903
Handle the submodules (for feed and item processing) Provide a basic management of feeds

Code

function _feedapi_insert(&$node) {
  if (isset($node->feed->url) && isset($node->feed->feed_type)) {
    if (isset($node->feedapi)) {
      $values = $node->feedapi;
    }
    else {

      // On revert revision, settings are on $node->feed->settings
      // @todo: verify, settings shouldn't be NOT an array here anyway.
      $values = (array) $node->feed->settings;
    }
    db_query("INSERT INTO {feedapi} (\n            nid, vid, url, link, feed_type, processors,\n            parsers, next_refresh_time, settings) VALUES\n            (%d, %d, '%s', '%s', '%s', '%s', '%s', %d, '%s')", $node->nid, $node->vid, $node->feed->url, isset($node->feed->options->link) ? $node->feed->options->link : '', $node->feed->feed_type, serialize($node->feed->processors), serialize($node->feed->parsers), $values['refresh_time'] == FEEDAPI_CRON_NEVER_REFRESH ? $values['refresh_time'] : time() + $values['refresh_time'], serialize(array()));

    // Store add on module's settings if user has permission to do so.
    if (user_access('advanced feedapi options')) {
      _feedapi_store_settings(array(
        'vid' => $node->vid,
      ), $values);
    }

    // Refresh feed if the user would like to do that
    $settings = feedapi_get_settings($node->type, $node->vid);
    if (isset($settings['refresh_on_create'])) {
      if ($settings['refresh_on_create'] == TRUE) {
        $node->feed->nid = $node->nid;
        $node->feed->vid = $node->vid;
        $node->feed->settings = $settings;
        feedapi_invoke('refresh', $node->feed);
      }
    }
  }
}