X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=statusnet%2Fstatusnet.php;h=5cb65b91fdb90d4ebec3c975d4a001086cefe3b5;hb=802c5ca87f5d851a9be776bfc6245c1606ff6c6e;hp=6bcf22b0983d4307a365afdb8c5933c228163128;hpb=fe4982d51b4c8ca0e0e44058e096549e555afee2;p=friendica-addons.git
diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php
index 6bcf22b0..5cb65b91 100644
--- a/statusnet/statusnet.php
+++ b/statusnet/statusnet.php
@@ -86,17 +86,17 @@ function statusnet_check_item_notification(App $a, &$notification_data)
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')
]
];
}
@@ -104,7 +104,7 @@ 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
@@ -116,18 +116,18 @@ function statusnet_settings_post(App $a, $post)
/* * *
* 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'])) {
/* * *
@@ -141,12 +141,12 @@ 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']);
}
}
}
@@ -159,52 +159,52 @@ 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.'));
}
}
} 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
} 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');
}
}
}
@@ -213,7 +213,7 @@ function statusnet_settings_post(App $a, $post)
function statusnet_settings(App $a, array &$data)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
return;
}
@@ -225,16 +225,16 @@ function statusnet_settings(App $a, array &$data)
* allow the user to cancel the connection process at this step
* 3) Checkbox for "Send public notices (respect size limitation)
*/
- $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');
+ $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) {
@@ -256,7 +256,7 @@ function statusnet_settings(App $a, array &$data)
$connected_account = DI::l10n()->t('Currently connected to: %s', $account->statusnet_profile_url, $account->screen_name);
}
- $user = User::getById(local_user());
+ $user = User::getById(DI::userSession()->getLocalUserId());
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.');
}
@@ -366,7 +366,7 @@ function statusnet_hook_fork(App $a, array &$b)
}
} else {
// Comments are never exported when we don't import the GNU Social timeline
- if (!strstr($post['postopts'], 'statusnet') || ($post['parent'] != $post['id']) || $post['private']) {
+ if (strpos($post['postopts'] ?? '', 'statusnet') === false || ($post['parent'] != $post['id']) || $post['private']) {
$b['execute'] = false;
return;
}
@@ -379,15 +379,15 @@ function statusnet_post_local(App $a, array &$b)
return;
}
- if (!local_user() || (local_user() != $b['uid'])) {
+ if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
return;
}
- $statusnet_post = DI::pConfig()->get(local_user(), 'statusnet', 'post');
+ $statusnet_post = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'post');
$statusnet_enable = (($statusnet_post && !empty($_REQUEST['statusnet_enable'])) ? intval($_REQUEST['statusnet_enable']) : 0);
// if API is used, default to the chosen settings
- if ($b['api_source'] && intval(DI::pConfig()->get(local_user(), 'statusnet', 'post_by_default'))) {
+ if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'post_by_default'))) {
$statusnet_enable = 1;
}
@@ -440,7 +440,7 @@ function statusnet_post_hook(App $a, array &$b)
return;
}
- $b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], $b['body']);
+ $b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], DI::contentItem()->addSharedPost($b));
$api = DI::pConfig()->get($b['uid'], 'statusnet', 'baseapi');
$hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api);
@@ -668,7 +668,7 @@ function statusnet_prepare_body(App $a, array &$b)
}
if ($b['preview']) {
- $max_char = DI::pConfig()->get(local_user(), 'statusnet', 'max_char');
+ $max_char = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'statusnet', 'max_char');
if (intval($max_char) == 0) {
$max_char = 140;
}
@@ -676,7 +676,7 @@ function statusnet_prepare_body(App $a, array &$b)
$item = $b['item'];
$item['plink'] = DI::baseUrl()->get() . '/display/' . $item['guid'];
- $condition = ['uri' => $item['thr-parent'], 'uid' => local_user()];
+ $condition = ['uri' => $item['thr-parent'], 'uid' => DI::userSession()->getLocalUserId()];
$orig_post = Post::selectFirst(['author-link', 'uri'], $condition);
if (DBA::isResult($orig_post)) {
$nick = preg_replace("=https?://(.*)/(.*)=ism", "$2", $orig_post['author-link']);
@@ -762,7 +762,6 @@ function statusnet_fetchtimeline(App $a, int $uid)
$osecret = DI::pConfig()->get($uid, 'statusnet', 'oauthsecret');
$lastid = DI::pConfig()->get($uid, 'statusnet', 'lastid');
- require_once 'mod/item.php';
// get the application name for the SN app
// 1st try personal config, then system config and fallback to the
// hostname of the node if neither one is set.
@@ -819,46 +818,33 @@ function statusnet_fetchtimeline(App $a, int $uid)
}
if (!stristr($post->source, $application_name)) {
- $_SESSION['authenticated'] = true;
- $_SESSION['uid'] = $uid;
-
- unset($_REQUEST);
- $_REQUEST['api_source'] = true;
- $_REQUEST['profile_uid'] = $uid;
- //$_REQUEST['source'] = 'StatusNet';
- $_REQUEST['source'] = $post->source;
- $_REQUEST['extid'] = Protocol::STATUSNET;
-
- if (isset($post->id)) {
- $_REQUEST['message_id'] = Item::newURI($uid, Protocol::STATUSNET . ':' . $post->id);
- }
-
- //$_REQUEST['date'] = $post->created_at;
+ $postarray['uid'] = $uid;
+ $postarray['app'] = $post->source;
+ $postarray['extid'] = Protocol::STATUSNET;
- $_REQUEST['title'] = '';
+ $postarray['title'] = '';
- $_REQUEST['body'] = $post->text;
+ $postarray['body'] = $post->text;
if (is_string($post->place->name)) {
- $_REQUEST['location'] = $post->place->name;
+ $postarray['location'] = $post->place->name;
}
if (is_string($post->place->full_name)) {
- $_REQUEST['location'] = $post->place->full_name;
+ $postarray['location'] = $post->place->full_name;
}
if (is_array($post->geo->coordinates)) {
- $_REQUEST['coord'] = $post->geo->coordinates[0] . ' ' . $post->geo->coordinates[1];
+ $postarray['coord'] = $post->geo->coordinates[0] . ' ' . $post->geo->coordinates[1];
}
if (is_array($post->coordinates->coordinates)) {
- $_REQUEST['coord'] = $post->coordinates->coordinates[1] . ' ' . $post->coordinates->coordinates[0];
+ $postarray['coord'] = $post->coordinates->coordinates[1] . ' ' . $post->coordinates->coordinates[0];
}
- //print_r($_REQUEST);
- if ($_REQUEST['body'] != '') {
+ if ($postarray['body'] != '') {
Logger::notice('statusnet: posting for user ' . $uid);
- item_post($a);
+ Item::insert($postarray, true);
}
}
}