Index: linkchecker.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/linkchecker/linkchecker.module,v
retrieving revision 1.7.2.77
diff -u -r1.7.2.77 linkchecker.module
--- linkchecker.module	12 Jul 2009 11:37:35 -0000	1.7.2.77
+++ linkchecker.module	12 Jul 2009 15:52:25 -0000
@@ -1020,11 +1020,87 @@
 function _linkchecker_link_replace(&$text, $old_link = '', $new_link = '') {
   // Don't do any string replacement if one of the values is empty.
   if (!empty($text) && !empty($old_link) && !empty($new_link)) {
-    // Full qualified domain links.
-    $text = str_replace(check_url($old_link), check_url($new_link), $text);
-    $text = str_replace($old_link, check_url($new_link), $text);
+    // Create local link variable.
+    $old_local_link = str_replace('http://'. $_SERVER['HTTP_HOST'], '', $old_link);
+    $new_local_link = str_replace('http://'. $_SERVER['HTTP_HOST'], '', $new_link);
+
+    // Build the regex with full qualified HTML URLs.
+    $regex_old_fqdn_html_links = preg_quote(check_url($old_link), '/') . '|'. preg_quote($old_link, '/');
+    $new_fqdn_html_link = check_url($new_link);
+
+    // Build the regex with local HTML URLs.
+    $regex_old_local_html_links = preg_quote(check_url($old_local_link), '/') . '|'. preg_quote($old_local_link, '/');
+    $new_local_html_link = check_url($new_local_link);
+
+    // Create array to fill with replacement rules.
+    $replacements = array();
+
+    // Add replace rules for a/area tags.
+    if (variable_get('linkchecker_extract_from_a', 1) == 1) {
+      $replacements['/(<(a|area)\s[^>]*href=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\4';
+      $replacements['/(<(a|area)\s[^>]*href=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\4';
+    }
+
+    // Add replace rules for audio tags.
+    if (variable_get('linkchecker_extract_from_audio', 0) == 1) {
+      $replacements['/(<audio\s[^>]*src=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+      $replacements['/(<audio\s[^>]*src=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+    }
+
+    // Add replace rules for embed tags.
+    if (variable_get('linkchecker_extract_from_embed', 0) == 1) {
+      $replacements['/(<embed\s[^>]*src=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+      $replacements['/(<embed\s[^>]*pluginurl=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+      $replacements['/(<embed\s[^>]*pluginspage=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+
+      $replacements['/(<embed\s[^>]*src=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+      $replacements['/(<embed\s[^>]*pluginurl=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+      $replacements['/(<embed\s[^>]*pluginspage=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+    }
+
+    // Add replace rules for iframe tags.
+    if (variable_get('linkchecker_extract_from_iframe', 0) == 1) {
+      $replacements['/(<iframe\s[^>]*src=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+      $replacements['/(<iframe\s[^>]*src=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+    }
+
+    // Add replace rules for img tags.
+    if (variable_get('linkchecker_extract_from_img', 0) == 1) {
+      $replacements['/(<img\s[^>]*src=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+      $replacements['/(<img\s[^>]*src=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+    }
+
+    // Add replace rules for object/param tags.
+    if (variable_get('linkchecker_extract_from_object', 0) == 1) {
+      $replacements['/(<object\s[^>]*data=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+      $replacements['/(<object\s[^>]*codebase=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+      $replacements['/(<param\s[^>]*((name|src)=["\'](archive|filename|href|movie|src|url)["\']\s[^>]*)+value=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\6';
+
+      $replacements['/(<object\s[^>]*data=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+      $replacements['/(<object\s[^>]*codebase=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+      $replacements['/(<param\s[^>]*((name|src)=["\'](archive|filename|href|movie|src|url)["\']\s[^>]*)+value=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\6';
+    }
+
+    // Add replace rules for source tags.
+    if (variable_get('linkchecker_extract_from_source', 0) == 1) {
+      $replacements['/(<source\s[^>]*src=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+      $replacements['/(<source\s[^>]*src=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+    }
+
+    // Add replace rules for video tags.
+    if (variable_get('linkchecker_extract_from_video', 0) == 1) {
+      $replacements['/(<video\s[^>]*poster=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+      $replacements['/(<video\s[^>]*src=["\'])('. $regex_old_fqdn_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_fqdn_html_link .'\3';
+
+      $replacements['/(<video\s[^>]*poster=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+      $replacements['/(<video\s[^>]*src=["\'])('. $regex_old_local_html_links .')(["\'][^>]*>)/i'] = '\1'. $new_local_html_link .'\3';
+    }
+
+    // Replace link by running all replacement rules on text.
+    foreach (array_unique($replacements) as $pattern => $replacement) {
+      preg_replace($pattern, $replacement, $text);
+    }
 
-    // TODO: Internal links (very risky).
   }
 }
 
