<?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;
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);
}