From bc3eba713ae5218f9c9e1e442453bcda1b6ef5a9 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Tue, 17 May 2011 07:20:26 +0200 Subject: made the connection process to SN more robust --- addon/statusnet/statusnet.php | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'addon/statusnet/statusnet.php') 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 -- cgit v1.2.3 From 85dc0826b6917d9809f9a7adeb3e0d015832ee91 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Tue, 17 May 2011 07:27:06 +0200 Subject: fixed a comment... --- addon/statusnet/statusnet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addon/statusnet/statusnet.php') diff --git a/addon/statusnet/statusnet.php b/addon/statusnet/statusnet.php index d1c6fd091..5ed92d13a 100644 --- a/addon/statusnet/statusnet.php +++ b/addon/statusnet/statusnet.php @@ -100,7 +100,7 @@ function statusnet_settings_post ($a,$post) { if (isset($_POST['statusnet-consumersecret'])) { // 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 + // resign quickly after this one try to fix the path ;-) $apibase = $_POST['statusnet-baseapi']; $f = fopen( $apibase . 'statusnet/version.xml', 'r'); $c = stream_get_contents($f); -- cgit v1.2.3 From a0a59e0518459076079e904cd257dd9608b9bd37 Mon Sep 17 00:00:00 2001 From: Friendika Date: Tue, 17 May 2011 18:25:18 -0700 Subject: statusnet post by default --- addon/statusnet/statusnet.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'addon/statusnet/statusnet.php') diff --git a/addon/statusnet/statusnet.php b/addon/statusnet/statusnet.php index 5ed92d13a..ad992f979 100644 --- a/addon/statusnet/statusnet.php +++ b/addon/statusnet/statusnet.php @@ -90,10 +90,11 @@ function statusnet_settings_post ($a,$post) { * if the statusnet-disconnect checkbox is set, clear the statusnet configuration * TODO can we revoke the access tokens at Twitter and do we need to do so? */ - del_pconfig( local_user(), 'statusnet', 'consumerkey' ); - del_pconfig( local_user(), 'statusnet', 'consumersecret' ); - del_pconfig( local_user(), 'statusnet', 'post' ); - del_pconfig( local_user(), 'statusnet', 'oauthtoken' ); + del_pconfig( local_user(), 'statusnet', 'consumerkey' ); + del_pconfig( local_user(), 'statusnet', 'consumersecret' ); + del_pconfig( local_user(), 'statusnet', 'post' ); + del_pconfig( local_user(), 'statusnet', 'post_by_default' ); + del_pconfig( local_user(), 'statusnet', 'oauthtoken' ); del_pconfig( local_user(), 'statusnet', 'oauthsecret' ); del_pconfig( local_user(), 'statusnet', 'baseapi' ); } else { @@ -149,6 +150,8 @@ function statusnet_settings_post ($a,$post) { // if no PIN is supplied in the POST variables, the user has changed the setting // to post a tweet for every new __public__ posting to the wall set_pconfig(local_user(),'statusnet','post',intval($_POST['statusnet-enable'])); + set_pconfig(local_user(),'statusnet','post_by_default',intval($_POST['statusnet-default'])); + notice( t('StatusNet settings updated.') . EOL); }}} } function statusnet_settings(&$a,&$s) { @@ -166,8 +169,10 @@ function statusnet_settings(&$a,&$s) { $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret' ); $otoken = get_pconfig(local_user(), 'statusnet', 'oauthtoken' ); $osecret = get_pconfig(local_user(), 'statusnet', 'oauthsecret' ); - $enabled = get_pconfig(local_user(), 'statusnet', 'post'); + $enabled = get_pconfig(local_user(), 'statusnet', 'post'); $checked = (($enabled) ? ' checked="checked" ' : ''); + $defenabled = get_pconfig(local_user(),'statusnet','post_by_default'); + $defchecked = (($defenabled) ? ' checked="checked" ' : ''); $s .= '
'; $s .= '

'. t('StatusNet Posting Settings').'

'; @@ -228,11 +233,15 @@ function statusnet_settings(&$a,&$s) { $connection = new StatusNetOAuth($api,$ckey,$csecret,$otoken,$osecret); $details = $connection->get('account/verify_credentials'); $s .= '

'. t('Currently connected to: ') .''.$details->screen_name.'
'.$details->description.'

'; - $s .= '

'. t('If enabled all your public postings will be posted to the associated StatusNet account as well.') .'

'; + $s .= '

'. t('If enabled all your public postings will be posted to the associated StatusNet account.') .'

'; $s .= '
'; - $s .= ''; + $s .= ''; $s .= ''; + $s .= '
'; + $s .= ''; + $s .= ''; $s .= '
'; + $s .= '
'; $s .= ''; $s .= ''; -- cgit v1.2.3 From 1fcf8ff5deaf1b175c41e4b6ef3d8a396a6de8dd Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 20 May 2011 07:08:20 -0700 Subject: replace fopen with fetch_url in statusnet plugin, many sites do not have fopen_url allowed. --- addon/statusnet/statusnet.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'addon/statusnet/statusnet.php') diff --git a/addon/statusnet/statusnet.php b/addon/statusnet/statusnet.php index ad992f979..358291d29 100644 --- a/addon/statusnet/statusnet.php +++ b/addon/statusnet/statusnet.php @@ -103,9 +103,7 @@ function statusnet_settings_post ($a,$post) { // we'll check the API Version for that, if we don't get one we'll try to fix the path but will // resign quickly after this one try to fix the path ;-) $apibase = $_POST['statusnet-baseapi']; - $f = fopen( $apibase . 'statusnet/version.xml', 'r'); - $c = stream_get_contents($f); - fclose($f); + $c = fetch_url( $apibase . 'statusnet/version.xml' ); if (strlen($c) > 0) { // ok the API path is correct, let's save the settings set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); @@ -114,9 +112,7 @@ function statusnet_settings_post ($a,$post) { } 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); + $c = fetch_url( $apibase . 'statusnet/version.xml' ); 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']); -- cgit v1.2.3 From 5f20925220574323e8d32483e57ef9ebbf0b3256 Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 20 May 2011 15:11:36 -0700 Subject: deny link not clickable on admin approval notification page --- addon/statusnet/statusnet.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addon/statusnet/statusnet.php') diff --git a/addon/statusnet/statusnet.php b/addon/statusnet/statusnet.php index 358291d29..1d12292c8 100644 --- a/addon/statusnet/statusnet.php +++ b/addon/statusnet/statusnet.php @@ -123,7 +123,7 @@ function statusnet_settings_post ($a,$post) { notice( t('We could not contact the StatusNet API with the Path you entered.').EOL ); } } - header('Location: '.$a->get_baseurl().'/settings/addon'); + goaway($a->get_baseurl().'/settings/addon'); } else { if (isset($_POST['statusnet-pin'])) { // if the user supplied us with a PIN from Twitter, let the magic of OAuth happen @@ -141,7 +141,7 @@ function statusnet_settings_post ($a,$post) { set_pconfig(local_user(),'statusnet', 'oauthsecret', $token['oauth_token_secret']); set_pconfig(local_user(),'statusnet', 'post', 1); // reload the Addon Settings page, if we don't do it see Bug #42 - header('Location: '.$a->get_baseurl().'/settings/addon'); + goaway($a->get_baseurl().'/settings/addon'); } else { // if no PIN is supplied in the POST variables, the user has changed the setting // to post a tweet for every new __public__ posting to the wall -- cgit v1.2.3