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)) {
+ if (!preg_match("=(https?://.+)/(?:posts|display|objects)/([a-zA-Z0-9-_@.:%]+[a-zA-Z0-9])=i", $url, $matches)) {
+ Logger::info('Invalid url', ['url' => $url]);
return false;
}
$item = Item::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
if (DBA::isResult($item)) {
+ Logger::info('Found', ['id' => $item['id']]);
return $item['id'];
}
- self::storeByGuid($guid, $matches[1], $uid);
+ Logger::info('Fetch GUID from origin', ['guid' => $guid, 'server' => $matches[1]]);
+ $ret = self::storeByGuid($guid, $matches[1], $uid);
+ Logger::info('Result', ['ret' => $ret]);
$item = Item::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
if (DBA::isResult($item)) {
+ Logger::info('Found', ['id' => $item['id']]);
return $item['id'];
} else {
+ Logger::info('Not found', ['guid' => $guid, 'uid' => $uid]);
return false;
}
}
*
* @return bool is it a hubzilla server?
*/
- public static function isRedmatrix($url)
+ private static function isHubzilla($url)
{
- return(strstr($url, "/channel/"));
+ return(strstr($url, '/channel/'));
}
/**
private static function plink($addr, $guid, $parent_guid = '')
{
$contact = Contact::getDetailsByAddr($addr);
+ if (empty($contact)) {
+ Logger::info('No contact data for address', ['addr' => $addr]);
+ return '';
+ }
- // Fallback
- if (!$contact) {
- if ($parent_guid != '') {
- return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $parent_guid . "#" . $guid;
- } else {
- return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $guid;
+ if (empty($contact['baseurl'])) {
+ $contact['baseurl'] = 'https://' . substr($addr, strpos($addr, '@') + 1);
+ Logger::info('Create baseurl from address', ['baseurl' => $contact['baseurl'], 'url' => $contact['url']]);
+ }
+
+ $platform = '';
+ $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => Strings::normaliseLink($contact['baseurl'])]);
+ if (!empty($gserver['platform'])) {
+ $platform = strtolower($gserver['platform']);
+ Logger::info('Detected platform', ['platform' => $platform, 'url' => $contact['url']]);
+ }
+
+ if (!in_array($platform, ['diaspora', 'friendica', 'hubzilla', 'socialhome'])) {
+ if (self::isHubzilla($contact['url'])) {
+ Logger::info('Detected unknown platform as Hubzilla', ['platform' => $platform, 'url' => $contact['url']]);
+ $platform = 'hubzilla';
+ } elseif ($contact['network'] == Protocol::DFRN) {
+ Logger::info('Detected unknown platform as Friendica', ['platform' => $platform, 'url' => $contact['url']]);
+ $platform = 'friendica';
}
}
- if ($contact["network"] == Protocol::DFRN) {
- return str_replace("/profile/" . $contact["nick"] . "/", "/display/" . $guid, $contact["url"] . "/");
+ if ($platform == 'friendica') {
+ return str_replace('/profile/' . $contact['nick'] . '/', '/display/' . $guid, $contact['url'] . '/');
+ }
+
+ if ($platform == 'hubzilla') {
+ return $contact['baseurl'] . '/item/' . $guid;
}
- if (self::isRedmatrix($contact["url"])) {
- return $contact["url"] . "/?mid=" . $guid;
+ if ($platform == 'socialhome') {
+ return $contact['baseurl'] . '/content/' . $guid;
+ }
+
+ if ($platform != 'diaspora') {
+ Logger::info('Unknown platform', ['platform' => $platform, 'url' => $contact['url']]);
+ return '';
}
if ($parent_guid != '') {
- return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $parent_guid . "#" . $guid;
+ return $contact['baseurl'] . '/posts/' . $parent_guid . '#' . $guid;
} else {
- return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $guid;
+ return $contact['baseurl'] . '/posts/' . $guid;
}
}
$datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
$datarray["plink"] = self::plink($author, $guid, $parent_item['guid']);
-
$body = Markdown::toBBCode($text);
$datarray["body"] = self::replacePeopleGuid($body, $person["url"]);
continue;
}
- Item::delete(['id' => $item['id']]);
+ Item::markForDeletion(['id' => $item['id']]);
Logger::log("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item["parent"], Logger::DEBUG);
}
$datarray["object-type"] = Activity\ObjectType::NOTE;
// Add OEmbed and other information to the body
- if (!self::isRedmatrix($contact["url"])) {
+ if (!self::isHubzilla($contact["url"])) {
$body = add_page_info_to_body($body, false, true);
}
}
$dob = DateTimeFormat::utc($year . '-' . $month . '-'. $day, 'Y-m-d');
}
- $about = $profile['about'];
- $about = strip_tags(BBCode::convert($about));
+ $about = BBCode::toMarkdown($profile['about']);
$location = Profile::formatLocation($profile);
$tags = '';