You are here

function _resp_img_replace in Responsive images and styles 7

2 calls to _resp_img_replace()
resp_img_block_view_alter in ./resp_img.module
Implements hook_block_view_alter().
resp_img_post_render in ./resp_img.module

File

./resp_img.module, line 362

Code

function _resp_img_replace($content) {
  $result = array();
  preg_match_all('/<img[^>]+>/i', $content, $result);
  $orig_imgs = $imgs = $result[0];
  $sfx = resp_img_suffix_load_all();
  $suffixes = array();
  foreach ($sfx as $suffix) {
    $suffixes[] = $suffix->suffix;
  }

  // media caches its file urls, so we need to replace all suffixes to the default suffix,
  // before finding the best fitting suffix with resp_img_replace_suffix.
  $imgs = str_replace($suffixes, variable_get('resp_img_default_suffix', ''), $imgs);
  $new_imgs = preg_replace('/(height|width)=("[^"]*")/i', "", $imgs);
  foreach ($new_imgs as &$img) {
    $src = array();
    preg_match('/src=("[^"]*")/i', $img, $src);
    $src = $src[1];
    $new_src = resp_img_replace_suffix($src);
    $img = str_replace($src, $new_src, $img);
  }
  $content = str_replace($orig_imgs, $new_imgs, $content);
  return $content;
}