Plugin Directory

Changeset 2198540 for https-redirection


Ignore:
Timestamp:
11/22/2019 02:39:27 AM (6 years ago)
Author:
mra13
Message:

WP 5.3 warning fix for the add_submenu_page() function call. Thanks to @vfontj for pointing this out.

Location:
https-redirection/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • https-redirection/trunk/https-redirection-settings.php

    r1908194 r2198540  
    77    $error = "";
    88    /* 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;
    1313
    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    }
    2424
    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
    3232        //clear caching plugins cache if needed
    3333        //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 );
    3838        }
    3939        }
    40             //httpsrdrctn_generate_htaccess();
    41         }
     40        //httpsrdrctn_generate_htaccess();
     41    }
    4242    }
    43     $siteSSLurl = get_home_url(null, '', 'https');
     43    $siteSSLurl = get_home_url( null, '', 'https' );
    4444    /* Display form on the setting page */
    4545    ?>
    4646    <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>
    4949
    5050        <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>
    5555        </div>
    5656
    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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</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>
    118118
    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>
    128128
    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>
     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>
    139139
    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>
    142142
    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>
    160159    </div><!-- end of wrap -->
    161160    <?php
  • https-redirection/trunk/https-redirection.php

    r1831198 r2198540  
    66  Description: The plugin HTTPS Redirection allows an automatic redirection to the "HTTPS" version/URL of the site.
    77  Author: Tips and Tricks HQ
    8   Version: 1.9
     8  Version: 1.9.1
    99  Author URI: https://www.tipsandtricks-hq.com/
    1010  License: GPLv2 or later
     
    1313 */
    1414
    15 if (!defined('ABSPATH')) {
     15if ( ! defined( 'ABSPATH' ) ) {
    1616    exit; //Exit if accessed directly
    1717}
     
    2222function httpsrdrctn_plugin_init() {
    2323    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' );
    2626    }
    2727
    2828    //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 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");
     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" );
    3838    }
    3939}
    4040
    4141function httpsrdrctn_start_buffer() {
    42     ob_start("httpsrdrctn_the_content");
     42    ob_start( "httpsrdrctn_the_content" );
    4343}
    4444
    4545function httpsrdrctn_end_buffer() {
    46     if (ob_get_length())
    47         ob_end_flush();
     46    if ( ob_get_length() )
     47    ob_end_flush();
    4848}
    4949
     
    5454function httpsrdrctn_load_language() {
    5555    /* 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/' );
    5757}
    5858
     
    6060    global $httpsrdrctn_plugin_info;
    6161
    62     $httpsrdrctn_plugin_info = get_plugin_data(__FILE__, false);
     62    $httpsrdrctn_plugin_info = get_plugin_data( __FILE__, false );
    6363
    6464    /* 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();
    6767    }
    6868}
     
    7474
    7575    $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" ]
    8181    );
    8282
    8383    /* 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' );
    8787    } 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' );
    9090    }
    9191
    9292    /* 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' );
    9595    else
    96         $httpsrdrctn_options = get_option('httpsrdrctn_options');
     96    $httpsrdrctn_options     = get_option( 'httpsrdrctn_options' );
    9797
    9898    /* 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
     106function httpsrdrctn_plugin_action_links( $links, $file ) {
    107107    /* Static so we don't call plugin_basename on every plugin row. */
    108108    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 );
    115115    }
    116116    return $links;
    117117}
    118118
    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>';
     119function 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>';
    123123    }
    124124    return $links;
     
    129129 */
    130130
    131 function httpsrdrctn_filter_content($content) {
     131function httpsrdrctn_filter_content( $content ) {
    132132    //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://',
    140140    );
    141     $ssl_array = str_replace("http://", "https://", $http_urls);
     141    $ssl_array   = str_replace( "http://", "https://", $http_urls );
    142142    //now replace these links
    143     $str = str_replace($http_urls, $ssl_array, $content);
     143    $str         = str_replace( $http_urls, $ssl_array, $content );
    144144
    145145    //replace all http links except hyperlinks
     
    147147
    148148    $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',
    153153    );
    154     $str = preg_replace($pattern, 'https://', $str);
     154    $str     = preg_replace( $pattern, 'https://', $str );
    155155    return $str;
    156156}
    157157
    158 function httpsrdrctn_the_content($content) {
     158function httpsrdrctn_the_content( $content ) {
    159159    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() );
    165165    // Get the page slug
    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         }
     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    }
    195195    }
    196196    return $content;
    197197}
    198198
    199 if (!function_exists('httpsrdrctn_admin_head')) {
     199if ( ! function_exists( 'httpsrdrctn_admin_head' ) ) {
    200200
    201201    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    }
    206206    }
    207207
     
    209209
    210210/* Function for delete delete options */
    211 if (!function_exists('httpsrdrctn_delete_options')) {
     211if ( ! function_exists( 'httpsrdrctn_delete_options' ) ) {
    212212
    213213    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' );
    216216    }
    217217
     
    219219
    220220function 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
     224add_action( 'admin_menu', 'add_httpsrdrctn_admin_menu' );
     225add_action( 'admin_init', 'httpsrdrctn_plugin_admin_init' );
     226add_action( 'admin_enqueue_scripts', 'httpsrdrctn_admin_head' );
    227227
    228228/* Adds "Settings" link to the plugin action page */
    229 add_filter('plugin_action_links', 'httpsrdrctn_plugin_action_links', 10, 2);
     229add_filter( 'plugin_action_links', 'httpsrdrctn_plugin_action_links', 10, 2 );
    230230/* Additional links on the plugin page */
    231 add_filter('plugin_row_meta', 'httpsrdrctn_register_plugin_links', 10, 2);
     231add_filter( 'plugin_row_meta', 'httpsrdrctn_register_plugin_links', 10, 2 );
    232232//add_filter('mod_rewrite_rules', 'httpsrdrctn_mod_rewrite_rules');//TODO 5
    233233
    234 register_uninstall_hook(__FILE__, 'httpsrdrctn_delete_options');
     234register_uninstall_hook( __FILE__, 'httpsrdrctn_delete_options' );
    235235
    236236httpsrdrctn_plugin_init();
  • https-redirection/trunk/https-rules-helper.php

    r1831198 r2198540  
    44
    55    function __construct() {
    6        
     6   
    77    }
    8    
     8
    99    function write_to_htaccess() {
    10         //clean up old rules first
    11         if ($this->delete_from_htaccess() == -1) {
    12             return -1; //unable to write to the file
    13         }
     10    //clean up old rules first
     11    if ( $this->delete_from_htaccess() == -1 ) {
     12        return -1; //unable to write to the file
     13    }
    1414
    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         }
     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    }
    2323
    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    }
    3530
    36         $rules = $this->getrules();
    37         if ($rules == -1) {
    38             return -1;
    39         }
     31    //backup_a_file($htaccess); //TODO - should we back up htaccess file?
    4032
    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
    4335
    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    }
    4740
    48         $blank = false;
     41    $rulesarray  = explode( PHP_EOL, $rules );
     42    $contents    = array_merge( $rulesarray, $ht );
    4943
    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
    6464    }
    6565
    6666    function getrules() {
    67         @ini_set('auto_detect_line_endings', true);
     67    @ini_set( 'auto_detect_line_endings', true );
    6868
    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    
     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
    8080    //check if some plugins are active to avoid incompatability issues
    8181    // 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;
    8686    } else {
    87         $wpfc=false;
     87        $wpfc = false;
    8888    }
    8989
    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;
     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;
    107107        }
    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 '';
    125115        }
    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 pages
    130116
    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;
    148119
    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
    153128
    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;
    155153    }
    156154
    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';
    159157
    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 array
    166         if ($ht_contents) { //as long as there are lines in the file
    167             $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        }
    174172
    175             foreach ($ht_contents as $n => $markerline) { //for each line in the file
    176                 if (strpos($markerline, '# BEGIN ' . $section) !== false) { //if we're at the beginning of the section
    177                     $state = false;
    178                 }
    179                 if ($state == true) { //as long as we're not in the section keep writing
    180                     fwrite($f, trim($markerline) . PHP_EOL);
    181                 }
    182                 if (strpos($markerline, '# END ' . $section) !== false) { //see if we're at the end of the section
    183                     $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;
    190188    }
    191189
    192190}
    193 
  • https-redirection/trunk/https-utillity-functions.php

    r1105728 r2198540  
    11<?php
    22
    3 function httpsrdrctn_force_https_embeds( $content ){
    4     $files_to_check = array( 'jpg', 'jpeg', 'gif', 'png', 'js', 'css' );
     3function httpsrdrctn_force_https_embeds( $content ) {
     4    $files_to_check = array( 'jpg', 'jpeg', 'gif', 'png', 'js', 'css' );
    55
    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 );
    1021    }
    11    
    12     $matches = array();
    13     $pattern = '/' . str_replace( '/', '\/', quotemeta( $http_domain ) ) . '\/[^\"\']*\.[' . implode( "|", $files_to_check ) . ']+/';
     22    }
    1423
    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;
    2525}
    2626
  • 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        });
    2114    });
     15    $(document).on('click', '.rewrite_delete_item', function () {
     16        $(this).each(function () {
     17        $(this).parent().remove();
     18        });
     19    });
     20    });
    2221})(jQuery);
  • https-redirection/trunk/readme.txt

    r2178929 r2198540  
    55Requires at least: 3.5
    66Tested up to: 5.3
    7 Stable tag: 1.9
     7Stable tag: 1.9.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    9494== Changelog ==
    9595
     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
    9699= v1.9 =
    97100- 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.