Index: feedaggregator_node.module =================================================================== --- feedaggregator_node.module (revision 1272) +++ feedaggregator_node.module (working copy) @@ -149,49 +149,50 @@ static $cat_names = array(); switch($op) { - case 'processor_name': - return array('feedaggregator_node' => t('Nodes')); + case 'processor_name': + return array('feedaggregator_node' => t('Nodes')); case 'item_save': if($feed['processor'] == 'feedaggregator_node') { - // Determin the full story URL + // Determine the full story URL $node['link'] = $item->get_link(); $node['guid'] = $item->get_id(); - // Check if the item already exists - $duplicate = db_fetch_array(db_query("SELECT nid FROM {aggregator_node} WHERE guid = '%s'", $node['guid'])); - if($duplicate['nid']) { + // Check if the item already exists + $duplicate = db_fetch_array(db_query("SELECT nid FROM {aggregator_node} WHERE guid = '%s'", $node['guid'])); + if($duplicate['nid']) { - // Does this feed support updating of existing items? - if(!$feed['update_items']) { - return array('saved' => FALSE); - } + // Does this feed support updating of existing items? + if(!$feed['update_items']) { + return array('saved' => FALSE); + } - $old_node = (array)node_load(array('nid' => $duplicate['nid'])); + $old_node = (array)node_load(array('nid' => $duplicate['nid'])); - // We need to compare the content after it has passed through Drupals filters - // as the existing stuff is provided to us after filtering. + // We need to compare the content after it has passed through Drupals filters + // as the existing stuff is provided to us after filtering. $new_title = $item->get_title(); - $new_body = check_markup($item->get_content(), $old_node['format'], FALSE); + $new_body = check_markup($item->get_content(), $old_node['format'], FALSE); - // Should this feed honor updating of existing items? - if(strcasecmp($old_node['body'], $new_body) == 0 && - strcasecmp($old_node['title'], $new_title) == 0) { - return array('saved' => FALSE); - } + // Should this feed honor updating of existing items? + if(strcasecmp($old_node['body'], $new_body) == 0 && strcasecmp($old_node['title'], $new_title) == 0) { + return array('saved' => FALSE); + } - $node = $old_node; + $node = $old_node; watchdog('aggregator', t('Updated node %title', array('%title' => $new_title)).serialize($node), WATCHDOG_NOTICE, l(t('view'), "node/{$node['nid']}")); - } else { - // Set nodes default options - $options = variable_get('node_options_aggregator-item', array('status', 'promote')); - foreach($options as $option) { - $node[$option] = 1; - } - $node['created'] = $item->get_date('U'); + } else { // Create a new node + + // Set nodes default options + $options = variable_get('node_options_aggregator-item', array('status', 'promote')); + foreach($options as $option) { + $node[$option] = 1; + } + + $node['created'] = $item->get_date('U'); $node['date'] = format_date($node['created'], 'custom', 'Y-m-d H:i:s O'); $node += array( 'fid' => $feed['fid'], @@ -199,67 +200,70 @@ 'iid' => $item->data['iid'], 'comment' => variable_get('comment_aggregator-item', 2) ); - } + } + $title = $item->get_title(); - $node = array( - 'changed' => time(), - 'title' => parse_entities($title), - 'body' => $item->get_content(), - 'taxonomy' => $feed['taxonomy'], - 'format' => $feed['format'] - ) + $node; + $base_node = array( + 'changed' => time(), + 'title' => parse_entities($title), + 'body' => $item->get_content(), + 'taxonomy' => $feed['taxonomy'], + 'format' => $feed['format'] + ); - // Convert Node array in to an object - $node = (object)$node; + $node = array_merge($node, $base_node); - if($feed['autotaxonomy'] && is_array($item->get_categories())) { - // Find the vocabulary associated with this node type - $vocab = feedaggregator_node_get_vocabulary(); + // Convert Node array in to an object + $node = (object)$node; - // Process any feed item category tags - if($vocab) { - foreach ($item->get_categories() as $category_name) { - if (trim($category_name) != '') { + if($feed['autotaxonomy'] && is_array($item->get_categories())) { + // Find the vocabulary associated with this node type + $vocab = feedaggregator_node_get_vocabulary(); - // See if the term is already defined - if (!isset($cat_names[$category_name])) { - $cat_names[$category_name] = module_invoke('taxonomy', 'get_term_by_name', $category_name); - } + // Process any feed item category tags + if($vocab) { + foreach ($item->get_categories() as $category_name) { + if (trim($category_name) != '') { - // If there is no existing term, create a new one - if (count($cat_names[$category_name]) == 0) { - $term = array(); - $term['name'] = check_plain($category_name); - $term['description'] = ''; - $term['vid'] = $vocab; - $term['weight'] = 0; - module_invoke('taxonomy', 'save_term', $term); + // See if the term is already defined + if (!isset($cat_names[$category_name])) { + $cat_names[$category_name] = module_invoke('taxonomy', 'get_term_by_name', $category_name); + } - // Assign the new term to our new node - $node->taxonomy[] = $term['tid']; - $cat_names[$category_name][0]->tid = $term['tid']; - } - else { - // Use the existing category term in the database - if (!in_array($cat_names[$category_name][0]->tid, $node->taxonomy)) { - $node->taxonomy[] = $cat_names[$category_name][0]->tid; - } - } - } - } - } - } + // If there is no existing term, create a new one + if (count($cat_names[$category_name]) == 0) { + $term = array(); + $term['name'] = check_plain($category_name); + $term['description'] = ''; + $term['vid'] = $vocab; + $term['weight'] = 0; + module_invoke('taxonomy', 'save_term', $term); - // Share the feeds item object with any modules implementing the hook_nodeapi() - $node->feedparser_item_data = $item; + // Assign the new term to our new node + $node->taxonomy[] = $term['tid']; + $cat_names[$category_name][0]->tid = $term['tid']; + } + else { + // Use the existing category term in the database + if (!in_array($cat_names[$category_name][0]->tid, $node->taxonomy)) { + $node->taxonomy[] = $cat_names[$category_name][0]->tid; + } + } + } + } + } + } + // Share the feeds item object with any modules implementing the hook_nodeapi() + $node->feedparser_item_data = $item; - // In order to process a node properly in a cron job we need to simulate a - // user (UID 1) being logged in so that node options are not lost during an update. - $current_user = $user; - $user = user_load(array('uid' => 1)); + + // In order to process a node properly in a cron job we need to simulate a + // user (UID 1) being logged in so that node options are not lost during an update. + $current_user = $user; + $user = user_load(array('uid' => 1)); node_object_prepare($node); $node = node_submit($node); $user = $current_user; @@ -269,8 +273,8 @@ $account = user_load(array('name' => $feed['name'])); $node->uid = $account->uid; - node_save($node); - return array('saved' => TRUE); + node_save($node); + return array('saved' => TRUE); } break;