Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mt/plugins/HttpHttpsTransfer/php/config.php
<?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
You can’t perform that action at this time.