diff --git a/SourceGithub/SourceGithub.php b/SourceGithub/SourceGithub.php old mode 100644 new mode 100755 index 98974a0..7dfb46b --- a/SourceGithub/SourceGithub.php +++ b/SourceGithub/SourceGithub.php @@ -397,18 +397,10 @@ $t_post_data = array( 'client_id' => $p_repo->info['hub_app_client_id'], 'client_secret' => $p_repo->info['hub_app_secret'], 'code' => $p_code ); - $t_data = url_post( $t_url, $t_post_data ); + $t_data = self::url_post( $t_url, $t_post_data ); $t_access_token = ''; if ( !empty( $t_data ) ) { - /* - $t_reader = new XMLReader; - if ( $t_reader->xml( $t_data ) === true ) { - if ( $t_reader->moveToAttribute( 'access_token' ) === true ) { - $t_access_token = $t_reader->readString(); - } - } - */ $t_response = array(); parse_str( $t_data, $t_response ); if ( isset( $t_response['access_token'] ) === true ) { @@ -426,5 +418,29 @@ return false; } } - -} + + public static function url_post( $p_url, $p_post_data ) { + $t_post_data = http_build_query( $p_post_data ); + error_log( 't_post_data = ' . $t_post_data ); + + # Use the PHP cURL extension + if( function_exists( 'curl_init' ) ) { + $t_curl = curl_init( $p_url ); + curl_setopt( $t_curl, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $t_curl, CURLOPT_POST, true ); + curl_setopt( $t_curl, CURLOPT_POSTFIELDS, $t_post_data ); + + $t_data = curl_exec( $t_curl ); + error_log( 't_data = ' . $t_data ); + curl_close( $t_curl ); + + return $t_data; + } else { + # Last resort system call + $t_url = escapeshellarg( $p_url ); + $t_post_data = escapeshellarg( $t_post_data ); + return shell_exec( 'curl ' . $t_url . ' -d ' . $t_post_data ); + } + } + +} \ No newline at end of file diff --git a/SourceGithub/lang/strings_english.txt b/SourceGithub/lang/strings_english.txt index dbaba36..36d1dd3 100644 --- a/SourceGithub/lang/strings_english.txt +++ b/SourceGithub/lang/strings_english.txt @@ -17,4 +17,10 @@ $s_plugin_SourceGithub_hub_app_client_id_secret_missing = 'N/A
You must enter the GitHub Application Client ID & Secret and update before you can authorize'; $s_plugin_SourceGithub_hub_app_authorize = 'Click to Authorize'; -$s_plugin_SourceGithub_hub_app_authorized = 'Authorized'; \ No newline at end of file +$s_plugin_SourceGithub_hub_app_authorized = 'Authorized'; + +$s_plugin_SourceGithub_repo_authorized = '

MantisBT is now authorized to access this GitHub repository.

'; +$s_plugin_SourceGithub_repo_authorization_failed = '

Sorry, MantisBT could not be authorized to access this GitHub repository.

'; + +$s_plugin_SourceGithub_oauth_authorization = 'GitHub OAuth Authorization'; +$s_plugin_SourceGithub_back_repo = 'Back to Repository'; diff --git a/SourceGithub/pages/oauth_authorize.php b/SourceGithub/pages/oauth_authorize.php index 906e37c..659e464 100644 --- a/SourceGithub/pages/oauth_authorize.php +++ b/SourceGithub/pages/oauth_authorize.php @@ -14,11 +14,26 @@ $t_repo = SourceRepo::load( $f_repo_id ); if ( SourceGithubPlugin::oauth_get_access_token( $t_repo, $f_code ) === true ) { - echo '

Your app is now authorized with GitHub.

'; + $t_was_authorized = true; } else { - echo '

Sorry, your app could not be authorized with GitHub.

'; + $t_was_authorized = false; } +?> + + + + + + + + + + + +
id, plugin_lang_get( 'back_repo' ) ) ?>
+ + \ No newline at end of file