You are here

function theme_flag in Flag 5

Theme an individual link and a message after the link is marked.

Parameters

$flag: The flag object.

$action: Which link to show: either "flag" or "unflag".

$content_id: The ID of the content being flagged.

$after_flagging: This function is called for both 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.

1 theme call to theme_flag()
flag_flag::theme in ./flag.inc
Renders a flag/unflag link. This is a wrapper around theme('flag') that, in Drupal 6, easily channels the call to the right template file.

File

./flag.module, line 600
The Flag module.

Code

function theme_flag($flag, $action, $content_id, $after_flagging = FALSE) {
  static $template;
  if (!isset($template)) {
    $template = './' . drupal_get_path('module', 'flag') . '/theme/flag.tpl.php';
  }
  $variables = array(
    'flag' => $flag,
    'action' => $action,
    'content_id' => $content_id,
    'after_flagging' => $after_flagging,
  );
  flag_template_preprocess('flag', $variables);
  extract($variables);
  ob_start();
  include $template;
  $output = ob_get_contents();
  ob_end_clean();

  // Unfortunately, the antique jQuery shipped with Drupal 5 has a bug: the
  // expression $('<tag>something</tag>') fails is 'something' contains a
  // newline. That's because jQuery's source has:
  //
  //  // Handle HTML strings
  //  if ( typeof a  == "string" ) {
  //    var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
  //    if ( m ) a = jQuery.clean( [ m[1] ] );
  //  }
  //
  // Note the "<.+>", which doesn't match newlines. In newer jQuery's that
  // expression was changed to:
  //
  //  var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/
  //
  // Note the \s which does match newlines.
  //
  // So we have to remove all newlines:
  $output = strtr($output, "\r\n", '  ');
  return $output;
}