Skip to content

Instantly share code, notes, and snippets.

@alfasado
Created April 2, 2014 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfasado/9929503 to your computer and use it in GitHub Desktop.
Save alfasado/9929503 to your computer and use it in GitHub Desktop.
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