Created
April 2, 2014 07:31
-
-
Save alfasado/9929503 to your computer and use it in GitHub Desktop.
mt/plugins/HttpHttpsTransfer/php/config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class HttpHttpsTransfer extends MTPlugin { | |
var $registry = array( | |
'config_settings' => array( | |
'HttpHttpsTransferPathBegin' => array( 'default' => '/entry_form/' ), | |
), | |
'callbacks' => array( | |
'post_init' => 'post_init', | |
), | |
); | |
function post_init ( $mt, &$ctx, &$args ) { | |
$app = $ctx->stash( 'bootstrapper' ); | |
$path = preg_quote( $app->config( 'HttpHttpsTransferPathBegin' ), '/' ); | |
$url = $app->stash( 'url' ); | |
$request = $app->stash( 'request' ); | |
if ( ( $_SERVER['HTTPS'] === NULL ) || ( $_SERVER[ 'HTTPS' ] == 'off' ) ) { | |
if ( preg_match( "!^$path!", $request ) ) { | |
$url = preg_replace( '!^http:!', 'https:', $url ); | |
$this->app->moved_permanently( $url ); | |
exit(); | |
} | |
} else { | |
if (! preg_match( "!^$path!", $request ) ) { | |
$url = preg_replace( '!^https:!', 'http:', $url ); | |
$this->app->moved_permanently( $url ); | |
exit(); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment