function _feedapi_inherit_do_inherit in FeedAPI 6
Same name and namespace in other branches
- 5 feedapi_inherit/feedapi_inherit.module \_feedapi_inherit_do_inherit()
Inherit the feed's taxonomy and og data to the given feed item. Todo: split this into a function for taxonomy and another one for og - easier maintainable.
1 call to _feedapi_inherit_do_inherit()
- feedapi_inherit_nodeapi in feedapi_inherit/
feedapi_inherit.module - Implementation of hook_nodeapi().
File
- feedapi_inherit/
feedapi_inherit.module, line 101 - Inherit group language and taxonomy settings from feeds to news items This is an add on processor for FeedAPI
Code
function _feedapi_inherit_do_inherit(&$item_node, $feed_node) {
$inherit_taxonomy = TRUE;
$inherit_og = TRUE;
if ($feed_node->feed->settings['processors']['feedapi_inherit']) {
$inherit_taxonomy = $feed_node->feed->settings['processors']['feedapi_inherit']['inherit_taxonomy'];
$inherit_og = $feed_node->feed->settings['processors']['feedapi_inherit']['inherit_og'];
$inherit_author = $feed_node->feed->settings['processors']['feedapi_inherit']['inherit_author'];
$inherit_translation = $feed_node->feed->settings['processors']['feedapi_inherit']['inherit_language'];
}
// Pass on author data
if ($inherit_author) {
$item_node->uid = $feed_node->uid;
}
// Pass on taxonomy data
if ($inherit_taxonomy && module_exists('taxonomy')) {
$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;
}
}
}
}
// Pass on group data
if ($inherit_og && module_exists('og')) {
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);
}
}
// Pass on language data
if ($inherit_translation && module_exists('translation')) {
$item_node->language = $feed_node->language;
}
}