From bc3eba713ae5218f9c9e1e442453bcda1b6ef5a9 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Tue, 17 May 2011 07:20:26 +0200 Subject: [PATCH] made the connection process to SN more robust --- addon/statusnet/statusnet.php | 39 ++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/addon/statusnet/statusnet.php b/addon/statusnet/statusnet.php index f763cd0c3..d1c6fd091 100644 --- a/addon/statusnet/statusnet.php +++ b/addon/statusnet/statusnet.php @@ -98,9 +98,34 @@ function statusnet_settings_post ($a,$post) { del_pconfig( local_user(), 'statusnet', 'baseapi' ); } else { if (isset($_POST['statusnet-consumersecret'])) { - set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); - set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); - set_pconfig(local_user(), 'statusnet', 'baseapi', $_POST['statusnet-baseapi']); + // check if we can reach the API of the StatusNet server + // we'll check the API Version for that, if we don't get one we'll try to fix the path but will + // resign + $apibase = $_POST['statusnet-baseapi']; + $f = fopen( $apibase . 'statusnet/version.xml', 'r'); + $c = stream_get_contents($f); + fclose($f); + if (strlen($c) > 0) { + // ok the API path is correct, let's save the settings + set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); + set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); + set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase ); + } else { + // the API path is not correct, maybe missing trailing / ? + $apibase = $apibase . '/'; + $f = fopen( $apibase . 'statusnet/version.xml', 'r'); + $c = stream_get_contents($f); + fclose($f); + if (strlen($c) > 0) { + // ok the API path is now correct, let's save the settings + set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); + set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); + set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase ); + } else { + // still not the correct API base, let's do noting + notice( t('We could not contact the StatusNet API with the Path you entered.').EOL ); + } + } header('Location: '.$a->get_baseurl().'/settings/addon'); } else { if (isset($_POST['statusnet-pin'])) { @@ -133,6 +158,7 @@ function statusnet_settings(&$a,&$s) { /*** * 1) Check that we have a base api url and a consumer key & secret * 2) If no OAuthtoken & stuff is present, generate button to get some + * allow the user to cancel the connection process at this step * 3) Checkbox for "Send public notices (respect size limitation) */ $api = get_pconfig(local_user(), 'statusnet', 'baseapi'); @@ -187,6 +213,13 @@ function statusnet_settings(&$a,&$s) { $s .= ''; $s .= '
'; $s .= '
'; + $s .= '

'.t('Cancel Connection Process').'

'; + $s .= '
'; + $s .= '

'.t('Current StatusNet API is').': '.$api.'

'; + $s .= ''; + $s .= ''; + $s .= '
'; + $s .= '
'; } else { /*** * we have an OAuth key / secret pair for the user