# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. --- /rules/rules/modules/taxonomy.rules.inc +++ /rules/rules/modules/taxonomy.rules.inc @@ -201,8 +201,8 @@ * Action: Remove a term from content. */ function rules_action_taxonomy_term_remove_from_content($node, $taxonomy_term, $settings) { - if (isset($node->taxonomy[$taxonomy_term->tid])) { - unset($node->taxonomy[$taxonomy_term->tid]); + if (isset($node->taxonomy[$taxonomy_term->vid]) && $node->taxonomy[$taxonomy_term->vid] == $taxonomy_term->tid) { + unset($node->taxonomy[$taxonomy_term->vid]); return array('node' => $node); } } @@ -277,5 +277,75 @@ } /** + * Implementation of hook_rules_condition_info(). + */ +function taxonomy_rules_condition_info() { + return array( + 'rules_condition_content_has_term' => array( + 'label' => t('Content has term'), + 'help' => t('Evaluates to TRUE if the given content has one of the selected terms.'), + 'module' => 'Taxonomy', + 'arguments' => array( + 'node' => array('type' => 'node', 'label' => t('Content')), + ), + ), + ); +} + +/** + * Condition: Check for selected terms. + */ +function rules_condition_content_has_term(&$node, $settings) { + + $taxonomy = $node->taxonomy; + + // If vocab is marked as tag, we format it to the proper format. + if (isset($taxonomy['tags']) && count($taxonomy['tags']) > 0) { + foreach ($taxonomy['tags'] as $vid => $term) { + $terms_names = explode(', ', $term); + foreach ($terms_names as $term_name) { + // It can return multiple terms with the same name. + $terms_objects = taxonomy_get_term_by_name($term_name); + foreach ($terms_objects as $term_object) { + $tid = $term_object->tid; + // Avoid terms with same name in different vocabularies. + if ($term_object->vid == $vid){ + $taxonomy[$vid][$tid] = $tid; + } + } + } + } + // Since we won't use it unset to not bother us. + unset($taxonomy['tags']); + } + + + if (isset($taxonomy) && (count($taxonomy) > 0)) { + $tids = array(); + + foreach ($taxonomy as $vocab) { + if (!empty($vocab) && is_array($vocab)) { + foreach ($vocab as $term) { + $tid = is_object($term) ? $term->tid : (is_array($term) ? reset($term) : $term); + $tids[$tid] = $tid; + } + } + else { + if (!empty($vocab)) { + $tids[$vocab->tid] = $vocab->tid; + } + } + } + + foreach ($settings['tids'] as $tid) { + if (isset($tids[$tid])) { + return TRUE; + } + } + } + return FALSE; +} + +/** * @} */