commit 75b15725c31fd018cc16e26eb35053fa344fe836
Author: flow <florian.weber@digi-info.de>
Date:   Thu Nov 4 14:08:09 2010 +0100

    add cck integration. add condition based on cck allowed values

diff --git a/context.core.inc b/context.core.inc
index 0beba81..e476f30 100644
--- a/context.core.inc
+++ b/context.core.inc
@@ -170,6 +170,11 @@ function context_node_condition(&$node, $op) {
       $plugin->execute($node, $op);
     }
   }
+  if (module_exists('content')) {
+    if ($plugin = context_get_plugin('condition', 'content')) {
+      $plugin->execute($node, $op);
+    }
+  }
   if (module_exists('book')) {
     if ($plugin = context_get_plugin('condition', 'book')) {
       $plugin->execute($node, $op);
diff --git a/context.plugins.inc b/context.plugins.inc
index d1ea06e..3677537 100644
--- a/context.plugins.inc
+++ b/context.plugins.inc
@@ -62,6 +62,13 @@ function _context_context_registry() {
       'plugin' => 'context_condition_bookroot',
     );
   }
+  if (module_exists('content')) {
+    $registry['conditions']['content'] = array(
+      'title' => t('Content'),
+      'description' => t('Set this context when viewing a node with the selected content.'),
+      'plugin' => 'context_condition_content',
+    );
+  }
   if (module_exists('locale')) {
     $registry['conditions']['language'] = array(
       'title' => t('Language'),
@@ -205,6 +212,16 @@ function _context_context_plugins() {
       ),
     );
   }
+  if (module_exists('content')) {
+    $plugins['context_condition_content'] = array(
+      'handler' => array(
+        'path' => drupal_get_path('module', 'context') .'/plugins',
+        'file' => 'context_condition_content.inc',
+        'class' => 'context_condition_content',
+        'parent' => 'context_condition',
+      ),
+    );
+  }
   if (module_exists('book')) {
     $plugins['context_condition_book'] = array(
       'handler' => array(
diff --git a/plugins/context_condition_content.inc b/plugins/context_condition_content.inc
new file mode 100644
index 0000000..08cd67f
--- /dev/null
+++ b/plugins/context_condition_content.inc
@@ -0,0 +1,48 @@
+<?php
+// $Id$
+
+/**
+ * Expose node content as a context condition.
+ */
+class context_condition_content extends context_condition {
+  function condition_values() {
+    $values = array();
+    if (module_exists('content')) {
+      foreach (content_fields() as $field) {
+        $field_values = array();
+        $field_values[$field['field_name']] = check_plain($field['widget']['label'] .' - '. $field['field_name']);
+        if ($options = content_allowed_values($field)) {
+          foreach ($options as $key => $value) {
+            $field_values[$field['field_name'] . ':' . $key] = check_plain("-- {$value}");
+          }
+          
+          $values += $field_values;
+        }
+      }
+    }
+    
+    return $values;
+  }
+
+  function execute($node, $op) {
+    if ($this->condition_used()) {
+      foreach ($this->get_contexts() as $context) {
+        $values = $this->fetch_from_context($context, 'values');
+        foreach (content_fields() as $field) {
+          // If field exists.
+          if (!empty($node->$field['field_name']) && in_array($field['field_name'], $values)) {
+            $this->condition_met($context, $field['field_name']);
+          }
+
+          if (!empty($node->$field['field_name']) && $options = content_allowed_values($field)) {
+            foreach ($node->$field['field_name'] as $item) {
+              if (in_array($field['field_name'] . ':' . $item['value'], $values)) {
+                $this->condition_met($context, $field['field_name'] . ':' . $item['value']);
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
