function _fetch_affected_keywords in Glossify 6
Same name and namespace in other branches
- 6.3 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.
1 call to _fetch_affected_keywords()
- glossify_nodeapi in ./
glossify.module - Implementation of hook_nodeapi().
File
- ./
glossify.module, line 472
Code
function _fetch_affected_keywords($node, $method, $keywordsource = NULL, $override = '') {
$keywords = array();
$existing_keywords = _fetch_keywords($node->nid, $method);
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':
if (isset($node->{$keywordsource}[0]['value']) && isset($node->{$override}[0]['value'])) {
$form_keywords = !empty($node->{$keywordsource}[0]['value']) ? array_map('trim', explode(',', $node->{$keywordsource}[0]['value'])) : array();
$form_override = $node->{$override}[0]['value'];
}
else {
drupal_set_message(t("This content type does not have the selected CCK Fields attached to it!<br />You need to either change the configuration or attach the selected CCK Fields to this content type."), 'warning');
return array();
}
break;
case 'taxonomy':
if (isset($node->taxonomy['tags'][$keywordsource])) {
$form_keywords = !empty($node->taxonomy['tags'][$keywordsource]) ? array_map('trim', explode(',', $node->taxonomy['tags'][$keywordsource])) : array();
$form_override = $override;
}
else {
drupal_set_message(t("This content type does not have the selected Vocabulary attached to it!<br />You need to either change the configuration or attach the selected Vocabulary to this content type."), 'warning');
return array();
}
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, $node->language, $keyword));
}
foreach ($ikwds2 as $keyword) {
$keywords = array_merge($keywords, _keyword_table('insert', $node->nid, $method, $node->language, $keyword, $form_override));
}
}
}
}
else {
foreach ($form_keywords as $keyword) {
$keywords = array_merge($keywords, _keyword_table('insert', $node->nid, $method, $node->language, $keyword, $form_override));
}
}
}
else {
if (count($existing_keywords) > 0) {
$keywords = array_merge($keywords, _keyword_table('delete', $node->nid, $method));
}
}
return $keywords;
}