';
- $s .= '';
+ $t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/ifttt/');
+ $html = Renderer::replaceMacros($t, [
+ '$l10n' => [
+ 'intro' => DI::l10n()->t('Create an account at IFTTT. Create three Facebook recipes that are connected with Maker (In the form "if Facebook then Maker") with the following parameters:'),
+ 'url' => DI::l10n()->t('URL'),
+ 'method' => DI::l10n()->t('Method'),
+ 'content_type' => DI::l10n()->t('Content Type'),
+ 'new_status_message_body' => DI::l10n()->t('Body for "new status message"'),
+ 'new_photo_upload_body' => DI::l10n()->t('Body for "new photo upload"'),
+ 'new_link_post_body' => DI::l10n()->t('Body for "new link post"'),
+ ],
+ '$url' => DI::baseUrl()->get() . '/ifttt/' . $a->getLoggedInUserNickname(),
+ '$new_status_message_body' => 'key=' . $key . '&type=status&msg=<<<{{Message}}>>>&date=<<<{{UpdatedAt}}>>>&url=<<<{{PageUrl}}>>>',
+ '$new_photo_upload_body' => 'key=' . $key . '&type=photo&link=<<<{{Link}}>>>&image=<<<{{ImageSource}}>>>&msg=<<<{{Caption}}>>>&date=<<<{{CreatedAt}}>>>&url=<<<{{PageUrl}}>>>',
+ '$new_link_post_body' => 'key=' . $key . '&type=link&link=<<<{{Link}}>>>&title=<<<{{Title}}>>>&msg=<<<{{Message}}>>>&description=<<<{{Description}}>>>&date=<<<{{CreatedAt}}>>>&url=<<<{{PageUrl}}>>>',
+ ]);
- $s .= '
';
- $s .= '
' . DI::l10n()->t('Create an account at IFTTT. Create three Facebook recipes that are connected with Maker (In the form "if Facebook then Maker") with the following parameters:') . '
+{{/if}}
diff --git a/statusnet/statusnet.css b/statusnet/statusnet.css
index f50d9c05..21f4733f 100644
--- a/statusnet/statusnet.css
+++ b/statusnet/statusnet.css
@@ -10,62 +10,3 @@
height: 52px;
vertical-align: middle;
}
-#statusnet-disconnect-label {
- float: left;
- width: 250px;
- margin-bottom: 25px;
-}
-#statusnet-disconnect {
- float: left;
-}
-
-#statusnet-default-label,
-#statusnet-applicationname-label,
-#statusnet-sendtaglinks-label,
-#statusnet-shortening-label,
-#statusnet-mirror-label,
-#statusnet-import-label,
-#statusnet-create_user-label,
-#statusnet-pin-label,
-#statusnet-enable-label {
- float: left;
- width: 250px;
- margin-bottom: 5px;
-}
-
-#statusnet-checkbox {
- float: left;
-}
-
-#statusnet-pin {
- float: left;
-}
-
-
-#statusnet-consumerkey-label {
- float: left;
- width: 250px;
- margin-bottom: 8px;
-}
-#statusnet-consumerkey {
- float: left;
- margin-bottom: 8px;
-}
-#statusnet-consumersecret-label {
- float: left;
- width: 250px;
- margin-bottom: 8px;
-}
-#statusnet-consumersecret {
- float: left;
- margin-bottom: 8px;
-}
-#statusnet-baseapi-label {
- float: left;
- width: 250px;
- margin-bottom: 25px;
-}
-#statusnet-baseapi {
- float: left;
- margin-bottom: 8px;
-}
diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php
index 75e44151..b2582b86 100644
--- a/statusnet/statusnet.php
+++ b/statusnet/statusnet.php
@@ -107,13 +107,13 @@ function statusnet_settings_post(App $a, $post)
return;
}
// don't check GNU Social settings if GNU Social submit button is not clicked
- if (empty($_POST['statusnet-submit'])) {
+ if (empty($_POST['statusnet-submit']) && empty($_POST['statusnet-disconnect'])) {
return;
}
- if (isset($_POST['statusnet-disconnect'])) {
+ if (!empty($_POST['statusnet-disconnect'])) {
/* * *
- * if the GNU Social-disconnect checkbox is set, clear the GNU Social configuration
+ * if the GNU Social-disconnect button is clicked, clear the GNU Social configuration
*/
DI::pConfig()->delete(local_user(), 'statusnet', 'consumerkey');
DI::pConfig()->delete(local_user(), 'statusnet', 'consumersecret');
@@ -149,7 +149,6 @@ function statusnet_settings_post(App $a, $post)
}
}
}
- DI::baseUrl()->redirect('settings/connectors');
} else {
if (isset($_POST['statusnet-consumersecret'])) {
// check if we can reach the API of the GNU Social server
@@ -177,7 +176,6 @@ function statusnet_settings_post(App $a, $post)
notice(DI::l10n()->t('We could not contact the GNU Social API with the Path you entered.') . EOL);
}
}
- DI::baseUrl()->redirect('settings/connectors');
} else {
if (isset($_POST['statusnet-pin'])) {
// if the user supplied us with a PIN from GNU Social, let the magic of OAuth happen
@@ -195,7 +193,6 @@ function statusnet_settings_post(App $a, $post)
DI::pConfig()->set(local_user(), 'statusnet', 'post', 1);
DI::pConfig()->set(local_user(), 'statusnet', 'post_taglinks', 1);
// reload the Addon Settings page, if we don't do it see Bug #42
- DI::baseUrl()->redirect('settings/connectors');
} else {
// if no PIN is supplied in the POST variables, the user has changed the setting
// to post a dent for every new __public__ posting to the wall
@@ -213,171 +210,125 @@ function statusnet_settings_post(App $a, $post)
}
}
-function statusnet_settings(App $a, &$s)
+function statusnet_settings(App $a, array &$data)
{
if (!local_user()) {
return;
}
- $user = User::getById(local_user());
+ DI::page()->registerStylesheet(__DIR__ . '/statusnet.css', 'all');
- DI::page()['htmlhead'] .= '' . "\r\n";
/* * *
* 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 = 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" ' : '');
+ $baseapi = 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', false);
+ $def_enabled = DI::pConfig()->get(local_user(), 'statusnet', 'post_by_default', false);
+ $mirror_enabled = DI::pConfig()->get(local_user(), 'statusnet', 'mirror_posts', false);
+ $createuser_enabled = DI::pConfig()->get(local_user(), 'statusnet', 'create_user', false);
+ $import = DI::pConfig()->get(local_user(), 'statusnet', 'import');
- $css = (($enabled) ? '' : '-disabled');
+ // 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', []));
- $s .= '';
- $s .= '
' . DI::l10n()->t('GNU Social Import/Export/Mirror') . '
';
- $s .= '';
- $s .= '
';
- $s .= '';
- $s .= '
' . DI::l10n()->t('GNU Social Import/Export/Mirror') . '
';
- $s .= '';
+ $submit = ['statusnet-submit' => DI::l10n()->t('Save Settings')];
- 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 .= '
' . DI::l10n()->t('Globally Available GNU Social OAuthKeys') . '
';
- $s .= '
' . 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.") . '
';
- $s .= '
';
- foreach ($globalsn as $asn) {
- $s .= '' . $asn['sitename'] . ' ';
+ if ($ckey && $csecret) {
+ if ($otoken && $osecret) {
+ /* * *
+ * we have an OAuth key / secret pair for the user
+ * so let's give a chance to disable the postings to GNU Social
+ */
+ $connection = new StatusNetOAuth($baseapi, $ckey, $csecret, $otoken, $osecret);
+ $account = $connection->get('account/verify_credentials');
+
+ if (!empty($account)) {
+ $connected_account = DI::l10n()->t('Currently connected to: %s', $account->statusnet_profile_url, $account->screen_name);
}
- $s .= '
';
- $s .= '';
- }
- $s .= '
' . DI::l10n()->t('Provide your own OAuth Credentials') . '
';
- $s .= '
' . 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. 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.') . '
';
- } else {
- /* * *
- * ok we have a consumer key pair now look into the OAuth stuff
- */
- if ((!$otoken) && (!$osecret)) {
+
+ $user = User::getById(local_user());
+ if ($user['hidewall']) {
+ $privacy_warning = DI::l10n()->t('Note: Due your privacy settings (Hide your profile details from unknown viewers?) the link potentially included in public postings relayed to GNU Social will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.');
+ }
+
+ $submit['statusnet-disconnect'] = DI::l10n()->t('Clear OAuth configuration');
+ } else {
/* * *
* 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);
+ $connection = new StatusNetOAuth($baseapi, $ckey, $csecret);
$request_token = $connection->getRequestToken('oob');
- $token = $request_token['oauth_token'];
- /* * *
- * make some nice form
- */
- $s .= '
' . 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 public posts will be posted to GNU Social.') . '
' . DI::l10n()->t('Current GNU Social API is') . ': ' . $api . '
';
- $s .= '';
- $s .= '';
- $s .= '
';
- $s .= '';
- } else {
- /* * *
- * we have an OAuth key / secret pair for the user
- * so let's give a chance to disable the postings to GNU Social
- */
- $connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret);
- $details = $connection->get('account/verify_credentials');
- if (!empty($details)) {
- $s .= '
' . DI::l10n()->t('If enabled all your public postings can be posted to the associated GNU Social account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.') . '
';
- if ($user['hidewall']) {
- $s .= '
' . DI::l10n()->t('Note: Due your privacy settings (Hide your profile details from unknown viewers?) the link potentially included in public postings relayed to GNU Social will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.') . '
';
- $s .= '';
+ $submit['statusnet-disconnect'] = DI::l10n()->t('Cancel GNU Social Connection');
}
}
- $s .= '
';
+
+
+ $t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/statusnet/');
+ $html = Renderer::replaceMacros($t, [
+ '$l10n' => [
+ 'global_title' => DI::l10n()->t('Globally Available GNU Social OAuthKeys'),
+ 'global_info' => DI::l10n()->t(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 (see below).')),
+ 'credentials_title' => DI::l10n()->t('Provide your own OAuth Credentials'),
+ 'credentials_info' => DI::l10n()->t('No consumer key pair for GNU Social found. Register your Friendica Account as a desktop application on your GNU Social account, copy the consumer key pair here and enter the API base root. Before you register your own OAuth key pair ask the administrator if there is already a key pair for this Friendica installation at your favorite GNU Social installation.'),
+ 'oauth_info' => 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 public posts will be posted to GNU Social.'),
+ 'oauth_alt' => DI::l10n()->t('Log in with GNU Social'),
+ 'oauth_cancel' => DI::l10n()->t('Cancel Connection Process'),
+ 'oauth_api' => DI::l10n()->t('Current GNU Social API is: %s', $baseapi),
+ 'connected_account' => $connected_account ?? '',
+ 'privacy_warning' => $privacy_warning ?? '',
+ ],
+
+ '$ckey' => $ckey,
+ '$csecret' => $csecret,
+ '$otoken' => $otoken,
+ '$osecret' => $osecret,
+ '$sites' => $sites,
+
+ '$authorize_url' => $authorize_url ?? '',
+ '$request_token' => $request_token ?? null,
+ '$account' => $account ?? null,
+
+ '$authenticate_url' => DI::baseUrl()->get() . '/statusnet/connect',
+
+ '$consumerkey' => ['statusnet-consumerkey', DI::l10n()->t('OAuth Consumer Key'), '', '', false, ' size="35'],
+ '$consumersecret' => ['statusnet-consumersecret', DI::l10n()->t('OAuth Consumer Secret'), '', '', false, ' size="35'],
+
+ '$baseapi' => ['statusnet-baseapi', DI::l10n()->t('Base API Path (remember the trailing /)'), '', '', false, ' size="35'],
+ '$pin' => ['statusnet-pin', DI::l10n()->t('Copy the security code from GNU Social here')],
+
+ '$enable' => ['statusnet-enabled', DI::l10n()->t('Allow posting to GNU Social'), $enabled, DI::l10n()->t('If enabled all your public postings can be posted to the associated GNU Social account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.')],
+ '$default' => ['statusnet-default', DI::l10n()->t('Post to GNU Social by default'), $def_enabled],
+ '$mirror' => ['statusnet-mirror', DI::l10n()->t('Mirror all public posts'), $mirror_enabled],
+ '$create_user' => ['statusnet-create_user', DI::l10n()->t('Automatically create contacts'), $createuser_enabled],
+ '$import' => ['statusnet-import', DI::l10n()->t('Import the remote timeline'), $import, '', [
+ 0 => DI::l10n()->t('Disabled'),
+ 1 => DI::l10n()->t('Full Timeline'),
+ 2 => DI::l10n()->t('Only Mentions'),
+ ]],
+ ]);
+
+ $data = [
+ 'connector' => 'statusnet',
+ 'title' => DI::l10n()->t('GNU Social Import/Export/Mirror'),
+ 'image' => 'images/gnusocial.png',
+ 'enabled' => $enabled,
+ 'html' => $html,
+ 'submit' => $submit,
+ ];
}
function statusnet_hook_fork(App $a, array &$b)
diff --git a/statusnet/templates/connector_settings.tpl b/statusnet/templates/connector_settings.tpl
new file mode 100644
index 00000000..b5a497a8
--- /dev/null
+++ b/statusnet/templates/connector_settings.tpl
@@ -0,0 +1,50 @@
+{{if $ckey && $csecret}}
+ {{if $otoken && $osecret}}
+ {{if $account}}
+
+{{/if}}
\ No newline at end of file
diff --git a/tumblr/templates/connector_settings.tpl b/tumblr/templates/connector_settings.tpl
new file mode 100644
index 00000000..d28fab9d
--- /dev/null
+++ b/tumblr/templates/connector_settings.tpl
@@ -0,0 +1,10 @@
+
';
- $s .= '';
+ // Hide the submit button by default
+ $submit = '';
if ((!$ckey) && (!$csecret)) {
/* no global consumer keys
* display warning and skip personal config
*/
- $s .= '
' . DI::l10n()->t('No consumer key pair for Twitter found. Please contact your site administrator.') . '
';
+ $html = '
' . DI::l10n()->t('No consumer key pair for Twitter found. Please contact your site administrator.') . '
';
} else {
// ok we have a consumer key pair now look into the OAuth stuff
if ((!$otoken) && (!$osecret)) {
@@ -338,17 +330,19 @@ function twitter_settings(App $a, &$s)
$connection = new TwitterOAuth($ckey, $csecret);
try {
$result = $connection->oauth('oauth/request_token', ['oauth_callback' => 'oob']);
- $s .= '
' . DI::l10n()->t('At this Friendica instance the Twitter addon was enabled but you have not yet connected your account to your Twitter account. To do so click the button below to get a PIN from Twitter which you have to copy into the input box below and submit the form. Only your public posts will be posted to Twitter.') . '
' . DI::l10n()->t('At this Friendica instance the Twitter addon was enabled but you have not yet connected your account to your Twitter account. To do so click the button below to get a PIN from Twitter which you have to copy into the input box below and submit the form. Only your public posts will be posted to Twitter.') . '
';
Logger::notice('Invalid twitter info (verify credentials).', ['auth' => TwitterOAuth::class]);
}
- $s .= '';
- $s .= Renderer::replaceMacros($field_checkbox, [
- '$field' => ['twitter-enable', DI::l10n()->t('Allow posting to Twitter'), $enabled, DI::l10n()->t('If enabled all your public postings can be posted to the associated Twitter account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.')]
- ]);
if ($user['hidewall']) {
- $s .= '
' . DI::l10n()->t('Note: Due to your privacy settings (Hide your profile details from unknown viewers?) the link potentially included in public postings relayed to Twitter will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.') . '
';
+ $privacy_warning = DI::l10n()->t('Note: Due to your privacy settings (Hide your profile details from unknown viewers?) the link potentially included in public postings relayed to Twitter will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.');
}
- $s .= Renderer::replaceMacros($field_checkbox, [
- '$field' => ['twitter-default', DI::l10n()->t('Send public postings to Twitter by default'), $defenabled, '']
+
+ $t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/twitter/');
+ $html = Renderer::replaceMacros($t, [
+ '$l10n' => [
+ 'connected' => $connected ?? '',
+ 'invalid' => DI::l10n()->t('Invalid Twitter info'),
+ 'disconnect' => DI::l10n()->t('Disconnect'),
+ 'privacy_warning' => $privacy_warning ?? '',
+ ],
+
+ '$account' => $account,
+ '$enable' => ['twitter-enable', DI::l10n()->t('Allow posting to Twitter'), $enabled, DI::l10n()->t('If enabled all your public postings can be posted to the associated Twitter account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.')],
+ '$default' => ['twitter-default', DI::l10n()->t('Send public postings to Twitter by default'), $defenabled],
+ '$mirror' => ['twitter-mirror', DI::l10n()->t('Mirror all posts from twitter that are no replies'), $mirrorenabled],
+ '$import' => ['twitter-import', DI::l10n()->t('Import the remote timeline'), $importenabled],
+ '$create_user' => ['twitter-create_user', DI::l10n()->t('Automatically create contacts'), $create_userenabled, DI::l10n()->t('This will automatically create a contact in Friendica as soon as you receive a message from an existing contact via the Twitter network. If you do not enable this, you need to manually add those Twitter contacts in Friendica from whom you would like to see posts here.')],
]);
- $s .= Renderer::replaceMacros($field_checkbox, [
- '$field' => ['twitter-mirror', DI::l10n()->t('Mirror all posts from twitter that are no replies'), $mirrorenabled, '']
- ]);
- $s .= Renderer::replaceMacros($field_checkbox, [
- '$field' => ['twitter-import', DI::l10n()->t('Import the remote timeline'), $importenabled, '']
- ]);
- $s .= Renderer::replaceMacros($field_checkbox, [
- '$field' => ['twitter-create_user', DI::l10n()->t('Automatically create contacts'), $create_userenabled, DI::l10n()->t('This will automatically create a contact in Friendica as soon as you receive a message from an existing contact via the Twitter network. If you do not enable this, you need to manually add those Twitter contacts in Friendica from whom you would like to see posts here.')]
- ]);
- $s .= '';
- $s .= '';
+
+ // Enable the default submit button
+ $submit = null;
} catch (TwitterOAuthException $e) {
- $s .= '