]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
Merge pull request #5574 from annando/issue-5436
[friendica.git] / src / Protocol / DFRN.php
index 29d3e7bfe835f7b14a8bd9ab6e1a0b4df66be6c4..296949ddcdb4a1e72799ca744afd83c3a08a0398 100644 (file)
@@ -20,10 +20,11 @@ use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
+use Friendica\Model\Conversation;
 use Friendica\Model\Event;
 use Friendica\Model\GContact;
-use Friendica\Model\Group;
 use Friendica\Model\Item;
+use Friendica\Model\PermissionSet;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
 use Friendica\Object\Image;
@@ -123,7 +124,7 @@ class DFRN
 
                // default permissions - anonymous user
 
-               $sql_extra = " AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = '' ";
+               $sql_extra = " AND NOT `item`.`private` ";
 
                $r = q(
                        "SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
@@ -175,30 +176,14 @@ class DFRN
 
                        $contact = $r[0];
                        include_once 'include/security.php';
-                       $groups = Group::getIdsByContactId($contact['id']);
 
-                       if (count($groups)) {
-                               for ($x = 0; $x < count($groups); $x ++) {
-                                       $groups[$x] = '<' . intval($groups[$x]) . '>' ;
-                               }
+                       $set = PermissionSet::get($owner_id, $contact['id']);
 
-                               $gs = implode('|', $groups);
+                       if (!empty($set)) {
+                               $sql_extra = " AND `item`.`psid` IN (" . implode(',', $set) .")";
                        } else {
-                               $gs = '<<>>' ; // Impossible to match
-                       }
-
-                       $sql_extra = sprintf(
-                               "
-                               AND ( `allow_cid` = '' OR     `allow_cid` REGEXP '<%d>' )
-                               AND ( `deny_cid`  = '' OR NOT `deny_cid`  REGEXP '<%d>' )
-                               AND ( `allow_gid` = '' OR     `allow_gid` REGEXP '%s' )
-                               AND ( `deny_gid`  = '' OR NOT `deny_gid`  REGEXP '%s')
-                       ",
-                               intval($contact['id']),
-                               intval($contact['id']),
-                               DBA::escape($gs),
-                               DBA::escape($gs)
-                       );
+                               $sql_extra = " AND NOT `item`.`private`";
+                       }
                }
 
                if ($public_feed) {
@@ -562,14 +547,14 @@ class DFRN
                }
 
                // For backward compatibility we keep this element
-               if ($owner['page-flags'] == PAGE_COMMUNITY) {
+               if ($owner['page-flags'] == Contact::PAGE_COMMUNITY) {
                        XML::addElement($doc, $root, "dfrn:community", 1);
                }
 
                // The former element is replaced by this one
                XML::addElement($doc, $root, "dfrn:account_type", $owner["account-type"]);
 
-               /// @todo We need a way to transmit the different page flags like "PAGE_PRVGROUP"
+               /// @todo We need a way to transmit the different page flags like "Contact::PAGE_PRVGROUP"
 
                XML::addElement($doc, $root, "updated", DateTimeFormat::utcNow(DateTimeFormat::ATOM));
 
@@ -911,7 +896,7 @@ class DFRN
                        $entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
                }
 
-               if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) {
+               if ($item['private']) {
                        $body = Item::fixPrivatePhotos($item['body'], $owner['uid'], $item, $cid);
                } else {
                        $body = $item['body'];
@@ -1005,8 +990,8 @@ class DFRN
                        XML::addElement($doc, $entry, "georss:point", $item['coord']);
                }
 
-               if (($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) {
-                       XML::addElement($doc, $entry, "dfrn:private", (($item['private']) ? $item['private'] : 1));
+               if ($item['private']) {
+                       XML::addElement($doc, $entry, "dfrn:private", ($item['private'] ? $item['private'] : 1));
                }
 
                if ($item['extid']) {
@@ -1235,11 +1220,11 @@ class DFRN
                $perm         = (($res->perm) ? $res->perm : null);
                $dfrn_version = (float) (($res->dfrn_version) ? $res->dfrn_version : 2.0);
                $rino_remote_version = intval($res->rino);
-               $page         = (($owner['page-flags'] == PAGE_COMMUNITY) ? 1 : 0);
+               $page         = (($owner['page-flags'] == Contact::PAGE_COMMUNITY) ? 1 : 0);
 
                logger("Remote rino version: ".$rino_remote_version." for ".$contact["url"], LOGGER_DEBUG);
 
-               if ($owner['page-flags'] == PAGE_PRVGROUP) {
+               if ($owner['page-flags'] == Contact::PAGE_PRVGROUP) {
                        $page = 2;
                }
 
@@ -1259,8 +1244,8 @@ class DFRN
                }
 
                if (($contact['duplex'] && strlen($contact['pubkey']))
-                       || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey']))
-                       || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))
+                       || ($owner['page-flags'] == Contact::PAGE_COMMUNITY && strlen($contact['pubkey']))
+                       || ($contact['rel'] == Contact::SHARING && strlen($contact['pubkey']))
                ) {
                        openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']);
                        openssl_public_decrypt($challenge, $postvars['challenge'], $contact['pubkey']);
@@ -1288,7 +1273,7 @@ class DFRN
                        $postvars['dissolve'] = '1';
                }
 
-               if ((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
+               if ((($contact['rel']) && ($contact['rel'] != Contact::SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == Contact::PAGE_COMMUNITY)) {
                        $postvars['data'] = $atom;
                        $postvars['perm'] = 'rw';
                } else {
@@ -1322,15 +1307,15 @@ class DFRN
 
                        if ($dfrn_version >= 2.1) {
                                if (($contact['duplex'] && strlen($contact['pubkey']))
-                                       || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey']))
-                                       || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))
+                                       || ($owner['page-flags'] == Contact::PAGE_COMMUNITY && strlen($contact['pubkey']))
+                                       || ($contact['rel'] == Contact::SHARING && strlen($contact['pubkey']))
                                ) {
                                        openssl_public_encrypt($key, $postvars['key'], $contact['pubkey']);
                                } else {
                                        openssl_private_encrypt($key, $postvars['key'], $contact['prvkey']);
                                }
                        } else {
-                               if (($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
+                               if (($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == Contact::PAGE_COMMUNITY)) {
                                        openssl_private_encrypt($key, $postvars['key'], $contact['prvkey']);
                                } else {
                                        openssl_public_encrypt($key, $postvars['key'], $contact['pubkey']);
@@ -1863,6 +1848,8 @@ class DFRN
 
                DBA::insert('mail', $msg);
 
+               $msg["id"] = DBA::lastInsertId();
+
                // send notifications.
                /// @TODO Arange this mess
                $notif_params = [
@@ -2150,7 +2137,7 @@ class DFRN
                if ($item["parent-uri"] != $item["uri"]) {
                        $community = false;
 
-                       if ($importer["page-flags"] == PAGE_COMMUNITY || $importer["page-flags"] == PAGE_PRVGROUP) {
+                       if ($importer["page-flags"] == Contact::PAGE_COMMUNITY || $importer["page-flags"] == Contact::PAGE_PRVGROUP) {
                                $sql_extra = "";
                                $community = true;
                                logger("possible community action");
@@ -2414,7 +2401,7 @@ class DFRN
 
                $item = $header;
 
-               $item["protocol"] = PROTOCOL_DFRN;
+               $item["protocol"] = Conversation::PARCEL_DFRN;
 
                $item["source"] = $xml;
 
@@ -2437,13 +2424,17 @@ class DFRN
 
                $owner_unknown = (isset($owner["contact-unknown"]) && $owner["contact-unknown"]);
 
+               $item["owner-name"] = $owner["name"];
                $item["owner-link"] = $owner["link"];
+               $item["owner-avatar"] = $owner["avatar"];
                $item["owner-id"] = Contact::getIdForURL($owner["link"], 0);
 
                // fetch the author
                $author = self::fetchauthor($xpath, $entry, $importer, "atom:author", true);
 
+               $item["author-name"] = $author["name"];
                $item["author-link"] = $author["link"];
+               $item["author-avatar"] = $author["avatar"];
                $item["author-id"] = Contact::getIdForURL($author["link"], 0);
 
                $item["title"] = XML::getFirstNodeValue($xpath, "atom:title/text()", $entry);
@@ -2642,6 +2633,7 @@ class DFRN
                                        $ev["edited"]  = $item["edited"];
                                        $ev["private"] = $item["private"];
                                        $ev["guid"]    = $item["guid"];
+                                       $ev["plink"]   = $item["plink"];
 
                                        $r = q(
                                                "SELECT `id` FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
@@ -2711,7 +2703,7 @@ class DFRN
                                $item["owner-id"] = Contact::getIdForURL($importer["url"], 0);
                        }
 
-                       if (($importer["rel"] == CONTACT_IS_FOLLOWER) && (!self::tgroupCheck($importer["importer_uid"], $item))) {
+                       if (($importer["rel"] == Contact::FOLLOWER) && (!self::tgroupCheck($importer["importer_uid"], $item))) {
                                logger("Contact ".$importer["id"]." is only follower and tgroup check was negative.", LOGGER_DEBUG);
                                return;
                        }
@@ -2860,7 +2852,7 @@ class DFRN
                                DBA::update('contact', ['contact-type' => $accounttype], ['id' => $importer["id"]]);
                        }
                        // A forum contact can either have set "forum" or "prv" - but not both
-                       if (($accounttype == ACCOUNT_TYPE_COMMUNITY) && (($forum != $importer["forum"]) || ($forum == $importer["prv"]))) {
+                       if (($accounttype == Contact::ACCOUNT_TYPE_COMMUNITY) && (($forum != $importer["forum"]) || ($forum == $importer["prv"]))) {
                                $condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $forum, !$forum, $importer["id"]];
                                DBA::update('contact', ['forum' => $forum, 'prv' => !$forum], $condition);
                        }
@@ -3039,8 +3031,8 @@ class DFRN
                        return false;
                }
 
-               $community_page = ($u[0]['page-flags'] == PAGE_COMMUNITY);
-               $prvgroup = ($u[0]['page-flags'] == PAGE_PRVGROUP);
+               $community_page = ($u[0]['page-flags'] == Contact::PAGE_COMMUNITY);
+               $prvgroup = ($u[0]['page-flags'] == Contact::PAGE_PRVGROUP);
 
                $link = normalise_link(System::baseUrl() . '/profile/' . $u[0]['nickname']);