You are here

function cdn_html_alter_image_urls in CDN 7.2

Same name and namespace in other branches
  1. 6.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()
CDNImageTestCase::testImage in tests/cdn.test
cdn_post_render_html_alter in ./cdn.module
Alter file URLs in the given HTML (currently only image file URLs).

File

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

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, 6, 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, 6, 1, 7);
}