]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
Merge pull request #9711 from MrPetovan/bug/fatal-errors
[friendica.git] / mod / item.php
index 6864dabacd6c367385791f087a1a654e39810c52..ed4e50348d0d0d00263864c9b05fb1ba92c15694 100644 (file)
@@ -50,6 +50,7 @@ use Friendica\Model\Notify\Type;
 use Friendica\Model\Photo;
 use Friendica\Model\Post;
 use Friendica\Model\Tag;
+use Friendica\Model\User;
 use Friendica\Network\HTTPException;
 use Friendica\Object\EMail\ItemCCEMail;
 use Friendica\Protocol\Activity;
@@ -195,8 +196,7 @@ function item_post(App $a) {
                $orig_post = Item::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]);
        }
 
-       $user = DBA::selectFirst('user', [], ['uid' => $profile_uid]);
-
+       $user = User::getById($profile_uid, ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
        if (!DBA::isResult($user) && !$toplevel_item_id) {
                return 0;
        }
@@ -261,17 +261,21 @@ function item_post(App $a) {
                $guid              = $orig_post['guid'];
                $extid             = $orig_post['extid'];
        } else {
-               $str_contact_allow = '';
-               $str_group_allow   = '';
-               $str_contact_deny  = '';
-               $str_group_deny    = '';
-
-               if (($_REQUEST['visibility'] ?? '') !== 'public') {
-                       $aclFormatter = DI::aclFormatter();
-                       $str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $user['allow_cid'] ?? '';
-                       $str_group_allow   = isset($_REQUEST['group_allow'])   ? $aclFormatter->toString($_REQUEST['group_allow'])   : $user['allow_gid'] ?? '';
-                       $str_contact_deny  = isset($_REQUEST['contact_deny'])  ? $aclFormatter->toString($_REQUEST['contact_deny'])  : $user['deny_cid']  ?? '';
-                       $str_group_deny    = isset($_REQUEST['group_deny'])    ? $aclFormatter->toString($_REQUEST['group_deny'])    : $user['deny_gid']  ?? '';
+               $aclFormatter = DI::aclFormatter();
+               $str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $user['allow_cid'] ?? '';
+               $str_group_allow   = isset($_REQUEST['group_allow'])   ? $aclFormatter->toString($_REQUEST['group_allow'])   : $user['allow_gid'] ?? '';
+               $str_contact_deny  = isset($_REQUEST['contact_deny'])  ? $aclFormatter->toString($_REQUEST['contact_deny'])  : $user['deny_cid']  ?? '';
+               $str_group_deny    = isset($_REQUEST['group_deny'])    ? $aclFormatter->toString($_REQUEST['group_deny'])    : $user['deny_gid']  ?? '';
+
+               $visibility = $_REQUEST['visibility'] ?? '';
+               if ($visibility === 'public') {
+                       // The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
+                       $str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
+               } else if ($visibility === 'custom') {
+                       // Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
+                       // case that would make it public. So we always append the author's contact id to the allowed contacts.
+                       // See https://github.com/friendica/friendica/issues/9672
+                       $str_contact_allow .= $aclFormatter->toString(Contact::getPublicIdByUserId($uid));
                }
 
                $title             = trim($_REQUEST['title']    ?? '');
@@ -750,7 +754,7 @@ function item_post(App $a) {
                                'type'  => Type::COMMENT,
                                'otype' => Notify\ObjectType::ITEM,
                                'verb'  => Activity::POST,
-                               'uid'   => $user['uid'],
+                               'uid'   => $profile_uid,
                                'cid'   => $datarray['author-id'],
                                'item'  => $datarray,
                                'link'  => DI::baseUrl() . '/display/' . urlencode($datarray['guid']),
@@ -760,7 +764,7 @@ function item_post(App $a) {
                                'type'  => Type::WALL,
                                'otype' => Notify\ObjectType::ITEM,
                                'verb'  => Activity::POST,
-                               'uid'   => $user['uid'],
+                               'uid'   => $profile_uid,
                                'cid'   => $datarray['author-id'],
                                'item'  => $datarray,
                                'link'  => DI::baseUrl() . '/display/' . urlencode($datarray['guid']),