]> git.mxchange.org Git - friendica.git/commitdiff
Improve probe_detect hook
authorHypolite Petovan <hypolite@mrpetovan.com>
Tue, 23 Nov 2021 22:46:20 +0000 (17:46 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 23 Nov 2021 22:46:20 +0000 (17:46 -0500)
- Remove Twitter probe from core
- Allow hook function to better abort the probe_detect process

doc/Addons.md
src/Network/Probe.php

index 230e9e93b96910688df22412c4e0095d02feaa35..51901fb95886e2d11651a2249209e626754a0deb 100644 (file)
@@ -477,7 +477,7 @@ Hook data:
 - **uri** (input): the profile URI.
 - **network** (input): the target network (can be empty for auto-detection).
 - **uid** (input): the user to return the contact data for (can be empty for public contacts).
-- **result** (output): Set by the hook function to indicate a successful detection.
+- **result** (output): Leave null if address isn't relevant to the connector, set to contact array if probe is successful, false otherwise.
 
 ### support_follow
 
index 10d03fa038a755bbbd3583be010441a4fb0f449a..ee36651d6d1719c839afebed6a4bbd8d8e0c1343 100644 (file)
@@ -682,26 +682,18 @@ class Probe
                        'uri'     => $uri,
                        'network' => $network,
                        'uid'     => $uid,
-                       'result'  => [],
+                       'result'  => null,
                ];
 
                Hook::callAll('probe_detect', $hookData);
 
-               if ($hookData['result']) {
-                       if (!is_array($hookData['result'])) {
-                               return [];
-                       } else {
-                               return $hookData['result'];
-                       }
+               if (isset($hookData['result'])) {
+                       return is_array($hookData['result']) ? $hookData['result'] : [];
                }
 
                $parts = parse_url($uri);
 
-               if (!empty($parts['scheme']) && !empty($parts['host'])) {
-                       if (in_array($parts['host'], ['twitter.com', 'mobile.twitter.com'])) {
-                               return self::twitter($uri);
-                       }
-               } elseif (strstr($uri, '@')) {
+               if (empty($parts['scheme']) || !empty($parts['host']) && strstr($uri, '@')) {
                        // If the URI starts with "mailto:" then jump directly to the mail detection
                        if (strpos($uri, 'mailto:') !== false) {
                                $uri = str_replace('mailto:', '', $uri);
@@ -711,12 +703,6 @@ class Probe
                        if ($network == Protocol::MAIL) {
                                return self::mail($uri, $uid);
                        }
-
-                       if (Strings::endsWith($uri, '@twitter.com')
-                               || Strings::endsWith($uri, '@mobile.twitter.com')
-                       ) {
-                               return self::twitter($uri);
-                       }
                } else {
                        Logger::info('URI was not detectable', ['uri' => $uri]);
                        return [];
@@ -1742,33 +1728,6 @@ class Probe
                return $data;
        }
 
-       /**
-        * Check for twitter contact
-        *
-        * @param string $uri
-        *
-        * @return array twitter data
-        */
-       private static function twitter($uri)
-       {
-               if (preg_match('=([^@]+)@(?:mobile\.)?twitter\.com$=i', $uri, $matches)) {
-                       $nick = $matches[1];
-               } elseif (preg_match('=^https?://(?:mobile\.)?twitter\.com/(.+)=i', $uri, $matches)) {
-                       $nick = $matches[1];
-               } else {
-                       return [];
-               }
-
-               $data = [];
-               $data['url'] = 'https://twitter.com/' . $nick;
-               $data['addr'] = $nick . '@twitter.com';
-               $data['nick'] = $data['name'] = $nick;
-               $data['network'] = Protocol::TWITTER;
-               $data['baseurl'] = 'https://twitter.com';
-
-               return $data;
-       }
-
        /**
         * Checks HTML page for RSS feed link
         *