Index: context.core.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/context/Attic/context.core.inc,v
retrieving revision 1.1.2.3.2.20.2.21
diff -u -p -r1.1.2.3.2.20.2.21 context.core.inc
--- context.core.inc	14 Jun 2010 18:25:46 -0000	1.1.2.3.2.20.2.21
+++ context.core.inc	18 Jun 2010 13:42:30 -0000
@@ -71,6 +71,18 @@ function context_context_registry() {
       'plugin' => 'context_condition_node_taxonomy',
     );
   }
+  if (module_exists('flag')) {
+    $registry['conditions']['node_flag'] = array(
+      'title' => t('Node flag'),
+      'description' => t('Set this context when viewing a flagged node.'),
+      'plugin' => 'context_condition_node_flag',
+    );
+    $registry['conditions']['user_flag'] = array(
+      'title' => t('User flag'),
+      'description' => t('Set this context when viewing a flagged user.'),
+      'plugin' => 'context_condition_user_flag',
+    );
+  }
   $registry['reactions'] = array(
     'block' => array(
       'title' => t('Blocks'),
@@ -249,6 +261,11 @@ function context_node_condition(&$node, 
       $plugin->execute($node, $op);
     }
   }
+  if (module_exists('flag')) {
+    if ($plugin = context_get_plugin('condition', 'node_flag')) {
+      $plugin->execute($node, $op);
+    }
+  }
   // Allow other plugins to easily be triggered on node-related events.
   drupal_alter('context_node_condition', $node, $op);
 }
@@ -280,6 +297,11 @@ function context_user($op, &$edit, &$acc
     if ($plugin = context_get_plugin('condition', 'user_page')) {
       $plugin->execute($account, $op);
     }
+    if (module_exists('flag')) {
+      if ($plugin = context_get_plugin('condition', 'user_flag')) {
+        $plugin->execute($account, $op);
+      }
+    }
   }
 }
 
Index: context.plugins.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/context/Attic/context.plugins.inc,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 context.plugins.inc
--- context.plugins.inc	8 Jun 2010 15:33:58 -0000	1.1.2.5
+++ context.plugins.inc	18 Jun 2010 13:42:31 -0000
@@ -113,6 +113,24 @@ function _context_context_plugins() {
       ),
     );
   }
+  if (module_exists('flag')) {
+    $plugins['context_condition_node_flag'] = array(
+      'handler' => array(
+        'path' => drupal_get_path('module', 'context') .'/plugins',
+        'file' => 'context_condition_node_flag.inc',
+        'class' => 'context_condition_node_flag',
+        'parent' => 'context_condition_node',
+      ),
+    );
+    $plugins['context_condition_user_flag'] = array(
+      'handler' => array(
+        'path' => drupal_get_path('module', 'context') .'/plugins',
+        'file' => 'context_condition_user_flag.inc',
+        'class' => 'context_condition_user_flag',
+        'parent' => 'context_condition_user',
+      ),
+    );
+  }
 
   /**
    * Reactions.
Index: plugins/context_condition_node_flag.inc
===================================================================
RCS file: plugins/context_condition_node_flag.inc
diff -N plugins/context_condition_node_flag.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/context_condition_node_flag.inc	18 Jun 2010 13:42:31 -0000
@@ -0,0 +1,43 @@
+<?php
+// $Id$
+
+/**
+ * Exposes flagged node views as a context condition.
+ */
+class context_condition_node_flag extends context_condition_node {
+  function condition_values() {
+    $values = array();
+    if (module_exists('flag')) {
+      // Get flags allowed for nodes.
+      $flags = flag_get_flags('node');
+      $node_types = node_get_types('names');
+      foreach ($flags as $flag) {
+        $values[$flag->name] = $flag->get_title();
+        foreach ($flag->types as $node_type) {
+          $values[$flag->name .':'. $node_type] = '-- '. $node_type .' ('. $node_types[$node_type] .')';
+        }
+      }
+    }
+    return $values;
+  }
+
+  function execute($node, $op) {
+    // Only view $op supported.
+    if ($this->condition_used() && $op == 'view') {
+      // Get flags for the node's type.
+      $flags = flag_get_flags('node', $node->type);
+      foreach ($flags as $flag) {
+        foreach ($this->get_contexts($flag->name) as $context) {
+          if ($flag->is_flagged($node->nid)) {
+            $this->condition_met($context, $flag->name);
+          }
+        }
+        foreach ($this->get_contexts($flag->name .':'. $node->type) as $context) {
+          if ($flag->is_flagged($node->nid)) {
+            $this->condition_met($context, $flag->name .':'. $node->type);
+          }
+        }
+      }
+    }
+  }
+}
Index: plugins/context_condition_user_flag.inc
===================================================================
RCS file: plugins/context_condition_user_flag.inc
diff -N plugins/context_condition_user_flag.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/context_condition_user_flag.inc	18 Jun 2010 13:42:31 -0000
@@ -0,0 +1,34 @@
+<?php
+// $Id$
+
+/**
+ * Expose flagged user pages as a context condition.
+ */
+class context_condition_user_flag extends context_condition_user {
+  function condition_values() {
+    $values = array();
+    if (module_exists('flag')) {
+      // Get flags for user content type.
+      $flags = flag_get_flags('user');
+      foreach ($flags as $flag) {
+        $values[$flag->name] = $flag->get_title();
+      }
+    }
+    return $values;
+  }
+
+  function execute($account, $op) {
+    // Only 'view' and 'form' $op supported.
+    if ($this->condition_used() && ($op == 'view' || $op == 'form')) {
+      // Get flags for user content type.
+      $flags = flag_get_flags('user');
+      foreach ($flags as $flag) {
+        foreach ($this->get_contexts($flag->name) as $context) {
+          if ($flag->is_flagged($account->uid)) {
+            $this->condition_met($context, $flag->name);
+          }
+        }
+      }
+    }
+  }
+}
