function _fetch_affected_keywords in Glossify 6.3
Same name and namespace in other branches
- 6 glossify.module \_fetch_affected_keywords()
Helper function that fetches and returns an array of all new and old keywords of a node, depending on the method. It also provides for an easy way to update the keywords of a given method/configuration combination.
2 calls to _fetch_affected_keywords()
- glossify_nodeapi in ./
glossify.module - Implementation of hook_nodeapi().
- _update_keywords_for_methods in ./
glossify.module - Helper function that updates the keyword-tables according to the new/old methods.
File
- ./
glossify.module, line 782
Code
function _fetch_affected_keywords($node, $method, $configuration = 'global', $keywordsource = NULL, $override = '') {
$keywords = array();
$existing_keywords = _fetch_keywords($node->nid, $method, $configuration);
switch ($method) {
case 'internal':
$form_keywords = !empty($node->glossify_keywords) ? array_map('trim', explode(',', $node->glossify_keywords)) : array();
$form_override = $node->glossify_override;
break;
case 'cck':
$keyword = $node->{$keywordsource};
$override = $node->{$override};
if (isset($keyword[0]['value'])) {
$form_keywords = !empty($keyword[0]['value']) ? array_map('trim', explode(',', $keyword[0]['value'])) : array();
}
if (isset($override[0]['value'])) {
$form_override = $override[0]['value'];
}
else {
$form_override = '';
}
break;
case 'taxonomy':
if (isset($node->taxonomy)) {
$form_keywords = array();
foreach ($node->taxonomy['tags'] as $vid => $tag) {
if (in_array($vid, $keywordsource)) {
$form_keywords = array_merge($form_keywords, array_map('trim', explode(',', $tag)));
}
}
$form_override = $override;
}
break;
}
if (count($form_keywords) > 0) {
if (count($existing_keywords)) {
$ikwds1 = array_diff($existing_keywords, $form_keywords);
$ikwds2 = array_diff($form_keywords, $existing_keywords);
if (count($ikwds1) !== count($ikwds2) || count($ikwds1) !== 0 && count($ikwds2) !== 0) {
$ikwds3 = array_intersect($ikwds1, $ikwds2);
if (count($ikwds3) == 0) {
foreach ($ikwds1 as $keyword) {
$keywords = array_merge($keywords, _keyword_table('delete', $node->nid, $method, $configuration, $node->language, $keyword));
}
foreach ($ikwds2 as $keyword) {
$keywords = array_merge($keywords, _keyword_table('insert', $node->nid, $method, $configuration, $node->language, $keyword, $form_override));
}
}
}
}
else {
foreach ($form_keywords as $keyword) {
$keywords = array_merge($keywords, _keyword_table('insert', $node->nid, $method, $configuration, $node->language, $keyword, $form_override));
}
}
}
else {
if (count($existing_keywords) > 0) {
$keywords = array_merge($keywords, _keyword_table('delete', $node->nid, $method, $configuration));
}
}
return $keywords;
}