]> git.mxchange.org Git - friendica.git/commitdiff
Refactor Item model
authorArt4 <art4@wlabs.de>
Mon, 18 Nov 2024 23:23:47 +0000 (23:23 +0000)
committerArt4 <art4@wlabs.de>
Mon, 18 Nov 2024 23:23:47 +0000 (23:23 +0000)
src/Model/Item.php

index ffdb9c67f0bc6186a1e40df0f7995b42d11f405c..53d0da290977a7d24450430912594d036748e4f2 100644 (file)
@@ -193,6 +193,7 @@ class Item
                        $fields['vid'] = Verb::getID($fields['verb']);
                }
 
+               $previous = [];
                if (!empty($fields['edited'])) {
                        $previous = Post::selectFirst(['edited'], $condition);
                }
@@ -856,6 +857,8 @@ class Item
 
                $priority = Worker::PRIORITY_HIGH;
 
+               $copy_permissions = false;
+
                // If it is a posting where users should get notifications, then define it as wall posting
                if ($notify) {
                        $item = self::prepareOriginPost($item);
@@ -3199,7 +3202,7 @@ class Item
                } elseif ($remote_user) {
                        // Authenticated visitor - fetch the matching permissionsets
                        $permissionSets = DI::permissionSet()->selectByContactId($remote_user, $owner_id);
-                       if (!empty($permissionSets)) {
+                       if (count($permissionSets) > 0) {
                                $condition = [
                                        "(`private` != ? OR (`private` = ? AND `wall`
                                        AND `psid` IN (" . implode(', ', array_fill(0, count($permissionSets), '?')) . ")))",
@@ -3228,17 +3231,12 @@ class Item
                        $table = DBA::quoteIdentifier($table) . '.';
                }
 
-               /*
-                * Construct permissions
-                *
-                * default permissions - anonymous user
-                */
-               $sql = sprintf(" AND " . $table . "`private` != %d", self::PRIVATE);
-
                // Profile owner - everything is visible
                if ($local_user && ($local_user == $owner_id)) {
-                       $sql = '';
-               } elseif ($remote_user) {
+                       return '';
+               }
+
+               if ($remote_user) {
                        /*
                         * Authenticated visitor. Unless pre-verified,
                         * check that the contact belongs to this $owner_id
@@ -3248,16 +3246,21 @@ class Item
                         */
                        $permissionSets = DI::permissionSet()->selectByContactId($remote_user, $owner_id);
 
-                       if (!empty($permissionSets)) {
+                       $sql_set = '';
+
+                       if (count($permissionSets) > 0) {
                                $sql_set = sprintf(" OR (" . $table . "`private` = %d AND " . $table . "`wall` AND " . $table . "`psid` IN (", self::PRIVATE) . implode(',', $permissionSets->column('id')) . "))";
-                       } else {
-                               $sql_set = '';
                        }
 
-                       $sql = sprintf(" AND (" . $table . "`private` != %d", self::PRIVATE) . $sql_set . ")";
+                       return sprintf(" AND (" . $table . "`private` != %d", self::PRIVATE) . $sql_set . ")";
                }
 
-               return $sql;
+               /*
+                * Construct permissions
+                *
+                * default permissions - anonymous user
+                */
+               return sprintf(" AND " . $table . "`private` != %d", self::PRIVATE);
        }
 
        /**
@@ -3381,6 +3384,7 @@ class Item
                $shared_uri_id      = 0;
                $shared_links       = [];
                $quote_shared_links = [];
+               $shared_item        = [];
 
                $shared = DI::contentItem()->getSharedPost($item, $fields);
                if (!empty($shared['post'])) {
@@ -3424,6 +3428,8 @@ class Item
                        }
                }
 
+               $sharedSplitAttachments = [];
+
                if (!empty($shared_item['uri-id'])) {
                        $shared_uri_id = $shared_item['uri-id'];
                        $shared_links[] = strtolower($shared_item['plink']);
@@ -3497,7 +3503,7 @@ class Item
                        $s = self::addGallery($s, $sharedSplitAttachments['visual']);
                        $s = self::addVisualAttachments($sharedSplitAttachments['visual'], $shared_item, $s, true);
                        $s = self::addLinkAttachment($shared_uri_id ?: $item['uri-id'], $sharedSplitAttachments, $body, $s, true, $quote_shared_links);
-                       $s = self::addNonVisualAttachments($sharedSplitAttachments['additional'], $item, $s, true);
+                       $s = self::addNonVisualAttachments($sharedSplitAttachments['additional'], $item, $s);
                        $body = BBCode::removeSharedData($body);
                }
 
@@ -3510,7 +3516,7 @@ class Item
                $s = self::addGallery($s, $itemSplitAttachments['visual']);
                $s = self::addVisualAttachments($itemSplitAttachments['visual'], $item, $s, false);
                $s = self::addLinkAttachment($item['uri-id'], $itemSplitAttachments, $body, $s, false, $shared_links);
-               $s = self::addNonVisualAttachments($itemSplitAttachments['additional'], $item, $s, false);
+               $s = self::addNonVisualAttachments($itemSplitAttachments['additional'], $item, $s);
                $s = self::addQuestions($item, $s);
 
                // Map.