コード例 #1
0
 /**
  * Save Settings
  *
  * @param none
  * @return void
  */
 public function save()
 {
     if (!wp_verify_nonce($_POST['_wpnonce'], 'wordpress-https')) {
         return false;
     }
     $message = __('Settings saved.', 'wordpress-https');
     $errors = array();
     $reload = false;
     $logout = false;
     $ssl_host = clone $this->getPlugin()->getHttpsUrl();
     foreach ($this->getPlugin()->getSettings() as $key => $default) {
         if (!array_key_exists($key, $_POST) && $default == 0) {
             $_POST[$key] = 0;
             $this->getPlugin()->setSetting($key, $_POST[$key]);
         } else {
             if (array_key_exists($key, $_POST)) {
                 if ($key == 'ssl_host') {
                     if ($_POST[$key] != '') {
                         $_POST[$key] = strtolower($_POST[$key]);
                         // Add Scheme
                         if (strpos($_POST[$key], 'http://') === false && strpos($_POST[$key], 'https://') === false) {
                             $_POST[$key] = 'https://' . $_POST[$key];
                         }
                         $ssl_host = Mvied_Url::fromString($_POST[$key]);
                         // Add Path
                         if (strpos($ssl_host->getPath(), $this->getPlugin()->getHttpUrl()->getPath()) !== true) {
                             $path = '/' . ltrim(str_replace(rtrim($this->getPlugin()->getHttpUrl()->getPath(), '/'), '', $ssl_host->getPath()), '/');
                             $ssl_host->setPath(rtrim($path, '/') . $this->getPlugin()->getHttpUrl()->getPath());
                         }
                         $ssl_host->setPath(rtrim($ssl_host->getPath(), '/') . '/');
                         if ($ssl_host->toString() != $this->getPlugin()->getHttpsUrl()->toString()) {
                             // Ensure that the WordPress installation is accessible at this host
                             //if ( $ssl_host->isValid() ) {
                             // If secure domain has changed and currently on SSL, logout user
                             if ($this->getPlugin()->isSsl()) {
                                 $logout = true;
                             }
                             $_POST[$key] = $ssl_host->toString();
                             /*} else {
                             			$errors[] = '<strong>SSL Host</strong> - Invalid WordPress installation at ' . $ssl_host;
                             			$_POST[$key] = get_option($key);
                             		}*/
                         } else {
                             $_POST[$key] = $this->getPlugin()->getHttpsUrl()->toString();
                         }
                     } else {
                         $_POST[$key] = get_option($key);
                     }
                 } else {
                     if ($key == 'ssl_proxy') {
                         // Reload if we're auto detecting the proxy and we're not in SSL
                         if ($_POST[$key] == 'auto' && !$this->getPlugin()->isSsl()) {
                             $reload = true;
                         }
                     } else {
                         if ($key == 'ssl_admin') {
                             if (force_ssl_admin() && $this->getPlugin()->getSetting('ssl_host_diff')) {
                                 $errors[] = '<strong>SSL Admin</strong> - FORCE_SSL_ADMIN should not be set to true in your wp-config.php while using a non-default SSL Host.';
                                 // If forcing SSL Admin and currently not SSL, logout user
                             } else {
                                 if ($_POST[$key] == 1 && !$this->getPlugin()->isSsl()) {
                                     $logout = true;
                                 }
                             }
                         } else {
                             if ($key == 'ssl_host_subdomain') {
                                 // Checks to see if the SSL Host is a subdomain
                                 $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;
                                 }
                             }
                         }
                     }
                 }
                 $this->getPlugin()->setSetting($key, $_POST[$key]);
             }
         }
     }
     if ($logout) {
         wp_logout();
     }
     $this->getPlugin()->renderView('ajax_message', array('message' => $message, 'errors' => $errors, 'reload' => $reload, 'logout' => $logout));
 }
コード例 #2
0
 /**
  * Replaces HTTPS Host with HTTP Host
  *
  * @param string $string
  * @return string $string
  */
 public function makeUrlHttp($string)
 {
     if ((string) $string == '') {
         return false;
     }
     // If relative
     if (strpos($string, '/') === 0) {
         if ($this->getSetting('ssl_host_diff') && strpos($string, $this->getHttpsUrl()->getPath()) !== false) {
             $string = str_replace($this->getHttpsUrl()->getPath(), $this->getHttpUrl()->getPath(), $string);
         }
     } else {
         if ($url = Mvied_Url::fromString($string)) {
             if ($this->isUrlLocal($string)) {
                 if ($url->getScheme() == 'https') {
                     $updated = Mvied_Url::fromString(apply_filters('http_internal_url', $url->toString()));
                     $updated->setScheme('http');
                     $updated->setHost($this->getHttpUrl()->getHost());
                     $updated->setPort($this->getHttpUrl()->getPort());
                     if ($this->getSetting('ssl_host_diff') && strpos($updated->getPath(), $this->getHttpsUrl()->getPath()) !== false) {
                         $updated->setPath(str_replace($this->getHttpsUrl()->getPath(), $this->getHttpUrl()->getPath(), $updated->getPath()));
                     }
                     if (strpos($url, 'wp-admin') !== false && preg_match('/redirect_to=([^&]+)/i', $url, $redirect) && isset($redirect[1])) {
                         $redirect_url = $redirect[1];
                         $url = str_replace($redirect_url, urlencode($this->makeUrlHttp(urldecode($redirect_url))), $url);
                     }
                     $string = str_replace($url, $updated, $string);
                 }
             } else {
                 $updated = Mvied_Url::fromString(apply_filters('http_external_url', $url->toString()));
                 $updated->setScheme('http');
                 $string = str_replace($url, $updated, $string);
             }
         }
     }
     unset($updated);
     unset($url);
     return $string;
 }
コード例 #3
0
 /**
  * Save Settings
  *
  * @param array $settings
  * @return void
  */
 public function save()
 {
     if (!wp_verify_nonce($_POST['_wpnonce'], $this->getPlugin()->getSlug())) {
         return false;
     }
     $message = __('Network settings saved.', 'wordpress-https');
     $errors = array();
     $reload = false;
     $logout = false;
     if (isset($_POST['blog']) && is_array($_POST['blog']) && sizeof($_POST['blog']) > 0) {
         foreach ($_POST['blog'] as $blog_id => $setting) {
             foreach ($setting as $key => $value) {
                 if ($key == 'ssl_host' && $value != '') {
                     $blog_url = Mvied_Url::fromString(get_site_url($blog_id, '', 'https'));
                     $value = strtolower($value);
                     // Add Scheme
                     if (strpos($value, 'http://') === false && strpos($value, 'https://') === false) {
                         $value = 'https://' . $value;
                     }
                     $ssl_host = Mvied_Url::fromString($value);
                     // Add Path
                     if (strpos($ssl_host->getPath(), $blog_url->getPath()) !== true) {
                         $path = '/' . ltrim(str_replace(rtrim($blog_url->getPath(), '/'), '', $ssl_host->getPath()), '/');
                         $ssl_host->setPath(rtrim($path, '/') . $blog_url->getPath());
                     }
                     $ssl_host->setPath(rtrim($ssl_host->getPath(), '/') . '/');
                     $value = $ssl_host->toString();
                 }
                 $this->getPlugin()->setSetting($key, $value, $blog_id);
             }
         }
     }
     if (isset($_POST['blog_default']) && is_array($_POST['blog_default']) && sizeof($_POST['blog_default']) > 0) {
         $this->getPlugin()->setSetting('network_defaults', $_POST['blog_default']);
     }
     if ($logout) {
         wp_logout();
     }
     $this->getPlugin()->renderView('ajax_message', array('message' => $message, 'errors' => $errors, 'reload' => $reload, 'logout' => $logout));
 }