Plugin Directory


Ignore:
Timestamp:
08/13/2014 09:16:12 AM (12 years ago)
Author:
mra13
Message:

committing v1.2

File:
1 edited

Legend:

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

    r957989 r965010  
    55Description: The plugin HTTPS Redirection allows an automatic redirection to the "HTTPS" version/URL of the site.
    66Author: Tips and Tricks HQ
    7 Version: 1.1
     7Version: 1.2
    88Author URI: http://www.tipsandtricks-hq.com/
    99License: GPLv2 or later
     
    3535if ( ! function_exists ( 'httpsrdrctn_plugin_init' ) ) {
    3636    function httpsrdrctn_plugin_init() {
     37        global $httpsrdrctn_options;
    3738        /* Internationalization, first(!) */
    3839        load_plugin_textdomain( 'https_redirection', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
     40        if( empty( $httpsrdrctn_options ) ){
     41            $httpsrdrctn_options = get_option( 'httpsrdrctn_options' );
     42        }
     43        if( isset($httpsrdrctn_options['force_resources']) && $httpsrdrctn_options['force_resources'] == '1' ){
     44                        //Handle the appropriate content filters to force the static resources to use HTTPS URL
     45            add_filter( 'the_content', 'httpsrdrctn_the_content' );
     46            add_filter( 'get_the_content', 'httpsrdrctn_the_content' );
     47            add_filter( 'the_excerpt', 'httpsrdrctn_the_content' );
     48            add_filter( 'get_the_excerpt', 'httpsrdrctn_the_content' );
     49        }
    3950    }
    4051}
     
    7990            'https_domain'  => 0,
    8091            'https_pages_array' => array(),
     92            'force_resources' => 0,
    8193            'plugin_option_version' => $httpsrdrctn_plugin_info["Version"]
    8294        );
     
    142154            $httpsrdrctn_options['https'] = isset( $_REQUEST['httpsrdrctn_https'] ) ? $_REQUEST['httpsrdrctn_https'] : 0 ;
    143155            $httpsrdrctn_options['https_domain'] = isset( $_REQUEST['httpsrdrctn_https_domain'] ) ? $_REQUEST['httpsrdrctn_https_domain'] : 0 ;
     156            $httpsrdrctn_options['force_resources'] = isset( $_REQUEST['httpsrdrctn_force_resources'] ) ? $_REQUEST['httpsrdrctn_force_resources'] : 0 ;
    144157           
    145158            if( isset( $_REQUEST['httpsrdrctn_https_pages_array'] ) ){
     
    187200                        <td>
    188201                            <label><input type="checkbox" name="httpsrdrctn_https" value="1" <?php if ( '1' == $httpsrdrctn_options['https'] ) echo "checked=\"checked\" "; ?>/></label><br />
     202                                                        <p class="description">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.</p>
     203                                                       
     204                                                        <br />
     205                                                        <p>You can apply a force HTTPS redirection on your entire domain or just a few pages.</p>
    189206                            <label <?php if( '0' == $httpsrdrctn_options['https'] ) echo 'class="hidden"'; ?>><input type="radio" name="httpsrdrctn_https_domain" value="1" <?php if ( '1' == $httpsrdrctn_options['https_domain'] ) echo "checked=\"checked\" "; ?>/> The whole domain</label><br />
    190207                            <label <?php if( '0' == $httpsrdrctn_options['https'] ) echo 'class="hidden"'; ?>><input type="radio" name="httpsrdrctn_https_domain" value="0" <?php if ( '0' == $httpsrdrctn_options['https_domain'] ) echo "checked=\"checked\" "; ?>/> A few pages</label><br />
     
    196213                            <span class="rewrite_new_item <?php if( '1' == $httpsrdrctn_options['https_domain'] || '0' == $httpsrdrctn_options['https'] ) echo 'hidden'; ?>" >
    197214                                <?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 />
    198                             </span>
     215                            </span>                                                       
     216                        </td>
     217                    </tr>
     218                    <tr valign="top">
     219                        <th scope="row"><?php _e( 'Force resources to use HTTPS URL', 'https_redirection' ); ?></th>
     220                        <td>
     221                            <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 />
     222                                                        <p class="description">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.</p>
    199223                        </td>
    200224                    </tr>
     
    352376}
    353377
     378if ( ! function_exists ( 'httpsrdrctn_the_content' ) ) {
     379    function httpsrdrctn_the_content( $content ) {
     380        global $httpsrdrctn_options;
     381        if( empty( $httpsrdrctn_options ) ){
     382            $httpsrdrctn_options = get_option( 'httpsrdrctn_options' );
     383        }
     384        if( $httpsrdrctn_options['force_resources'] == '1' && $httpsrdrctn_options['https'] == 1 ){
     385            if( $httpsrdrctn_options['https_domain'] == 1 ){
     386                if( strpos( home_url(), 'https' ) !== false ){
     387                    $http_domain = str_replace( 'https', 'http', home_url() );
     388                    $https_domain = home_url();
     389                }
     390                else{
     391                    $http_domain = home_url();
     392                    $https_domain = str_replace( 'http', 'https', home_url() );
     393                }
     394                $content = str_replace( $http_domain, $https_domain, $content );
     395            }
     396            else if( ! empty( $httpsrdrctn_options['https_pages_array'] ) ) {
     397                foreach( $httpsrdrctn_options['https_pages_array'] as $https_page ) {
     398                    if( strpos( home_url(), 'https' ) !== false ){
     399                        $http_domain = str_replace( 'https', 'http', home_url() );
     400                        $https_domain = home_url();
     401                    }
     402                    else{
     403                        $http_domain = home_url();
     404                        $https_domain = str_replace( 'http', 'https', home_url() );
     405                    }
     406                    $content = str_replace( $http_domain . '/' . $https_page, $https_domain . '/' . $https_page, $content );
     407                }
     408            }
     409        }
     410        return $content;
     411    }
     412}
     413
    354414if ( ! function_exists ( 'httpsrdrctn_admin_head' ) ) {
    355415    function httpsrdrctn_admin_head() {
Note: See TracChangeset for help on using the changeset viewer.