00001 <?php
00002
00003
00004
00005
00006 class context_condition_node_taxonomy extends context_condition_node {
00007 function condition_values() {
00008 $values = array();
00009 if (module_exists('taxonomy')) {
00010 foreach (taxonomy_get_vocabularies() as $vocab) {
00011 if (empty($vocab->tags)) {
00012 foreach (taxonomy_get_tree($vocab->vid) as $term) {
00013 $values[$term->tid] = check_plain($term->name);
00014 }
00015 }
00016 }
00017 }
00018 return $values;
00019 }
00020
00021 function condition_form($context) {
00022 $form = parent::condition_form($context);
00023 $form['#type'] = 'select';
00024 $form['#size'] = 12;
00025 $form['#multiple'] = TRUE;
00026 $vocabularies = taxonomy_get_vocabularies();
00027 $options = array();
00028 foreach ($vocabularies as $vid => $vocabulary) {
00029 $tree = taxonomy_get_tree($vid);
00030 if ($tree && (count($tree) > 0)) {
00031 $options[$vocabulary->name] = array();
00032 foreach ($tree as $term) {
00033 $options[$vocabulary->name][$term->tid] = str_repeat('-', $term->depth) . $term->name;
00034 }
00035 }
00036 }
00037 $form['#options'] = $options;
00038 return $form;
00039 }
00040
00041 function execute($node, $op) {
00042
00043 $fields = field_info_fields();
00044 $instance_fields = field_info_instances('node', $node->type);
00045 $check_fields = array();
00046 foreach ($instance_fields as $key => $field_info) {
00047 if ($fields[$key]['type'] == 'taxonomy_term_reference') {
00048 $check_fields[] = $key;
00049 }
00050 }
00051
00052 if ($this->condition_used() && !empty($check_fields)) {
00053 foreach ($check_fields as $field) {
00054 if ($terms = field_get_items('node', $node, $field)) {
00055 foreach ($terms as $term) {
00056 foreach ($this->get_contexts($term['tid']) as $context) {
00057
00058 if ($op === 'form') {
00059 $options = $this->fetch_from_context($context, 'options');
00060 if (!empty($options['node_form'])) {
00061 $this->condition_met($context, $term['tid']);
00062 }
00063 }
00064 else {
00065 $this->condition_met($context, $term['tid']);
00066 }
00067 }
00068 }
00069 }
00070 }
00071 }
00072 }
00073 }