- $api = DI::pConfig()->get(local_user(), 'statusnet', 'baseapi');
- $ckey = DI::pConfig()->get(local_user(), 'statusnet', 'consumerkey');
- $csecret = DI::pConfig()->get(local_user(), 'statusnet', 'consumersecret');
- $otoken = DI::pConfig()->get(local_user(), 'statusnet', 'oauthtoken');
- $osecret = DI::pConfig()->get(local_user(), 'statusnet', 'oauthsecret');
- $enabled = DI::pConfig()->get(local_user(), 'statusnet', 'post');
- $checked = (($enabled) ? ' checked="checked" ' : '');
- $defenabled = DI::pConfig()->get(local_user(), 'statusnet', 'post_by_default');
- $defchecked = (($defenabled) ? ' checked="checked" ' : '');
- $mirrorenabled = DI::pConfig()->get(local_user(), 'statusnet', 'mirror_posts');
- $mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : '');
- $import = DI::pConfig()->get(local_user(), 'statusnet', 'import');
- $importselected = ["", "", ""];
- $importselected[$import] = ' selected="selected"';
- //$importenabled = DI::pConfig()->get(local_user(),'statusnet','import');
- //$importchecked = (($importenabled) ? ' checked="checked" ' : '');
- $create_userenabled = DI::pConfig()->get(local_user(), 'statusnet', 'create_user');
- $create_userchecked = (($create_userenabled) ? ' checked="checked" ' : '');
-
- $css = (($enabled) ? '' : '-disabled');
-
- $s .= '<span id="settings_statusnet_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_statusnet_expanded\'); openClose(\'settings_statusnet_inflated\');">';
- $s .= '<img class="connector' . $css . '" src="images/gnusocial.png" /><h3 class="connector">' . DI::l10n()->t('GNU Social Import/Export/Mirror') . '</h3>';
- $s .= '</span>';
- $s .= '<div id="settings_statusnet_expanded" class="settings-block" style="display: none;">';
- $s .= '<span class="fakelink" onclick="openClose(\'settings_statusnet_expanded\'); openClose(\'settings_statusnet_inflated\');">';
- $s .= '<img class="connector' . $css . '" src="images/gnusocial.png" /><h3 class="connector">' . DI::l10n()->t('GNU Social Import/Export/Mirror') . '</h3>';
- $s .= '</span>';
-
- if ((!$ckey) && (!$csecret)) {
- /* * *
- * no consumer keys
- */
- $globalsn = DI::config()->get('statusnet', 'sites');
- /* * *
- * lets check if we have one or more globally configured GNU Social
- * server OAuth credentials in the configuration. If so offer them
- * with a little explanation to the user as choice - otherwise
- * ignore this option entirely.
- */
- if (!$globalsn == null) {
- $s .= '<h4>' . DI::l10n()->t('Globally Available GNU Social OAuthKeys') . '</h4>';
- $s .= '<p>' . DI::l10n()->t("There are preconfigured OAuth key pairs for some GNU Social servers available. If you are using one of them, please use these credentials. If not feel free to connect to any other GNU Social instance \x28see below\x29.") . '</p>';
- $s .= '<div id="statusnet-preconf-wrapper">';
- foreach ($globalsn as $asn) {
- $s .= '<input type="radio" name="statusnet-preconf-apiurl" value="' . $asn['apiurl'] . '">' . $asn['sitename'] . '<br />';
- }
- $s .= '<p></p><div class="clear"></div></div>';
- $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="statusnet-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
- }
- $s .= '<h4>' . DI::l10n()->t('Provide your own OAuth Credentials') . '</h4>';
- $s .= '<p>' . DI::l10n()->t('No consumer key pair for GNU Social found. Register your Friendica Account as an desktop client on your GNU Social account, copy the consumer key pair here and enter the API base root.<br />Before you register your own OAuth key pair ask the administrator if there is already a key pair for this Friendica installation at your favorited GNU Social installation.') . '</p>';
- $s .= '<div id="statusnet-consumer-wrapper">';
- $s .= '<label id="statusnet-consumerkey-label" for="statusnet-consumerkey">' . DI::l10n()->t('OAuth Consumer Key') . '</label>';
- $s .= '<input id="statusnet-consumerkey" type="text" name="statusnet-consumerkey" size="35" /><br />';
- $s .= '<div class="clear"></div>';
- $s .= '<label id="statusnet-consumersecret-label" for="statusnet-consumersecret">' . DI::l10n()->t('OAuth Consumer Secret') . '</label>';
- $s .= '<input id="statusnet-consumersecret" type="text" name="statusnet-consumersecret" size="35" /><br />';
- $s .= '<div class="clear"></div>';
- $s .= '<label id="statusnet-baseapi-label" for="statusnet-baseapi">' . DI::l10n()->t("Base API Path \x28remember the trailing /\x29") . '</label>';
- $s .= '<input id="statusnet-baseapi" type="text" name="statusnet-baseapi" size="35" /><br />';
- $s .= '<div class="clear"></div>';
- //$s .= '<label id="statusnet-applicationname-label" for="statusnet-applicationname">'.DI::l10n()->t('GNU Socialapplication name').'</label>';
- //$s .= '<input id="statusnet-applicationname" type="text" name="statusnet-applicationname" size="35" /><br />';
- $s .= '<p></p><div class="clear"></div>';
- $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="statusnet-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
- $s .= '</div>';
- } else {
- /* * *
- * ok we have a consumer key pair now look into the OAuth stuff
- */
- if ((!$otoken) && (!$osecret)) {
- /* * *
- * the user has not yet connected the account to GNU Social
- * get a temporary OAuth key/secret pair and display a button with
- * which the user can request a PIN to connect the account to a
- * account at GNU Social
- */
- $connection = new StatusNetOAuth($api, $ckey, $csecret);
- $request_token = $connection->getRequestToken('oob');
- $token = $request_token['oauth_token'];
- /* * *
- * make some nice form
- */
- $s .= '<p>' . DI::l10n()->t('To connect to your GNU Social account click the button below to get a security code from GNU Social which you have to copy into the input box below and submit the form. Only your <strong>public</strong> posts will be posted to GNU Social.') . '</p>';
- $s .= '<a href="' . $connection->getAuthorizeURL($token, False) . '" target="_statusnet"><img src="addon/statusnet/signinwithstatusnet.png" alt="' . DI::l10n()->t('Log in with GNU Social') . '"></a>';
- $s .= '<div id="statusnet-pin-wrapper">';
- $s .= '<label id="statusnet-pin-label" for="statusnet-pin">' . DI::l10n()->t('Copy the security code from GNU Social here') . '</label>';
- $s .= '<input id="statusnet-pin" type="text" name="statusnet-pin" />';
- $s .= '<input id="statusnet-token" type="hidden" name="statusnet-token" value="' . $token . '" />';
- $s .= '<input id="statusnet-token2" type="hidden" name="statusnet-token2" value="' . $request_token['oauth_token_secret'] . '" />';
- $s .= '</div><div class="clear"></div>';
- $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="statusnet-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
- $s .= '<h4>' . DI::l10n()->t('Cancel Connection Process') . '</h4>';
- $s .= '<div id="statusnet-cancel-wrapper">';
- $s .= '<p>' . DI::l10n()->t('Current GNU Social API is') . ': ' . $api . '</p>';
- $s .= '<label id="statusnet-cancel-label" for="statusnet-cancel">' . DI::l10n()->t('Cancel GNU Social Connection') . '</label>';
- $s .= '<input id="statusnet-cancel" type="checkbox" name="statusnet-disconnect" value="1" />';
- $s .= '</div><div class="clear"></div>';
- $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="statusnet-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
- } else {
+ $baseapi = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'baseapi');
+ $ckey = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'consumerkey');
+ $csecret = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'consumersecret');
+ $otoken = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'oauthtoken');
+ $osecret = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'oauthsecret');
+ $enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'post', false);
+ $def_enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'post_by_default', false);
+ $mirror_enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'mirror_posts', false);
+ $createuser_enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'create_user', false);
+ $import = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'import');
+
+ // Radio button list to select existing application credentials
+ $sites = array_map(function ($site) {
+ return ['statusnet-preconf-apiurl', $site['sitename'], $site['apiurl']];
+ }, DI::config()->get('statusnet', 'sites', []));
+
+ $submit = ['statusnet-submit' => DI::l10n()->t('Save Settings')];
+
+ if ($ckey && $csecret) {
+ if ($otoken && $osecret) {