You are here

function feedapi_nodeapi in FeedAPI 5

Same name and namespace in other branches
  1. 6 feedapi.module \feedapi_nodeapi()

Implementation of hook_nodeapi().

File

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

Code

function feedapi_nodeapi(&$node, $op, $teaser, $page) {
  if (isset($node->feed) || feedapi_enabled_type($node->type)) {
    switch ($op) {
      case 'insert':
        _feedapi_insert($node, $teaser, $page);
        break;
      case 'update':
        _feedapi_update($node, $teaser, $page);
        break;
      case 'load':
        if ($feed = db_fetch_object(db_query('SELECT * FROM {feedapi} WHERE nid = %d', $node->nid))) {
          $node->feed = $feed;
          $node->feed->settings = feedapi_get_settings($node->type, $node->nid);

          // Load parsers and processors from content type
          $node_type_settings = feedapi_get_settings($node->type);
          $node->feed->parsers = _feedapi_format_settings($node_type_settings, 'parsers');
          $node->feed->processors = _feedapi_format_settings($node_type_settings, 'processors');
        }
        break;
      case 'delete':

        // Could be a performance problem - think of thousands of node feed items.
        //  This is a temporary status. See: http://drupal.org/node/195723
        // feedapi_invoke_feedapi('purge', $node->feed);
        db_query("DELETE FROM {feedapi_stat} WHERE id = %d", $node->nid);
        db_query("DELETE FROM {feedapi} WHERE nid = %d", $node->nid);
        break;
      case 'validate':
        if (!$node->title) {
          form_set_error('title', t('Title could not be retrieved from feed.'));
        }
        break;
      case 'submit':

        // Todo: the first case essentially copies the entire feed array from feedapi to feed.
        // Figure out a way how to save this step.
        $node->feed = isset($node->feedapi_feed_object) ? $node->feedapi_feed_object : _feedapi_build_feed_object($node->type, $node->feedapi['feedapi_url']);
        break;
    }
  }
}