]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/NoScrape.php
Merge pull request #12562 from MrPetovan/bug/notices
[friendica.git] / src / Module / NoScrape.php
index c5a66c9bb6c972133cc9823c96c4eef80d2a386d..f5c5c725e0344928cca6bbd0f745f94025f0faed 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 namespace Friendica\Module;
 
 use Friendica\BaseModule;
-use Friendica\Core\Protocol;
 use Friendica\Core\System;
-use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\APContact;
 use Friendica\Model\User;
 
 /**
@@ -35,14 +34,14 @@ use Friendica\Model\User;
  */
 class NoScrape extends BaseModule
 {
-       public function rawContent()
+       protected function rawContent(array $request = [])
        {
                $a = DI::app();
 
-               if (isset(static::$parameters['nick'])) {
+               if (isset($this->parameters['nick'])) {
                        // Get infos about a specific nick (public)
-                       $which = static::$parameters['nick'];
-               } elseif (local_user() && isset(static::$parameters['profile']) && DI::args()->get(2) == 'view') {
+                       $which = $this->parameters['nick'];
+               } elseif (DI::userSession()->getLocalUserId() && isset($this->parameters['profile']) && DI::args()->get(2) == 'view') {
                        // view infos about a known profile (needs a login)
                        $which = $a->getLoggedInUserNickname();
                } else {
@@ -89,32 +88,14 @@ class NoScrape extends BaseModule
                }
 
                if (!($owner['hide-friends'] ?? false)) {
-                       $json_info['contacts'] = DBA::count('contact',
-                               [
-                                       'uid'     => $owner['uid'],
-                                       'self'    => 0,
-                                       'blocked' => 0,
-                                       'pending' => 0,
-                                       'hidden'  => 0,
-                                       'archive' => 0,
-                                       'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]
-                               ]);
+                       $apcontact = APContact::getByURL($owner['url']);
+                       $json_info['contacts'] = max($apcontact['following_count'], $apcontact['followers_count']);
                }
 
                // We display the last activity (post or login), reduced to year and week number
-               $last_active = 0;
-               $condition   = ['uid' => $owner['uid'], 'self' => true];
-               $contact     = DBA::selectFirst('contact', ['last-item'], $condition);
-               if (DBA::isResult($contact)) {
-                       $last_active = strtotime($contact['last-item']);
-               }
-
-               $condition = ['uid' => $owner['uid']];
-               $user      = DBA::selectFirst('user', ['login_date'], $condition);
-               if (DBA::isResult($user)) {
-                       if ($last_active < strtotime($user['login_date'])) {
-                               $last_active = strtotime($user['login_date']);
-                       }
+               $last_active = strtotime($owner['last-item']);
+               if ($owner['last-activity'] && $last_active < strtotime($owner['last-activity'])) {
+                       $last_active = strtotime($owner['last-activity']);
                }
                $json_info['last-activity'] = date('o-W', $last_active);
 
@@ -122,7 +103,7 @@ class NoScrape extends BaseModule
                $profile_fields = ['about', 'locality', 'region', 'postal-code', 'country-name', 'xmpp', 'matrix'];
                foreach ($profile_fields as $field) {
                        if (!empty($owner[$field])) {
-                               $json_info["$field"] = $owner[$field];
+                               $json_info[$field] = $owner[$field];
                        }
                }