X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FDiaspora.php;h=325debe7bc97d65f84d2e7e4d7cdd7ba4898ecfe;hb=0b976ad193a2c3ab824905861a3d59d4d3c200d8;hp=8e2e487796a300c373edddebc880cd9833e3af7f;hpb=7ce48d1b77e9a691b1f77ec01690175f6b27bda9;p=friendica.git diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 8e2e487796..325debe7bc 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -942,31 +942,41 @@ class Diaspora * @brief Fetches data for a given handle * * @param string $handle The handle + * @param boolean $update true = always update, false = never update, null = update when not found or outdated * * @return array the queried data * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function personByHandle($handle) + public static function personByHandle($handle, $update = null) { - $update = false; - $person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'addr' => $handle]); + if (!DBA::isResult($person)) { + $urls = [$handle, str_replace('http://', 'https://', $handle), Strings::normaliseLink($handle)]; + $person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'url' => $urls]); + } + if (DBA::isResult($person)) { Logger::debug("In cache " . print_r($person, true)); - // update record occasionally so it doesn't get stale - $d = strtotime($person["updated"]." +00:00"); - if ($d < strtotime("now - 14 days")) { - $update = true; - } + if (is_null($update)) { + // update record occasionally so it doesn't get stale + $d = strtotime($person["updated"]." +00:00"); + if ($d < strtotime("now - 14 days")) { + $update = true; + } - if ($person["guid"] == "") { - $update = true; + if ($person["guid"] == "") { + $update = true; + } } + } elseif (is_null($update)) { + $update = !DBA::isResult($person); + } else { + $person = []; } - if (!DBA::isResult($person) || $update) { + if ($update) { Logger::log("create or refresh", Logger::DEBUG); $r = Probe::uri($handle, Protocol::DIASPORA); @@ -975,12 +985,7 @@ class Diaspora if ($r && ($r["network"] === Protocol::DIASPORA)) { self::updateFContact($r); - // Fetch the updated or added contact - $person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'addr' => $handle]); - if (!DBA::isResult($person)) { - $person = $r; - $person['id'] = 0; - } + $person = self::personByHandle($handle, false); } } @@ -1117,6 +1122,20 @@ class Diaspora return $contact; } + /** + * Checks if the given contact url does support ActivityPub + * + * @param string $url profile url + * @param boolean $update true = always update, false = never update, null = update when not found or outdated + * @return boolean + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + public static function isSupportedByContactUrl($url, $update = null) + { + return !empty(self::personByHandle($url, $update)); + } + /** * @brief Check if posting is allowed for this contact * @@ -1414,6 +1433,39 @@ class Diaspora return $msg; } + /** + * @brief Fetches an item with a given URL + * + * @param string $url the message url + * + * @return int the message id of the stored message or false + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + public static function fetchByURL($url, $uid = 0) + { + // Check for Diaspora (and Friendica) typical paths + if (!preg_match("=(https?://.+)/(?:posts|display)/([a-zA-Z0-9-_@.:%]+[a-zA-Z0-9])=i", $url, $matches)) { + return false; + } + + $guid = urldecode($matches[2]); + + $item = Item::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]); + if (DBA::isResult($item)) { + return $item['id']; + } + + self::storeByGuid($guid, $matches[1], $uid); + + $item = Item::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]); + if (DBA::isResult($item)) { + return $item['id']; + } else { + return false; + } + } + /** * @brief Fetches the item record of a given guid *