X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=statusnet%2Fstatusnet.php;h=5cb65b91fdb90d4ebec3c975d4a001086cefe3b5;hb=802c5ca87f5d851a9be776bfc6245c1606ff6c6e;hp=75e4415151188f7a9c0b74d3b09e3b73d8d420db;hpb=6a349e7fd98c331373b3ae948d273fc36058bbb7;p=friendica-addons.git
diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php
index 75e44151..5cb65b91 100644
--- a/statusnet/statusnet.php
+++ b/statusnet/statusnet.php
@@ -56,6 +56,7 @@ use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Model\User;
+use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
@@ -73,29 +74,29 @@ function statusnet_install()
Hook::register('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
Hook::register('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
Hook::register('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
- Logger::notice("installed GNU Social");
+ Logger::notice('installed GNU Social');
}
function statusnet_check_item_notification(App $a, &$notification_data)
{
- if (DI::pConfig()->get($notification_data["uid"], 'statusnet', 'post')) {
- $notification_data["profiles"][] = DI::pConfig()->get($notification_data["uid"], 'statusnet', 'own_url');
+ if (DI::pConfig()->get($notification_data['uid'], 'statusnet', 'post')) {
+ $notification_data['profiles'][] = DI::pConfig()->get($notification_data['uid'], 'statusnet', 'own_url');
}
}
function statusnet_jot_nets(App $a, array &$jotnets_fields)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
return;
}
- if (DI::pConfig()->get(local_user(), 'statusnet', 'post')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'post')) {
$jotnets_fields[] = [
'type' => 'checkbox',
'field' => [
'statusnet_enable',
DI::l10n()->t('Post to GNU Social'),
- DI::pConfig()->get(local_user(), 'statusnet', 'post_by_default')
+ DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'post_by_default')
]
];
}
@@ -103,30 +104,30 @@ function statusnet_jot_nets(App $a, array &$jotnets_fields)
function statusnet_settings_post(App $a, $post)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
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');
- DI::pConfig()->delete(local_user(), 'statusnet', 'post');
- DI::pConfig()->delete(local_user(), 'statusnet', 'post_by_default');
- DI::pConfig()->delete(local_user(), 'statusnet', 'oauthtoken');
- DI::pConfig()->delete(local_user(), 'statusnet', 'oauthsecret');
- DI::pConfig()->delete(local_user(), 'statusnet', 'baseapi');
- DI::pConfig()->delete(local_user(), 'statusnet', 'lastid');
- DI::pConfig()->delete(local_user(), 'statusnet', 'mirror_posts');
- DI::pConfig()->delete(local_user(), 'statusnet', 'import');
- DI::pConfig()->delete(local_user(), 'statusnet', 'create_user');
- DI::pConfig()->delete(local_user(), 'statusnet', 'own_url');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'consumerkey');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'consumersecret');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'post');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'post_by_default');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'oauthtoken');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'oauthsecret');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'baseapi');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'lastid');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'mirror_posts');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'import');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'create_user');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'own_url');
} else {
if (isset($_POST['statusnet-preconf-apiurl'])) {
/* * *
@@ -140,16 +141,15 @@ function statusnet_settings_post(App $a, $post)
$apibase = $asn['apiurl'];
$c = DI::httpClient()->fetch($apibase . 'statusnet/version.xml');
if (strlen($c) > 0) {
- DI::pConfig()->set(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey']);
- DI::pConfig()->set(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret']);
- DI::pConfig()->set(local_user(), 'statusnet', 'baseapi', $asn['apiurl']);
- //DI::pConfig()->set(local_user(), 'statusnet', 'application_name', $asn['applicationname'] );
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'consumerkey', $asn['consumerkey']);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'consumersecret', $asn['consumersecret']);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'baseapi', $asn['apiurl']);
+ //DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'application_name', $asn['applicationname'] );
} else {
- notice(DI::l10n()->t('Please contact your site administrator. The provided API URL is not valid.') . EOL . $asn['apiurl'] . EOL);
+ DI::sysmsg()->addNotice(DI::l10n()->t('Please contact your site administrator. The provided API URL is not valid.') . ' ' . $asn['apiurl']);
}
}
}
- DI::baseUrl()->redirect('settings/connectors');
} else {
if (isset($_POST['statusnet-consumersecret'])) {
// check if we can reach the API of the GNU Social server
@@ -159,225 +159,177 @@ function statusnet_settings_post(App $a, $post)
$c = DI::httpClient()->fetch($apibase . 'statusnet/version.xml');
if (strlen($c) > 0) {
// ok the API path is correct, let's save the settings
- DI::pConfig()->set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
- DI::pConfig()->set(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
- DI::pConfig()->set(local_user(), 'statusnet', 'baseapi', $apibase);
- //DI::pConfig()->set(local_user(), 'statusnet', 'application_name', $_POST['statusnet-applicationname'] );
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'baseapi', $apibase);
+ //DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'application_name', $_POST['statusnet-applicationname'] );
} else {
// the API path is not correct, maybe missing trailing / ?
$apibase = $apibase . '/';
$c = DI::httpClient()->fetch($apibase . 'statusnet/version.xml');
if (strlen($c) > 0) {
// ok the API path is now correct, let's save the settings
- DI::pConfig()->set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
- DI::pConfig()->set(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
- DI::pConfig()->set(local_user(), 'statusnet', 'baseapi', $apibase);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'baseapi', $apibase);
} else {
// still not the correct API base, let's do noting
- notice(DI::l10n()->t('We could not contact the GNU Social API with the Path you entered.') . EOL);
+ DI::sysmsg()->addNotice(DI::l10n()->t('We could not contact the GNU Social API with the Path you entered.'));
}
}
- 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
- $api = DI::pConfig()->get(local_user(), 'statusnet', 'baseapi');
- $ckey = DI::pConfig()->get(local_user(), 'statusnet', 'consumerkey');
- $csecret = DI::pConfig()->get(local_user(), 'statusnet', 'consumersecret');
+ $api = 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');
// the token and secret for which the PIN was generated were hidden in the settings
// form as token and token2, we need a new connection to GNU Social using these token
// and secret to request a Access Token with the PIN
$connection = new StatusNetOAuth($api, $ckey, $csecret, $_POST['statusnet-token'], $_POST['statusnet-token2']);
$token = $connection->getAccessToken($_POST['statusnet-pin']);
// ok, now that we have the Access Token, save them in the user config
- DI::pConfig()->set(local_user(), 'statusnet', 'oauthtoken', $token['oauth_token']);
- DI::pConfig()->set(local_user(), 'statusnet', 'oauthsecret', $token['oauth_token_secret']);
- DI::pConfig()->set(local_user(), 'statusnet', 'post', 1);
- DI::pConfig()->set(local_user(), 'statusnet', 'post_taglinks', 1);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'oauthtoken', $token['oauth_token']);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'oauthsecret', $token['oauth_token_secret']);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'post', 1);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), '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
- DI::pConfig()->set(local_user(), 'statusnet', 'post', intval($_POST['statusnet-enable']));
- DI::pConfig()->set(local_user(), 'statusnet', 'post_by_default', intval($_POST['statusnet-default']));
- DI::pConfig()->set(local_user(), 'statusnet', 'mirror_posts', intval($_POST['statusnet-mirror']));
- DI::pConfig()->set(local_user(), 'statusnet', 'import', intval($_POST['statusnet-import']));
- DI::pConfig()->set(local_user(), 'statusnet', 'create_user', intval($_POST['statusnet-create_user']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'post', intval($_POST['statusnet-enable']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'post_by_default', intval($_POST['statusnet-default']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'mirror_posts', intval($_POST['statusnet-mirror']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'import', intval($_POST['statusnet-import']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'statusnet', 'create_user', intval($_POST['statusnet-create_user']));
if (!intval($_POST['statusnet-mirror']))
- DI::pConfig()->delete(local_user(), 'statusnet', 'lastid');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'statusnet', 'lastid');
}
}
}
}
}
-function statusnet_settings(App $a, &$s)
+function statusnet_settings(App $a, array &$data)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
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" ' : '');
-
- $css = (($enabled) ? '' : '-disabled');
-
- $s .= '';
- $s .= '
' . DI::l10n()->t('GNU Social Import/Export/Mirror') . '
';
- $s .= '';
- $s .= '
';
- $s .= '';
- $s .= '
' . DI::l10n()->t('GNU Social Import/Export/Mirror') . '
';
- $s .= '';
-
- 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.") . '
' . 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)) {
- /* * *
- * 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 .= '
' . 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('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.') . '
' . 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.') . '
';
+ $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.');
}
- $s .= '
';
-
- $s .= '';
- //$s .= '';
-
- $s .= '';
- $s .= '';
- $s .= '';
- $s .= '';
- $s .= '';
- $s .= '';
- /*
- $s .= '';
- $s .= '';
- $s .= '';
+
+ $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
*/
- $s .= '