Skip to content
Browse files

Moved logic for determining if a URL is a subdomain of another URL in…

…to the WordPressHTTPS_Url object.
  • Loading branch information...
1 parent 71ae8b9 commit 5f426b8b3cafecebfade060acade0e48c5103acb @mvied committed Feb 5, 2013
Showing with 19 additions and 14 deletions.
  1. +2 −10 lib/WordPressHTTPS.php
  2. +2 −4 lib/WordPressHTTPS/Module/Settings.php
  3. +15 −0 lib/WordPressHTTPS/Url.php
View
12 lib/WordPressHTTPS.php
@@ -195,17 +195,9 @@ public function install() {
}
}
- // Checks to see if the SSL Host is a subdomain
- $http_domain = $this->getHttpUrl()->getBaseHost();
- $https_domain = $this->getHttpsUrl()->getBaseHost();
-
- if ( $this->getHttpsUrl()->setScheme('http')->toString() != $this->getHttpUrl()->toString() && $http_domain == $https_domain ) {
- $subdomain = true;
- } else {
- $subdomain = false;
- }
+ $is_subdomain = $this->getHttpsUrl()->isSubdomain($this->getHttpUrl());
foreach ( $blogs as $blog_id ) {
- $this->setSetting('ssl_host_subdomain', $subdomain, $blog_id);
+ $this->setSetting('ssl_host_subdomain', $is_subdomain, $blog_id);
}
}
View
6 lib/WordPressHTTPS/Module/Settings.php
@@ -283,10 +283,8 @@ public function save() {
}
} else if ( $key == 'ssl_host_subdomain' ) {
// Checks to see if the SSL Host is a subdomain
- $http_domain = $this->getPlugin()->getHttpUrl()->getBaseHost();
- $https_domain = $this->getPlugin()->getHttpsUrl()->getBaseHost();
-
- if ( $ssl_host->setScheme('http') != $this->getPlugin()->getHttpUrl() && $http_domain == $https_domain ) {
+ $is_subdomain = $this->getPlugin()->getHttpsUrl()->isSubdomain($this->getPlugin()->getHttpUrl());
+ if ( $ssl_host->setScheme('http') != $this->getPlugin()->getHttpUrl() && $is_subdomain ) {
$_POST[$key] = 1;
} else {
$_POST[$key] = 0;
View
15 lib/WordPressHTTPS/Url.php
@@ -441,6 +441,21 @@ public function isValid( $verify_ssl = false ) {
}
/**
+ * Compares URL objects to determine if either of them are a subdomain of the other.
+ *
+ * @param WordPressHTTPS_Url $url
+ * @return boolean
+ */
+ public function isSubdomain( WordPressHTTPS_Url $url ) {
+ $this_host = $this->getBaseHost();
+ $other_host = $url->getBaseHost();
+ if ( $this_host == $other_host ) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
* Factory object from an array provided by the parse_url function
*
* Example of usage:

0 comments on commit 5f426b8

Please sign in to comment.
Something went wrong with that request. Please try again.