Index: flag.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/flag.module,v
retrieving revision 1.11.2.11
diff -u -F^[^a-z]*function -r1.11.2.11 flag.module
--- flag.module	10 Jul 2008 15:16:26 -0000	1.11.2.11
+++ flag.module	13 Jul 2008 09:27:18 -0000
@@ -859,26 +859,69 @@ function theme_flag($flag, $content_type
  *
  * @param $flag
  *   The flag object.
- * @param $content_type
- *   The type of content being flagged. Usually "node".
  * @param $content_id
  *   The ID of the content being flagged.
  * @param $action
  *   Either "flag" or "unflag".
  * @param $after_flagging
- *   This function is called for both the link both before and after being
+ *   This function is called for the link both before and after being
+ *   flagged. If displaying to the user immediately after flagging, this value
+ *   will be boolean TRUE. This is usually used in conjunction with immedate
+ *   JavaScript-based toggling of flags.
+ */
+function theme_flag_link($flag, $content_id, $action, $after_flagging = FALSE) {
+  $variables = flag_link_variables($flag, $content_id, $action, $after_flagging);
+  extract($variables);
+  ob_start();
+?>
+<?php
+/**
+ * @file
+ * Default theme implementation to display a flag link.
+ *
+ * Available variables:
+ * - $flag: The flag object itself. You will only need to use it when the
+ *   following variables don't suffice.
+ * - $link_href: The URL for the flag link.
+ * - $link_text: The text to show for the link.
+ * - $link_title: The title attribute for the link.
+ * - $last_action: The action, as the English verb 'flagged' or 'unflagged',
+ *   that led to the current status of the flag.
+ * - $message_text: The long message to show after a flag action has been carried out.
+ * - $after_flagging: This template is called for the link both before and after being
  *   flagged. If displaying to the user immediately after flagging, this value
  *   will be boolean TRUE. This is usually used in conjunction with immedate
  *   JavaScript-based toggling of flags.
  */
-function theme_flag_link($flag, $content_type, $content_id, $action, $after_flagging = FALSE) {
-  $output = '<span class="flag-wrapper">';
-  $output .= l($flag->{$action .'_short'}, 'flag/'. $action .'/'. $flag->name .'/'. $content_type .'/'. $content_id, array('query' => drupal_get_destination(), 'attributes' => array('title' => $flag->{$action .'_long'}, 'class' => $action .' flag-'. $flag->name . ($after_flagging ? ($action == 'flag' ? ' unflagged' : ' flagged') : ''))));
+?>
+<span class="flag-wrapper flag-<?php echo $flag->name; ?>">
+  <a href="<?php echo $link_href; ?>" title="<?php echo $link_title; ?>" class="flag <?php echo $action; ?>-action <?php echo $after_flagging ? $last_action : ''; ?>"><?php echo $link_text; ?></a>
+  <?php if ($after_flagging): ?>
+    <span class="flag-message flag-<?php echo $last_action; ?>-message">
+      <?php echo $message_text; ?>
+    </span>
+  <?php endif; ?>
+</span>
+<?php
+  $output = ob_get_contents();
+  ob_end_clean();
+  return $output;
+}
+
+/**
+ * A preprocess-style function for our theme_flag_link(). It generates the
+ * variables needed there. Explanation for each variable is in the template above.
+ */
+function flag_link_variables($flag, $content_id, $action, $after_flagging) {
+  $variables['link_href'] = check_url(url("flag/$action/$flag->name/$flag->content_type/$content_id", array('query' => drupal_get_destination())));
+  $variables['link_text'] = $flag->{$action .'_short'};
+  $variables['link_title'] = strip_tags($flag->{$action .'_long'});
+  $variables['last_action'] = ($action == 'flag' ? 'unflagged' : 'flagged');
   if ($after_flagging) {
-    $output .= '<span class="flag-message flag-'. $action .'-message">'. $flag->{($action == 'flag' ? 'unflag' : 'flag') .'_message'} .'</span>';
+    $inverse_action = ($action == 'flag' ? 'unflag' : 'flag');
+    $variables['message_text'] = $flag->{$inverse_action .'_message'};
   }
-  $output .= '</span>';
-  return $output;
+  return $variables;
 }
 
 /**
