]> git.mxchange.org Git - friendica-addons.git/blobdiff - twitter/twitter.php
[twitter] Return null in the probe_detect hook result key on unsuccessful probe
[friendica-addons.git] / twitter / twitter.php
index f35ff8d3e6d036284f55f560cc89796b2fd3803c..aaa378d18098f618693bbe0f8b27eabbe7979586 100644 (file)
@@ -6,6 +6,7 @@
  * 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.
@@ -525,7 +526,12 @@ function twitter_probe_detect(array &$hookData)
        $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'] = [];
        }
 }
 
@@ -1099,7 +1105,7 @@ function twitter_prepare_body(array &$b)
        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' => DI::userSession()->getLocalUserId()];
                $orig_post = Post::selectFirst(['author-link'], $condition);
@@ -1288,10 +1294,10 @@ function twitter_fetchtimeline(int $uid): void
        $osecret = DI::pConfig()->get($uid, 'twitter', 'oauthsecret');
        $lastid  = DI::pConfig()->get($uid, 'twitter', 'lastid');
 
-       $application_name = DI::keyValue()->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);
@@ -1693,7 +1699,7 @@ function twitter_expand_entities($body, stdClass $status)
        $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]] = [
@@ -2187,10 +2193,10 @@ function twitter_fetchhometimeline(int $uid): void
 
        Logger::info('Fetching timeline', ['uid' => $uid]);
 
-       $application_name = DI::keyValue()->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);