function _autofloat in AutoFloat 6
Same name and namespace in other branches
- 6.2 autofloat.module \_autofloat()
 
Find a rejected 'div', a selected 'span', a link with image or an image.
1 call to _autofloat()
- autofloat_filter in ./
autofloat.module  - Implements hook_filter_info().
 
File
- ./
autofloat.module, line 85  - Autofloat module: A filter that floats images left and right automatically.
 
Code
function _autofloat($text, $format) {
  $selector = variable_get('autofloat_span', 'caption');
  // Divide the variable into two selectors if a comma is found.
  $selector = explode(',', $selector);
  // Make sure both array keys exist, if not the regex breaks.
  if (isset($selector[0]) == FALSE) {
    $selector[0] = '';
  }
  if (isset($selector[1]) == FALSE) {
    $selector[1] = '';
  }
  $rejector = variable_get('autofloat_div', 'flickr-photoset');
  // Divide the variable into two rejectors if a comma is found.
  $rejector = explode(',', $rejector);
  // Make sure both array keys exist, if not the regex breaks.
  if (isset($rejector[0]) == FALSE) {
    $rejector[0] = '';
  }
  if (isset($rejector[1]) == FALSE) {
    $rejector[1] = '';
  }
  // Regex in four parts (divided by '|') matching a rejected 'div', a
  // selected 'span', a link with image or an image. A pattern inside an
  // already found pattern gets ignored, to avoid floats inside floats.
  $text = preg_replace_callback('@<(
  div ([^>]*)(class\\s*=\\s*["\'](nofloat|' . trim($rejector[0]) . '|' . trim($rejector[1]) . ')["\'])([^>]*)>(.*?)</div| # find a rejected div
  span([^>]*)(class\\s*=\\s*["\'](float|' . trim($selector[0]) . '|' . trim($selector[1]) . ')["\'])([^>]*)>(.*?)</span| # find a selected span
  (a[^>]*)(href=)([^>]*)(><img[^>]*>(.*?)(</img>)?</a)| # find a link with image
  img (.+?) # find an image
  )>@isx', 'autofloat_filter_callback', $text);
  return $text;
}