function feedapi_nodeapi in FeedAPI 6
Same name and namespace in other branches
- 5 feedapi.module \feedapi_nodeapi()
Implementation of hook_nodeapi().
File
- ./
feedapi.module, line 122 - 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 'validate':
$node->feed->settings = feedapi_get_settings($node->type);
$node->feed->parsers = _feedapi_format_settings($node->feed->settings, 'parsers');
$node->feed->processors = _feedapi_format_settings($node->feed->settings, 'processors');
if (count($node->feed->parsers) < 1) {
if (user_access('administer content types')) {
form_set_error('', t('There are no enabled parsers for this content type. In order to import feed items, you need to select a feed parser from the <a href="@url">content type settings</a>.', array(
'@url' => url("admin/content/node-type/{$node->type}"),
)));
}
else {
form_set_error('', t('There is no parser enabled for this content-type. Contact your site administrator for help.'));
}
}
if (count($node->feed->processors) < 1) {
if (user_access('administer content types')) {
form_set_error('', t('There are no enabled processors for this content type. In order to import feed items, you need to select a processor from the <a href="@url">content type settings</a>.', array(
'@url' => url("admin/content/node-type/{$node->type}"),
)));
}
else {
form_set_error('', t('There is no processor enabled for this content-type. Contact your site administrator for help.'));
}
}
break;
case 'insert':
_feedapi_insert($node);
break;
case 'update':
_feedapi_update($node);
break;
case 'load':
if ($feed = db_fetch_object(db_query('SELECT * FROM {feedapi} WHERE vid = %d', $node->vid))) {
$node->feed = $feed;
$node->feed->vid = $node->vid;
$node->feed->nid = $node->nid;
$node->feed->settings = feedapi_get_settings($node->type, $node->vid);
// 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('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 'presave':
if (is_array($node->feedapi) || isset($node->feedapi_object)) {
$node->feed = isset($node->feedapi_object) ? $node->feedapi_object : _feedapi_build_feed_object($node->type, $node->feedapi['feedapi_url']);
}
break;
case 'delete revision':
db_query("DELETE FROM {feedapi} WHERE nid = %d AND vid = %d", $node->nid, $node->vid);
break;
}
}
}