You are here

function cdn_html_alter_image_urls in CDN 6.2

Same name and namespace in other branches
  1. 7.2 cdn.fallback.inc \cdn_html_alter_image_urls()

Alter image file URLs in a piece of HTML.

2 calls to cdn_html_alter_image_urls()
cdn_nodeapi in ./cdn.module
Implementation of hook_nodeapi().
cdn_preprocess_page in ./cdn.fallback.inc
Implementation of template_preprocess_page().

File

./cdn.fallback.inc, line 76
Fallback when hook_file_url_alter() is not available (i.e. when the core patch is not installed or when not using a patched Drupal distribution): use the Parallel module's logic (with some adaptations to be able to use the CDN module's logic…

Code

function cdn_html_alter_image_urls(&$html) {
  $url_prefix_regex = _cdn_generate_url_prefix_regex();

  // TRICKY: order matters!
  // Image file URLs of <a> tags that wrap <img> tags.
  $pattern = "#((<a\\s+|<a\\s+[^>]*\\s+)href\\s*=\\s*[\"|'])({$url_prefix_regex})([^\"|^'|^\\?]*)()(\\?[^\"|^']*)?";
  $pattern .= "(";

  // Capture everything after the path.
  $pattern .= "([\"|'][^>]*)>";

  // End of opening <a> tag.
  $pattern .= "((<img\\s+|<img\\s+[^>]*\\s+)src\\s*=\\s*[\"|'])([^\"|^']*)([\"|'])";

  // Wrapped <img> tag.
  $pattern .= ")#i";
  _cdn_html_alter_file_url($html, $pattern, 0, 4, 5, 1, 7, 11);

  // Image file URLs in <img> tags.
  $pattern = "#((<img\\s+|<img\\s+[^>]*\\s+)src\\s*=\\s*[\"|'])({$url_prefix_regex})([^\"|^'|^\\?]*)()(\\?[^\"|^']*)?([\"|'])#i";
  _cdn_html_alter_file_url($html, $pattern, 0, 4, 5, 1, 7);
}