Only in .: 632920-90_inherit.patch diff -urp ./feeds.api.php ../NEWfeeds/feeds.api.php --- ./feeds.api.php 2010-05-20 10:46:24.000000000 -0400 +++ ../NEWfeeds/feeds.api.php 2010-05-20 11:02:34.000000000 -0400 @@ -169,5 +169,22 @@ function hook_feeds_data_processor_targe } /** + * Alter inheritors for node processor. Use this hook to add additional + * inheritors to the node processor. This hook does only run if the importer is + * attached to a content type. + * + * The inheritor callback takes two arguments, first the $item_node and second + * the $feed_node. The $item_node is the node beeing created (or updated) and + * $feed_node is the node that the importer is attached to. + */ +function hook_feeds_node_processor_inheritors(&$inheritors) { + $inheritors['user'] = array( + 'name' => t('Inherit author'), + 'description' => t('Feed item nodes will be authored by the same user as the feed node.'), + 'callback' => 'feeds_inherit_user', + ); +} + +/** * @} */ diff -urp ./plugins/FeedsNodeProcessor.inc ../NEWfeeds/plugins/FeedsNodeProcessor.inc --- ./plugins/FeedsNodeProcessor.inc 2010-05-20 10:46:35.000000000 -0400 +++ ../NEWfeeds/plugins/FeedsNodeProcessor.inc 2010-05-20 11:11:39.000000000 -0400 @@ -65,6 +65,13 @@ class FeedsNodeProcessor extends FeedsPr // Map and save nodes. If errors occur don't stop but report them. try { $this->map($item, $node); + + // Add attributes inherited from the source feed node to the node. + if ($source->feed_nid) { + $feed_node = node_load($source->feed_nid); + $this->inherit($feed_node, $node); + } + node_save($node); if (!empty($nid)) { $batch->updated++; @@ -172,6 +179,7 @@ class FeedsNodeProcessor extends FeedsPr 'update_existing' => 0, 'expire' => FEEDS_EXPIRE_NEVER, 'mappings' => array(), + 'inherit' => array(), ); } @@ -202,6 +210,22 @@ class FeedsNodeProcessor extends FeedsPr '#description' => t('Check if existing items should be updated from the feed.'), '#default_value' => $this->config['update_existing'], ); + $disabled = !feeds_importer($this->id)->config['content_type']; + $form['inherit'] = array( + '#type' => 'fieldset', + '#title' => t('Inherit from feed node'), + '#description' => $disabled ? t('Only available for importers that are attached to a content type (see Basic settings).') : t('Copy one or more properties from the feed node to feed item nodes created by this importer.'), + '#tree' => TRUE, + ); + foreach ($this->getInheritors() as $key => $info) { + $form['inherit'][$key] = array( + '#type' => 'checkbox', + '#title' => $info['name'], + '#description' => $info['description'], + '#default_value' => $disabled ? 0 : $this->config['inherit'][$key], + '#disabled' => $disabled, + ); + } return $form; } @@ -336,12 +360,139 @@ class FeedsNodeProcessor extends FeedsPr } return ''; } + + /** + * Invoke inheritors depending on configuration. + */ + protected function inherit($item_node, $feed_node) { + $inheritors = $this->getInheritors(); + foreach ($this->config['inherit'] as $key => $value) { + if ($value && function_exists($inheritors[$key]['callback'])) { + $inheritors[$key]['callback']($feed_node, $item_node); + } + } + } + + /** + * Get a list of available inheritors. + */ + protected function getInheritors() { + $inheritors = array(); + if (module_exists('og')) { + $inheritors['og'] = array( + 'name' => t('Inherit organic group(s)'), + 'description' => t('Feed item nodes inherit organic group settings from feed node.'), + 'callback' => 'feeds_inherit_og', + ); + } + if (module_exists('locale')) { + $inheritors['translation'] = array( + 'name' => t('Inherit language'), + 'description' => t('Feed nodes inherit language settings from feed node.'), + 'callback' => 'feeds_inherit_translation', + ); + } + if (module_exists('taxonomy')) { + $inheritors['taxonomy'] = array( + 'name' => t('Inherit taxonomy'), + 'description' => t('Feed item nodes inherit taxonomy terms from feed node.'), + 'callback' => 'feeds_inherit_taxonomy', + ); + } + $inheritors['user'] = array( + 'name' => t('Inherit author'), + 'description' => t('Feed item nodes will be authored by the same user as the feed node.'), + 'callback' => 'feeds_inherit_user', + ); + drupal_alter('feeds_node_processor_inheritors', $inheritors); + return $inheritors; + } } /** - * Copy of node_delete() that circumvents node_access(). - * - * Used for batch deletion. + * @defgroup inheritors Inheritors for Feeds node processor. + * @{ + */ + +/** + * Inherit OG properties. + */ +function feeds_inherit_og($item_node, $feed_node) { + if (isset($feed_node->og_public) ) { + if (!isset($item_node->og_public)) { + $item_node->og_public = 1; + } + $item_node->og_public = $item_node->og_public & $feed_node->og_public; + } + if (isset($feed_node->og_groups)) { + if (!(isset($item_node->og_groups) && is_array($item_node->og_groups))) { + $item_node->og_groups = array(); + } + $item_node->og_groups = array_merge($feed_node->og_groups, $item_node->og_groups); + foreach ($item_node->og_groups as $gid) { + if ($gid != 0) { + $transformed_groups[$gid] = $gid; + } + } + $item_node->og_groups = $transformed_groups; + } + if (isset($feed_node->og_groups_names)) { + if (!is_array($item_node->og_groups_names)) { + $item_node->og_groups_names = array(); + } + $item_node->og_groups_names = array_merge($feed_node->og_groups_names, $item_node->og_groups_names); + } +} + +/** + * Inherit translation properties. + */ +function feeds_inherit_translation($item_node, $feed_node) { + $item_node->language = $feed_node->language; +} + +/** + * Inherit taxonomy properties. + */ +function feeds_inherit_taxonomy($item_node, $feed_node) { + $terms = taxonomy_node_get_terms($feed_node); + if (!(isset($item_node->taxonomy) && is_array($item_node->taxonomy))) { + $item_node->taxonomy = array(); + } + foreach ($terms as $tid => $term) { + $vid = $term->vid; + $vocabulary = taxonomy_vocabulary_load($vid); + if ($vocabulary->multiple) { + if (!(isset($item_node->taxonomy[$vid]) && is_array($item_node->taxonomy[$vid]))) { + $item_node->taxonomy[$vid] = array(); + } + if (!in_array($tid, $item_node->taxonomy[$vid])) { + $item_node->taxonomy[$vid][$tid] = $tid; + } + } + else { + if (!$item_node->taxonomy[$vid]) { + $item_node->taxonomy[$vid] = $tid; + } + } + } +} + +/** + * Inherit user properties. +*/ +function feeds_inherit_user($item_node, $feed_node) { + $item_node->uid = $feed_node->uid; +} + +/** + * @} +*/ + +/** + * Copy of node_delete() that circumvents node_access(). + * + * Used for batch deletion. */ function _feeds_node_delete($nid) {