Advertisement
kitchin

WIP: fixes to plugin "Wordpress HTTPS", line 213.

Apr 12th, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.53 KB | None | 0 0
  1.    // Update anchor tags to appropriate URL's
  2.    preg_match_all('/\<a[^>]+[\'"]((http|https):\/\/[\/-\w\.#?=&;]+)[^>]+>/im', $buffer, $matches);
  3.  
  4.    $home_path= parse_url(get_option('home'), PHP_URL_PATH) or $home_path= '/';
  5.    $home_len= strlen($home_path);
  6.  
  7.    for ($i = 0; $i<sizeof($matches[0]); $i++) { // fix
  8.     $html     = $matches[0][$i];
  9.     $url      = $matches[1][$i];
  10.     $scheme   = $matches[2][$i];
  11.  
  12. /////////////////////////////////////////////////
  13. // this is all borked
  14. /////////////////////////////////////////////////
  15. //     $url_path = parse_url($url, PHP_URL_PATH);
  16. //     if ($this->shared_ssl) {
  17. //      $url_path = str_replace(parse_url($this->https_url, PHP_URL_PATH), '', $url_path); // wrong, https_url already stripped of path
  18. //     } else {
  19. //      $url_path = str_replace(parse_url(get_option('home'), PHP_URL_PATH), '', $url_path);
  20. //     }
  21. //
  22. //     if ($url_path == '/') {  // wrong, external links can match this
  23. //      $post = get_option('page_on_front');
  24. //     } else {
  25. //      $post = get_page_by_path($url_path); // wrong unless WP installed in root www
  26. //      $post = $post->ID;
  27. //     }
  28. /////////////////////////////////////////////////
  29.  
  30.     $scheme= strtolower($scheme);
  31.     $url_start= $scheme . '://' . strtolower(parse_url($url, PHP_URL_HOST));
  32.  
  33.     if ($url_start == $this->http_url) {
  34.       // ok
  35.     } elseif ($url_start == $this->https_url) {
  36.       // ok
  37.     } else {
  38.       continue; // bail on external links
  39.     }
  40.  
  41.     $url_path= parse_url($url, PHP_URL_PATH) or $url_path='/';
  42.  
  43.     if ($home_len <= strlen($url_path) && $home_path == substr($url_path, 0, $home_len)) {
  44.      $url_path= substr($url_path, $home_len);
  45.     } else {
  46.      continue;
  47.     }
  48.  
  49.     if ($url_path == '') {
  50.      $post = get_option('page_on_front');
  51.     } else {
  52.      $post = get_page_by_path($url_path);
  53.      $post and $post = $post->ID;
  54.     }
  55.  
  56.     $force_ssl_admin= defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN && is_admin(); // new code
  57.  
  58.     if ($post) {
  59.      // $force_ssl = get_post_meta($post, 'force_ssl', true); // was
  60.      $force_ssl= $force_ssl_admin || get_post_meta($post, 'force_ssl', true); // now
  61.      if ($force_ssl) {
  62.       if ($scheme=='http') {
  63.        $buffer = str_replace($html, str_replace($this->http_url, $this->https_url, $html), $buffer);
  64.       }
  65.      } else if (get_option('wordpress-https_exclusive_https') == 1) {
  66.       if ($scheme=='https') {
  67.        $buffer = str_replace($html, str_replace($this->https_url, $this->http_url, $html), $buffer);
  68.       }
  69.      }
  70.     }
  71.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement