You are here

function autofloat_filter_callback in AutoFloat 7

Same name and namespace in other branches
  1. 6 autofloat.module \autofloat_filter_callback()

Filter callback. Conditionally apply a wrapper with an alternating class.

1 string reference to 'autofloat_filter_callback'
_autofloat_filter in ./autofloat.module
Find a rejected 'div', a selected 'span', a link with image or an image.

File

./autofloat.module, line 130
Autofloat module: A filter that floats images left and right automatically.

Code

function autofloat_filter_callback($matches) {
  static $count = 0;

  // See if no class of nofloat is found and we are not dealing with a div.
  if (preg_match('@((class\\s*=\\s*["\']nofloat)|(^<div))@i', $matches[0]) == 0) {

    // Start on the left or right depending on the settings.
    if (variable_get('autofloat_start', 0) == 0) {
      $zebra = $count % 2 ? 'even' : 'odd';
    }
    else {
      $zebra = $count % 2 ? 'odd' : 'even';
    }
    $count++;

    // Wrap our element in a span with alternating class.
    return '<span class="autofloat-' . $zebra . '">' . $matches[0] . '</span>';
  }
  else {
    return $matches[0];
  }
}