]> git.mxchange.org Git - friendica.git/commitdiff
Fix noscrape publishing and pulling, added header
authorMichael <heluecht@pirati.ca>
Thu, 17 Jun 2021 11:23:32 +0000 (11:23 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 17 Jun 2021 11:23:32 +0000 (11:23 +0000)
16 files changed:
database.sql
doc/database/db_apcontact.md
doc/database/db_contact.md
mod/cal.php
mod/photos.php
mod/videos.php
src/Core/Update.php
src/Model/APContact.php
src/Model/Contact.php
src/Model/Profile.php
src/Module/NoScrape.php
src/Network/Probe.php
src/Object/Api/Mastodon/Account.php
src/Protocol/ActivityPub.php
static/dbstructure.config.php
static/dbview.config.php

index 7102b40df63003654416751f65a71599c18954b2..9e9427bdaae77b91bd6827d3b3fa5328a63fbbfa 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2021.06-rc (Siberian Iris)
--- DB_UPDATE_VERSION 1422
+-- DB_UPDATE_VERSION 1423
 -- ------------------------------------------
 
 
@@ -120,6 +120,7 @@ CREATE TABLE IF NOT EXISTS `contact` (
        `photo` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo of the contact',
        `thumb` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (thumb size)',
        `micro` varchar(255) DEFAULT '' COMMENT 'Link to the profile photo (micro size)',
+       `header` varchar(255) COMMENT 'Header picture',
        `site-pubkey` text COMMENT '',
        `issued-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
        `dfrn-id` varchar(255) NOT NULL DEFAULT '' COMMENT '',
@@ -343,6 +344,7 @@ CREATE TABLE IF NOT EXISTS `apcontact` (
        `name` varchar(255) COMMENT '',
        `about` text COMMENT '',
        `photo` varchar(255) COMMENT '',
+       `header` varchar(255) COMMENT 'Header picture',
        `addr` varchar(255) COMMENT '',
        `alias` varchar(255) COMMENT '',
        `pubkey` text COMMENT '',
@@ -2256,6 +2258,7 @@ CREATE VIEW `owner-view` AS SELECT
        `contact`.`photo` AS `photo`,
        `contact`.`thumb` AS `thumb`,
        `contact`.`micro` AS `micro`,
+       `contact`.`header` AS `header`,
        `contact`.`site-pubkey` AS `site-pubkey`,
        `contact`.`issued-id` AS `issued-id`,
        `contact`.`dfrn-id` AS `dfrn-id`,
index 539be251ae7805ae757c7b885daf930a24acd2b2..03a4acd4215346415bc48de94cbf4736ac431ae8 100644 (file)
@@ -21,6 +21,7 @@ Fields
 | name             |                              | varchar(255)   | YES  |     | NULL                |       |
 | about            |                              | text           | YES  |     | NULL                |       |
 | photo            |                              | varchar(255)   | YES  |     | NULL                |       |
+| header           | Header picture               | varchar(255)   | YES  |     | NULL                |       |
 | addr             |                              | varchar(255)   | YES  |     | NULL                |       |
 | alias            |                              | varchar(255)   | YES  |     | NULL                |       |
 | pubkey           |                              | text           | YES  |     | NULL                |       |
index 0e04c1ece8530e7fad7821f7f0d501c0a511e6c2..23a3b533af5942c86265ea5141593620f6438299 100644 (file)
@@ -30,6 +30,7 @@ Fields
 | photo                     | Link to the profile photo of the contact                  | varchar(255)       | YES  |     |                     |                |
 | thumb                     | Link to the profile photo (thumb size)                    | varchar(255)       | YES  |     |                     |                |
 | micro                     | Link to the profile photo (micro size)                    | varchar(255)       | YES  |     |                     |                |
+| header                    | Header picture                                            | varchar(255)       | YES  |     | NULL                |                |
 | site-pubkey               |                                                           | text               | YES  |     | NULL                |                |
 | issued-id                 |                                                           | varchar(255)       | NO   |     |                     |                |
 | dfrn-id                   |                                                           | varchar(255)       | NO   |     |                     |                |
index c867582a7f96e6bcbbc12a677cb5334c6e4f63ff..f3ff80cf99b3239d4cd8d5689f548a63c3acbdf1 100644 (file)
@@ -67,7 +67,7 @@ function cal_init(App $a)
                return;
        }
 
-       $a->profile = Profile::getByNickname($nick, $a->profile_uid);
+       $a->profile = Profile::getByNickname($nick);
        if (empty($a->profile)) {
                throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
        }
index d23c454c036499bc4595b2ba81863afde5f1aff3..b0bd79b8f52afd17dfdf9034363d27f31c028821 100644 (file)
@@ -73,7 +73,7 @@ function photos_init(App $a) {
                $a->profile_uid = $user['uid'];
                $is_owner = (local_user() && (local_user() == $a->profile_uid));
 
-               $profile = Profile::getByNickname($nick, $a->profile_uid);
+               $profile = Profile::getByNickname($nick);
 
                $account_type = Contact::getAccountType($profile);
 
index 020e5f6cb10c900ca56037b3de87a5696b2e47ca..ccf1cba141a764c94b1aae18dd0ab84a5919c3e6 100644 (file)
@@ -56,7 +56,7 @@ function videos_init(App $a)
                $a->data['user'] = $user[0];
                $a->profile_uid = $user[0]['uid'];
 
-               $profile = Profile::getByNickname($nick, $a->profile_uid);
+               $profile = Profile::getByNickname($nick);
 
                $account_type = Contact::getAccountType($profile);
 
index 6b4d6f286bea8f2b2193a7a7cedf3c172b8306a5..fa3c6b62d0fa15121791e04d85686ccffd292176 100644 (file)
@@ -213,6 +213,8 @@ class Update
                                        if ($sendMail) {
                                                self::updateSuccessful($stored, $current);
                                        }
+                               } else {
+                                       Logger::warning('Update lock could not be acquired');
                                }
                        }
                }
index 8795b22aa506f2e74d84c0373e00375bea21c509..bd6931c4cbe566a99bd8109bccf2fffb3a831aa0 100644 (file)
@@ -211,6 +211,11 @@ class APContact
                        $apcontact['photo'] = JsonLD::fetchElement($compacted['as:icon'], 'as:url', '@id');
                }
 
+               $apcontact['header'] = JsonLD::fetchElement($compacted, 'as:image', '@id');
+               if (is_array($apcontact['header']) || !empty($compacted['as:image']['as:url']['@id'])) {
+                       $apcontact['header'] = JsonLD::fetchElement($compacted['as:image'], 'as:url', '@id');
+               }
+
                if (empty($apcontact['alias'])) {
                        $apcontact['alias'] = JsonLD::fetchElement($compacted, 'as:url', '@id');
                        if (is_array($apcontact['alias'])) {
index f196f6f6a7682c8c79e23f821d0e8a2069183994..f0d1c62bd93d38a8302e383d3aa1fed6fbf4ba0d 100644 (file)
@@ -1103,7 +1103,7 @@ class Contact
                if (($uid == 0) && (empty($data['network']) || ($data['network'] == Protocol::PHANTOM))) {
                        // Fetch data for the public contact via the first found personal contact
                        /// @todo Check if this case can happen at all (possibly with mail accounts?)
-                       $fields = ['name', 'nick', 'url', 'addr', 'alias', 'avatar', 'contact-type',
+                       $fields = ['name', 'nick', 'url', 'addr', 'alias', 'avatar', 'header', 'contact-type',
                                'keywords', 'location', 'about', 'unsearchable', 'batch', 'notify', 'poll',
                                'request', 'confirm', 'poco', 'subscribe', 'network', 'baseurl', 'gsid'];
 
@@ -1949,8 +1949,8 @@ class Contact
                // These fields aren't updated by this routine:
                // 'xmpp', 'sensitive'
 
-               $fields = ['uid', 'avatar', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe', 'manually-approve',
-                       'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
+               $fields = ['uid', 'avatar', 'header', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
+                       'manually-approve', 'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
                        'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey', 'last-item'];
                $contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
                if (!DBA::isResult($contact)) {
index 03e35c02b010a6bf91ed95afdda927d6e0d0ae8d..b32c58fc9313c97334471e3301cf910e6c08ee11 100644 (file)
@@ -283,24 +283,17 @@ class Profile
        }
 
        /**
-        * Get all profile data of a local user
-        *
-        * If the viewer is an authenticated remote viewer, the profile displayed is the
-        * one that has been configured for his/her viewing in the Contact manager.
-        * Passing a non-zero profile ID can also allow a preview of a selected profile
-        * by the owner
+        * Get the profile for the given nick name
         *
         * Includes all available profile data
         *
         * @param string $nickname   nick
-        * @param int    $uid        uid
-        * @param int    $profile_id ID of the profile
         * @return array
         * @throws \Exception
         */
-       public static function getByNickname($nickname, $uid = 0)
+       public static function getByNickname($nickname)
        {
-               $profile = DBA::selectFirst('owner-view', [], ['nickname' => $nickname, 'uid' => $uid]);
+               $profile = DBA::selectFirst('owner-view', [], ['nickname' => $nickname]);
                return $profile;
        }
 
index a76b3a951737676cf556a7162fadd01fe10c77a6..56fe4eab461ca61bc8778775ff91e0a95c25fea5 100644 (file)
@@ -50,7 +50,7 @@ class NoScrape extends BaseModule
                        System::jsonError(403, 'Authentication required');
                }
 
-               $profile = Profile::getByNickname($which, local_user());
+               $profile = Profile::getByNickname($which);
 
                if (empty($profile['uid'])) {
                        System::jsonError(404, 'Profile not found');
index 5f3c516820f544f10fe2bfd6e71fcd68797fd822..d6ae415d30b13aee085a22de4e7572c8e99d15af 100644 (file)
@@ -87,8 +87,8 @@ class Probe
         */
        private static function rearrangeData($data)
        {
-               $fields = ["name", "nick", "guid", "url", "addr", "alias", "photo", "account-type",
-                               "community", "keywords", "location", "about", "hide",
+               $fields = ["name", "nick", "guid", "url", "addr", "alias", "photo", "header",
+                               "account-type", "community", "keywords", "location", "about", "hide",
                                "batch", "notify", "poll", "request", "confirm", "subscribe", "poco",
                                "following", "followers", "inbox", "outbox", "sharedinbox",
                                "priority", "network", "pubkey", "manually-approve", "baseurl", "gsid"];
@@ -1016,18 +1016,18 @@ class Probe
                $curlResult = DI::httpRequest()->get($noscrape_url);
                if ($curlResult->isTimeout()) {
                        self::$istimeout = true;
-                       return [];
+                       return $data;
                }
                $content = $curlResult->getBody();
                if (!$content) {
                        Logger::info('Empty body', ['url' => $noscrape_url]);
-                       return [];
+                       return $data;
                }
 
                $json = json_decode($content, true);
                if (!is_array($json)) {
                        Logger::info('No json data', ['url' => $noscrape_url]);
-                       return [];
+                       return $data;
                }
 
                if (!empty($json["fn"])) {
@@ -2222,7 +2222,7 @@ class Probe
 
                $data = ['name' => $profile['name'], 'nick' => $profile['nick'], 'guid' => $approfile['diaspora:guid'] ?? '',
                        'url' => $profile['url'], 'addr' => $profile['addr'], 'alias' => $profile['alias'],
-                       'photo' => $profile['photo'], 'account-type' => $profile['contact-type'],
+                       'photo' => $profile['photo'], 'header' => $profile['header'], 'account-type' => $profile['contact-type'],
                        'community' => ($profile['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY),
                        'keywords' => $profile['keywords'], 'location' => $profile['location'], 'about' => $profile['about'], 
                        'hide' => !$profile['net-publish'], 'batch' => '', 'notify' => $profile['notify'],
index f9c77675fa73680714af79ccea7b47e0ba28a861..691e62048d68dc836ccbe9f2d27729ab89dab5de 100644 (file)
@@ -114,9 +114,8 @@ class Account extends BaseDataTransferObject
                $this->url             = $publicContact['url'];
                $this->avatar          = $userContact['avatar'] ?? $publicContact['avatar'];
                $this->avatar_static   = $userContact['avatar'] ?? $publicContact['avatar'];
-               // No header picture in Friendica
-               $this->header          = '';
-               $this->header_static   = '';
+               $this->header          = ($userContact['header'] ?? $publicContact['header']) ?? '';
+               $this->header_static   = ($userContact['header'] ?? $publicContact['header']) ?? '';
                $this->followers_count = $apcontact['followers_count'] ?? 0;
                $this->following_count = $apcontact['following_count'] ?? 0;
                $this->statuses_count  = $apcontact['statuses_count'] ?? 0;
index c42dad2eb39c26dc6b6990f0e924235d05455b0a..6f9d7cf2485d78ecdc2015da5f99379d3c8842cf 100644 (file)
@@ -151,6 +151,7 @@ class ActivityPub
                $profile['outbox'] = $apcontact['outbox'];
                $profile['sharedinbox'] = $apcontact['sharedinbox'];
                $profile['photo'] = $apcontact['photo'];
+               $profile['header'] = $apcontact['header'];
                $profile['account-type'] = self::getAccountType($apcontact);
                $profile['community'] = ($profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
                // $profile['keywords']
index da33e234262f97e7eccc2bfef21a63c6fdd69757..53e341507b25626d5b1db95ff02af3f0d4a1aa5c 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1422);
+       define('DB_UPDATE_VERSION', 1423);
 }
 
 return [
@@ -177,6 +177,7 @@ return [
                        "photo" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo of the contact"],
                        "thumb" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo (thumb size)"],
                        "micro" => ["type" => "varchar(255)", "default" => "", "comment" => "Link to the profile photo (micro size)"],
+                       "header" => ["type" => "varchar(255)", "comment" => "Header picture"],
                        "site-pubkey" => ["type" => "text", "comment" => ""],
                        "issued-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
                        "dfrn-id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
@@ -404,6 +405,7 @@ return [
                        "name" => ["type" => "varchar(255)", "comment" => ""],
                        "about" => ["type" => "text", "comment" => ""],
                        "photo" => ["type" => "varchar(255)", "comment" => ""],
+                       "header" => ["type" => "varchar(255)", "comment" => "Header picture"],
                        "addr" => ["type" => "varchar(255)", "comment" => ""],
                        "alias" => ["type" => "varchar(255)", "comment" => ""],
                        "pubkey" => ["type" => "text", "comment" => ""],
index 6dd8cfe3bd5792f707c8a3f0bfccea09470137c0..01cda59a62c0da7b849f137faf2eaf5e8cd0878e 100644 (file)
                        "photo" => ["contact", "photo"],
                        "thumb" => ["contact", "thumb"],
                        "micro" => ["contact", "micro"],
+                       "header" => ["contact", "header"],
                        "site-pubkey" => ["contact", "site-pubkey"],
                        "issued-id" => ["contact", "issued-id"],
                        "dfrn-id" => ["contact", "dfrn-id"],