]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/CheckRelMeProfileLink.php
Merge pull request #12814 from nupplaphil/bug/config_multi_serialize
[friendica.git] / src / Worker / CheckRelMeProfileLink.php
index 691931bdc3426ba4238eb3c6ae7edb813fe6cd75..334bea27e58bb61c639c5a68699a42a8b3ef8977 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 namespace Friendica\Worker;
 
 use DOMDocument;
-use Friendica\DI;
-use Friendica\Database\DBA;
+use Friendica\Content\Text\HTML;
 use Friendica\Core\Logger;
+use Friendica\DI;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
 use Friendica\Network\HTTPClient\Client\HttpClientOptions;
-use Friendica\Util\Network;
-use Friendica\Util\Strings;
+use GuzzleHttp\Psr7\Uri;
 
 /* This class is used to verify the homepage link of a user profile.
  * To do so, we look for rel="me" links in the given homepage, if one
@@ -55,48 +54,39 @@ class CheckRelMeProfileLink
         */
        public static function execute(int $uid)
        {
-               Logger::notice('Verifying the homepage', [$uid]);
-               $homepageUrlVerified = false;
+               Logger::notice('Verifying the homepage', ['uid' => $uid]);
+               Profile::update(['homepage_verified' => false], $uid);
+
                $owner = User::getOwnerDataById($uid);
-               Logger::notice(print_r($owner));
-               if (!empty($owner['homepage'])) {
-                       $xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
-                       $curlResult = DI::httpClient()->get($owner['homepage'], $accept_content = HttpClientAccept::HTML, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
-                       if ($curlResult->isTimeout()) {
-                               Logger::notice('Could not check homepage link of the user because the page loading request timed out.', [$uid, $owner['homepage']]);
-                       } else {
-                               $content = $curlResult->getBody();
-                               if (!$content) {
-                                       Logger::notice('Empty body of the fetched homepage link). Cannot verify the relation to profile of UID %s.', [$uid, $owner['homepage']]);
-                               } else {
-                                       $doc = new DOMDocument();
-                                       $doc->loadHTML($content);
-                                       if (!$doc) {
-                                               Logger::notice('Could not parse the content');
-                                       } else {
-                                               foreach ($doc->getElementsByTagName('a') as $link) {
-                                                       $rel = $link->getAttribute('rel');
-                                                       if ($rel=='me') {
-                                                               $href = $link->getAttribute('href');
-                                                               if (strpos($href, 'http')!==false) {
-                                                                       if (!$homepageUrlVerified) {
-                                                                               $homepageUrlVerified = Strings::compareLink($owner['url'], $href);
-                                                                       }
-                                                               }
-                                                       }
-                                               }
-                                       }
-                                       if ($homepageUrlVerified) {
-                                               Profile::update(['homepage_verified' => 1], $uid);
-                                               Logger::notice('Homepage URL verified', [$uid, $owner['homepage']]);
-                                       } else {
-                                               Profile::update(['homepage_verified' => 0], $uid);
-                                               Logger::notice('Homepage URL could not be verified', [$uid, $owner['homepage']]);
-                                       }
-                               }
-                       }
+               if (empty($owner['homepage'])) {
+                       Logger::notice('The user has no homepage link.', ['uid' => $uid]);
+                       return;
+               }
+
+               $xrd_timeout = DI::config()->get('system', 'xrd_timeout');
+               $curlResult  = DI::httpClient()->get($owner['homepage'], HttpClientAccept::HTML, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
+               if (!$curlResult->isSuccess()) {
+                       Logger::notice('Could not cURL the homepage URL', ['owner homepage' => $owner['homepage']]);
+                       return;
+               }
+
+               $content = $curlResult->getBody();
+               if (!$content) {
+                       Logger::notice('Empty body of the fetched homepage link). Cannot verify the relation to profile of UID %s.', ['uid' => $uid, 'owner homepage' => $owner['homepage']]);
+                       return;
+               }
+
+               $doc = new DOMDocument();
+               if (!@$doc->loadHTML($content)) {
+                       Logger::notice('Could not parse the content');
+                       return;
+               }
+
+               if (HTML::checkRelMeLink($doc, new Uri($owner['url']))) {
+                       Profile::update(['homepage_verified' => true], $uid);
+                       Logger::notice('Homepage URL verified', ['uid' => $uid, 'owner homepage' => $owner['homepage']]);
                } else {
-                       Logger::notice('The user has no homepage link.', [$uid]);
+                       Logger::notice('Homepage URL could not be verified', ['uid' => $uid, 'owner homepage' => $owner['homepage']]);
                }
        }
 }