1. --- wordpress-https.php 2011-08-09 11:37:45.000000000 -0700
  2. +++ wordpress-https-patched.php 2011-08-21 17:40:02.851635730 -0700
  3. @@ -348,9 +348,10 @@
  4.             if ( $this->is_ssl() ) {
  5.                 // Fix the regular stuff
  6.                 if ( is_admin() ) {
  7. -                   preg_match_all('/\<(script|link|img)[^>]+((http|https):\/\/[\/-\w\.#?=\+&;]+)[^>]+>/im', $buffer, $matches);
  8. +                   // RegEx's altered to include port
  9. +                   preg_match_all('/\<(script|link|img)[^>]+((http|https):\/\/[-\w\.\d]+(:\d+)?)[^>]+>/im', $buffer, $matches);
  10.                 } else {
  11. -                   preg_match_all('/\<(script|link|img|input|form|embed|param)[^>]+((http|https):\/\/[\/-\w\.#?=\+&;]+)[^>]+>/im', $buffer, $matches);
  12. +                   preg_match_all('/\<(script|link|img|input|form|embed|param)[^>]+((http|https):\/\/[-\w\.\d]+(:\d+)?)[^>]+>/im', $buffer, $matches);
  13.                 }
  14.  
  15.                 $external_urls = get_option('wordpress-https_external_urls');
  16. @@ -395,7 +396,7 @@
  17.                 }
  18.  
  19.                 // Fix any CSS background images
  20. -               preg_match_all('/background: url\([\'"]?(http:\/\/[\/-\w\.#?=\+&;]+)[\'"]?\)/im', $buffer, $matches);
  21. +               preg_match_all('/background: url\([\'"]?(http:\/\/[-\w\.\d]+(:\d+)?)[\'"]?\)/im', $buffer, $matches);
  22.                 for ($i = 0; $i<=sizeof($matches[0]); $i++) {
  23.                     $css = $matches[0][$i];
  24.                     $url = $matches[1][$i];
  25. @@ -419,7 +420,7 @@
  26.             }
  27.  
  28.             // Update anchor and form tags to appropriate URL's
  29. -           preg_match_all('/\<(a|form)[^>]+[\'"]((http|https):\/\/[\/-\w\.#?=\+&;]+)[^>]+>/im', $buffer, $matches);
  30. +           preg_match_all('/\<(a|form)[^>]+[\'"]((http|https):\/\/[-\w\.\d]+(:\d+)?)[^>]+>/im', $buffer, $matches);
  31.  
  32.             for ($i = 0; $i<=sizeof($matches[0]); $i++) {
  33.                 $html = $matches[0][$i];
  34. @@ -470,7 +471,9 @@
  35.                     $type = $matches[1][$i];
  36.                     $url = $matches[2][$i];
  37.  
  38. -                   $buffer = str_replace($html, str_replace($url, $this->https_url, $html), $buffer);
  39. +                   if (strpos($html, $url) != strpos($html, $this->https_url)) { // https url isn't already there
  40. +                       $buffer = str_replace($html, str_replace($url, $this->https_url, $html), $buffer);
  41. +                   }
  42.                 }
  43.             }
  44.  
  45. @@ -675,7 +678,8 @@
  46.          * @return string $string
  47.          */
  48.         function replace_http_url($string) {
  49. -           preg_match_all('/(http|https):\/\/[\/-\w\.#?=\+&;]+/im', $string, $url);
  50. +           preg_match_all('/((http|https):\/\/[-\w\.\d]+(:\d+)?)[\/-\w\.#?=\+&;]*/im', $string, $url);
  51. +           $base_url = $url[1][0];
  52.             $url = $url[0][0];
  53.  
  54.             // If URL matches home_url, but lacks www, add www
  55. @@ -688,7 +692,7 @@
  56.             }
  57.  
  58.             // Replace the HTTPS version of the domain with $this->https_url for Shared SSL
  59. -           $string = str_replace($this->replace_http($this->http_url), $this->https_url, $string);
  60. +           $string = str_replace($base_url, $this->https_url, $string);
  61.             $string = str_replace($this->http_url, $this->https_url, $string);
  62.             return $string;
  63.         }
  64. @@ -737,7 +741,7 @@
  65.                                 $url = parse_url($_POST[$key]);
  66.                             }
  67.                             if ( sizeof($url) > 1 ) {
  68. -                               $_POST[$key] = 'https://' . $url['host'] . @$url['path'];
  69. +                               $_POST[$key] = 'https://' . $url['host'] . (isset($url['port']) ? ':' . $url['port'] : '') . @$url['path'];
  70.                                 if ( substr($_POST[$key], -1, 1) == '/' ) {
  71.                                     $_POST[$key] = substr($_POST[$key], 0, strlen($_POST[$key])-1);
  72.                                 }
  73. @@ -919,4 +923,4 @@
  74.         global $wordpress_https;
  75.         return $wordpress_https->auth_redirect();
  76.     }
  77. -}
  78. \ No newline at end of file
  79. +}