From 41775561d5ccbb57ce94ab4be85b5d85a25913d8 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 11 Nov 2005 01:21:28 +0000 Subject: [PATCH] Add HTTPS support, fixes #1372 git-svn-id: http://svn.automattic.com/wordpress/trunk@3041 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/install.php | 3 ++- wp-admin/upgrade-schema.php | 3 ++- wp-includes/functions.php | 2 +- wp-login.php | 7 ++++--- xmlrpc.php | 6 +++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/wp-admin/install.php b/wp-admin/install.php index 8b5375652..e669af286 100644 --- a/wp-admin/install.php +++ b/wp-admin/install.php @@ -6,7 +6,8 @@ if (!file_exists('../wp-config.php')) require_once('../wp-config.php'); require_once('./upgrade-functions.php'); -$guessurl = str_replace('/wp-admin/install.php?step=2', '', 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) ); +$schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; +$guessurl = str_replace('/wp-admin/install.php?step=2', '', $schema . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) ); if (isset($_GET['step'])) $step = $_GET['step']; diff --git a/wp-admin/upgrade-schema.php b/wp-admin/upgrade-schema.php index 061a735ed..565567577 100644 --- a/wp-admin/upgrade-schema.php +++ b/wp-admin/upgrade-schema.php @@ -150,7 +150,8 @@ CREATE TABLE $wpdb->usermeta ( function populate_options() { global $wpdb; - $guessurl = preg_replace('|/wp-admin/.*|i', '', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); + $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; + $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); add_option('siteurl', $guessurl, __('WordPress web address')); add_option('blogname', __('My Weblog'), __('Blog title')); add_option('blogdescription', __('Just another WordPress weblog'), __('Short tagline')); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index aa26f6fa6..1710fe20d 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -823,7 +823,7 @@ function make_url_footnote($content) { $link_url = $matches[2][$i]; $link_text = $matches[4][$i]; $content = str_replace($link_match, $link_text.' '.$link_number, $content); - $link_url = (strtolower(substr($link_url,0,7)) != 'http://') ? get_settings('home') . $link_url : $link_url; + $link_url = ((strtolower(substr($link_url,0,7)) != 'http://')||(strtolower(substr($link_url,0,7)) != 'https://')) ? get_settings('home') . $link_url : $link_url; $links_summary .= "\n".$link_number.' '.$link_url; } $content = strip_tags($content); diff --git a/wp-login.php b/wp-login.php index 94cafb2c4..54c0a3f77 100644 --- a/wp-login.php +++ b/wp-login.php @@ -11,9 +11,10 @@ header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('cha if ( defined('RELOCATE') ) { // Move flag is set if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) ) $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] ); - - if ( dirname('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_settings('siteurl') ) - update_option('siteurl', dirname('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) ); + + $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; + if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_settings('siteurl') ) + update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) ); } switch($action) { diff --git a/xmlrpc.php b/xmlrpc.php index ff77a70b4..5ec9534d6 100644 --- a/xmlrpc.php +++ b/xmlrpc.php @@ -324,7 +324,7 @@ class wp_xmlrpc_server extends IXR_Server { /* warning: here we make the assumption that the weblog's URI is on the same server */ $filename = get_settings('home') . '/'; - $filename = preg_replace('#http://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename); + $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename); $f = fopen($filename, 'r'); $content = fread($f, filesize($filename)); @@ -359,7 +359,7 @@ class wp_xmlrpc_server extends IXR_Server { /* warning: here we make the assumption that the weblog's URI is on the same server */ $filename = get_settings('home') . '/'; - $filename = preg_replace('#http://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename); + $filename = preg_replace('#https?://.+?/#', $_SERVER['DOCUMENT_ROOT'].'/', $filename); if ($f = fopen($filename, 'w+')) { fwrite($f, $content); @@ -1147,7 +1147,7 @@ class wp_xmlrpc_server extends IXR_Server { $error_code = -1; // Check if the page linked to is in our site - $pos1 = strpos($pagelinkedto, str_replace('http://', '', str_replace('www.', '', get_settings('home')))); + $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_settings('home'))); if( !$pos1 ) return new IXR_Error(0, 'Is there no link to us?');