Changeset 2198540 for https-redirection
- Timestamp:
- 11/22/2019 02:39:27 AM (6 years ago)
- Location:
- https-redirection/trunk
- Files:
-
- 6 edited
-
https-redirection-settings.php (modified) (1 diff)
-
https-redirection.php (modified) (10 diffs)
-
https-rules-helper.php (modified) (1 diff)
-
https-utillity-functions.php (modified) (1 diff)
-
js/script.js (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
https-redirection/trunk/https-redirection-settings.php
r1908194 r2198540 7 7 $error = ""; 8 8 /* Save data for settings page */ 9 if ( isset($_REQUEST['httpsrdrctn_form_submit']) && check_admin_referer(plugin_basename(__FILE__), 'httpsrdrctn_nonce_name')) {10 $httpsrdrctn_options['https'] = isset($_REQUEST['httpsrdrctn_https']) ? $_REQUEST['httpsrdrctn_https'] : 0;11 $httpsrdrctn_options['https_domain'] = isset($_REQUEST['httpsrdrctn_https_domain']) ? $_REQUEST['httpsrdrctn_https_domain'] : 0;12 $httpsrdrctn_options['force_resources'] = isset($_REQUEST['httpsrdrctn_force_resources']) ? $_REQUEST['httpsrdrctn_force_resources'] : 0;9 if ( isset( $_REQUEST[ 'httpsrdrctn_form_submit' ] ) && check_admin_referer( plugin_basename( __FILE__ ), 'httpsrdrctn_nonce_name' ) ) { 10 $httpsrdrctn_options[ 'https' ] = isset( $_REQUEST[ 'httpsrdrctn_https' ] ) ? $_REQUEST[ 'httpsrdrctn_https' ] : 0; 11 $httpsrdrctn_options[ 'https_domain' ] = isset( $_REQUEST[ 'httpsrdrctn_https_domain' ] ) ? $_REQUEST[ 'httpsrdrctn_https_domain' ] : 0; 12 $httpsrdrctn_options[ 'force_resources' ] = isset( $_REQUEST[ 'httpsrdrctn_force_resources' ] ) ? $_REQUEST[ 'httpsrdrctn_force_resources' ] : 0; 13 13 14 if (isset($_REQUEST['httpsrdrctn_https_pages_array'])) {15 $httpsrdrctn_options['https_pages_array'] = array();16 //var_dump($httpsrdrctn_options['https_pages_array']);17 foreach ($_REQUEST['httpsrdrctn_https_pages_array'] as $httpsrdrctn_https_page) {18 if (!empty($httpsrdrctn_https_page) && $httpsrdrctn_https_page != '') {19 $httpsrdrctn_https_page = str_replace('https', 'http', $httpsrdrctn_https_page);20 $httpsrdrctn_options['https_pages_array'][] = trim(str_replace(home_url(), '', $httpsrdrctn_https_page), '/');21 }22 }23 }14 if ( isset( $_REQUEST[ 'httpsrdrctn_https_pages_array' ] ) ) { 15 $httpsrdrctn_options[ 'https_pages_array' ] = array(); 16 //var_dump($httpsrdrctn_options['https_pages_array']); 17 foreach ( $_REQUEST[ 'httpsrdrctn_https_pages_array' ] as $httpsrdrctn_https_page ) { 18 if ( ! empty( $httpsrdrctn_https_page ) && $httpsrdrctn_https_page != '' ) { 19 $httpsrdrctn_https_page = str_replace( 'https', 'http', $httpsrdrctn_https_page ); 20 $httpsrdrctn_options[ 'https_pages_array' ][] = trim( str_replace( home_url(), '', $httpsrdrctn_https_page ), '/' ); 21 } 22 } 23 } 24 24 25 if ("" == $error) {26 /* Update options in the database */27 update_option('httpsrdrctn_options', $httpsrdrctn_options, '', 'yes');28 $message = __("Settings saved.", 'https_redirection');29 $httpsrdrctn_obj = new HTTPSRDRCTN_RULES();30 $httpsrdrctn_obj->write_to_htaccess();31 25 if ( "" == $error ) { 26 /* Update options in the database */ 27 update_option( 'httpsrdrctn_options', $httpsrdrctn_options, '', 'yes' ); 28 $message = __( "Settings saved.", 'https_redirection' ); 29 $httpsrdrctn_obj = new HTTPSRDRCTN_RULES(); 30 $httpsrdrctn_obj->write_to_htaccess(); 31 32 32 //clear caching plugins cache if needed 33 33 //WP Fastest Cache 34 if ( isset($GLOBALS["wp_fastest_cache"])) {35 $wpfc =$GLOBALS["wp_fastest_cache"];36 if ( method_exists($wpfc,'deleteCache') && is_callable(array($wpfc,'deleteCache'))) {37 $wpfc->deleteCache( true);34 if ( isset( $GLOBALS[ "wp_fastest_cache" ] ) ) { 35 $wpfc = $GLOBALS[ "wp_fastest_cache" ]; 36 if ( method_exists( $wpfc, 'deleteCache' ) && is_callable( array( $wpfc, 'deleteCache' ) ) ) { 37 $wpfc->deleteCache( true ); 38 38 } 39 39 } 40 //httpsrdrctn_generate_htaccess();41 }40 //httpsrdrctn_generate_htaccess(); 41 } 42 42 } 43 $siteSSLurl = get_home_url( null, '', 'https');43 $siteSSLurl = get_home_url( null, '', 'https' ); 44 44 /* Display form on the setting page */ 45 45 ?> 46 46 <div class="wrap"> 47 48 <h2><?php _e( 'HTTPS Redirection Settings', 'https_redirection'); ?></h2>47 48 <h2><?php _e( 'HTTPS Redirection Settings', 'https_redirection' ); ?></h2> 49 49 50 50 <div style="background: #fff6d5; border: 1px solid #d1b655; color: #3f2502; margin: 10px 0; padding: 5px 5px 5px 10px; text-shadow: 1px 1px #ffffff;"> 51 <p><?php echo sprintf(__("When you enable the HTTPS redirection, the plugin will force redirect the URL to the HTTPS version of the URL. So before enabling this plugin's feature, visit your site's HTTPS URL %s to make sure the page loads correctly. Otherwise you may get locked out if your SSL certificate is not installed correctly on your site or the HTTPS URL is not working and this plugin is auto redirecting to the HTTPS URL.",'https_redirection'),'<a href="'.$siteSSLurl.'" target="_blank">'.$siteSSLurl.'</a>');?>52 </p>53 <p><span style='font-weight:bold;color:red;'><?php _e('Important!','https_redirection');?></span> <?php _e("If you're using caching plugins similar to W3 Total Cache or WP Super Cache, you need to clear their cache after you enable or disable automatic redirection option. Failing to do so may result in mixed content warning from browser.",'https_redirection');?>54 </p>51 <p><?php echo sprintf( __( "When you enable the HTTPS redirection, the plugin will force redirect the URL to the HTTPS version of the URL. So before enabling this plugin's feature, visit your site's HTTPS URL %s to make sure the page loads correctly. Otherwise you may get locked out if your SSL certificate is not installed correctly on your site or the HTTPS URL is not working and this plugin is auto redirecting to the HTTPS URL.", 'https_redirection' ), '<a href="' . $siteSSLurl . '" target="_blank">' . $siteSSLurl . '</a>' ); ?> 52 </p> 53 <p><span style='font-weight:bold;color:red;'><?php _e( 'Important!', 'https_redirection' ); ?></span> <?php _e( "If you're using caching plugins similar to W3 Total Cache or WP Super Cache, you need to clear their cache after you enable or disable automatic redirection option. Failing to do so may result in mixed content warning from browser.", 'https_redirection' ); ?> 54 </p> 55 55 </div> 56 56 57 <?php58 if (get_option('permalink_structure')) {59 //Pretty permalink is enabled. So allow HTTPS redirection feature.60 ?>61 <div id="httpsrdrctn_settings_notice" class="updated fade" style="display:none"><p><strong><?php _e("Notice:", 'https_redirection'); ?></strong> <?php _e("The plugin's settings have been changed. In order to save them please don't forget to click the 'Save Changes' button.", 'https_redirection'); ?></p></div>62 <div class="updated fade" <?php if (!isset($_REQUEST['httpsrdrctn_form_submit']) || $error != "") echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div>63 <div class="error" <?php if ("" == $error) echo "style=\"display:none\""; ?>><p><?php echo $error; ?></p></div>64 <form id="httpsrdrctn_settings_form" method="post" action="">65 <table class="form-table">66 <tr valign="top">67 <th scope="row"><?php _e('Enable automatic redirection to the "HTTPS"', 'https_redirection'); ?></th>68 <td>69 <label><input type="checkbox" id="httpsrdrctn-checkbox" name="httpsrdrctn_https" value="1" <?php if ('1' == $httpsrdrctn_options['https']) echo "checked=\"checked\" "; ?>/></label><br />70 <p class="description"><?php _e("Use this option to make your webpage(s) load in HTTPS version only. If someone enters a non-https URL in the browser's address bar then the plugin will automatically redirect to the HTTPS version of that URL.",'https_redirection');?></p>71 </td>72 </tr>73 </table>74 <div style="position: relative">75 <table class="form-table">76 <tr>77 <th scope="row"><?php _e('Apply HTTPS redirection on:','https_redirection');?></th>78 <td>79 <label><input type="radio" name="httpsrdrctn_https_domain" value="1" <?php if ('1' == $httpsrdrctn_options['https_domain']) echo "checked=\"checked\" "; ?>/> <?php _e('The whole domain','https_redirection');?></label><br />80 <label><input type="radio" name="httpsrdrctn_https_domain" value="0" <?php if ('0' == $httpsrdrctn_options['https_domain']) echo "checked=\"checked\" "; ?>/> <?php _e('A few pages','https_redirection');?></label><br />81 <?php foreach ($httpsrdrctn_options['https_pages_array'] as $https_page) { ?>82 <span>83 <?php echo str_replace("http://", "https://", home_url()); ?>/<input type="text" name="httpsrdrctn_https_pages_array[]" value="<?php echo $https_page; ?>" /> <span class="rewrite_delete_item"> </span> <span class="rewrite_item_blank_error"><?php _e('Please, fill field', 'list'); ?></span><br />84 </span>85 <?php } ?>86 <span class="rewrite_new_item" >87 <?php echo str_replace("http://", "https://", home_url()); ?>/<input type="text" name="httpsrdrctn_https_pages_array[]" value="" /> <span class="rewrite_add_item"> </span> <span class="rewrite_item_blank_error"><?php _e('Please, fill field', 'list'); ?></span><br />88 </span>89 </td>90 </tr>91 <tr valign="top">92 <th scope="row"><?php _e('Force resources to use HTTPS URL', 'https_redirection'); ?></th>93 <td>94 <label><input type="checkbox" name="httpsrdrctn_force_resources" value="1" <?php if (isset($httpsrdrctn_options['force_resources']) && $httpsrdrctn_options['force_resources'] == '1') echo "checked=\"checked\" "; ?>/></label><br />95 <p class="description"><?php _e('When checked, the plugin will force load HTTPS URL for any static resources in your content. Example: if you have have an image embedded in a post with a NON-HTTPS URL, this option will change that to a HTTPS URL.','https_redirection');?></p>96 </td>97 </tr>98 </table>99 <style>100 #httpsrdrctn-overlay {101 position: absolute;102 top: 10px;103 background-color: white;104 width: 100%;105 height: 100%;106 opacity: 0.5;107 text-align: center;108 }109 </style>110 <div id="httpsrdrctn-overlay"<?php echo ($httpsrdrctn_options['https'] == 1 ? ' class="hidden"' : ''); ?>></div>111 </div>112 <input type="hidden" name="httpsrdrctn_form_submit" value="submit" />113 <p class="submit">114 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />115 </p>116 <?php wp_nonce_field(plugin_basename(__FILE__), 'httpsrdrctn_nonce_name'); ?>117 </form>57 <?php 58 if ( get_option( 'permalink_structure' ) ) { 59 //Pretty permalink is enabled. So allow HTTPS redirection feature. 60 ?> 61 <div id="httpsrdrctn_settings_notice" class="updated fade" style="display:none"><p><strong><?php _e( "Notice:", 'https_redirection' ); ?></strong> <?php _e( "The plugin's settings have been changed. In order to save them please don't forget to click the 'Save Changes' button.", 'https_redirection' ); ?></p></div> 62 <div class="updated fade" <?php if ( ! isset( $_REQUEST[ 'httpsrdrctn_form_submit' ] ) || $error != "" ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div> 63 <div class="error" <?php if ( "" == $error ) echo "style=\"display:none\""; ?>><p><?php echo $error; ?></p></div> 64 <form id="httpsrdrctn_settings_form" method="post" action=""> 65 <table class="form-table"> 66 <tr valign="top"> 67 <th scope="row"><?php _e( 'Enable automatic redirection to the "HTTPS"', 'https_redirection' ); ?></th> 68 <td> 69 <label><input type="checkbox" id="httpsrdrctn-checkbox" name="httpsrdrctn_https" value="1" <?php if ( '1' == $httpsrdrctn_options[ 'https' ] ) echo "checked=\"checked\" "; ?>/></label><br /> 70 <p class="description"><?php _e( "Use this option to make your webpage(s) load in HTTPS version only. If someone enters a non-https URL in the browser's address bar then the plugin will automatically redirect to the HTTPS version of that URL.", 'https_redirection' ); ?></p> 71 </td> 72 </tr> 73 </table> 74 <div style="position: relative"> 75 <table class="form-table"> 76 <tr> 77 <th scope="row"><?php _e( 'Apply HTTPS redirection on:', 'https_redirection' ); ?></th> 78 <td> 79 <label><input type="radio" name="httpsrdrctn_https_domain" value="1" <?php if ( '1' == $httpsrdrctn_options[ 'https_domain' ] ) echo "checked=\"checked\" "; ?>/> <?php _e( 'The whole domain', 'https_redirection' ); ?></label><br /> 80 <label><input type="radio" name="httpsrdrctn_https_domain" value="0" <?php if ( '0' == $httpsrdrctn_options[ 'https_domain' ] ) echo "checked=\"checked\" "; ?>/> <?php _e( 'A few pages', 'https_redirection' ); ?></label><br /> 81 <?php foreach ( $httpsrdrctn_options[ 'https_pages_array' ] as $https_page ) { ?> 82 <span> 83 <?php echo str_replace( "http://", "https://", home_url() ); ?>/<input type="text" name="httpsrdrctn_https_pages_array[]" value="<?php echo $https_page; ?>" /> <span class="rewrite_delete_item"> </span> <span class="rewrite_item_blank_error"><?php _e( 'Please, fill field', 'list' ); ?></span><br /> 84 </span> 85 <?php } ?> 86 <span class="rewrite_new_item" > 87 <?php echo str_replace( "http://", "https://", home_url() ); ?>/<input type="text" name="httpsrdrctn_https_pages_array[]" value="" /> <span class="rewrite_add_item"> </span> <span class="rewrite_item_blank_error"><?php _e( 'Please, fill field', 'list' ); ?></span><br /> 88 </span> 89 </td> 90 </tr> 91 <tr valign="top"> 92 <th scope="row"><?php _e( 'Force resources to use HTTPS URL', 'https_redirection' ); ?></th> 93 <td> 94 <label><input type="checkbox" name="httpsrdrctn_force_resources" value="1" <?php if ( isset( $httpsrdrctn_options[ 'force_resources' ] ) && $httpsrdrctn_options[ 'force_resources' ] == '1' ) echo "checked=\"checked\" "; ?>/></label><br /> 95 <p class="description"><?php _e( 'When checked, the plugin will force load HTTPS URL for any static resources in your content. Example: if you have have an image embedded in a post with a NON-HTTPS URL, this option will change that to a HTTPS URL.', 'https_redirection' ); ?></p> 96 </td> 97 </tr> 98 </table> 99 <style> 100 #httpsrdrctn-overlay { 101 position: absolute; 102 top: 10px; 103 background-color: white; 104 width: 100%; 105 height: 100%; 106 opacity: 0.5; 107 text-align: center; 108 } 109 </style> 110 <div id="httpsrdrctn-overlay"<?php echo ($httpsrdrctn_options[ 'https' ] == 1 ? ' class="hidden"' : ''); ?>></div> 111 </div> 112 <input type="hidden" name="httpsrdrctn_form_submit" value="submit" /> 113 <p class="submit"> 114 <input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ) ?>" /> 115 </p> 116 <?php wp_nonce_field( plugin_basename( __FILE__ ), 'httpsrdrctn_nonce_name' ); ?> 117 </form> 118 118 119 <script>120 jQuery('input#httpsrdrctn-checkbox').change(function () {121 if (jQuery(this).is(':checked')) {122 jQuery('div#httpsrdrctn-overlay').fadeOut('fast');123 } else {124 jQuery('div#httpsrdrctn-overlay').fadeIn('fast');125 }126 });127 </script>119 <script> 120 jQuery('input#httpsrdrctn-checkbox').change(function () { 121 if (jQuery(this).is(':checked')) { 122 jQuery('div#httpsrdrctn-overlay').fadeOut('fast'); 123 } else { 124 jQuery('div#httpsrdrctn-overlay').fadeIn('fast'); 125 } 126 }); 127 </script> 128 128 129 <div style="background: #FFEBE8; border: 1px solid #CC0000; color: #333333; margin: 10px 0; padding: 5px 5px 5px 10px;">130 <p><strong><?php _e("Notice:", 'https_redirection'); ?></strong> <?php _e("It is very important to be extremely attentive when making changes to .htaccess file.", 'https_redirection'); ?></p>131 <p><?php _e('If after making changes your site stops functioning, do the following:','https_redirection');?></p>132 <p><?php _e('Step #1: Open .htaccess file in the root directory of the WordPress install and delete everything between the following two lines','https_redirection');?></p>133 <p style="border: 1px solid #ccc; padding: 10px;">134 # BEGIN HTTPS Redirection Plugin<br />135 # END HTTPS Redirection Plugin136 </p>137 <p><?php _e('Step #2: Save the htaccess file (this will erase any change this plugin made to that file).','https_redirection');?></p>138 <p><?php _e("Step #3: Deactivate the plugin or rename this plugin's folder (which will deactivate the plugin).",'https_redirection');?></p>129 <div style="background: #FFEBE8; border: 1px solid #CC0000; color: #333333; margin: 10px 0; padding: 5px 5px 5px 10px;"> 130 <p><strong><?php _e( "Notice:", 'https_redirection' ); ?></strong> <?php _e( "It is very important to be extremely attentive when making changes to .htaccess file.", 'https_redirection' ); ?></p> 131 <p><?php _e( 'If after making changes your site stops functioning, do the following:', 'https_redirection' ); ?></p> 132 <p><?php _e( 'Step #1: Open .htaccess file in the root directory of the WordPress install and delete everything between the following two lines', 'https_redirection' ); ?></p> 133 <p style="border: 1px solid #ccc; padding: 10px;"> 134 # BEGIN HTTPS Redirection Plugin<br /> 135 # END HTTPS Redirection Plugin 136 </p> 137 <p><?php _e( 'Step #2: Save the htaccess file (this will erase any change this plugin made to that file).', 'https_redirection' ); ?></p> 138 <p><?php _e( "Step #3: Deactivate the plugin or rename this plugin's folder (which will deactivate the plugin).", 'https_redirection' ); ?></p> 139 139 140 <p><?php _e('The changes will be applied immediately after saving the changes, if you are not sure - do not click the "Save changes" button.','https_redirection');?></p>141 </div>140 <p><?php _e( 'The changes will be applied immediately after saving the changes, if you are not sure - do not click the "Save changes" button.', 'https_redirection' ); ?></p> 141 </div> 142 142 143 <?php 144 } else { 145 //pretty permalink is NOT enabled. This plugin can't work. 146 ?> 147 <div class="error"> 148 <p><?php _e('HTTPS redirection only works if you have pretty permalinks enabled.', 'https_redirection'); ?></p> 149 <p><?php _e('To enable pretty permalinks go to <em>Settings > Permalinks</em> and select any option other than "default".', 'https_redirection'); ?></p> 150 <p><a href="options-permalink.php"><?php _e('Enable Permalinks','https_redirection');?></a></p> 151 </div> 152 <?php 153 } 154 155 ?> 156 <div style="background: #D7E7F5; border: 1px solid #1166BB; color: #333333; margin: 20px 0; padding: 10px;"> 157 You can view the <a href="https://www.tipsandtricks-hq.com/wordpress-easy-https-redirection-plugin" target="_blank">HTTPS Redirection plugin details</a> on our site. 158 Check out our other <a href="https://www.tipsandtricks-hq.com/development-center" target="_blank">WordPress plugins</a> and <a href="https://www.appthemes.com/" target="_blank">WordPress themes</a>. 159 </div> 143 <?php 144 } else { 145 //pretty permalink is NOT enabled. This plugin can't work. 146 ?> 147 <div class="error"> 148 <p><?php _e( 'HTTPS redirection only works if you have pretty permalinks enabled.', 'https_redirection' ); ?></p> 149 <p><?php _e( 'To enable pretty permalinks go to <em>Settings > Permalinks</em> and select any option other than "default".', 'https_redirection' ); ?></p> 150 <p><a href="options-permalink.php"><?php _e( 'Enable Permalinks', 'https_redirection' ); ?></a></p> 151 </div> 152 <?php 153 } 154 ?> 155 <div style="background: #D7E7F5; border: 1px solid #1166BB; color: #333333; margin: 20px 0; padding: 10px;"> 156 You can view the <a href="https://www.tipsandtricks-hq.com/wordpress-easy-https-redirection-plugin" target="_blank">HTTPS Redirection plugin details</a> on our site. 157 Check out our other <a href="https://www.tipsandtricks-hq.com/development-center" target="_blank">WordPress plugins</a> and <a href="https://www.appthemes.com/" target="_blank">WordPress themes</a>. 158 </div> 160 159 </div><!-- end of wrap --> 161 160 <?php -
https-redirection/trunk/https-redirection.php
r1831198 r2198540 6 6 Description: The plugin HTTPS Redirection allows an automatic redirection to the "HTTPS" version/URL of the site. 7 7 Author: Tips and Tricks HQ 8 Version: 1.9 8 Version: 1.9.1 9 9 Author URI: https://www.tipsandtricks-hq.com/ 10 10 License: GPLv2 or later … … 13 13 */ 14 14 15 if ( !defined('ABSPATH')) {15 if ( ! defined( 'ABSPATH' ) ) { 16 16 exit; //Exit if accessed directly 17 17 } … … 22 22 function httpsrdrctn_plugin_init() { 23 23 global $httpsrdrctn_options; 24 if ( empty($httpsrdrctn_options)) {25 $httpsrdrctn_options = get_option('httpsrdrctn_options');24 if ( empty( $httpsrdrctn_options ) ) { 25 $httpsrdrctn_options = get_option( 'httpsrdrctn_options' ); 26 26 } 27 27 28 28 //Do force resource embedded using HTTPS 29 if ( isset($httpsrdrctn_options['force_resources']) && $httpsrdrctn_options['force_resources'] == '1') {30 //Handle the appropriate content filters to force the static resources to use HTTPS URL31 if (is_admin()) {32 add_action("admin_init", "httpsrdrctn_start_buffer");33 } else {34 add_action("init", "httpsrdrctn_start_buffer");35 add_action("init", "httpsrdrctn_init_time_tasks");36 }37 add_action("shutdown", "httpsrdrctn_end_buffer");29 if ( isset( $httpsrdrctn_options[ 'force_resources' ] ) && $httpsrdrctn_options[ 'force_resources' ] == '1' ) { 30 //Handle the appropriate content filters to force the static resources to use HTTPS URL 31 if ( is_admin() ) { 32 add_action( "admin_init", "httpsrdrctn_start_buffer" ); 33 } else { 34 add_action( "init", "httpsrdrctn_start_buffer" ); 35 add_action( "init", "httpsrdrctn_init_time_tasks" ); 36 } 37 add_action( "shutdown", "httpsrdrctn_end_buffer" ); 38 38 } 39 39 } 40 40 41 41 function httpsrdrctn_start_buffer() { 42 ob_start( "httpsrdrctn_the_content");42 ob_start( "httpsrdrctn_the_content" ); 43 43 } 44 44 45 45 function httpsrdrctn_end_buffer() { 46 if ( ob_get_length())47 ob_end_flush();46 if ( ob_get_length() ) 47 ob_end_flush(); 48 48 } 49 49 … … 54 54 function httpsrdrctn_load_language() { 55 55 /* Internationalization */ 56 load_plugin_textdomain( 'https_redirection', false, dirname(plugin_basename(__FILE__)) . '/languages/');56 load_plugin_textdomain( 'https_redirection', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 57 57 } 58 58 … … 60 60 global $httpsrdrctn_plugin_info; 61 61 62 $httpsrdrctn_plugin_info = get_plugin_data( __FILE__, false);62 $httpsrdrctn_plugin_info = get_plugin_data( __FILE__, false ); 63 63 64 64 /* Call register settings function */ 65 if ( isset($_GET['page']) && "https-redirection" == $_GET['page']) {66 register_httpsrdrctn_settings();65 if ( isset( $_GET[ 'page' ] ) && "https-redirection" == $_GET[ 'page' ] ) { 66 register_httpsrdrctn_settings(); 67 67 } 68 68 } … … 74 74 75 75 $httpsrdrctn_option_defaults = array( 76 'https'=> 0,77 'https_domain'=> 1,78 'https_pages_array'=> array(),79 'force_resources'=> 0,80 'plugin_option_version' => $httpsrdrctn_plugin_info["Version"]76 'https' => 0, 77 'https_domain' => 1, 78 'https_pages_array' => array(), 79 'force_resources' => 0, 80 'plugin_option_version' => $httpsrdrctn_plugin_info[ "Version" ] 81 81 ); 82 82 83 83 /* Install the option defaults */ 84 if ( 1 == $wpmu) {85 if (!get_site_option('httpsrdrctn_options'))86 add_site_option('httpsrdrctn_options', $httpsrdrctn_option_defaults, '', 'yes');84 if ( 1 == $wpmu ) { 85 if ( ! get_site_option( 'httpsrdrctn_options' ) ) 86 add_site_option( 'httpsrdrctn_options', $httpsrdrctn_option_defaults, '', 'yes' ); 87 87 } else { 88 if (!get_option('httpsrdrctn_options'))89 add_option('httpsrdrctn_options', $httpsrdrctn_option_defaults, '', 'yes');88 if ( ! get_option( 'httpsrdrctn_options' ) ) 89 add_option( 'httpsrdrctn_options', $httpsrdrctn_option_defaults, '', 'yes' ); 90 90 } 91 91 92 92 /* Get options from the database */ 93 if ( 1 == $wpmu)94 $httpsrdrctn_options = get_site_option('httpsrdrctn_options');93 if ( 1 == $wpmu ) 94 $httpsrdrctn_options = get_site_option( 'httpsrdrctn_options' ); 95 95 else 96 $httpsrdrctn_options = get_option('httpsrdrctn_options');96 $httpsrdrctn_options = get_option( 'httpsrdrctn_options' ); 97 97 98 98 /* Array merge incase this version has added new options */ 99 if ( !isset($httpsrdrctn_options['plugin_option_version']) || $httpsrdrctn_options['plugin_option_version'] != $httpsrdrctn_plugin_info["Version"]) {100 $httpsrdrctn_options = array_merge($httpsrdrctn_option_defaults, $httpsrdrctn_options);101 $httpsrdrctn_options['plugin_option_version'] = $httpsrdrctn_plugin_info["Version"];102 update_option('httpsrdrctn_options', $httpsrdrctn_options);103 } 104 } 105 106 function httpsrdrctn_plugin_action_links( $links, $file) {99 if ( ! isset( $httpsrdrctn_options[ 'plugin_option_version' ] ) || $httpsrdrctn_options[ 'plugin_option_version' ] != $httpsrdrctn_plugin_info[ "Version" ] ) { 100 $httpsrdrctn_options = array_merge( $httpsrdrctn_option_defaults, $httpsrdrctn_options ); 101 $httpsrdrctn_options[ 'plugin_option_version' ] = $httpsrdrctn_plugin_info[ "Version" ]; 102 update_option( 'httpsrdrctn_options', $httpsrdrctn_options ); 103 } 104 } 105 106 function httpsrdrctn_plugin_action_links( $links, $file ) { 107 107 /* Static so we don't call plugin_basename on every plugin row. */ 108 108 static $this_plugin; 109 if ( !$this_plugin)110 $this_plugin = plugin_basename(__FILE__);111 112 if ( $file == $this_plugin) {113 $settings_link = '<a href="admin.php?page=https-redirection">' . __('Settings', 'https_redirection') . '</a>';114 array_unshift($links, $settings_link);109 if ( ! $this_plugin ) 110 $this_plugin = plugin_basename( __FILE__ ); 111 112 if ( $file == $this_plugin ) { 113 $settings_link = '<a href="admin.php?page=https-redirection">' . __( 'Settings', 'https_redirection' ) . '</a>'; 114 array_unshift( $links, $settings_link ); 115 115 } 116 116 return $links; 117 117 } 118 118 119 function httpsrdrctn_register_plugin_links( $links, $file) {120 $base = plugin_basename( __FILE__);121 if ( $file == $base) {122 $links[] = '<a href="admin.php?page=https-redirection">' . __('Settings', 'https_redirection') . '</a>';119 function httpsrdrctn_register_plugin_links( $links, $file ) { 120 $base = plugin_basename( __FILE__ ); 121 if ( $file == $base ) { 122 $links[] = '<a href="admin.php?page=https-redirection">' . __( 'Settings', 'https_redirection' ) . '</a>'; 123 123 } 124 124 return $links; … … 129 129 */ 130 130 131 function httpsrdrctn_filter_content( $content) {131 function httpsrdrctn_filter_content( $content ) { 132 132 //filter buffer 133 $home_no_www = str_replace("://www.", "://", get_option('home'));134 $home_yes_www = str_replace("://", "://www.", $home_no_www);135 $http_urls = array(136 str_replace("https://", "http://", $home_yes_www),137 str_replace("https://", "http://", $home_no_www),138 "src='http://",139 'src="http://',133 $home_no_www = str_replace( "://www.", "://", get_option( 'home' ) ); 134 $home_yes_www = str_replace( "://", "://www.", $home_no_www ); 135 $http_urls = array( 136 str_replace( "https://", "http://", $home_yes_www ), 137 str_replace( "https://", "http://", $home_no_www ), 138 "src='http://", 139 'src="http://', 140 140 ); 141 $ssl_array = str_replace("http://", "https://", $http_urls);141 $ssl_array = str_replace( "http://", "https://", $http_urls ); 142 142 //now replace these links 143 $str = str_replace($http_urls, $ssl_array, $content);143 $str = str_replace( $http_urls, $ssl_array, $content ); 144 144 145 145 //replace all http links except hyperlinks … … 147 147 148 148 $pattern = array( 149 '/url\([\'"]?\K(http:\/\/)(?=[^)]+)/i',150 '/<link .*?href=[\'"]\K(http:\/\/)(?=[^\'"]+)/i',151 '/<meta property="og:image" .*?content=[\'"]\K(http:\/\/)(?=[^\'"]+)/i',152 '/<form [^>]*?action=[\'"]\K(http:\/\/)(?=[^\'"]+)/i',149 '/url\([\'"]?\K(http:\/\/)(?=[^)]+)/i', 150 '/<link .*?href=[\'"]\K(http:\/\/)(?=[^\'"]+)/i', 151 '/<meta property="og:image" .*?content=[\'"]\K(http:\/\/)(?=[^\'"]+)/i', 152 '/<form [^>]*?action=[\'"]\K(http:\/\/)(?=[^\'"]+)/i', 153 153 ); 154 $str = preg_replace($pattern, 'https://', $str);154 $str = preg_replace( $pattern, 'https://', $str ); 155 155 return $str; 156 156 } 157 157 158 function httpsrdrctn_the_content( $content) {158 function httpsrdrctn_the_content( $content ) { 159 159 global $httpsrdrctn_options; 160 if ( empty($httpsrdrctn_options)) {161 $httpsrdrctn_options = get_option('httpsrdrctn_options');162 } 163 164 $current_page = sanitize_post($GLOBALS['wp_the_query']->get_queried_object());160 if ( empty( $httpsrdrctn_options ) ) { 161 $httpsrdrctn_options = get_option( 'httpsrdrctn_options' ); 162 } 163 164 $current_page = sanitize_post( $GLOBALS[ 'wp_the_query' ]->get_queried_object() ); 165 165 // Get the page slug 166 $slug = str_replace(home_url() . '/', '', get_permalink($current_page));167 $slug = rtrim($slug, "/"); //remove trailing slash if it's there168 169 if ( $httpsrdrctn_options['force_resources'] == '1' && $httpsrdrctn_options['https'] == 1) {170 if ($httpsrdrctn_options['https_domain'] == 1) {171 $content = httpsrdrctn_filter_content($content);172 } else if (!empty($httpsrdrctn_options['https_pages_array'])) {173 $pages_str= '';174 $on_https_page= false;175 foreach ($httpsrdrctn_options['https_pages_array'] as $https_page) {176 $pages_str .= preg_quote($https_page, '/') . '[\/|][\'"]|'; //let's add page to the preg expression string in case we'd need it later177 if ($https_page == $slug) { //if we are on the page that is in the array, let's set the var to true178 $on_https_page = true;179 } else { //if not - let's replace all links to that page only to https180 $http_domain= home_url();181 $https_domain = str_replace('http://', 'https://', home_url());182 $content = str_replace($http_domain . '/' . $https_page, $https_domain . '/' . $https_page, $content);183 }184 }185 if ($on_https_page) { //we are on one of the https pages186 $pages_str = substr($pages_str, 0, strlen($pages_str) - 1); //remove last '|'187 $content = httpsrdrctn_filter_content($content); //let's change everything to https first188 $http_domain = str_replace('https://', 'http://', home_url());189 $https_domain = str_replace('http://', 'https://', home_url());190 //now let's change all inner links to http, excluding those that user sets to be https in plugin settings191 $content = preg_replace('/<a .*?href=[\'"]\K' . preg_quote($https_domain, '/') . '\/((?!' . $pages_str . ').)(?=[^\'"]+)/i', $http_domain . '/$1', $content);192 $content = preg_replace('/' . preg_quote($https_domain, '/') . '([\'"])/i', $http_domain . '$1', $content);193 }194 }166 $slug = str_replace( home_url() . '/', '', get_permalink( $current_page ) ); 167 $slug = rtrim( $slug, "/" ); //remove trailing slash if it's there 168 169 if ( $httpsrdrctn_options[ 'force_resources' ] == '1' && $httpsrdrctn_options[ 'https' ] == 1 ) { 170 if ( $httpsrdrctn_options[ 'https_domain' ] == 1 ) { 171 $content = httpsrdrctn_filter_content( $content ); 172 } else if ( ! empty( $httpsrdrctn_options[ 'https_pages_array' ] ) ) { 173 $pages_str = ''; 174 $on_https_page = false; 175 foreach ( $httpsrdrctn_options[ 'https_pages_array' ] as $https_page ) { 176 $pages_str .= preg_quote( $https_page, '/' ) . '[\/|][\'"]|'; //let's add page to the preg expression string in case we'd need it later 177 if ( $https_page == $slug ) { //if we are on the page that is in the array, let's set the var to true 178 $on_https_page = true; 179 } else { //if not - let's replace all links to that page only to https 180 $http_domain = home_url(); 181 $https_domain = str_replace( 'http://', 'https://', home_url() ); 182 $content = str_replace( $http_domain . '/' . $https_page, $https_domain . '/' . $https_page, $content ); 183 } 184 } 185 if ( $on_https_page ) { //we are on one of the https pages 186 $pages_str = substr( $pages_str, 0, strlen( $pages_str ) - 1 ); //remove last '|' 187 $content = httpsrdrctn_filter_content( $content ); //let's change everything to https first 188 $http_domain = str_replace( 'https://', 'http://', home_url() ); 189 $https_domain = str_replace( 'http://', 'https://', home_url() ); 190 //now let's change all inner links to http, excluding those that user sets to be https in plugin settings 191 $content = preg_replace( '/<a .*?href=[\'"]\K' . preg_quote( $https_domain, '/' ) . '\/((?!' . $pages_str . ').)(?=[^\'"]+)/i', $http_domain . '/$1', $content ); 192 $content = preg_replace( '/' . preg_quote( $https_domain, '/' ) . '([\'"])/i', $http_domain . '$1', $content ); 193 } 194 } 195 195 } 196 196 return $content; 197 197 } 198 198 199 if ( !function_exists('httpsrdrctn_admin_head')) {199 if ( ! function_exists( 'httpsrdrctn_admin_head' ) ) { 200 200 201 201 function httpsrdrctn_admin_head() { 202 if (isset($_REQUEST['page']) && 'https-redirection' == $_REQUEST['page']) {203 wp_enqueue_style('httpsrdrctn_stylesheet', plugins_url('css/style.css', __FILE__));204 wp_enqueue_script('httpsrdrctn_script', plugins_url('js/script.js', __FILE__));205 }202 if ( isset( $_REQUEST[ 'page' ] ) && 'https-redirection' == $_REQUEST[ 'page' ] ) { 203 wp_enqueue_style( 'httpsrdrctn_stylesheet', plugins_url( 'css/style.css', __FILE__ ) ); 204 wp_enqueue_script( 'httpsrdrctn_script', plugins_url( 'js/script.js', __FILE__ ) ); 205 } 206 206 } 207 207 … … 209 209 210 210 /* Function for delete delete options */ 211 if ( !function_exists('httpsrdrctn_delete_options')) {211 if ( ! function_exists( 'httpsrdrctn_delete_options' ) ) { 212 212 213 213 function httpsrdrctn_delete_options() { 214 delete_option('httpsrdrctn_options');215 delete_site_option('httpsrdrctn_options');214 delete_option( 'httpsrdrctn_options' ); 215 delete_site_option( 'httpsrdrctn_options' ); 216 216 } 217 217 … … 219 219 220 220 function add_httpsrdrctn_admin_menu() { 221 add_submenu_page( 'options-general.php', 'HTTPS Redirection', 'HTTPS Redirection', 'manage_options', 'https-redirection', 'httpsrdrctn_settings_page', plugins_url("images/px.png", __FILE__), 1001);222 } 223 224 add_action( 'admin_menu', 'add_httpsrdrctn_admin_menu');225 add_action( 'admin_init', 'httpsrdrctn_plugin_admin_init');226 add_action( 'admin_enqueue_scripts', 'httpsrdrctn_admin_head');221 add_submenu_page( 'options-general.php', 'HTTPS Redirection', 'HTTPS Redirection', 'manage_options', 'https-redirection', 'httpsrdrctn_settings_page' ); 222 } 223 224 add_action( 'admin_menu', 'add_httpsrdrctn_admin_menu' ); 225 add_action( 'admin_init', 'httpsrdrctn_plugin_admin_init' ); 226 add_action( 'admin_enqueue_scripts', 'httpsrdrctn_admin_head' ); 227 227 228 228 /* Adds "Settings" link to the plugin action page */ 229 add_filter( 'plugin_action_links', 'httpsrdrctn_plugin_action_links', 10, 2);229 add_filter( 'plugin_action_links', 'httpsrdrctn_plugin_action_links', 10, 2 ); 230 230 /* Additional links on the plugin page */ 231 add_filter( 'plugin_row_meta', 'httpsrdrctn_register_plugin_links', 10, 2);231 add_filter( 'plugin_row_meta', 'httpsrdrctn_register_plugin_links', 10, 2 ); 232 232 //add_filter('mod_rewrite_rules', 'httpsrdrctn_mod_rewrite_rules');//TODO 5 233 233 234 register_uninstall_hook( __FILE__, 'httpsrdrctn_delete_options');234 register_uninstall_hook( __FILE__, 'httpsrdrctn_delete_options' ); 235 235 236 236 httpsrdrctn_plugin_init(); -
https-redirection/trunk/https-rules-helper.php
r1831198 r2198540 4 4 5 5 function __construct() { 6 6 7 7 } 8 8 9 9 function write_to_htaccess() { 10 //clean up old rules first11 if ($this->delete_from_htaccess() == -1) {12 return -1; //unable to write to the file13 }10 //clean up old rules first 11 if ( $this->delete_from_htaccess() == -1 ) { 12 return -1; //unable to write to the file 13 } 14 14 15 $htaccess= ABSPATH . '.htaccess';16 //get the subdirectory if it is installed in one17 $siteurl = explode('/', get_option('siteurl'));18 if (isset($siteurl[3])) {19 $dir = '/' . $siteurl[3] . '/';20 } else {21 $dir = '/';22 }15 $htaccess = ABSPATH . '.htaccess'; 16 //get the subdirectory if it is installed in one 17 $siteurl = explode( '/', get_option( 'siteurl' ) ); 18 if ( isset( $siteurl[ 3 ] ) ) { 19 $dir = '/' . $siteurl[ 3 ] . '/'; 20 } else { 21 $dir = '/'; 22 } 23 23 24 if (!$f = @fopen($htaccess, 'a+')) { 25 @chmod($htaccess, 0644); 26 if (!$f = @fopen($htaccess, 'a+')) { 27 return -1; 28 } 29 } 30 31 //backup_a_file($htaccess); //TODO - should we back up htaccess file? 32 33 @ini_set('auto_detect_line_endings', true); 34 $ht = explode(PHP_EOL, implode('', file($htaccess))); //parse each line of file into array 24 if ( ! $f = @fopen( $htaccess, 'a+' ) ) { 25 @chmod( $htaccess, 0644 ); 26 if ( ! $f = @fopen( $htaccess, 'a+' ) ) { 27 return -1; 28 } 29 } 35 30 36 $rules = $this->getrules(); 37 if ($rules == -1) { 38 return -1; 39 } 31 //backup_a_file($htaccess); //TODO - should we back up htaccess file? 40 32 41 $rulesarray = explode(PHP_EOL, $rules);42 $contents = array_merge($rulesarray, $ht); 33 @ini_set( 'auto_detect_line_endings', true ); 34 $ht = explode( PHP_EOL, implode( '', file( $htaccess ) ) ); //parse each line of file into array 43 35 44 if (!$f = @fopen($htaccess, 'w+')) { 45 return -1; //we can't write to the file 46 } 36 $rules = $this->getrules(); 37 if ( $rules == -1 ) { 38 return -1; 39 } 47 40 48 $blank = false; 41 $rulesarray = explode( PHP_EOL, $rules ); 42 $contents = array_merge( $rulesarray, $ht ); 49 43 50 //write each line to file 51 foreach ($contents as $insertline) { 52 if (trim($insertline) == '') { 53 if ($blank == false) { 54 fwrite($f, PHP_EOL . trim($insertline)); 55 } 56 $blank = true; 57 } else { 58 $blank = false; 59 fwrite($f, PHP_EOL . trim($insertline)); 60 } 61 } 62 @fclose($f); 63 return 1; //success 44 if ( ! $f = @fopen( $htaccess, 'w+' ) ) { 45 return -1; //we can't write to the file 46 } 47 48 $blank = false; 49 50 //write each line to file 51 foreach ( $contents as $insertline ) { 52 if ( trim( $insertline ) == '' ) { 53 if ( $blank == false ) { 54 fwrite( $f, PHP_EOL . trim( $insertline ) ); 55 } 56 $blank = true; 57 } else { 58 $blank = false; 59 fwrite( $f, PHP_EOL . trim( $insertline ) ); 60 } 61 } 62 @fclose( $f ); 63 return 1; //success 64 64 } 65 65 66 66 function getrules() { 67 @ini_set('auto_detect_line_endings', true);67 @ini_set( 'auto_detect_line_endings', true ); 68 68 69 //figure out what server they're using70 if (strstr(strtolower(filter_var($_SERVER['SERVER_SOFTWARE'], FILTER_SANITIZE_STRING)), 'apache')) {71 $server_type = 'apache';72 } else if (strstr(strtolower(filter_var($_SERVER['SERVER_SOFTWARE'], FILTER_SANITIZE_STRING)), 'nginx')) {73 $server_type = 'nginx';74 } else if (strstr(strtolower(filter_var($_SERVER['SERVER_SOFTWARE'], FILTER_SANITIZE_STRING)), 'litespeed')) {75 $server_type = 'litespeed';76 } else { //unsupported server77 return -1;78 }79 69 //figure out what server they're using 70 if ( strstr( strtolower( filter_var( $_SERVER[ 'SERVER_SOFTWARE' ], FILTER_SANITIZE_STRING ) ), 'apache' ) ) { 71 $server_type = 'apache'; 72 } else if ( strstr( strtolower( filter_var( $_SERVER[ 'SERVER_SOFTWARE' ], FILTER_SANITIZE_STRING ) ), 'nginx' ) ) { 73 $server_type = 'nginx'; 74 } else if ( strstr( strtolower( filter_var( $_SERVER[ 'SERVER_SOFTWARE' ], FILTER_SANITIZE_STRING ) ), 'litespeed' ) ) { 75 $server_type = 'litespeed'; 76 } else { //unsupported server 77 return -1; 78 } 79 80 80 //check if some plugins are active to avoid incompatability issues 81 81 // WP Fastest Cache 82 if ( isset($GLOBALS["wp_fastest_cache"])) {83 $wpfc =true;84 $wpfc_rules ='# WP Fastest Cache compatability'.PHP_EOL;85 $wpfc_rules .='RewriteCond %{REQUEST_URI} !wp-content\/cache\/(all|wpfc-mobile-cache)'.PHP_EOL;82 if ( isset( $GLOBALS[ "wp_fastest_cache" ] ) ) { 83 $wpfc = true; 84 $wpfc_rules = '# WP Fastest Cache compatability' . PHP_EOL; 85 $wpfc_rules .= 'RewriteCond %{REQUEST_URI} !wp-content\/cache\/(all|wpfc-mobile-cache)' . PHP_EOL; 86 86 } else { 87 $wpfc =false;87 $wpfc = false; 88 88 } 89 89 90 $rules= '';91 $httpsrdrctn_options = get_option('httpsrdrctn_options');92 $https_full_domain = $httpsrdrctn_options['https_domain'];93 $auto_redirect_enabled = $httpsrdrctn_options['https'];94 95 if($auto_redirect_enabled != '1'){96 //HTTPS Redirection is NOT enabled97 return $rules;98 }99 100 if($https_full_domain == '1'){//HTTPS Redirection on Full Site101 $rules.= '<IfModule mod_rewrite.c>' . PHP_EOL;102 $rules.= 'RewriteEngine On' . PHP_EOL;103 104 $rules .= 'RewriteCond %{SERVER_PORT} !^443$' . PHP_EOL; //Alternative is to use RewriteCond %{HTTPS} off105 if ( $wpfc) {106 $rules .=$wpfc_rules;90 $rules = ''; 91 $httpsrdrctn_options = get_option( 'httpsrdrctn_options' ); 92 $https_full_domain = $httpsrdrctn_options[ 'https_domain' ]; 93 $auto_redirect_enabled = $httpsrdrctn_options[ 'https' ]; 94 95 if ( $auto_redirect_enabled != '1' ) { 96 //HTTPS Redirection is NOT enabled 97 return $rules; 98 } 99 100 if ( $https_full_domain == '1' ) {//HTTPS Redirection on Full Site 101 $rules .= '<IfModule mod_rewrite.c>' . PHP_EOL; 102 $rules .= 'RewriteEngine On' . PHP_EOL; 103 104 $rules .= 'RewriteCond %{SERVER_PORT} !^443$' . PHP_EOL; //Alternative is to use RewriteCond %{HTTPS} off 105 if ( $wpfc ) { 106 $rules .= $wpfc_rules; 107 107 } 108 $rules .= 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]' . PHP_EOL; 109 110 $rules .= '</IfModule>' . PHP_EOL; 111 } 112 else{//HTTPS Redirection on a Few Pages ONLY 113 114 if (empty($httpsrdrctn_options['https_pages_array'])) { 115 //No specific page has been configured 116 return ''; 117 } 118 119 $rules .= '<IfModule mod_rewrite.c>' . PHP_EOL; 120 $rules .= 'RewriteEngine On' . PHP_EOL; 121 122 $rules .= 'RewriteCond %{SERVER_PORT} !^443$' . PHP_EOL; //Alternative is to use RewriteCond %{HTTPS} off 123 if ($wpfc) { 124 $rules.=$wpfc_rules; 108 $rules .= 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]' . PHP_EOL; 109 110 $rules .= '</IfModule>' . PHP_EOL; 111 } else {//HTTPS Redirection on a Few Pages ONLY 112 if ( empty( $httpsrdrctn_options[ 'https_pages_array' ] ) ) { 113 //No specific page has been configured 114 return ''; 125 115 } 126 $count = 0;127 $total_pages = count($httpsrdrctn_options['https_pages_array']);128 foreach ($httpsrdrctn_options['https_pages_array'] as $https_page) {129 //Add a RewriteCond line for each of the individual pages130 116 131 $count ++; 132 133 if(empty($https_page)){ 134 continue; 135 } 136 137 $rules .= 'RewriteCond %{REQUEST_URI} '.trim($https_page); 138 if($total_pages != $count){//This is not the last page so join them with an OR condition 139 $rules .= ' [OR]'; 140 } 141 $rules .= PHP_EOL; 142 } 143 144 $rules .= 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]' . PHP_EOL; 145 146 $rules .= '</IfModule>' . PHP_EOL; 147 } 117 $rules .= '<IfModule mod_rewrite.c>' . PHP_EOL; 118 $rules .= 'RewriteEngine On' . PHP_EOL; 148 119 149 //Add outer markers if we have rules 150 if ($rules != '') { 151 $rules = "# BEGIN HTTPS Redirection Plugin" . PHP_EOL . $rules . "# END HTTPS Redirection Plugin" . PHP_EOL; 152 } 120 $rules .= 'RewriteCond %{SERVER_PORT} !^443$' . PHP_EOL; //Alternative is to use RewriteCond %{HTTPS} off 121 if ( $wpfc ) { 122 $rules .= $wpfc_rules; 123 } 124 $count = 0; 125 $total_pages = count( $httpsrdrctn_options[ 'https_pages_array' ] ); 126 foreach ( $httpsrdrctn_options[ 'https_pages_array' ] as $https_page ) { 127 //Add a RewriteCond line for each of the individual pages 153 128 154 return $rules; 129 $count ++; 130 131 if ( empty( $https_page ) ) { 132 continue; 133 } 134 135 $rules .= 'RewriteCond %{REQUEST_URI} ' . trim( $https_page ); 136 if ( $total_pages != $count ) {//This is not the last page so join them with an OR condition 137 $rules .= ' [OR]'; 138 } 139 $rules .= PHP_EOL; 140 } 141 142 $rules .= 'RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]' . PHP_EOL; 143 144 $rules .= '</IfModule>' . PHP_EOL; 145 } 146 147 //Add outer markers if we have rules 148 if ( $rules != '' ) { 149 $rules = "# BEGIN HTTPS Redirection Plugin" . PHP_EOL . $rules . "# END HTTPS Redirection Plugin" . PHP_EOL; 150 } 151 152 return $rules; 155 153 } 156 154 157 function delete_from_htaccess( $section = 'HTTPS Redirection Plugin') {158 $htaccess = ABSPATH . '.htaccess';155 function delete_from_htaccess( $section = 'HTTPS Redirection Plugin' ) { 156 $htaccess = ABSPATH . '.htaccess'; 159 157 160 @ini_set('auto_detect_line_endings', true);161 if (!file_exists($htaccess)) {162 $ht = @fopen($htaccess, 'a+');163 @fclose($ht);164 }165 $ht_contents = explode(PHP_EOL, implode('', file($htaccess))); //parse each line of file into array166 if ($ht_contents) { //as long as there are lines in the file167 $state= true;168 if (!$f = @fopen($htaccess, 'w+')) {169 @chmod($htaccess, 0644);170 if (!$f = @fopen($htaccess, 'w+')) {171 return -1;172 }173 }158 @ini_set( 'auto_detect_line_endings', true ); 159 if ( ! file_exists( $htaccess ) ) { 160 $ht = @fopen( $htaccess, 'a+' ); 161 @fclose( $ht ); 162 } 163 $ht_contents = explode( PHP_EOL, implode( '', file( $htaccess ) ) ); //parse each line of file into array 164 if ( $ht_contents ) { //as long as there are lines in the file 165 $state = true; 166 if ( ! $f = @fopen( $htaccess, 'w+' ) ) { 167 @chmod( $htaccess, 0644 ); 168 if ( ! $f = @fopen( $htaccess, 'w+' ) ) { 169 return -1; 170 } 171 } 174 172 175 foreach ($ht_contents as $n => $markerline) { //for each line in the file176 if (strpos($markerline, '# BEGIN ' . $section) !== false) { //if we're at the beginning of the section177 $state = false;178 }179 if ($state == true) { //as long as we're not in the section keep writing180 fwrite($f, trim($markerline) . PHP_EOL);181 }182 if (strpos($markerline, '# END ' . $section) !== false) { //see if we're at the end of the section183 $state = true;184 }185 }186 @fclose($f);187 return 1;188 }189 return 1;173 foreach ( $ht_contents as $n => $markerline ) { //for each line in the file 174 if ( strpos( $markerline, '# BEGIN ' . $section ) !== false ) { //if we're at the beginning of the section 175 $state = false; 176 } 177 if ( $state == true ) { //as long as we're not in the section keep writing 178 fwrite( $f, trim( $markerline ) . PHP_EOL ); 179 } 180 if ( strpos( $markerline, '# END ' . $section ) !== false ) { //see if we're at the end of the section 181 $state = true; 182 } 183 } 184 @fclose( $f ); 185 return 1; 186 } 187 return 1; 190 188 } 191 189 192 190 } 193 -
https-redirection/trunk/https-utillity-functions.php
r1105728 r2198540 1 1 <?php 2 2 3 function httpsrdrctn_force_https_embeds( $content ) {4 $files_to_check = array( 'jpg', 'jpeg', 'gif', 'png', 'js', 'css' );3 function httpsrdrctn_force_https_embeds( $content ) { 4 $files_to_check = array( 'jpg', 'jpeg', 'gif', 'png', 'js', 'css' ); 5 5 6 if ( strpos( home_url(), 'https' ) !== false ) { 7 $http_domain = str_replace( 'https', 'http', home_url() ); 8 } else { 9 $http_domain = home_url(); 6 if ( strpos( home_url(), 'https' ) !== false ) { 7 $http_domain = str_replace( 'https', 'http', home_url() ); 8 } else { 9 $http_domain = home_url(); 10 } 11 12 $matches = array(); 13 $pattern = '/' . str_replace( '/', '\/', quotemeta( $http_domain ) ) . '\/[^\"\']*\.[' . implode( "|", $files_to_check ) . ']+/'; 14 15 preg_match_all( $pattern, $content, $matches ); 16 17 if ( ! empty( $matches ) ) { 18 foreach ( $matches[ 0 ] as $match ) { 19 $match_https = str_replace( 'http', 'https', $match ); 20 $content = str_replace( $match, $match_https, $content ); 10 21 } 11 12 $matches = array(); 13 $pattern = '/' . str_replace( '/', '\/', quotemeta( $http_domain ) ) . '\/[^\"\']*\.[' . implode( "|", $files_to_check ) . ']+/'; 22 } 14 23 15 preg_match_all( $pattern, $content, $matches ); 16 17 if( ! empty( $matches ) ){ 18 foreach( $matches[0] as $match ){ 19 $match_https = str_replace( 'http', 'https', $match ); 20 $content = str_replace( $match, $match_https, $content ); 21 } 22 } 23 24 return $content; 24 return $content; 25 25 } 26 26 -
https-redirection/trunk/js/script.js
r940834 r2198540 1 (function($) { 2 $(document).ready( function() { 3 /* add notice about changing in the settings page */ 4 $( document ).on( 'click', '.rewrite_add_item', function(){ 5 $(this).each( function(){ 6 if( $( this ).prev().val() != '' ){ 7 $( this ).next().hide(); 8 $( this ).parents( '.rewrite_new_item' ).removeClass( 'rewrite_new_item' ).clone().addClass( 'rewrite_new_item' ).appendTo( $( this ).parents( "td" ) ).find( 'input' ).val( '' ); 9 $( this ).addClass( 'rewrite_delete_item' ).removeClass( 'rewrite_add_item' ); 10 } 11 else{ 12 $(this).next().show(); 13 } 14 }); 15 }); 16 $( document ).on( 'click', '.rewrite_delete_item', function(){ 17 $( this ).each( function(){ 18 $( this ).parent().remove(); 19 }); 20 }); 1 (function ($) { 2 $(document).ready(function () { 3 /* add notice about changing in the settings page */ 4 $(document).on('click', '.rewrite_add_item', function () { 5 $(this).each(function () { 6 if ($(this).prev().val() != '') { 7 $(this).next().hide(); 8 $(this).parents('.rewrite_new_item').removeClass('rewrite_new_item').clone().addClass('rewrite_new_item').appendTo($(this).parents("td")).find('input').val(''); 9 $(this).addClass('rewrite_delete_item').removeClass('rewrite_add_item'); 10 } else { 11 $(this).next().show(); 12 } 13 }); 21 14 }); 15 $(document).on('click', '.rewrite_delete_item', function () { 16 $(this).each(function () { 17 $(this).parent().remove(); 18 }); 19 }); 20 }); 22 21 })(jQuery); -
https-redirection/trunk/readme.txt
r2178929 r2198540 5 5 Requires at least: 3.5 6 6 Tested up to: 5.3 7 Stable tag: 1.9 7 Stable tag: 1.9.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 94 94 == Changelog == 95 95 96 = v1.9.1 = 97 - WP 5.3 warning fix for the add_submenu_page() function call. Thanks to @vfontj for pointing this out. 98 96 99 = v1.9 = 97 100 - WP Fastest Cache cache is automatically cleared when plugin settings are changed. This is to prevent "mixed content" warning from browsers.
Note: See TracChangeset
for help on using the changeset viewer.