Skip to content
Browse files

Updated Domain Mapping to URL Mapping. Now allowed to map external an…

…d internal domains to and from HTTPS.
  • Loading branch information...
1 parent 201c953 commit 417f13a448d559d4457bf445c782546004b7f628 @mvied committed Mar 31, 2013
View
48 css/settings.css
@@ -59,9 +59,6 @@
margin: 5px auto 13px auto;
}
-#wphttps-main input[type="text"] {
- margin: -5px 0 0 0;
-}
#wphttps-main input[type="checkbox"] {
margin: 7px 0 0 0;
vertical-align: bottom;
@@ -90,8 +87,8 @@
#wphttps-main #settings-reset,
#wphttps-main #settings-cache-reset,
#wphttps-main #network-settings-reset,
-#wphttps-main #filters-reset,
-#wphttps-main #domain-mapping-reset {
+#wphttps-main #url-filters-reset,
+#wphttps-main #url-mapping-reset {
float: left;
margin-right: 10px;
}
@@ -133,33 +130,37 @@
#wphttps-main #ssl_proxy_row p.description {
width: 65%;
}
-#wphttps-main #domain_mapping td {
- padding: 10px 0;
+#wphttps-main #url_mapping td {
+ padding: 0 3px;
}
-#wphttps-main #domain_mapping td.sep {
- padding: 8px 0;
+#wphttps-main #url_mapping td.sep {
+ line-height: 26px;
+ width: 1%;
+ text-align: center;
}
-#wphttps-main #domain_mapping .http_scheme,
-#wphttps-main #domain_mapping .https_scheme {
- width: 30px;
- padding: 10px;
+#wphttps-main #url_mapping td.scheme {
+ width: 1%;
+ text-align: right;
+}
+#wphttps-main #url_mapping td.scheme select {
+ width: 60px;
}
-#wphttps-main #domain_mapping .https_scheme {
- width: 35px;
+#wphttps-main #url_mapping td.controls {
+ padding: 4px 0px;
+ width: 6%;
}
-#wphttps-main #domain_mapping .http_domain .label,
-#wphttps-main #domain_mapping .https_domain .label {
+#wphttps-main #url_mapping .host .label {
display: block;
float: left;
text-align: right;
padding-right: 2%;
-}
-#wphttps-main #domain_mapping input {
- width: 96%;
+}
+#wphttps-main #url_mapping input {
+ width: 100%;
padding-left: 2%;
padding-right: 2%;
}
-#wphttps-main #domain_mapping .add {
+#wphttps-main #url_mapping .add {
display: block;
height: 16px;
width: 16px;
@@ -168,7 +169,7 @@
float: left;
background: url(../img/add.png) no-repeat 50% 50%;
}
-#wphttps-main #domain_mapping .remove {
+#wphttps-main #url_mapping .remove {
display: block;
height: 16px;
width: 16px;
@@ -177,14 +178,15 @@
float: left;
background: url(../img/delete.png) no-repeat 50% 50%;
}
-#wphttps-main #domain_mapping .sep .label {
+#wphttps-main #url_mapping .url-sep .label {
display: block;
height: 16px;
width: 16px;
overflow: hidden;
text-indent: -1000em;
background: url(../img/arrow_right.png) no-repeat 50% 50%;
margin: 0 auto;
+ padding: 5px 10px;
}
#wphttps-main #regex-help {
View
54 lib/WordPressHTTPS.php
@@ -80,8 +80,39 @@ class WordPressHTTPS extends Mvied_Plugin_Modular {
* @var array
*/
public static $ssl_host_mapping = array(
- 'w.sharethis.com' => 'ws.sharethis.com',
- '\d.gravatar.com' => 'secure.gravatar.com',
+ array(
+ array(
+ 'scheme' => 'http',
+ 'host' => 'w.sharethis.com'
+ ),array(
+ 'scheme' => 'https',
+ 'host' => 'ws.sharethis.com'
+ )
+ ),array(
+ array(
+ 'scheme' => 'https',
+ 'host' => 'ws.sharethis.com'
+ ),array(
+ 'scheme' => 'http',
+ 'host' => 'w.sharethis.com'
+ )
+ ),array(
+ array(
+ 'scheme' => 'http',
+ 'host' => '\d.gravatar.com'
+ ),array(
+ 'scheme' => 'https',
+ 'host' => 'secure.gravatar.com'
+ )
+ ),array(
+ array(
+ 'scheme' => 'https',
+ 'host' => 'secure.gravatar.com'
+ ),array(
+ 'scheme' => 'http',
+ 'host' => '0.gravatar.com'
+ )
+ )
);
/**
@@ -248,6 +279,25 @@ public function install() {
$this->setSetting('frontpage', 0, $blog_id);
}
+ // Reformat ssl_host_mapping
+ $ssl_host_mapping = $this->getSetting('ssl_host_mapping', $blog_id);
+ if ( $ssl_host_mapping != array() && !is_array($ssl_host_mapping[0]) ) {
+ $mappings = array();
+ foreach( $ssl_host_mapping as $http_host => $https_host ) {
+ $mappings[] = array(
+ array(
+ 'scheme' => 'http',
+ 'host' => $http_host
+ ),
+ array(
+ 'scheme' => 'https',
+ 'host' => $https_host
+ )
+ );
+ }
+ $this->setSetting('ssl_host_mapping', $mappings, $blog_id);
+ }
+
// Reset cache
$this->setSetting('secure_external_urls', $this->_settings['secure_external_urls'], $blog_id);
$this->setSetting('unsecure_external_urls', $this->_settings['unsecure_external_urls'], $blog_id);
View
117 lib/WordPressHTTPS/Module/DomainMapping.php
@@ -1,117 +0,0 @@
-<?php
-/**
- * Domain Mapping Module
- *
- * Provides a way for users to specify if a host hosts their HTTPS
- * content on a different domain.
- *
- * @author Mike Ems
- * @package WordPressHTTPS
- *
- */
-
-class WordPressHTTPS_Module_DomainMapping extends Mvied_Plugin_Module {
-
- /**
- * Initialize Module
- *
- * @param none
- * @return void
- */
- public function init() {
- if ( is_admin() ) {
- add_action('wp_ajax_' . $this->getPlugin()->getSlug() . '_domain_mapping_save', array(&$this, 'save'));
- add_action('wp_ajax_' . $this->getPlugin()->getSlug() . '_domain_mapping_reset', array(&$this, 'reset'));
- if ( isset($_GET['page']) && strpos($_GET['page'], $this->getPlugin()->getSlug()) !== false ) {
- // Add meta boxes
- add_action('admin_init', array(&$this, 'add_meta_boxes'));
- }
- }
-
- // Custom filter https_external_url
- add_filter('https_external_url', array(&$this, 'map_url'), 10);
- }
-
- /**
- * Domain Mapping
- *
- * @param string $url
- * @return string $url
- */
- public function map_url( $url ) {
- if ( is_array($this->getPlugin()->getSetting('ssl_host_mapping')) && sizeof($this->getPlugin()->getSetting('ssl_host_mapping')) > 0 ) {
- foreach( $this->getPlugin()->getSetting('ssl_host_mapping') as $http_domain => $https_domain ) {
- preg_match('/' . $http_domain . '/', $url, $matches);
- if ( sizeof($matches) > 0 ) {
- $url = preg_replace('/' . $http_domain . '/', $https_domain, $url);
- }
- }
- }
- return $url;
- }
-
- /**
- * Add meta boxes to WordPress HTTPS Settings page.
- *
- * @param none
- * @return void
- */
- public function add_meta_boxes() {
- add_meta_box(
- $this->getPlugin()->getSlug() . '_domain_mapping',
- __( 'Domain Mapping', $this->getPlugin()->getSlug() ),
- array($this->getPlugin()->getModule('Admin'), 'meta_box_render'),
- 'toplevel_page_' . $this->getPlugin()->getSlug(),
- 'main',
- 'core',
- array( 'metabox' => 'domain_mapping' )
- );
- }
-
- /**
- * Reset Domain Mapping
- *
- * @param array $settings
- * @return void
- */
- public function reset() {
- if ( !wp_verify_nonce($_POST['_wpnonce'], $this->getPlugin()->getSlug()) ) {
- return false;
- }
-
- $message = __('Domain Mapping reset.','wordpress-https');
- $errors = array();
- $reload = true;
-
- $this->getPlugin()->setSetting('ssl_host_mapping', WordPressHTTPS::$ssl_host_mapping);
-
- $this->getPlugin()->renderView('ajax_message', array('message' => $message, 'errors' => $errors, 'reload' => $reload));
- }
-
- /**
- * Save Domain Mapping
- *
- * @param array $settings
- * @return void
- */
- public function save() {
- if ( !wp_verify_nonce($_POST['_wpnonce'], $this->getPlugin()->getSlug()) ) {
- return false;
- }
-
- $message = __('Domain Mapping saved.','wordpress-https');
- $errors = array();
- $reload = false;
-
- $ssl_host_mapping = array();
- for( $i=0; $i<sizeof($_POST['http_domain']); $i++ ) {
- if ( isset($_POST['http_domain'][$i]) && $_POST['http_domain'][$i] != '' && isset($_POST['https_domain'][$i]) && $_POST['https_domain'][$i] != '' ) {
- $ssl_host_mapping[str_replace('\\\\', '\\', $_POST['http_domain'][$i])] = str_replace('\\\\', '\\', $_POST['https_domain'][$i]);
- }
- }
- $this->getPlugin()->setSetting('ssl_host_mapping', $ssl_host_mapping);
-
- $this->getPlugin()->renderView('ajax_message', array('message' => $message, 'errors' => $errors, 'reload' => $reload));
- }
-
-}
View
158 lib/WordPressHTTPS/Module/UrlMapping.php
@@ -0,0 +1,158 @@
+<?php
+/**
+ * URL Mapping Module
+ *
+ * Provides a way for users to specify if a host hosts their HTTPS
+ * content on a different domain.
+ *
+ * @author Mike Ems
+ * @package WordPressHTTPS
+ *
+ */
+
+class WordPressHTTPS_Module_UrlMapping extends Mvied_Plugin_Module {
+
+ /**
+ * Initialize Module
+ *
+ * @param none
+ * @return void
+ */
+ public function init() {
+ if ( is_admin() ) {
+ add_action('wp_ajax_' . $this->getPlugin()->getSlug() . '_url_mapping_save', array(&$this, 'save'));
+ add_action('wp_ajax_' . $this->getPlugin()->getSlug() . '_url_mapping_reset', array(&$this, 'reset'));
+ if ( isset($_GET['page']) && strpos($_GET['page'], $this->getPlugin()->getSlug()) !== false ) {
+ // Add meta boxes
+ add_action('admin_init', array(&$this, 'add_meta_boxes'));
+ }
+ }
+
+ add_filter('http_internal_url', array(&$this, 'map_http_url'), 10);
+ add_filter('http_external_url', array(&$this, 'map_http_url'), 10);
+ add_filter('https_internal_url', array(&$this, 'map_https_url'), 10);
+ add_filter('https_external_url', array(&$this, 'map_https_url'), 10);
+ }
+
+ /**
+ * Map HTTP URL
+ *
+ * @param string $url
+ * @return string $url
+ */
+ public function map_http_url( $url ) {
+ if ( is_array($this->getPlugin()->getSetting('ssl_host_mapping')) && sizeof($this->getPlugin()->getSetting('ssl_host_mapping')) > 0 ) {
+ foreach( $this->getPlugin()->getSetting('ssl_host_mapping') as $mapping ) {
+ if ( !is_array($mapping) || @$mapping[0]['scheme'] != 'https' ) {
+ continue;
+ }
+ $http_url = 'http://' . @$mapping[1]['host'] . ( isset($mapping[1]['port']) ? ':' . $mapping[1]['port'] : '' ) . @$mapping[1]['path'];
+ $https_url = 'https://' . @$mapping[0]['host'] . ( isset($mapping[0]['port']) ? ':' . $mapping[0]['port'] : '' ) . @$mapping[0]['path'];
+ preg_match('|' . $https_url . '|', $url, $matches);
+ if ( sizeof($matches) > 0 ) {
+ $url = preg_replace('|' . $https_url . '|', $http_url, $url);
+ }
+ }
+ }
+ return $url;
+ }
+
+ /**
+ * Map HTTPS URL
+ *
+ * @param string $url
+ * @return string $url
+ */
+ public function map_https_url( $url ) {
+ if ( is_array($this->getPlugin()->getSetting('ssl_host_mapping')) && sizeof($this->getPlugin()->getSetting('ssl_host_mapping')) > 0 ) {
+ foreach( $this->getPlugin()->getSetting('ssl_host_mapping') as $mapping ) {
+ if ( !is_array($mapping) || @$mapping[0]['scheme'] != 'http' ) {
+ continue;
+ }
+ $http_url = 'http://' . @$mapping[0]['host'] . ( isset($mapping[0]['port']) ? ':' . $mapping[0]['port'] : '' ) . @$mapping[0]['path'];
+ $https_url = 'https://' . @$mapping[1]['host'] . ( isset($mapping[1]['port']) ? ':' . $mapping[1]['port'] : '' ) . @$mapping[1]['path'];
+ preg_match('|' . $http_url . '|', $url, $matches);
+ if ( sizeof($matches) > 0 ) {
+ $url = preg_replace('|' . $http_url . '|', $https_url, $url);
+ }
+ }
+ }
+ return $url;
+ }
+
+ /**
+ * Add meta boxes to WordPress HTTPS Settings page.
+ *
+ * @param none
+ * @return void
+ */
+ public function add_meta_boxes() {
+ add_meta_box(
+ $this->getPlugin()->getSlug() . '_url_mapping',
+ __( 'URL Mapping', $this->getPlugin()->getSlug() ),
+ array($this->getPlugin()->getModule('Admin'), 'meta_box_render'),
+ 'toplevel_page_' . $this->getPlugin()->getSlug(),
+ 'main',
+ 'core',
+ array( 'metabox' => 'url_mapping' )
+ );
+ }
+
+ /**
+ * Reset URL Mapping
+ *
+ * @param array $settings
+ * @return void
+ */
+ public function reset() {
+ if ( !wp_verify_nonce($_POST['_wpnonce'], $this->getPlugin()->getSlug()) ) {
+ return false;
+ }
+
+ $message = __('URL Mapping reset.','wordpress-https');
+ $errors = array();
+ $reload = true;
+
+ $this->getPlugin()->setSetting('ssl_host_mapping', WordPressHTTPS::$ssl_host_mapping);
+
+ $this->getPlugin()->renderView('ajax_message', array('message' => $message, 'errors' => $errors, 'reload' => $reload));
+ }
+
+ /**
+ * Save URL Mapping
+ *
+ * @param array $settings
+ * @return void
+ */
+ public function save() {
+ if ( !wp_verify_nonce($_POST['_wpnonce'], $this->getPlugin()->getSlug()) ) {
+ return false;
+ }
+
+ $message = __('URL Mapping saved.','wordpress-https');
+ $errors = array();
+ $reload = false;
+
+ $ssl_host_mapping = $this->getPlugin()->getSetting('ssl_host_mapping');
+ $mappings = array();
+ $i = 0;
+ for( $j=0; $j<sizeof($_POST['url_mapping']['scheme']); $j+=2 ) {
+ if ( isset($_POST['url_mapping']['host'][$j]) && $_POST['url_mapping']['host'][$j] != '' && isset($_POST['url_mapping']['host'][$j+1]) && $_POST['url_mapping']['host'][$j+1] != '' ) {
+ $mappings[$i][] = array(
+ 'scheme' => $_POST['url_mapping']['scheme'][$j],
+ 'host' => $_POST['url_mapping']['host'][$j]
+ );
+ $mappings[$i][] = array(
+ 'scheme' => $_POST['url_mapping']['scheme'][$j+1],
+ 'host' => $_POST['url_mapping']['host'][$j+1]
+ );
+ $i++;
+ }
+ }
+ $mappings = stripslashes_deep($mappings);
+ $this->getPlugin()->setSetting('ssl_host_mapping', $mappings);
+
+ $this->getPlugin()->renderView('ajax_message', array('message' => $message, 'errors' => $errors, 'reload' => $reload));
+ }
+
+}
View
3 readme.txt
@@ -99,6 +99,9 @@ add_filter('force_ssl', 'store_force_ssl', 10, 3);`
* Tested with WordPress v3.6.
* Added internal caching to Parser module to drastically reduce queries.
* Added checks for domain mapping plugin.
+* Renamed Domain Mapping featured to URL Mapping to reduce confusion.
+* Added ability to map both to and from HTTPS with URL Mapping.
+* Added ability to also map local resources using URL Mapping.
* Added Portuegese translation.
* Fixed bug when external resources contained a port number, the port was not removed when testing for HTTPS.
* External HTTPS elements on HTTP pages will now stay HTTPS.
View
125 view/metabox/domain_mapping.php
@@ -1,125 +0,0 @@
-<?php
-if ( !defined('ABSPATH') ) exit;
-?>
-<form name="<?php echo $this->getSlug(); ?>_domain_mapping_form" id="<?php echo $this->getSlug(); ?>_domain_mapping_form" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
-<?php wp_nonce_field($this->getSlug()); ?>
-<input type="hidden" name="action" id="action" value="" />
-
-<p><?php printf( __('Domain mapping allows you to map external domains that host their HTTPS content on a different domain. You may use %s regular expressions %s','wordpress-https'),'<a href="#TB_inline?height=155&width=350&inlineId=regex-help&" class="thickbox" title="' . __('Regular Expressions Help','wordpress-https') . '">', '</a>') ; ?>.</p>
-
-<table class="form-table" id="domain_mapping">
- <thead>
- </thead>
-<?php
- $ssl_host_mapping = ( is_array($this->getSetting('ssl_host_mapping')) ? $this->getSetting('ssl_host_mapping') : array() );
- foreach( $ssl_host_mapping as $http_domain => $https_domain ) {
-?>
- <tr valign="top" class="domain_mapping_row">
- <td class="http_scheme">
- <span class="label">http://</span>
- </td>
- <td class="http_domain">
- <input type="text" name="http_domain[]" value="<?php echo $http_domain; ?>" />
- </td>
- <td class="sep">
- <span class="label">&gt;</span>
- </td>
- <td class="https_scheme">
- <span class="label">https://</span>
- </td>
- <td class="https_domain">
- <input type="text" name="https_domain[]" value="<?php echo $https_domain; ?>" />
- </td>
- <td class="controls">
- <a class="remove" href="#" title="<?php _e('Remove URL Filter','wordpress-https'); ?>"><?php _e('Remove','wordpress-https'); ?></a>
- <a class="add" href="#" title="<?php _e('Add URL Filter','wordpress-https'); ?>"><?php _e('Add','wordpress-https'); ?></a>
- </td>
- </tr>
-
-<?php } ?>
- <tr valign="top" class="domain_mapping_row">
- <td class="http_scheme">
- <span class="label">http://</span>
- </td>
- <td class="http_domain">
- <input type="text" name="http_domain[]" value="" />
- </td>
- <td class="sep">
- <span class="label">&gt;</span>
- </td>
- <td class="https_scheme">
- <span class="label">https://</span>
- </td>
- <td class="https_domain">
- <input type="text" name="https_domain[]" value="" />
- </td>
- <td class="controls">
- <a class="remove" href="#" title="<?php _e('Remove URL Filter','wordpress-https'); ?>"><?php _e('Remove','wordpress-https'); ?></a>
- <a class="add" href="#" title="<?php _e('Add URL Filter','wordpress-https'); ?>"><?php _e('Add','wordpress-https'); ?></a>
- </td>
- </tr>
-</table>
-
-<p class="button-controls">
- <input type="submit" name="domain-mapping-save" value="<?php _e('Save Changes','wordpress-https'); ?>" class="button-primary" id="domain-mapping-save" />
- <input type="submit" name="domain-mapping-reset" value="<?php _e('Reset','wordpress-https'); ?>" class="button-secondary" id="domain-mapping-reset" />
- <img alt="<?php _e('Waiting...','wordpress-https'); ?>" src="<?php echo admin_url('/images/wpspin_light.gif'); ?>" class="waiting submit-waiting" />
-</p>
-</form>
-<script type="text/javascript">
-jQuery(document).ready(function($) {
- var form = $('#<?php echo $this->getSlug(); ?>_domain_mapping_form').first();
- $('#domain-mapping-save').click(function() {
- $(form).find('input[name="action"]').val('<?php echo $this->getSlug(); ?>_domain_mapping_save');
- });
- $('#domain-mapping-reset').click(function() {
- $(form).find('input[name="action"]').val('<?php echo $this->getSlug(); ?>_domain_mapping_reset');
- });
- $(form).submit(function(e) {
- e.preventDefault();
- $(form).find('.submit-waiting').show();
- $.post(ajaxurl, $(form).serialize(), function(response) {
- $(form).find('.submit-waiting').hide();
- $('#message-body').html(response).fadeOut(0).fadeIn().delay(5000).fadeOut();
- });
- });
-
- if ( $('#domain_mapping tr').length <= 1 ) {
- $('#domain_mapping .remove').hide();
- } else {
- $('#domain_mapping .remove').show();
- $('#domain_mapping .add').hide();
- $('#domain_mapping tr:last-child .add').show();
- }
-
- $('.domain_mapping_row .add').live('click', function(e) {
- e.preventDefault();
- var row = $(this).parents('tr').clone();
- row.find('input').val('');
- $(this).parents('table').append(row);
- $(this).hide();
- $('#domain_mapping .remove').show();
- return false;
- });
-
- $('.domain_mapping_row .remove').live('click', function(e) {
- e.preventDefault();
- $(this).parents('tr').remove();
- if ( $('#domain_mapping tr').length <= 1 ) {
- $('#domain_mapping .remove').hide();
- } else {
- $('#domain_mapping .remove').show();
- }
- $('#domain_mapping .add').hide();
- $('#domain_mapping tr:last-child .add').show();
- return false;
- });
-
- $('#domain_mapping-reset').click(function(e, el) {
- if ( ! confirm('<?php _e('Are you sure you want to reset all WordPress HTTPS domain mappings?','wordpress-https'); ?>') ) {
- e.preventDefault();
- return false;
- }
- });
-});
-</script>
View
52 view/metabox/filters.php
@@ -1,52 +0,0 @@
-<?php
-if ( !defined('ABSPATH') ) exit;
-?>
-<form name="<?php echo $this->getSlug(); ?>_filters_form" id="<?php echo $this->getSlug(); ?>_filters_form" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
-<?php wp_nonce_field($this->getSlug()); ?>
-<input type="hidden" name="action" id="action" value="" />
-
-<table class="form-table">
- <tr valign="top" id="secure_filter_row">
- <th scope="row">
- <?php _e('Secure Filters','wordpress-https'); ?>
- <p class="description"><?php printf( __("Example: If you have an E-commerce shop and all of the URL's begin with /store/, you could secure all store links by entering '/store/' on one line. You may use %s regular expressions %s",'wordpress-https'),'<a href="#TB_inline?height=155&width=350&inlineId=regex-help" class="thickbox" title="' . __('Regular Expressions Help','wordpress-https') . '">','</a>'); ?>.</p>
- </th>
- <td>
- <textarea name="secure_filter" id="secure_filter"><?php echo implode("\n", $this->getSetting('secure_filter')); ?></textarea>
- </td>
- </tr>
-</table>
-
-<p class="button-controls">
- <input type="submit" name="filters-save" value="<?php _e('Save Changes','wordpress-https'); ?>" class="button-primary" id="filters-save" />
- <input type="submit" name="filters-reset" value="<?php _e('Reset','wordpress-https'); ?>" class="button-secondary" id="filters-reset" />
- <img alt="<?php _e('Waiting...','wordpress-https'); ?>" src="<?php echo admin_url('/images/wpspin_light.gif'); ?>" class="waiting submit-waiting" />
-</p>
-</form>
-
-<script type="text/javascript">
-jQuery(document).ready(function($) {
- var form = $('#<?php echo $this->getSlug(); ?>_filters_form').first();
- $('#filters-save').click(function() {
- $(form).find('input[name="action"]').val('<?php echo $this->getSlug(); ?>_filters_save');
- });
- $('#filters-reset').click(function() {
- $(form).find('input[name="action"]').val('<?php echo $this->getSlug(); ?>_filters_reset');
- });
- $(form).submit(function(e) {
- e.preventDefault();
- $(form).find('.submit-waiting').show();
- $.post(ajaxurl, $(form).serialize(), function(response) {
- $(form).find('.submit-waiting').hide();
- $('#message-body').html(response).fadeOut(0).fadeIn().delay(5000).fadeOut();
- });
- });
-
- $('#filters-reset').click(function(e, el) {
- if ( ! confirm('<?php _e('Are you sure you want to reset all WordPress HTTPS filters?','wordpress-https'); ?>') ) {
- e.preventDefault();
- return false;
- }
- });
-});
-</script>
View
211 view/metabox/url_mapping.php
@@ -0,0 +1,211 @@
+<?php
+if ( !defined('ABSPATH') ) exit;
+$http_url = clone $this->getHttpUrl();
+$http_url = rtrim($http_url->setScheme('')->toString(), '/');
+$https_url = clone $this->getHttpsUrl();
+$https_url = rtrim($https_url->setScheme('')->toString(), '/');
+?>
+<form name="<?php echo $this->getSlug(); ?>_url_mapping_form" id="<?php echo $this->getSlug(); ?>_url_mapping_form" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
+<?php wp_nonce_field($this->getSlug()); ?>
+<input type="hidden" name="action" id="action" value="" />
+
+<p><?php printf( __('URL Mapping allows you to map urls that host their HTTPS content on a different url. You may use %s regular expressions %s for the URL on the left side of the mapping.','wordpress-https'),'<a href="#TB_inline?height=155&width=350&inlineId=regex-help&" class="thickbox" title="' . __('Regular Expressions Help','wordpress-https') . '">', '</a>') ; ?></p>
+
+<table class="form-table" id="url_mapping">
+ <thead>
+ </thead>
+ <tbody>
+ <tr valign="top" class="url_mapping_row url_mapping_row">
+ <td class="scheme">
+ <select name="http_scheme" disabled="disabled">
+ <option>http</option>
+ </select>
+ </td>
+ <td class="sep">
+ <span class="label">://</span>
+ </td>
+ <td class="host">
+ <input id="http_url" type="text" name="http_host" value="<?php echo $http_url ?>" disabled="disabled" title="<?php echo _e('You can modify this mapping by changing your Home URL.','wordpress-https'); ?>" />
+ </td>
+ <td class="sep url-sep">
+ <span class="label">&gt;</span>
+ </td>
+ <td class="scheme">
+ <select name="https_scheme" disabled="disabled">
+ <option>https</option>
+ </select>
+ </td>
+ <td class="sep">
+ <span class="label">://</span>
+ </td>
+ <td class="host">
+ <input id="https_url" type="text" name="https_host" value="<?php echo $https_url ?>" disabled="disabled" title="<?php echo _e('You can modify this mapping by changing your SSL Host in the settings above.','wordpress-https'); ?>" />
+ </td>
+ <td class="controls">
+ </td>
+ </tr>
+<?php
+ $ssl_host_mapping = ( is_array($this->getSetting('ssl_host_mapping')) ? $this->getSetting('ssl_host_mapping') : array() );
+ if ( sizeof($ssl_host_mapping) > 0 ) {
+ foreach( $ssl_host_mapping as $mapping ) {
+ if ( !is_array($mapping) ) {
+ continue;
+ }
+?>
+ <tr valign="top" class="url_mapping_row">
+ <td class="scheme">
+ <select name="url_mapping[scheme][]">
+ <option<?php echo @$mapping[0]['scheme'] == 'http' ? ' selected="selected"' : ''; ?>>http</option>
+ <option<?php echo @$mapping[0]['scheme'] == 'https' ? ' selected="selected"' : ''; ?>>https</option>
+ </select>
+ </td>
+ <td class="sep">
+ <span class="label">://</span>
+ </td>
+ <td class="host">
+ <input type="text" name="url_mapping[host][]" value="<?php echo @$mapping[0]['host'] . ( isset($mapping[0]['port']) ? ':' . $mapping[0]['port'] : '' ) . @$mapping[0]['path']; ?>" />
+ </td>
+ <td class="sep url-sep">
+ <span class="label">&gt;</span>
+ </td>
+ <td class="scheme">
+ <select name="url_mapping[scheme][]">
+ <option<?php echo @$mapping[1]['scheme'] == 'https' ? ' selected="selected"' : ''; ?>>https</option>
+ <option<?php echo @$mapping[1]['scheme'] == 'http' ? ' selected="selected"' : ''; ?>>http</option>
+ </select>
+ </td>
+ <td class="sep">
+ <span class="label">://</span>
+ </td>
+ <td class="host">
+ <input type="text" name="url_mapping[host][]" value="<?php echo @$mapping[1]['host'] . ( isset($mapping[1]['port']) ? ':' . $mapping[1]['port'] : '' ) . @$mapping[1]['path']; ?>" />
+ </td>
+ <td class="controls">
+ <a class="remove" href="#" title="<?php _e('Remove URL Mapping','wordpress-https'); ?>"><?php _e('Remove','wordpress-https'); ?></a>
+ <a class="add" href="#" title="<?php _e('Add URL Mapping','wordpress-https'); ?>"><?php _e('Add','wordpress-https'); ?></a>
+ </td>
+ </tr>
+
+<?php
+ }
+ }
+?>
+ <tr valign="top" class="url_mapping_row">
+ <td class="scheme">
+ <select name="url_mapping[scheme][]">
+ <option>http</option>
+ <option>https</option>
+ </select>
+ </td>
+ <td class="sep">
+ <span class="label">://</span>
+ </td>
+ <td class="host">
+ <input type="text" name="url_mapping[host][]" value="" />
+ </td>
+ <td class="sep url-sep">
+ <span class="label">&gt;</span>
+ </td>
+ <td class="scheme">
+ <select name="url_mapping[scheme][]">
+ <option>https</option>
+ <option>http</option>
+ </select>
+ </td>
+ <td class="sep">
+ <span class="label">://</span>
+ </td>
+ <td class="host">
+ <input type="text" name="url_mapping[host][]" value="" />
+ </td>
+ <td class="controls">
+ <a class="remove" href="#" title="<?php _e('Remove URL Mapping','wordpress-https'); ?>"><?php _e('Remove','wordpress-https'); ?></a>
+ <a class="add" href="#" title="<?php _e('Add URL Mapping','wordpress-https'); ?>"><?php _e('Add','wordpress-https'); ?></a>
+ </td>
+ </tr>
+ </tbody>
+</table>
+
+<p class="button-controls">
+ <input type="submit" name="url-mapping-save" value="<?php _e('Save Changes','wordpress-https'); ?>" class="button-primary" id="url-mapping-save" />
+ <input type="submit" name="url-mapping-reset" value="<?php _e('Reset','wordpress-https'); ?>" class="button-secondary" id="url-mapping-reset" />
+ <img alt="<?php _e('Waiting...','wordpress-https'); ?>" src="<?php echo admin_url('/images/wpspin_light.gif'); ?>" class="waiting submit-waiting" />
+</p>
+</form>
+<script type="text/javascript">
+jQuery(document).ready(function($) {
+ var form = $('#<?php echo $this->getSlug(); ?>_url_mapping_form').first();
+ $('#url-mapping-save').click(function() {
+ $(form).find('input[name="action"]').val('<?php echo $this->getSlug(); ?>_url_mapping_save');
+ });
+ $('#url-mapping-reset').click(function() {
+ if ( ! confirm('<?php _e('Are you sure you want to reset all WordPress HTTPS url mappings?','wordpress-https'); ?>') ) {
+ e.preventDefault();
+ return false;
+ }
+ $(form).find('input[name="action"]').val('<?php echo $this->getSlug(); ?>_url_mapping_reset');
+ });
+ $(form).submit(function(e) {
+ e.preventDefault();
+ $(form).find('.submit-waiting').show();
+ $.post(ajaxurl, $(form).serialize(), function(response) {
+ $(form).find('.submit-waiting').hide();
+ $('#message-body').html(response).fadeOut(0).fadeIn().delay(5000).fadeOut();
+ });
+ });
+
+ var ssl_host;
+ $('#ssl_host').keyup(function() {
+ var value = $(this).val();
+ $('#https_url').val($('#https_url').val().replace(ssl_host, value));
+ ssl_host = value;
+ }).keyup();
+
+ $('#url_mapping').on('change', '.url_mapping_row .scheme select', function(e) {
+ e.preventDefault();
+ var thisSelect = this;
+ $(thisSelect).parents('tr').find('select').each(function(i, otherSelect) {
+ if ( thisSelect != otherSelect ) {
+ if ( $(thisSelect).val() == 'http' ) {
+ $(otherSelect).val('https');
+ } else {
+ $(otherSelect).val('http');
+ }
+ }
+ });
+ return false;
+ });
+
+ $('#url_mapping').on('click', '.url_mapping_row .add', function(e) {
+ e.preventDefault();
+ var row = $(this).parents('tr').clone();
+ row.find('input').val('');
+ $(this).parents('table').append(row);
+ $(this).hide();
+ $('#url_mapping .remove').show();
+ return false;
+ });
+
+ $('#url_mapping').on('click', '.url_mapping_row .remove', function(e) {
+ e.preventDefault();
+ $(this).parents('tr').remove();
+ if ( $('#url_mapping tr').length <= 2 ) {
+ $('#url_mapping .remove').hide();
+ } else {
+ $('#url_mapping .remove').show();
+ }
+ $('#url_mapping .add').hide();
+ $('#url_mapping tr:last-child .add').show();
+ return false;
+ });
+
+
+ if ( $('#url_mapping tr').length <= 2 ) {
+ $('#url_mapping .remove').hide();
+ } else {
+ $('#url_mapping .remove').show();
+ $('#url_mapping .add').hide();
+ $('#url_mapping tr:last-child .add').show();
+ }
+});
+</script>

0 comments on commit 417f13a

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