<?php
-
/**
- * @file src/Model/Item.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
*/
namespace Friendica\Model;
}
// Creates or assigns the permission set
- $item['psid'] = PermissionSet::fetchIDForPost($item);
+ $item['psid'] = PermissionSet::getIdFromACL(
+ $item['uid'],
+ $item['allow_cid'],
+ $item['allow_gid'],
+ $item['deny_cid'],
+ $item['deny_gid']
+ );
+
+ $item['allow_cid'] = null;
+ $item['allow_gid'] = null;
+ $item['deny_cid'] = null;
+ $item['deny_gid'] = null;
// We are doing this outside of the transaction to avoid timing problems
if (!self::insertActivity($item)) {
$private = ($user['allow_cid'] || $user['allow_gid'] || $user['deny_cid'] || $user['deny_gid']) ? 1 : 0;
- $psid = PermissionSet::fetchIDForPost($user);
+ $psid = PermissionSet::getIdFromACL(
+ $user['uid'],
+ $user['allow_cid'],
+ $user['allow_gid'],
+ $user['deny_cid'],
+ $user['deny_gid']
+ );
$forum_mode = ($prvgroup ? 2 : 1);
return 0;
}
+ /**
+ * Return the URI for a link to the post
+ *
+ * @param string $uri URI or link to post
+ *
+ * @return string URI
+ */
+ public static function getURIByLink(string $uri)
+ {
+ $ssl_uri = str_replace('http://', 'https://', $uri);
+ $uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
+
+ $item = DBA::selectFirst('item', ['uri'], ['uri' => $uris]);
+ if (DBA::isResult($item)) {
+ return $item['uri'];
+ }
+
+ $itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]);
+ if (!DBA::isResult($itemcontent)) {
+ return '';
+ }
+
+ $itemuri = DBA::selectFirst('item-uri', ['uri'], ['id' => $itemcontent['uri-id']]);
+ if (DBA::isResult($itemuri)) {
+ return $itemuri['uri'];
+ }
+
+ return '';
+ }
+
/**
* Fetches item for given URI or plink
*
return $item_id;
}
- if (ActivityPub\Processor::fetchMissingActivity($uri)) {
- $item_id = self::searchByLink($uri, $uid);
+ if ($fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri)) {
+ $item_id = self::searchByLink($fetched_uri, $uid);
} else {
$item_id = Diaspora::fetchByURL($uri);
}