* Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
* Maintainer: Hypolite Petovan <https://friendica.mrpetovan.com/profile/hypolite>
+ * Status: unsupported
*
* Copyright (c) 2011-2013 Tobias Diekershoff, Michael Vogel, Hypolite Petovan
* All rights reserved.
* we do not need "Twitter as login". When you've registered the app you get the
* OAuth Consumer key and secret pair for your application/site.
*
- * Add this key pair to your global config/addon.config.php or use the admin panel.
+ * Add this key pair to your config/twitter.config.php file or use the admin panel.
*
- * 'twitter' => [
- * 'consumerkey' => '',
- * 'consumersecret' => '',
- * ],
+ * return [
+ * 'twitter' => [
+ * 'consumerkey' => '',
+ * 'consumersecret' => '',
+ * ],
+ * ];
*
* To activate the addon itself add it to the system.addon
* setting. After this, your user can configure their Twitter account settings
use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Protocol\Activity;
-use Friendica\Core\Config\Util\ConfigFileLoader;
+use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\System;
+use Friendica\Model\Photo;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
use Friendica\Util\Strings;
// Hook functions
-function twitter_load_config(App $a, ConfigFileLoader $loader)
+function twitter_load_config(ConfigFileManager $loader)
{
- $a->getConfigCache()->load($loader->loadAddonConfig('twitter'));
+ DI::app()->getConfigCache()->load($loader->loadAddonConfig('twitter'), \Friendica\Core\Config\ValueObject\Cache::SOURCE_STATIC);
}
-function twitter_check_item_notification(App $a, array &$notification_data)
+function twitter_check_item_notification(array &$notification_data)
{
$own_id = DI::pConfig()->get($notification_data['uid'], 'twitter', 'own_id');
}
}
-function twitter_support_follow(App $a, array &$data)
+function twitter_support_follow(array &$data)
{
if ($data['protocol'] == Protocol::TWITTER) {
$data['result'] = true;
}
}
-function twitter_follow(App $a, array &$contact)
+function twitter_follow(array &$contact)
{
Logger::info('Check if contact is twitter contact', ['url' => $contact['url']]);
$nickname = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $contact['url']);
$nickname = str_replace('@twitter.com', '', $nickname);
- $uid = $a->getLoggedInUserId();
+ $uid = DI::userSession()->getLocalUserId();
if (!twitter_api_contact('friendships/create', ['network' => Protocol::TWITTER, 'nick' => $nickname], $uid)) {
$contact = null;
}
}
-function twitter_unfollow(App $a, array &$hook_data)
+function twitter_unfollow(array &$hook_data)
{
$hook_data['result'] = twitter_api_contact('friendships/destroy', $hook_data['contact'], $hook_data['uid']);
}
-function twitter_block(App $a, array &$hook_data)
+function twitter_block(array &$hook_data)
{
$hook_data['result'] = twitter_api_contact('blocks/create', $hook_data['contact'], $hook_data['uid']);
}
}
-function twitter_unblock(App $a, array &$hook_data)
+function twitter_unblock(array &$hook_data)
{
$hook_data['result'] = twitter_api_contact('blocks/destroy', $hook_data['contact'], $hook_data['uid']);
}
return null;
}
- return twitter_api_call($uid, $apiPath, ['screen_name' => $contact['nick']]);
+ return (bool)twitter_api_call($uid, $apiPath, ['screen_name' => $contact['nick']]);
}
-function twitter_jot_nets(App $a, array &$jotnets_fields)
+function twitter_jot_nets(array &$jotnets_fields)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
return;
}
- if (DI::pConfig()->get(local_user(), 'twitter', 'post')) {
+ if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'post')) {
$jotnets_fields[] = [
'type' => 'checkbox',
'field' => [
'twitter_enable',
DI::l10n()->t('Post to Twitter'),
- DI::pConfig()->get(local_user(), 'twitter', 'post_by_default')
+ DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'post_by_default')
]
];
}
}
-function twitter_settings_post(App $a)
+function twitter_settings_post()
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
return;
}
// don't check twitter settings if twitter submit button is not clicked
* if the twitter-disconnect checkbox is set, clear the OAuth key/secret pair
* from the user configuration
*/
- DI::pConfig()->delete(local_user(), 'twitter', 'consumerkey');
- DI::pConfig()->delete(local_user(), 'twitter', 'consumersecret');
- DI::pConfig()->delete(local_user(), 'twitter', 'oauthtoken');
- DI::pConfig()->delete(local_user(), 'twitter', 'oauthsecret');
- DI::pConfig()->delete(local_user(), 'twitter', 'post');
- DI::pConfig()->delete(local_user(), 'twitter', 'post_by_default');
- DI::pConfig()->delete(local_user(), 'twitter', 'lastid');
- DI::pConfig()->delete(local_user(), 'twitter', 'mirror_posts');
- DI::pConfig()->delete(local_user(), 'twitter', 'import');
- DI::pConfig()->delete(local_user(), 'twitter', 'create_user');
- DI::pConfig()->delete(local_user(), 'twitter', 'own_id');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'consumerkey');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'consumersecret');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'oauthtoken');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'oauthsecret');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'post');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'post_by_default');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'lastid');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'thread');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'mirror_posts');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'import');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'create_user');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'auto_follow');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'own_id');
} else {
if (isset($_POST['twitter-pin'])) {
// if the user supplied us with a PIN from Twitter, let the magic of OAuth happen
$connection = new TwitterOAuth($ckey, $csecret, $_POST['twitter-token'], $_POST['twitter-token2']);
$token = $connection->oauth('oauth/access_token', ['oauth_verifier' => $_POST['twitter-pin']]);
// ok, now that we have the Access Token, save them in the user config
- DI::pConfig()->set(local_user(), 'twitter', 'oauthtoken', $token['oauth_token']);
- DI::pConfig()->set(local_user(), 'twitter', 'oauthsecret', $token['oauth_token_secret']);
- DI::pConfig()->set(local_user(), 'twitter', 'post', 1);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'oauthtoken', $token['oauth_token']);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'oauthsecret', $token['oauth_token_secret']);
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'post', 1);
} catch(Exception $e) {
- notice($e->getMessage());
+ DI::sysmsg()->addNotice($e->getMessage());
} catch(TwitterOAuthException $e) {
- notice($e->getMessage());
+ DI::sysmsg()->addNotice($e->getMessage());
}
} 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
- DI::pConfig()->set(local_user(), 'twitter', 'post', intval($_POST['twitter-enable']));
- DI::pConfig()->set(local_user(), 'twitter', 'post_by_default', intval($_POST['twitter-default']));
- DI::pConfig()->set(local_user(), 'twitter', 'mirror_posts', intval($_POST['twitter-mirror']));
- DI::pConfig()->set(local_user(), 'twitter', 'import', intval($_POST['twitter-import']));
- DI::pConfig()->set(local_user(), 'twitter', 'create_user', intval($_POST['twitter-create_user']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'post', intval($_POST['twitter-enable']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'post_by_default', intval($_POST['twitter-default']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'thread', intval($_POST['twitter-thread']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'mirror_posts', intval($_POST['twitter-mirror']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'import', intval($_POST['twitter-import']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'create_user', intval($_POST['twitter-create_user']));
+ DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'twitter', 'auto_follow', intval($_POST['twitter-auto_follow']));
if (!intval($_POST['twitter-mirror'])) {
- DI::pConfig()->delete(local_user(), 'twitter', 'lastid');
+ DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'twitter', 'lastid');
}
}
}
}
-function twitter_settings(App $a, array &$data)
+function twitter_settings(array &$data)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
return;
}
- $user = User::getById(local_user());
+ $user = User::getById(DI::userSession()->getLocalUserId());
DI::page()->registerStylesheet(__DIR__ . '/twitter.css', 'all');
*/
$ckey = DI::config()->get('twitter', 'consumerkey');
$csecret = DI::config()->get('twitter', 'consumersecret');
- $otoken = DI::pConfig()->get(local_user(), 'twitter', 'oauthtoken');
- $osecret = DI::pConfig()->get(local_user(), 'twitter', 'oauthsecret');
+ $otoken = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'oauthtoken');
+ $osecret = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'oauthsecret');
- $enabled = intval(DI::pConfig()->get(local_user(), 'twitter', 'post'));
- $defenabled = intval(DI::pConfig()->get(local_user(), 'twitter', 'post_by_default'));
- $mirrorenabled = intval(DI::pConfig()->get(local_user(), 'twitter', 'mirror_posts'));
- $importenabled = intval(DI::pConfig()->get(local_user(), 'twitter', 'import'));
- $create_userenabled = intval(DI::pConfig()->get(local_user(), 'twitter', 'create_user'));
+ $enabled = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'post'));
+ $defenabled = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'post_by_default'));
+ $threadenabled = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'thread'));
+ $mirrorenabled = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'mirror_posts'));
+ $importenabled = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'import'));
+ $create_userenabled = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'create_user'));
+ $auto_followenabled = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'auto_follow'));
// Hide the submit button by default
$submit = '';
'$account' => $account,
'$enable' => ['twitter-enable', DI::l10n()->t('Allow posting to Twitter'), $enabled, DI::l10n()->t('If enabled all your <strong>public</strong> 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],
+ '$thread' => ['twitter-thread', DI::l10n()->t('Use threads instead of truncating the content'), $threadenabled],
'$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.')],
+ '$auto_follow' => ['twitter-auto_follow', DI::l10n()->t('Follow in fediverse'), $auto_followenabled, DI::l10n()->t('Automatically subscribe to the contact in the fediverse, when a fediverse account is mentioned in name or description and we are following the Twitter contact.')],
]);
// Enable the default submit button
];
}
-function twitter_hook_fork(App $a, array &$b)
+function twitter_hook_fork(array &$b)
{
DI::logger()->debug('twitter_hook_fork', $b);
return;
}
- if (substr($post['app'], 0, 7) == 'Twitter') {
+ if (substr($post['app'] ?? '', 0, 7) == 'Twitter') {
DI::logger()->info('No Twitter app');
$b['execute'] = false;
return;
}
} else {
// Comments are never exported when we don't import the twitter timeline
- if (!strstr($post['postopts'], 'twitter') || ($post['parent'] != $post['id']) || $post['private']) {
+ if (!strstr($post['postopts'] ?? '', 'twitter') || ($post['parent'] != $post['id']) || $post['private']) {
DI::logger()->info('Comments are never exported when we don\'t import the twitter timeline');
$b['execute'] = false;
return;
}
}
-function twitter_post_local(App $a, array &$b)
+function twitter_post_local(array &$b)
{
if ($b['edit']) {
return;
}
- if (!local_user() || (local_user() != $b['uid'])) {
+ if (!DI::userSession()->getLocalUserId() || (DI::userSession()->getLocalUserId() != $b['uid'])) {
return;
}
- $twitter_post = intval(DI::pConfig()->get(local_user(), 'twitter', 'post'));
+ $twitter_post = intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'post'));
$twitter_enable = (($twitter_post && !empty($_REQUEST['twitter_enable'])) ? intval($_REQUEST['twitter_enable']) : 0);
// if API is used, default to the chosen settings
- if ($b['api_source'] && intval(DI::pConfig()->get(local_user(), 'twitter', 'post_by_default'))) {
+ if ($b['api_source'] && intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'twitter', 'post_by_default'))) {
$twitter_enable = 1;
}
$b['postopts'] .= 'twitter';
}
-function twitter_probe_detect(App $a, array &$hookData)
+function twitter_probe_detect(array &$hookData)
{
// Don't overwrite an existing result
if (isset($hookData['result'])) {
$user = twitter_fetchuser($nick);
if ($user) {
- $hookData['result'] = twitter_user_to_contact($user);
+ $hookData['result'] = twitter_user_to_contact($user) ?: null;
+ }
+
+ // Authoritative probe should set the result even if the probe was unsuccessful
+ if ($hookData['network'] == Protocol::TWITTER && empty($hookData['result'])) {
+ $hookData['result'] = [];
}
}
-function twitter_item_by_link(App $a, array &$hookData)
+function twitter_item_by_link(array &$hookData)
{
// Don't overwrite an existing result
if (isset($hookData['item_id'])) {
empty(DI::pConfig()->get($hookData['uid'], 'twitter', 'oauthtoken'))
|| empty(DI::pConfig()->get($hookData['uid'], 'twitter', 'oauthsecret'))
) {
- notice(DI::l10n()->t('Please connect a Twitter account in your Social Network settings to import Twitter posts.'));
+ DI::sysmsg()->addNotice(DI::l10n()->t('Please connect a Twitter account in your Social Network settings to import Twitter posts.'));
return;
}
$status = twitter_statuses_show($matches[1]);
if (empty($status->id_str)) {
- notice(DI::l10n()->t('Twitter post not found.'));
+ DI::sysmsg()->addNotice(DI::l10n()->t('Twitter post not found.'));
return;
}
- $item = twitter_createpost($a, $hookData['uid'], $status, [], true, false, false);
+ $item = twitter_createpost($hookData['uid'], $status, [], true, false, false);
if (!empty($item)) {
$hookData['item_id'] = Item::insert($item);
}
}
-function twitter_api_post(string $apiPath, string $pid, int $uid): ?bool
+function twitter_api_post(string $apiPath, string $pid, int $uid): ?object
{
if (empty($pid)) {
- return false;
+ return null;
}
return twitter_api_call($uid, $apiPath, ['id' => $pid]);
}
-function twitter_api_call(int $uid, string $apiPath, array $parameters = []): ?bool
+function twitter_api_call(int $uid, string $apiPath, array $parameters = []): ?object
{
$ckey = DI::config()->get('twitter', 'consumerkey');
$csecret = DI::config()->get('twitter', 'consumersecret');
Logger::info('[twitter] API call successful', ['apiPath' => $apiPath, 'parameters' => $parameters]);
Logger::debug('[twitter] API call result', ['apiPath' => $apiPath, 'parameters' => $parameters, 'result' => $result]);
- return true;
+ return $result;
} catch (TwitterOAuthException $twitterOAuthException) {
- Logger::warning('Unable to communicate with twitter', ['apiPath' => $apiPath, 'parameters' => $parameters, 'code' => $twitterOAuthException->getCode(), 'exception' => $twitterOAuthException]);
- return false;
+ Logger::notice('Unable to communicate with twitter', ['apiPath' => $apiPath, 'parameters' => $parameters, 'code' => $twitterOAuthException->getCode(), 'exception' => $twitterOAuthException]);
+ return null;
} catch (Exception $e) {
Logger::notice('[twitter] API call failed', ['apiPath' => $apiPath, 'parameters' => $parameters, 'code' => $e->getCode(), 'message' => $e->getMessage()]);
- return false;
+ return null;
}
}
return (int)$id;
}
-function twitter_post_hook(App $a, array &$b)
+function twitter_post_hook(array &$b)
{
- DI::logger()->info('twitter_post_hook', $b);
+ DI::logger()->debug('Invoke post hook', $b);
if ($b['deleted']) {
twitter_delete_item($b);
return;
}
- $b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], $b['body']);
+ $b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], DI::contentItem()->addSharedPost($b));
$thr_parent = null;
$condition = ['uri' => $b['thr-parent'], 'uid' => $b['uid']];
$thr_parent = Post::selectFirst(['uri', 'extid', 'author-link', 'author-nick', 'author-network'], $condition);
if (!DBA::isResult($thr_parent)) {
- Logger::warning('No parent found', ['thr-parent' => $b['thr-parent']]);
+ Logger::notice('No parent found', ['thr-parent' => $b['thr-parent']]);
return;
}
Logger::info('We have customer key and oauth stuff, going to send.');
// If it's a repeated message from twitter then do a native retweet and exit
- if (twitter_is_retweet($a, $b['uid'], $b['body'])) {
+ if (twitter_is_retweet($b['uid'], $b['body'])) {
return;
}
// and now tweet it :-)
$post = [];
- if (!empty($msgarr['images'])) {
- Logger::info('Got images', ['id' => $b['id'], 'images' => $msgarr['images']]);
+ if (!empty($msgarr['images']) || !empty($msgarr['remote_images'])) {
+ Logger::info('Got images', ['id' => $b['id'], 'images' => $msgarr['images'] ?? [], 'remote_images' => $msgarr['remote_images'] ?? []]);
try {
$media_ids = [];
- foreach ($msgarr['images'] as $image) {
+ foreach ($msgarr['images'] ?? [] as $image) {
if (count($media_ids) == 4) {
continue;
}
+ try {
+ $media_ids[] = twitter_upload_image($connection, $cb, $image, $b);
+ } catch (\Throwable $th) {
+ Logger::warning('Error while uploading image', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+ }
+ }
- $img_str = DI::httpClient()->fetch($image['url']);
-
- $tempfile = tempnam(System::getTempPath(), 'cache');
- file_put_contents($tempfile, $img_str);
-
- Logger::info('Uploading', ['id' => $b['id'], 'image' => $image['url']]);
- $media = $connection->upload('media/upload', ['media' => $tempfile]);
-
- unlink($tempfile);
-
- if (isset($media->media_id_string)) {
- $media_ids[] = $media->media_id_string;
-
- if (!empty($image['description'])) {
- $data = ['media_id' => $media->media_id_string,
- 'alt_text' => ['text' => substr($image['description'], 0, 420)]];
- $ret = $cb->media_metadata_create($data);
- Logger::info('Metadata create', ['id' => $b['id'], 'data' => $data, 'return' => $ret]);
- }
- } else {
- Logger::error('Failed upload', ['id' => $b['id'], 'image' => $image['url'], 'return' => $media]);
- throw new Exception('Failed upload of ' . $image['url']);
+ foreach ($msgarr['remote_images'] ?? [] as $image) {
+ if (count($media_ids) == 4) {
+ continue;
+ }
+ try {
+ $media_ids[] = twitter_upload_image($connection, $cb, $image, $b);
+ } catch (\Throwable $th) {
+ Logger::warning('Error while uploading image', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
}
}
$post['media_ids'] = implode(',', $media_ids);
}
}
- $post['status'] = $msg;
+ if (!DI::pConfig()->get($b['uid'], 'twitter', 'thread') || empty($msgarr['parts']) || (count($msgarr['parts']) == 1)) {
+ Logger::debug('Post single message', ['id' => $b['id']]);
- if ($thr_parent) {
- $post['in_reply_to_status_id'] = twitter_get_id($thr_parent['uri']);
- }
+ $post['status'] = $msg;
+
+ if ($thr_parent) {
+ $post['in_reply_to_status_id'] = twitter_get_id($thr_parent['uri']);
+ }
+
+ $result = $connection->post('statuses/update', $post);
+ Logger::info('twitter_post send', ['id' => $b['id'], 'result' => $result]);
- $result = $connection->post('statuses/update', $post);
- Logger::info('twitter_post send', ['id' => $b['id'], 'result' => $result]);
+ if (!empty($result->source)) {
+ DI::keyValue()->set('twitter_application_name', strip_tags($result->source));
+ }
- if (!empty($result->source)) {
- DI::config()->set('twitter', 'application_name', strip_tags($result->source));
+ if (!empty($result->errors)) {
+ Logger::error('Send to Twitter failed', ['id' => $b['id'], 'error' => $result->errors]);
+ Worker::defer();
+ } elseif ($thr_parent) {
+ Logger::notice('Post send, updating extid', ['id' => $b['id'], 'extid' => $result->id_str]);
+ Item::update(['extid' => 'twitter::' . $result->id_str], ['id' => $b['id']]);
+ }
+ } else {
+ if ($thr_parent) {
+ $in_reply_to_status_id = twitter_get_id($thr_parent['uri']);
+ } else {
+ $in_reply_to_status_id = 0;
+ }
+
+ Logger::debug('Post message thread', ['id' => $b['id'], 'parts' => count($msgarr['parts'])]);
+ foreach ($msgarr['parts'] as $key => $part) {
+ $post['status'] = $part;
+
+ if ($in_reply_to_status_id) {
+ $post['in_reply_to_status_id'] = $in_reply_to_status_id;
+ }
+
+ $result = $connection->post('statuses/update', $post);
+ Logger::debug('twitter_post send', ['part' => $key, 'id' => $b['id'], 'result' => $result]);
+
+ if (!empty($result->errors)) {
+ Logger::warning('Send to Twitter failed', ['part' => $key, 'id' => $b['id'], 'error' => $result->errors]);
+ Worker::defer();
+ break;
+ } elseif ($key == 0) {
+ Logger::debug('Updating extid', ['part' => $key, 'id' => $b['id'], 'extid' => $result->id_str]);
+ Item::update(['extid' => 'twitter::' . $result->id_str], ['id' => $b['id']]);
+ }
+
+ if (!empty($result->source)) {
+ $application_name = strip_tags($result->source);
+ }
+
+ $in_reply_to_status_id = $result->id_str;
+ unset($post['media_ids']);
+ }
+
+ if (!empty($application_name)) {
+ DI::keyValue()->set('twitter_application_name', strip_tags($application_name));
+ }
}
+ }
+}
- if (!empty($result->errors)) {
- Logger::error('Send to Twitter failed', ['id' => $b['id'], 'error' => $result->errors]);
- Worker::defer();
- } elseif ($thr_parent) {
- Logger::notice('Post send, updating extid', ['id' => $b['id'], 'extid' => $result->id_str]);
- Item::update(['extid' => 'twitter::' . $result->id_str], ['id' => $b['id']]);
+function twitter_upload_image($connection, $cb, array $image, array $item)
+{
+ if (!empty($image['id'])) {
+ $photo = Photo::selectFirst([], ['id' => $image['id']]);
+ } else {
+ $photo = Photo::createPhotoForExternalResource($image['url']);
+ }
+
+ $tempfile = tempnam(System::getTempPath(), 'cache');
+ file_put_contents($tempfile, Photo::getImageForPhoto($photo));
+
+ Logger::info('Uploading', ['id' => $item['id'], 'image' => $image]);
+ $media = $connection->upload('media/upload', ['media' => $tempfile]);
+
+ unlink($tempfile);
+
+ if (isset($media->media_id_string)) {
+ $media_id = $media->media_id_string;
+
+ if (!empty($image['description'])) {
+ $data = ['media_id' => $media->media_id_string,
+ 'alt_text' => ['text' => substr($image['description'], 0, 420)]];
+ $ret = $cb->media_metadata_create($data);
+ Logger::info('Metadata create', ['id' => $item['id'], 'data' => $data, 'return' => $ret]);
}
+ } else {
+ Logger::error('Failed upload', ['id' => $item['id'], 'image' => $image['url'], 'return' => $media]);
+ throw new Exception('Failed upload of ' . $image['url']);
}
+
+ return $media_id;
}
function twitter_delete_item(array $item)
$condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid']];
$thr_parent = Post::selectFirst(['uri', 'extid', 'author-link', 'author-nick', 'author-network'], $condition);
if (!DBA::isResult($thr_parent)) {
- Logger::warning('No parent found', ['thr-parent' => $item['thr-parent']]);
+ Logger::notice('No parent found', ['thr-parent' => $item['thr-parent']]);
return;
}
}
}
-function twitter_addon_admin_post(App $a)
+function twitter_addon_admin_post()
{
DI::config()->set('twitter', 'consumerkey', trim($_POST['consumerkey'] ?? ''));
DI::config()->set('twitter', 'consumersecret', trim($_POST['consumersecret'] ?? ''));
}
-function twitter_addon_admin(App $a, string &$o)
+function twitter_addon_admin(string &$o)
{
$t = Renderer::getMarkupTemplate('admin.tpl', 'addon/twitter/');
]);
}
-function twitter_cron(App $a)
+function twitter_cron()
{
- $last = DI::config()->get('twitter', 'last_poll');
+ $last = DI::keyValue()->get('twitter_last_poll');
$poll_interval = intval(DI::config()->get('twitter', 'poll_interval'));
if (!$poll_interval) {
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'twitter', 'k' => 'mirror_posts', 'v' => true]);
foreach ($pconfigs as $rr) {
Logger::notice('Fetching', ['user' => $rr['uid']]);
- Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], 'addon/twitter/twitter_sync.php', 1, (int) $rr['uid']);
+ Worker::add(['priority' => Worker::PRIORITY_MEDIUM, 'force_priority' => true], 'addon/twitter/twitter_sync.php', 1, (int) $rr['uid']);
}
$abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
}
Logger::notice('importing timeline', ['user' => $rr['uid']]);
- Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], 'addon/twitter/twitter_sync.php', 2, (int) $rr['uid']);
+ Worker::add(['priority' => Worker::PRIORITY_MEDIUM, 'force_priority' => true], 'addon/twitter/twitter_sync.php', 2, (int) $rr['uid']);
/*
// To-Do
// check for new contacts once a day
$next_contact_check = 0;
if($next_contact_check <= time()) {
- pumpio_getallusers($a, $rr["uid"]);
+ pumpio_getallusers($rr["uid"]);
DI::pConfig()->set($rr['uid'],'pumpio','contact_check',time());
}
*/
Logger::notice('twitter: cron_end');
- DI::config()->set('twitter', 'last_poll', time());
+ DI::keyValue()->set('twitter_last_poll', time());
}
-function twitter_expire(App $a)
+function twitter_expire()
{
$days = DI::config()->get('twitter', 'expire');
Logger::notice('End expiry');
}
-function twitter_prepare_body(App $a, array &$b)
+function twitter_prepare_body(array &$b)
{
if ($b['item']['network'] != Protocol::TWITTER) {
return;
if ($b['preview']) {
$max_char = 280;
$item = $b['item'];
- $item['plink'] = DI::baseUrl()->get() . '/display/' . $item['guid'];
+ $item['plink'] = DI::baseUrl() . '/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'], $condition);
if (DBA::isResult($orig_post)) {
$nicknameplain = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post['author-link']);
/**
* Parse Twitter status URLs since Twitter removed OEmbed
*
- * @param App $a
* @param array $b Expected format:
* [
* 'url' => [URL to parse],
* ]
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
-function twitter_parse_link(App $a, array &$b)
+function twitter_parse_link(array &$b)
{
// Only handle Twitter status URLs
if (!preg_match('#^https?://(?:mobile\.|www\.)?twitter.com/[^/]+/status/(\d+).*#', $b['url'], $matches)) {
return;
}
- $item = twitter_createpost($a, 0, $status, [], true, false, true);
+ $item = twitter_createpost(0, $status, [], true, false, true);
+ if (empty($item)) {
+ return;
+ }
if ($b['format'] == 'json') {
$images = [];
/**
* @brief Build the item array for the mirrored post
*
- * @param App $a Application class
* @param integer $uid User id
* @param object $post Twitter object with the post
*
* @return array item data to be posted
*/
-function twitter_do_mirrorpost(App $a, int $uid, $post)
+function twitter_do_mirrorpost(int $uid, $post)
{
$datarray['uid'] = $uid;
$datarray['extid'] = 'twitter::' . $post->id;
if (!empty($post->retweeted_status)) {
// We don't support nested shares, so we mustn't show quotes as shares on retweets
- $item = twitter_createpost($a, $uid, $post->retweeted_status, ['id' => 0], false, false, true, -1);
+ $item = twitter_createpost($uid, $post->retweeted_status, ['id' => 0], false, false, true, -1);
- if (empty($item['body'])) {
+ if (empty($item)) {
return [];
}
$datarray['body'] .= $item['body'] . '[/share]';
} else {
- $item = twitter_createpost($a, $uid, $post, ['id' => 0], false, false, false, -1);
+ $item = twitter_createpost($uid, $post, ['id' => 0], false, false, false, -1);
- if (empty($item['body'])) {
+ if (empty($item)) {
return [];
}
return $datarray;
}
-function twitter_fetchtimeline(App $a, int $uid)
+/**
+ * Fetches the Twitter user's own posts
+ *
+ * @param int $uid
+ * @return void
+ * @throws Exception
+ */
+function twitter_fetchtimeline(int $uid): void
{
$ckey = DI::config()->get('twitter', 'consumerkey');
$csecret = DI::config()->get('twitter', 'consumersecret');
$osecret = DI::pConfig()->get($uid, 'twitter', 'oauthsecret');
$lastid = DI::pConfig()->get($uid, 'twitter', 'lastid');
- $application_name = DI::config()->get('twitter', 'application_name');
+ $application_name = DI::keyValue()->get('twitter_application_name') ?? '';
if ($application_name == '') {
- $application_name = DI::baseUrl()->getHostname();
+ $application_name = DI::baseUrl()->getHost();
}
$connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
// Ensure to have the own contact
try {
- twitter_fetch_own_contact($a, $uid);
+ twitter_fetch_own_contact($uid);
} catch (TwitterOAuthException $e) {
- Logger::warning('Error fetching own contact', ['uid' => $uid, 'message' => $e->getMessage()]);
+ Logger::notice('Error fetching own contact', ['uid' => $uid, 'message' => $e->getMessage()]);
return;
}
try {
$items = $connection->get('statuses/user_timeline', $parameters);
} catch (TwitterOAuthException $e) {
- Logger::warning('Error fetching timeline', ['uid' => $uid, 'message' => $e->getMessage()]);
+ Logger::notice('Error fetching timeline', ['uid' => $uid, 'message' => $e->getMessage()]);
return;
}
}
if ($first_time) {
+ Logger::notice('First time, continue');
continue;
}
- if (!stristr($post->source, $application_name)) {
- Logger::info('Preparing mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]);
+ if (stristr($post->source, $application_name)) {
+ Logger::notice('Source is application name', ['source' => $post->source, 'application_name' => $application_name]);
+ continue;
+ }
+ Logger::info('Preparing mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]);
- $mirrorpost = twitter_do_mirrorpost($a, $uid, $post);
+ $mirrorpost = twitter_do_mirrorpost($uid, $post);
- if (empty($mirrorpost['body'])) {
- continue;
- }
+ if (empty($mirrorpost['body'])) {
+ Logger::notice('Body is empty', ['post' => $post, 'mirrorpost' => $mirrorpost]);
+ continue;
+ }
- Logger::info('Posting mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]);
+ Logger::info('Posting mirror post', ['twitter-id' => $post->id_str, 'uid' => $uid]);
- Post\Delayed::add($mirrorpost['extid'], $mirrorpost, PRIORITY_MEDIUM, Post\Delayed::UNPREPARED);
- }
+ Post\Delayed::add($mirrorpost['extid'], $mirrorpost, Worker::PRIORITY_MEDIUM, Post\Delayed::PREPARED);
}
}
DI::pConfig()->set($uid, 'twitter', 'lastid', $lastid);
Logger::info('Fetched friendship relation', ['user' => $uid, 'target' => $target, 'relation' => $relation]);
} catch (Throwable $e) {
- Logger::warning('Error fetching friendship status', ['uid' => $uid, 'target' => $target, 'message' => $e->getMessage()]);
+ Logger::notice('Error fetching friendship status', ['uid' => $uid, 'target' => $target, 'message' => $e->getMessage()]);
}
return $relation;
Contact::update($fields, ['id' => $cid]);
Contact::updateAvatar($cid, $avatar);
} else {
- Logger::warning('No contact found', ['fields' => $fields]);
+ Logger::notice('No contact found', ['fields' => $fields]);
}
$contact = DBA::selectFirst('contact', [], ['uid' => $uid, 'alias' => 'twitter::' . $data->id_str]);
if (!DBA::isResult($contact) && empty($cid)) {
- Logger::warning('User contact not found', ['uid' => $uid, 'twitter-id' => $data->id_str]);
+ Logger::notice('User contact not found', ['uid' => $uid, 'twitter-id' => $data->id_str]);
return 0;
} elseif (!$create_user) {
return $cid;
Contact::updateAvatar($contact_id, $avatar);
+ if (Contact::isSharing($contact_id, $uid, true) && DI::pConfig()->get($uid, 'twitter', 'auto_follow')) {
+ twitter_auto_follow($uid, $data);
+ }
+
return $contact_id;
}
+/**
+ * Follow a fediverse account that is proived in the name or the profile
+ *
+ * @param integer $uid
+ * @param object $data
+ */
+function twitter_auto_follow(int $uid, object $data)
+{
+ $addrpattern = '([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6})';
+
+ // Search for user@domain.tld in the name
+ if (preg_match('#' . $addrpattern . '#', $data->name, $match)) {
+ if (twitter_add_contact($match[1], true, $uid)) {
+ return;
+ }
+ }
+
+ // Search for @user@domain.tld in the description
+ if (preg_match('#@' . $addrpattern . '#', $data->description, $match)) {
+ if (twitter_add_contact($match[1], true, $uid)) {
+ return;
+ }
+ }
+
+ // Search for user@domain.tld in the description
+ // We don't probe here, since this could be a mail address
+ if (preg_match('#' . $addrpattern . '#', $data->description, $match)) {
+ if (twitter_add_contact($match[1], false, $uid)) {
+ return;
+ }
+ }
+
+ // Search for profile links in the description
+ foreach ($data->entities->description->urls as $url) {
+ if (!empty($url->expanded_url)) {
+ // We only probe on Mastodon style URL to reduce the number of unsuccessful probes
+ twitter_add_contact($url->expanded_url, strpos($url->expanded_url, '@'), $uid);
+ }
+ }
+}
+
+/**
+ * Check if the provided address is a fediverse account and adds it
+ *
+ * @param string $addr
+ * @param boolean $probe
+ * @param integer $uid
+ * @return boolean
+ */
+function twitter_add_contact(string $addr, bool $probe, int $uid): bool
+{
+ $contact = Contact::getByURL($addr, $probe ? null : false, ['id', 'url', 'network']);
+ if (empty($contact)) {
+ Logger::debug('Not a contact address', ['uid' => $uid, 'probe' => $probe, 'addr' => $addr]);
+ return false;
+ }
+
+ if (!in_array($contact['network'], Protocol::FEDERATED)) {
+ Logger::debug('Not a federated network', ['uid' => $uid, 'addr' => $addr, 'contact' => $contact]);
+ return false;
+ }
+
+ if (Contact::isSharing($contact['id'], $uid)) {
+ Logger::debug('Contact has already been added', ['uid' => $uid, 'addr' => $addr, 'contact' => $contact]);
+ return true;
+ }
+
+ Logger::info('Add contact', ['uid' => $uid, 'addr' => $addr, 'contact' => $contact]);
+ Worker::add(Worker::PRIORITY_LOW, 'AddContact', $uid, $contact['url']);
+
+ return true;
+}
+
/**
* @param string $screen_name
* @return stdClass|null
$parameters = ['screen_name' => $screen_name];
$user = $connection->get('users/show', $parameters);
} catch (TwitterOAuthException $e) {
- Logger::warning('Error fetching user', ['user' => $screen_name, 'message' => $e->getMessage()]);
+ Logger::notice('Error fetching user', ['user' => $screen_name, 'message' => $e->getMessage()]);
return null;
}
$replacementList = [];
foreach ($status->entities->hashtags AS $hashtag) {
- $replace = '#[url=' . DI::baseUrl()->get() . '/search?tag=' . $hashtag->text . ']' . $hashtag->text . '[/url]';
+ $replace = '#[url=' . DI::baseUrl() . '/search?tag=' . $hashtag->text . ']' . $hashtag->text . '[/url]';
$taglist['#' . $hashtag->text] = ['#', $hashtag->text, ''];
$replacementList[$hashtag->indices[0]] = [
/**
* Undocumented function
*
- * @param App $a
* @param integer $uid User ID
* @param object $post Incoming Twitter post
* @param array $self
* @param integer $uriId URI Id used to store tags. 0 = create a new one; -1 = don't store tags for this post.
* @return array item array
*/
-function twitter_createpost(App $a, int $uid, $post, array $self, $create_user, bool $only_existing_contact, bool $noquote, int $uriId = 0): array
+function twitter_createpost(int $uid, $post, array $self, $create_user, bool $only_existing_contact, bool $noquote, int $uriId = 0): array
{
$postarray = [];
$postarray['network'] = Protocol::TWITTER;
$item = Post::selectFirst(['uri'], ['uri' => $thr_parent, 'uid' => $uid]);
if (!DBA::isResult($item)) {
- $item = Post::selectFirst(['uri'], ['extid' => $thr_parent, 'uid' => $uid, 'gravity' => GRAVITY_COMMENT]);
+ $item = Post::selectFirst(['uri'], ['extid' => $thr_parent, 'uid' => $uid, 'gravity' => Item::GRAVITY_COMMENT]);
}
if (DBA::isResult($item)) {
if (DBA::isResult($self)) {
$contactid = $self['id'];
+ $postarray['owner-id'] = Contact::getIdForURL($self['url']);
$postarray['owner-name'] = $self['name'];
$postarray['owner-link'] = $self['url'];
$postarray['owner-avatar'] = $self['photo'];
$postarray['coord'] = $post->coordinates->coordinates[1] . ' ' . $post->coordinates->coordinates[0];
}
if (!empty($post->retweeted_status)) {
- $retweet = twitter_createpost($a, $uid, $post->retweeted_status, $self, false, false, $noquote);
+ $retweet = twitter_createpost($uid, $post->retweeted_status, $self, false, false, $noquote);
- if (empty($retweet['body'])) {
+ if (empty($retweet)) {
return [];
}
// CHange the other post into a reshare activity
$postarray['verb'] = Activity::ANNOUNCE;
- $postarray['gravity'] = GRAVITY_ACTIVITY;
+ $postarray['gravity'] = Item::GRAVITY_ACTIVITY;
$postarray['object-type'] = Activity\ObjectType::NOTE;
$postarray['thr-parent'] = $retweet['uri'];
// To avoid recursive share blocks we just provide the link to avoid removing quote context.
$postarray['body'] .= "\n\nhttps://twitter.com/" . $post->quoted_status->user->screen_name . "/status/" . $post->quoted_status->id_str;
} else {
- $quoted = twitter_createpost($a, 0, $post->quoted_status, $self, false, false, true);
- if (!empty($quoted['body'])) {
+ $quoted = twitter_createpost(0, $post->quoted_status, $self, false, false, true);
+ if (!empty($quoted)) {
Item::insert($quoted);
$post = Post::selectFirst(['guid', 'uri-id'], ['uri' => $quoted['uri'], 'uid' => 0]);
Logger::info('Stored quoted post', ['uid' => $uid, 'uri-id' => $uriId, 'post' => $post]);
}
}
-function twitter_fetchparentposts(App $a, int $uid, $post, TwitterOAuth $connection, array $self)
+function twitter_fetchparentposts(int $uid, $post, TwitterOAuth $connection, array $self)
{
Logger::info('Fetching parent posts', ['user' => $uid, 'post' => $post->id_str]);
try {
$post = twitter_statuses_show($post->in_reply_to_status_id_str, $connection);
} catch (TwitterOAuthException $e) {
- Logger::warning('Error fetching parent post', ['uid' => $uid, 'post' => $post->id_str, 'message' => $e->getMessage()]);
+ Logger::notice('Error fetching parent post', ['uid' => $uid, 'post' => $post->id_str, 'message' => $e->getMessage()]);
break;
}
if (!empty($posts)) {
foreach ($posts as $post) {
- $postarray = twitter_createpost($a, $uid, $post, $self, false, !DI::pConfig()->get($uid, 'twitter', 'create_user'), false);
+ $postarray = twitter_createpost($uid, $post, $self, false, !DI::pConfig()->get($uid, 'twitter', 'create_user'), false);
- if (empty($postarray['body'])) {
+ if (empty($postarray)) {
continue;
}
}
}
-function twitter_fetchhometimeline(App $a, int $uid)
+/**
+ * Fetches the posts received by the Twitter user
+ *
+ * @param int $uid
+ * @return void
+ * @throws Exception
+ */
+function twitter_fetchhometimeline(int $uid): void
{
$ckey = DI::config()->get('twitter', 'consumerkey');
$csecret = DI::config()->get('twitter', 'consumersecret');
Logger::info('Fetching timeline', ['uid' => $uid]);
- $application_name = DI::config()->get('twitter', 'application_name');
+ $application_name = DI::keyValue()->get('twitter_application_name') ?? '';
if ($application_name == '') {
- $application_name = DI::baseUrl()->getHostname();
+ $application_name = DI::baseUrl()->getHost();
}
$connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
try {
- $own_contact = twitter_fetch_own_contact($a, $uid);
+ $own_contact = twitter_fetch_own_contact($uid);
} catch (TwitterOAuthException $e) {
- Logger::warning('Error fetching own contact', ['uid' => $uid, 'message' => $e->getMessage()]);
+ Logger::notice('Error fetching own contact', ['uid' => $uid, 'message' => $e->getMessage()]);
return;
}
if (DBA::isResult($contact)) {
$own_id = $contact['nick'];
} else {
- Logger::warning('Own twitter contact not found', ['uid' => $uid]);
+ Logger::notice('Own twitter contact not found', ['uid' => $uid]);
return;
}
try {
$items = $connection->get('statuses/home_timeline', $parameters);
} catch (TwitterOAuthException $e) {
- Logger::warning('Error fetching home timeline', ['uid' => $uid, 'message' => $e->getMessage()]);
+ Logger::notice('Error fetching home timeline', ['uid' => $uid, 'message' => $e->getMessage()]);
return;
}
if (!is_array($items)) {
- Logger::warning('home timeline is no array', ['items' => $items]);
+ Logger::notice('home timeline is no array', ['items' => $items]);
return;
}
if (empty($items)) {
- Logger::notice('No new timeline content', ['uid' => $uid]);
+ Logger::info('No new timeline content', ['uid' => $uid]);
return;
}
}
if ($post->in_reply_to_status_id_str != '') {
- twitter_fetchparentposts($a, $uid, $post, $connection, $self);
+ twitter_fetchparentposts($uid, $post, $connection, $self);
}
Logger::info('Preparing post ' . $post->id_str . ' for user ' . $uid);
- $postarray = twitter_createpost($a, $uid, $post, $self, $create_user, true, false);
+ $postarray = twitter_createpost($uid, $post, $self, $create_user, true, false);
- if (empty($postarray['body']) || trim($postarray['body']) == '') {
- Logger::info('Empty body for post ' . $post->id_str . ' and user ' . $uid);
+ if (empty($postarray)) {
+ Logger::info('Empty post ' . $post->id_str . ' and user ' . $uid);
continue;
}
if (empty($postarray['thr-parent'])) {
$contact = DBA::selectFirst('contact', [], ['id' => $postarray['contact-id'], 'self' => false]);
if (DBA::isResult($contact) && Item::isRemoteSelf($contact, $postarray)) {
- $notify = PRIORITY_MEDIUM;
+ $notify = Worker::PRIORITY_MEDIUM;
}
}
+ $postarray['wall'] = (bool)$notify;
+
$item = Item::insert($postarray, $notify);
$postarray['id'] = $item;
try {
$items = $connection->get('statuses/mentions_timeline', $parameters);
} catch (TwitterOAuthException $e) {
- Logger::warning('Error fetching mentions', ['uid' => $uid, 'message' => $e->getMessage()]);
+ Logger::notice('Error fetching mentions', ['uid' => $uid, 'message' => $e->getMessage()]);
return;
}
if (!is_array($items)) {
- Logger::warning('mentions are no arrays', ['items' => $items]);
+ Logger::notice('mentions are no arrays', ['items' => $items]);
return;
}
}
if ($post->in_reply_to_status_id_str != '') {
- twitter_fetchparentposts($a, $uid, $post, $connection, $self);
+ twitter_fetchparentposts($uid, $post, $connection, $self);
}
- $postarray = twitter_createpost($a, $uid, $post, $self, false, !$create_user, false);
+ $postarray = twitter_createpost($uid, $post, $self, false, !$create_user, false);
- if (empty($postarray['body'])) {
+ if (empty($postarray)) {
continue;
}
Logger::info('Last mentions ID for user ' . $uid . ' is now ' . $lastid);
}
-function twitter_fetch_own_contact(App $a, int $uid)
+function twitter_fetch_own_contact(int $uid)
{
$ckey = DI::config()->get('twitter', 'consumerkey');
$csecret = DI::config()->get('twitter', 'consumersecret');
return $contact_id;
}
-function twitter_is_retweet(App $a, int $uid, string $body): bool
+function twitter_is_retweet(int $uid, string $body): bool
{
$body = trim($body);