Index: flag.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.module,v
retrieving revision 1.11.2.72.2.11
diff -u -p -r1.11.2.72.2.11 flag.module
--- flag.module	18 Sep 2009 22:30:28 -0000	1.11.2.72.2.11
+++ flag.module	24 Sep 2009 18:44:35 -0000
@@ -73,6 +73,17 @@ function flag_menu() {
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
   );
+  
+  if (module_exists('ctools')) {
+    // args are $js, $action, $flag_name and $content_id
+    $items['flag/confirm/%ctools_js/%/%/%'] = array(
+      'page callback' => 'flag_ctools_confirm',
+      'page arguments' => array(2,3,4,5),
+      'access callback' => 'user_access',
+      'access arguments' => array('access content'),
+      'type' => MENU_CALLBACK,
+    );
+  }
 
   return $items;
 }
@@ -190,6 +201,30 @@ function flag_link($type, $object = NULL
  *   An array defining properties of the link.
  */
 function flag_flag_link(&$flag, $action, $content_id) {
+  switch ($flag->link_type) {
+    case 'confirm':
+      return array(
+        'href' => "flag/confirm/$action/{$flag->name}/$content_id",
+        'query' => drupal_get_destination(),
+      );
+      break;
+    case 'confirm-ctools':
+      ctools_include('modal');
+      ctools_modal_add_js();
+      return array(
+        'href' => "flag/confirm/nojs/$action/{$flag->name}/$content_id",
+        'attributes' => array('class' => 'ctools-use-modal'),
+      );
+      break;
+    case 'toggle':
+    default:
+      $token = flag_get_token($content_id);
+      return array(
+        'href' => "flag/$action/{$flag->name}/$content_id",
+        'query' => drupal_get_destination() . '&token=' . $token,
+      );
+      break; 
+  }
   $token = flag_get_token($content_id);
   return array(
     'href' => "flag/". ($flag->link_type == 'confirm' ? 'confirm/' : '') ."$action/$flag->name/$content_id",
@@ -201,7 +236,7 @@ function flag_flag_link(&$flag, $action,
  * Implementation of hook_flag_link_types().
  */
 function flag_flag_link_types() {
-  return array(
+  $types = array(
     'toggle' => array(
       'title' => t('JavaScript toggle'),
       'description' => t('An AJAX request will be made and degrades to type "Normal link" if JavaScript is not available.'),
@@ -215,6 +250,14 @@ function flag_flag_link_types() {
       'description' => t('The user will be taken to a confirmation form on a separate page to confirm the flag.'),
     ),
   );
+  
+  if (module_exists('ctools')) {
+    $types['confirm-ctools'] = array(
+      'title' => t('Chaos Tools Modal Confirm'),
+      'description' => t('The user will be presented with a confirmation form in a Chaos Tools confirmation form'),
+    );
+  }
+  return $types;
 }
 
 /**
@@ -514,11 +557,39 @@ function flag_page($action = NULL, $flag
 }
 
 /**
+ * page callback for the ctools confirm form
+ */
+function flag_ctools_confirm($js, $action, $flag_name, $content_id) {
+  if ($js) {
+    $commands = array();
+    ctools_include('ajax');
+    ctools_include('modal');
+    $args = array($action, $flag_name, $content_id);
+    $form_state = array(
+      'ajax' => TRUE,
+      'title' => t('Some title?'),
+      'args' => $args,
+    );
+    $commands = ctools_modal_form_wrapper('flag_confirm', $form_state);
+    if (empty($commands)) {
+      $flag = flag_get_flag($flag_name);
+      $inverse_action = ($action == 'flag' ? 'unflag' : 'flag');
+      $text = $flag->get_label($inverse_action . '_message', $content_id);
+      $commands[] = ctools_modal_command_display(t($action), $text);
+      $commands[] = array('command' => 'reload');
+    }
+    ctools_ajax_render($commands);
+  }
+  else {
+    return drupal_get_form('flag_confirm', $action, $flag_name, $content_id);
+  }
+}
+
+/**
  * Form for confirming the (un)flagging of a piece of content.
  */
 function flag_confirm(&$form_state, $action = 'flag', $flag_name, $content_id = '') {
   $form = array();
-
   $form['action'] = array(
     '#type' => 'value',
     '#value' => $action,
