From 0a5476591d99af6155dff047795a06da6eb9fc62 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 10 Sep 2018 21:07:25 +0000 Subject: [PATCH 01/97] Activitity pub - first commit with much test code --- src/Module/Inbox.php | 47 +++ src/Protocol/ActivityPub.php | 772 +++++++++++++++++++++++++++++++++++ 2 files changed, 819 insertions(+) create mode 100644 src/Module/Inbox.php create mode 100644 src/Protocol/ActivityPub.php diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php new file mode 100644 index 0000000000..86fdae7c90 --- /dev/null +++ b/src/Module/Inbox.php @@ -0,0 +1,47 @@ + $_SERVER, 'body' => $obj])); + + logger('Blubb: init ' . $tempfile); + exit(); +// goaway($dest); + } + + public static function post() + { + $a = self::getApp(); + + logger('Blubb: post'); + exit(); +// goaway($dest); + } +} diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php new file mode 100644 index 0000000000..f1d885b6c6 --- /dev/null +++ b/src/Protocol/ActivityPub.php @@ -0,0 +1,772 @@ +get_curl_code(); +echo $return_code."\n"; + print_r(BaseObject::getApp()->get_curl_headers()); + print_r($headers); + } + + /** + * Return the ActivityPub profile of the given user + * + * @param integer $uid User ID + * @return array + */ + public static function profile($uid) + { + $accounttype = ['Person', 'Organization', 'Service', 'Group', 'Application']; + + $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false, + 'account_removed' => false, 'verified' => true]; + $fields = ['guid', 'nickname', 'pubkey', 'account-type']; + $user = DBA::selectFirst('user', $fields, $condition); + if (!DBA::isResult($user)) { + return []; + } + + $fields = ['locality', 'region', 'country-name']; + $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid, 'is-default' => true]); + if (!DBA::isResult($profile)) { + return []; + } + + $fields = ['name', 'url', 'location', 'about', 'avatar']; + $contact = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]); + if (!DBA::isResult($contact)) { + return []; + } + + $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', + ['uuid' => 'http://schema.org/identifier', 'sensitive' => 'as:sensitive', + 'vcard' => 'http://www.w3.org/2006/vcard/ns#']]]; + + $data['id'] = $contact['url']; + $data['uuid'] = $user['guid']; + $data['type'] = $accounttype[$user['account-type']]; + $data['following'] = System::baseUrl() . '/following/' . $user['nickname']; + $data['followers'] = System::baseUrl() . '/followers/' . $user['nickname']; + $data['inbox'] = System::baseUrl() . '/inbox/' . $user['nickname']; + $data['outbox'] = System::baseUrl() . '/outbox/' . $user['nickname']; + $data['preferredUsername'] = $user['nickname']; + $data['name'] = $contact['name']; + $data['vcard:hasAddress'] = ['@type' => 'Home', 'vcard:country-name' => $profile['country-name'], + 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']]; + $data['summary'] = $contact['about']; + $data['url'] = $contact['url']; + $data['manuallyApprovesFollowers'] = false; + $data['publicKey'] = ['id' => $contact['url'] . '#main-key', + 'owner' => $contact['url'], + 'publicKeyPem' => $user['pubkey']]; + $data['endpoints'] = ['sharedInbox' => System::baseUrl() . '/inbox']; + $data['icon'] = ['type' => 'Image', + 'url' => $contact['avatar']]; + + // tags: https://kitty.town/@inmysocks/100656097926961126.json + return $data; + } + + public static function createActivityFromItem($item_id) + { + $item = Item::selectFirst([], ['id' => $item_id]); + + $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', + ['Emoji' => 'toot:Emoji', 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri', + 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri', + 'ostatus' => 'http://ostatus.org#', 'sensitive' => 'as:sensitive', + 'toot' => 'http://joinmastodon.org/ns#']]]; + + $data['type'] = 'Create'; + $data['id'] = $item['plink']; + $data['actor'] = $item['author-link']; + $data['to'] = 'https://www.w3.org/ns/activitystreams#Public'; + $data['object'] = self::createNote($item); +// print_r($data); +// print_r($item); + return $data; + } + + public static function createNote($item) + { + $data = []; + $data['type'] = 'Note'; + $data['id'] = $item['plink']; + //$data['context'] = $data['conversation'] = $item['parent-uri']; + $data['actor'] = $item['author-link']; +// if (!$item['private']) { +// $data['to'] = []; +// $data['to'][] = '"https://pleroma.soykaf.com/users/heluecht"'; + $data['to'] = 'https://www.w3.org/ns/activitystreams#Public'; +// $data['cc'] = 'https://pleroma.soykaf.com/users/heluecht'; +// } + $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); + $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); + $data['attributedTo'] = $item['author-link']; + $data['title'] = BBCode::convert($item['title'], false, 7); + $data['content'] = BBCode::convert($item['body'], false, 7); + //$data['summary'] = ''; + //$data['sensitive'] = false; + //$data['emoji'] = []; + //$data['tag'] = []; + //$data['attachment'] = []; + return $data; + } + + /** + * Fetches ActivityPub content from the given url + * + * @param string $url content url + * @return array + */ + public static function fetchContent($url) + { + $ret = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json']); + + if (!$ret['success'] || empty($ret['body'])) { + return; + } + + return json_decode($ret['body'], true); + } + + /** + * Resolves the profile url from the address by using webfinger + * + * @param string $addr profile address (user@domain.tld) + * @return string url + */ + private static function addrToUrl($addr) + { + $addr_parts = explode('@', $addr); + if (count($addr_parts) != 2) { + return false; + } + + $webfinger = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr); + + $ret = Network::curl($webfinger, false, $redirects, ['accept_content' => 'application/jrd+json,application/json']); + if (!$ret['success'] || empty($ret['body'])) { + return false; + } + + $data = json_decode($ret['body'], true); + + if (empty($data['links'])) { + return false; + } + + foreach ($data['links'] as $link) { + if (empty($link['href']) || empty($link['rel']) || empty($link['type'])) { + continue; + } + + if (($link['rel'] == 'self') && ($link['type'] == 'application/activity+json')) { + return $link['href']; + } + } + + return false; + } + + /** + * Fetches a profile from the given url + * + * @param string $url profile url + * @return array + */ + public static function fetchProfile($url) + { + if (empty(parse_url($url, PHP_URL_SCHEME))) { + $url = self::addrToUrl($url); + if (empty($url)) { + return false; + } + } + + $data = self::fetchContent($url); + + if (empty($data) || empty($data['id']) || empty($data['inbox'])) { + return false; + } + + $profile = ['network' => Protocol::ACTIVITYPUB]; + $profile['nick'] = $data['preferredUsername']; + $profile['name'] = defaults($data, 'name', $profile['nick']); + $profile['guid'] = defaults($data, 'uuid', null); + $profile['url'] = $data['id']; + $profile['alias'] = self::processElement($data, 'url', 'href'); + + $parts = parse_url($profile['url']); + unset($parts['scheme']); + unset($parts['path']); + $profile['addr'] = $profile['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts)); + + $profile['photo'] = self::processElement($data, 'icon', 'url'); + $profile['about'] = defaults($data, 'summary', ''); + $profile['batch'] = self::processElement($data, 'endpoints', 'sharedInbox'); + $profile['pubkey'] = self::processElement($data, 'publicKey', 'publicKeyPem'); + $profile['notify'] = $data['inbox']; + $profile['poll'] = $data['outbox']; + + // Check if the address is resolvable + if (self::addrToUrl($profile['addr']) == $profile['url']) { + $parts = parse_url($profile['url']); + unset($parts['path']); + $profile['baseurl'] = Network::unparseURL($parts); + } else { + unset($profile['addr']); + } + + if ($profile['url'] == $profile['alias']) { + unset($profile['alias']); + } + + // Remove all "null" fields + foreach ($profile as $field => $content) { + if (is_null($content)) { + unset($profile[$field]); + } + } + + // Handled + unset($data['id']); + unset($data['inbox']); + unset($data['outbox']); + unset($data['preferredUsername']); + unset($data['name']); + unset($data['summary']); + unset($data['url']); + unset($data['publicKey']); + unset($data['endpoints']); + unset($data['icon']); + unset($data['uuid']); + + // To-Do + unset($data['type']); + unset($data['manuallyApprovesFollowers']); + + // Unhandled + unset($data['@context']); + unset($data['tag']); + unset($data['attachment']); + unset($data['image']); + unset($data['nomadicLocations']); + unset($data['signature']); + unset($data['following']); + unset($data['followers']); + unset($data['featured']); + unset($data['movedTo']); + unset($data['liked']); + unset($data['sharedInbox']); // Misskey + unset($data['isCat']); // Misskey + unset($data['kroeg:blocks']); // Kroeg + unset($data['updated']); // Kroeg + +/* if (!empty($data)) { + print_r($data); + die(); + } +*/ + return $profile; + } + + public static function fetchOutbox($url) + { + $data = self::fetchContent($url); + if (empty($data)) { + return; + } + + if (!empty($data['orderedItems'])) { + $items = $data['orderedItems']; + } elseif (!empty($data['first']['orderedItems'])) { + $items = $data['first']['orderedItems']; + } elseif (!empty($data['first'])) { + self::fetchOutbox($data['first']); + return; + } else { + $items = []; + } + + foreach ($items as $activity) { + self::processActivity($activity, $url); + } + } + + function processActivity($activity, $url) + { + if (empty($activity['type'])) { + return; + } + + if (empty($activity['object'])) { + return; + } + + if (empty($activity['actor'])) { + return; + } + + $actor = self::processElement($activity, 'actor', 'id'); + if (empty($actor)) { + return; + } + + if (is_string($activity['object'])) { + $object_url = $activity['object']; + } elseif (!empty($activity['object']['id'])) { + $object_url = $activity['object']['id']; + } else { + return; + } + + $receivers = self::getReceivers($activity); + if (empty($receivers)) { + return; + } + + // ---------------------------------- + // unhandled + unset($activity['@context']); + unset($activity['id']); + + // Non standard + unset($activity['title']); + unset($activity['atomUri']); + unset($activity['context_id']); + unset($activity['statusnetConversationId']); + + $structure = $activity; + + // To-Do? + unset($activity['context']); + unset($activity['location']); + + // handled + unset($activity['to']); + unset($activity['cc']); + unset($activity['bto']); + unset($activity['bcc']); + unset($activity['type']); + unset($activity['actor']); + unset($activity['object']); + unset($activity['published']); + unset($activity['updated']); + unset($activity['instrument']); + unset($activity['inReplyTo']); + + if (!empty($activity)) { + echo "Activity\n"; + print_r($activity); + die($url."\n"); + } + + $activity = $structure; + // ---------------------------------- + + $item = self::fetchObject($object_url, $url); + if (empty($item)) { + return; + } + + $item = self::addActivityFields($item, $activity); + + $item['owner'] = $actor; + + $item['receiver'] = array_merge($item['receiver'], $receivers); + + switch ($activity['type']) { + case 'Create': + case 'Update': + self::createItem($item); + break; + + case 'Announce': + self::announceItem($item); + break; + + case 'Like': + case 'Dislike': + self::activityItem($item); + break; + + case 'Follow': + break; + + default: + echo "Unknown activity: ".$activity['type']."\n"; + print_r($item); + die(); + break; + } + } + + private static function getReceivers($activity) + { + $receivers = []; + + $elements = ['to', 'cc', 'bto', 'bcc']; + foreach ($elements as $element) { + if (empty($activity[$element])) { + continue; + } + + // The receiver can be an arror or a string + if (is_string($activity[$element])) { + $activity[$element] = [$activity[$element]]; + } + + foreach ($activity[$element] as $receiver) { + if ($receiver == self::PUBLIC) { + $receivers[$receiver] = 0; + } + + $condition = ['self' => true, 'nurl' => normalise_link($receiver)]; + $contact = DBA::selectFirst('contact', ['id'], $condition); + if (!DBA::isResult($contact)) { + continue; + } + $receivers[$receiver] = $contact['id']; + } + } + return $receivers; + } + + private static function addActivityFields($item, $activity) + { + if (!empty($activity['published']) && empty($item['published'])) { + $item['published'] = $activity['published']; + } + + if (!empty($activity['updated']) && empty($item['updated'])) { + $item['updated'] = $activity['updated']; + } + + if (!empty($activity['inReplyTo']) && empty($item['parent-uri'])) { + $item['parent-uri'] = self::processElement($activity, 'inReplyTo', 'id'); + } + + if (!empty($activity['instrument'])) { + $item['service'] = self::processElement($activity, 'instrument', 'name', 'Service'); + } + + // Remove all "null" fields + foreach ($item as $field => $content) { + if (is_null($content)) { + unset($item[$field]); + } + } + + return $item; + } + + private static function fetchObject($object_url, $url) + { + $data = self::fetchContent($object_url); + if (empty($data)) { + return false; + } + + if (empty($data['type'])) { + return false; + } else { + $type = $data['type']; + } + + if (in_array($type, ['Note', 'Article', 'Video'])) { + $common = self::processCommonData($data, $url); + } + + switch ($type) { + case 'Note': + return array_merge($common, self::processNote($data, $url)); + case 'Article': + return array_merge($common, self::processArticle($data, $url)); + case 'Video': + return array_merge($common, self::processVideo($data, $url)); + + case 'Announce': + if (empty($data['object'])) { + return false; + } + return self::fetchObject($data['object'], $url); + + case 'Person': + case 'Tombstone': + break; + + default: + echo "Unknown object type: ".$data['type']."\n"; + print_r($data); + die($url."\n"); + break; + } + } + + private static function processCommonData(&$object, $url) + { + if (empty($object['id']) || empty($object['attributedTo'])) { + return false; + } + + $item = []; + $item['uri'] = $object['id']; + + if (!empty($object['inReplyTo'])) { + $item['reply-to-uri'] = self::processElement($object, 'inReplyTo', 'id'); + } else { + $item['reply-to-uri'] = $item['uri']; + } + + $item['published'] = defaults($object, 'published', null); + $item['updated'] = defaults($object, 'updated', $item['published']); + + if (empty($item['published']) && !empty($item['updated'])) { + $item['published'] = $item['updated']; + } + + $item['uuid'] = defaults($object, 'uuid', null); + $item['owner'] = $item['author'] = self::processElement($object, 'attributedTo', 'id'); + $item['context'] = defaults($object, 'context', null); + $item['conversation'] = defaults($object, 'conversation', null); + $item['sensitive'] = defaults($object, 'sensitive', null); + $item['name'] = defaults($object, 'name', null); + $item['title'] = defaults($object, 'title', null); + $item['content'] = defaults($object, 'content', null); + $item['summary'] = defaults($object, 'summary', null); + $item['location'] = self::processElement($object, 'location', 'name', 'Place'); + $item['attachments'] = defaults($object, 'attachment', null); + $item['tags'] = defaults($object, 'tag', null); + $item['service'] = self::processElement($object, 'instrument', 'name', 'Service'); + $item['alternate-url'] = self::processElement($object, 'url', 'href'); + $item['receiver'] = self::getReceivers($object); + + // handled + unset($object['id']); + unset($object['inReplyTo']); + unset($object['published']); + unset($object['updated']); + unset($object['uuid']); + unset($object['attributedTo']); + unset($object['context']); + unset($object['conversation']); + unset($object['sensitive']); + unset($object['name']); + unset($object['title']); + unset($object['content']); + unset($object['summary']); + unset($object['location']); + unset($object['attachment']); + unset($object['tag']); + unset($object['instrument']); + unset($object['url']); + unset($object['to']); + unset($object['cc']); + unset($object['bto']); + unset($object['bcc']); + + // To-Do + unset($object['source']); + + // Unhandled + unset($object['@context']); + unset($object['type']); + unset($object['actor']); + unset($object['signature']); + unset($object['mediaType']); + unset($object['duration']); + unset($object['replies']); + unset($object['icon']); + + /* + audience, preview, endTime, startTime, generator, image + */ + + return $item; + } + + private static function processNote($object, $url) + { + $item = []; + + // To-Do? + unset($object['emoji']); + unset($object['atomUri']); + unset($object['inReplyToAtomUri']); + + // Unhandled + unset($object['contentMap']); + unset($object['announcement_count']); + unset($object['announcements']); + unset($object['context_id']); + unset($object['likes']); + unset($object['like_count']); + unset($object['inReplyToStatusId']); + unset($object['shares']); + unset($object['quoteUrl']); + unset($object['statusnetConversationId']); + + if (empty($object)) + return $item; + + echo "Unknown Note\n"; + print_r($object); + print_r($item); + die($url."\n"); + + return []; + } + + private static function processArticle($object, $url) + { + $item = []; + + if (empty($object)) + return $item; + + echo "Unknown Article\n"; + print_r($object); + print_r($item); + die($url."\n"); + + return []; + } + + private static function processVideo($object, $url) + { + $item = []; + + // To-Do? + unset($object['category']); + unset($object['licence']); + unset($object['language']); + unset($object['commentsEnabled']); + + // Unhandled + unset($object['views']); + unset($object['waitTranscoding']); + unset($object['state']); + unset($object['support']); + unset($object['subtitleLanguage']); + unset($object['likes']); + unset($object['dislikes']); + unset($object['shares']); + unset($object['comments']); + + if (empty($object)) + return $item; + + echo "Unknown Video\n"; + print_r($object); + print_r($item); + die($url."\n"); + + return []; + } + + private static function processElement($array, $element, $key, $type = null) + { + if (empty($array)) { + return false; + } + + if (empty($array[$element])) { + return false; + } + + if (is_string($array[$element])) { + return $array[$element]; + } + + if (is_null($type)) { + if (!empty($array[$element][$key])) { + return $array[$element][$key]; + } + + if (!empty($array[$element][0][$key])) { + return $array[$element][0][$key]; + } + + return false; + } + + if (!empty($array[$element][$key]) && !empty($array[$element]['type']) && ($array[$element]['type'] == $type)) { + return $array[$element][$key]; + } + + /// @todo Add array search + + return false; + } + + private static function createItem($item) + { +// print_r($item); + } + + private static function announceItem($item) + { +// print_r($item); + } + + private static function activityItem($item) + { + // print_r($item); + } + +} From 1afa6523bc6988843c576a5664b393d0d1e80e88 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 11 Sep 2018 07:07:56 +0000 Subject: [PATCH 02/97] Adding (temporary) calls to AP in existing stuff --- mod/display.php | 11 ++++++++++- mod/profile.php | 10 ++++++++++ mod/xrd.php | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mod/display.php b/mod/display.php index 907bf8ebba..21e28d5617 100644 --- a/mod/display.php +++ b/mod/display.php @@ -17,6 +17,7 @@ use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\Profile; use Friendica\Protocol\DFRN; +use Friendica\Protocol\ActivityPub; function display_init(App $a) { @@ -43,7 +44,7 @@ function display_init(App $a) $item = null; - $fields = ['id', 'parent', 'author-id', 'body', 'uid']; + $fields = ['id', 'parent', 'author-id', 'body', 'uid', 'guid']; // If there is only one parameter, then check if this parameter could be a guid if ($a->argc == 2) { @@ -76,6 +77,14 @@ function display_init(App $a) displayShowFeed($item["id"], false); } + if (stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json')) { + $wall_item = Item::selectFirst(['id', 'uid'], ['guid' => $item['guid'], 'wall' => true]); + if ($wall_item['uid'] == 180) { + $data = ActivityPub::createActivityFromItem($wall_item['id']); + echo json_encode($data); + exit(); + } + } if ($item["id"] != $item["parent"]) { $item = Item::selectFirstForUser(local_user(), $fields, ['id' => $item["parent"]]); } diff --git a/mod/profile.php b/mod/profile.php index 2e3ccd28c5..fd23964e41 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -20,6 +20,7 @@ use Friendica\Model\Profile; use Friendica\Module\Login; use Friendica\Protocol\DFRN; use Friendica\Util\DateTimeFormat; +use Friendica\Protocol\ActivityPub; function profile_init(App $a) { @@ -49,6 +50,15 @@ function profile_init(App $a) DFRN::autoRedir($a, $which); } + if (stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json')) { + $user = DBA::selectFirst('user', ['uid'], ['nickname' => $which]); + if ($user['uid'] == 180) { + $data = ActivityPub::profile($user['uid']); + echo json_encode($data); + exit(); + } + } + Profile::load($a, $which, $profile); $blocked = !local_user() && !remote_user() && Config::get('system', 'block_public'); diff --git a/mod/xrd.php b/mod/xrd.php index 61505f2996..87766ca26e 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -92,6 +92,10 @@ function xrd_json($a, $uri, $alias, $profile_url, $r) ['rel' => 'http://purl.org/openwebauth/v1', 'type' => 'application/x-dfrn+json', 'href' => System::baseUrl().'/owa'] ] ]; + if ($r['uid'] == 180) { + $json['links'][] = ['rel' => 'self', 'type' => 'application/activity+json', 'href' => $profile_url]; + } + echo json_encode($json); killme(); } From 8c07baf54b0d426d3e38d3d01aaeffd9ceb1d8f1 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 12 Sep 2018 06:01:28 +0000 Subject: [PATCH 03/97] Better http answers --- src/Module/Inbox.php | 23 +++++------------------ src/Protocol/ActivityPub.php | 3 +++ 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 86fdae7c90..0bc78b030c 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -9,6 +9,7 @@ use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Util\HTTPSignature; use Friendica\Util\Network; +use Friendica\Core\System; /** * ActivityPub Inbox @@ -18,30 +19,16 @@ class Inbox extends BaseModule public static function init() { $a = self::getApp(); - logger('Blubb: init 1'); $postdata = file_get_contents('php://input'); - $obj = json_decode($postdata); - - if (empty($obj)) { - exit(); + if (empty($postdata)) { + System::httpExit(400); } $tempfile = tempnam(get_temppath(), 'activitypub'); - file_put_contents($tempfile, json_encode(['header' => $_SERVER, 'body' => $obj])); + file_put_contents($tempfile, json_encode(['header' => $_SERVER, 'body' => $postdata])); - logger('Blubb: init ' . $tempfile); - exit(); -// goaway($dest); - } - - public static function post() - { - $a = self::getApp(); - - logger('Blubb: post'); - exit(); -// goaway($dest); + System::httpExit(200); } } diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index f1d885b6c6..8992c525b0 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -25,6 +25,9 @@ use Friendica\Content\Text\BBCode; * * https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/ * https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/ + * + * Digest: https://tools.ietf.org/html/rfc5843 + * https://tools.ietf.org/html/draft-cavage-http-signatures-10#ref-15 */ class ActivityPub { From 969311cb44a2748ebc93c485e1cd57ad86e0f139 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 12 Sep 2018 18:48:18 +0000 Subject: [PATCH 04/97] Replacing the non standard "title" with "name" --- src/Protocol/ActivityPub.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 8992c525b0..07989621f1 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -160,7 +160,7 @@ echo $return_code."\n"; $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); $data['attributedTo'] = $item['author-link']; - $data['title'] = BBCode::convert($item['title'], false, 7); + $data['name'] = BBCode::convert($item['title'], false, 7); $data['content'] = BBCode::convert($item['body'], false, 7); //$data['summary'] = ''; //$data['sensitive'] = false; @@ -588,10 +588,10 @@ echo $return_code."\n"; $item['context'] = defaults($object, 'context', null); $item['conversation'] = defaults($object, 'conversation', null); $item['sensitive'] = defaults($object, 'sensitive', null); - $item['name'] = defaults($object, 'name', null); - $item['title'] = defaults($object, 'title', null); - $item['content'] = defaults($object, 'content', null); + $item['name'] = defaults($object, 'title', null); + $item['name'] = defaults($object, 'name', $item['name']); $item['summary'] = defaults($object, 'summary', null); + $item['content'] = defaults($object, 'content', null); $item['location'] = self::processElement($object, 'location', 'name', 'Place'); $item['attachments'] = defaults($object, 'attachment', null); $item['tags'] = defaults($object, 'tag', null); From 67fa0ed433fa2519108e5f9b4715b3fdea1cb9fd Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 12 Sep 2018 21:30:10 +0000 Subject: [PATCH 05/97] Signature check added --- src/Module/Inbox.php | 13 +-- src/Protocol/ActivityPub.php | 157 +++++++++++++++++++++++++++++++++-- 2 files changed, 158 insertions(+), 12 deletions(-) diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 0bc78b030c..63de5de12d 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -5,10 +5,7 @@ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\Database\DBA; -use Friendica\Model\Contact; -use Friendica\Util\HTTPSignature; -use Friendica\Util\Network; +use Friendica\Protocol\ActivityPub; use Friendica\Core\System; /** @@ -26,7 +23,13 @@ class Inbox extends BaseModule System::httpExit(400); } - $tempfile = tempnam(get_temppath(), 'activitypub'); + if (ActivityPub::verifySignature($postdata, $_SERVER)) { + $filename = 'signed-activitypub'; + } else { + $filename = 'failed-activitypub'; + } + + $tempfile = tempnam(get_temppath(), filename); file_put_contents($tempfile, json_encode(['header' => $_SERVER, 'body' => $postdata])); System::httpExit(200); diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 07989621f1..83aae72aa5 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -53,16 +53,11 @@ class ActivityPub $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",headers="(request-target) host date",signature="' . $signature . '"'; $headers[] = 'Content-Type: application/activity+json'; -//print_r($headers); -//die($signed_data); -//$headers = []; -// $headers = HTTPSignature::createSig('', $headers, $owner['uprvkey'], $owner['url'] . '#main-key', false, false, 'sha256'); Network::post($target, $content, $headers); $return_code = BaseObject::getApp()->get_curl_code(); -echo $return_code."\n"; - print_r(BaseObject::getApp()->get_curl_headers()); - print_r($headers); + + echo $return_code."\n"; } /** @@ -226,6 +221,154 @@ echo $return_code."\n"; return false; } + public static function verifySignature($content, $http_headers) + { + $object = json_decode($content, true); + + if (empty($object)) { + return false; + } + + $actor = self::processElement($object, 'actor', 'id'); + + $headers = []; + $headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . $http_headers['REQUEST_URI']; + + // First take every header + foreach ($http_headers as $k => $v) { + $field = str_replace('_', '-', strtolower($k)); + $headers[$field] = $v; + } + + // Now add every http header + foreach ($http_headers as $k => $v) { + if (strpos($k, 'HTTP_') === 0) { + $field = str_replace('_', '-', strtolower(substr($k, 5))); + $headers[$field] = $v; + } + } + + $sig_block = ActivityPub::parseSigHeader($http_headers['HTTP_SIGNATURE']); + + if (empty($sig_block) || empty($sig_block['headers']) || empty($sig_block['keyId'])) { + return false; + } + + $signed_data = ''; + foreach ($sig_block['headers'] as $h) { + if (array_key_exists($h, $headers)) { + $signed_data .= $h . ': ' . $headers[$h] . "\n"; + } + } + $signed_data = rtrim($signed_data, "\n"); + + if (empty($signed_data)) { + return false; + } + + $algorithm = null; + + if ($sig_block['algorithm'] === 'rsa-sha256') { + $algorithm = 'sha256'; + } + + if ($sig_block['algorithm'] === 'rsa-sha512') { + $algorithm = 'sha512'; + } + + if (empty($algorithm)) { + return false; + } + + $key = self::fetchKey($sig_block['keyId'], $actor); + + if (empty($key)) { + return false; + } + + if (!Crypto::rsaVerify($signed_data, $sig_block['signature'], $key, $algorithm)) { + return false; + } + + // Check the digest if it was part of the signed data + if (in_array('digest', $sig_block['headers'])) { + $digest = explode('=', $headers['digest'], 2); + if ($digest[0] === 'SHA-256') { + $hashalg = 'sha256'; + } + if ($digest[0] === 'SHA-512') { + $hashalg = 'sha512'; + } + + /// @todo addd all hashes from the rfc + + if (!empty($hashalg) && base64_encode(hash($hashalg, $content, true)) != $digest[1]) { + return false; + } + } + + // Check the content-length if it was part of the signed data + if (in_array('content-length', $sig_block['headers'])) { + if (strlen($content) != $headers['content-length']) { + return false; + } + } + + return true; + + } + + private static function fetchKey($id, $actor) + { + $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id); + + $profile = self::fetchProfile($url); + if (!empty($profile)) { + return $profile['pubkey']; + } elseif ($url != $actor) { + $profile = self::fetchProfile($actor); + if (!empty($profile)) { + return $profile['pubkey']; + } + } + + return false; + } + + /** + * @brief + * + * @param string $header + * @return array associate array with + * - \e string \b keyID + * - \e string \b algorithm + * - \e array \b headers + * - \e string \b signature + */ + private static function parseSigHeader($header) + { + $ret = []; + $matches = []; + + if (preg_match('/keyId="(.*?)"/ism',$header,$matches)) { + $ret['keyId'] = $matches[1]; + } + + if (preg_match('/algorithm="(.*?)"/ism',$header,$matches)) { + $ret['algorithm'] = $matches[1]; + } + + if (preg_match('/headers="(.*?)"/ism',$header,$matches)) { + $ret['headers'] = explode(' ', $matches[1]); + } + + if (preg_match('/signature="(.*?)"/ism',$header,$matches)) { + $ret['signature'] = base64_decode(preg_replace('/\s+/','',$matches[1])); + } + + return $ret; + } + /** * Fetches a profile from the given url * From f7b03bc5f39e0efd8c1b278d665f7babaad58985 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 12 Sep 2018 21:33:44 +0000 Subject: [PATCH 06/97] Missing $ --- src/Module/Inbox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 63de5de12d..bb0d9ef040 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -29,7 +29,7 @@ class Inbox extends BaseModule $filename = 'failed-activitypub'; } - $tempfile = tempnam(get_temppath(), filename); + $tempfile = tempnam(get_temppath(), $filename); file_put_contents($tempfile, json_encode(['header' => $_SERVER, 'body' => $postdata])); System::httpExit(200); From c2f6b166c7302d39e6e754119679036a4fca7473 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 13 Sep 2018 21:57:41 +0000 Subject: [PATCH 07/97] We now use the regular probing function --- src/Network/Probe.php | 12 +++++++++++- src/Protocol/ActivityPub.php | 13 ++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index af2d1c9a16..99ecb668c8 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -19,6 +19,7 @@ use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Protocol\Email; use Friendica\Protocol\Feed; +use Friendica\Protocol\ActivityPub; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -328,7 +329,16 @@ class Probe $uid = local_user(); } - $data = self::detect($uri, $network, $uid); + if ($network != Protocol::ACTIVITYPUB) { + $data = self::detect($uri, $network, $uid); + } + + if (empty($data) || ($data['network'] == Protocol::PHANTOM)) { + $ap_profile = ActivityPub::fetchProfile($uri); + if (!empty($ap_profile) && ($ap_profile['network'] == Protocol::ACTIVITYPUB)) { + $data = $ap_profile; + } + } if (!isset($data["url"])) { $data["url"] = $uri; diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 83aae72aa5..12c849d5b4 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -15,6 +15,7 @@ use Friendica\Model\User; use Friendica\Util\DateTimeFormat; use Friendica\Util\Crypto; use Friendica\Content\Text\BBCode; +use Friendica\Network\Probe; /** * @brief ActivityPub Protocol class @@ -322,11 +323,11 @@ class ActivityPub { $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id); - $profile = self::fetchProfile($url); + $profile = Probe::uri($url, Protocol::ACTIVITYPUB); if (!empty($profile)) { return $profile['pubkey']; } elseif ($url != $actor) { - $profile = self::fetchProfile($actor); + $profile = Probe::uri($actor, Protocol::ACTIVITYPUB); if (!empty($profile)) { return $profile['pubkey']; } @@ -395,19 +396,21 @@ class ActivityPub $profile['name'] = defaults($data, 'name', $profile['nick']); $profile['guid'] = defaults($data, 'uuid', null); $profile['url'] = $data['id']; - $profile['alias'] = self::processElement($data, 'url', 'href'); $parts = parse_url($profile['url']); unset($parts['scheme']); unset($parts['path']); $profile['addr'] = $profile['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts)); - + $profile['alias'] = self::processElement($data, 'url', 'href'); $profile['photo'] = self::processElement($data, 'icon', 'url'); + // $profile['community'] + // $profile['keywords'] + // $profile['location'] $profile['about'] = defaults($data, 'summary', ''); $profile['batch'] = self::processElement($data, 'endpoints', 'sharedInbox'); - $profile['pubkey'] = self::processElement($data, 'publicKey', 'publicKeyPem'); $profile['notify'] = $data['inbox']; $profile['poll'] = $data['outbox']; + $profile['pubkey'] = self::processElement($data, 'publicKey', 'publicKeyPem'); // Check if the address is resolvable if (self::addrToUrl($profile['addr']) == $profile['url']) { From 7b45bdea173496b7a5fdf994f28b986d4a80d193 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 13 Sep 2018 22:12:33 +0000 Subject: [PATCH 08/97] Preparation for adding more networks there --- src/Network/Probe.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 99ecb668c8..d48617f43b 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -333,7 +333,7 @@ class Probe $data = self::detect($uri, $network, $uid); } - if (empty($data) || ($data['network'] == Protocol::PHANTOM)) { + if (in_array(defaults($data, 'network', ''), ['', Protocol::PHANTOM])) { $ap_profile = ActivityPub::fetchProfile($uri); if (!empty($ap_profile) && ($ap_profile['network'] == Protocol::ACTIVITYPUB)) { $data = $ap_profile; From 61e2c7d20dfcf3eba7442c2b181d22b8926062e3 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 14 Sep 2018 16:51:32 +0000 Subject: [PATCH 09/97] Added AP to many network conditions / enabling inbox processing --- include/conversation.php | 6 +- mod/contacts.php | 10 +- mod/dirfind.php | 2 +- src/Content/ContactSelector.php | 33 ++++--- src/Content/Widget.php | 5 +- src/Model/Contact.php | 6 +- src/Model/Conversation.php | 6 +- src/Model/Item.php | 8 +- src/Module/Inbox.php | 6 +- src/Network/Probe.php | 2 + src/Protocol/ActivityPub.php | 163 ++++++++++++++++++++++++------- src/Protocol/PortableContact.php | 2 +- src/Worker/Notifier.php | 4 +- src/Worker/UpdateGContact.php | 4 +- 14 files changed, 178 insertions(+), 79 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 45e5d1caa3..835d227477 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -556,7 +556,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o if (in_array($mode, ['community', 'contacts'])) { $writable = true; } else { - $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]); + $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]); } if (!local_user()) { @@ -807,7 +807,7 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid) foreach ($items as $index => $item) { if ($item['uid'] == 0) { - $items[$index]['writable'] = in_array($item['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]); + $items[$index]['writable'] = in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]); } } @@ -877,7 +877,7 @@ function item_photo_menu($item) { } if ((($cid == 0) || ($rel == Contact::FOLLOWER)) && - in_array($item['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) { + in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) { $menu[L10n::t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']); } } else { diff --git a/mod/contacts.php b/mod/contacts.php index 68f68fec3b..031f6964c3 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -537,7 +537,7 @@ function contacts_content(App $a, $update = 0) $relation_text = ''; } - if (!in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) { + if (!in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) { $relation_text = ""; } @@ -559,7 +559,7 @@ function contacts_content(App $a, $update = 0) } $lblsuggest = (($contact['network'] === Protocol::DFRN) ? L10n::t('Suggest friends') : ''); - $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]); + $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]); $nettype = L10n::t('Network type: %s', ContactSelector::networkToName($contact['network'], $contact["url"])); @@ -968,7 +968,7 @@ function contact_conversations(App $a, $contact_id, $update) $profiledata = Contact::getDetailsByURL($contact["url"]); if (local_user()) { - if (in_array($profiledata["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) { + if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) { $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]); } } @@ -992,7 +992,7 @@ function contact_posts(App $a, $contact_id) $profiledata = Contact::getDetailsByURL($contact["url"]); if (local_user()) { - if (in_array($profiledata["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) { + if (in_array($profiledata["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) { $profiledata["remoteconnect"] = System::baseUrl()."/follow?url=".urlencode($profiledata["url"]); } } @@ -1073,7 +1073,7 @@ function _contact_detail_for_template(array $rr) */ function contact_actions($contact) { - $poll_enabled = in_array($contact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]); + $poll_enabled = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL]); $contact_actions = []; // Provide friend suggestion only for Friendica contacts diff --git a/mod/dirfind.php b/mod/dirfind.php index 332fe90f6c..4223bb6ecd 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -54,7 +54,7 @@ function dirfind_content(App $a, $prefix = "") { if ((valid_email($search) && Network::isEmailDomainValid($search)) || (substr(normalise_link($search), 0, 7) == "http://")) { $user_data = Probe::uri($search); - $discover_user = (in_array($user_data["network"], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])); + $discover_user = (in_array($user_data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])); } } diff --git a/src/Content/ContactSelector.php b/src/Content/ContactSelector.php index d5efecb806..dc158cfa5f 100644 --- a/src/Content/ContactSelector.php +++ b/src/Content/ContactSelector.php @@ -75,21 +75,22 @@ class ContactSelector public static function networkToName($s, $profile = "") { $nets = [ - Protocol::DFRN => L10n::t('Friendica'), - Protocol::OSTATUS => L10n::t('OStatus'), - Protocol::FEED => L10n::t('RSS/Atom'), - Protocol::MAIL => L10n::t('Email'), - Protocol::DIASPORA => L10n::t('Diaspora'), - Protocol::ZOT => L10n::t('Zot!'), - Protocol::LINKEDIN => L10n::t('LinkedIn'), - Protocol::XMPP => L10n::t('XMPP/IM'), - Protocol::MYSPACE => L10n::t('MySpace'), - Protocol::GPLUS => L10n::t('Google+'), - Protocol::PUMPIO => L10n::t('pump.io'), - Protocol::TWITTER => L10n::t('Twitter'), - Protocol::DIASPORA2 => L10n::t('Diaspora Connector'), - Protocol::STATUSNET => L10n::t('GNU Social Connector'), - Protocol::PNUT => L10n::t('pnut'), + Protocol::DFRN => L10n::t('Friendica'), + Protocol::OSTATUS => L10n::t('OStatus'), + Protocol::FEED => L10n::t('RSS/Atom'), + Protocol::MAIL => L10n::t('Email'), + Protocol::DIASPORA => L10n::t('Diaspora'), + Protocol::ZOT => L10n::t('Zot!'), + Protocol::LINKEDIN => L10n::t('LinkedIn'), + Protocol::XMPP => L10n::t('XMPP/IM'), + Protocol::MYSPACE => L10n::t('MySpace'), + Protocol::GPLUS => L10n::t('Google+'), + Protocol::PUMPIO => L10n::t('pump.io'), + Protocol::TWITTER => L10n::t('Twitter'), + Protocol::DIASPORA2 => L10n::t('Diaspora Connector'), + Protocol::STATUSNET => L10n::t('GNU Social Connector'), + Protocol::ACTIVITYPUB => L10n::t('ActivityPub'), + Protocol::PNUT => L10n::t('pnut'), ]; Addon::callHooks('network_to_name', $nets); @@ -99,7 +100,7 @@ class ContactSelector $networkname = str_replace($search, $replace, $s); - if ((in_array($s, [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) && ($profile != "")) { + if ((in_array($s, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) && ($profile != "")) { $r = DBA::fetchFirst("SELECT `gserver`.`platform` FROM `gcontact` INNER JOIN `gserver` ON `gserver`.`nurl` = `gcontact`.`server_url` WHERE `gcontact`.`nurl` = ? AND `platform` != ''", normalise_link($profile)); diff --git a/src/Content/Widget.php b/src/Content/Widget.php index f245f0d95e..faba55b7a8 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -142,10 +142,7 @@ class Widget $nets = array(); while ($rr = DBA::fetch($r)) { - /// @TODO If 'network' is not there, this triggers an E_NOTICE - if ($rr['network']) { - $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' )); - } + $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' )); } DBA::close($r); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 1bbc0228a8..ab804ab7f1 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -775,7 +775,7 @@ class Contact extends BaseObject } if ((empty($profile["addr"]) || empty($profile["name"])) && (defaults($profile, "gid", 0) != 0) - && in_array($profile["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]) + && in_array($profile["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]) ) { Worker::add(PRIORITY_LOW, "UpdateGContact", $profile["gid"]); } @@ -1088,7 +1088,7 @@ class Contact extends BaseObject } // Last try in gcontact for unsupported networks - if (!in_array($data["network"], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::PUMPIO, Protocol::MAIL, Protocol::FEED])) { + if (!in_array($data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::PUMPIO, Protocol::MAIL, Protocol::FEED])) { if ($uid != 0) { return 0; } @@ -1327,7 +1327,7 @@ class Contact extends BaseObject return ''; } - if (in_array($r[0]["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) { + if (in_array($r[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) { $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))"; } else { $sql = "`item`.`uid` = ?"; diff --git a/src/Model/Conversation.php b/src/Model/Conversation.php index 0692a73412..ba50dc25e4 100644 --- a/src/Model/Conversation.php +++ b/src/Model/Conversation.php @@ -22,6 +22,7 @@ class Conversation const PARCEL_DIASPORA = 2; const PARCEL_SALMON = 3; const PARCEL_FEED = 4; // Deprecated + const PARCEL_ACTIVITYPUB = 5; const PARCEL_SPLIT_CONVERSATION = 6; const PARCEL_TWITTER = 67; @@ -34,7 +35,7 @@ class Conversation public static function insert(array $arr) { if (in_array(defaults($arr, 'network', Protocol::PHANTOM), - [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::TWITTER]) && !empty($arr['uri'])) { + [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::TWITTER]) && !empty($arr['uri'])) { $conversation = ['item-uri' => $arr['uri'], 'received' => DateTimeFormat::utcNow()]; if (isset($arr['parent-uri']) && ($arr['parent-uri'] != $arr['uri'])) { @@ -70,7 +71,8 @@ class Conversation unset($old_conv['source']); } // Update structure data all the time but the source only when its from a better protocol. - if (isset($conversation['protocol']) && isset($conversation['source']) && ($old_conv['protocol'] < $conversation['protocol']) && ($old_conv['protocol'] != 0)) { + if (isset($conversation['protocol']) && isset($conversation['source']) && ($old_conv['protocol'] < $conversation['protocol']) + && ($old_conv['protocol'] != 0) && ($old_conv['protocol'] != self::PARCEL_ACTIVITYPUB)) { unset($conversation['protocol']); unset($conversation['source']); } diff --git a/src/Model/Item.php b/src/Model/Item.php index d10a211a59..9406df2ac8 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -176,7 +176,7 @@ class Item extends BaseObject // We can always comment on posts from these networks if (array_key_exists('writable', $row) && - in_array($row['internal-network'], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) { + in_array($row['internal-network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) { $row['writable'] = true; } @@ -1352,7 +1352,7 @@ class Item extends BaseObject * We have to check several networks since Friendica posts could be repeated * via OStatus (maybe Diasporsa as well) */ - if (in_array($item['network'], [Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS, ""])) { + if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS, ""])) { $condition = ["`uri` = ? AND `uid` = ? AND `network` IN (?, ?, ?)", trim($item['uri']), $item['uid'], Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS]; @@ -2053,7 +2053,7 @@ class Item extends BaseObject // Only distribute public items from native networks $condition = ['id' => $itemid, 'uid' => 0, - 'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""], + 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""], 'visible' => true, 'deleted' => false, 'moderated' => false, 'private' => false]; $item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $itemid]); if (!DBA::isResult($item)) { @@ -2175,7 +2175,7 @@ class Item extends BaseObject } // is it an entry from a connector? Only add an entry for natively connected networks - if (!in_array($item["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) { + if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) { return; } diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index bb0d9ef040..dafc418f69 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -32,6 +32,10 @@ class Inbox extends BaseModule $tempfile = tempnam(get_temppath(), $filename); file_put_contents($tempfile, json_encode(['header' => $_SERVER, 'body' => $postdata])); - System::httpExit(200); + logger('Incoming message stored under ' . $tempfile); + + ActivityPub::processInbox($postdata, $_SERVER); + + System::httpExit(202); } } diff --git a/src/Network/Probe.php b/src/Network/Probe.php index d48617f43b..2cf91486bb 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -331,6 +331,8 @@ class Probe if ($network != Protocol::ACTIVITYPUB) { $data = self::detect($uri, $network, $uid); + } else { + $data = null; } if (in_array(defaults($data, 'network', ''), ['', Protocol::PHANTOM])) { diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 12c849d5b4..71e554d8e5 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -10,11 +10,14 @@ use Friendica\BaseObject; use Friendica\Util\Network; use Friendica\Util\HTTPSignature; use Friendica\Core\Protocol; +use Friendica\Model\Conversation; +use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\User; use Friendica\Util\DateTimeFormat; use Friendica\Util\Crypto; use Friendica\Content\Text\BBCode; +use Friendica\Content\Text\HTML; use Friendica\Network\Probe; /** @@ -474,6 +477,25 @@ class ActivityPub return $profile; } + public static function processInbox($body, $header) + { + logger('Incoming message', LOGGER_DEBUG); + + if (!self::verifySignature($body, $header)) { + logger('Invalid signature, message will be discarded.', LOGGER_DEBUG); + return; + } + + $activity = json_decode($body, true); + + if (!is_array($activity)) { + logger('Invalid body.', LOGGER_DEBUG); + return; + } + + self::processActivity($activity, $body); + } + public static function fetchOutbox($url) { $data = self::fetchContent($url); @@ -493,26 +515,31 @@ class ActivityPub } foreach ($items as $activity) { - self::processActivity($activity, $url); + self::processActivity($activity); } } - function processActivity($activity, $url) + function processActivity($activity, $body = '') { if (empty($activity['type'])) { + logger('Empty type', LOGGER_DEBUG); return; } if (empty($activity['object'])) { + logger('Empty object', LOGGER_DEBUG); return; } if (empty($activity['actor'])) { + logger('Empty actor', LOGGER_DEBUG); return; + } $actor = self::processElement($activity, 'actor', 'id'); if (empty($actor)) { + logger('Empty actor - 2', LOGGER_DEBUG); return; } @@ -521,11 +548,13 @@ class ActivityPub } elseif (!empty($activity['object']['id'])) { $object_url = $activity['object']['id']; } else { + logger('No object found', LOGGER_DEBUG); return; } $receivers = self::getReceivers($activity); if (empty($receivers)) { + logger('No receivers found', LOGGER_DEBUG); return; } @@ -545,6 +574,7 @@ class ActivityPub // To-Do? unset($activity['context']); unset($activity['location']); + unset($activity['signature']); // handled unset($activity['to']); @@ -559,17 +589,19 @@ class ActivityPub unset($activity['instrument']); unset($activity['inReplyTo']); +/* if (!empty($activity)) { echo "Activity\n"; print_r($activity); die($url."\n"); } - +*/ $activity = $structure; // ---------------------------------- - $item = self::fetchObject($object_url, $url); + $item = self::fetchObject($object_url, $activity['object']); if (empty($item)) { + logger("Object data couldn't be processed", LOGGER_DEBUG); return; } @@ -579,28 +611,32 @@ class ActivityPub $item['receiver'] = array_merge($item['receiver'], $receivers); + logger('Processing activity: ' . $activity['type'], LOGGER_DEBUG); + switch ($activity['type']) { case 'Create': case 'Update': - self::createItem($item); + self::createItem($item, $body); break; case 'Announce': - self::announceItem($item); + self::announceItem($item, $body); break; case 'Like': case 'Dislike': - self::activityItem($item); + self::activityItem($item, $body); break; case 'Follow': break; default: - echo "Unknown activity: ".$activity['type']."\n"; + logger('Unknown activity: ' . $activity['type'], LOGGER_DEBUG); +/* echo "Unknown activity: ".$activity['type']."\n"; print_r($item); die(); +*/ break; } } @@ -626,11 +662,11 @@ class ActivityPub } $condition = ['self' => true, 'nurl' => normalise_link($receiver)]; - $contact = DBA::selectFirst('contact', ['id'], $condition); + $contact = DBA::selectFirst('contact', ['uid'], $condition); if (!DBA::isResult($contact)) { continue; } - $receivers[$receiver] = $contact['id']; + $receivers[$receiver] = $contact['uid']; } } return $receivers; @@ -653,67 +689,78 @@ class ActivityPub if (!empty($activity['instrument'])) { $item['service'] = self::processElement($activity, 'instrument', 'name', 'Service'); } - +/* // Remove all "null" fields foreach ($item as $field => $content) { if (is_null($content)) { unset($item[$field]); } } - +*/ return $item; } - private static function fetchObject($object_url, $url) + private static function fetchObject($object_url, $object = []) { $data = self::fetchContent($object_url); if (empty($data)) { - return false; + $data = $object; + if (empty($data)) { + logger('Empty content'); + return false; + } else { + logger('Using provided object'); + } } if (empty($data['type'])) { + logger('Empty type'); return false; } else { $type = $data['type']; + logger('Type ' . $type); } if (in_array($type, ['Note', 'Article', 'Video'])) { - $common = self::processCommonData($data, $url); + $common = self::processCommonData($data); } switch ($type) { case 'Note': - return array_merge($common, self::processNote($data, $url)); + return array_merge($common, self::processNote($data)); case 'Article': - return array_merge($common, self::processArticle($data, $url)); + return array_merge($common, self::processArticle($data)); case 'Video': - return array_merge($common, self::processVideo($data, $url)); + return array_merge($common, self::processVideo($data)); case 'Announce': if (empty($data['object'])) { return false; } - return self::fetchObject($data['object'], $url); + return self::fetchObject($data['object']); case 'Person': case 'Tombstone': break; default: - echo "Unknown object type: ".$data['type']."\n"; + logger('Unknown object type: ' . $data['type'], LOGGER_DEBUG); +/* echo "Unknown object type: ".$data['type']."\n"; print_r($data); die($url."\n"); +*/ break; } } - private static function processCommonData(&$object, $url) + private static function processCommonData(&$object) { if (empty($object['id']) || empty($object['attributedTo'])) { return false; } $item = []; + $item['type'] = $object['type']; $item['uri'] = $object['id']; if (!empty($object['inReplyTo'])) { @@ -789,7 +836,7 @@ class ActivityPub return $item; } - private static function processNote($object, $url) + private static function processNote($object) { $item = []; @@ -810,33 +857,33 @@ class ActivityPub unset($object['quoteUrl']); unset($object['statusnetConversationId']); - if (empty($object)) +// if (empty($object)) return $item; - +/* echo "Unknown Note\n"; print_r($object); print_r($item); die($url."\n"); - +*/ return []; } - private static function processArticle($object, $url) + private static function processArticle($object) { $item = []; - if (empty($object)) +// if (empty($object)) return $item; - +/* echo "Unknown Article\n"; print_r($object); print_r($item); die($url."\n"); - +*/ return []; } - private static function processVideo($object, $url) + private static function processVideo($object) { $item = []; @@ -857,14 +904,14 @@ class ActivityPub unset($object['shares']); unset($object['comments']); - if (empty($object)) +// if (empty($object)) return $item; - +/* echo "Unknown Video\n"; print_r($object); print_r($item); die($url."\n"); - +*/ return []; } @@ -903,9 +950,55 @@ class ActivityPub return false; } - private static function createItem($item) + private static function createItem($activity, $body) { -// print_r($item); +// print_r($activity); + + $item = []; + $item['network'] = Protocol::ACTIVITYPUB; + $item['wall'] = 0; + $item['origin'] = 0; +// $item['private'] = 0; + $item['gravity'] = GRAVITY_COMMENT; + $item['author-id'] = Contact::getIdForURL($activity['author'], 0, true); + $item['owner-id'] = Contact::getIdForURL($activity['owner'], 0, true); + $item['uri'] = $activity['uri']; + $item['parent-uri'] = $activity['reply-to-uri']; + $item['verb'] = ACTIVITY_POST; // Todo + $item['object-type'] = ACTIVITY_OBJ_NOTE; // Todo + $item['created'] = $activity['published']; + $item['edited'] = $activity['updated']; + $item['guid'] = $activity['uuid']; + $item['title'] = HTML::toBBCode($activity['name']); + $item['content-warning'] = HTML::toBBCode($activity['summary']); + $item['body'] = HTML::toBBCode($activity['content']); + $item['location'] = $activity['location']; +// $item['attach'] = $activity['attachments']; +// $item['tag'] = self::constructTagList($activity['tags'], $activity['sensitive']); + $item['app'] = $activity['service']; + $item['plink'] = $activity['alternate-url']; + + $item['protocol'] = Conversation::PARCEL_ACTIVITYPUB; + $item['source'] = $body; +// $item[''] = $activity['context']; + $item['conversation-uri'] = $activity['conversation']; + + foreach ($activity['receiver'] as $receiver) { + $item['uid'] = $receiver; + $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true); + + if (($receiver != 0) && empty($item['contact-id'])) { + $item['contact-id'] = Contact::getIdForURL($activity['author'], 0, true); + } + + $item_id = Item::insert($item); + logger('Storing for user ' . $item['uid'] . ': ' . $item_id); + if (!empty($item_id) && ($item['uid'] == 0)) { + Item::distribute($item_id); + } +//print_r($item); + } +// $item[''] = $activity['receiver']; } private static function announceItem($item) diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 20ee77a07c..61274dc2be 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -333,7 +333,7 @@ class PortableContact $server_url = normalise_link(self::detectServer($profile)); } - if (!in_array($gcontacts[0]["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) { + if (!in_array($gcontacts[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) { logger("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", LOGGER_DEBUG); return false; } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 61eaba388b..55f80c94d7 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -363,9 +363,9 @@ class Notifier } // It only makes sense to distribute answers to OStatus messages to Friendica and OStatus - but not Diaspora - $networks = [Protocol::OSTATUS, Protocol::DFRN]; + $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DFRN]; } else { - $networks = [Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA, Protocol::MAIL]; + $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA, Protocol::MAIL]; } } else { $public_message = false; diff --git a/src/Worker/UpdateGContact.php b/src/Worker/UpdateGContact.php index f2919e4a75..67362917c3 100644 --- a/src/Worker/UpdateGContact.php +++ b/src/Worker/UpdateGContact.php @@ -29,13 +29,13 @@ class UpdateGContact return; } - if (!in_array($r[0]["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) { + if (!in_array($r[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) { return; } $data = Probe::uri($r[0]["url"]); - if (!in_array($data["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) { + if (!in_array($data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) { if ($r[0]["server_url"] != "") { PortableContact::checkServer($r[0]["server_url"], $r[0]["network"]); } From 2e7ca76e15dd8aba82c730a222f8711ed71dead3 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 14 Sep 2018 21:10:49 +0000 Subject: [PATCH 10/97] More fields to import / like could possibly work --- src/Protocol/ActivityPub.php | 280 +++++++++++++++-------------------- 1 file changed, 123 insertions(+), 157 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 71e554d8e5..54c479b50c 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -37,7 +37,7 @@ class ActivityPub { const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; - public static function transmit($content, $target, $uid) + public static function transmit($data, $target, $uid) { $owner = User::getOwnerDataById($uid); @@ -45,6 +45,8 @@ class ActivityPub return; } + $content = json_encode($data); + $host = parse_url($target, PHP_URL_HOST); $path = parse_url($target, PHP_URL_PATH); $date = date('r'); @@ -138,8 +140,6 @@ class ActivityPub $data['actor'] = $item['author-link']; $data['to'] = 'https://www.w3.org/ns/activitystreams#Public'; $data['object'] = self::createNote($item); -// print_r($data); -// print_r($item); return $data; } @@ -150,25 +150,38 @@ class ActivityPub $data['id'] = $item['plink']; //$data['context'] = $data['conversation'] = $item['parent-uri']; $data['actor'] = $item['author-link']; -// if (!$item['private']) { -// $data['to'] = []; -// $data['to'][] = '"https://pleroma.soykaf.com/users/heluecht"'; - $data['to'] = 'https://www.w3.org/ns/activitystreams#Public'; -// $data['cc'] = 'https://pleroma.soykaf.com/users/heluecht'; -// } + $data['to'] = []; + if (!$item['private']) { + $data['to'][] = '"https://pleroma.soykaf.com/users/heluecht"'; + } $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); $data['attributedTo'] = $item['author-link']; $data['name'] = BBCode::convert($item['title'], false, 7); $data['content'] = BBCode::convert($item['body'], false, 7); - //$data['summary'] = ''; - //$data['sensitive'] = false; - //$data['emoji'] = []; - //$data['tag'] = []; - //$data['attachment'] = []; + //$data['summary'] = ''; // Ignore by now + //$data['sensitive'] = false; // - Query NSFW + //$data['emoji'] = []; // Ignore by now + //$data['tag'] = []; /// @ToDo + //$data['attachment'] = []; // @ToDo return $data; } + public static function transmitActivity($activity, $target, $uid) + { + $profile = Probe::uri($target, Protocol::ACTIVITYPUB); + + $owner = User::getOwnerDataById($uid); + + $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => 'https://pirati.ca/' . strtolower($activity) . '/' . System::createGUID(), + 'type' => $activity, + 'actor' => $owner['url'], + 'object' => $profile['url']]; + + return self::transmit($data, $profile['notify'], $uid); + } + /** * Fetches ActivityPub content from the given url * @@ -304,7 +317,7 @@ class ActivityPub $hashalg = 'sha512'; } - /// @todo addd all hashes from the rfc + /// @todo add all hashes from the rfc if (!empty($hashalg) && base64_encode(hash($hashalg, $content, true)) != $digest[1]) { return false; @@ -435,19 +448,7 @@ class ActivityPub } } - // Handled - unset($data['id']); - unset($data['inbox']); - unset($data['outbox']); - unset($data['preferredUsername']); - unset($data['name']); - unset($data['summary']); - unset($data['url']); - unset($data['publicKey']); - unset($data['endpoints']); - unset($data['icon']); - unset($data['uuid']); - +/* // To-Do unset($data['type']); unset($data['manuallyApprovesFollowers']); @@ -468,11 +469,6 @@ class ActivityPub unset($data['isCat']); // Misskey unset($data['kroeg:blocks']); // Kroeg unset($data['updated']); // Kroeg - -/* if (!empty($data)) { - print_r($data); - die(); - } */ return $profile; } @@ -559,6 +555,7 @@ class ActivityPub } // ---------------------------------- +/* // unhandled unset($activity['@context']); unset($activity['id']); @@ -569,40 +566,22 @@ class ActivityPub unset($activity['context_id']); unset($activity['statusnetConversationId']); - $structure = $activity; - // To-Do? unset($activity['context']); unset($activity['location']); unset($activity['signature']); - - // handled - unset($activity['to']); - unset($activity['cc']); - unset($activity['bto']); - unset($activity['bcc']); - unset($activity['type']); - unset($activity['actor']); - unset($activity['object']); - unset($activity['published']); - unset($activity['updated']); - unset($activity['instrument']); - unset($activity['inReplyTo']); - -/* - if (!empty($activity)) { - echo "Activity\n"; - print_r($activity); - die($url."\n"); - } */ - $activity = $structure; - // ---------------------------------- - $item = self::fetchObject($object_url, $activity['object']); - if (empty($item)) { - logger("Object data couldn't be processed", LOGGER_DEBUG); - return; + if (!in_array($activity['type'], ['Like', 'Dislike'])) { + $item = self::fetchObject($object_url, $activity['object']); + if (empty($item)) { + logger("Object data couldn't be processed", LOGGER_DEBUG); + return; + } + } else { + $item['object'] = $object_url; + $item['receiver'] = []; + $item['type'] = $activity['type']; } $item = self::addActivityFields($item, $activity); @@ -616,11 +595,8 @@ class ActivityPub switch ($activity['type']) { case 'Create': case 'Update': - self::createItem($item, $body); - break; - case 'Announce': - self::announceItem($item, $body); + self::createItem($item, $body); break; case 'Like': @@ -633,10 +609,6 @@ class ActivityPub default: logger('Unknown activity: ' . $activity['type'], LOGGER_DEBUG); -/* echo "Unknown activity: ".$activity['type']."\n"; - print_r($item); - die(); -*/ break; } } @@ -689,14 +661,6 @@ class ActivityPub if (!empty($activity['instrument'])) { $item['service'] = self::processElement($activity, 'instrument', 'name', 'Service'); } -/* - // Remove all "null" fields - foreach ($item as $field => $content) { - if (is_null($content)) { - unset($item[$field]); - } - } -*/ return $item; } @@ -745,10 +709,6 @@ class ActivityPub default: logger('Unknown object type: ' . $data['type'], LOGGER_DEBUG); -/* echo "Unknown object type: ".$data['type']."\n"; - print_r($data); - die($url."\n"); -*/ break; } } @@ -792,30 +752,7 @@ class ActivityPub $item['alternate-url'] = self::processElement($object, 'url', 'href'); $item['receiver'] = self::getReceivers($object); - // handled - unset($object['id']); - unset($object['inReplyTo']); - unset($object['published']); - unset($object['updated']); - unset($object['uuid']); - unset($object['attributedTo']); - unset($object['context']); - unset($object['conversation']); - unset($object['sensitive']); - unset($object['name']); - unset($object['title']); - unset($object['content']); - unset($object['summary']); - unset($object['location']); - unset($object['attachment']); - unset($object['tag']); - unset($object['instrument']); - unset($object['url']); - unset($object['to']); - unset($object['cc']); - unset($object['bto']); - unset($object['bcc']); - +/* // To-Do unset($object['source']); @@ -829,10 +766,9 @@ class ActivityPub unset($object['replies']); unset($object['icon']); - /* + // Also missing: audience, preview, endTime, startTime, generator, image - */ - +*/ return $item; } @@ -840,6 +776,7 @@ class ActivityPub { $item = []; +/* // To-Do? unset($object['emoji']); unset($object['atomUri']); @@ -856,37 +793,21 @@ class ActivityPub unset($object['shares']); unset($object['quoteUrl']); unset($object['statusnetConversationId']); - -// if (empty($object)) - return $item; -/* - echo "Unknown Note\n"; - print_r($object); - print_r($item); - die($url."\n"); */ - return []; + return $item; } private static function processArticle($object) { $item = []; -// if (empty($object)) - return $item; -/* - echo "Unknown Article\n"; - print_r($object); - print_r($item); - die($url."\n"); -*/ - return []; + return $item; } private static function processVideo($object) { $item = []; - +/* // To-Do? unset($object['category']); unset($object['licence']); @@ -903,16 +824,8 @@ class ActivityPub unset($object['dislikes']); unset($object['shares']); unset($object['comments']); - -// if (empty($object)) - return $item; -/* - echo "Unknown Video\n"; - print_r($object); - print_r($item); - die($url."\n"); */ - return []; + return $item; } private static function processElement($array, $element, $key, $type = null) @@ -950,37 +863,90 @@ class ActivityPub return false; } + private static function convertMentions($body) + { + $URLSearchString = "^\[\]"; + $body = preg_replace("/\[url\=([$URLSearchString]*)\]([#@!])(.*?)\[\/url\]/ism", '$2[url=$1]$3[/url]', $body); + + return $body; + } + + private static function constructTagList($tags, $sensitive) + { + if (empty($tags)) { + return ''; + } + + $tag_text = ''; + foreach ($tags as $tag) { + if (in_array($tag['type'], ['Mention', 'Hashtag'])) { + if (!empty($tag_text)) { + $tag_text .= ','; + } + + $tag_text .= substr($tag['name'], 0, 1) . '[url=' . $tag['href'] . ']' . substr($tag['name'], 1) . '[/url]'; + } + } + + /// @todo add nsfw for $sensitive + + return $tag_text; + } + + private static function constructAttachList($attachments, $item) + { + if (empty($attachments)) { + return $item; + } + + foreach ($attachments as $attach) { + $filetype = strtolower(substr($attach['mediaType'], 0, strpos($attach['mediaType'], '/'))); + if ($filetype == 'image') { + $item['body'] .= "\n[img]".$attach['url'].'[/img]'; + } else { + if (!empty($item["attach"])) { + $item["attach"] .= ','; + } else { + $item["attach"] = ''; + } + if (!isset($attach['length'])) { + $attach['length'] = "0"; + } + $item["attach"] .= '[attach]href="'.$attach['url'].'" length="'.$attach['length'].'" type="'.$attach['mediaType'].'" title="'.defaults($attach, 'name', '').'"[/attach]'; + } + } + + return $item; + } + private static function createItem($activity, $body) { -// print_r($activity); + /// @todo What to do with $activity['context']? $item = []; $item['network'] = Protocol::ACTIVITYPUB; - $item['wall'] = 0; - $item['origin'] = 0; -// $item['private'] = 0; - $item['gravity'] = GRAVITY_COMMENT; + $item['private'] = !in_array(0, $activity['receiver']); $item['author-id'] = Contact::getIdForURL($activity['author'], 0, true); $item['owner-id'] = Contact::getIdForURL($activity['owner'], 0, true); $item['uri'] = $activity['uri']; $item['parent-uri'] = $activity['reply-to-uri']; - $item['verb'] = ACTIVITY_POST; // Todo - $item['object-type'] = ACTIVITY_OBJ_NOTE; // Todo + $item['verb'] = ACTIVITY_POST; + $item['object-type'] = ACTIVITY_OBJ_NOTE; /// Todo? $item['created'] = $activity['published']; $item['edited'] = $activity['updated']; $item['guid'] = $activity['uuid']; $item['title'] = HTML::toBBCode($activity['name']); $item['content-warning'] = HTML::toBBCode($activity['summary']); - $item['body'] = HTML::toBBCode($activity['content']); + $item['body'] = self::convertMentions(HTML::toBBCode($activity['content'])); $item['location'] = $activity['location']; -// $item['attach'] = $activity['attachments']; -// $item['tag'] = self::constructTagList($activity['tags'], $activity['sensitive']); + $item['tag'] = self::constructTagList($activity['tags'], $activity['sensitive']); $item['app'] = $activity['service']; - $item['plink'] = $activity['alternate-url']; + $item['plink'] = defaults($activity, 'alternate-url', $item['uri']); + + $item = self::constructAttachList($activity['attachments'], $item); $item['protocol'] = Conversation::PARCEL_ACTIVITYPUB; $item['source'] = $body; -// $item[''] = $activity['context']; $item['conversation-uri'] = $activity['conversation']; foreach ($activity['receiver'] as $receiver) { @@ -996,19 +962,19 @@ class ActivityPub if (!empty($item_id) && ($item['uid'] == 0)) { Item::distribute($item_id); } -//print_r($item); } -// $item[''] = $activity['receiver']; } - private static function announceItem($item) + private static function activityItem($data) { -// print_r($item); - } - - private static function activityItem($item) - { - // print_r($item); + logger('Activity "' . $data['type'] . '" for ' . $data['object']); + $items = Item::select(['id'], ['uri' => $data['object']]); + while ($item = Item::fetch($items)) { + logger('Activity ' . $data['type'] . ' for item ' . $item['id'], LOGGER_DEBUG); + Item::performLike($item['id'], strtolower($data['type'])); + } + DBA::close($item); + logger('Activity done'); } } From fb5b6e4a1409a2f8de0b393fea184a2894fd2e0e Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Sep 2018 07:37:34 +0000 Subject: [PATCH 11/97] New uri format for our posts that is AP compatible --- src/Model/Item.php | 8 +------- src/Protocol/Diaspora.php | 14 +++++--------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 9406df2ac8..69a3783bbd 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2329,13 +2329,7 @@ class Item extends BaseObject $guid = System::createGUID(32); } - $hostname = self::getApp()->get_hostname(); - - $user = DBA::selectFirst('user', ['nickname'], ['uid' => $uid]); - - $uri = "urn:X-dfrn:" . $hostname . ':' . $user['nickname'] . ':' . $guid; - - return $uri; + return self::getApp()->get_baseurl() . '/object/' . $guid; } /** diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 7af8dbd424..11a0e5996e 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1592,17 +1592,13 @@ class Diaspora if (DBA::isResult($item)) { return $item["uri"]; } elseif (!$onlyfound) { - $contact = Contact::getDetailsByAddr($author, 0); - if (!empty($contact['network'])) { - $prefix = 'urn:X-' . $contact['network'] . ':'; - } else { - // This fallback should happen most unlikely - $prefix = 'urn:X-dspr:'; - } + $person = self::personByHandle($author); - $author_parts = explode('@', $author); + $parts = parse_url($person['url']); + unset($parts['path']); + $host_url = Network::unparseURL($parts); - return $prefix . $author_parts[1] . ':' . $author_parts[0] . ':'. $guid; + return $host_url . '/object/' . $guid; } return ""; From 957c70d1c6664ff845f32246b89271e2357177c0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Sep 2018 07:40:19 +0000 Subject: [PATCH 12/97] Several improvements --- src/Protocol/ActivityPub.php | 71 +++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 54c479b50c..6489ef8121 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -136,7 +136,7 @@ class ActivityPub 'toot' => 'http://joinmastodon.org/ns#']]]; $data['type'] = 'Create'; - $data['id'] = $item['plink']; + $data['id'] = $item['uri']; $data['actor'] = $item['author-link']; $data['to'] = 'https://www.w3.org/ns/activitystreams#Public'; $data['object'] = self::createNote($item); @@ -147,18 +147,31 @@ class ActivityPub { $data = []; $data['type'] = 'Note'; - $data['id'] = $item['plink']; - //$data['context'] = $data['conversation'] = $item['parent-uri']; + $data['id'] = $item['uri']; + + if ($item['uri'] != $item['thr-parent']) { + $data['inReplyTo'] = $item['thr-parent']; + } + + $conversation = DBA::selectFirst('conversation', ['conversation-uri'], ['item-uri' => $item['parent-uri']]); + if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) { + $conversation_uri = $conversation['conversation-uri']; + } else { + $conversation_uri = $item['parent-uri']; + } + + $data['context'] = $data['conversation'] = $conversation_uri; $data['actor'] = $item['author-link']; $data['to'] = []; if (!$item['private']) { - $data['to'][] = '"https://pleroma.soykaf.com/users/heluecht"'; + $data['to'][] = 'https://www.w3.org/ns/activitystreams#Public'; } $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); $data['attributedTo'] = $item['author-link']; $data['name'] = BBCode::convert($item['title'], false, 7); $data['content'] = BBCode::convert($item['body'], false, 7); + $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"]; //$data['summary'] = ''; // Ignore by now //$data['sensitive'] = false; // - Query NSFW //$data['emoji'] = []; // Ignore by now @@ -548,12 +561,6 @@ class ActivityPub return; } - $receivers = self::getReceivers($activity); - if (empty($receivers)) { - logger('No receivers found', LOGGER_DEBUG); - return; - } - // ---------------------------------- /* // unhandled @@ -573,12 +580,19 @@ class ActivityPub */ if (!in_array($activity['type'], ['Like', 'Dislike'])) { + $receivers = self::getReceivers($activity); + if (empty($receivers)) { + logger('No receivers found', LOGGER_DEBUG); + return; + } + $item = self::fetchObject($object_url, $activity['object']); if (empty($item)) { logger("Object data couldn't be processed", LOGGER_DEBUG); return; } } else { + $receivers = []; $item['object'] = $object_url; $item['receiver'] = []; $item['type'] = $activity['type']; @@ -659,7 +673,7 @@ class ActivityPub } if (!empty($activity['instrument'])) { - $item['service'] = self::processElement($activity, 'instrument', 'name', 'Service'); + $item['service'] = self::processElement($activity, 'instrument', 'name', 'type', 'Service'); } return $item; } @@ -670,19 +684,28 @@ class ActivityPub if (empty($data)) { $data = $object; if (empty($data)) { - logger('Empty content'); + logger('Empty content', LOGGER_DEBUG); return false; + } elseif (is_string($data)) { + logger('No object array provided.', LOGGER_DEBUG); + $item = Item::selectFirst([], ['uri' => $data]); + if (!DBA::isResult($item)) { + logger('Object with url ' . $data . ' was not found locally.', LOGGER_DEBUG); + return false; + } + logger('Using already stored item', LOGGER_DEBUG); + $data = self::createNote($item); } else { - logger('Using provided object'); + logger('Using provided object', LOGGER_DEBUG); } } if (empty($data['type'])) { - logger('Empty type'); + logger('Empty type', LOGGER_DEBUG); return false; } else { $type = $data['type']; - logger('Type ' . $type); + logger('Type ' . $type, LOGGER_DEBUG); } if (in_array($type, ['Note', 'Article', 'Video'])) { @@ -745,10 +768,11 @@ class ActivityPub $item['name'] = defaults($object, 'name', $item['name']); $item['summary'] = defaults($object, 'summary', null); $item['content'] = defaults($object, 'content', null); - $item['location'] = self::processElement($object, 'location', 'name', 'Place'); + $item['source'] = defaults($object, 'source', null); + $item['location'] = self::processElement($object, 'location', 'name', 'type', 'Place'); $item['attachments'] = defaults($object, 'attachment', null); $item['tags'] = defaults($object, 'tag', null); - $item['service'] = self::processElement($object, 'instrument', 'name', 'Service'); + $item['service'] = self::processElement($object, 'instrument', 'name', 'type', 'Service'); $item['alternate-url'] = self::processElement($object, 'url', 'href'); $item['receiver'] = self::getReceivers($object); @@ -828,7 +852,7 @@ class ActivityPub return $item; } - private static function processElement($array, $element, $key, $type = null) + private static function processElement($array, $element, $key, $type = null, $type_value = null) { if (empty($array)) { return false; @@ -842,7 +866,7 @@ class ActivityPub return $array[$element]; } - if (is_null($type)) { + if (is_null($type_value)) { if (!empty($array[$element][$key])) { return $array[$element][$key]; } @@ -854,7 +878,7 @@ class ActivityPub return false; } - if (!empty($array[$element][$key]) && !empty($array[$element]['type']) && ($array[$element]['type'] == $type)) { + if (!empty($array[$element][$key]) && !empty($array[$element][$type]) && ($array[$element][$type] == $type_value)) { return $array[$element][$key]; } @@ -945,6 +969,11 @@ class ActivityPub $item = self::constructAttachList($activity['attachments'], $item); + $source = self::processElement($activity, 'source', 'content', 'mediaType', 'text/bbcode'); + if (!empty($source)) { + $item['body'] = $source; + } + $item['protocol'] = Conversation::PARCEL_ACTIVITYPUB; $item['source'] = $body; $item['conversation-uri'] = $activity['conversation']; @@ -974,7 +1003,7 @@ class ActivityPub Item::performLike($item['id'], strtolower($data['type'])); } DBA::close($item); - logger('Activity done'); + logger('Activity done', LOGGER_DEBUG); } } From 35854a0ad1b05704f9b573aab0a142daa2ebc7ec Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Sep 2018 10:13:41 +0000 Subject: [PATCH 13/97] Adding "(AP)" to the server name when posted via AP --- src/Content/ContactSelector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Content/ContactSelector.php b/src/Content/ContactSelector.php index dc158cfa5f..6a701f25f3 100644 --- a/src/Content/ContactSelector.php +++ b/src/Content/ContactSelector.php @@ -107,6 +107,10 @@ class ContactSelector if (DBA::isResult($r)) { $networkname = $r['platform']; + + if ($s == Protocol::ACTIVITYPUB) { + $networkname .= ' (AP)'; + } } } From 96f575fe281b3629389c7d7a5a84751cf8000675 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Sep 2018 10:14:56 +0000 Subject: [PATCH 14/97] Processing of personal inbox enabled --- src/Module/Inbox.php | 15 +++++++++++-- src/Protocol/ActivityPub.php | 42 +++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index dafc418f69..d47419a415 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -7,6 +7,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Protocol\ActivityPub; use Friendica\Core\System; +use Friendica\Database\DBA; /** * ActivityPub Inbox @@ -30,11 +31,21 @@ class Inbox extends BaseModule } $tempfile = tempnam(get_temppath(), $filename); - file_put_contents($tempfile, json_encode(['header' => $_SERVER, 'body' => $postdata])); + file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata])); logger('Incoming message stored under ' . $tempfile); - ActivityPub::processInbox($postdata, $_SERVER); + if (!empty($a->argv[1])) { + $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]); + if (!DBA::isResult($user)) { + System::httpExit(404); + } + $uid = $user['uid']; + } else { + $uid = 0; + } + + ActivityPub::processInbox($postdata, $_SERVER, $uid); System::httpExit(202); } diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 6489ef8121..e80568487b 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -32,6 +32,20 @@ use Friendica\Network\Probe; * * Digest: https://tools.ietf.org/html/rfc5843 * https://tools.ietf.org/html/draft-cavage-http-signatures-10#ref-15 + * + * To-do: + * + * Receiver: + * - Activities: Follow, Accept, Update + * - Object Types: Person, Tombstome + * + * Transmitter: + * - Activities: Like, Dislike, Follow, Accept, Update + * - Object Tyoes: Article, Announce, Person, Tombstone + * + * General: + * - Message distribution + * - Endpoints: Outbox, Object, Follower, Following */ class ActivityPub { @@ -187,7 +201,7 @@ class ActivityPub $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => 'https://pirati.ca/' . strtolower($activity) . '/' . System::createGUID(), + 'id' => 'https://pirati.ca/activity/' . System::createGUID(), 'type' => $activity, 'actor' => $owner['url'], 'object' => $profile['url']]; @@ -486,9 +500,9 @@ class ActivityPub return $profile; } - public static function processInbox($body, $header) + public static function processInbox($body, $header, $uid) { - logger('Incoming message', LOGGER_DEBUG); + logger('Incoming message for user ' . $uid, LOGGER_DEBUG); if (!self::verifySignature($body, $header)) { logger('Invalid signature, message will be discarded.', LOGGER_DEBUG); @@ -502,7 +516,7 @@ class ActivityPub return; } - self::processActivity($activity, $body); + self::processActivity($activity, $body, $uid); } public static function fetchOutbox($url) @@ -528,7 +542,7 @@ class ActivityPub } } - function processActivity($activity, $body = '') + function processActivity($activity, $body = '', $uid = null) { if (empty($activity['type'])) { logger('Empty type', LOGGER_DEBUG); @@ -578,21 +592,25 @@ class ActivityPub unset($activity['location']); unset($activity['signature']); */ + // Fetch all receivers from to, cc, bto and bcc + $receivers = self::getReceivers($activity); + + // When it is a delivery to a personal inbox we add that user to the receivers + if (!empty($uid)) { + $owner = User::getOwnerDataById($uid); + $additional = [$owner['url'] => $uid]; + $receivers = array_merge($receivers, $additional); + } + + logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG); if (!in_array($activity['type'], ['Like', 'Dislike'])) { - $receivers = self::getReceivers($activity); - if (empty($receivers)) { - logger('No receivers found', LOGGER_DEBUG); - return; - } - $item = self::fetchObject($object_url, $activity['object']); if (empty($item)) { logger("Object data couldn't be processed", LOGGER_DEBUG); return; } } else { - $receivers = []; $item['object'] = $object_url; $item['receiver'] = []; $item['type'] = $activity['type']; From 6a8ebc8639507404be07bb7d6fd5a37189e46563 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Sep 2018 18:54:45 +0000 Subject: [PATCH 15/97] Contact follow and unfollow workd partially --- mod/dfrn_confirm.php | 40 +++----- mod/follow.php | 3 +- src/Model/Contact.php | 43 +++++---- src/Model/Item.php | 67 +++++++++++++ src/Protocol/ActivityPub.php | 177 +++++++++++++++++++++++++++++++---- 5 files changed, 268 insertions(+), 62 deletions(-) diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 41b5e0ef54..2a872dd414 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -28,6 +28,7 @@ use Friendica\Model\Group; use Friendica\Model\User; use Friendica\Network\Probe; use Friendica\Protocol\Diaspora; +use Friendica\Protocol\ActivityPub; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -335,10 +336,17 @@ function dfrn_confirm_post(App $a, $handsfree = null) intval($contact_id) ); } else { + if ($network == Protocol::ACTIVITYPUB) { + ActivityPub::transmitContactActivity('Accept', $contact['url'], $contact['hub-verify'], $uid); + $pending = true; + } else { + $pending = false; + } + // $network !== Protocol::DFRN $network = defaults($contact, 'network', Protocol::OSTATUS); - $arr = Probe::uri($contact['url']); + $arr = Probe::uri($contact['url'], $network); $notify = defaults($contact, 'notify' , $arr['notify']); $poll = defaults($contact, 'poll' , $arr['poll']); @@ -362,30 +370,12 @@ function dfrn_confirm_post(App $a, $handsfree = null) DBA::delete('intro', ['id' => $intro_id]); - $r = q("UPDATE `contact` SET `name-date` = '%s', - `uri-date` = '%s', - `addr` = '%s', - `notify` = '%s', - `poll` = '%s', - `blocked` = 0, - `pending` = 0, - `network` = '%s', - `writable` = %d, - `hidden` = %d, - `rel` = %d - WHERE `id` = %d - ", - DBA::escape(DateTimeFormat::utcNow()), - DBA::escape(DateTimeFormat::utcNow()), - DBA::escape($addr), - DBA::escape($notify), - DBA::escape($poll), - DBA::escape($network), - intval($writable), - intval($hidden), - intval($new_relation), - intval($contact_id) - ); + $fields = ['name-date' => DateTimeFormat::utcNow(), + 'uri-date' => DateTimeFormat::utcNow(), 'addr' => $addr, + 'notify' => $notify, 'poll' => $poll, 'blocked' => false, + 'pending' => $pending, 'network' => $network, + 'writable' => $writable, 'hidden' => $hidden, 'rel' => $new_relation]; + DBA::update('contact', $fields, ['id' => $contact_id]); } if (!DBA::isResult($r)) { diff --git a/mod/follow.php b/mod/follow.php index 627ab52033..65028a70e0 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -31,7 +31,8 @@ function follow_post(App $a) // This is just a precaution if maybe this page is called somewhere directly via POST $_SESSION['fastlane'] = $url; - $result = Contact::createFromProbe($uid, $url, true); + $result = Contact::createFromProbe($uid, $url, true, Protocol::ACTIVITYPUB); +// $result = Contact::createFromProbe($uid, $url, true); if ($result['success'] == false) { if ($result['message']) { diff --git a/src/Model/Contact.php b/src/Model/Contact.php index ab804ab7f1..2bcb86327b 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -16,6 +16,7 @@ use Friendica\Database\DBA; use Friendica\Model\Profile; use Friendica\Network\Probe; use Friendica\Object\Image; +use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Diaspora; use Friendica\Protocol\DFRN; use Friendica\Protocol\OStatus; @@ -555,6 +556,8 @@ class Contact extends BaseObject } } elseif ($contact['network'] == Protocol::DIASPORA) { Diaspora::sendUnshare($user, $contact); + } elseif ($contact['network'] == Protocol::ACTIVITYPUB) { + ActivityPub::transmitContactActivity('Undo', $contact['url'], '', $user['uid']); } } @@ -1054,7 +1057,6 @@ class Contact extends BaseObject if (!x($contact, 'avatar')) { $update_contact = true; } - if (!$update_contact || $no_update) { return $contact_id; } @@ -1495,10 +1497,11 @@ class Contact extends BaseObject } /** - * @param integer $id contact id + * @param integer $id contact id + * @param string $network Optional network we are probing for * @return boolean */ - public static function updateFromProbe($id) + public static function updateFromProbe($id, $network = '') { /* Warning: Never ever fetch the public key via Probe::uri and write it into the contacts. @@ -1511,10 +1514,10 @@ class Contact extends BaseObject return false; } - $ret = Probe::uri($contact["url"]); + $ret = Probe::uri($contact["url"], $network); // If Probe::uri fails the network code will be different - if ($ret["network"] != $contact["network"]) { + if (($ret["network"] != $contact["network"]) && ($ret["network"] != $network)) { return false; } @@ -1537,14 +1540,15 @@ class Contact extends BaseObject DBA::update( 'contact', [ - 'url' => $ret['url'], - 'nurl' => normalise_link($ret['url']), - 'addr' => $ret['addr'], - 'alias' => $ret['alias'], - 'batch' => $ret['batch'], - 'notify' => $ret['notify'], - 'poll' => $ret['poll'], - 'poco' => $ret['poco'] + 'url' => $ret['url'], + 'nurl' => normalise_link($ret['url']), + 'network' => $ret['network'], + 'addr' => $ret['addr'], + 'alias' => $ret['alias'], + 'batch' => $ret['batch'], + 'notify' => $ret['notify'], + 'poll' => $ret['poll'], + 'poco' => $ret['poco'] ], ['id' => $id] ); @@ -1686,7 +1690,7 @@ class Contact extends BaseObject $hidden = (($ret['network'] === Protocol::MAIL) ? 1 : 0); - if (in_array($ret['network'], [Protocol::MAIL, Protocol::DIASPORA])) { + if (in_array($ret['network'], [Protocol::MAIL, Protocol::DIASPORA, Protocol::ACTIVITYPUB])) { $writeable = 1; } @@ -1766,6 +1770,9 @@ class Contact extends BaseObject } elseif ($contact['network'] == Protocol::DIASPORA) { $ret = Diaspora::sendShare($a->user, $contact); logger('share returns: ' . $ret); + } elseif ($contact['network'] == Protocol::ACTIVITYPUB) { + $ret = ActivityPub::transmitActivity('Follow', $contact['url'], $uid); + logger('Follow returns: ' . $ret); } } @@ -1814,7 +1821,7 @@ class Contact extends BaseObject return $contact; } - public static function addRelationship($importer, $contact, $datarray, $item, $sharing = false) { + public static function addRelationship($importer, $contact, $datarray, $item = '', $sharing = false) { // Should always be set if (empty($datarray['author-id'])) { return; @@ -1839,13 +1846,17 @@ class Contact extends BaseObject DBA::update('contact', ['rel' => self::FRIEND, 'writable' => true], ['id' => $contact['id'], 'uid' => $importer['uid']]); } + + if ($contact['network'] == Protocol::ACTIVITYPUB) { + ActivityPub::transmitContactActivity('Accept', $contact['url'], $contact['hub-verify'], $importer['uid']); + } + // send email notification to owner? } else { if (DBA::exists('contact', ['nurl' => normalise_link($url), 'uid' => $importer['uid'], 'pending' => true])) { logger('ignoring duplicated connection request from pending contact ' . $url); return; } - // create contact record q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`, `blocked`, `readonly`, `pending`, `writable`) diff --git a/src/Model/Item.php b/src/Model/Item.php index 69a3783bbd..68ebc690e8 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2071,6 +2071,47 @@ class Item extends BaseObject $users = []; + $owner = DBA::selectFirst('contact', ['url', 'nurl', 'alias'], ['id' => $parent['owner-id']]); + if (!DBA::isResult($owner)) { + return; + } + + $condition = ['nurl' => $owner['nurl'], 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $contacts = DBA::select('contact', ['uid'], $condition); + while ($contact = DBA::fetch($contacts)) { + if ($contact['uid'] == 0) { + continue; + } + + $users[$contact['uid']] = $contact['uid']; + } + DBA::close($contacts); + + $condition = ['alias' => $owner['url'], 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $contacts = DBA::select('contact', ['uid'], $condition); + while ($contact = DBA::fetch($contacts)) { + if ($contact['uid'] == 0) { + continue; + } + + $users[$contact['uid']] = $contact['uid']; + } + DBA::close($contacts); + + if (!empty($owner['alias'])) { + $condition = ['url' => $owner['alias'], 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $contacts = DBA::select('contact', ['uid'], $condition); + while ($contact = DBA::fetch($contacts)) { + if ($contact['uid'] == 0) { + continue; + } + + $users[$contact['uid']] = $contact['uid']; + } + DBA::close($contacts); + } +/* + $condition = ["`nurl` IN (SELECT `nurl` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)", $parent['owner-id'], Contact::SHARING, Contact::FRIEND]; @@ -2080,6 +2121,32 @@ class Item extends BaseObject $users[$contact['uid']] = $contact['uid']; } + DBA::close($contacts); + + // And the same with the alias in the user contacts + $condition = ["`alias` IN (SELECT `url` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)", + $parent['owner-id'], Contact::SHARING, Contact::FRIEND]; + + $contacts = DBA::select('contact', ['uid'], $condition); + + while ($contact = DBA::fetch($contacts)) { + $users[$contact['uid']] = $contact['uid']; + } + + DBA::close($contacts); + + // And vice versa + $condition = ["`url` IN (SELECT `alias` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)", + $parent['owner-id'], Contact::SHARING, Contact::FRIEND]; + + $contacts = DBA::select('contact', ['uid'], $condition); + + while ($contact = DBA::fetch($contacts)) { + $users[$contact['uid']] = $contact['uid']; + } + + DBA::close($contacts); +*/ $origin_uid = 0; if ($item['uri'] != $item['parent-uri']) { diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index e80568487b..78d5d44daf 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -33,14 +33,17 @@ use Friendica\Network\Probe; * Digest: https://tools.ietf.org/html/rfc5843 * https://tools.ietf.org/html/draft-cavage-http-signatures-10#ref-15 * + * Part of the code for HTTP signing is taken from the Osada project. + * + * * To-do: * * Receiver: - * - Activities: Follow, Accept, Update + * - Activities: Undo, Update * - Object Types: Person, Tombstome * * Transmitter: - * - Activities: Like, Dislike, Follow, Accept, Update + * - Activities: Like, Dislike, Update, Undo * - Object Tyoes: Article, Announce, Person, Tombstone * * General: @@ -77,7 +80,7 @@ class ActivityPub Network::post($target, $content, $headers); $return_code = BaseObject::getApp()->get_curl_code(); - echo $return_code."\n"; + logger('Transmit to ' . $target . ' returned ' . $return_code); } /** @@ -206,6 +209,28 @@ class ActivityPub 'actor' => $owner['url'], 'object' => $profile['url']]; + logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG); + return self::transmit($data, $profile['notify'], $uid); + } + + public static function transmitContactActivity($activity, $target, $id, $uid) + { + $profile = Probe::uri($target, Protocol::ACTIVITYPUB); + + if (empty($id)) { + $id = 'https://pirati.ca/activity/' . System::createGUID(); + } + + $owner = User::getOwnerDataById($uid); + $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => 'https://pirati.ca/activity/' . System::createGUID(), + 'type' => $activity, + 'actor' => $owner['url'], + 'object' => ['id' => $id, 'type' => 'Follow', + 'actor' => $owner['url'], + 'object' => $profile['url']]]; + + logger('Sending ' . $activity . ' to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); return self::transmit($data, $profile['notify'], $uid); } @@ -604,14 +629,24 @@ class ActivityPub logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG); - if (!in_array($activity['type'], ['Like', 'Dislike'])) { + logger('Processing activity: ' . $activity['type'], LOGGER_DEBUG); + + // Fetch the content only on activities where this matters + if (in_array($activity['type'], ['Create', 'Update', 'Announce'])) { $item = self::fetchObject($object_url, $activity['object']); if (empty($item)) { logger("Object data couldn't be processed", LOGGER_DEBUG); return; } } else { - $item['object'] = $object_url; + if (in_array($activity['type'], ['Accept'])) { + $item['object'] = self::processElement($activity, 'object', 'actor', 'type', 'Follow'); + } elseif (in_array($activity['type'], ['Undo'])) { + $item['object'] = self::processElement($activity, 'object', 'object', 'type', 'Follow'); + } else { + $item['object'] = $object_url; + } + $item['id'] = $activity['id']; $item['receiver'] = []; $item['type'] = $activity['type']; } @@ -622,8 +657,6 @@ class ActivityPub $item['receiver'] = array_merge($item['receiver'], $receivers); - logger('Processing activity: ' . $activity['type'], LOGGER_DEBUG); - switch ($activity['type']) { case 'Create': case 'Update': @@ -632,11 +665,25 @@ class ActivityPub break; case 'Like': + self::likeItem($item, $body); + break; + case 'Dislike': - self::activityItem($item, $body); + break; + + case 'Delete': break; case 'Follow': + self::followUser($item); + break; + + case 'Accept': + self::acceptFollowUser($item); + break; + + case 'Undo': + self::undoFollowUser($item); break; default: @@ -962,18 +1009,42 @@ class ActivityPub } private static function createItem($activity, $body) + { + $item = []; + $item['verb'] = ACTIVITY_POST; + $item['parent-uri'] = $activity['reply-to-uri']; + + if ($activity['reply-to-uri'] == $activity['uri']) { + $item['gravity'] = GRAVITY_PARENT; + $item['object-type'] = ACTIVITY_OBJ_NOTE; + } else { + $item['gravity'] = GRAVITY_COMMENT; + $item['object-type'] = ACTIVITY_OBJ_COMMENT; + } + + self::postItem($activity, $item, $body); + } + + private static function likeItem($activity, $body) + { + $item = []; + $item['verb'] = ACTIVITY_LIKE; + $item['parent-uri'] = $activity['object']; + $item['gravity'] = GRAVITY_ACTIVITY; + $item['object-type'] = ACTIVITY_OBJ_NOTE; + + self::postItem($activity, $item, $body); + } + + private static function postItem($activity, $item, $body) { /// @todo What to do with $activity['context']? - $item = []; $item['network'] = Protocol::ACTIVITYPUB; $item['private'] = !in_array(0, $activity['receiver']); $item['author-id'] = Contact::getIdForURL($activity['author'], 0, true); $item['owner-id'] = Contact::getIdForURL($activity['owner'], 0, true); $item['uri'] = $activity['uri']; - $item['parent-uri'] = $activity['reply-to-uri']; - $item['verb'] = ACTIVITY_POST; - $item['object-type'] = ACTIVITY_OBJ_NOTE; /// Todo? $item['created'] = $activity['published']; $item['edited'] = $activity['updated']; $item['guid'] = $activity['uuid']; @@ -1012,16 +1083,82 @@ class ActivityPub } } - private static function activityItem($data) + private static function followUser($activity) { - logger('Activity "' . $data['type'] . '" for ' . $data['object']); - $items = Item::select(['id'], ['uri' => $data['object']]); - while ($item = Item::fetch($items)) { - logger('Activity ' . $data['type'] . ' for item ' . $item['id'], LOGGER_DEBUG); - Item::performLike($item['id'], strtolower($data['type'])); + if (empty($activity['receiver'][$activity['object']])) { + return; } - DBA::close($item); - logger('Activity done', LOGGER_DEBUG); + + $uid = $activity['receiver'][$activity['object']]; + $owner = User::getOwnerDataById($uid); + + $cid = Contact::getIdForURL($activity['owner'], $uid); + if (!empty($cid)) { + $contact = DBA::selectFirst('contact', [], ['id' => $cid]); + } else { + $contact = false; + } + + $item = ['author-id' => Contact::getIdForURL($activity['owner'])]; + + Contact::addRelationship($owner, $contact, $item); + + $cid = Contact::getIdForURL($activity['owner'], $uid); + if (empty($cid)) { + return; + } + + $contact = DBA::selectFirst('contact', ['network'], ['id' => $cid]); + if ($contact['network'] != Protocol::ACTIVITYPUB) { + Contact::updateFromProbe($cid, Protocol::ACTIVITYPUB); + } + + DBA::update('contact', ['hub-verify' => $activity['id']], ['id' => $cid]); + logger('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']); } + private static function acceptFollowUser($activity) + { + if (empty($activity['receiver'][$activity['object']])) { + return; + } + + $uid = $activity['receiver'][$activity['object']]; + $owner = User::getOwnerDataById($uid); + + $cid = Contact::getIdForURL($activity['owner'], $uid); + if (empty($cid)) { + logger('No contact found for ' . $activity['owner'], LOGGER_DEBUG); + return; + } + + $fields = ['pending' => false]; + $condition = ['id' => $cid, 'pending' => true]; + DBA::update('comtact', $fields, $condition); + logger('Accept contact request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG); + } + + private static function undoFollowUser($activity) + { + if (empty($activity['receiver'][$activity['object']])) { + return; + } + + $uid = $activity['receiver'][$activity['object']]; + $owner = User::getOwnerDataById($uid); + + $cid = Contact::getIdForURL($activity['owner'], $uid); + if (empty($cid)) { + logger('No contact found for ' . $activity['owner'], LOGGER_DEBUG); + return; + } + + $contact = DBA::selectFirst('contact', [], ['id' => $cid]); + if (!DBA::isResult($contact)) { + return; + } + + Contact::removeFollower($owner, $contact); + logger('Undo following request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG); + } } From 86bd28370525a4fb6d4a55ea48cb509ef58ce5ff Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Sep 2018 20:31:05 +0000 Subject: [PATCH 16/97] The whole contact handling does work now, yeah ... --- mod/dfrn_confirm.php | 2 +- src/Model/Contact.php | 6 +++--- src/Protocol/ActivityPub.php | 27 ++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 2a872dd414..4abaf978fb 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -337,7 +337,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) ); } else { if ($network == Protocol::ACTIVITYPUB) { - ActivityPub::transmitContactActivity('Accept', $contact['url'], $contact['hub-verify'], $uid); + ActivityPub::transmitContactAccept($contact['url'], $contact['hub-verify'], $uid); $pending = true; } else { $pending = false; diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 2bcb86327b..1e61c0d10d 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -557,7 +557,7 @@ class Contact extends BaseObject } elseif ($contact['network'] == Protocol::DIASPORA) { Diaspora::sendUnshare($user, $contact); } elseif ($contact['network'] == Protocol::ACTIVITYPUB) { - ActivityPub::transmitContactActivity('Undo', $contact['url'], '', $user['uid']); + ActivityPub::transmitContactUndo($contact['url'], '', $user['uid']); } } @@ -1834,7 +1834,7 @@ class Contact extends BaseObject return; } - $url = $pub_contact['url']; + $url = defaults($datarray, 'author-link', $pub_contact['url']); $name = $pub_contact['name']; $photo = $pub_contact['photo']; $nick = $pub_contact['nick']; @@ -1848,7 +1848,7 @@ class Contact extends BaseObject } if ($contact['network'] == Protocol::ACTIVITYPUB) { - ActivityPub::transmitContactActivity('Accept', $contact['url'], $contact['hub-verify'], $importer['uid']); + ActivityPub::transmitContactAccept($contact['url'], $contact['hub-verify'], $importer['uid']); } // send email notification to owner? diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 78d5d44daf..73d5231d72 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -213,7 +213,24 @@ class ActivityPub return self::transmit($data, $profile['notify'], $uid); } - public static function transmitContactActivity($activity, $target, $id, $uid) + public static function transmitContactAccept($target, $id, $uid) + { + $profile = Probe::uri($target, Protocol::ACTIVITYPUB); + + $owner = User::getOwnerDataById($uid); + $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => 'https://pirati.ca/activity/' . System::createGUID(), + 'type' => 'Accept', + 'actor' => $owner['url'], + 'object' => ['id' => $id, 'type' => 'Follow', + 'actor' => $profile['url'], + 'object' => $owner['url']]]; + + logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); + return self::transmit($data, $profile['notify'], $uid); + } + + public static function transmitContactUndo($target, $id, $uid) { $profile = Probe::uri($target, Protocol::ACTIVITYPUB); @@ -224,13 +241,13 @@ class ActivityPub $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', 'id' => 'https://pirati.ca/activity/' . System::createGUID(), - 'type' => $activity, + 'type' => 'Undo', 'actor' => $owner['url'], 'object' => ['id' => $id, 'type' => 'Follow', 'actor' => $owner['url'], 'object' => $profile['url']]]; - logger('Sending ' . $activity . ' to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); + logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); return self::transmit($data, $profile['notify'], $uid); } @@ -1099,10 +1116,10 @@ class ActivityPub $contact = false; } - $item = ['author-id' => Contact::getIdForURL($activity['owner'])]; + $item = ['author-id' => Contact::getIdForURL($activity['owner']), + 'author-link' => $activity['owner']]; Contact::addRelationship($owner, $contact, $item); - $cid = Contact::getIdForURL($activity['owner'], $uid); if (empty($cid)) { return; From f5104f3e46d27e6535bd8a07a98ead5b0c6755a8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Sep 2018 20:48:24 +0000 Subject: [PATCH 17/97] Removed harcoded host names --- src/Protocol/ActivityPub.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 73d5231d72..df6b0342be 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -39,11 +39,11 @@ use Friendica\Network\Probe; * To-do: * * Receiver: - * - Activities: Undo, Update + * - Activities: Dislike, Update, Delete * - Object Types: Person, Tombstome * * Transmitter: - * - Activities: Like, Dislike, Update, Undo + * - Activities: Like, Dislike, Update, Delete * - Object Tyoes: Article, Announce, Person, Tombstone * * General: @@ -204,7 +204,7 @@ class ActivityPub $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => 'https://pirati.ca/activity/' . System::createGUID(), + 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => $activity, 'actor' => $owner['url'], 'object' => $profile['url']]; @@ -219,7 +219,7 @@ class ActivityPub $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => 'https://pirati.ca/activity/' . System::createGUID(), + 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => 'Accept', 'actor' => $owner['url'], 'object' => ['id' => $id, 'type' => 'Follow', @@ -235,12 +235,12 @@ class ActivityPub $profile = Probe::uri($target, Protocol::ACTIVITYPUB); if (empty($id)) { - $id = 'https://pirati.ca/activity/' . System::createGUID(); + $id = System::baseUrl() . '/activity/' . System::createGUID(); } $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => 'https://pirati.ca/activity/' . System::createGUID(), + 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => 'Undo', 'actor' => $owner['url'], 'object' => ['id' => $id, 'type' => 'Follow', From 2eabe45a8e23512e31517ae8660f0576c111e32c Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Sep 2018 22:25:58 +0000 Subject: [PATCH 18/97] Contact reject does work now as well --- mod/dfrn_confirm.php | 6 +++++- src/Model/Contact.php | 6 +++++- src/Protocol/ActivityPub.php | 35 ++++++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 4abaf978fb..90d3d8990c 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -356,7 +356,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) $new_relation = $contact['rel']; $writable = $contact['writable']; - if ($network === Protocol::DIASPORA) { + if (in_array($network, [Protocol::DIASPORA, Protocol::ACTIVITYPUB])) { if ($duplex) { $new_relation = Contact::FRIEND; } else { @@ -393,6 +393,10 @@ function dfrn_confirm_post(App $a, $handsfree = null) Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact['id']); + if ($network == Protocol::ACTIVITYPUB && $duplex) { + ActivityPub::transmitActivity('Follow', $contact['url'], $uid); + } + // Let's send our user to the contact editor in case they want to // do anything special with this new friend. if ($handsfree === null) { diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 1e61c0d10d..ae42030952 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -557,7 +557,11 @@ class Contact extends BaseObject } elseif ($contact['network'] == Protocol::DIASPORA) { Diaspora::sendUnshare($user, $contact); } elseif ($contact['network'] == Protocol::ACTIVITYPUB) { - ActivityPub::transmitContactUndo($contact['url'], '', $user['uid']); + ActivityPub::transmitContactUndo($contact['url'], $user['uid']); + + if ($dissolve) { + ActivityPub::transmitContactReject($contact['url'], $contact['hub-verify'], $user['uid']); + } } } diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index df6b0342be..19407b825b 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -230,17 +230,32 @@ class ActivityPub return self::transmit($data, $profile['notify'], $uid); } - public static function transmitContactUndo($target, $id, $uid) + public static function transmitContactReject($target, $id, $uid) { $profile = Probe::uri($target, Protocol::ACTIVITYPUB); - if (empty($id)) { - $id = System::baseUrl() . '/activity/' . System::createGUID(); - } - $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', 'id' => System::baseUrl() . '/activity/' . System::createGUID(), + 'type' => 'Reject', + 'actor' => $owner['url'], + 'object' => ['id' => $id, 'type' => 'Follow', + 'actor' => $profile['url'], + 'object' => $owner['url']]]; + + logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); + return self::transmit($data, $profile['notify'], $uid); + } + + public static function transmitContactUndo($target, $uid) + { + $profile = Probe::uri($target, Protocol::ACTIVITYPUB); + + $id = System::baseUrl() . '/activity/' . System::createGUID(); + + $owner = User::getOwnerDataById($uid); + $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => $id, 'type' => 'Undo', 'actor' => $owner['url'], 'object' => ['id' => $id, 'type' => 'Follow', @@ -1150,8 +1165,14 @@ class ActivityPub } $fields = ['pending' => false]; - $condition = ['id' => $cid, 'pending' => true]; - DBA::update('comtact', $fields, $condition); + + $contact = DBA::selectFirst('contact', ['rel'], ['id' => $cid]); + if ($contact['rel'] == Contact::FOLLOWER) { + $fields['rel'] = Contact::FRIEND; + } + + $condition = ['id' => $cid]; + DBA::update('contact', $fields, $condition); logger('Accept contact request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG); } From a7f5c1f4c63136901a72269ec0fdfb1f6db3e4e5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 15 Sep 2018 23:06:03 +0000 Subject: [PATCH 19/97] Likes work now --- src/Protocol/ActivityPub.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 19407b825b..85d21d7cba 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -34,7 +34,7 @@ use Friendica\Network\Probe; * https://tools.ietf.org/html/draft-cavage-http-signatures-10#ref-15 * * Part of the code for HTTP signing is taken from the Osada project. - * + * https://framagit.org/macgirvin/osada * * To-do: * @@ -49,6 +49,7 @@ use Friendica\Network\Probe; * General: * - Message distribution * - Endpoints: Outbox, Object, Follower, Following + * - General cleanup */ class ActivityPub { @@ -676,6 +677,19 @@ class ActivityPub } elseif (in_array($activity['type'], ['Undo'])) { $item['object'] = self::processElement($activity, 'object', 'object', 'type', 'Follow'); } else { + $item['uri'] = $activity['id']; + $item['author'] = $activity['actor']; + $item['updated'] = $item['published'] = $activity['published']; + $item['uuid'] = ''; + $item['name'] = $activity['type']; + $item['summary'] = ''; + $item['content'] = ''; + $item['location'] = ''; + $item['tags'] = []; + $item['sensitive'] = false; + $item['service'] = ''; + $item['attachments'] = []; + $item['conversation'] = ''; $item['object'] = $object_url; } $item['id'] = $activity['id']; From 1f98414bdd271ea4a6b0938f09bec6f881c450dc Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 16 Sep 2018 05:49:13 +0000 Subject: [PATCH 20/97] Some code cleanup --- src/Protocol/ActivityPub.php | 340 +++++++++++++++-------------------- 1 file changed, 149 insertions(+), 191 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 85d21d7cba..3047853b11 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -131,7 +131,7 @@ class ActivityPub 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']]; $data['summary'] = $contact['about']; $data['url'] = $contact['url']; - $data['manuallyApprovesFollowers'] = false; + $data['manuallyApprovesFollowers'] = false; /// @todo $data['publicKey'] = ['id' => $contact['url'] . '#main-key', 'owner' => $contact['url'], 'publicKeyPem' => $user['pubkey']]; @@ -533,28 +533,18 @@ class ActivityPub } } -/* // To-Do - unset($data['type']); - unset($data['manuallyApprovesFollowers']); + // type, manuallyApprovesFollowers // Unhandled - unset($data['@context']); - unset($data['tag']); - unset($data['attachment']); - unset($data['image']); - unset($data['nomadicLocations']); - unset($data['signature']); - unset($data['following']); - unset($data['followers']); - unset($data['featured']); - unset($data['movedTo']); - unset($data['liked']); - unset($data['sharedInbox']); // Misskey - unset($data['isCat']); // Misskey - unset($data['kroeg:blocks']); // Kroeg - unset($data['updated']); // Kroeg -*/ + // @context, tag, attachment, image, nomadicLocations, signature, following, followers, featured, movedTo, liked + + // Unhandled from Misskey + // sharedInbox, isCat + + // Unhandled from Kroeg + // kroeg:blocks, updated + return $profile; } @@ -600,7 +590,72 @@ class ActivityPub } } - function processActivity($activity, $body = '', $uid = null) + private static function prepareObjectData($activity, $uid) + { + $actor = self::processElement($activity, 'actor', 'id'); + if (empty($actor)) { + logger('Empty actor', LOGGER_DEBUG); + return []; + } + + // Fetch all receivers from to, cc, bto and bcc + $receivers = self::getReceivers($activity); + + // When it is a delivery to a personal inbox we add that user to the receivers + if (!empty($uid)) { + $owner = User::getOwnerDataById($uid); + $additional = [$owner['url'] => $uid]; + $receivers = array_merge($receivers, $additional); + } + + logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG); + + if (is_string($activity['object'])) { + $object_url = $activity['object']; + } elseif (!empty($activity['object']['id'])) { + $object_url = $activity['object']['id']; + } else { + logger('No object found', LOGGER_DEBUG); + return []; + } + + // Fetch the content only on activities where this matters + if (in_array($activity['type'], ['Create', 'Update', 'Announce'])) { + $object_data = self::fetchObject($object_url, $activity['object']); + if (empty($object_data)) { + logger("Object data couldn't be processed", LOGGER_DEBUG); + return []; + } + } elseif ($activity['type'] == 'Accept') { + $object_data = []; + $object_data['object_type'] = self::processElement($activity, 'object', 'type'); + $object_data['object'] = self::processElement($activity, 'object', 'actor'); + } elseif ($activity['type'] == 'Undo') { + $object_data = []; + $object_data['object_type'] = self::processElement($activity, 'object', 'type'); + $object_data['object'] = self::processElement($activity, 'object', 'object'); + } elseif (in_array($activity['type'], ['Like', 'Dislike'])) { + // Create a mostly empty array out of the activity data (instead of the object). + // This way we later don't have to check for the existence of ech individual array element. + $object_data = self::processCommonData($activity); + $object_data['name'] = $activity['type']; + $object_data['author'] = $activity['actor']; + $object_data['object'] = $object_url; + } elseif ($activity['type'] == 'Follow') { + $object_data['id'] = $activity['id']; + $object_data['object'] = $object_url; + } + + $object_data = self::addActivityFields($object_data, $activity); + + $object_data['type'] = $activity['type']; + $object_data['owner'] = $actor; + $object_data['receiver'] = array_merge(defaults($object_data, 'receiver', []), $receivers); + + return $object_data; + } + + private static function processActivity($activity, $body = '', $uid = null) { if (empty($activity['type'])) { logger('Empty type', LOGGER_DEBUG); @@ -618,118 +673,53 @@ class ActivityPub } - $actor = self::processElement($activity, 'actor', 'id'); - if (empty($actor)) { - logger('Empty actor - 2', LOGGER_DEBUG); - return; - } - - if (is_string($activity['object'])) { - $object_url = $activity['object']; - } elseif (!empty($activity['object']['id'])) { - $object_url = $activity['object']['id']; - } else { - logger('No object found', LOGGER_DEBUG); - return; - } - - // ---------------------------------- -/* - // unhandled - unset($activity['@context']); - unset($activity['id']); - // Non standard - unset($activity['title']); - unset($activity['atomUri']); - unset($activity['context_id']); - unset($activity['statusnetConversationId']); + // title, atomUri, context_id, statusnetConversationId // To-Do? - unset($activity['context']); - unset($activity['location']); - unset($activity['signature']); -*/ - // Fetch all receivers from to, cc, bto and bcc - $receivers = self::getReceivers($activity); - - // When it is a delivery to a personal inbox we add that user to the receivers - if (!empty($uid)) { - $owner = User::getOwnerDataById($uid); - $additional = [$owner['url'] => $uid]; - $receivers = array_merge($receivers, $additional); - } - - logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG); + // context, location, signature; logger('Processing activity: ' . $activity['type'], LOGGER_DEBUG); - // Fetch the content only on activities where this matters - if (in_array($activity['type'], ['Create', 'Update', 'Announce'])) { - $item = self::fetchObject($object_url, $activity['object']); - if (empty($item)) { - logger("Object data couldn't be processed", LOGGER_DEBUG); - return; - } - } else { - if (in_array($activity['type'], ['Accept'])) { - $item['object'] = self::processElement($activity, 'object', 'actor', 'type', 'Follow'); - } elseif (in_array($activity['type'], ['Undo'])) { - $item['object'] = self::processElement($activity, 'object', 'object', 'type', 'Follow'); - } else { - $item['uri'] = $activity['id']; - $item['author'] = $activity['actor']; - $item['updated'] = $item['published'] = $activity['published']; - $item['uuid'] = ''; - $item['name'] = $activity['type']; - $item['summary'] = ''; - $item['content'] = ''; - $item['location'] = ''; - $item['tags'] = []; - $item['sensitive'] = false; - $item['service'] = ''; - $item['attachments'] = []; - $item['conversation'] = ''; - $item['object'] = $object_url; - } - $item['id'] = $activity['id']; - $item['receiver'] = []; - $item['type'] = $activity['type']; + $object_data = self::prepareObjectData($activity, $uid); + if (empty($object_data)) { + logger('No object data found', LOGGER_DEBUG); + return; } - $item = self::addActivityFields($item, $activity); - - $item['owner'] = $actor; - - $item['receiver'] = array_merge($item['receiver'], $receivers); - switch ($activity['type']) { case 'Create': - case 'Update': case 'Announce': - self::createItem($item, $body); + self::createItem($object_data, $body); break; case 'Like': - self::likeItem($item, $body); + self::likeItem($object_data, $body); break; case 'Dislike': break; + case 'Update': + break; + case 'Delete': break; case 'Follow': - self::followUser($item); + self::followUser($object_data); break; case 'Accept': - self::acceptFollowUser($item); + if ($object_data['object_type'] == 'Follow') { + self::acceptFollowUser($object_data); + } break; case 'Undo': - self::undoFollowUser($item); + if ($object_data['object_type'] == 'Follow') { + self::undoFollowUser($object_data); + } break; default: @@ -769,24 +759,24 @@ class ActivityPub return $receivers; } - private static function addActivityFields($item, $activity) + private static function addActivityFields($object_data, $activity) { - if (!empty($activity['published']) && empty($item['published'])) { - $item['published'] = $activity['published']; + if (!empty($activity['published']) && empty($object_data['published'])) { + $object_data['published'] = $activity['published']; } - if (!empty($activity['updated']) && empty($item['updated'])) { - $item['updated'] = $activity['updated']; + if (!empty($activity['updated']) && empty($object_data['updated'])) { + $object_data['updated'] = $activity['updated']; } - if (!empty($activity['inReplyTo']) && empty($item['parent-uri'])) { - $item['parent-uri'] = self::processElement($activity, 'inReplyTo', 'id'); + if (!empty($activity['inReplyTo']) && empty($object_data['parent-uri'])) { + $object_data['parent-uri'] = self::processElement($activity, 'inReplyTo', 'id'); } if (!empty($activity['instrument'])) { - $item['service'] = self::processElement($activity, 'instrument', 'name', 'type', 'Service'); + $object_data['service'] = self::processElement($activity, 'instrument', 'name', 'type', 'Service'); } - return $item; + return $object_data; } private static function fetchObject($object_url, $object = []) @@ -849,118 +839,86 @@ class ActivityPub private static function processCommonData(&$object) { - if (empty($object['id']) || empty($object['attributedTo'])) { + if (empty($object['id'])) { return false; } - $item = []; - $item['type'] = $object['type']; - $item['uri'] = $object['id']; + $object_data = []; + $object_data['type'] = $object['type']; + $object_data['uri'] = $object['id']; if (!empty($object['inReplyTo'])) { - $item['reply-to-uri'] = self::processElement($object, 'inReplyTo', 'id'); + $object_data['reply-to-uri'] = self::processElement($object, 'inReplyTo', 'id'); } else { - $item['reply-to-uri'] = $item['uri']; + $object_data['reply-to-uri'] = $object_data['uri']; } - $item['published'] = defaults($object, 'published', null); - $item['updated'] = defaults($object, 'updated', $item['published']); + $object_data['published'] = defaults($object, 'published', null); + $object_data['updated'] = defaults($object, 'updated', $object_data['published']); - if (empty($item['published']) && !empty($item['updated'])) { - $item['published'] = $item['updated']; + if (empty($object_data['published']) && !empty($object_data['updated'])) { + $object_data['published'] = $object_data['updated']; } - $item['uuid'] = defaults($object, 'uuid', null); - $item['owner'] = $item['author'] = self::processElement($object, 'attributedTo', 'id'); - $item['context'] = defaults($object, 'context', null); - $item['conversation'] = defaults($object, 'conversation', null); - $item['sensitive'] = defaults($object, 'sensitive', null); - $item['name'] = defaults($object, 'title', null); - $item['name'] = defaults($object, 'name', $item['name']); - $item['summary'] = defaults($object, 'summary', null); - $item['content'] = defaults($object, 'content', null); - $item['source'] = defaults($object, 'source', null); - $item['location'] = self::processElement($object, 'location', 'name', 'type', 'Place'); - $item['attachments'] = defaults($object, 'attachment', null); - $item['tags'] = defaults($object, 'tag', null); - $item['service'] = self::processElement($object, 'instrument', 'name', 'type', 'Service'); - $item['alternate-url'] = self::processElement($object, 'url', 'href'); - $item['receiver'] = self::getReceivers($object); - -/* - // To-Do - unset($object['source']); + $object_data['uuid'] = defaults($object, 'uuid', null); + $object_data['owner'] = $object_data['author'] = self::processElement($object, 'attributedTo', 'id'); + $object_data['context'] = defaults($object, 'context', null); + $object_data['conversation'] = defaults($object, 'conversation', null); + $object_data['sensitive'] = defaults($object, 'sensitive', null); + $object_data['name'] = defaults($object, 'title', null); + $object_data['name'] = defaults($object, 'name', $object_data['name']); + $object_data['summary'] = defaults($object, 'summary', null); + $object_data['content'] = defaults($object, 'content', null); + $object_data['source'] = defaults($object, 'source', null); + $object_data['location'] = self::processElement($object, 'location', 'name', 'type', 'Place'); + $object_data['attachments'] = defaults($object, 'attachment', null); + $object_data['tags'] = defaults($object, 'tag', null); + $object_data['service'] = self::processElement($object, 'instrument', 'name', 'type', 'Service'); + $object_data['alternate-url'] = self::processElement($object, 'url', 'href'); + $object_data['receiver'] = self::getReceivers($object); // Unhandled - unset($object['@context']); - unset($object['type']); - unset($object['actor']); - unset($object['signature']); - unset($object['mediaType']); - unset($object['duration']); - unset($object['replies']); - unset($object['icon']); + // @context, type, actor, signature, mediaType, duration, replies, icon - // Also missing: - audience, preview, endTime, startTime, generator, image -*/ - return $item; + // Also missing: (Defined in the standard, but currently unused) + // audience, preview, endTime, startTime, generator, image + + return $object_data; } private static function processNote($object) { - $item = []; + $object_data = []; -/* // To-Do? - unset($object['emoji']); - unset($object['atomUri']); - unset($object['inReplyToAtomUri']); + // emoji, atomUri, inReplyToAtomUri // Unhandled - unset($object['contentMap']); - unset($object['announcement_count']); - unset($object['announcements']); - unset($object['context_id']); - unset($object['likes']); - unset($object['like_count']); - unset($object['inReplyToStatusId']); - unset($object['shares']); - unset($object['quoteUrl']); - unset($object['statusnetConversationId']); -*/ - return $item; + // contentMap, announcement_count, announcements, context_id, likes, like_count + // inReplyToStatusId, shares, quoteUrl, statusnetConversationId + + return $object_data; } private static function processArticle($object) { - $item = []; + $object_data = []; - return $item; + return $object_data; } private static function processVideo($object) { - $item = []; -/* + $object_data = []; + // To-Do? - unset($object['category']); - unset($object['licence']); - unset($object['language']); - unset($object['commentsEnabled']); + // category, licence, language, commentsEnabled // Unhandled - unset($object['views']); - unset($object['waitTranscoding']); - unset($object['state']); - unset($object['support']); - unset($object['subtitleLanguage']); - unset($object['likes']); - unset($object['dislikes']); - unset($object['shares']); - unset($object['comments']); -*/ - return $item; + // views, waitTranscoding, state, support, subtitleLanguage + // likes, dislikes, shares, comments + + return $object_data; } private static function processElement($array, $element, $key, $type = null, $type_value = null) From 6f3b2b65866a841e5e47b59dfa686d9c7d74f58d Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 16 Sep 2018 09:06:09 +0000 Subject: [PATCH 21/97] Handling of unlisted posts, better uid detection --- mod/follow.php | 4 +- src/Model/Contact.php | 24 ++++------- src/Model/Item.php | 37 +--------------- src/Protocol/ActivityPub.php | 84 ++++++++++++++++++++++++++---------- 4 files changed, 73 insertions(+), 76 deletions(-) diff --git a/mod/follow.php b/mod/follow.php index 65028a70e0..ad1dd349cc 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -31,8 +31,8 @@ function follow_post(App $a) // This is just a precaution if maybe this page is called somewhere directly via POST $_SESSION['fastlane'] = $url; - $result = Contact::createFromProbe($uid, $url, true, Protocol::ACTIVITYPUB); -// $result = Contact::createFromProbe($uid, $url, true); +// $result = Contact::createFromProbe($uid, $url, true, Protocol::ACTIVITYPUB); + $result = Contact::createFromProbe($uid, $url, true); if ($result['success'] == false) { if ($result['message']) { diff --git a/src/Model/Contact.php b/src/Model/Contact.php index ae42030952..b6b7081626 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1322,33 +1322,27 @@ class Contact extends BaseObject require_once 'include/conversation.php'; - // There are no posts with "uid = 0" with connector networks - // This speeds up the query a lot - $r = q("SELECT `network`, `id` AS `author-id`, `contact-type` FROM `contact` - WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0", - DBA::escape(normalise_link($contact_url)) - ); + $cid = Self::getIdForURL($contact_url); - if (!DBA::isResult($r)) { + $contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]); + if (!DBA::isResult($contact)) { return ''; } - if (in_array($r[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) { + if (in_array($contact["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) { $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))"; } else { $sql = "`item`.`uid` = ?"; } - $author_id = intval($r[0]["author-id"]); - - $contact = ($r[0]["contact-type"] == self::ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id'); + $contact_field = ($contact["contact-type"] == self::ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id'); if ($thread_mode) { - $condition = ["`$contact` = ? AND `gravity` = ? AND " . $sql, - $author_id, GRAVITY_PARENT, local_user()]; + $condition = ["`$contact_field` = ? AND `gravity` = ? AND " . $sql, + $cid, GRAVITY_PARENT, local_user()]; } else { - $condition = ["`$contact` = ? AND `gravity` IN (?, ?) AND " . $sql, - $author_id, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()]; + $condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql, + $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()]; } $params = ['order' => ['created' => true], diff --git a/src/Model/Item.php b/src/Model/Item.php index 68ebc690e8..b9cc6c2b9a 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2071,6 +2071,7 @@ class Item extends BaseObject $users = []; + /// @todo add a field "pcid" in the contact table that referrs to the public contact id. $owner = DBA::selectFirst('contact', ['url', 'nurl', 'alias'], ['id' => $parent['owner-id']]); if (!DBA::isResult($owner)) { return; @@ -2110,43 +2111,7 @@ class Item extends BaseObject } DBA::close($contacts); } -/* - $condition = ["`nurl` IN (SELECT `nurl` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)", - $parent['owner-id'], Contact::SHARING, Contact::FRIEND]; - - $contacts = DBA::select('contact', ['uid'], $condition); - - while ($contact = DBA::fetch($contacts)) { - $users[$contact['uid']] = $contact['uid']; - } - - DBA::close($contacts); - - // And the same with the alias in the user contacts - $condition = ["`alias` IN (SELECT `url` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)", - $parent['owner-id'], Contact::SHARING, Contact::FRIEND]; - - $contacts = DBA::select('contact', ['uid'], $condition); - - while ($contact = DBA::fetch($contacts)) { - $users[$contact['uid']] = $contact['uid']; - } - - DBA::close($contacts); - - // And vice versa - $condition = ["`url` IN (SELECT `alias` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)", - $parent['owner-id'], Contact::SHARING, Contact::FRIEND]; - - $contacts = DBA::select('contact', ['uid'], $condition); - - while ($contact = DBA::fetch($contacts)) { - $users[$contact['uid']] = $contact['uid']; - } - - DBA::close($contacts); -*/ $origin_uid = 0; if ($item['uri'] != $item['parent-uri']) { diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 3047853b11..2b05ff68c7 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -65,17 +65,20 @@ class ActivityPub $content = json_encode($data); + // Header data that is about to be signed. + /// @todo Add "digest" $host = parse_url($target, PHP_URL_HOST); $path = parse_url($target, PHP_URL_PATH); $date = date('r'); + $content_length = strlen($content); - $headers = ['Host: ' . $host, 'Date: ' . $date]; + $headers = ['Host: ' . $host, 'Date: ' . $date, 'Content-Length: ' . $content_length]; - $signed_data = "(request-target): post " . $path . "\nhost: " . $host . "\ndate: " . $date; + $signed_data = "(request-target): post " . $path . "\nhost: " . $host . "\ndate: " . $date . "\ncontent-length: " . $content_length; $signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256')); - $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",headers="(request-target) host date",signature="' . $signature . '"'; + $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",headers="(request-target) host date content-length",signature="' . $signature . '"'; $headers[] = 'Content-Type: application/activity+json'; Network::post($target, $content, $headers); @@ -102,7 +105,7 @@ class ActivityPub return []; } - $fields = ['locality', 'region', 'country-name']; + $fields = ['locality', 'region', 'country-name', 'page-flags']; $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid, 'is-default' => true]); if (!DBA::isResult($profile)) { return []; @@ -131,7 +134,7 @@ class ActivityPub 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']]; $data['summary'] = $contact['about']; $data['url'] = $contact['url']; - $data['manuallyApprovesFollowers'] = false; /// @todo + $data['manuallyApprovesFollowers'] = in_array($profile['page-flags'], [Contact::PAGE_NORMAL, Contact::PAGE_PRVGROUP]); $data['publicKey'] = ['id' => $contact['url'] . '#main-key', 'owner' => $contact['url'], 'publicKeyPem' => $user['pubkey']]; @@ -392,7 +395,7 @@ class ActivityPub return false; } - // Check the digest if it was part of the signed data + // Check the digest when it is part of the signed data if (in_array('digest', $sig_block['headers'])) { $digest = explode('=', $headers['digest'], 2); if ($digest[0] === 'SHA-256') { @@ -409,7 +412,7 @@ class ActivityPub } } - // Check the content-length if it was part of the signed data + // Check the content-length when it is part of the signed data if (in_array('content-length', $sig_block['headers'])) { if (strlen($content) != $headers['content-length']) { return false; @@ -599,7 +602,7 @@ class ActivityPub } // Fetch all receivers from to, cc, bto and bcc - $receivers = self::getReceivers($activity); + $receivers = self::getReceivers($activity, $actor); // When it is a delivery to a personal inbox we add that user to the receivers if (!empty($uid)) { @@ -728,10 +731,13 @@ class ActivityPub } } - private static function getReceivers($activity) + private static function getReceivers($activity, $actor) { $receivers = []; + $data = self::fetchContent($actor); + $followers = defaults($data, 'followers', ''); + $elements = ['to', 'cc', 'bto', 'bcc']; foreach ($elements as $element) { if (empty($activity[$element])) { @@ -744,8 +750,25 @@ class ActivityPub } foreach ($activity[$element] as $receiver) { - if ($receiver == self::PUBLIC) { - $receivers[$receiver] = 0; + // Mastodon puts public only in "cc" not in "to" when the post should not be listed + if (($receiver == self::PUBLIC) && ($element == 'to')) { + $receivers['uid:0'] = 0; + } + + if (($receiver == self::PUBLIC)) { + $receivers['uid:-1'] = -1; + } + + if (in_array($receiver, [$followers, self::PUBLIC])) { + $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $contacts = DBA::select('contact', ['uid'], $condition); + while ($contact = DBA::fetch($contacts)) { + if ($contact['uid'] != 0) { + $receivers['uid:' . $contact['uid']] = $contact['uid']; + } + } + DBA::close($contacts); + continue; } $condition = ['self' => true, 'nurl' => normalise_link($receiver)]; @@ -753,7 +776,7 @@ class ActivityPub if (!DBA::isResult($contact)) { continue; } - $receivers[$receiver] = $contact['uid']; + $receivers['cid:' . $contact['uid']] = $contact['uid']; } } return $receivers; @@ -875,7 +898,7 @@ class ActivityPub $object_data['tags'] = defaults($object, 'tag', null); $object_data['service'] = self::processElement($object, 'instrument', 'name', 'type', 'Service'); $object_data['alternate-url'] = self::processElement($object, 'url', 'href'); - $object_data['receiver'] = self::getReceivers($object); + $object_data['receiver'] = self::getReceivers($object, $object_data['owner']); // Unhandled // @context, type, actor, signature, mediaType, duration, replies, icon @@ -1045,7 +1068,11 @@ class ActivityPub /// @todo What to do with $activity['context']? $item['network'] = Protocol::ACTIVITYPUB; - $item['private'] = !in_array(0, $activity['receiver']); + $item['private'] = !in_array(-1, $activity['receiver']); + if (in_array(-1, $activity['receiver'])) { + $item['private'] = 2; + } + $item['author-id'] = Contact::getIdForURL($activity['author'], 0, true); $item['owner-id'] = Contact::getIdForURL($activity['owner'], 0, true); $item['uri'] = $activity['uri']; @@ -1072,6 +1099,10 @@ class ActivityPub $item['conversation-uri'] = $activity['conversation']; foreach ($activity['receiver'] as $receiver) { + if ($receiver < 0) { + continue; + } + $item['uid'] = $receiver; $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true); @@ -1081,19 +1112,26 @@ class ActivityPub $item_id = Item::insert($item); logger('Storing for user ' . $item['uid'] . ': ' . $item_id); - if (!empty($item_id) && ($item['uid'] == 0)) { - Item::distribute($item_id); - } + } + } + + private static function getUserOfObject($object) + { + $self = DBA::selectFirst('contact', ['uid'], ['nurl' => normalise_link($object), 'self' => true]); + if (!DBA::isResult(§self)) { + return false; + } else { + return $self['uid']; } } private static function followUser($activity) { - if (empty($activity['receiver'][$activity['object']])) { + $uid = self::getUserOfObject[$activity['object']]; + if (empty($uid)) { return; } - $uid = $activity['receiver'][$activity['object']]; $owner = User::getOwnerDataById($uid); $cid = Contact::getIdForURL($activity['owner'], $uid); @@ -1123,11 +1161,11 @@ class ActivityPub private static function acceptFollowUser($activity) { - if (empty($activity['receiver'][$activity['object']])) { + $uid = self::getUserOfObject[$activity['object']]; + if (empty($uid)) { return; } - $uid = $activity['receiver'][$activity['object']]; $owner = User::getOwnerDataById($uid); $cid = Contact::getIdForURL($activity['owner'], $uid); @@ -1150,11 +1188,11 @@ class ActivityPub private static function undoFollowUser($activity) { - if (empty($activity['receiver'][$activity['object']])) { + $uid = self::getUserOfObject[$activity['object']]; + if (empty($uid)) { return; } - $uid = $activity['receiver'][$activity['object']]; $owner = User::getOwnerDataById($uid); $cid = Contact::getIdForURL($activity['owner'], $uid); From 629cca19631d918a98063a8f1f8d9fa46b0c3d81 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 16 Sep 2018 13:04:00 +0000 Subject: [PATCH 22/97] Added function to fetch missing data, code bugfixing --- src/Protocol/ActivityPub.php | 105 +++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 37 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 2b05ff68c7..12477bad6b 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -279,7 +279,6 @@ class ActivityPub public static function fetchContent($url) { $ret = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json']); - if (!$ret['success'] || empty($ret['body'])) { return; } @@ -613,6 +612,8 @@ class ActivityPub logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG); + $public = in_array(0, $receivers); + if (is_string($activity['object'])) { $object_url = $activity['object']; } elseif (!empty($activity['object']['id'])) { @@ -647,6 +648,8 @@ class ActivityPub } elseif ($activity['type'] == 'Follow') { $object_data['id'] = $activity['id']; $object_data['object'] = $object_url; + } else { + $object_data = []; } $object_data = self::addActivityFields($object_data, $activity); @@ -738,6 +741,8 @@ class ActivityPub $data = self::fetchContent($actor); $followers = defaults($data, 'followers', ''); + logger('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG); + $elements = ['to', 'cc', 'bto', 'bcc']; foreach ($elements as $element) { if (empty($activity[$element])) { @@ -750,17 +755,23 @@ class ActivityPub } foreach ($activity[$element] as $receiver) { - // Mastodon puts public only in "cc" not in "to" when the post should not be listed - if (($receiver == self::PUBLIC) && ($element == 'to')) { + if ($receiver == self::PUBLIC) { $receivers['uid:0'] = 0; - } - if (($receiver == self::PUBLIC)) { - $receivers['uid:-1'] = -1; + // This will most likely catch all OStatus connections to Mastodon + $condition = ['alias' => [$actor, normalise_link($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $contacts = DBA::select('contact', ['uid'], $condition); + while ($contact = DBA::fetch($contacts)) { + if ($contact['uid'] != 0) { + $receivers['uid:' . $contact['uid']] = $contact['uid']; + } + } + DBA::close($contacts); } if (in_array($receiver, [$followers, self::PUBLIC])) { - $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND], + 'network' => Protocol::ACTIVITYPUB]; $contacts = DBA::select('contact', ['uid'], $condition); while ($contact = DBA::fetch($contacts)) { if ($contact['uid'] != 0) { @@ -802,26 +813,27 @@ class ActivityPub return $object_data; } - private static function fetchObject($object_url, $object = []) + private static function fetchObject($object_url, $object = [], $public = true) { - $data = self::fetchContent($object_url); - if (empty($data)) { - $data = $object; + if ($public) { + $data = self::fetchContent($object_url); if (empty($data)) { - logger('Empty content', LOGGER_DEBUG); - return false; - } elseif (is_string($data)) { - logger('No object array provided.', LOGGER_DEBUG); - $item = Item::selectFirst([], ['uri' => $data]); - if (!DBA::isResult($item)) { - logger('Object with url ' . $data . ' was not found locally.', LOGGER_DEBUG); - return false; - } - logger('Using already stored item', LOGGER_DEBUG); - $data = self::createNote($item); - } else { - logger('Using provided object', LOGGER_DEBUG); + logger('Empty content for ' . $object_url . ', check if content is available locally.', LOGGER_DEBUG); + $data = $object_url; } + } else { + logger('Using original object for url ' . $object_url, LOGGER_DEBUG); + $data = $object; + } + + if (is_string($data)) { + $item = Item::selectFirst([], ['uri' => $data]); + if (!DBA::isResult($item)) { + logger('Object with url ' . $data . ' was not found locally.', LOGGER_DEBUG); + return false; + } + logger('Using already stored item for url ' . $object_url, LOGGER_DEBUG); + $data = self::createNote($item); } if (empty($data['type'])) { @@ -1049,6 +1061,11 @@ class ActivityPub $item['object-type'] = ACTIVITY_OBJ_COMMENT; } + if (($activity['uri'] != $activity['reply-to-uri']) && !Item::exists(['uri' => $activity['reply-to-uri']])) { + logger('Parent ' . $activity['reply-to-uri'] . ' not found. Try to refetch it.'); + self::fetchMissingActivity($activity['reply-to-uri']); + } + self::postItem($activity, $item, $body); } @@ -1068,11 +1085,7 @@ class ActivityPub /// @todo What to do with $activity['context']? $item['network'] = Protocol::ACTIVITYPUB; - $item['private'] = !in_array(-1, $activity['receiver']); - if (in_array(-1, $activity['receiver'])) { - $item['private'] = 2; - } - + $item['private'] = !in_array(0, $activity['receiver']); $item['author-id'] = Contact::getIdForURL($activity['author'], 0, true); $item['owner-id'] = Contact::getIdForURL($activity['owner'], 0, true); $item['uri'] = $activity['uri']; @@ -1099,10 +1112,6 @@ class ActivityPub $item['conversation-uri'] = $activity['conversation']; foreach ($activity['receiver'] as $receiver) { - if ($receiver < 0) { - continue; - } - $item['uid'] = $receiver; $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true); @@ -1115,10 +1124,32 @@ class ActivityPub } } + private static function fetchMissingActivity($url) + { + $object = ActivityPub::fetchContent($url); + if (empty($object)) { + logger('Activity ' . $url . ' was not fetchable, aborting.'); + return; + } + + $activity = []; + $activity['@context'] = $object['@context']; + unset($object['@context']); + $activity['id'] = $object['id']; + $activity['to'] = defaults($object, 'to', []); + $activity['cc'] = defaults($object, 'cc', []); + $activity['actor'] = $object['attributedTo']; + $activity['object'] = $object; + $activity['published'] = $object['published']; + $activity['type'] = 'Create'; + self::processActivity($activity); + logger('Activity ' . $url . ' had been fetched and processed.'); + } + private static function getUserOfObject($object) { $self = DBA::selectFirst('contact', ['uid'], ['nurl' => normalise_link($object), 'self' => true]); - if (!DBA::isResult(§self)) { + if (!DBA::isResult($self)) { return false; } else { return $self['uid']; @@ -1127,7 +1158,7 @@ class ActivityPub private static function followUser($activity) { - $uid = self::getUserOfObject[$activity['object']]; + $uid = self::getUserOfObject($activity['object']); if (empty($uid)) { return; } @@ -1161,7 +1192,7 @@ class ActivityPub private static function acceptFollowUser($activity) { - $uid = self::getUserOfObject[$activity['object']]; + $uid = self::getUserOfObject($activity['object']); if (empty($uid)) { return; } @@ -1188,7 +1219,7 @@ class ActivityPub private static function undoFollowUser($activity) { - $uid = self::getUserOfObject[$activity['object']]; + $uid = self::getUserOfObject($activity['object']); if (empty($uid)) { return; } From e4d28629e43f829877336f4207edd304069f9ed8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 16 Sep 2018 17:47:00 +0000 Subject: [PATCH 23/97] First posting tests --- mod/follow.php | 4 +- src/Protocol/ActivityPub.php | 37 +++++++++------- src/Worker/Delivery.php | 82 ++++++++++++++++++++++++++++++++++++ src/Worker/Notifier.php | 2 +- 4 files changed, 107 insertions(+), 18 deletions(-) diff --git a/mod/follow.php b/mod/follow.php index ad1dd349cc..65028a70e0 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -31,8 +31,8 @@ function follow_post(App $a) // This is just a precaution if maybe this page is called somewhere directly via POST $_SESSION['fastlane'] = $url; -// $result = Contact::createFromProbe($uid, $url, true, Protocol::ACTIVITYPUB); - $result = Contact::createFromProbe($uid, $url, true); + $result = Contact::createFromProbe($uid, $url, true, Protocol::ACTIVITYPUB); +// $result = Contact::createFromProbe($uid, $url, true); if ($result['success'] == false) { if ($result['message']) { diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 12477bad6b..ad27535ae6 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -95,8 +95,7 @@ class ActivityPub */ public static function profile($uid) { - $accounttype = ['Person', 'Organization', 'Service', 'Group', 'Application']; - + $accounttype = ['Person', 'Organization', 'Service', 'Group', 'Application', 'page-flags']; $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false, 'account_removed' => false, 'verified' => true]; $fields = ['guid', 'nickname', 'pubkey', 'account-type']; @@ -105,7 +104,7 @@ class ActivityPub return []; } - $fields = ['locality', 'region', 'country-name', 'page-flags']; + $fields = ['locality', 'region', 'country-name']; $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid, 'is-default' => true]); if (!DBA::isResult($profile)) { return []; @@ -119,6 +118,7 @@ class ActivityPub $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', ['uuid' => 'http://schema.org/identifier', 'sensitive' => 'as:sensitive', + 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'vcard' => 'http://www.w3.org/2006/vcard/ns#']]]; $data['id'] = $contact['url']; @@ -130,7 +130,7 @@ class ActivityPub $data['outbox'] = System::baseUrl() . '/outbox/' . $user['nickname']; $data['preferredUsername'] = $user['nickname']; $data['name'] = $contact['name']; - $data['vcard:hasAddress'] = ['@type' => 'Home', 'vcard:country-name' => $profile['country-name'], + $data['vcard:hasAddress'] = ['@type' => 'vcard:Home', 'vcard:country-name' => $profile['country-name'], 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']]; $data['summary'] = $contact['about']; $data['url'] = $contact['url']; @@ -183,9 +183,8 @@ class ActivityPub $data['context'] = $data['conversation'] = $conversation_uri; $data['actor'] = $item['author-link']; - $data['to'] = []; if (!$item['private']) { - $data['to'][] = 'https://www.w3.org/ns/activitystreams#Public'; + $data['to'] = 'https://www.w3.org/ns/activitystreams#Public'; } $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); @@ -606,7 +605,7 @@ class ActivityPub // When it is a delivery to a personal inbox we add that user to the receivers if (!empty($uid)) { $owner = User::getOwnerDataById($uid); - $additional = [$owner['url'] => $uid]; + $additional = ['uid:' . $uid => $uid]; $receivers = array_merge($receivers, $additional); } @@ -738,10 +737,15 @@ class ActivityPub { $receivers = []; - $data = self::fetchContent($actor); - $followers = defaults($data, 'followers', ''); + if (!empty($actor)) { + $data = self::fetchContent($actor); + $followers = defaults($data, 'followers', ''); - logger('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG); + logger('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG); + } else { + logger('Empty actor', LOGGER_DEBUG); + $followers = ''; + } $elements = ['to', 'cc', 'bto', 'bcc']; foreach ($elements as $element) { @@ -757,7 +761,9 @@ class ActivityPub foreach ($activity[$element] as $receiver) { if ($receiver == self::PUBLIC) { $receivers['uid:0'] = 0; + } + if (($receiver == self::PUBLIC) && !empty($actor)) { // This will most likely catch all OStatus connections to Mastodon $condition = ['alias' => [$actor, normalise_link($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]]; $contacts = DBA::select('contact', ['uid'], $condition); @@ -769,7 +775,7 @@ class ActivityPub DBA::close($contacts); } - if (in_array($receiver, [$followers, self::PUBLIC])) { + if (in_array($receiver, [$followers, self::PUBLIC]) && !empty($actor)) { $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB]; $contacts = DBA::select('contact', ['uid'], $condition); @@ -787,7 +793,7 @@ class ActivityPub if (!DBA::isResult($contact)) { continue; } - $receivers['cid:' . $contact['uid']] = $contact['uid']; + $receivers['uid:' . $contact['uid']] = $contact['uid']; } } return $receivers; @@ -820,6 +826,7 @@ class ActivityPub if (empty($data)) { logger('Empty content for ' . $object_url . ', check if content is available locally.', LOGGER_DEBUG); $data = $object_url; + $data = $object; } } else { logger('Using original object for url ' . $object_url, LOGGER_DEBUG); @@ -1063,7 +1070,7 @@ class ActivityPub if (($activity['uri'] != $activity['reply-to-uri']) && !Item::exists(['uri' => $activity['reply-to-uri']])) { logger('Parent ' . $activity['reply-to-uri'] . ' not found. Try to refetch it.'); - self::fetchMissingActivity($activity['reply-to-uri']); + self::fetchMissingActivity($activity['reply-to-uri'], $activity); } self::postItem($activity, $item, $body); @@ -1124,7 +1131,7 @@ class ActivityPub } } - private static function fetchMissingActivity($url) + private static function fetchMissingActivity($url, $child) { $object = ActivityPub::fetchContent($url); if (empty($object)) { @@ -1138,7 +1145,7 @@ class ActivityPub $activity['id'] = $object['id']; $activity['to'] = defaults($object, 'to', []); $activity['cc'] = defaults($object, 'cc', []); - $activity['actor'] = $object['attributedTo']; + $activity['actor'] = $activity['author']; $activity['object'] = $object; $activity['published'] = $object['published']; $activity['type'] = 'Create'; diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index e0a5c09c27..ef3a34649d 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -15,6 +15,7 @@ use Friendica\Model\Item; use Friendica\Model\Queue; use Friendica\Model\User; use Friendica\Protocol\DFRN; +use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Diaspora; use Friendica\Protocol\Email; @@ -165,6 +166,10 @@ class Delivery extends BaseObject switch ($contact['network']) { + case Protocol::ACTIVITYPUB: + self::deliverActivityPub($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup); + break; + case Protocol::DFRN: self::deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup); break; @@ -383,6 +388,83 @@ class Delivery extends BaseObject logger('Unknown mode ' . $cmd . ' for ' . $loc); } + /** + * @brief Deliver content via ActivityPub +q * + * @param string $cmd Command + * @param array $contact Contact record of the receiver + * @param array $owner Owner record of the sender + * @param array $items Item record of the content and the parent + * @param array $target_item Item record of the content + * @param boolean $public_message Is the content public? + * @param boolean $top_level Is it a thread starter? + * @param boolean $followup Is it an answer to a remote post? + */ + private static function deliverActivityPub($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup) + { + // We don't treat Forum posts as "wall-to-wall" to be able to post them via ActivityPub + $walltowall = $top_level && ($owner['id'] != $items[0]['contact-id']) & ($owner['account-type'] != Contact::ACCOUNT_TYPE_COMMUNITY); + + if ($public_message) { + $loc = 'public batch ' . $contact['batch']; + } else { + $loc = $contact['addr']; + } + + logger('Deliver ' . $target_item["guid"] . ' via ActivityPub to ' . $loc); + +// if (Config::get('system', 'dfrn_only') || !Config::get('system', 'diaspora_enabled')) { +// return; +// } + if ($cmd == self::MAIL) { +// ActivityPub::sendMail($target_item, $owner, $contact); + return; + } + + if ($cmd == self::SUGGESTION) { + return; + } +// if (!$contact['pubkey'] && !$public_message) { +// logger('No public key, no delivery.'); +// return; +// } + if (($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) { + // top-level retraction + logger('ActivityPub retract: ' . $loc); +// ActivityPub::sendRetraction($target_item, $owner, $contact, $public_message); + return; + } elseif ($cmd == self::RELOCATION) { +// ActivityPub::sendAccountMigration($owner, $contact, $owner['uid']); + return; + } elseif ($followup) { + // send comments and likes to owner to relay + logger('ActivityPub followup: ' . $loc); + $data = ActivityPub::createActivityFromItem($target_item['id']); + $content = json_encode($data); + ActivityPub::transmit($content, $contact['notify'], $owner['uid']); +// ActivityPub::sendFollowup($target_item, $owner, $contact, $public_message); + return; + } elseif ($target_item['uri'] !== $target_item['parent-uri']) { + // we are the relay - send comments, likes and relayable_retractions to our conversants + logger('ActivityPub relay: ' . $loc); + $data = ActivityPub::createActivityFromItem($target_item['id']); + $content = json_encode($data); + ActivityPub::transmit($content, $contact['notify'], $owner['uid']); +// ActivityPub::sendRelay($target_item, $owner, $contact, $public_message); + return; + } elseif ($top_level && !$walltowall) { + // currently no workable solution for sending walltowall + logger('ActivityPub status: ' . $loc); + $data = ActivityPub::createActivityFromItem($target_item['id']); + $content = json_encode($data); + ActivityPub::transmit($content, $contact['notify'], $owner['uid']); +// ActivityPub::sendStatus($target_item, $owner, $contact, $public_message); + return; + } + + logger('Unknown mode ' . $cmd . ' for ' . $loc); + } + /** * @brief Deliver content via mail * diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 55f80c94d7..6a37186186 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -448,7 +448,7 @@ class Notifier } } - $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false, + $condition = ['network' => [Protocol::DFRN, Protocol::ACTIVITYPUB], 'uid' => $owner['uid'], 'blocked' => false, 'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; $r2 = DBA::toArray(DBA::select('contact', ['id', 'name', 'network'], $condition)); From 699a4140f9a4bf31d406b684e58ea3b8ef3417c2 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 16 Sep 2018 20:12:48 +0000 Subject: [PATCH 24/97] Now sending does finally work - and some AP standards are improved as well --- mod/display.php | 2 +- mod/profile.php | 2 +- src/Module/Inbox.php | 2 +- src/Protocol/ActivityPub.php | 32 +++++++++++++++++++++----------- src/Worker/Delivery.php | 9 +++------ 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/mod/display.php b/mod/display.php index 21e28d5617..047f752c98 100644 --- a/mod/display.php +++ b/mod/display.php @@ -77,7 +77,7 @@ function display_init(App $a) displayShowFeed($item["id"], false); } - if (stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json')) { + if (ActivityPub::isRequest()) { $wall_item = Item::selectFirst(['id', 'uid'], ['guid' => $item['guid'], 'wall' => true]); if ($wall_item['uid'] == 180) { $data = ActivityPub::createActivityFromItem($wall_item['id']); diff --git a/mod/profile.php b/mod/profile.php index fd23964e41..a284e10f2d 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -50,7 +50,7 @@ function profile_init(App $a) DFRN::autoRedir($a, $which); } - if (stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json')) { + if (ActivityPub::isRequest()) { $user = DBA::selectFirst('user', ['uid'], ['nickname' => $which]); if ($user['uid'] == 180) { $data = ActivityPub::profile($user['uid']); diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index d47419a415..21dd77151c 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -47,6 +47,6 @@ class Inbox extends BaseModule ActivityPub::processInbox($postdata, $_SERVER, $uid); - System::httpExit(202); + System::httpExit(201); } } diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index ad27535ae6..5b5d16e85a 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -55,6 +55,12 @@ class ActivityPub { const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; + public static function isRequest() + { + return stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json') || + stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/ld+json'); + } + public static function transmit($data, $target, $uid) { $owner = User::getOwnerDataById($uid); @@ -66,19 +72,19 @@ class ActivityPub $content = json_encode($data); // Header data that is about to be signed. - /// @todo Add "digest" $host = parse_url($target, PHP_URL_HOST); $path = parse_url($target, PHP_URL_PATH); - $date = date('r'); + $digest = 'SHA-256=' . base64_encode(hash('sha256', $content, true)); $content_length = strlen($content); - $headers = ['Host: ' . $host, 'Date: ' . $date, 'Content-Length: ' . $content_length]; + $headers = ['Content-Length: ' . $content_length, 'Digest: ' . $digest, 'Host: ' . $host]; - $signed_data = "(request-target): post " . $path . "\nhost: " . $host . "\ndate: " . $date . "\ncontent-length: " . $content_length; + $signed_data = "(request-target): post " . $path . "\ncontent-length: " . $content_length . "\ndigest: " . $digest . "\nhost: " . $host; $signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256')); - $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",headers="(request-target) host date content-length",signature="' . $signature . '"'; + $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) content-length digest host",signature="' . $signature . '"'; + $headers[] = 'Content-Type: application/activity+json'; Network::post($target, $content, $headers); @@ -157,7 +163,7 @@ class ActivityPub 'toot' => 'http://joinmastodon.org/ns#']]]; $data['type'] = 'Create'; - $data['id'] = $item['uri']; + $data['id'] = $item['uri'] . '/activity'; $data['actor'] = $item['author-link']; $data['to'] = 'https://www.w3.org/ns/activitystreams#Public'; $data['object'] = self::createNote($item); @@ -210,7 +216,8 @@ class ActivityPub 'id' => System::baseUrl() . '/activity/' . System::createGUID(), 'type' => $activity, 'actor' => $owner['url'], - 'object' => $profile['url']]; + 'object' => $profile['url'], + 'to' => $profile['url']]; logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG); return self::transmit($data, $profile['notify'], $uid); @@ -227,7 +234,8 @@ class ActivityPub 'actor' => $owner['url'], 'object' => ['id' => $id, 'type' => 'Follow', 'actor' => $profile['url'], - 'object' => $owner['url']]]; + 'object' => $owner['url']], + 'to' => $profile['url']]; logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); return self::transmit($data, $profile['notify'], $uid); @@ -244,7 +252,8 @@ class ActivityPub 'actor' => $owner['url'], 'object' => ['id' => $id, 'type' => 'Follow', 'actor' => $profile['url'], - 'object' => $owner['url']]]; + 'object' => $owner['url']], + 'to' => $profile['url']]; logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); return self::transmit($data, $profile['notify'], $uid); @@ -263,7 +272,8 @@ class ActivityPub 'actor' => $owner['url'], 'object' => ['id' => $id, 'type' => 'Follow', 'actor' => $owner['url'], - 'object' => $profile['url']]]; + 'object' => $profile['url']], + 'to' => $profile['url']]; logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); return self::transmit($data, $profile['notify'], $uid); @@ -277,7 +287,7 @@ class ActivityPub */ public static function fetchContent($url) { - $ret = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json']); + $ret = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json, application/ld+json']); if (!$ret['success'] || empty($ret['body'])) { return; } diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index ef3a34649d..8ee00af630 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -440,24 +440,21 @@ q * // send comments and likes to owner to relay logger('ActivityPub followup: ' . $loc); $data = ActivityPub::createActivityFromItem($target_item['id']); - $content = json_encode($data); - ActivityPub::transmit($content, $contact['notify'], $owner['uid']); + ActivityPub::transmit($data, $contact['notify'], $owner['uid']); // ActivityPub::sendFollowup($target_item, $owner, $contact, $public_message); return; } elseif ($target_item['uri'] !== $target_item['parent-uri']) { // we are the relay - send comments, likes and relayable_retractions to our conversants logger('ActivityPub relay: ' . $loc); $data = ActivityPub::createActivityFromItem($target_item['id']); - $content = json_encode($data); - ActivityPub::transmit($content, $contact['notify'], $owner['uid']); + ActivityPub::transmit($data, $contact['notify'], $owner['uid']); // ActivityPub::sendRelay($target_item, $owner, $contact, $public_message); return; } elseif ($top_level && !$walltowall) { // currently no workable solution for sending walltowall logger('ActivityPub status: ' . $loc); $data = ActivityPub::createActivityFromItem($target_item['id']); - $content = json_encode($data); - ActivityPub::transmit($content, $contact['notify'], $owner['uid']); + ActivityPub::transmit($data, $contact['notify'], $owner['uid']); // ActivityPub::sendStatus($target_item, $owner, $contact, $public_message); return; } From 91d1b4de5d1b08bd240ea3d96b3a84e5caecfd6c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 17 Sep 2018 05:51:05 +0000 Subject: [PATCH 25/97] We now use the conversation data with AP --- config/dbstructure.json | 2 +- src/Model/Conversation.php | 8 ++++---- src/Module/Inbox.php | 2 +- src/Protocol/ActivityPub.php | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/config/dbstructure.json b/config/dbstructure.json index c467ba6bc7..8767c0db16 100644 --- a/config/dbstructure.json +++ b/config/dbstructure.json @@ -215,7 +215,7 @@ "reply-to-uri": {"type": "varbinary(255)", "not null": "1", "default": "", "comment": "URI to which this item is a reply"}, "conversation-uri": {"type": "varbinary(255)", "not null": "1", "default": "", "comment": "GNU Social conversation URI"}, "conversation-href": {"type": "varbinary(255)", "not null": "1", "default": "", "comment": "GNU Social conversation link"}, - "protocol": {"type": "tinyint unsigned", "not null": "1", "default": "0", "comment": "The protocol of the item"}, + "protocol": {"type": "tinyint unsigned", "not null": "1", "default": "255", "comment": "The protocol of the item"}, "source": {"type": "mediumtext", "comment": "Original source"}, "received": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": "Receiving date"} }, diff --git a/src/Model/Conversation.php b/src/Model/Conversation.php index ba50dc25e4..be1eaf2295 100644 --- a/src/Model/Conversation.php +++ b/src/Model/Conversation.php @@ -17,14 +17,14 @@ class Conversation * These constants represent the parcel format used to transport a conversation independently of the message protocol. * It currently is stored in the "protocol" field for legacy reasons. */ - const PARCEL_UNKNOWN = 0; + const PARCEL_ACTIVITYPUB = 0; const PARCEL_DFRN = 1; const PARCEL_DIASPORA = 2; const PARCEL_SALMON = 3; const PARCEL_FEED = 4; // Deprecated - const PARCEL_ACTIVITYPUB = 5; const PARCEL_SPLIT_CONVERSATION = 6; const PARCEL_TWITTER = 67; + const PARCEL_UNKNOWN = 255; /** * @brief Store the conversation data @@ -71,8 +71,8 @@ class Conversation unset($old_conv['source']); } // Update structure data all the time but the source only when its from a better protocol. - if (isset($conversation['protocol']) && isset($conversation['source']) && ($old_conv['protocol'] < $conversation['protocol']) - && ($old_conv['protocol'] != 0) && ($old_conv['protocol'] != self::PARCEL_ACTIVITYPUB)) { + if (empty($conversation['source']) || (!empty($old_conv['source']) && + ($old_conv['protocol'] < defaults($conversation, 'protocol', PARCEL_UNKNOWN)))) { unset($conversation['protocol']); unset($conversation['source']); } diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 21dd77151c..d47419a415 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -47,6 +47,6 @@ class Inbox extends BaseModule ActivityPub::processInbox($postdata, $_SERVER, $uid); - System::httpExit(201); + System::httpExit(202); } } diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 5b5d16e85a..9fb22b2bd9 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -32,6 +32,7 @@ use Friendica\Network\Probe; * * Digest: https://tools.ietf.org/html/rfc5843 * https://tools.ietf.org/html/draft-cavage-http-signatures-10#ref-15 + * https://github.com/digitalbazaar/php-json-ld * * Part of the code for HTTP signing is taken from the Osada project. * https://framagit.org/macgirvin/osada @@ -156,6 +157,19 @@ class ActivityPub { $item = Item::selectFirst([], ['id' => $item_id]); + if (!DBA::isResult($item)) { + return false; + } + + $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB]; + $conversation = DBA::selectFirst('conversation', ['source'], $condition); + if (DBA::isResult($conversation)) { + $data = json_decode($conversation['source']); + if (!empty($data)) { + return $data; + } + } + $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', ['Emoji' => 'toot:Emoji', 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri', @@ -1029,6 +1043,11 @@ class ActivityPub $tag_text .= ','; } + if (empty($tag['href'])) { + //$tag['href'] + logger('Blubb!'); + } + $tag_text .= substr($tag['name'], 0, 1) . '[url=' . $tag['href'] . ']' . substr($tag['name'], 1) . '[/url]'; } } From f772ece86f4de915c006fd44409ed6d2244c0465 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 17 Sep 2018 21:13:08 +0000 Subject: [PATCH 26/97] New delivery module for ap --- mod/display.php | 2 +- src/Model/Item.php | 2 +- src/Model/Term.php | 11 +++ src/Protocol/ActivityPub.php | 135 +++++++++++++++++++++++++++++++++-- src/Worker/APDelivery.php | 28 ++++++++ src/Worker/Delivery.php | 79 -------------------- src/Worker/Notifier.php | 15 +++- 7 files changed, 183 insertions(+), 89 deletions(-) create mode 100644 src/Worker/APDelivery.php diff --git a/mod/display.php b/mod/display.php index 047f752c98..1b4508c18d 100644 --- a/mod/display.php +++ b/mod/display.php @@ -80,7 +80,7 @@ function display_init(App $a) if (ActivityPub::isRequest()) { $wall_item = Item::selectFirst(['id', 'uid'], ['guid' => $item['guid'], 'wall' => true]); if ($wall_item['uid'] == 180) { - $data = ActivityPub::createActivityFromItem($wall_item['id']); + $data = ActivityPub::createObjectFromItemID($wall_item['id']); echo json_encode($data); exit(); } diff --git a/src/Model/Item.php b/src/Model/Item.php index b9cc6c2b9a..e590c0c5c5 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2851,7 +2851,7 @@ class Item extends BaseObject } // returns an array of contact-ids that are allowed to see this object - private static function enumeratePermissions($obj) + public static function enumeratePermissions($obj) { $allow_people = expand_acl($obj['allow_cid']); $allow_groups = Group::expand(expand_acl($obj['allow_gid'])); diff --git a/src/Model/Term.php b/src/Model/Term.php index a81241cb42..2623125329 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -33,6 +33,17 @@ class Term return $tag_text; } + public static function tagArrayFromItemId($itemid) + { + $condition = ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]; + $tags = DBA::select('term', ['type', 'term', 'url'], $condition); + if (!DBA::isResult($tags)) { + return []; + } + + return DBA::toArray($tags); + } + public static function fileTextFromItemId($itemid) { $file_text = ''; diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 9fb22b2bd9..c148e26c69 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -13,6 +13,7 @@ use Friendica\Core\Protocol; use Friendica\Model\Conversation; use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\Term; use Friendica\Model\User; use Friendica\Util\DateTimeFormat; use Friendica\Util\Crypto; @@ -153,6 +154,111 @@ class ActivityPub return $data; } + public static function createPermissionBlockForItem($item) + { + $data = ['to' => [], 'cc' => []]; + + $terms = Term::tagArrayFromItemId($item['id']); + + if (!$item['private']) { + $data['to'][] = self::PUBLIC; + $data['cc'][] = System::baseUrl() . '/followers/' . $item['author-nick']; + + foreach ($terms as $term) { + if ($term['type'] != TERM_MENTION) { + continue; + } + $profile = Probe::uri($term['url'], Protocol::ACTIVITYPUB); + if ($profile['network'] == Protocol::ACTIVITYPUB) { + $data['cc'][] = $profile['url']; + } + } + } else { + $receiver_list = Item::enumeratePermissions($item); + + $mentioned = []; + + foreach ($terms as $term) { + if ($term['type'] != TERM_MENTION) { + continue; + } + $cid = Contact::getIdForURL($term['url'], $item['uid']); + if (!empty($cid) && in_array($cid, $receiver_list)) { + $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); + $data['to'][] = $contact['url']; + } + } + + foreach ($receiver_list as $receiver) { + $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]); + $data['cc'][] = $contact['url']; + } + + if (empty($data['to'])) { + $data['to'] = $data['cc']; + unset($data['cc']); + } + } + + return $data; + } + + public static function fetchTargetInboxes($item) + { + $inboxes = []; + + $terms = Term::tagArrayFromItemId($item['id']); + if (!$item['private']) { + $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $item['uid'], 'network' => Protocol::ACTIVITYPUB]); + while ($contact = DBA::fetch($contacts)) { + $contact = defaults($contact, 'batch', $contact['notify']); + $inboxes[$contact] = $contact; + } + DBA::close($contacts); + + foreach ($terms as $term) { + if ($term['type'] != TERM_MENTION) { + continue; + } + $profile = Probe::uri($term['url'], Protocol::ACTIVITYPUB); + if ($profile['network'] == Protocol::ACTIVITYPUB) { + $target = defaults($profile, 'batch', $profile['notify']); + $inboxes[$target] = $target; + } + } + } else { + $receiver_list = Item::enumeratePermissions($item); + + $mentioned = []; + + foreach ($terms as $term) { + if ($term['type'] != TERM_MENTION) { + continue; + } + $cid = Contact::getIdForURL($term['url'], $item['uid']); + if (!empty($cid) && in_array($cid, $receiver_list)) { + $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); + $profile = Probe::uri($contact['url'], Protocol::ACTIVITYPUB); + if ($profile['network'] == Protocol::ACTIVITYPUB) { + $target = defaults($profile, 'batch', $profile['notify']); + $inboxes[$target] = $target; + } + } + } + + foreach ($receiver_list as $receiver) { + $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]); + $profile = Probe::uri($contact['url'], Protocol::ACTIVITYPUB); + if ($profile['network'] == Protocol::ACTIVITYPUB) { + $target = defaults($profile, 'batch', $profile['notify']); + $inboxes[$target] = $target; + } + } + } + + return $inboxes; + } + public static function createActivityFromItem($item_id) { $item = Item::selectFirst([], ['id' => $item_id]); @@ -177,13 +283,34 @@ class ActivityPub 'toot' => 'http://joinmastodon.org/ns#']]]; $data['type'] = 'Create'; - $data['id'] = $item['uri'] . '/activity'; + $data['id'] = $item['uri'] . '#activity'; $data['actor'] = $item['author-link']; - $data['to'] = 'https://www.w3.org/ns/activitystreams#Public'; + $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); + $data['object'] = self::createNote($item); return $data; } + public static function createObjectFromItemID($item_id) + { + $item = Item::selectFirst([], ['id' => $item_id]); + + if (!DBA::isResult($item)) { + return false; + } + + $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', + ['Emoji' => 'toot:Emoji', 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri', + 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri', + 'ostatus' => 'http://ostatus.org#', 'sensitive' => 'as:sensitive', + 'toot' => 'http://joinmastodon.org/ns#']]]; + + $data = array_merge($data, self::createNote($item)); + + + return $data; + } + public static function createNote($item) { $data = []; @@ -203,9 +330,7 @@ class ActivityPub $data['context'] = $data['conversation'] = $conversation_uri; $data['actor'] = $item['author-link']; - if (!$item['private']) { - $data['to'] = 'https://www.w3.org/ns/activitystreams#Public'; - } + $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); $data['attributedTo'] = $item['author-link']; diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php new file mode 100644 index 0000000000..b7e881c7a3 --- /dev/null +++ b/src/Worker/APDelivery.php @@ -0,0 +1,28 @@ + $item_id]); + $data = ActivityPub::createActivityFromItem($item_id); + ActivityPub::transmit($data, $inbox, $item['uid']); + } + + return; + } +} diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 8ee00af630..e0a5c09c27 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -15,7 +15,6 @@ use Friendica\Model\Item; use Friendica\Model\Queue; use Friendica\Model\User; use Friendica\Protocol\DFRN; -use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Diaspora; use Friendica\Protocol\Email; @@ -166,10 +165,6 @@ class Delivery extends BaseObject switch ($contact['network']) { - case Protocol::ACTIVITYPUB: - self::deliverActivityPub($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup); - break; - case Protocol::DFRN: self::deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup); break; @@ -388,80 +383,6 @@ class Delivery extends BaseObject logger('Unknown mode ' . $cmd . ' for ' . $loc); } - /** - * @brief Deliver content via ActivityPub -q * - * @param string $cmd Command - * @param array $contact Contact record of the receiver - * @param array $owner Owner record of the sender - * @param array $items Item record of the content and the parent - * @param array $target_item Item record of the content - * @param boolean $public_message Is the content public? - * @param boolean $top_level Is it a thread starter? - * @param boolean $followup Is it an answer to a remote post? - */ - private static function deliverActivityPub($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup) - { - // We don't treat Forum posts as "wall-to-wall" to be able to post them via ActivityPub - $walltowall = $top_level && ($owner['id'] != $items[0]['contact-id']) & ($owner['account-type'] != Contact::ACCOUNT_TYPE_COMMUNITY); - - if ($public_message) { - $loc = 'public batch ' . $contact['batch']; - } else { - $loc = $contact['addr']; - } - - logger('Deliver ' . $target_item["guid"] . ' via ActivityPub to ' . $loc); - -// if (Config::get('system', 'dfrn_only') || !Config::get('system', 'diaspora_enabled')) { -// return; -// } - if ($cmd == self::MAIL) { -// ActivityPub::sendMail($target_item, $owner, $contact); - return; - } - - if ($cmd == self::SUGGESTION) { - return; - } -// if (!$contact['pubkey'] && !$public_message) { -// logger('No public key, no delivery.'); -// return; -// } - if (($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) { - // top-level retraction - logger('ActivityPub retract: ' . $loc); -// ActivityPub::sendRetraction($target_item, $owner, $contact, $public_message); - return; - } elseif ($cmd == self::RELOCATION) { -// ActivityPub::sendAccountMigration($owner, $contact, $owner['uid']); - return; - } elseif ($followup) { - // send comments and likes to owner to relay - logger('ActivityPub followup: ' . $loc); - $data = ActivityPub::createActivityFromItem($target_item['id']); - ActivityPub::transmit($data, $contact['notify'], $owner['uid']); -// ActivityPub::sendFollowup($target_item, $owner, $contact, $public_message); - return; - } elseif ($target_item['uri'] !== $target_item['parent-uri']) { - // we are the relay - send comments, likes and relayable_retractions to our conversants - logger('ActivityPub relay: ' . $loc); - $data = ActivityPub::createActivityFromItem($target_item['id']); - ActivityPub::transmit($data, $contact['notify'], $owner['uid']); -// ActivityPub::sendRelay($target_item, $owner, $contact, $public_message); - return; - } elseif ($top_level && !$walltowall) { - // currently no workable solution for sending walltowall - logger('ActivityPub status: ' . $loc); - $data = ActivityPub::createActivityFromItem($target_item['id']); - ActivityPub::transmit($data, $contact['notify'], $owner['uid']); -// ActivityPub::sendStatus($target_item, $owner, $contact, $public_message); - return; - } - - logger('Unknown mode ' . $cmd . ' for ' . $loc); - } - /** * @brief Deliver content via mail * diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 6a37186186..693a9e343d 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -16,6 +16,7 @@ use Friendica\Model\Item; use Friendica\Model\PushSubscriber; use Friendica\Model\User; use Friendica\Network\Probe; +use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Diaspora; use Friendica\Protocol\OStatus; use Friendica\Protocol\Salmon; @@ -363,9 +364,9 @@ class Notifier } // It only makes sense to distribute answers to OStatus messages to Friendica and OStatus - but not Diaspora - $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DFRN]; + $networks = [Protocol::OSTATUS, Protocol::DFRN]; } else { - $networks = [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA, Protocol::MAIL]; + $networks = [Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA, Protocol::MAIL]; } } else { $public_message = false; @@ -413,6 +414,14 @@ class Notifier } } + $inboxes = ActivityPub::fetchTargetInboxes($target_item); + foreach ($inboxes as $inbox) { + logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); + + Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true], + 'APDelivery', $cmd, $item_id, $inbox); + } + // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts // They are especially used for notifications to OStatus users that don't follow us. if (!Config::get('system', 'dfrn_only') && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) { @@ -448,7 +457,7 @@ class Notifier } } - $condition = ['network' => [Protocol::DFRN, Protocol::ACTIVITYPUB], 'uid' => $owner['uid'], 'blocked' => false, + $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false, 'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; $r2 = DBA::toArray(DBA::select('contact', ['id', 'name', 'network'], $condition)); From 464650d4d79de8fed6ecbb05049eb38792c3b71a Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 18 Sep 2018 07:28:35 +0000 Subject: [PATCH 27/97] Public posts to Pleroma do work now, limited posts to Hubzilla and Mastodon as well --- src/Protocol/ActivityPub.php | 74 +++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index c148e26c69..b4646ad54f 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -174,6 +174,7 @@ class ActivityPub } } } else { + $data['to'][] = System::baseUrl() . '/followers/' . $item['author-nick']; $receiver_list = Item::enumeratePermissions($item); $mentioned = []; @@ -209,7 +210,8 @@ class ActivityPub $terms = Term::tagArrayFromItemId($item['id']); if (!$item['private']) { - $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $item['uid'], 'network' => Protocol::ACTIVITYPUB]); + $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $item['uid'], + 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB]); while ($contact = DBA::fetch($contacts)) { $contact = defaults($contact, 'batch', $contact['notify']); $inboxes[$contact] = $contact; @@ -240,7 +242,8 @@ class ActivityPub $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); $profile = Probe::uri($contact['url'], Protocol::ACTIVITYPUB); if ($profile['network'] == Protocol::ACTIVITYPUB) { - $target = defaults($profile, 'batch', $profile['notify']); + //$target = defaults($profile, 'batch', $profile['notify']); + $target = $profile['notify']; $inboxes[$target] = $target; } } @@ -250,12 +253,22 @@ class ActivityPub $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]); $profile = Probe::uri($contact['url'], Protocol::ACTIVITYPUB); if ($profile['network'] == Protocol::ACTIVITYPUB) { - $target = defaults($profile, 'batch', $profile['notify']); + //$target = defaults($profile, 'batch', $profile['notify']); + $target = $profile['notify']; $inboxes[$target] = $target; } } } + $profile = Probe::uri($target, Protocol::ACTIVITYPUB); + if (!empty($profile['batch'])) { + unset($inboxes[$profile['batch']]); + } + + if (!empty($profile['notify'])) { + unset($inboxes[$profile['notify']]); + } + return $inboxes; } @@ -285,6 +298,13 @@ class ActivityPub $data['type'] = 'Create'; $data['id'] = $item['uri'] . '#activity'; $data['actor'] = $item['author-link']; + + $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); + + if ($item["created"] != $item["edited"]) { + $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); + } + $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); $data['object'] = self::createNote($item); @@ -311,6 +331,38 @@ class ActivityPub return $data; } + private static function createTagList($item) + { + $tags = []; + + $receiver_list = Item::enumeratePermissions($item); + foreach ($receiver_list as $receiver) { + $contact = DBA::selectFirst('contact', ['url', 'addr'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]); + if (!empty($contact['addr'])) { + $mention = '@' . $contact['addr']; + } else { + $mention = '@' . $term['url']; + } + $tags[] = ['type' => 'Mention', 'href' => $contact['url'], 'name' => $mention]; + } + + $terms = Term::tagArrayFromItemId($item['id']); + foreach ($terms as $term) { + if ($term['type'] == TERM_MENTION) { + $contact = Contact::getDetailsByURL($term['url']); + if (!empty($contact['addr'])) { + $mention = '@' . $contact['addr']; + } else { + $mention = '@' . $term['url']; + } + + $tags[] = ['type' => 'Mention', 'href' => $term['url'], 'name' => $mention]; + } + } + + return $tags; + } + public static function createNote($item) { $data = []; @@ -332,16 +384,20 @@ class ActivityPub $data['actor'] = $item['author-link']; $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); - $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); + + if ($item["created"] != $item["edited"]) { + $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); + } + $data['attributedTo'] = $item['author-link']; $data['name'] = BBCode::convert($item['title'], false, 7); $data['content'] = BBCode::convert($item['body'], false, 7); $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"]; - //$data['summary'] = ''; // Ignore by now - //$data['sensitive'] = false; // - Query NSFW - //$data['emoji'] = []; // Ignore by now - //$data['tag'] = []; /// @ToDo - //$data['attachment'] = []; // @ToDo + $data['summary'] = ''; // Ignore by now + $data['sensitive'] = false; // - Query NSFW + $data['emoji'] = []; // Ignore by now + $data['tag'] = self::createTagList($item); + $data['attachment'] = []; // @ToDo return $data; } From cb073bea613faaee591267cb7eca376ecc0e129f Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 18 Sep 2018 19:36:27 +0000 Subject: [PATCH 28/97] Private posts with Mastodon don't work - but this is expected --- src/Protocol/ActivityPub.php | 44 ++++++++++++------------------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index b4646ad54f..47f81f8bf4 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -125,9 +125,8 @@ class ActivityPub } $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', - ['uuid' => 'http://schema.org/identifier', 'sensitive' => 'as:sensitive', - 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', - 'vcard' => 'http://www.w3.org/2006/vcard/ns#']]]; + ['vcard' => 'http://www.w3.org/2006/vcard/ns#', 'uuid' => 'http://schema.org/identifier', + 'sensitive' => 'as:sensitive', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers']]]; $data['id'] = $contact['url']; $data['uuid'] = $user['guid']; @@ -174,7 +173,7 @@ class ActivityPub } } } else { - $data['to'][] = System::baseUrl() . '/followers/' . $item['author-nick']; + //$data['cc'][] = System::baseUrl() . '/followers/' . $item['author-nick']; $receiver_list = Item::enumeratePermissions($item); $mentioned = []; @@ -197,7 +196,7 @@ class ActivityPub if (empty($data['to'])) { $data['to'] = $data['cc']; - unset($data['cc']); + $data['cc'] = []; } } @@ -242,8 +241,7 @@ class ActivityPub $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); $profile = Probe::uri($contact['url'], Protocol::ACTIVITYPUB); if ($profile['network'] == Protocol::ACTIVITYPUB) { - //$target = defaults($profile, 'batch', $profile['notify']); - $target = $profile['notify']; + $target = defaults($profile, 'batch', $profile['notify']); $inboxes[$target] = $target; } } @@ -253,8 +251,7 @@ class ActivityPub $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]); $profile = Probe::uri($contact['url'], Protocol::ACTIVITYPUB); if ($profile['network'] == Protocol::ACTIVITYPUB) { - //$target = defaults($profile, 'batch', $profile['notify']); - $target = $profile['notify']; + $target = defaults($profile, 'batch', $profile['notify']); $inboxes[$target] = $target; } } @@ -290,10 +287,10 @@ class ActivityPub } $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', - ['Emoji' => 'toot:Emoji', 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri', - 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri', - 'ostatus' => 'http://ostatus.org#', 'sensitive' => 'as:sensitive', - 'toot' => 'http://joinmastodon.org/ns#']]]; + ['ostatus' => 'http://ostatus.org#', 'sensitive' => 'as:sensitive', + 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri', + 'conversation' => 'ostatus:conversation', + 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; $data['type'] = 'Create'; $data['id'] = $item['uri'] . '#activity'; @@ -320,10 +317,10 @@ class ActivityPub } $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', - ['Emoji' => 'toot:Emoji', 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri', - 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri', - 'ostatus' => 'http://ostatus.org#', 'sensitive' => 'as:sensitive', - 'toot' => 'http://joinmastodon.org/ns#']]]; + ['ostatus' => 'http://ostatus.org#', 'sensitive' => 'as:sensitive', + 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri', + 'conversation' => 'ostatus:conversation', + 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; $data = array_merge($data, self::createNote($item)); @@ -335,17 +332,6 @@ class ActivityPub { $tags = []; - $receiver_list = Item::enumeratePermissions($item); - foreach ($receiver_list as $receiver) { - $contact = DBA::selectFirst('contact', ['url', 'addr'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]); - if (!empty($contact['addr'])) { - $mention = '@' . $contact['addr']; - } else { - $mention = '@' . $term['url']; - } - $tags[] = ['type' => 'Mention', 'href' => $contact['url'], 'name' => $mention]; - } - $terms = Term::tagArrayFromItemId($item['id']); foreach ($terms as $term) { if ($term['type'] == TERM_MENTION) { @@ -395,7 +381,7 @@ class ActivityPub $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"]; $data['summary'] = ''; // Ignore by now $data['sensitive'] = false; // - Query NSFW - $data['emoji'] = []; // Ignore by now + //$data['emoji'] = []; // Ignore by now $data['tag'] = self::createTagList($item); $data['attachment'] = []; // @ToDo return $data; From 5de4afecf138726dc483ebf90e4fe354002389bc Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 18 Sep 2018 22:09:27 +0000 Subject: [PATCH 29/97] Table for AP contacts, JSON-LD parser included --- composer.json | 3 +- composer.lock | 58 ++++++++++++++++++++++++--- config/dbstructure.json | 28 +++++++++++++ src/Protocol/ActivityPub.php | 78 +++++++++++++++++++++++------------- 4 files changed, 133 insertions(+), 34 deletions(-) diff --git a/composer.json b/composer.json index 04e4b655da..329c22664f 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,8 @@ "npm-asset/jgrowl": "^1.4", "npm-asset/fullcalendar": "^3.0.1", "npm-asset/cropperjs": "1.2.2", - "npm-asset/imagesloaded": "4.1.4" + "npm-asset/imagesloaded": "4.1.4", + "digitalbazaar/json-ld": "^0.4.7" }, "repositories": [ { diff --git a/composer.lock b/composer.lock index 76c20a1b93..a564990347 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "d62c3e3d6971ee63a862a22ff3cd3768", + "content-hash": "7bfbddde186f6599a2f2012bb13cbbd8", "packages": [ { "name": "asika/simple-console", @@ -149,6 +149,52 @@ }, "type": "bower-asset-library" }, + { + "name": "digitalbazaar/json-ld", + "version": "0.4.7", + "source": { + "type": "git", + "url": "https://github.com/digitalbazaar/php-json-ld.git", + "reference": "dc1bd23f0ee2efd27ccf636d32d2738dabcee182" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/digitalbazaar/php-json-ld/zipball/dc1bd23f0ee2efd27ccf636d32d2738dabcee182", + "reference": "dc1bd23f0ee2efd27ccf636d32d2738dabcee182", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "files": [ + "jsonld.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Digital Bazaar, Inc.", + "email": "support@digitalbazaar.com" + } + ], + "description": "A JSON-LD Processor and API implementation in PHP.", + "homepage": "https://github.com/digitalbazaar/php-json-ld", + "keywords": [ + "JSON-LD", + "Linked Data", + "RDF", + "Semantic Web", + "json", + "jsonld" + ], + "time": "2016-04-25T04:17:52+00:00" + }, { "name": "divineomega/password_exposed", "version": "v2.5.1", @@ -3145,7 +3191,7 @@ } ], "description": "Provides the functionality to compare PHP values for equality", - "homepage": "https://github.com/sebastianbergmann/comparator", + "homepage": "http://www.github.com/sebastianbergmann/comparator", "keywords": [ "comparator", "compare", @@ -3247,7 +3293,7 @@ } ], "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "https://github.com/sebastianbergmann/environment", + "homepage": "http://www.github.com/sebastianbergmann/environment", "keywords": [ "Xdebug", "environment", @@ -3315,7 +3361,7 @@ } ], "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "https://github.com/sebastianbergmann/exporter", + "homepage": "http://www.github.com/sebastianbergmann/exporter", "keywords": [ "export", "exporter" @@ -3367,7 +3413,7 @@ } ], "description": "Snapshotting of global state", - "homepage": "https://github.com/sebastianbergmann/global-state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", "keywords": [ "global state" ], @@ -3469,7 +3515,7 @@ } ], "description": "Provides functionality to recursively process PHP variables", - "homepage": "https://github.com/sebastianbergmann/recursion-context", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", "time": "2016-11-19T07:33:16+00:00" }, { diff --git a/config/dbstructure.json b/config/dbstructure.json index 8767c0db16..8f67686156 100644 --- a/config/dbstructure.json +++ b/config/dbstructure.json @@ -15,6 +15,34 @@ "name": ["UNIQUE", "name"] } }, + "apcontact": { + "comment": "ActivityPub compatible contacts - used in the ActivityPub implementation", + "fields": { + "url": {"type": "varbinary(255)", "not null": "1", "primary": "1", "comment": "URL of the contact"}, + "uuid": {"type": "varchar(255)", "comment": ""}, + "type": {"type": "varchar(20)", "not null": "1", "comment": ""}, + "following": {"type": "varchar(255)", "comment": ""}, + "followers": {"type": "varchar(255)", "comment": ""}, + "inbox": {"type": "varchar(255)", "not null": "1", "comment": ""}, + "outbox": {"type": "varchar(255)", "comment": ""}, + "sharedinbox": {"type": "varchar(255)", "comment": ""}, + "nick": {"type": "varchar(255)", "not null": "1", "default": "", "comment": ""}, + "name": {"type": "varchar(255)", "comment": ""}, + "about": {"type": "text", "comment": ""}, + "photo": {"type": "varchar(255)", "comment": ""}, + "addr": {"type": "varchar(255)", "comment": ""}, + "alias": {"type": "varchar(255)", "comment": ""}, + "pubkey": {"type": "text", "comment": ""}, + "baseurl": {"type": "varchar(255)", "comment": "baseurl of the ap contact"}, + "updated": {"type": "datetime", "not null": "1", "default": "0001-01-01 00:00:00", "comment": ""} + + }, + "indexes": { + "PRIMARY": ["url"], + "addr": ["addr(32)"], + "url": ["followers(190)"] + } + }, "attach": { "comment": "file attachments", "fields": { diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 47f81f8bf4..ffde0eff00 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -684,39 +684,63 @@ class ActivityPub return false; } - $profile = ['network' => Protocol::ACTIVITYPUB]; - $profile['nick'] = $data['preferredUsername']; - $profile['name'] = defaults($data, 'name', $profile['nick']); - $profile['guid'] = defaults($data, 'uuid', null); - $profile['url'] = $data['id']; + $apcontact = []; + $apcontact['url'] = $data['id']; + $apcontact['uuid'] = defaults($data, 'uuid', null); + $apcontact['type'] = defaults($data, 'type', null); + $apcontact['following'] = defaults($data, 'following', null); + $apcontact['followers'] = defaults($data, 'followers', null); + $apcontact['inbox'] = defaults($data, 'inbox', null); + $apcontact['outbox'] = defaults($data, 'outbox', null); + $apcontact['sharedinbox'] = self::processElement($data, 'endpoints', 'sharedInbox'); + $apcontact['nick'] = defaults($data, 'preferredUsername', null); + $apcontact['name'] = defaults($data, 'name', $apcontact['nick']); + $apcontact['about'] = defaults($data, 'summary', ''); + $apcontact['photo'] = self::processElement($data, 'icon', 'url'); + $apcontact['alias'] = self::processElement($data, 'url', 'href'); - $parts = parse_url($profile['url']); + $parts = parse_url($apcontact['url']); unset($parts['scheme']); unset($parts['path']); - $profile['addr'] = $profile['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts)); - $profile['alias'] = self::processElement($data, 'url', 'href'); - $profile['photo'] = self::processElement($data, 'icon', 'url'); + $apcontact['addr'] = $apcontact['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts)); + + $apcontact['pubkey'] = self::processElement($data, 'publicKey', 'publicKeyPem'); + + // Check if the address is resolvable + if (self::addrToUrl($apcontact['addr']) == $apcontact['url']) { + $parts = parse_url($apcontact['url']); + unset($parts['path']); + $apcontact['baseurl'] = Network::unparseURL($parts); + } else { + $apcontact['addr'] = null; + } + + if ($apcontact['url'] == $apcontact['alias']) { + $apcontact['alias'] = null; + } + + $apcontact['updated'] = DateTimeFormat::utcNow(); + + DBA::update('apcontact', $apcontact, ['url' => $url], true); + + // Array that is compatible to Probe::uri + $profile = ['network' => Protocol::ACTIVITYPUB]; + $profile['nick'] = $apcontact['nick']; + $profile['name'] = $apcontact['name']; + $profile['guid'] = $apcontact['uuid']; + $profile['url'] = $apcontact['url']; + $profile['addr'] = $apcontact['addr']; + $profile['alias'] = $apcontact['alias']; + $profile['photo'] = $apcontact['photo']; // $profile['community'] // $profile['keywords'] // $profile['location'] - $profile['about'] = defaults($data, 'summary', ''); - $profile['batch'] = self::processElement($data, 'endpoints', 'sharedInbox'); - $profile['notify'] = $data['inbox']; - $profile['poll'] = $data['outbox']; - $profile['pubkey'] = self::processElement($data, 'publicKey', 'publicKeyPem'); - - // Check if the address is resolvable - if (self::addrToUrl($profile['addr']) == $profile['url']) { - $parts = parse_url($profile['url']); - unset($parts['path']); - $profile['baseurl'] = Network::unparseURL($parts); - } else { - unset($profile['addr']); - } - - if ($profile['url'] == $profile['alias']) { - unset($profile['alias']); - } + $profile['about'] = $apcontact['about']; + $profile['batch'] = $apcontact['sharedinbox']; + $profile['notify'] = $apcontact['inbox']; + $profile['poll'] = $apcontact['outbox']; + $profile['pubkey'] = $apcontact['pubkey']; + $profile['baseurl'] = $apcontact['baseurl']; // Remove all "null" fields foreach ($profile as $field => $content) { From f20bed67a95160f5a6539dde49f82a8ac53161ad Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Sep 2018 05:00:49 +0000 Subject: [PATCH 30/97] Table "apcontact" is now in use / added functionality to handle JSON-LD --- src/Network/Probe.php | 2 +- src/Protocol/ActivityPub.php | 178 +++++++++++++++++++++++++---------- 2 files changed, 128 insertions(+), 52 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 0e9219c5a6..c0c627bfe9 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -336,7 +336,7 @@ class Probe } if (in_array(defaults($data, 'network', ''), ['', Protocol::PHANTOM])) { - $ap_profile = ActivityPub::fetchProfile($uri); + $ap_profile = ActivityPub::probeProfile($uri); if (!empty($ap_profile) && ($ap_profile['network'] == Protocol::ACTIVITYPUB)) { $data = $ap_profile; } diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index ffde0eff00..4a2394a24b 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -19,7 +19,8 @@ use Friendica\Util\DateTimeFormat; use Friendica\Util\Crypto; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; -use Friendica\Network\Probe; +use Friendica\Core\Cache; +use digitalbazaar\jsonld; /** * @brief ActivityPub Protocol class @@ -57,6 +58,51 @@ class ActivityPub { const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; +public static function jsonld_document_loader($url) +{ + $recursion = 0; + + $x = debug_backtrace(); + if ($x) { + foreach ($x as $n) { + if ($n['function'] === __FUNCTION__) { + $recursion ++; + } + } + } + + if ($recursion > 5) { + logger('jsonld bomb detected at: ' . $url); + exit(); + } + + $result = Cache::get('jsonld_document_loader:' . $url); + if (!is_null($result)) { + return $result; + } + + $data = jsonld_default_document_loader($url); + Cache::set('jsonld_document_loader:' . $url, $data, CACHE_DAY); + return $data; +} + + public static function compactJsonLD($json) + { + jsonld_set_document_loader('Friendica\Protocol\ActivityPub::jsonld_document_loader'); + + $context = (object)['as' => 'https://www.w3.org/ns/activitystreams', + 'w3sec' => 'https://w3id.org/security', + 'ostatus' => (object)['@id' => 'http://ostatus.org#', '@type' => '@id'], + 'vcard' => (object)['@id' => 'http://www.w3.org/2006/vcard/ns#', '@type' => '@id'], + 'uuid' => (object)['@id' => 'http://schema.org/identifier', '@type' => '@id']]; + + $jsonobj = json_decode(json_encode($json)); + + $compacted = jsonld_compact($jsonobj, $context); + + return json_decode(json_encode($compacted), true); + } + public static function isRequest() { return stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json') || @@ -167,8 +213,8 @@ class ActivityPub if ($term['type'] != TERM_MENTION) { continue; } - $profile = Probe::uri($term['url'], Protocol::ACTIVITYPUB); - if ($profile['network'] == Protocol::ACTIVITYPUB) { + $profile = self::fetchprofile($term['url']); + if (!empty($profile)) { $data['cc'][] = $profile['url']; } } @@ -221,9 +267,9 @@ class ActivityPub if ($term['type'] != TERM_MENTION) { continue; } - $profile = Probe::uri($term['url'], Protocol::ACTIVITYPUB); - if ($profile['network'] == Protocol::ACTIVITYPUB) { - $target = defaults($profile, 'batch', $profile['notify']); + $profile = self::fetchprofile($term['url']); + if (!empty($profile)) { + $target = defaults($profile, 'sharedinbox', $profile['inbox']); $inboxes[$target] = $target; } } @@ -239,9 +285,9 @@ class ActivityPub $cid = Contact::getIdForURL($term['url'], $item['uid']); if (!empty($cid) && in_array($cid, $receiver_list)) { $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); - $profile = Probe::uri($contact['url'], Protocol::ACTIVITYPUB); - if ($profile['network'] == Protocol::ACTIVITYPUB) { - $target = defaults($profile, 'batch', $profile['notify']); + $profile = self::fetchprofile($contact['url']); + if (!empty($profile['network'])) { + $target = defaults($profile, 'sharedinbox', $profile['inbox']); $inboxes[$target] = $target; } } @@ -249,21 +295,21 @@ class ActivityPub foreach ($receiver_list as $receiver) { $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]); - $profile = Probe::uri($contact['url'], Protocol::ACTIVITYPUB); - if ($profile['network'] == Protocol::ACTIVITYPUB) { - $target = defaults($profile, 'batch', $profile['notify']); + $profile = self::fetchprofile($contact['url']); + if (!empty($profile['network'])) { + $target = defaults($profile, 'sharedinbox', $profile['inbox']); $inboxes[$target] = $target; } } } - $profile = Probe::uri($target, Protocol::ACTIVITYPUB); - if (!empty($profile['batch'])) { - unset($inboxes[$profile['batch']]); + $profile = self::fetchprofile($item['author-link']); + if (!empty($profile['sharedinbox'])) { + unset($inboxes[$profile['sharedinbox']]); } - if (!empty($profile['notify'])) { - unset($inboxes[$profile['notify']]); + if (!empty($profile['inbox'])) { + unset($inboxes[$profile['inbox']]); } return $inboxes; @@ -389,7 +435,7 @@ class ActivityPub public static function transmitActivity($activity, $target, $uid) { - $profile = Probe::uri($target, Protocol::ACTIVITYPUB); + $profile = self::fetchprofile($target); $owner = User::getOwnerDataById($uid); @@ -401,12 +447,12 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG); - return self::transmit($data, $profile['notify'], $uid); + return self::transmit($data, $profile['inbox'], $uid); } public static function transmitContactAccept($target, $id, $uid) { - $profile = Probe::uri($target, Protocol::ACTIVITYPUB); + $profile = self::fetchprofile($target); $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', @@ -419,12 +465,12 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); - return self::transmit($data, $profile['notify'], $uid); + return self::transmit($data, $profile['inbox'], $uid); } public static function transmitContactReject($target, $id, $uid) { - $profile = Probe::uri($target, Protocol::ACTIVITYPUB); + $profile = self::fetchprofile($target); $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', @@ -437,12 +483,12 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); - return self::transmit($data, $profile['notify'], $uid); + return self::transmit($data, $profile['inbox'], $uid); } public static function transmitContactUndo($target, $uid) { - $profile = Probe::uri($target, Protocol::ACTIVITYPUB); + $profile = self::fetchprofile($target); $id = System::baseUrl() . '/activity/' . System::createGUID(); @@ -457,7 +503,7 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); - return self::transmit($data, $profile['notify'], $uid); + return self::transmit($data, $profile['inbox'], $uid); } /** @@ -616,11 +662,11 @@ class ActivityPub { $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id); - $profile = Probe::uri($url, Protocol::ACTIVITYPUB); + $profile = self::fetchprofile($url); if (!empty($profile)) { return $profile['pubkey']; } elseif ($url != $actor) { - $profile = Probe::uri($actor, Protocol::ACTIVITYPUB); + $profile = self::fetchprofile($actor); if (!empty($profile)) { return $profile['pubkey']; } @@ -663,14 +709,29 @@ class ActivityPub return $ret; } - /** - * Fetches a profile from the given url - * - * @param string $url profile url - * @return array - */ - public static function fetchProfile($url) + public static function fetchprofile($url, $update = false) { + if (empty($url)) { + return false; + } + + if (!$update) { + $apcontact = DBA::selectFirst('apcontact', [], ['url' => $url]); + if (DBA::isResult($apcontact)) { + return $apcontact; + } + + $apcontact = DBA::selectFirst('apcontact', [], ['alias' => $url]); + if (DBA::isResult($apcontact)) { + return $apcontact; + } + + $apcontact = DBA::selectFirst('apcontact', [], ['addr' => $url]); + if (DBA::isResult($apcontact)) { + return $apcontact; + } + } + if (empty(parse_url($url, PHP_URL_SCHEME))) { $url = self::addrToUrl($url); if (empty($url)) { @@ -704,7 +765,19 @@ class ActivityPub unset($parts['path']); $apcontact['addr'] = $apcontact['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts)); - $apcontact['pubkey'] = self::processElement($data, 'publicKey', 'publicKeyPem'); + $apcontact['pubkey'] = trim(self::processElement($data, 'publicKey', 'publicKeyPem')); + + // To-Do + // manuallyApprovesFollowers + + // Unhandled + // @context, tag, attachment, image, nomadicLocations, signature, following, followers, featured, movedTo, liked + + // Unhandled from Misskey + // sharedInbox, isCat + + // Unhandled from Kroeg + // kroeg:blocks, updated // Check if the address is resolvable if (self::addrToUrl($apcontact['addr']) == $apcontact['url']) { @@ -723,7 +796,22 @@ class ActivityPub DBA::update('apcontact', $apcontact, ['url' => $url], true); - // Array that is compatible to Probe::uri + return $apcontact; + } + + /** + * Fetches a profile from the given url into an array that is compatible to Probe::uri + * + * @param string $url profile url + * @return array + */ + public static function probeProfile($url) + { + $apcontact = self::fetchprofile($url, true); + if (empty($apcontact)) { + return false; + } + $profile = ['network' => Protocol::ACTIVITYPUB]; $profile['nick'] = $apcontact['nick']; $profile['name'] = $apcontact['name']; @@ -749,18 +837,6 @@ class ActivityPub } } - // To-Do - // type, manuallyApprovesFollowers - - // Unhandled - // @context, tag, attachment, image, nomadicLocations, signature, following, followers, featured, movedTo, liked - - // Unhandled from Misskey - // sharedInbox, isCat - - // Unhandled from Kroeg - // kroeg:blocks, updated - return $profile; } @@ -953,8 +1029,8 @@ class ActivityPub $receivers = []; if (!empty($actor)) { - $data = self::fetchContent($actor); - $followers = defaults($data, 'followers', ''); + $profile = self::fetchprofile($actor); + $followers = defaults($profile, 'followers', ''); logger('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG); } else { @@ -1365,7 +1441,7 @@ class ActivityPub $activity['id'] = $object['id']; $activity['to'] = defaults($object, 'to', []); $activity['cc'] = defaults($object, 'cc', []); - $activity['actor'] = $activity['author']; + $activity['actor'] = $child['author']; $activity['object'] = $object; $activity['published'] = $object['published']; $activity['type'] = 'Create'; From 34cb0aa406969967fa521211116564805ef6b631 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Sep 2018 05:30:07 +0000 Subject: [PATCH 31/97] JSON-LD stuff is now in a separate file --- src/Protocol/ActivityPub.php | 47 ------------------------- src/Util/JsonLD.php | 68 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 src/Util/JsonLD.php diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 4a2394a24b..36cc32d64b 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -19,8 +19,6 @@ use Friendica\Util\DateTimeFormat; use Friendica\Util\Crypto; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; -use Friendica\Core\Cache; -use digitalbazaar\jsonld; /** * @brief ActivityPub Protocol class @@ -58,51 +56,6 @@ class ActivityPub { const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; -public static function jsonld_document_loader($url) -{ - $recursion = 0; - - $x = debug_backtrace(); - if ($x) { - foreach ($x as $n) { - if ($n['function'] === __FUNCTION__) { - $recursion ++; - } - } - } - - if ($recursion > 5) { - logger('jsonld bomb detected at: ' . $url); - exit(); - } - - $result = Cache::get('jsonld_document_loader:' . $url); - if (!is_null($result)) { - return $result; - } - - $data = jsonld_default_document_loader($url); - Cache::set('jsonld_document_loader:' . $url, $data, CACHE_DAY); - return $data; -} - - public static function compactJsonLD($json) - { - jsonld_set_document_loader('Friendica\Protocol\ActivityPub::jsonld_document_loader'); - - $context = (object)['as' => 'https://www.w3.org/ns/activitystreams', - 'w3sec' => 'https://w3id.org/security', - 'ostatus' => (object)['@id' => 'http://ostatus.org#', '@type' => '@id'], - 'vcard' => (object)['@id' => 'http://www.w3.org/2006/vcard/ns#', '@type' => '@id'], - 'uuid' => (object)['@id' => 'http://schema.org/identifier', '@type' => '@id']]; - - $jsonobj = json_decode(json_encode($json)); - - $compacted = jsonld_compact($jsonobj, $context); - - return json_decode(json_encode($compacted), true); - } - public static function isRequest() { return stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json') || diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php new file mode 100644 index 0000000000..e8ff5888de --- /dev/null +++ b/src/Util/JsonLD.php @@ -0,0 +1,68 @@ + 5) { + logger('jsonld bomb detected at: ' . $url); + exit(); + } + + $result = Cache::get('documentLoader:' . $url); + if (!is_null($result)) { + return $result; + } + + $data = jsonld_default_document_loader($url); + Cache::set('documentLoader:' . $url, $data, CACHE_DAY); + return $data; + } + + public static function normalize($json) + { + jsonld_set_document_loader('Friendica\Util\JsonLD::documentLoader'); + + $jsonobj = json_decode(json_encode($json)); + + return jsonld_normalize($jsonobj, array('algorithm' => 'URDNA2015', 'format' => 'application/nquads')); + } + + public static function compact($json) + { + jsonld_set_document_loader('Friendica\Util\JsonLD::documentLoader'); + + $context = (object)['as' => 'https://www.w3.org/ns/activitystreams', + 'w3sec' => 'https://w3id.org/security', + 'ostatus' => (object)['@id' => 'http://ostatus.org#', '@type' => '@id'], + 'vcard' => (object)['@id' => 'http://www.w3.org/2006/vcard/ns#', '@type' => '@id'], + 'uuid' => (object)['@id' => 'http://schema.org/identifier', '@type' => '@id']]; + + $jsonobj = json_decode(json_encode($json)); + + $compacted = jsonld_compact($jsonobj, $context); + + return json_decode(json_encode($compacted), true); + } +} From 0d51474e73dc50ac0b7159cb92fcadeafb976fc1 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Sep 2018 05:37:01 +0000 Subject: [PATCH 32/97] Relocated function --- src/Protocol/ActivityPub.php | 72 ++++++++++-------------------------- src/Util/JsonLD.php | 35 ++++++++++++++++++ 2 files changed, 54 insertions(+), 53 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 36cc32d64b..bd125aaaef 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -19,6 +19,7 @@ use Friendica\Util\DateTimeFormat; use Friendica\Util\Crypto; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; +use Friendica\Util\JsonLD; /** * @brief ActivityPub Protocol class @@ -522,7 +523,7 @@ class ActivityPub return false; } - $actor = self::processElement($object, 'actor', 'id'); + $actor = JsonLD::fetchElement($object, 'actor', 'id'); $headers = []; $headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . $http_headers['REQUEST_URI']; @@ -706,19 +707,19 @@ class ActivityPub $apcontact['followers'] = defaults($data, 'followers', null); $apcontact['inbox'] = defaults($data, 'inbox', null); $apcontact['outbox'] = defaults($data, 'outbox', null); - $apcontact['sharedinbox'] = self::processElement($data, 'endpoints', 'sharedInbox'); + $apcontact['sharedinbox'] = JsonLD::fetchElement($data, 'endpoints', 'sharedInbox'); $apcontact['nick'] = defaults($data, 'preferredUsername', null); $apcontact['name'] = defaults($data, 'name', $apcontact['nick']); $apcontact['about'] = defaults($data, 'summary', ''); - $apcontact['photo'] = self::processElement($data, 'icon', 'url'); - $apcontact['alias'] = self::processElement($data, 'url', 'href'); + $apcontact['photo'] = JsonLD::fetchElement($data, 'icon', 'url'); + $apcontact['alias'] = JsonLD::fetchElement($data, 'url', 'href'); $parts = parse_url($apcontact['url']); unset($parts['scheme']); unset($parts['path']); $apcontact['addr'] = $apcontact['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts)); - $apcontact['pubkey'] = trim(self::processElement($data, 'publicKey', 'publicKeyPem')); + $apcontact['pubkey'] = trim(JsonLD::fetchElement($data, 'publicKey', 'publicKeyPem')); // To-Do // manuallyApprovesFollowers @@ -837,7 +838,7 @@ class ActivityPub private static function prepareObjectData($activity, $uid) { - $actor = self::processElement($activity, 'actor', 'id'); + $actor = JsonLD::fetchElement($activity, 'actor', 'id'); if (empty($actor)) { logger('Empty actor', LOGGER_DEBUG); return []; @@ -875,12 +876,12 @@ class ActivityPub } } elseif ($activity['type'] == 'Accept') { $object_data = []; - $object_data['object_type'] = self::processElement($activity, 'object', 'type'); - $object_data['object'] = self::processElement($activity, 'object', 'actor'); + $object_data['object_type'] = JsonLD::fetchElement($activity, 'object', 'type'); + $object_data['object'] = JsonLD::fetchElement($activity, 'object', 'actor'); } elseif ($activity['type'] == 'Undo') { $object_data = []; - $object_data['object_type'] = self::processElement($activity, 'object', 'type'); - $object_data['object'] = self::processElement($activity, 'object', 'object'); + $object_data['object_type'] = JsonLD::fetchElement($activity, 'object', 'type'); + $object_data['object'] = JsonLD::fetchElement($activity, 'object', 'object'); } elseif (in_array($activity['type'], ['Like', 'Dislike'])) { // Create a mostly empty array out of the activity data (instead of the object). // This way we later don't have to check for the existence of ech individual array element. @@ -1054,11 +1055,11 @@ class ActivityPub } if (!empty($activity['inReplyTo']) && empty($object_data['parent-uri'])) { - $object_data['parent-uri'] = self::processElement($activity, 'inReplyTo', 'id'); + $object_data['parent-uri'] = JsonLD::fetchElement($activity, 'inReplyTo', 'id'); } if (!empty($activity['instrument'])) { - $object_data['service'] = self::processElement($activity, 'instrument', 'name', 'type', 'Service'); + $object_data['service'] = JsonLD::fetchElement($activity, 'instrument', 'name', 'type', 'Service'); } return $object_data; } @@ -1134,7 +1135,7 @@ class ActivityPub $object_data['uri'] = $object['id']; if (!empty($object['inReplyTo'])) { - $object_data['reply-to-uri'] = self::processElement($object, 'inReplyTo', 'id'); + $object_data['reply-to-uri'] = JsonLD::fetchElement($object, 'inReplyTo', 'id'); } else { $object_data['reply-to-uri'] = $object_data['uri']; } @@ -1147,7 +1148,7 @@ class ActivityPub } $object_data['uuid'] = defaults($object, 'uuid', null); - $object_data['owner'] = $object_data['author'] = self::processElement($object, 'attributedTo', 'id'); + $object_data['owner'] = $object_data['author'] = JsonLD::fetchElement($object, 'attributedTo', 'id'); $object_data['context'] = defaults($object, 'context', null); $object_data['conversation'] = defaults($object, 'conversation', null); $object_data['sensitive'] = defaults($object, 'sensitive', null); @@ -1156,11 +1157,11 @@ class ActivityPub $object_data['summary'] = defaults($object, 'summary', null); $object_data['content'] = defaults($object, 'content', null); $object_data['source'] = defaults($object, 'source', null); - $object_data['location'] = self::processElement($object, 'location', 'name', 'type', 'Place'); + $object_data['location'] = JsonLD::fetchElement($object, 'location', 'name', 'type', 'Place'); $object_data['attachments'] = defaults($object, 'attachment', null); $object_data['tags'] = defaults($object, 'tag', null); - $object_data['service'] = self::processElement($object, 'instrument', 'name', 'type', 'Service'); - $object_data['alternate-url'] = self::processElement($object, 'url', 'href'); + $object_data['service'] = JsonLD::fetchElement($object, 'instrument', 'name', 'type', 'Service'); + $object_data['alternate-url'] = JsonLD::fetchElement($object, 'url', 'href'); $object_data['receiver'] = self::getReceivers($object, $object_data['owner']); // Unhandled @@ -1207,41 +1208,6 @@ class ActivityPub return $object_data; } - private static function processElement($array, $element, $key, $type = null, $type_value = null) - { - if (empty($array)) { - return false; - } - - if (empty($array[$element])) { - return false; - } - - if (is_string($array[$element])) { - return $array[$element]; - } - - if (is_null($type_value)) { - if (!empty($array[$element][$key])) { - return $array[$element][$key]; - } - - if (!empty($array[$element][0][$key])) { - return $array[$element][0][$key]; - } - - return false; - } - - if (!empty($array[$element][$key]) && !empty($array[$element][$type]) && ($array[$element][$type] == $type_value)) { - return $array[$element][$key]; - } - - /// @todo Add array search - - return false; - } - private static function convertMentions($body) { $URLSearchString = "^\[\]"; @@ -1358,7 +1324,7 @@ class ActivityPub $item = self::constructAttachList($activity['attachments'], $item); - $source = self::processElement($activity, 'source', 'content', 'mediaType', 'text/bbcode'); + $source = JsonLD::fetchElement($activity, 'source', 'content', 'mediaType', 'text/bbcode'); if (!empty($source)) { $item['body'] = $source; } diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index e8ff5888de..8fd9f90cb4 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -65,4 +65,39 @@ class JsonLD return json_decode(json_encode($compacted), true); } + + public static function fetchElement($array, $element, $key, $type = null, $type_value = null) + { + if (empty($array)) { + return false; + } + + if (empty($array[$element])) { + return false; + } + + if (is_string($array[$element])) { + return $array[$element]; + } + + if (is_null($type_value)) { + if (!empty($array[$element][$key])) { + return $array[$element][$key]; + } + + if (!empty($array[$element][0][$key])) { + return $array[$element][0][$key]; + } + + return false; + } + + if (!empty($array[$element][$key]) && !empty($array[$element][$type]) && ($array[$element][$type] == $type_value)) { + return $array[$element][$key]; + } + + /// @todo Add array search + + return false; + } } From 0866fbaf8c65eedbf2d57a1b61f4fe96b2a526fd Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Sep 2018 09:50:03 +0000 Subject: [PATCH 33/97] Code cleaning / wrong table for flags --- src/Protocol/ActivityPub.php | 6 ++-- src/Util/HTTPSignature.php | 67 ------------------------------------ 2 files changed, 3 insertions(+), 70 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index bd125aaaef..25ebedc8bd 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -103,10 +103,10 @@ class ActivityPub */ public static function profile($uid) { - $accounttype = ['Person', 'Organization', 'Service', 'Group', 'Application', 'page-flags']; + $accounttype = ['Person', 'Organization', 'Service', 'Group', 'Application']; $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false, 'account_removed' => false, 'verified' => true]; - $fields = ['guid', 'nickname', 'pubkey', 'account-type']; + $fields = ['guid', 'nickname', 'pubkey', 'account-type', 'page-flags']; $user = DBA::selectFirst('user', $fields, $condition); if (!DBA::isResult($user)) { return []; @@ -141,7 +141,7 @@ class ActivityPub 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']]; $data['summary'] = $contact['about']; $data['url'] = $contact['url']; - $data['manuallyApprovesFollowers'] = in_array($profile['page-flags'], [Contact::PAGE_NORMAL, Contact::PAGE_PRVGROUP]); + $data['manuallyApprovesFollowers'] = in_array($user['page-flags'], [Contact::PAGE_NORMAL, Contact::PAGE_PRVGROUP]); $data['publicKey'] = ['id' => $contact['url'] . '#main-key', 'owner' => $contact['url'], 'publicKeyPem' => $user['pubkey']]; diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 911de4308e..adf5d8ad27 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -18,30 +18,6 @@ use Friendica\Database\DBA; class HTTPSignature { - /** - * @brief RFC5843 - * - * Disabled until Friendica's ActivityPub implementation - * is ready. - * - * @see https://tools.ietf.org/html/rfc5843 - * - * @param string $body The value to create the digest for - * @param boolean $set (optional, default true) - * If set send a Digest HTTP header - * - * @return string The generated digest of $body - */ -// public static function generateDigest($body, $set = true) -// { -// $digest = base64_encode(hash('sha256', $body, true)); -// -// if($set) { -// header('Digest: SHA-256=' . $digest); -// } -// return $digest; -// } - // See draft-cavage-http-signatures-08 public static function verify($data, $key = '') { @@ -127,12 +103,6 @@ class HTTPSignature logger('Got keyID ' . $sig_block['keyId']); - // We don't use Activity Pub at the moment. -// if (!$key) { -// $result['signer'] = $sig_block['keyId']; -// $key = self::getActivitypubKey($sig_block['keyId']); -// } - if (!$key) { return $result; } @@ -171,43 +141,6 @@ class HTTPSignature return $result; } - /** - * Fetch the public key for Activity Pub contact. - * - * @param string|int The identifier (contact addr or contact ID). - * @return string|boolean The public key or false on failure. - */ - private static function getActivitypubKey($id) - { - if (strpos($id, 'acct:') === 0) { - $contact = DBA::selectFirst('contact', ['pubkey'], ['uid' => 0, 'addr' => str_replace('acct:', '', $id)]); - } else { - $contact = DBA::selectFirst('contact', ['pubkey'], ['id' => $id, 'network' => 'activitypub']); - } - - if (DBA::isResult($contact)) { - return $contact['pubkey']; - } - - if(function_exists('as_fetch')) { - $r = as_fetch($id); - } - - if ($r) { - $j = json_decode($r, true); - - if (array_key_exists('publicKey', $j) && array_key_exists('publicKeyPem', $j['publicKey'])) { - if ((array_key_exists('id', $j['publicKey']) && $j['publicKey']['id'] !== $id) && $j['id'] !== $id) { - return false; - } - - return $j['publicKey']['publicKeyPem']; - } - } - - return false; - } - /** * @brief * From 11310f4cf0eb66206ba758e178a892345028bf15 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Sep 2018 18:16:14 +0000 Subject: [PATCH 34/97] Relocated AP signature functions, reduced magic auth functions --- src/Module/Inbox.php | 3 +- src/Module/Magic.php | 6 +- src/Module/Owa.php | 2 +- src/Protocol/ActivityPub.php | 196 +---------------------- src/Util/HTTPSignature.php | 291 +++++++++++++++++++++-------------- src/Worker/APDelivery.php | 3 +- 6 files changed, 192 insertions(+), 309 deletions(-) diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index d47419a415..49df14762e 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -8,6 +8,7 @@ use Friendica\BaseModule; use Friendica\Protocol\ActivityPub; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\Util\HTTPSignature; /** * ActivityPub Inbox @@ -24,7 +25,7 @@ class Inbox extends BaseModule System::httpExit(400); } - if (ActivityPub::verifySignature($postdata, $_SERVER)) { + if (HTTPSignature::verifyAP($postdata, $_SERVER)) { $filename = 'signed-activitypub'; } else { $filename = 'failed-activitypub'; diff --git a/src/Module/Magic.php b/src/Module/Magic.php index cf77482e5a..0b4126e0e9 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -76,13 +76,9 @@ class Magic extends BaseModule // Create a header that is signed with the local users private key. $headers = HTTPSignature::createSig( - '', $headers, $user['prvkey'], - 'acct:' . $user['nickname'] . '@' . $a->get_hostname() . ($a->urlpath ? '/' . $a->urlpath : ''), - false, - true, - 'sha512' + 'acct:' . $user['nickname'] . '@' . $a->get_hostname() . ($a->urlpath ? '/' . $a->urlpath : '') ); // Try to get an authentication token from the other instance. diff --git a/src/Module/Owa.php b/src/Module/Owa.php index 1d6b1332dc..68f31c59de 100644 --- a/src/Module/Owa.php +++ b/src/Module/Owa.php @@ -54,7 +54,7 @@ class Owa extends BaseModule if (DBA::isResult($contact)) { // Try to verify the signed header with the public key of the contact record // we have found. - $verified = HTTPSignature::verify('', $contact['pubkey']); + $verified = HTTPSignature:verifyMagic($contact['pubkey']); if ($verified && $verified['header_signed'] && $verified['header_valid']) { logger('OWA header: ' . print_r($verified, true), LOGGER_DATA); diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 25ebedc8bd..d952f4de8f 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -63,38 +63,6 @@ class ActivityPub stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/ld+json'); } - public static function transmit($data, $target, $uid) - { - $owner = User::getOwnerDataById($uid); - - if (!$owner) { - return; - } - - $content = json_encode($data); - - // Header data that is about to be signed. - $host = parse_url($target, PHP_URL_HOST); - $path = parse_url($target, PHP_URL_PATH); - $digest = 'SHA-256=' . base64_encode(hash('sha256', $content, true)); - $content_length = strlen($content); - - $headers = ['Content-Length: ' . $content_length, 'Digest: ' . $digest, 'Host: ' . $host]; - - $signed_data = "(request-target): post " . $path . "\ncontent-length: " . $content_length . "\ndigest: " . $digest . "\nhost: " . $host; - - $signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256')); - - $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) content-length digest host",signature="' . $signature . '"'; - - $headers[] = 'Content-Type: application/activity+json'; - - Network::post($target, $content, $headers); - $return_code = BaseObject::getApp()->get_curl_code(); - - logger('Transmit to ' . $target . ' returned ' . $return_code); - } - /** * Return the ActivityPub profile of the given user * @@ -401,7 +369,7 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG); - return self::transmit($data, $profile['inbox'], $uid); + return HTTPSignature::transmit($data, $profile['inbox'], $uid); } public static function transmitContactAccept($target, $id, $uid) @@ -419,7 +387,7 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); - return self::transmit($data, $profile['inbox'], $uid); + return HTTPSignature::transmit($data, $profile['inbox'], $uid); } public static function transmitContactReject($target, $id, $uid) @@ -437,7 +405,7 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); - return self::transmit($data, $profile['inbox'], $uid); + return HTTPSignature::transmit($data, $profile['inbox'], $uid); } public static function transmitContactUndo($target, $uid) @@ -457,7 +425,7 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); - return self::transmit($data, $profile['inbox'], $uid); + return HTTPSignature::transmit($data, $profile['inbox'], $uid); } /** @@ -515,154 +483,6 @@ class ActivityPub return false; } - public static function verifySignature($content, $http_headers) - { - $object = json_decode($content, true); - - if (empty($object)) { - return false; - } - - $actor = JsonLD::fetchElement($object, 'actor', 'id'); - - $headers = []; - $headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . $http_headers['REQUEST_URI']; - - // First take every header - foreach ($http_headers as $k => $v) { - $field = str_replace('_', '-', strtolower($k)); - $headers[$field] = $v; - } - - // Now add every http header - foreach ($http_headers as $k => $v) { - if (strpos($k, 'HTTP_') === 0) { - $field = str_replace('_', '-', strtolower(substr($k, 5))); - $headers[$field] = $v; - } - } - - $sig_block = ActivityPub::parseSigHeader($http_headers['HTTP_SIGNATURE']); - - if (empty($sig_block) || empty($sig_block['headers']) || empty($sig_block['keyId'])) { - return false; - } - - $signed_data = ''; - foreach ($sig_block['headers'] as $h) { - if (array_key_exists($h, $headers)) { - $signed_data .= $h . ': ' . $headers[$h] . "\n"; - } - } - $signed_data = rtrim($signed_data, "\n"); - - if (empty($signed_data)) { - return false; - } - - $algorithm = null; - - if ($sig_block['algorithm'] === 'rsa-sha256') { - $algorithm = 'sha256'; - } - - if ($sig_block['algorithm'] === 'rsa-sha512') { - $algorithm = 'sha512'; - } - - if (empty($algorithm)) { - return false; - } - - $key = self::fetchKey($sig_block['keyId'], $actor); - - if (empty($key)) { - return false; - } - - if (!Crypto::rsaVerify($signed_data, $sig_block['signature'], $key, $algorithm)) { - return false; - } - - // Check the digest when it is part of the signed data - if (in_array('digest', $sig_block['headers'])) { - $digest = explode('=', $headers['digest'], 2); - if ($digest[0] === 'SHA-256') { - $hashalg = 'sha256'; - } - if ($digest[0] === 'SHA-512') { - $hashalg = 'sha512'; - } - - /// @todo add all hashes from the rfc - - if (!empty($hashalg) && base64_encode(hash($hashalg, $content, true)) != $digest[1]) { - return false; - } - } - - // Check the content-length when it is part of the signed data - if (in_array('content-length', $sig_block['headers'])) { - if (strlen($content) != $headers['content-length']) { - return false; - } - } - - return true; - - } - - private static function fetchKey($id, $actor) - { - $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id); - - $profile = self::fetchprofile($url); - if (!empty($profile)) { - return $profile['pubkey']; - } elseif ($url != $actor) { - $profile = self::fetchprofile($actor); - if (!empty($profile)) { - return $profile['pubkey']; - } - } - - return false; - } - - /** - * @brief - * - * @param string $header - * @return array associate array with - * - \e string \b keyID - * - \e string \b algorithm - * - \e array \b headers - * - \e string \b signature - */ - private static function parseSigHeader($header) - { - $ret = []; - $matches = []; - - if (preg_match('/keyId="(.*?)"/ism',$header,$matches)) { - $ret['keyId'] = $matches[1]; - } - - if (preg_match('/algorithm="(.*?)"/ism',$header,$matches)) { - $ret['algorithm'] = $matches[1]; - } - - if (preg_match('/headers="(.*?)"/ism',$header,$matches)) { - $ret['headers'] = explode(' ', $matches[1]); - } - - if (preg_match('/signature="(.*?)"/ism',$header,$matches)) { - $ret['signature'] = base64_decode(preg_replace('/\s+/','',$matches[1])); - } - - return $ret; - } - public static function fetchprofile($url, $update = false) { if (empty($url)) { @@ -798,7 +618,7 @@ class ActivityPub { logger('Incoming message for user ' . $uid, LOGGER_DEBUG); - if (!self::verifySignature($body, $header)) { + if (!HTTPSignature::verifyAP($body, $header)) { logger('Invalid signature, message will be discarded.', LOGGER_DEBUG); return; } @@ -813,7 +633,7 @@ class ActivityPub self::processActivity($activity, $body, $uid); } - public static function fetchOutbox($url) + public static function fetchOutbox($url, $uid) { $data = self::fetchContent($url); if (empty($data)) { @@ -825,14 +645,14 @@ class ActivityPub } elseif (!empty($data['first']['orderedItems'])) { $items = $data['first']['orderedItems']; } elseif (!empty($data['first'])) { - self::fetchOutbox($data['first']); + self::fetchOutbox($data['first'], $uid); return; } else { $items = []; } foreach ($items as $activity) { - self::processActivity($activity); + self::processActivity($activity, '', $uid); } } diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index adf5d8ad27..f6a5fe1fe4 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -5,8 +5,11 @@ */ namespace Friendica\Util; +use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Database\DBA; +use Friendica\Model\User; +use Friendica\Protocol\ActivityPub; /** * @brief Implements HTTP Signatures per draft-cavage-http-signatures-07. @@ -19,56 +22,36 @@ use Friendica\Database\DBA; class HTTPSignature { // See draft-cavage-http-signatures-08 - public static function verify($data, $key = '') + public static function verifyMagic($key) { - $body = $data; $headers = null; $spoofable = false; $result = [ 'signer' => '', 'header_signed' => false, - 'header_valid' => false, - 'content_signed' => false, - 'content_valid' => false + 'header_valid' => false ]; // Decide if $data arrived via controller submission or curl. - if (is_array($data) && $data['header']) { - if (!$data['success']) { - return $result; - } + $headers = []; + $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']).' '.$_SERVER['REQUEST_URI']; - $h = new HTTPHeaders($data['header']); - $headers = $h->fetch(); - $body = $data['body']; - } else { - $headers = []; - $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']).' '.$_SERVER['REQUEST_URI']; - - foreach ($_SERVER as $k => $v) { - if (strpos($k, 'HTTP_') === 0) { - $field = str_replace('_', '-', strtolower(substr($k, 5))); - $headers[$field] = $v; - } + foreach ($_SERVER as $k => $v) { + if (strpos($k, 'HTTP_') === 0) { + $field = str_replace('_', '-', strtolower(substr($k, 5))); + $headers[$field] = $v; } } $sig_block = null; - if (array_key_exists('signature', $headers)) { - $sig_block = self::parseSigheader($headers['signature']); - } elseif (array_key_exists('authorization', $headers)) { - $sig_block = self::parseSigheader($headers['authorization']); - } + $sig_block = self::parseSigheader($headers['authorization']); if (!$sig_block) { logger('no signature provided.'); return $result; } - // Warning: This log statement includes binary data - // logger('sig_block: ' . print_r($sig_block,true), LOGGER_DATA); - $result['header_signed'] = true; $signed_headers = $sig_block['headers']; @@ -88,13 +71,7 @@ class HTTPSignature $signed_data = rtrim($signed_data, "\n"); - $algorithm = null; - if ($sig_block['algorithm'] === 'rsa-sha256') { - $algorithm = 'sha256'; - } - if ($sig_block['algorithm'] === 'rsa-sha512') { - $algorithm = 'sha512'; - } + $algorithm = 'sha512'; if ($key && function_exists($key)) { $result['signer'] = $sig_block['keyId']; @@ -119,93 +96,39 @@ class HTTPSignature $result['header_valid'] = true; } - if (in_array('digest', $signed_headers)) { - $result['content_signed'] = true; - $digest = explode('=', $headers['digest']); - - if ($digest[0] === 'SHA-256') { - $hashalg = 'sha256'; - } - if ($digest[0] === 'SHA-512') { - $hashalg = 'sha512'; - } - - // The explode operation will have stripped the '=' padding, so compare against unpadded base64. - if (rtrim(base64_encode(hash($hashalg, $body, true)), '=') === $digest[1]) { - $result['content_valid'] = true; - } - } - - logger('Content_Valid: ' . $result['content_valid']); - return $result; } /** * @brief * - * @param string $request * @param array $head * @param string $prvkey * @param string $keyid (optional, default 'Key') - * @param boolean $send_headers (optional, default false) - * If set send a HTTP header - * @param boolean $auth (optional, default false) - * @param string $alg (optional, default 'sha256') - * @param string $crypt_key (optional, default null) - * @param string $crypt_algo (optional, default 'aes256ctr') * * @return array */ - public static function createSig($request, $head, $prvkey, $keyid = 'Key', $send_headers = false, $auth = false, $alg = 'sha256', $crypt_key = null, $crypt_algo = 'aes256ctr') + public static function createSig($head, $prvkey, $keyid = 'Key') { $return_headers = []; - if ($alg === 'sha256') { - $algorithm = 'rsa-sha256'; - } + $alg = 'sha512'; + $algorithm = 'rsa-sha512'; - if ($alg === 'sha512') { - $algorithm = 'rsa-sha512'; - } - - $x = self::sign($request, $head, $prvkey, $alg); + $x = self::sign($head, $prvkey, $alg); $headerval = 'keyId="' . $keyid . '",algorithm="' . $algorithm . '",headers="' . $x['headers'] . '",signature="' . $x['signature'] . '"'; - if ($crypt_key) { - $x = Crypto::encapsulate($headerval, $crypt_key, $crypt_algo); - $headerval = 'iv="' . $x['iv'] . '",key="' . $x['key'] . '",alg="' . $x['alg'] . '",data="' . $x['data'] . '"'; - } - - if ($auth) { - $sighead = 'Authorization: Signature ' . $headerval; - } else { - $sighead = 'Signature: ' . $headerval; - } + $sighead = 'Authorization: Signature ' . $headerval; if ($head) { foreach ($head as $k => $v) { - if ($send_headers) { - // This is for ActivityPub implementation. - // Since the Activity Pub implementation isn't - // ready at the moment, we comment it out. - // header($k . ': ' . $v); - } else { - $return_headers[] = $k . ': ' . $v; - } + $return_headers[] = $k . ': ' . $v; } } - if ($send_headers) { - // This is for ActivityPub implementation. - // Since the Activity Pub implementation isn't - // ready at the moment, we comment it out. - // header($sighead); - } else { - $return_headers[] = $sighead; - } + $return_headers[] = $sighead; return $return_headers; } @@ -213,35 +136,27 @@ class HTTPSignature /** * @brief * - * @param string $request * @param array $head * @param string $prvkey * @param string $alg (optional) default 'sha256' * * @return array */ - private static function sign($request, $head, $prvkey, $alg = 'sha256') + private static function sign($head, $prvkey, $alg = 'sha256') { $ret = []; $headers = ''; $fields = ''; - if ($request) { - $headers = '(request-target)' . ': ' . trim($request) . "\n"; - $fields = '(request-target)'; - } - - if ($head) { - foreach ($head as $k => $v) { - $headers .= strtolower($k) . ': ' . trim($v) . "\n"; - if ($fields) { - $fields .= ' '; - } - $fields .= strtolower($k); + foreach ($head as $k => $v) { + $headers .= strtolower($k) . ': ' . trim($v) . "\n"; + if ($fields) { + $fields .= ' '; } - // strip the trailing linefeed - $headers = rtrim($headers, "\n"); + $fields .= strtolower($k); } + // strip the trailing linefeed + $headers = rtrim($headers, "\n"); $sig = base64_encode(Crypto::rsaSign($headers, $prvkey, $alg)); @@ -338,4 +253,154 @@ class HTTPSignature return ''; } + + /** + * Functions for ActivityPub + */ + + public static function transmit($data, $target, $uid) + { + $owner = User::getOwnerDataById($uid); + + if (!$owner) { + return; + } + + $content = json_encode($data); + + // Header data that is about to be signed. + $host = parse_url($target, PHP_URL_HOST); + $path = parse_url($target, PHP_URL_PATH); + $digest = 'SHA-256=' . base64_encode(hash('sha256', $content, true)); + $content_length = strlen($content); + + $headers = ['Content-Length: ' . $content_length, 'Digest: ' . $digest, 'Host: ' . $host]; + + $signed_data = "(request-target): post " . $path . "\ncontent-length: " . $content_length . "\ndigest: " . $digest . "\nhost: " . $host; + + $signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256')); + + $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",algorithm="rsa-sha256",headers="(request-target) content-length digest host",signature="' . $signature . '"'; + + $headers[] = 'Content-Type: application/activity+json'; + + Network::post($target, $content, $headers); + $return_code = BaseObject::getApp()->get_curl_code(); + + logger('Transmit to ' . $target . ' returned ' . $return_code); + } + + public static function verifyAP($content, $http_headers) + { + $object = json_decode($content, true); + + if (empty($object)) { + return false; + } + + $actor = JsonLD::fetchElement($object, 'actor', 'id'); + + $headers = []; + $headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . $http_headers['REQUEST_URI']; + + // First take every header + foreach ($http_headers as $k => $v) { + $field = str_replace('_', '-', strtolower($k)); + $headers[$field] = $v; + } + + // Now add every http header + foreach ($http_headers as $k => $v) { + if (strpos($k, 'HTTP_') === 0) { + $field = str_replace('_', '-', strtolower(substr($k, 5))); + $headers[$field] = $v; + } + } + + $sig_block = self::parseSigHeader($http_headers['HTTP_SIGNATURE']); + + if (empty($sig_block) || empty($sig_block['headers']) || empty($sig_block['keyId'])) { + return false; + } + + $signed_data = ''; + foreach ($sig_block['headers'] as $h) { + if (array_key_exists($h, $headers)) { + $signed_data .= $h . ': ' . $headers[$h] . "\n"; + } + } + $signed_data = rtrim($signed_data, "\n"); + + if (empty($signed_data)) { + return false; + } + + $algorithm = null; + + if ($sig_block['algorithm'] === 'rsa-sha256') { + $algorithm = 'sha256'; + } + + if ($sig_block['algorithm'] === 'rsa-sha512') { + $algorithm = 'sha512'; + } + + if (empty($algorithm)) { + return false; + } + + $key = self::fetchKey($sig_block['keyId'], $actor); + + if (empty($key)) { + return false; + } + + if (!Crypto::rsaVerify($signed_data, $sig_block['signature'], $key, $algorithm)) { + return false; + } + + // Check the digest when it is part of the signed data + if (in_array('digest', $sig_block['headers'])) { + $digest = explode('=', $headers['digest'], 2); + if ($digest[0] === 'SHA-256') { + $hashalg = 'sha256'; + } + if ($digest[0] === 'SHA-512') { + $hashalg = 'sha512'; + } + + /// @todo add all hashes from the rfc + + if (!empty($hashalg) && base64_encode(hash($hashalg, $content, true)) != $digest[1]) { + return false; + } + } + + // Check the content-length when it is part of the signed data + if (in_array('content-length', $sig_block['headers'])) { + if (strlen($content) != $headers['content-length']) { + return false; + } + } + + return true; + + } + + private static function fetchKey($id, $actor) + { + $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id); + + $profile = ActivityPub::fetchprofile($url); + if (!empty($profile)) { + return $profile['pubkey']; + } elseif ($url != $actor) { + $profile = ActivityPub::fetchprofile($actor); + if (!empty($profile)) { + return $profile['pubkey']; + } + } + + return false; + } } diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index b7e881c7a3..f43c56a3ec 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -7,6 +7,7 @@ namespace Friendica\Worker; use Friendica\BaseObject; use Friendica\Protocol\ActivityPub; use Friendica\Model\Item; +use Friendica\Util\HTTPSignature; class APDelivery extends BaseObject { @@ -20,7 +21,7 @@ class APDelivery extends BaseObject } else { $item = Item::selectFirst(['uid'], ['id' => $item_id]); $data = ActivityPub::createActivityFromItem($item_id); - ActivityPub::transmit($data, $inbox, $item['uid']); + HTTPSignature::transmit($data, $inbox, $item['uid']); } return; From 752b5fe28464c7f1dec79132b6ef74ae71420d8b Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 20 Sep 2018 21:45:23 +0000 Subject: [PATCH 35/97] Outgoing posts are now signed --- src/Protocol/ActivityPub.php | 22 +++++++-- src/Util/LDSignature.php | 92 ++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 src/Util/LDSignature.php diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index d952f4de8f..6f5fdedc95 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -20,6 +20,7 @@ use Friendica\Util\Crypto; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Util\JsonLD; +use Friendica\Util\LDSignature; /** * @brief ActivityPub Protocol class @@ -273,7 +274,10 @@ class ActivityPub $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); $data['object'] = self::createNote($item); - return $data; + + $owner = User::getOwnerDataById($item['uid']); + + return LDSignature::sign($data, $owner); } public static function createObjectFromItemID($item_id) @@ -369,7 +373,9 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG); - return HTTPSignature::transmit($data, $profile['inbox'], $uid); + + $signed = LDSignature::sign($data, $owner); + return HTTPSignature::transmit($signed, $profile['inbox'], $uid); } public static function transmitContactAccept($target, $id, $uid) @@ -387,7 +393,9 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); - return HTTPSignature::transmit($data, $profile['inbox'], $uid); + + $signed = LDSignature::sign($data, $owner); + return HTTPSignature::transmit($signed, $profile['inbox'], $uid); } public static function transmitContactReject($target, $id, $uid) @@ -405,7 +413,9 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); - return HTTPSignature::transmit($data, $profile['inbox'], $uid); + + $signed = LDSignature::sign($data, $owner); + return HTTPSignature::transmit($signed, $profile['inbox'], $uid); } public static function transmitContactUndo($target, $uid) @@ -425,7 +435,9 @@ class ActivityPub 'to' => $profile['url']]; logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); - return HTTPSignature::transmit($data, $profile['inbox'], $uid); + + $signed = LDSignature::sign($data, $owner); + return HTTPSignature::transmit($signed, $profile['inbox'], $uid); } /** diff --git a/src/Util/LDSignature.php b/src/Util/LDSignature.php new file mode 100644 index 0000000000..7288b584c7 --- /dev/null +++ b/src/Util/LDSignature.php @@ -0,0 +1,92 @@ + 'RsaSignature2017', + 'nonce' => random_string(64), + 'creator' => $owner['url'] . '#main-key', + 'created' => DateTimeFormat::utcNow() + ]; + + $ohash = self::hash(self::signable_options($options)); + $dhash = self::hash(self::signable_data($data)); + $options['signatureValue'] = base64_encode(Crypto::rsaSign($ohash . $dhash, $owner['uprvkey'])); + + return array_merge($data, ['signature' => $options]); + } + + + private static function signable_data($data) + { + $newdata = []; + if (!empty($data)) { + foreach ($data as $k => $v) { + if (!in_array($k, ['signature'])) { + $newdata[$k] = $v; + } + } + } + return $newdata; + } + + + private static function signable_options($options) + { + $newopts = ['@context' => 'https://w3id.org/identity/v1']; + if (!empty($options)) { + foreach ($options as $k => $v) { + if (!in_array($k, ['type','id','signatureValue'])) { + $newopts[$k] = $v; + } + } + } + return $newopts; + } + + private static function hash($obj) + { + return hash('sha256', JsonLD::normalize($obj)); + } +} From 355346298bc99c97fa98157701c3fe7ef4905e5c Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Sep 2018 03:39:32 +0000 Subject: [PATCH 36/97] LD signatures will now be checked when receiving messages --- src/Protocol/ActivityPub.php | 23 +++++++++++++++++++---- src/Util/HTTPSignature.php | 2 ++ src/Util/LDSignature.php | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 6f5fdedc95..c064ffa396 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -688,7 +688,22 @@ class ActivityPub logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG); - $public = in_array(0, $receivers); + $unsigned = true; + + if (LDSignature::isSigned($activity)) { + if (!LDSignature::isVerified($activity)) { + logger('Invalid signature. Quitting here.', LOGGER_DEBUG); + return []; + } + logger('Valid signature.', LOGGER_DEBUG); + $unsigned = false; + } elseif (!in_array(0, $receivers)) { + /// @todo Add some checks to only accept unsigned private posts directly from the actor + $unsigned = false; + logger('Private post without signature.', LOGGER_DEBUG); + } else { + logger('Public post without signature. Object data will be fetched.', LOGGER_DEBUG); + } if (is_string($activity['object'])) { $object_url = $activity['object']; @@ -701,7 +716,7 @@ class ActivityPub // Fetch the content only on activities where this matters if (in_array($activity['type'], ['Create', 'Update', 'Announce'])) { - $object_data = self::fetchObject($object_url, $activity['object']); + $object_data = self::fetchObject($object_url, $activity['object'], $unsigned); if (empty($object_data)) { logger("Object data couldn't be processed", LOGGER_DEBUG); return []; @@ -896,9 +911,9 @@ class ActivityPub return $object_data; } - private static function fetchObject($object_url, $object = [], $public = true) + private static function fetchObject($object_url, $object = [], $unsigned = true) { - if ($public) { + if ($unsigned) { $data = self::fetchContent($object_url); if (empty($data)) { logger('Empty content for ' . $object_url . ', check if content is available locally.', LOGGER_DEBUG); diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index f6a5fe1fe4..2d8254eeb8 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -393,10 +393,12 @@ class HTTPSignature $profile = ActivityPub::fetchprofile($url); if (!empty($profile)) { + logger('Taking key from id ' . $id, LOGGER_DEBUG); return $profile['pubkey']; } elseif ($url != $actor) { $profile = ActivityPub::fetchprofile($actor); if (!empty($profile)) { + logger('Taking key from actor ' . $actor, LOGGER_DEBUG); return $profile['pubkey']; } } diff --git a/src/Util/LDSignature.php b/src/Util/LDSignature.php index 7288b584c7..a52d84e478 100644 --- a/src/Util/LDSignature.php +++ b/src/Util/LDSignature.php @@ -20,6 +20,24 @@ class LDSignature } if (empty($pubkey)) { +/* + $creator = $data['signature']['creator']; + $actor = JsonLD::fetchElement($data, 'actor', 'id'); + + $url = (strpos($creator, '#') ? substr($creator, 0, strpos($creator, '#')) : $creator); + + $profile = ActivityPub::fetchprofile($url); + if (!empty($profile)) { + logger('Taking key from creator ' . $creator, LOGGER_DEBUG); + } elseif ($url != $actor) { + $profile = ActivityPub::fetchprofile($actor); + if (empty($profile)) { + return false; + } + logger('Taking key from actor ' . $actor, LOGGER_DEBUG); + } + +*/ $actor = JsonLD::fetchElement($data, 'actor', 'id'); if (empty($actor)) { return false; From 5310d54c130d0fabd952250b5fd924b567578c6d Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Sep 2018 04:51:54 +0000 Subject: [PATCH 37/97] Fetch the receiver from the parent posting as well --- src/Protocol/ActivityPub.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index c064ffa396..edc3de3f3b 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -829,6 +829,15 @@ class ActivityPub { $receivers = []; + // When it is an answer, we inherite the receivers from the parent + $replyto = JsonLD::fetchElement($activity, 'inReplyTo', 'id'); + if (!empty($replyto)) { + $parents = Item::select(['uid'], ['uri' => $replyto]); + while ($parent = Item::fetch($parents)) { + $receivers['uid:' . $parent['uid']] = $parent['uid']; + } + } + if (!empty($actor)) { $profile = self::fetchprofile($actor); $followers = defaults($profile, 'followers', ''); @@ -1211,6 +1220,7 @@ class ActivityPub $activity['object'] = $object; $activity['published'] = $object['published']; $activity['type'] = 'Create'; + self::processActivity($activity); logger('Activity ' . $url . ' had been fetched and processed.'); } From 59cd6611ec3b28fc48f6a0faca9bf31367b4ae72 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Sep 2018 05:41:18 +0000 Subject: [PATCH 38/97] Direkt delivery is done --- src/Worker/Notifier.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 693a9e343d..3e73b5b5ed 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -414,7 +414,25 @@ class Notifier } } - $inboxes = ActivityPub::fetchTargetInboxes($target_item); + $inboxes = []; + + if ($followup) { + $profile = ActivityPub::fetchprofile($parent['author-link']); + if (!empty($profile)) { + $target = defaults($profile, 'sharedinbox', $profile['inbox']); + $inboxes[$target] = $target; + } + } else { + if ($target_item['origin']) { + $inboxes = ActivityPub::fetchTargetInboxes($target_item); + } + + if ($parent['origin']) { + $parent_inboxes = ActivityPub::fetchTargetInboxes($parent); + $inboxes = array_merge($inboxes, $parent_inboxes); + } + } + foreach ($inboxes as $inbox) { logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); From 4c224fbddd47bb0e5d6c6b03eb68c79ae848568f Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Sep 2018 12:06:36 +0000 Subject: [PATCH 39/97] Deliver everything to all receivers in the thread --- src/Protocol/ActivityPub.php | 29 ++++++++++++++++++++++------- src/Worker/Notifier.php | 20 ++++++-------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index edc3de3f3b..ad4308cbb6 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -46,13 +46,13 @@ use Friendica\Util\LDSignature; * - Object Types: Person, Tombstome * * Transmitter: - * - Activities: Like, Dislike, Update, Delete - * - Object Tyoes: Article, Announce, Person, Tombstone + * - Activities: Like, Dislike, Update, Delete, Announce + * - Object Tyoes: Article, Person, Tombstone * * General: - * - Message distribution - * - Endpoints: Outbox, Object, Follower, Following + * - Endpoints: Outbox, Follower, Following * - General cleanup + * - Queueing unsucessful deliveries */ class ActivityPub { @@ -172,13 +172,28 @@ class ActivityPub return $data; } - public static function fetchTargetInboxes($item) + public static function fetchTargetInboxes($item, $uid) { $inboxes = []; + $parents = Item::select(['author-link', 'owner-link'], ['parent' => $item['parent']]); + while ($parent = Item::fetch($parents)) { + $profile = self::fetchprofile($parent['author-link']); + if (!empty($profile)) { + $target = defaults($profile, 'sharedinbox', $profile['inbox']); + $inboxes[$target] = $target; + } + $profile = self::fetchprofile($parent['owner-link']); + if (!empty($profile)) { + $target = defaults($profile, 'sharedinbox', $profile['inbox']); + $inboxes[$target] = $target; + } + } + DBA::close($parents); + $terms = Term::tagArrayFromItemId($item['id']); if (!$item['private']) { - $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $item['uid'], + $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid, 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB]); while ($contact = DBA::fetch($contacts)) { $contact = defaults($contact, 'batch', $contact['notify']); @@ -205,7 +220,7 @@ class ActivityPub if ($term['type'] != TERM_MENTION) { continue; } - $cid = Contact::getIdForURL($term['url'], $item['uid']); + $cid = Contact::getIdForURL($term['url'], $uid); if (!empty($cid) && in_array($cid, $receiver_list)) { $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); $profile = self::fetchprofile($contact['url']); diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 3e73b5b5ed..286bcd03ee 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -416,21 +416,13 @@ class Notifier $inboxes = []; - if ($followup) { - $profile = ActivityPub::fetchprofile($parent['author-link']); - if (!empty($profile)) { - $target = defaults($profile, 'sharedinbox', $profile['inbox']); - $inboxes[$target] = $target; - } - } else { - if ($target_item['origin']) { - $inboxes = ActivityPub::fetchTargetInboxes($target_item); - } + if ($target_item['origin']) { + $inboxes = ActivityPub::fetchTargetInboxes($target_item, $uid); + } - if ($parent['origin']) { - $parent_inboxes = ActivityPub::fetchTargetInboxes($parent); - $inboxes = array_merge($inboxes, $parent_inboxes); - } + if ($parent['origin']) { + $parent_inboxes = ActivityPub::fetchTargetInboxes($parent, $uid); + $inboxes = array_merge($inboxes, $parent_inboxes); } foreach ($inboxes as $inbox) { From b44fc62708f111449f9ead95c09d4570465c94b7 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Sep 2018 22:31:33 +0000 Subject: [PATCH 40/97] Improvements to signature check, private posts do work now again --- src/Module/Inbox.php | 4 +- src/Protocol/ActivityPub.php | 158 ++++++++++++++++++++++++----------- src/Util/HTTPSignature.php | 13 ++- src/Util/JsonLD.php | 21 ++++- src/Util/LDSignature.php | 67 +++++++-------- 5 files changed, 166 insertions(+), 97 deletions(-) diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 49df14762e..891211186a 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -25,14 +25,14 @@ class Inbox extends BaseModule System::httpExit(400); } - if (HTTPSignature::verifyAP($postdata, $_SERVER)) { + if (HTTPSignature::getSigner($postdata, $_SERVER)) { $filename = 'signed-activitypub'; } else { $filename = 'failed-activitypub'; } $tempfile = tempnam(get_temppath(), $filename); - file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata])); + file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); logger('Incoming message stored under ' . $tempfile); diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index ad4308cbb6..b27101aac8 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -122,10 +122,49 @@ class ActivityPub return $data; } + public static function fetchPermissionBlockFromConversation($item) + { + if (empty($item['thr-parent'])) { + return []; + } + + $condition = ['item-uri' => $item['thr-parent'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB]; + $conversation = DBA::selectFirst('conversation', ['source'], $condition); + if (!DBA::isResult($conversation)) { + return []; + } + + $activity = json_decode($conversation['source'], true); + + $actor = JsonLD::fetchElement($activity, 'actor', 'id'); + $profile = ActivityPub::fetchprofile($actor); + + $permissions = []; + + $elements = ['to', 'cc', 'bto', 'bcc']; + foreach ($elements as $element) { + if (empty($activity[$element])) { + continue; + } + if (is_string($activity[$element])) { + $activity[$element] = [$activity[$element]]; + } + foreach ($activity[$element] as $receiver) { + if ($receiver == $profile['followers']) { + $receiver = System::baseUrl() . '/followers/' . $item['author-nick']; + } + $permissions[$element][] = $receiver; + } + } + return $permissions; + } + public static function createPermissionBlockForItem($item) { $data = ['to' => [], 'cc' => []]; + $data = array_merge($data, self::fetchPermissionBlockFromConversation($item)); + $terms = Term::tagArrayFromItemId($item['id']); if (!$item['private']) { @@ -146,6 +185,7 @@ class ActivityPub $receiver_list = Item::enumeratePermissions($item); $mentioned = []; + $contacts = []; foreach ($terms as $term) { if ($term['type'] != TERM_MENTION) { @@ -155,12 +195,16 @@ class ActivityPub if (!empty($cid) && in_array($cid, $receiver_list)) { $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); $data['to'][] = $contact['url']; + $contacts[$contact['url']] = $contact['url']; } } foreach ($receiver_list as $receiver) { $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]); - $data['cc'][] = $contact['url']; + if (empty($contacts[$contact['url']])) { + $data['cc'][] = $contact['url']; + $contacts[$contact['url']] = $contact['url']; + } } if (empty($data['to'])) { @@ -213,7 +257,6 @@ class ActivityPub } } else { $receiver_list = Item::enumeratePermissions($item); - $mentioned = []; foreach ($terms as $term) { @@ -224,7 +267,7 @@ class ActivityPub if (!empty($cid) && in_array($cid, $receiver_list)) { $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); $profile = self::fetchprofile($contact['url']); - if (!empty($profile['network'])) { + if (!empty($profile)) { $target = defaults($profile, 'sharedinbox', $profile['inbox']); $inboxes[$target] = $target; } @@ -234,7 +277,7 @@ class ActivityPub foreach ($receiver_list as $receiver) { $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]); $profile = self::fetchprofile($contact['url']); - if (!empty($profile['network'])) { + if (!empty($profile)) { $target = defaults($profile, 'sharedinbox', $profile['inbox']); $inboxes[$target] = $target; } @@ -276,8 +319,8 @@ class ActivityPub 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; - $data['type'] = 'Create'; $data['id'] = $item['uri'] . '#activity'; + $data['type'] = 'Create'; $data['actor'] = $item['author-link']; $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); @@ -339,13 +382,27 @@ class ActivityPub public static function createNote($item) { $data = []; - $data['type'] = 'Note'; $data['id'] = $item['uri']; + $data['type'] = 'Note'; + $data['summary'] = null; // Ignore by now if ($item['uri'] != $item['thr-parent']) { $data['inReplyTo'] = $item['thr-parent']; + } else { + $data['inReplyTo'] = null; } + $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); + + if ($item["created"] != $item["edited"]) { + $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); + } + + $data['url'] = $item['uri']; + $data['attributedTo'] = $item['author-link']; + $data['actor'] = $item['author-link']; + $data['sensitive'] = false; // - Query NSFW + $conversation = DBA::selectFirst('conversation', ['conversation-uri'], ['item-uri' => $item['parent-uri']]); if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) { $conversation_uri = $conversation['conversation-uri']; @@ -353,24 +410,19 @@ class ActivityPub $conversation_uri = $item['parent-uri']; } - $data['context'] = $data['conversation'] = $conversation_uri; - $data['actor'] = $item['author-link']; - $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); - $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); + $data['conversation'] = $conversation_uri; - if ($item["created"] != $item["edited"]) { - $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); + if (!empty($item['title'])) { + $data['name'] = BBCode::convert($item['title'], false, 7); } - $data['attributedTo'] = $item['author-link']; - $data['name'] = BBCode::convert($item['title'], false, 7); $data['content'] = BBCode::convert($item['body'], false, 7); $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"]; - $data['summary'] = ''; // Ignore by now - $data['sensitive'] = false; // - Query NSFW - //$data['emoji'] = []; // Ignore by now - $data['tag'] = self::createTagList($item); $data['attachment'] = []; // @ToDo + $data['tag'] = self::createTagList($item); + $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); + + //$data['emoji'] = []; // Ignore by now return $data; } @@ -643,21 +695,45 @@ class ActivityPub public static function processInbox($body, $header, $uid) { - logger('Incoming message for user ' . $uid, LOGGER_DEBUG); - - if (!HTTPSignature::verifyAP($body, $header)) { - logger('Invalid signature, message will be discarded.', LOGGER_DEBUG); + $http_signer = HTTPSignature::getSigner($body, $header); + if (empty($http_signer)) { + logger('Invalid HTTP signature, message will be discarded.', LOGGER_DEBUG); return; + } else { + logger('HTTP signature is signed by ' . $http_signer, LOGGER_DEBUG); } $activity = json_decode($body, true); - if (!is_array($activity)) { + $actor = JsonLD::fetchElement($activity, 'actor', 'id'); + logger('Message for user ' . $uid . ' is from actor ' . $actor, LOGGER_DEBUG); + + if (empty($activity)) { logger('Invalid body.', LOGGER_DEBUG); return; } - self::processActivity($activity, $body, $uid); + if (LDSignature::isSigned($activity)) { + $ld_signer = LDSignature::getSigner($activity); + if (!empty($ld_signer)) { + logger('JSON-LD signature is signed by ' . $ld_signer, LOGGER_DEBUG); + $trust_source = true; + } elseif ($actor == $http_signer) { + logger('Bad JSON-LD signature, but HTTP signer fits the actor.', LOGGER_DEBUG); + $trust_source = true; + } else { + logger('Invalid JSON-LD signature.', LOGGER_DEBUG); + $trust_source = false; + } + } elseif ($actor == $http_signer) { + logger('Trusting post without JSON-LD signature, The actor fits the HTTP signer.', LOGGER_DEBUG); + $trust_source = true; + } else { + logger('No JSON-LD signature, different actor.', LOGGER_DEBUG); + $trust_source = false; + } + + self::processActivity($activity, $body, $uid, $trust_source); } public static function fetchOutbox($url, $uid) @@ -679,11 +755,11 @@ class ActivityPub } foreach ($items as $activity) { - self::processActivity($activity, '', $uid); + self::processActivity($activity, '', $uid, true); } } - private static function prepareObjectData($activity, $uid) + private static function prepareObjectData($activity, $uid, $trust_source) { $actor = JsonLD::fetchElement($activity, 'actor', 'id'); if (empty($actor)) { @@ -703,23 +779,6 @@ class ActivityPub logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG); - $unsigned = true; - - if (LDSignature::isSigned($activity)) { - if (!LDSignature::isVerified($activity)) { - logger('Invalid signature. Quitting here.', LOGGER_DEBUG); - return []; - } - logger('Valid signature.', LOGGER_DEBUG); - $unsigned = false; - } elseif (!in_array(0, $receivers)) { - /// @todo Add some checks to only accept unsigned private posts directly from the actor - $unsigned = false; - logger('Private post without signature.', LOGGER_DEBUG); - } else { - logger('Public post without signature. Object data will be fetched.', LOGGER_DEBUG); - } - if (is_string($activity['object'])) { $object_url = $activity['object']; } elseif (!empty($activity['object']['id'])) { @@ -731,7 +790,7 @@ class ActivityPub // Fetch the content only on activities where this matters if (in_array($activity['type'], ['Create', 'Update', 'Announce'])) { - $object_data = self::fetchObject($object_url, $activity['object'], $unsigned); + $object_data = self::fetchObject($object_url, $activity['object'], $trust_source); if (empty($object_data)) { logger("Object data couldn't be processed", LOGGER_DEBUG); return []; @@ -767,7 +826,7 @@ class ActivityPub return $object_data; } - private static function processActivity($activity, $body = '', $uid = null) + private static function processActivity($activity, $body = '', $uid = null, $trust_source = false) { if (empty($activity['type'])) { logger('Empty type', LOGGER_DEBUG); @@ -793,7 +852,7 @@ class ActivityPub logger('Processing activity: ' . $activity['type'], LOGGER_DEBUG); - $object_data = self::prepareObjectData($activity, $uid); + $object_data = self::prepareObjectData($activity, $uid, $trust_source); if (empty($object_data)) { logger('No object data found', LOGGER_DEBUG); return; @@ -935,14 +994,15 @@ class ActivityPub return $object_data; } - private static function fetchObject($object_url, $object = [], $unsigned = true) + private static function fetchObject($object_url, $object = [], $trust_source = false) { - if ($unsigned) { + if (!$trust_source || is_string($object)) { $data = self::fetchContent($object_url); if (empty($data)) { logger('Empty content for ' . $object_url . ', check if content is available locally.', LOGGER_DEBUG); $data = $object_url; - $data = $object; + } else { + logger('Fetched content for ' . $object_url, LOGGER_DEBUG); } } else { logger('Using original object for url ' . $object_url, LOGGER_DEBUG); diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 2d8254eeb8..8fa8566af3 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -266,7 +266,7 @@ class HTTPSignature return; } - $content = json_encode($data); + $content = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); // Header data that is about to be signed. $host = parse_url($target, PHP_URL_HOST); @@ -290,7 +290,7 @@ class HTTPSignature logger('Transmit to ' . $target . ' returned ' . $return_code); } - public static function verifyAP($content, $http_headers) + public static function getSigner($content, $http_headers) { $object = json_decode($content, true); @@ -355,7 +355,7 @@ class HTTPSignature return false; } - if (!Crypto::rsaVerify($signed_data, $sig_block['signature'], $key, $algorithm)) { + if (!Crypto::rsaVerify($signed_data, $sig_block['signature'], $key['pubkey'], $algorithm)) { return false; } @@ -383,8 +383,7 @@ class HTTPSignature } } - return true; - + return $key['url']; } private static function fetchKey($id, $actor) @@ -394,12 +393,12 @@ class HTTPSignature $profile = ActivityPub::fetchprofile($url); if (!empty($profile)) { logger('Taking key from id ' . $id, LOGGER_DEBUG); - return $profile['pubkey']; + return ['url' => $url, 'pubkey' => $profile['pubkey']]; } elseif ($url != $actor) { $profile = ActivityPub::fetchprofile($actor); if (!empty($profile)) { logger('Taking key from actor ' . $actor, LOGGER_DEBUG); - return $profile['pubkey']; + return ['url' => $actor, 'pubkey' => $profile['pubkey']]; } } diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 8fd9f90cb4..600896715a 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -40,11 +40,26 @@ class JsonLD return $data; } + private static function objectify($element) + { + if (is_array($element)) { + $keys = array_keys($element); + if (is_int(array_pop($keys))) { + return array_map('objectify', $element); + } else { + return (object)array_map('objectify', $element); + } + } else { + return $element; + } + } + public static function normalize($json) { jsonld_set_document_loader('Friendica\Util\JsonLD::documentLoader'); - $jsonobj = json_decode(json_encode($json)); +// $jsonobj = array_map('Friendica\Util\JsonLD::objectify', $json); + $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); return jsonld_normalize($jsonobj, array('algorithm' => 'URDNA2015', 'format' => 'application/nquads')); } @@ -59,11 +74,11 @@ class JsonLD 'vcard' => (object)['@id' => 'http://www.w3.org/2006/vcard/ns#', '@type' => '@id'], 'uuid' => (object)['@id' => 'http://schema.org/identifier', '@type' => '@id']]; - $jsonobj = json_decode(json_encode($json)); + $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); $compacted = jsonld_compact($jsonobj, $context); - return json_decode(json_encode($compacted), true); + return json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true); } public static function fetchElement($array, $element, $key, $type = null, $type_value = null) diff --git a/src/Util/LDSignature.php b/src/Util/LDSignature.php index a52d84e478..6db66a52a5 100644 --- a/src/Util/LDSignature.php +++ b/src/Util/LDSignature.php @@ -13,50 +13,52 @@ class LDSignature return !empty($data['signature']); } - public static function isVerified($data, $pubkey = null) + public static function getSigner($data) { if (!self::isSigned($data)) { return false; } - if (empty($pubkey)) { /* - $creator = $data['signature']['creator']; - $actor = JsonLD::fetchElement($data, 'actor', 'id'); + $creator = $data['signature']['creator']; + $actor = JsonLD::fetchElement($data, 'actor', 'id'); - $url = (strpos($creator, '#') ? substr($creator, 0, strpos($creator, '#')) : $creator); + $url = (strpos($creator, '#') ? substr($creator, 0, strpos($creator, '#')) : $creator); - $profile = ActivityPub::fetchprofile($url); - if (!empty($profile)) { - logger('Taking key from creator ' . $creator, LOGGER_DEBUG); - } elseif ($url != $actor) { - $profile = ActivityPub::fetchprofile($actor); - if (empty($profile)) { - return false; - } - logger('Taking key from actor ' . $actor, LOGGER_DEBUG); + $profile = ActivityPub::fetchprofile($url); + if (!empty($profile)) { + logger('Taking key from creator ' . $creator, LOGGER_DEBUG); + } elseif ($url != $actor) { + $profile = ActivityPub::fetchprofile($actor); + if (empty($profile)) { + return false; } + logger('Taking key from actor ' . $actor, LOGGER_DEBUG); + } */ - $actor = JsonLD::fetchElement($data, 'actor', 'id'); - if (empty($actor)) { - return false; - } - - $profile = ActivityPub::fetchprofile($actor); - if (empty($profile['pubkey'])) { - return false; - } - $pubkey = $profile['pubkey']; + $actor = JsonLD::fetchElement($data, 'actor', 'id'); + if (empty($actor)) { + return false; } + $profile = ActivityPub::fetchprofile($actor); + if (empty($profile['pubkey'])) { + return false; + } + $pubkey = $profile['pubkey']; + $ohash = self::hash(self::signable_options($data['signature'])); $dhash = self::hash(self::signable_data($data)); $x = Crypto::rsaVerify($ohash . $dhash, base64_decode($data['signature']['signatureValue']), $pubkey); logger('LD-verify: ' . intval($x)); - return $x; + if (empty($x)) { + return false; + } else { + return $actor; + } } public static function sign($data, $owner) @@ -65,7 +67,7 @@ class LDSignature 'type' => 'RsaSignature2017', 'nonce' => random_string(64), 'creator' => $owner['url'] . '#main-key', - 'created' => DateTimeFormat::utcNow() + 'created' => DateTimeFormat::utcNow(DateTimeFormat::ATOM) ]; $ohash = self::hash(self::signable_options($options)); @@ -78,15 +80,8 @@ class LDSignature private static function signable_data($data) { - $newdata = []; - if (!empty($data)) { - foreach ($data as $k => $v) { - if (!in_array($k, ['signature'])) { - $newdata[$k] = $v; - } - } - } - return $newdata; + unset($data['signature']); + return $data; } @@ -95,7 +90,7 @@ class LDSignature $newopts = ['@context' => 'https://w3id.org/identity/v1']; if (!empty($options)) { foreach ($options as $k => $v) { - if (!in_array($k, ['type','id','signatureValue'])) { + if (!in_array($k, ['type', 'id', 'signatureValue'])) { $newopts[$k] = $v; } } From b7744ae3eb07f7e8b9bd4e68d331ce053ffb689c Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 22 Sep 2018 04:39:04 +0000 Subject: [PATCH 41/97] Inherit the receivers from the previous post --- src/Protocol/ActivityPub.php | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index b27101aac8..7205f5ab92 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -122,7 +122,7 @@ class ActivityPub return $data; } - public static function fetchPermissionBlockFromConversation($item) + private static function fetchPermissionBlockFromConversation($item) { if (empty($item['thr-parent'])) { return []; @@ -216,9 +216,47 @@ class ActivityPub return $data; } + private static function fetchTargetInboxesFromConversation($item) + { + if (empty($item['thr-parent'])) { + return []; + } + + $condition = ['item-uri' => $item['thr-parent'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB]; + $conversation = DBA::selectFirst('conversation', ['source'], $condition); + if (!DBA::isResult($conversation)) { + return []; + } + + $activity = json_decode($conversation['source'], true); + + $actor = JsonLD::fetchElement($activity, 'actor', 'id'); + $profile = ActivityPub::fetchprofile($actor); + + $inboxes = []; + + $elements = ['to', 'cc', 'bto', 'bcc']; + foreach ($elements as $element) { + if (empty($activity[$element])) { + continue; + } + if (is_string($activity[$element])) { + $activity[$element] = [$activity[$element]]; + } + foreach ($activity[$element] as $receiver) { + $profile = self::fetchprofile($receiver); + if (!empty($profile)) { + $target = defaults($profile, 'sharedinbox', $profile['inbox']); + $inboxes[$target] = $target; + } + } + } + return $inboxes; + } + public static function fetchTargetInboxes($item, $uid) { - $inboxes = []; + $inboxes = self::fetchTargetInboxesFromConversation($item); $parents = Item::select(['author-link', 'owner-link'], ['parent' => $item['parent']]); while ($parent = Item::fetch($parents)) { From 71cbe562934edaeaf33d17831094c15a09e1613b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 22 Sep 2018 04:49:16 +0000 Subject: [PATCH 42/97] Use the follower collection --- src/Protocol/ActivityPub.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 7205f5ab92..2c288feb5d 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -216,7 +216,7 @@ class ActivityPub return $data; } - private static function fetchTargetInboxesFromConversation($item) + private static function fetchTargetInboxesFromConversation($item, $uid) { if (empty($item['thr-parent'])) { return []; @@ -244,10 +244,20 @@ class ActivityPub $activity[$element] = [$activity[$element]]; } foreach ($activity[$element] as $receiver) { - $profile = self::fetchprofile($receiver); - if (!empty($profile)) { - $target = defaults($profile, 'sharedinbox', $profile['inbox']); - $inboxes[$target] = $target; + if ($receiver == $profile['followers']) { + $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid, + 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB]); + while ($contact = DBA::fetch($contacts)) { + $contact = defaults($contact, 'batch', $contact['notify']); + $inboxes[$contact] = $contact; + } + DBA::close($contacts); + } else { + $profile = self::fetchprofile($receiver); + if (!empty($profile)) { + $target = defaults($profile, 'sharedinbox', $profile['inbox']); + $inboxes[$target] = $target; + } } } } @@ -256,7 +266,7 @@ class ActivityPub public static function fetchTargetInboxes($item, $uid) { - $inboxes = self::fetchTargetInboxesFromConversation($item); + $inboxes = self::fetchTargetInboxesFromConversation($item, $uid); $parents = Item::select(['author-link', 'owner-link'], ['parent' => $item['parent']]); while ($parent = Item::fetch($parents)) { From b906b083bc5becf28003372348f223f8a82cef14 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 22 Sep 2018 05:58:56 +0000 Subject: [PATCH 43/97] The target inbox is now generated after the permission bloxk --- src/Protocol/ActivityPub.php | 141 ++++++++++------------------------- 1 file changed, 41 insertions(+), 100 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 2c288feb5d..339312245e 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -139,6 +139,8 @@ class ActivityPub $actor = JsonLD::fetchElement($activity, 'actor', 'id'); $profile = ActivityPub::fetchprofile($actor); + $item_profile = ActivityPub::fetchprofile($item['owner-link']); + $permissions = []; $elements = ['to', 'cc', 'bto', 'bcc']; @@ -150,8 +152,8 @@ class ActivityPub $activity[$element] = [$activity[$element]]; } foreach ($activity[$element] as $receiver) { - if ($receiver == $profile['followers']) { - $receiver = System::baseUrl() . '/followers/' . $item['author-nick']; + if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) { + $receiver = $item_profile['followers']; } $permissions[$element][] = $receiver; } @@ -165,27 +167,32 @@ class ActivityPub $data = array_merge($data, self::fetchPermissionBlockFromConversation($item)); + $actor_profile = ActivityPub::fetchprofile($item['author-link']); + $terms = Term::tagArrayFromItemId($item['id']); + $contacts = []; + if (!$item['private']) { $data['to'][] = self::PUBLIC; - $data['cc'][] = System::baseUrl() . '/followers/' . $item['author-nick']; + if (!empty($actor_profile['followers'])) { + $data['cc'][] = $actor_profile['followers']; + } foreach ($terms as $term) { if ($term['type'] != TERM_MENTION) { continue; } $profile = self::fetchprofile($term['url']); - if (!empty($profile)) { + if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; + $contacts[$profile['url']] = $profile['url']; } } } else { - //$data['cc'][] = System::baseUrl() . '/followers/' . $item['author-nick']; $receiver_list = Item::enumeratePermissions($item); $mentioned = []; - $contacts = []; foreach ($terms as $term) { if ($term['type'] != TERM_MENTION) { @@ -213,38 +220,43 @@ class ActivityPub } } + $parents = Item::select(['author-link', 'owner-link'], ['parent' => $item['parent']]); + while ($parent = Item::fetch($parents)) { + $profile = self::fetchprofile($parent['author-link']); + if (!empty($profile) && empty($contacts[$profile['url']])) { + $data['cc'][] = $profile['url']; + $contacts[$profile['url']] = $profile['url']; + } + + $profile = self::fetchprofile($parent['owner-link']); + if (!empty($profile) && empty($contacts[$profile['url']])) { + $data['cc'][] = $profile['url']; + $contacts[$profile['url']] = $profile['url']; + } + } + DBA::close($parents); + return $data; } - private static function fetchTargetInboxesFromConversation($item, $uid) + public static function fetchTargetInboxes($item, $uid) { - if (empty($item['thr-parent'])) { + $permissions = self::createPermissionBlockForItem($item); + if (empty($permissions)) { return []; } - $condition = ['item-uri' => $item['thr-parent'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB]; - $conversation = DBA::selectFirst('conversation', ['source'], $condition); - if (!DBA::isResult($conversation)) { - return []; - } - - $activity = json_decode($conversation['source'], true); - - $actor = JsonLD::fetchElement($activity, 'actor', 'id'); - $profile = ActivityPub::fetchprofile($actor); - $inboxes = []; + $item_profile = ActivityPub::fetchprofile($item['owner-link']); + $elements = ['to', 'cc', 'bto', 'bcc']; foreach ($elements as $element) { - if (empty($activity[$element])) { + if (empty($permissions[$element])) { continue; } - if (is_string($activity[$element])) { - $activity[$element] = [$activity[$element]]; - } - foreach ($activity[$element] as $receiver) { - if ($receiver == $profile['followers']) { + foreach ($permissions[$element] as $receiver) { + if ($receiver == $item_profile['followers']) { $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid, 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB]); while ($contact = DBA::fetch($contacts)) { @@ -261,84 +273,13 @@ class ActivityPub } } } - return $inboxes; - } - public static function fetchTargetInboxes($item, $uid) - { - $inboxes = self::fetchTargetInboxesFromConversation($item, $uid); - - $parents = Item::select(['author-link', 'owner-link'], ['parent' => $item['parent']]); - while ($parent = Item::fetch($parents)) { - $profile = self::fetchprofile($parent['author-link']); - if (!empty($profile)) { - $target = defaults($profile, 'sharedinbox', $profile['inbox']); - $inboxes[$target] = $target; - } - $profile = self::fetchprofile($parent['owner-link']); - if (!empty($profile)) { - $target = defaults($profile, 'sharedinbox', $profile['inbox']); - $inboxes[$target] = $target; - } - } - DBA::close($parents); - - $terms = Term::tagArrayFromItemId($item['id']); - if (!$item['private']) { - $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid, - 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB]); - while ($contact = DBA::fetch($contacts)) { - $contact = defaults($contact, 'batch', $contact['notify']); - $inboxes[$contact] = $contact; - } - DBA::close($contacts); - - foreach ($terms as $term) { - if ($term['type'] != TERM_MENTION) { - continue; - } - $profile = self::fetchprofile($term['url']); - if (!empty($profile)) { - $target = defaults($profile, 'sharedinbox', $profile['inbox']); - $inboxes[$target] = $target; - } - } - } else { - $receiver_list = Item::enumeratePermissions($item); - $mentioned = []; - - foreach ($terms as $term) { - if ($term['type'] != TERM_MENTION) { - continue; - } - $cid = Contact::getIdForURL($term['url'], $uid); - if (!empty($cid) && in_array($cid, $receiver_list)) { - $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); - $profile = self::fetchprofile($contact['url']); - if (!empty($profile)) { - $target = defaults($profile, 'sharedinbox', $profile['inbox']); - $inboxes[$target] = $target; - } - } - } - - foreach ($receiver_list as $receiver) { - $contact = DBA::selectFirst('contact', ['url'], ['id' => $receiver, 'network' => Protocol::ACTIVITYPUB]); - $profile = self::fetchprofile($contact['url']); - if (!empty($profile)) { - $target = defaults($profile, 'sharedinbox', $profile['inbox']); - $inboxes[$target] = $target; - } - } + if (!empty($item_profile['sharedinbox'])) { + unset($inboxes[$item_profile['sharedinbox']]); } - $profile = self::fetchprofile($item['author-link']); - if (!empty($profile['sharedinbox'])) { - unset($inboxes[$profile['sharedinbox']]); - } - - if (!empty($profile['inbox'])) { - unset($inboxes[$profile['inbox']]); + if (!empty($item_profile['inbox'])) { + unset($inboxes[$item_profile['inbox']]); } return $inboxes; From 214407bdc8e7ae126f1b44eaaa1f902e38fb1b9d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 22 Sep 2018 14:12:54 +0000 Subject: [PATCH 44/97] Improve communication --- index.php | 4 +++ src/Protocol/ActivityPub.php | 67 ++++++++++++++++++++++-------------- src/Worker/APDelivery.php | 5 ++- src/Worker/Notifier.php | 2 +- 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/index.php b/index.php index 8b0bd47251..a62b7a2ea1 100644 --- a/index.php +++ b/index.php @@ -215,6 +215,10 @@ if (strlen($a->module)) { * First see if we have an addon which is masquerading as a module. */ + if ($a->module == 'object') { + $a->module = 'display'; + } + // Compatibility with the Android Diaspora client if ($a->module == 'stream') { goaway('network?f=&order=post'); diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 339312245e..95542ba966 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -155,7 +155,9 @@ class ActivityPub if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) { $receiver = $item_profile['followers']; } - $permissions[$element][] = $receiver; + if ($receiver != $item['owner-link']) { + $permissions[$element][] = $receiver; + } } } return $permissions; @@ -171,7 +173,7 @@ class ActivityPub $terms = Term::tagArrayFromItemId($item['id']); - $contacts = []; + $contacts[$item['author-link']] = $item['author-link']; if (!$item['private']) { $data['to'][] = self::PUBLIC; @@ -213,11 +215,6 @@ class ActivityPub $contacts[$contact['url']] = $contact['url']; } } - - if (empty($data['to'])) { - $data['to'] = $data['cc']; - $data['cc'] = []; - } } $parents = Item::select(['author-link', 'owner-link'], ['parent' => $item['parent']]); @@ -236,6 +233,11 @@ class ActivityPub } DBA::close($parents); + if (empty($data['to'])) { + $data['to'] = $data['cc']; + $data['cc'] = []; + } + return $data; } @@ -318,9 +320,12 @@ class ActivityPub $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); } + $data['context_id'] = $item['parent']; + $data['context'] = self::createConversationURLFromItem($item); + $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); - $data['object'] = self::createNote($item); + $data['object'] = self::createObjectTypeFromItem($item); $owner = User::getOwnerDataById($item['uid']); @@ -341,7 +346,7 @@ class ActivityPub 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; - $data = array_merge($data, self::createNote($item)); + $data = array_merge($data, self::createObjectTypeFromItem($item)); return $data; @@ -364,15 +369,31 @@ class ActivityPub $tags[] = ['type' => 'Mention', 'href' => $term['url'], 'name' => $mention]; } } - return $tags; } - public static function createNote($item) + private static function createConversationURLFromItem($item) { + $conversation = DBA::selectFirst('conversation', ['conversation-uri'], ['item-uri' => $item['parent-uri']]); + if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) { + $conversation_uri = $conversation['conversation-uri']; + } else { + $conversation_uri = $item['parent-uri']; + } + return $conversation_uri; + } + + private static function createObjectTypeFromItem($item) + { + if (!empty($item['title'])) { + $type = 'Article'; + } else { + $type = 'Note'; + } + $data = []; $data['id'] = $item['uri']; - $data['type'] = 'Note'; + $data['type'] = $type; $data['summary'] = null; // Ignore by now if ($item['uri'] != $item['thr-parent']) { @@ -387,19 +408,12 @@ class ActivityPub $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); } - $data['url'] = $item['uri']; + $data['url'] = $item['plink']; $data['attributedTo'] = $item['author-link']; $data['actor'] = $item['author-link']; $data['sensitive'] = false; // - Query NSFW - - $conversation = DBA::selectFirst('conversation', ['conversation-uri'], ['item-uri' => $item['parent-uri']]); - if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) { - $conversation_uri = $conversation['conversation-uri']; - } else { - $conversation_uri = $item['parent-uri']; - } - - $data['conversation'] = $conversation_uri; + $data['context_id'] = $item['parent']; + $data['conversation'] = $data['context'] = self::createConversationURLFromItem($item); if (!empty($item['title'])) { $data['name'] = BBCode::convert($item['title'], false, 7); @@ -704,14 +718,17 @@ class ActivityPub if (LDSignature::isSigned($activity)) { $ld_signer = LDSignature::getSigner($activity); - if (!empty($ld_signer)) { + if (!empty($ld_signer && ($actor == $http_signer))) { + logger('The HTTP and the JSON-LD signature belong to ' . $ld_signer, LOGGER_DEBUG); + $trust_source = true; + } elseif (!empty($ld_signer)) { logger('JSON-LD signature is signed by ' . $ld_signer, LOGGER_DEBUG); $trust_source = true; } elseif ($actor == $http_signer) { logger('Bad JSON-LD signature, but HTTP signer fits the actor.', LOGGER_DEBUG); $trust_source = true; } else { - logger('Invalid JSON-LD signature.', LOGGER_DEBUG); + logger('Invalid JSON-LD signature and the HTTP signer is different.', LOGGER_DEBUG); $trust_source = false; } } elseif ($actor == $http_signer) { @@ -1005,7 +1022,7 @@ class ActivityPub return false; } logger('Using already stored item for url ' . $object_url, LOGGER_DEBUG); - $data = self::createNote($item); + $data = self::createObjectTypeFromItem($item); } if (empty($data['type'])) { diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index f43c56a3ec..493bb5fac8 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -11,7 +11,7 @@ use Friendica\Util\HTTPSignature; class APDelivery extends BaseObject { - public static function execute($cmd, $item_id, $inbox) + public static function execute($cmd, $item_id, $inbox, $uid) { logger('Invoked: ' . $cmd . ': ' . $item_id . ' to ' . $inbox, LOGGER_DEBUG); @@ -19,9 +19,8 @@ class APDelivery extends BaseObject } elseif ($cmd == Delivery::SUGGESTION) { } elseif ($cmd == Delivery::RELOCATION) { } else { - $item = Item::selectFirst(['uid'], ['id' => $item_id]); $data = ActivityPub::createActivityFromItem($item_id); - HTTPSignature::transmit($data, $inbox, $item['uid']); + HTTPSignature::transmit($data, $inbox, $uid); } return; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 286bcd03ee..b457b78008 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -429,7 +429,7 @@ class Notifier logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true], - 'APDelivery', $cmd, $item_id, $inbox); + 'APDelivery', $cmd, $item_id, $inbox, $uid); } // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts From c7e047bf83b134f8733afca00609159638e62e4e Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 22 Sep 2018 15:34:42 +0000 Subject: [PATCH 45/97] Fixed composer.lock --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index 42e6c3661b..5c3903a853 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "7bfbddde186f6599a2f2012bb13cbbd8", + "content-hash": "5f6a43237dc52758484cd21cd76e8ce6", "packages": [ { "name": "asika/simple-console", From 8d72c864b2daad75ecace47ebbe5b679b52b012f Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 22 Sep 2018 22:17:32 +0000 Subject: [PATCH 46/97] Updated composer --- composer.lock | 596 ++++++++++++++++++++++---------------------------- 1 file changed, 266 insertions(+), 330 deletions(-) diff --git a/composer.lock b/composer.lock index 5c3903a853..27e0f329e0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "5f6a43237dc52758484cd21cd76e8ce6", + "content-hash": "36f76191086a7f81370b51d0ff8cea1d", "packages": [ { "name": "asika/simple-console", @@ -41,16 +41,16 @@ }, { "name": "bower-asset/Chart-js", - "version": "v2.7.1", + "version": "v2.7.2", "source": { "type": "git", "url": "https://github.com/chartjs/Chart.js.git", - "reference": "0fead21939b92c15093c1b7d5ee2627fb5900fff" + "reference": "98f104cdd03617f1300b417b3d60c23d4e3e3403" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/chartjs/Chart.js/zipball/0fead21939b92c15093c1b7d5ee2627fb5900fff", - "reference": "0fead21939b92c15093c1b7d5ee2627fb5900fff", + "url": "https://api.github.com/repos/chartjs/Chart.js/zipball/98f104cdd03617f1300b417b3d60c23d4e3e3403", + "reference": "98f104cdd03617f1300b417b3d60c23d4e3e3403", "shasum": "" }, "type": "bower-asset-library", @@ -69,7 +69,7 @@ "MIT" ], "description": "Simple HTML5 charts using the canvas element.", - "time": "2017-10-28T15:01:52+00:00" + "time": "2018-03-01T21:45:21+00:00" }, { "name": "bower-asset/base64", @@ -135,16 +135,16 @@ }, { "name": "bower-asset/vue", - "version": "v2.5.16", + "version": "v2.5.17", "source": { "type": "git", "url": "https://github.com/vuejs/vue.git", - "reference": "25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6" + "reference": "636c9b4ef17f2062720b677cbbe613f146f4d4db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vuejs/vue/zipball/25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6", - "reference": "25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6", + "url": "https://api.github.com/repos/vuejs/vue/zipball/636c9b4ef17f2062720b677cbbe613f146f4d4db", + "reference": "636c9b4ef17f2062720b677cbbe613f146f4d4db", "shasum": "" }, "type": "bower-asset-library" @@ -196,29 +196,118 @@ "time": "2016-04-25T04:17:52+00:00" }, { - "name": "divineomega/password_exposed", - "version": "v2.5.1", + "name": "divineomega/do-file-cache", + "version": "v2.0.2", "source": { "type": "git", - "url": "https://github.com/DivineOmega/password_exposed.git", - "reference": "c928bf722eb02398df11076add60df070cb55581" + "url": "https://github.com/DivineOmega/DO-File-Cache.git", + "reference": "261c6e30a0de8cd325f826d08b2e51b2e367a1a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/DivineOmega/password_exposed/zipball/c928bf722eb02398df11076add60df070cb55581", - "reference": "c928bf722eb02398df11076add60df070cb55581", + "url": "https://api.github.com/repos/DivineOmega/DO-File-Cache/zipball/261c6e30a0de8cd325f826d08b2e51b2e367a1a3", + "reference": "261c6e30a0de8cd325f826d08b2e51b2e367a1a3", "shasum": "" }, "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^6.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "DivineOmega\\DOFileCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-only" + ], + "description": "DO File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.", + "keywords": [ + "cache", + "caching", + "caching library", + "file cache", + "library", + "php" + ], + "time": "2018-09-12T23:08:34+00:00" + }, + { + "name": "divineomega/do-file-cache-psr-6", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/DivineOmega/DO-File-Cache-PSR-6.git", + "reference": "18f9807d0491d093e9a12741afb40257d92f017e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DivineOmega/DO-File-Cache-PSR-6/zipball/18f9807d0491d093e9a12741afb40257d92f017e", + "reference": "18f9807d0491d093e9a12741afb40257d92f017e", + "shasum": "" + }, + "require": { + "divineomega/do-file-cache": "^2.0.0", + "psr/cache": "^1.0" + }, + "require-dev": { + "cache/integration-tests": "^0.16.0", + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5.7" + }, + "type": "library", + "autoload": { + "psr-4": { + "DivineOmega\\DOFileCachePSR6\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-only" + ], + "authors": [ + { + "name": "Jordan Hall", + "email": "jordan@hall05.co.uk" + } + ], + "description": "PSR-6 adapter for DO File Cache", + "time": "2018-07-13T08:32:36+00:00" + }, + { + "name": "divineomega/password_exposed", + "version": "v2.5.3", + "source": { + "type": "git", + "url": "https://github.com/DivineOmega/password_exposed.git", + "reference": "1f1b49e3ec55b0f07115d342b145091368b081c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DivineOmega/password_exposed/zipball/1f1b49e3ec55b0f07115d342b145091368b081c4", + "reference": "1f1b49e3ec55b0f07115d342b145091368b081c4", + "shasum": "" + }, + "require": { + "divineomega/do-file-cache-psr-6": "^2.0", "guzzlehttp/guzzle": "^6.3", "paragonie/certainty": "^1", - "php": ">=5.6", - "rapidwebltd/rw-file-cache-psr-6": "^1.0" + "php": ">=5.6" }, "require-dev": { "fzaninotto/faker": "^1.7", + "php-coveralls/php-coveralls": "^2.1", "phpunit/phpunit": "^5.7", - "satooshi/php-coveralls": "^2.0", "vimeo/psalm": "^1" }, "type": "library", @@ -241,7 +330,7 @@ } ], "description": "This PHP package provides a `password_exposed` helper function, that uses the haveibeenpwned.com API to check if a password has been exposed in a data breach.", - "time": "2018-04-02T18:16:36+00:00" + "time": "2018-07-12T22:09:43+00:00" }, { "name": "ezyang/htmlpurifier", @@ -289,16 +378,16 @@ }, { "name": "fxp/composer-asset-plugin", - "version": "v1.4.2", + "version": "v1.4.4", "source": { "type": "git", "url": "https://github.com/fxpio/composer-asset-plugin.git", - "reference": "61352d99940d2b2392a5d2db83b8c0ef5faf222a" + "reference": "0d07328eef6e6f3753aa835fd2faef7fed1717bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fxpio/composer-asset-plugin/zipball/61352d99940d2b2392a5d2db83b8c0ef5faf222a", - "reference": "61352d99940d2b2392a5d2db83b8c0ef5faf222a", + "url": "https://api.github.com/repos/fxpio/composer-asset-plugin/zipball/0d07328eef6e6f3753aa835fd2faef7fed1717bf", + "reference": "0d07328eef6e6f3753aa835fd2faef7fed1717bf", "shasum": "" }, "require": { @@ -306,7 +395,7 @@ "php": ">=5.3.3" }, "require-dev": { - "composer/composer": "^1.4.0" + "composer/composer": "^1.6.0" }, "type": "composer-plugin", "extra": { @@ -344,20 +433,20 @@ "npm", "package" ], - "time": "2017-10-20T06:53:56+00:00" + "time": "2018-07-02T11:37:17+00:00" }, { "name": "guzzlehttp/guzzle", - "version": "6.3.0", + "version": "6.3.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699" + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699", - "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", "shasum": "" }, "require": { @@ -367,7 +456,7 @@ }, "require-dev": { "ext-curl": "*", - "phpunit/phpunit": "^4.0 || ^5.0", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", "psr/log": "^1.0" }, "suggest": { @@ -376,7 +465,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "6.2-dev" + "dev-master": "6.3-dev" } }, "autoload": { @@ -409,7 +498,7 @@ "rest", "web service" ], - "time": "2017-06-22T18:50:49+00:00" + "time": "2018-04-22T15:46:56+00:00" }, { "name": "guzzlehttp/promises", @@ -672,16 +761,16 @@ }, { "name": "mobiledetect/mobiledetectlib", - "version": "2.8.30", + "version": "2.8.33", "source": { "type": "git", "url": "https://github.com/serbanghita/Mobile-Detect.git", - "reference": "5500bbbf312fe77ef0c7223858dad84fe49ee0c3" + "reference": "cd385290f9a0d609d2eddd165a1e44ec1bf12102" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/serbanghita/Mobile-Detect/zipball/5500bbbf312fe77ef0c7223858dad84fe49ee0c3", - "reference": "5500bbbf312fe77ef0c7223858dad84fe49ee0c3", + "url": "https://api.github.com/repos/serbanghita/Mobile-Detect/zipball/cd385290f9a0d609d2eddd165a1e44ec1bf12102", + "reference": "cd385290f9a0d609d2eddd165a1e44ec1bf12102", "shasum": "" }, "require": { @@ -720,7 +809,7 @@ "mobile detector", "php mobile detect" ], - "time": "2017-12-18T10:38:51+00:00" + "time": "2018-09-01T15:05:15+00:00" }, { "name": "npm-asset/cropperjs", @@ -861,67 +950,16 @@ }, { "name": "npm-asset/fullcalendar", - "version": "3.8.2", + "version": "3.9.0", "dist": { "type": "tar", - "url": "https://registry.npmjs.org/fullcalendar/-/fullcalendar-3.8.2.tgz", + "url": "https://registry.npmjs.org/fullcalendar/-/fullcalendar-3.9.0.tgz", "reference": null, - "shasum": "ef7dc77b89134bbe6163e51136f7a1f8bfc1d807" + "shasum": "b608a9989f3416f0b1d526c6bdfeeaf2ac79eda5" }, "require": { "npm-asset/jquery": ">=2,<4.0", - "npm-asset/moment": ">=2.9.0,<3.0.0" - }, - "require-dev": { - "npm-asset/awesome-typescript-loader": ">=3.3.0,<4.0.0", - "npm-asset/bootstrap": ">=3.3.7,<4.0.0", - "npm-asset/components-jqueryui": "dev-github:components/jqueryui", - "npm-asset/css-loader": ">=0.28.7,<0.29.0", - "npm-asset/del": ">=2.2.1,<3.0.0", - "npm-asset/dts-generator": ">=2.1.0,<3.0.0", - "npm-asset/eslint": ">=4.13.1,<5.0.0", - "npm-asset/eslint-config-standard": ">=11.0.0-beta.0,<12.0.0", - "npm-asset/eslint-plugin-import": ">=2.8.0,<3.0.0", - "npm-asset/eslint-plugin-node": ">=5.2.1,<6.0.0", - "npm-asset/eslint-plugin-promise": ">=3.6.0,<4.0.0", - "npm-asset/eslint-plugin-standard": ">=3.0.1,<4.0.0", - "npm-asset/extract-text-webpack-plugin": ">=3.0.2,<4.0.0", - "npm-asset/glob": ">=7.1.2,<8.0.0", - "npm-asset/gulp": ">=3.9.1,<4.0.0", - "npm-asset/gulp-cssmin": ">=0.1.7,<0.2.0", - "npm-asset/gulp-eslint": ">=4.0.0,<5.0.0", - "npm-asset/gulp-filter": ">=4.0.0,<5.0.0", - "npm-asset/gulp-modify-file": ">=1.0.0,<2.0.0", - "npm-asset/gulp-rename": ">=1.2.2,<2.0.0", - "npm-asset/gulp-shell": ">=0.6.5,<0.7.0", - "npm-asset/gulp-tslint": ">=8.1.2,<9.0.0", - "npm-asset/gulp-uglify": ">=2.0.0,<3.0.0", - "npm-asset/gulp-util": ">=3.0.7,<4.0.0", - "npm-asset/gulp-watch": ">=4.3.11,<5.0.0", - "npm-asset/gulp-zip": ">=3.2.0,<4.0.0", - "npm-asset/jasmine-core": "2.5.2", - "npm-asset/jasmine-fixture": ">=2.0.0,<3.0.0", - "npm-asset/jasmine-jquery": ">=2.1.1,<3.0.0", - "npm-asset/jquery-mockjax": ">=2.2.0,<3.0.0", - "npm-asset/jquery-simulate": "dev-github:jquery/jquery-simulate", - "npm-asset/karma": ">=0.13.22,<0.14.0", - "npm-asset/karma-jasmine": ">=1.0.2,<2.0.0", - "npm-asset/karma-phantomjs-launcher": ">=1.0.0,<2.0.0", - "npm-asset/karma-sourcemap-loader": ">=0.3.7,<0.4.0", - "npm-asset/karma-verbose-reporter": "0.0.6", - "npm-asset/moment-timezone": ">=0.5.5,<0.6.0", - "npm-asset/native-promise-only": ">=0.8.1,<0.9.0", - "npm-asset/node-sass": ">=4.7.2,<5.0.0", - "npm-asset/phantomjs-prebuilt": ">=2.1.7,<3.0.0", - "npm-asset/sass-loader": ">=6.0.6,<7.0.0", - "npm-asset/tslib": ">=1.8.0,<2.0.0", - "npm-asset/tslint": ">=5.8.0,<6.0.0", - "npm-asset/tslint-config-standard": ">=7.0.0,<8.0.0", - "npm-asset/types--jquery": "2.0.47", - "npm-asset/typescript": ">=2.6.2,<3.0.0", - "npm-asset/webpack": ">=3.8.1,<4.0.0", - "npm-asset/webpack-stream": ">=4.0.0,<5.0.0", - "npm-asset/yargs": ">=4.8.1,<5.0.0" + "npm-asset/moment": ">=2.20.1,<3.0.0" }, "type": "npm-asset-library", "extra": { @@ -969,7 +1007,7 @@ "full-sized", "jquery-plugin" ], - "time": "2018-01-30T23:49:01+00:00" + "time": "2018-03-05T03:30:23+00:00" }, { "name": "npm-asset/imagesloaded", @@ -1196,12 +1234,12 @@ }, { "name": "npm-asset/jquery-datetimepicker", - "version": "2.5.17", + "version": "2.5.20", "dist": { "type": "tar", - "url": "https://registry.npmjs.org/jquery-datetimepicker/-/jquery-datetimepicker-2.5.17.tgz", + "url": "https://registry.npmjs.org/jquery-datetimepicker/-/jquery-datetimepicker-2.5.20.tgz", "reference": null, - "shasum": "8857a631f248081d4072563bde40fa8c17e407b1" + "shasum": "687d6204b90b03dc93f725f8df036e1d061f37ac" }, "require": { "npm-asset/jquery": ">=1.7.2", @@ -1209,8 +1247,14 @@ "npm-asset/php-date-formatter": ">=1.3.4,<2.0.0" }, "require-dev": { + "npm-asset/chai": ">=4.1.2,<5.0.0", "npm-asset/concat": "dev-github:azer/concat", "npm-asset/concat-cli": ">=4.0.0,<5.0.0", + "npm-asset/karma": ">=2.0.0,<3.0.0", + "npm-asset/karma-chai": ">=0.1.0,<0.2.0", + "npm-asset/karma-firefox-launcher": ">=1.1.0,<2.0.0", + "npm-asset/karma-mocha": ">=1.3.0,<2.0.0", + "npm-asset/mocha": ">=5.0.4,<6.0.0", "npm-asset/uglifycss": ">=0.0.27,<0.0.28", "npm-asset/uglifyjs": ">=2.4.10,<3.0.0" }, @@ -1226,13 +1270,13 @@ "url": "git+https://github.com/xdan/datetimepicker.git" }, "npm-asset-scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "test": "karma start --browsers Firefox karma.conf.js --single-run", "concat": "concat-cli -f node_modules/php-date-formatter/js/php-date-formatter.min.js jquery.datetimepicker.js node_modules/jquery-mousewheel/jquery.mousewheel.js -o build/jquery.datetimepicker.full.js", "minify": "uglifyjs jquery.datetimepicker.js -c -m -o build/jquery.datetimepicker.min.js && uglifycss jquery.datetimepicker.css > build/jquery.datetimepicker.min.css", "minifyconcat": "uglifyjs build/jquery.datetimepicker.full.js -c -m -o build/jquery.datetimepicker.full.min.js", "github": "git add --all && git commit -m \"New version %npm_package_version% \" && git tag %npm_package_version% && git push --tags origin HEAD:master && npm publish", "build": "npm run minify && npm run concat && npm run minifyconcat", - "public": "npm version patch --no-git-tag-version && npm run build && npm run github" + "public": "npm run test && npm version patch --no-git-tag-version && npm run build && npm run github" } }, "license": [ @@ -1242,7 +1286,7 @@ { "name": "Chupurnov", "email": "chupurnov@gmail.com", - "url": "http://xdsoft.net/" + "url": "https://xdsoft.net/" } ], "description": "jQuery Plugin DateTimePicker it is DatePicker and TimePicker in one", @@ -1256,7 +1300,7 @@ "time", "timepicker" ], - "time": "2018-01-23T05:56:50+00:00" + "time": "2018-03-21T16:26:39+00:00" }, { "name": "npm-asset/jquery-mousewheel", @@ -1315,45 +1359,12 @@ }, { "name": "npm-asset/moment", - "version": "2.20.1", + "version": "2.22.2", "dist": { "type": "tar", - "url": "https://registry.npmjs.org/moment/-/moment-2.20.1.tgz", + "url": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz", "reference": null, - "shasum": "d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd" - }, - "require-dev": { - "npm-asset/benchmark": "dev-default|*", - "npm-asset/coveralls": ">=2.11.2,<3.0.0", - "npm-asset/es6-promise": "dev-default|*", - "npm-asset/grunt": "~0.4", - "npm-asset/grunt-benchmark": "dev-default|*", - "npm-asset/grunt-cli": "dev-default|*", - "npm-asset/grunt-contrib-clean": "dev-default|*", - "npm-asset/grunt-contrib-concat": "dev-default|*", - "npm-asset/grunt-contrib-copy": "dev-default|*", - "npm-asset/grunt-contrib-jshint": "dev-default|*", - "npm-asset/grunt-contrib-uglify": "dev-default|*", - "npm-asset/grunt-contrib-watch": "dev-default|*", - "npm-asset/grunt-env": "dev-default|*", - "npm-asset/grunt-exec": "dev-default|*", - "npm-asset/grunt-jscs": "dev-default|*", - "npm-asset/grunt-karma": "dev-default|*", - "npm-asset/grunt-nuget": "dev-default|*", - "npm-asset/grunt-string-replace": "dev-default|*", - "npm-asset/karma": "dev-default|*", - "npm-asset/karma-chrome-launcher": "dev-default|*", - "npm-asset/karma-firefox-launcher": "dev-default|*", - "npm-asset/karma-qunit": "dev-default|*", - "npm-asset/karma-sauce-launcher": "dev-default|*", - "npm-asset/load-grunt-tasks": "dev-default|*", - "npm-asset/nyc": ">=2.1.4,<3.0.0", - "npm-asset/qunit": ">=0.7.5,<0.8.0", - "npm-asset/qunit-cli": ">=0.1.4,<0.2.0", - "npm-asset/rollup": "dev-default|*", - "npm-asset/spacejam": "dev-default|*", - "npm-asset/typescript": ">=1.8.10,<2.0.0", - "npm-asset/uglify-js": "dev-default|*" + "shasum": "3c257f9839fc0e93ff53149632239eb90783ff66" }, "type": "npm-asset-library", "extra": { @@ -1423,16 +1434,21 @@ "time", "validate" ], - "time": "2017-12-19T04:44:18+00:00" + "time": "2018-06-01T06:58:41+00:00" }, { "name": "npm-asset/php-date-formatter", - "version": "1.3.4", + "version": "v1.3.5", + "source": { + "type": "git", + "url": "https://github.com/kartik-v/php-date-formatter.git", + "reference": "d842e1c4e6a8d6108017b726321c305bb5ae4fb5" + }, "dist": { - "type": "tar", - "url": "https://registry.npmjs.org/php-date-formatter/-/php-date-formatter-1.3.4.tgz", - "reference": null, - "shasum": "09a15ae0766ba0beb1900c27c1ec319ef2e4563e" + "type": "zip", + "url": "https://api.github.com/repos/kartik-v/php-date-formatter/zipball/d842e1c4e6a8d6108017b726321c305bb5ae4fb5", + "reference": "d842e1c4e6a8d6108017b726321c305bb5ae4fb5", + "shasum": "" }, "type": "npm-asset-library", "extra": { @@ -1445,35 +1461,31 @@ }, "npm-asset-repository": { "type": "git", - "url": "git+https://github.com/kartik-v/php-date-formatter.git" - }, - "npm-asset-scripts": [] + "url": "https://github.com/kartik-v/php-date-formatter.git" + } }, "license": [ "BSD-3-Clause" ], "authors": [ - { - "name": "Kartik Visweswaran", - "email": "kartikv2@gmail.com" - } + "Kartik Visweswaran " ], "description": "A Javascript datetime formatting and manipulation library using PHP date-time formats.", "homepage": "https://github.com/kartik-v/php-date-formatter", - "time": "2016-02-18T15:15:55+00:00" + "time": "2018-07-13T06:56:46+00:00" }, { "name": "paragonie/certainty", - "version": "v1.0.2", + "version": "v1.0.4", "source": { "type": "git", "url": "https://github.com/paragonie/certainty.git", - "reference": "a2d14f5b0b85c58329dee248d77d34e7e1202a32" + "reference": "d0f22c0fe579cf0e4f8ee301de5bc97ab124faac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/certainty/zipball/a2d14f5b0b85c58329dee248d77d34e7e1202a32", - "reference": "a2d14f5b0b85c58329dee248d77d34e7e1202a32", + "url": "https://api.github.com/repos/paragonie/certainty/zipball/d0f22c0fe579cf0e4f8ee301de5bc97ab124faac", + "reference": "d0f22c0fe579cf0e4f8ee301de5bc97ab124faac", "shasum": "" }, "require": { @@ -1520,28 +1532,27 @@ "ssl", "tls" ], - "time": "2018-03-12T18:34:23+00:00" + "time": "2018-04-09T07:21:55+00:00" }, { "name": "paragonie/constant_time_encoding", - "version": "v1.0.2", + "version": "v2.2.2", "source": { "type": "git", "url": "https://github.com/paragonie/constant_time_encoding.git", - "reference": "6111a38faf6fdebc14e36652d22036f379ba58d3" + "reference": "eccf915f45f911bfb189d1d1638d940ec6ee6e33" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/6111a38faf6fdebc14e36652d22036f379ba58d3", - "reference": "6111a38faf6fdebc14e36652d22036f379ba58d3", + "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/eccf915f45f911bfb189d1d1638d940ec6ee6e33", + "reference": "eccf915f45f911bfb189d1d1638d940ec6ee6e33", "shasum": "" }, "require": { - "php": "^5.3|^7" + "php": "^7" }, "require-dev": { - "paragonie/random_compat": "^1|^2", - "phpunit/phpunit": "4.*|5.*", + "phpunit/phpunit": "^6|^7", "vimeo/psalm": "^1" }, "type": "library", @@ -1583,20 +1594,20 @@ "hex2bin", "rfc4648" ], - "time": "2018-03-10T19:46:06+00:00" + "time": "2018-03-10T19:47:49+00:00" }, { "name": "paragonie/random_compat", - "version": "v2.0.11", + "version": "v2.0.17", "source": { "type": "git", "url": "https://github.com/paragonie/random_compat.git", - "reference": "5da4d3c796c275c55f057af5a643ae297d96b4d8" + "reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/random_compat/zipball/5da4d3c796c275c55f057af5a643ae297d96b4d8", - "reference": "5da4d3c796c275c55f057af5a643ae297d96b4d8", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/29af24f25bab834fcbb38ad2a69fa93b867e070d", + "reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d", "shasum": "" }, "require": { @@ -1628,27 +1639,28 @@ "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", "keywords": [ "csprng", + "polyfill", "pseudorandom", "random" ], - "time": "2017-09-27T21:40:39+00:00" + "time": "2018-07-04T16:31:37+00:00" }, { "name": "paragonie/sodium_compat", - "version": "v1.6.0", + "version": "v1.7.0", "source": { "type": "git", "url": "https://github.com/paragonie/sodium_compat.git", - "reference": "1f6e5682eff4a5a6a394b14331a1904f1740e432" + "reference": "7b73005be3c224f12c47bd75a23ce24b762e47e8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/1f6e5682eff4a5a6a394b14331a1904f1740e432", - "reference": "1f6e5682eff4a5a6a394b14331a1904f1740e432", + "url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/7b73005be3c224f12c47bd75a23ce24b762e47e8", + "reference": "7b73005be3c224f12c47bd75a23ce24b762e47e8", "shasum": "" }, "require": { - "paragonie/random_compat": "^1|^2", + "paragonie/random_compat": ">=1", "php": "^5.2.4|^5.3|^5.4|^5.5|^5.6|^7" }, "require-dev": { @@ -1713,7 +1725,7 @@ "secret-key cryptography", "side-channel resistant" ], - "time": "2018-02-15T05:50:20+00:00" + "time": "2018-09-22T03:59:58+00:00" }, { "name": "pear/text_languagedetect", @@ -1855,94 +1867,6 @@ ], "time": "2016-08-06T14:39:51+00:00" }, - { - "name": "rapidwebltd/rw-file-cache", - "version": "v1.2.5", - "source": { - "type": "git", - "url": "https://github.com/rapidwebltd/RW-File-Cache.git", - "reference": "4a1d5aaefa6ffafec8e2d60787f12bcd9890977e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/rapidwebltd/RW-File-Cache/zipball/4a1d5aaefa6ffafec8e2d60787f12bcd9890977e", - "reference": "4a1d5aaefa6ffafec8e2d60787f12bcd9890977e", - "shasum": "" - }, - "require": { - "php": ">=5.2.1" - }, - "require-dev": { - "phpunit/phpunit": "^5.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "rapidweb\\RWFileCache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0-only" - ], - "description": "RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.", - "homepage": "https://github.com/rapidwebltd/RW-File-Cache", - "keywords": [ - "cache", - "caching", - "caching library", - "file cache", - "library", - "php" - ], - "time": "2018-01-23T17:20:58+00:00" - }, - { - "name": "rapidwebltd/rw-file-cache-psr-6", - "version": "v1.0.0", - "source": { - "type": "git", - "url": "https://github.com/rapidwebltd/RW-File-Cache-PSR-6.git", - "reference": "b74ea201d4c964f0e6db0fb036d1ab28a570df66" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/rapidwebltd/RW-File-Cache-PSR-6/zipball/b74ea201d4c964f0e6db0fb036d1ab28a570df66", - "reference": "b74ea201d4c964f0e6db0fb036d1ab28a570df66", - "shasum": "" - }, - "require": { - "psr/cache": "^1.0", - "rapidwebltd/rw-file-cache": "^1.2.3" - }, - "require-dev": { - "cache/integration-tests": "^0.16.0", - "phpunit/phpunit": "^5.7" - }, - "type": "library", - "autoload": { - "psr-4": { - "rapidweb\\RWFileCachePSR6\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0-only" - ], - "authors": [ - { - "name": "Jordan Hall", - "email": "jordan.hall@rapidweb.biz" - } - ], - "description": "PSR-6 adapter for RW File Cache", - "time": "2018-01-30T19:13:45+00:00" - }, { "name": "seld/cli-prompt", "version": "1.0.3", @@ -1993,16 +1917,16 @@ }, { "name": "smarty/smarty", - "version": "v3.1.31", + "version": "v3.1.33", "source": { "type": "git", "url": "https://github.com/smarty-php/smarty.git", - "reference": "c7d42e4a327c402897dd587871434888fde1e7a9" + "reference": "dd55b23121e55a3b4f1af90a707a6c4e5969530f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/smarty-php/smarty/zipball/c7d42e4a327c402897dd587871434888fde1e7a9", - "reference": "c7d42e4a327c402897dd587871434888fde1e7a9", + "url": "https://api.github.com/repos/smarty-php/smarty/zipball/dd55b23121e55a3b4f1af90a707a6c4e5969530f", + "reference": "dd55b23121e55a3b4f1af90a707a6c4e5969530f", "shasum": "" }, "require": { @@ -2042,7 +1966,7 @@ "keywords": [ "templating" ], - "time": "2016-12-14T21:57:25+00:00" + "time": "2018-09-12T20:54:16+00:00" } ], "packages-dev": [ @@ -2191,53 +2115,6 @@ ], "time": "2017-10-19T19:58:43+00:00" }, - { - "name": "phar-io/version", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/phar-io/version.git", - "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df", - "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - }, - { - "name": "Sebastian Heuer", - "email": "sebastian@phpeople.de", - "role": "Developer" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "Developer" - } - ], - "description": "Library for handling version information and constraints", - "time": "2017-03-05T17:38:23+00:00" - }, { "name": "phpdocumentor/reflection-common", "version": "1.0.1", @@ -2386,16 +2263,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.6", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712" + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712", - "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", "shasum": "" }, "require": { @@ -2407,12 +2284,12 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.8.x-dev" } }, "autoload": { @@ -2445,7 +2322,7 @@ "spy", "stub" ], - "time": "2018-04-18T13:57:24+00:00" + "time": "2018-08-05T17:53:17+00:00" }, { "name": "phpunit/dbunit", @@ -3406,21 +3283,80 @@ "time": "2016-10-03T07:35:21+00:00" }, { - "name": "symfony/yaml", - "version": "v3.4.8", + "name": "symfony/polyfill-ctype", + "version": "v1.9.0", "source": { "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "a42f9da85c7c38d59f5e53f076fe81a091f894d0" + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/a42f9da85c7c38d59f5e53f076fe81a091f894d0", - "reference": "a42f9da85c7c38d59f5e53f076fe81a091f894d0", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8" + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-08-06T14:22:27+00:00" + }, + { + "name": "symfony/yaml", + "version": "v3.4.15", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/c2f4812ead9f847cb69e90917ca7502e6892d6b8", + "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/polyfill-ctype": "~1.8" }, "conflict": { "symfony/console": "<3.4" @@ -3461,7 +3397,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-04-03T05:14:20+00:00" + "time": "2018-08-10T07:34:36+00:00" }, { "name": "webmozart/assert", From ca574e10276de79fa8de79931532d5974948084e Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 22 Sep 2018 23:17:01 +0000 Subject: [PATCH 47/97] We can now like and dislike --- src/Protocol/ActivityPub.php | 59 +++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 95542ba966..6c46da553d 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -42,12 +42,12 @@ use Friendica\Util\LDSignature; * To-do: * * Receiver: - * - Activities: Dislike, Update, Delete + * - Activities: Update, Delete * - Object Types: Person, Tombstome * * Transmitter: - * - Activities: Like, Dislike, Update, Delete, Announce - * - Object Tyoes: Article, Person, Tombstone + * - Activities: Announce + * - Object Tyoes: Person, Tombstone * * General: * - Endpoints: Outbox, Follower, Following @@ -287,6 +287,33 @@ class ActivityPub return $inboxes; } + public static function getTypeOfItem($item) + { + if ($item['verb'] == ACTIVITY_POST) { + if ($item['created'] == $item['edited']) { + $type = 'Create'; + } else { + $type = 'Update'; + } + } elseif ($item['verb'] == ACTIVITY_LIKE) { + $type = 'Like'; + } elseif ($item['verb'] == ACTIVITY_DISLIKE) { + $type = 'Dislike'; + } elseif ($item['verb'] == ACTIVITY_ATTEND) { + $type = 'Accept'; + } elseif ($item['verb'] == ACTIVITY_ATTENDNO) { + $type = 'Reject'; + } elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) { + $type = 'TentativeAccept'; + } + + if ($item['deleted']) { + $type = 'Delete'; + } + + return $type; + } + public static function createActivityFromItem($item_id) { $item = Item::selectFirst([], ['id' => $item_id]); @@ -311,7 +338,7 @@ class ActivityPub 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; $data['id'] = $item['uri'] . '#activity'; - $data['type'] = 'Create'; + $data['type'] = self::getTypeOfItem($item);; $data['actor'] = $item['author-link']; $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); @@ -325,7 +352,11 @@ class ActivityPub $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); - $data['object'] = self::createObjectTypeFromItem($item); + if (in_array($data['type'], ['Create', 'Update', 'Announce'])) { + $data['object'] = self::CreateNote($item); + } else { + $data['object'] = $item['thr-parent']; + } $owner = User::getOwnerDataById($item['uid']); @@ -346,7 +377,7 @@ class ActivityPub 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; - $data = array_merge($data, self::createObjectTypeFromItem($item)); + $data = array_merge($data, self::CreateNote($item)); return $data; @@ -383,7 +414,7 @@ class ActivityPub return $conversation_uri; } - private static function createObjectTypeFromItem($item) + private static function CreateNote($item) { if (!empty($item['title'])) { $type = 'Article'; @@ -875,6 +906,7 @@ class ActivityPub break; case 'Dislike': + self::dislikeItem($object_data, $body); break; case 'Update': @@ -1022,7 +1054,7 @@ class ActivityPub return false; } logger('Using already stored item for url ' . $object_url, LOGGER_DEBUG); - $data = self::createObjectTypeFromItem($item); + $data = self::CreateNote($item); } if (empty($data['type'])) { @@ -1239,6 +1271,17 @@ class ActivityPub self::postItem($activity, $item, $body); } + private static function dislikeItem($activity, $body) + { + $item = []; + $item['verb'] = ACTIVITY_DISLIKE; + $item['parent-uri'] = $activity['object']; + $item['gravity'] = GRAVITY_ACTIVITY; + $item['object-type'] = ACTIVITY_OBJ_NOTE; + + self::postItem($activity, $item, $body); + } + private static function postItem($activity, $item, $body) { /// @todo What to do with $activity['context']? From a56565fa99838b91198c0ff3a813ec27fe8f4f48 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 22 Sep 2018 23:49:27 +0000 Subject: [PATCH 48/97] AP is enabled for all users --- mod/display.php | 2 +- mod/follow.php | 3 +-- mod/profile.php | 2 +- mod/xrd.php | 4 +--- src/Network/Probe.php | 5 +++-- src/Protocol/ActivityPub.php | 13 +++++++------ 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/mod/display.php b/mod/display.php index 1b4508c18d..ff98e689d3 100644 --- a/mod/display.php +++ b/mod/display.php @@ -79,7 +79,7 @@ function display_init(App $a) if (ActivityPub::isRequest()) { $wall_item = Item::selectFirst(['id', 'uid'], ['guid' => $item['guid'], 'wall' => true]); - if ($wall_item['uid'] == 180) { + if (DBA::isResult($wall_item)) { $data = ActivityPub::createObjectFromItemID($wall_item['id']); echo json_encode($data); exit(); diff --git a/mod/follow.php b/mod/follow.php index 65028a70e0..627ab52033 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -31,8 +31,7 @@ function follow_post(App $a) // This is just a precaution if maybe this page is called somewhere directly via POST $_SESSION['fastlane'] = $url; - $result = Contact::createFromProbe($uid, $url, true, Protocol::ACTIVITYPUB); -// $result = Contact::createFromProbe($uid, $url, true); + $result = Contact::createFromProbe($uid, $url, true); if ($result['success'] == false) { if ($result['message']) { diff --git a/mod/profile.php b/mod/profile.php index a284e10f2d..0035ba26ad 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -52,7 +52,7 @@ function profile_init(App $a) if (ActivityPub::isRequest()) { $user = DBA::selectFirst('user', ['uid'], ['nickname' => $which]); - if ($user['uid'] == 180) { + if (DBM::isResult($user)) { $data = ActivityPub::profile($user['uid']); echo json_encode($data); exit(); diff --git a/mod/xrd.php b/mod/xrd.php index 87766ca26e..6a5fdbbdb9 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -80,6 +80,7 @@ function xrd_json($a, $uri, $alias, $profile_url, $r) ['rel' => NAMESPACE_DFRN, 'href' => $profile_url], ['rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']], ['rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url], + ['rel' => 'self', 'type' => 'application/activity+json', 'href' => $profile_url], ['rel' => 'http://microformats.org/profile/hcard', 'type' => 'text/html', 'href' => System::baseUrl().'/hcard/'.$r['nickname']], ['rel' => NAMESPACE_POCO, 'href' => System::baseUrl().'/poco/'.$r['nickname']], ['rel' => 'http://webfinger.net/rel/avatar', 'type' => 'image/jpeg', 'href' => System::baseUrl().'/photo/profile/'.$r['uid'].'.jpg'], @@ -92,9 +93,6 @@ function xrd_json($a, $uri, $alias, $profile_url, $r) ['rel' => 'http://purl.org/openwebauth/v1', 'type' => 'application/x-dfrn+json', 'href' => System::baseUrl().'/owa'] ] ]; - if ($r['uid'] == 180) { - $json['links'][] = ['rel' => 'self', 'type' => 'application/activity+json', 'href' => $profile_url]; - } echo json_encode($json); killme(); diff --git a/src/Network/Probe.php b/src/Network/Probe.php index c0c627bfe9..b19f34b762 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -335,8 +335,9 @@ class Probe $data = null; } - if (in_array(defaults($data, 'network', ''), ['', Protocol::PHANTOM])) { - $ap_profile = ActivityPub::probeProfile($uri); + $ap_profile = ActivityPub::probeProfile($uri); + + if (!empty($ap_profile) && (defaults($data, 'network', '') != Protocol::DFRN)) { if (!empty($ap_profile) && ($ap_profile['network'] == Protocol::ACTIVITYPUB)) { $data = $ap_profile; } diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 6c46da553d..415d714d9a 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -332,9 +332,9 @@ class ActivityPub } $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', - ['ostatus' => 'http://ostatus.org#', 'sensitive' => 'as:sensitive', - 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri', - 'conversation' => 'ostatus:conversation', + ['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier', + 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag', + 'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; $data['id'] = $item['uri'] . '#activity'; @@ -372,9 +372,9 @@ class ActivityPub } $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', - ['ostatus' => 'http://ostatus.org#', 'sensitive' => 'as:sensitive', - 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri', - 'conversation' => 'ostatus:conversation', + ['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier', + 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag', + 'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; $data = array_merge($data, self::CreateNote($item)); @@ -433,6 +433,7 @@ class ActivityPub $data['inReplyTo'] = null; } + $data['uuid'] = $item['guid']; $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); if ($item["created"] != $item["edited"]) { From 6df6d824271475f7699ad28a0b9f5fc0b7008c3c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Sep 2018 08:52:07 +0000 Subject: [PATCH 49/97] We can now like and dislike --- mod/profile.php | 2 +- src/Model/Item.php | 6 +-- src/Object/Post.php | 2 +- src/Protocol/ActivityPub.php | 76 ++++++++++++++++++++++-------------- 4 files changed, 52 insertions(+), 34 deletions(-) diff --git a/mod/profile.php b/mod/profile.php index 0035ba26ad..8df63705e4 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -52,7 +52,7 @@ function profile_init(App $a) if (ActivityPub::isRequest()) { $user = DBA::selectFirst('user', ['uid'], ['nickname' => $which]); - if (DBM::isResult($user)) { + if (DBA::isResult($user)) { $data = ActivityPub::profile($user['uid']); echo json_encode($data); exit(); diff --git a/src/Model/Item.php b/src/Model/Item.php index e590c0c5c5..2926e460ab 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1081,9 +1081,9 @@ class Item extends BaseObject DBA::delete('item-delivery-data', ['iid' => $item['id']]); - if (!empty($item['iaid']) && !self::exists(['iaid' => $item['iaid'], 'deleted' => false])) { - DBA::delete('item-activity', ['id' => $item['iaid']], ['cascade' => false]); - } + //if (!empty($item['iaid']) && !self::exists(['iaid' => $item['iaid'], 'deleted' => false])) { + // DBA::delete('item-activity', ['id' => $item['iaid']], ['cascade' => false]); + //} if (!empty($item['icid']) && !self::exists(['icid' => $item['icid'], 'deleted' => false])) { DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]); } diff --git a/src/Object/Post.php b/src/Object/Post.php index 038ca270d7..39d9743b22 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -324,7 +324,7 @@ class Post extends BaseObject $owner_name_e = $this->getOwnerName(); // Disable features that aren't available in several networks - if (!in_array($item["network"], [Protocol::DFRN, Protocol::DIASPORA]) && isset($buttons["dislike"])) { + if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA]) && isset($buttons["dislike"])) { unset($buttons["dislike"]); $isevent = false; $tagger = ''; diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 415d714d9a..87889300c7 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -42,11 +42,11 @@ use Friendica\Util\LDSignature; * To-do: * * Receiver: - * - Activities: Update, Delete + * - Activities: Update, Delete (Activities/Notes) * - Object Types: Person, Tombstome * * Transmitter: - * - Activities: Announce + * - Activities: Announce, Delete Notes * - Object Tyoes: Person, Tombstone * * General: @@ -139,7 +139,12 @@ class ActivityPub $actor = JsonLD::fetchElement($activity, 'actor', 'id'); $profile = ActivityPub::fetchprofile($actor); - $item_profile = ActivityPub::fetchprofile($item['owner-link']); + $item_profile = ActivityPub::fetchprofile($item['author-link']); + $exclude[] = $item['author-link']; + + if ($item['gravity'] == GRAVITY_PARENT) { + $exclude[] = $item['owner-link']; + } $permissions = []; @@ -155,7 +160,7 @@ class ActivityPub if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) { $receiver = $item_profile['followers']; } - if ($receiver != $item['owner-link']) { + if (!in_array($receiver, $exclude)) { $permissions[$element][] = $receiver; } } @@ -217,7 +222,7 @@ class ActivityPub } } - $parents = Item::select(['author-link', 'owner-link'], ['parent' => $item['parent']]); + $parents = Item::select(['author-link', 'owner-link', 'gravity'], ['parent' => $item['parent']]); while ($parent = Item::fetch($parents)) { $profile = self::fetchprofile($parent['author-link']); if (!empty($profile) && empty($contacts[$profile['url']])) { @@ -225,6 +230,10 @@ class ActivityPub $contacts[$profile['url']] = $profile['url']; } + if ($item['gravity'] != GRAVITY_PARENT) { + continue; + } + $profile = self::fetchprofile($parent['owner-link']); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; @@ -250,13 +259,18 @@ class ActivityPub $inboxes = []; - $item_profile = ActivityPub::fetchprofile($item['owner-link']); + if ($item['gravity'] == GRAVITY_ACTIVITY) { + $item_profile = ActivityPub::fetchprofile($item['author-link']); + } else { + $item_profile = ActivityPub::fetchprofile($item['owner-link']); + } $elements = ['to', 'cc', 'bto', 'bcc']; foreach ($elements as $element) { if (empty($permissions[$element])) { continue; } + foreach ($permissions[$element] as $receiver) { if ($receiver == $item_profile['followers']) { $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid, @@ -276,14 +290,6 @@ class ActivityPub } } - if (!empty($item_profile['sharedinbox'])) { - unset($inboxes[$item_profile['sharedinbox']]); - } - - if (!empty($item_profile['inbox'])) { - unset($inboxes[$item_profile['inbox']]); - } - return $inboxes; } @@ -305,16 +311,14 @@ class ActivityPub $type = 'Reject'; } elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) { $type = 'TentativeAccept'; - } - - if ($item['deleted']) { - $type = 'Delete'; + } else { + $type = ''; } return $type; } - public static function createActivityFromItem($item_id) + public static function createActivityFromItem($item_id, $object_mode = false) { $item = Item::selectFirst([], ['id' => $item_id]); @@ -331,14 +335,24 @@ class ActivityPub } } - $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', - ['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier', - 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag', - 'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation', - 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; + $type = self::getTypeOfItem($item); - $data['id'] = $item['uri'] . '#activity'; - $data['type'] = self::getTypeOfItem($item);; + if (!$object_mode) { + $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', + ['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier', + 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag', + 'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation', + 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; + + if ($item['deleted']) { + $type = 'Undo'; + } + } else { + $data = []; + } + + $data['id'] = $item['uri'] . '#' . $type; + $data['type'] = $type; $data['actor'] = $item['author-link']; $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); @@ -347,20 +361,25 @@ class ActivityPub $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); } - $data['context_id'] = $item['parent']; $data['context'] = self::createConversationURLFromItem($item); $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); if (in_array($data['type'], ['Create', 'Update', 'Announce'])) { $data['object'] = self::CreateNote($item); + } elseif ($data['type'] == 'Undo') { + $data['object'] = self::createActivityFromItem($item_id, true); } else { $data['object'] = $item['thr-parent']; } $owner = User::getOwnerDataById($item['uid']); - return LDSignature::sign($data, $owner); + if (!$object_mode) { + return LDSignature::sign($data, $owner); + } else { + return $data; + } } public static function createObjectFromItemID($item_id) @@ -444,7 +463,6 @@ class ActivityPub $data['attributedTo'] = $item['author-link']; $data['actor'] = $item['author-link']; $data['sensitive'] = false; // - Query NSFW - $data['context_id'] = $item['parent']; $data['conversation'] = $data['context'] = self::createConversationURLFromItem($item); if (!empty($item['title'])) { From feeec908d30c660824a0adc77b3e61e50644c943 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Sep 2018 09:20:25 +0000 Subject: [PATCH 50/97] We can delete notes / changed credits --- src/Protocol/ActivityPub.php | 23 +++++++++++++++-------- src/Util/HTTPSignature.php | 3 +++ src/Util/LDSignature.php | 5 +++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 87889300c7..4d7657865c 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -34,10 +34,6 @@ use Friendica\Util\LDSignature; * * Digest: https://tools.ietf.org/html/rfc5843 * https://tools.ietf.org/html/draft-cavage-http-signatures-10#ref-15 - * https://github.com/digitalbazaar/php-json-ld - * - * Part of the code for HTTP signing is taken from the Osada project. - * https://framagit.org/macgirvin/osada * * To-do: * @@ -46,8 +42,8 @@ use Friendica\Util\LDSignature; * - Object Types: Person, Tombstome * * Transmitter: - * - Activities: Announce, Delete Notes - * - Object Tyoes: Person, Tombstone + * - Activities: Announce + * - Object Tyoes: Person * * General: * - Endpoints: Outbox, Follower, Following @@ -344,8 +340,10 @@ class ActivityPub 'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; - if ($item['deleted']) { + if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) { $type = 'Undo'; + } elseif ($item['deleted']) { + $type = 'Delete'; } } else { $data = []; @@ -365,7 +363,7 @@ class ActivityPub $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); - if (in_array($data['type'], ['Create', 'Update', 'Announce'])) { + if (in_array($data['type'], ['Create', 'Update', 'Announce', 'Delete'])) { $data['object'] = self::CreateNote($item); } elseif ($data['type'] == 'Undo') { $data['object'] = self::createActivityFromItem($item_id, true); @@ -441,9 +439,18 @@ class ActivityPub $type = 'Note'; } + if ($item['deleted']) { + $type = 'Tombstone'; + } + $data = []; $data['id'] = $item['uri']; $data['type'] = $type; + + if ($item['deleted']) { + return $data; + } + $data['summary'] = null; // Ignore by now if ($item['uri'] != $item['thr-parent']) { diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 8fa8566af3..aba280cf1d 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -16,6 +16,9 @@ use Friendica\Protocol\ActivityPub; * * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/Zotlabs/Web/HTTPSig.php * + * Other parts of the code for HTTP signing are taken from the Osada project. + * https://framagit.org/macgirvin/osada + * * @see https://tools.ietf.org/html/draft-cavage-http-signatures-07 */ diff --git a/src/Util/LDSignature.php b/src/Util/LDSignature.php index 6db66a52a5..6d6dd16f3a 100644 --- a/src/Util/LDSignature.php +++ b/src/Util/LDSignature.php @@ -6,6 +6,11 @@ use Friendica\Util\JsonLD; use Friendica\Util\DateTimeFormat; use Friendica\Protocol\ActivityPub; +/** + * @brief Implements JSON-LD signatures + * + * Ported from Osada: https://framagit.org/macgirvin/osada + */ class LDSignature { public static function isSigned($data) From 8c7e5bb776583ac97b31bc023fbc335b1a2b1251 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Sep 2018 17:29:31 +0000 Subject: [PATCH 51/97] all endpoints are now working --- mod/admin.php | 2 +- src/Model/Profile.php | 13 +++ src/Module/Followers.php | 38 ++++++++ src/Module/Following.php | 38 ++++++++ src/Module/Outbox.php | 38 ++++++++ src/Protocol/ActivityPub.php | 180 ++++++++++++++++++++++++++++++----- 6 files changed, 285 insertions(+), 24 deletions(-) create mode 100644 src/Module/Followers.php create mode 100644 src/Module/Following.php create mode 100644 src/Module/Outbox.php diff --git a/mod/admin.php b/mod/admin.php index d4fcc533f7..de7b78c084 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1478,7 +1478,7 @@ function admin_page_site(App $a) '$community_page_style' => ['community_page_style', L10n::t("Community pages for visitors"), Config::get('system','community_page_style'), L10n::t("Which community pages should be available for visitors. Local users always see both pages."), $community_page_style_choices], '$max_author_posts_community_page' => ['max_author_posts_community_page', L10n::t("Posts per user on community page"), Config::get('system','max_author_posts_community_page'), L10n::t("The maximum number of posts per user on the community page. \x28Not valid for 'Global Community'\x29")], '$ostatus_disabled' => ['ostatus_disabled', L10n::t("Enable OStatus support"), !Config::get('system','ostatus_disabled'), L10n::t("Provide built-in OStatus \x28StatusNet, GNU Social etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")], - '$ostatus_full_threads' => ['ostatus_full_threads', L10n::t("Only import OStatus threads from our contacts"), Config::get('system','ostatus_full_threads'), L10n::t("Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.")], + '$ostatus_full_threads' => ['ostatus_full_threads', L10n::t("Only import OStatus/ActivityPub threads from our contacts"), Config::get('system','ostatus_full_threads'), L10n::t("Normally we import every content from our OStatus and ActivityPub contacts. With this option we only store threads that are started by a contact that is known on our system.")], '$ostatus_not_able' => L10n::t("OStatus support can only be enabled if threading is enabled."), '$diaspora_able' => $diaspora_able, '$diaspora_not_able' => L10n::t("Diaspora support can't be enabled because Friendica was installed into a sub directory."), diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 3a014517da..d25bdd4fad 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -28,6 +28,19 @@ require_once 'include/dba.php'; class Profile { + /** + * @brief Returns default profile for a given user id + * + * @param integer User ID + * + * @return array Profile data + */ + public static function getProfileForUser($uid) + { + $profile = DBA::selectFirst('profile', [], ['uid' => $uid, 'is-default' => true]); + return $profile; + } + /** * @brief Returns a formatted location string from the given profile array * diff --git a/src/Module/Followers.php b/src/Module/Followers.php new file mode 100644 index 0000000000..80ad68def4 --- /dev/null +++ b/src/Module/Followers.php @@ -0,0 +1,38 @@ +argv[1])) { + System::httpExit(404); + } + + $owner = User::getOwnerDataByNick($a->argv[1]); + if (empty($owner)) { + System::httpExit(404); + } + + $page = defaults($_REQUEST, 'page', null); + + $followers = ActivityPub::getFollowers($owner, $page); + + header('Content-Type: application/activity+json'); + echo json_encode($followers); + exit(); + } +} diff --git a/src/Module/Following.php b/src/Module/Following.php new file mode 100644 index 0000000000..091a505cc9 --- /dev/null +++ b/src/Module/Following.php @@ -0,0 +1,38 @@ +argv[1])) { + System::httpExit(404); + } + + $owner = User::getOwnerDataByNick($a->argv[1]); + if (empty($owner)) { + System::httpExit(404); + } + + $page = defaults($_REQUEST, 'page', null); + + $Following = ActivityPub::getFollowing($owner, $page); + + header('Content-Type: application/activity+json'); + echo json_encode($Following); + exit(); + } +} diff --git a/src/Module/Outbox.php b/src/Module/Outbox.php new file mode 100644 index 0000000000..722315145f --- /dev/null +++ b/src/Module/Outbox.php @@ -0,0 +1,38 @@ +argv[1])) { + System::httpExit(404); + } + + $owner = User::getOwnerDataByNick($a->argv[1]); + if (empty($owner)) { + System::httpExit(404); + } + + $page = defaults($_REQUEST, 'page', null); + + $Outbox = ActivityPub::getOutbox($owner, $page); + + header('Content-Type: application/activity+json'); + echo json_encode($Outbox); + exit(); + } +} diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 4d7657865c..fa88847f37 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -13,6 +13,7 @@ use Friendica\Core\Protocol; use Friendica\Model\Conversation; use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\Profile; use Friendica\Model\Term; use Friendica\Model\User; use Friendica\Util\DateTimeFormat; @@ -21,6 +22,7 @@ use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Util\JsonLD; use Friendica\Util\LDSignature; +use Friendica\Core\Config; /** * @brief ActivityPub Protocol class @@ -35,24 +37,32 @@ use Friendica\Util\LDSignature; * Digest: https://tools.ietf.org/html/rfc5843 * https://tools.ietf.org/html/draft-cavage-http-signatures-10#ref-15 * + * Mastodon implementation of supported activities: + * https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/activity.rb#L26 + * * To-do: * * Receiver: - * - Activities: Update, Delete (Activities/Notes) + * - Activities: Update (Notes, Person), Delete (Person, Activities, Notes) * - Object Types: Person, Tombstome * * Transmitter: - * - Activities: Announce + * - Activities: Announce, Update (Person) * - Object Tyoes: Person * * General: - * - Endpoints: Outbox, Follower, Following - * - General cleanup * - Queueing unsucessful deliveries + * - Event support + * - Polling the outboxes for missing content? */ class ActivityPub { const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; + const CONTEXT = ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', + ['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier', + 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag', + 'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation', + 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]; public static function isRequest() { @@ -60,6 +70,124 @@ class ActivityPub stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/ld+json'); } + public static function getFollowers($owner, $page = null) + { + $condition = ['rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'], + 'self' => false, 'hidden' => false, 'archive' => false, 'pending' => false]; + $count = DBA::count('contact', $condition); + + $data = ['@context' => self::CONTEXT]; + $data['id'] = System::baseUrl() . '/followers/' . $owner['nickname']; + $data['type'] = 'OrderedCollection'; + $data['totalItems'] = $count; + + // When we hide our friends we will only show the pure number but don't allow more. + $profile = Profile::getProfileForUser($owner['uid']); + if (!empty($profile['hide-friends'])) { + return $data; + } + + if (empty($page)) { + $data['first'] = System::baseUrl() . '/followers/' . $owner['nickname'] . '?page=1'; + } else { + $list = []; + + $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]); + while ($contact = DBA::fetch($contacts)) { + $list[] = $contact['url']; + } + + if (!empty($list)) { + $data['next'] = System::baseUrl() . '/followers/' . $owner['nickname'] . '?page=' . ($page + 1); + } + + $data['partOf'] = System::baseUrl() . '/followers/' . $owner['nickname']; + + $data['orderedItems'] = $list; + } + + return $data; + } + + public static function getFollowing($owner, $page = null) + { + $condition = ['rel' => [Contact::SHARING, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'], + 'self' => false, 'hidden' => false, 'archive' => false, 'pending' => false]; + $count = DBA::count('contact', $condition); + + $data = ['@context' => self::CONTEXT]; + $data['id'] = System::baseUrl() . '/following/' . $owner['nickname']; + $data['type'] = 'OrderedCollection'; + $data['totalItems'] = $count; + + // When we hide our friends we will only show the pure number but don't allow more. + $profile = Profile::getProfileForUser($owner['uid']); + if (!empty($profile['hide-friends'])) { + return $data; + } + + if (empty($page)) { + $data['first'] = System::baseUrl() . '/following/' . $owner['nickname'] . '?page=1'; + } else { + $list = []; + + $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]); + while ($contact = DBA::fetch($contacts)) { + $list[] = $contact['url']; + } + + if (!empty($list)) { + $data['next'] = System::baseUrl() . '/following/' . $owner['nickname'] . '?page=' . ($page + 1); + } + + $data['partOf'] = System::baseUrl() . '/following/' . $owner['nickname']; + + $data['orderedItems'] = $list; + } + + return $data; + } + + public static function getOutbox($owner, $page = null) + { + $public_contact = Contact::getIdForURL($owner['url'], 0, true); + + $condition = ['uid' => $owner['uid'], 'contact-id' => $owner['id'], 'author-id' => $public_contact, + 'wall' => true, 'private' => false, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], + 'deleted' => false, 'visible' => true]; + $count = DBA::count('item', $condition); + + $data = ['@context' => self::CONTEXT]; + $data['id'] = System::baseUrl() . '/outbox/' . $owner['nickname']; + $data['type'] = 'OrderedCollection'; + $data['totalItems'] = $count; + + if (empty($page)) { + $data['first'] = System::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=1'; + } else { + $list = []; + + $condition['parent-network'] = Protocol::NATIVE_SUPPORT; + + $items = Item::select(['id'], $condition, ['limit' => [($page - 1) * 20, 20], 'order' => ['created' => true]]); + while ($item = Item::fetch($items)) { + $object = self::createObjectFromItemID($item['id']); + unset($object['@context']); + $list[] = $object; + } + + if (!empty($list)) { + $data['next'] = System::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=' . ($page + 1); + } + + $data['partOf'] = System::baseUrl() . '/outbox/' . $owner['nickname']; + + $data['orderedItems'] = $list; + } + + return $data; + } + /** * Return the ActivityPub profile of the given user * @@ -186,7 +314,7 @@ class ActivityPub if ($term['type'] != TERM_MENTION) { continue; } - $profile = self::fetchprofile($term['url']); + $profile = self::fetchprofile($term['url'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; $contacts[$profile['url']] = $profile['url']; @@ -218,9 +346,11 @@ class ActivityPub } } +// It is to decide whether we should include all profiles in a thread to the list of receivers +/* $parents = Item::select(['author-link', 'owner-link', 'gravity'], ['parent' => $item['parent']]); while ($parent = Item::fetch($parents)) { - $profile = self::fetchprofile($parent['author-link']); + $profile = self::fetchprofile($parent['author-link'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; $contacts[$profile['url']] = $profile['url']; @@ -230,14 +360,14 @@ class ActivityPub continue; } - $profile = self::fetchprofile($parent['owner-link']); + $profile = self::fetchprofile($parent['owner-link'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; $contacts[$profile['url']] = $profile['url']; } } DBA::close($parents); - +*/ if (empty($data['to'])) { $data['to'] = $data['cc']; $data['cc'] = []; @@ -334,11 +464,7 @@ class ActivityPub $type = self::getTypeOfItem($item); if (!$object_mode) { - $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', - ['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier', - 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag', - 'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation', - 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; + $data = ['@context' => self::CONTEXT]; if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) { $type = 'Undo'; @@ -388,15 +514,9 @@ class ActivityPub return false; } - $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', - ['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier', - 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag', - 'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation', - 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]]; - + $data = ['@context' => self::CONTEXT]; $data = array_merge($data, self::CreateNote($item)); - return $data; } @@ -579,7 +699,6 @@ class ActivityPub if (!$ret['success'] || empty($ret['body'])) { return; } - return json_decode($ret['body'], true); } @@ -622,13 +741,20 @@ class ActivityPub return false; } - public static function fetchprofile($url, $update = false) + /** + * Fetches a profile form a given url + * + * @param string $url profile url + * @param boolean $update true = always update, false = never update, null = update when not found + * @return array profile array + */ + public static function fetchprofile($url, $update = null) { if (empty($url)) { return false; } - if (!$update) { + if (empty($update)) { $apcontact = DBA::selectFirst('apcontact', [], ['url' => $url]); if (DBA::isResult($apcontact)) { return $apcontact; @@ -643,6 +769,10 @@ class ActivityPub if (DBA::isResult($apcontact)) { return $apcontact; } + + if (!is_null($update)) { + return false; + } } if (empty(parse_url($url, PHP_URL_SCHEME))) { @@ -1354,6 +1484,10 @@ class ActivityPub private static function fetchMissingActivity($url, $child) { + if (Config::get('system', 'ostatus_full_threads')) { + return; + } + $object = ActivityPub::fetchContent($url); if (empty($object)) { logger('Activity ' . $url . ' was not fetchable, aborting.'); From 094c27add682c861604425be7a08fa168761e4f1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Sep 2018 19:25:20 +0000 Subject: [PATCH 52/97] Update person, undo activity and improved security checks --- src/Protocol/ActivityPub.php | 91 +++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 12 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index fa88847f37..edec1ea2df 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -43,16 +43,30 @@ use Friendica\Core\Config; * To-do: * * Receiver: - * - Activities: Update (Notes, Person), Delete (Person, Activities, Notes) - * - Object Types: Person, Tombstome + * - Update Note + * - Delete Note + * - Delete Person + * - Undo Announce + * - Reject Follow + * - Undo Accept + * - Undo Follow + * - Add + * - Create Image + * - Create Video + * - Event + * - Remove + * - Block + * - Flag * * Transmitter: - * - Activities: Announce, Update (Person) - * - Object Tyoes: Person + * - Announce + * - Undo Announce + * - Update Person + * - Reject Follow + * - Event * * General: * - Queueing unsucessful deliveries - * - Event support * - Polling the outboxes for missing content? */ class ActivityPub @@ -270,7 +284,7 @@ class ActivityPub $exclude[] = $item['owner-link']; } - $permissions = []; + $permissions['to'][] = $actor; $elements = ['to', 'cc', 'bto', 'bcc']; foreach ($elements as $element) { @@ -280,6 +294,7 @@ class ActivityPub if (is_string($activity[$element])) { $activity[$element] = [$activity[$element]]; } + foreach ($activity[$element] as $receiver) { if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) { $receiver = $item_profile['followers']; @@ -346,10 +361,13 @@ class ActivityPub } } -// It is to decide whether we should include all profiles in a thread to the list of receivers -/* $parents = Item::select(['author-link', 'owner-link', 'gravity'], ['parent' => $item['parent']]); while ($parent = Item::fetch($parents)) { + // Don't include data from future posts + if ($parent['id'] >= $item['id']) { + continue; + } + $profile = self::fetchprofile($parent['author-link'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; @@ -367,7 +385,7 @@ class ActivityPub } } DBA::close($parents); -*/ + if (empty($data['to'])) { $data['to'] = $data['cc']; $data['cc'] = []; @@ -952,7 +970,7 @@ class ActivityPub } } - private static function prepareObjectData($activity, $uid, $trust_source) + private static function prepareObjectData($activity, $uid, &$trust_source) { $actor = JsonLD::fetchElement($activity, 'actor', 'id'); if (empty($actor)) { @@ -982,12 +1000,18 @@ class ActivityPub } // Fetch the content only on activities where this matters - if (in_array($activity['type'], ['Create', 'Update', 'Announce'])) { + if (in_array($activity['type'], ['Create', 'Announce'])) { $object_data = self::fetchObject($object_url, $activity['object'], $trust_source); if (empty($object_data)) { logger("Object data couldn't be processed", LOGGER_DEBUG); return []; } + // We had been able to retrieve the object data - so we can trust the source + $trust_source = true; + } elseif ($activity['type'] == 'Update') { + $object_data = []; + $object_data['object_type'] = JsonLD::fetchElement($activity, 'object', 'type'); + $object_data['object'] = $activity['object']; } elseif ($activity['type'] == 'Accept') { $object_data = []; $object_data['object_type'] = JsonLD::fetchElement($activity, 'object', 'type'); @@ -995,7 +1019,11 @@ class ActivityPub } elseif ($activity['type'] == 'Undo') { $object_data = []; $object_data['object_type'] = JsonLD::fetchElement($activity, 'object', 'type'); - $object_data['object'] = JsonLD::fetchElement($activity, 'object', 'object'); + if ($object_data['object_type'] == 'Follow') { + $object_data['object'] = JsonLD::fetchElement($activity, 'object', 'object'); + } else { + $object_data['object'] = $activity['object']; + } } elseif (in_array($activity['type'], ['Like', 'Dislike'])) { // Create a mostly empty array out of the activity data (instead of the object). // This way we later don't have to check for the existence of ech individual array element. @@ -1045,12 +1073,17 @@ class ActivityPub logger('Processing activity: ' . $activity['type'], LOGGER_DEBUG); + // $trust_source is called by reference and is set to true if the content was retrieved successfully $object_data = self::prepareObjectData($activity, $uid, $trust_source); if (empty($object_data)) { logger('No object data found', LOGGER_DEBUG); return; } + if (!trust_source) { + logger('No trust for activity type "' . $activity['type'] . '", so we quit now.', LOGGER_DEBUG); + } + switch ($activity['type']) { case 'Create': case 'Announce': @@ -1066,6 +1099,9 @@ class ActivityPub break; case 'Update': + if (in_array($object_data['object_type'], ['Person', 'Organization', 'Service', 'Group', 'Application'])) { + self::updatePerson($object_data, $body); + } break; case 'Delete': @@ -1084,6 +1120,8 @@ class ActivityPub case 'Undo': if ($object_data['object_type'] == 'Follow') { self::undoFollowUser($object_data); + } elseif (in_array($object_data['object_type'], ['Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept'])) { + self::undoActivity($object_data); } break; @@ -1553,6 +1591,15 @@ class ActivityPub logger('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']); } + private static function updatePerson($activity) + { + if (empty($activity['object']['id'])) { + return; + } + + self::fetchprofile($activity['object']['id'], true); + } + private static function acceptFollowUser($activity) { $uid = self::getUserOfObject($activity['object']); @@ -1580,6 +1627,26 @@ class ActivityPub logger('Accept contact request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG); } + private static function undoActivity($activity) + { + $activity_url = JsonLD::fetchElement($activity, 'object', 'id'); + if (empty($activity_url)) { + return; + } + + $actor = JsonLD::fetchElement($activity, 'object', 'actor'); + if (empty($actor)) { + return; + } + + $author_id = Contact::getIdForURL($actor); + if (empty($author_id)) { + return; + } + + Item::delete(['uri' => $activity_url, 'author-id' => $author_id, 'gravity' => GRAVITY_ACTIVITY]); + } + private static function undoFollowUser($activity) { $uid = self::getUserOfObject($activity['object']); From b386add31505af206ad1f5dd1f98e7011bac81e5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 23 Sep 2018 22:12:12 +0000 Subject: [PATCH 53/97] Switch contacts from OStatus to ActivityPub --- src/Protocol/ActivityPub.php | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index edec1ea2df..d4c904eb18 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -857,6 +857,19 @@ class ActivityPub DBA::update('apcontact', $apcontact, ['url' => $url], true); + // Update some data in the contact table with various ways to catch them all + $contact_fields = ['name' => $apcontact['name'], 'about' => $apcontact['about']]; + DBA::update('contact', $contact_fields, ['nurl' => normalise_link($url)]); + + $contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => normalise_link($url)]); + while ($contact = DBA::fetch($contacts)) { + Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']); + } + DBA::close($contacts); + + // Update the gcontact table + DBA::update('gcontact', $contact_fields, ['nurl' => normalise_link($url)]); + return $apcontact; } @@ -1203,9 +1216,50 @@ class ActivityPub $receivers['uid:' . $contact['uid']] = $contact['uid']; } } + + self::switchContacts($receivers, $actor); + return $receivers; } + private static function switchContact($cid, $uid, $url) + { + $profile = ActivityPub::probeProfile($url); + if (empty($profile)) { + return; + } + + logger('Switch contact ' . $cid . ' (' . $profile['url'] . ') for user ' . $uid . ' from OStatus to ActivityPub'); + + $photo = $profile['photo']; + unset($profile['photo']); + unset($profile['baseurl']); + + $profile['nurl'] = normalise_link($profile['url']); + DBA::update('contact', $profile, ['id' => $cid]); + + Contact::updateAvatar($photo, $uid, $cid); + } + + private static function switchContacts($receivers, $actor) + { + if (empty($actor)) { + return; + } + + foreach ($receivers as $receiver) { + $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'nurl' => normalise_link($actor)]); + if (DBA::isResult($contact)) { + self::switchContact($contact['id'], $receiver, $actor); + } + + $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'alias' => [normalise_link($actor), $actor]]); + if (DBA::isResult($contact)) { + self::switchContact($contact['id'], $receiver, $actor); + } + } + } + private static function addActivityFields($object_data, $activity) { if (!empty($activity['published']) && empty($object_data['published'])) { From 59c137b9467c9e06ca851af8372ac51762d2c4c9 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 24 Sep 2018 05:35:47 +0000 Subject: [PATCH 54/97] Variable fix --- src/Protocol/ActivityPub.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index d4c904eb18..4697e3f8fc 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -68,6 +68,8 @@ use Friendica\Core\Config; * General: * - Queueing unsucessful deliveries * - Polling the outboxes for missing content? + * - Checking signature fails + * - Possibly using the LD-JSON parser */ class ActivityPub { @@ -1093,7 +1095,7 @@ class ActivityPub return; } - if (!trust_source) { + if (!$trust_source) { logger('No trust for activity type "' . $activity['type'] . '", so we quit now.', LOGGER_DEBUG); } From 5e3f71680c7ff4b018bb9929b9127dc2424eb34f Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 24 Sep 2018 21:47:10 +0000 Subject: [PATCH 55/97] Disabled logging --- src/Module/Inbox.php | 4 +++- src/Protocol/ActivityPub.php | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 891211186a..4fc450d85a 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -25,6 +25,8 @@ class Inbox extends BaseModule System::httpExit(400); } +// Enable for test purposes +/* if (HTTPSignature::getSigner($postdata, $_SERVER)) { $filename = 'signed-activitypub'; } else { @@ -35,7 +37,7 @@ class Inbox extends BaseModule file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); logger('Incoming message stored under ' . $tempfile); - +*/ if (!empty($a->argv[1])) { $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]); if (!DBA::isResult($user)) { diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 4697e3f8fc..62d6dac0f8 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -363,7 +363,7 @@ class ActivityPub } } - $parents = Item::select(['author-link', 'owner-link', 'gravity'], ['parent' => $item['parent']]); + $parents = Item::select(['id', 'author-link', 'owner-link', 'gravity'], ['parent' => $item['parent']]); while ($parent = Item::fetch($parents)) { // Don't include data from future posts if ($parent['id'] >= $item['id']) { @@ -1535,6 +1535,11 @@ class ActivityPub private static function postItem($activity, $item, $body) { /// @todo What to do with $activity['context']? + if (empty($activity['author'])) + logger('Empty author'); + + if (empty($activity['owner'])) + logger('Empty owner'); $item['network'] = Protocol::ACTIVITYPUB; $item['private'] = !in_array(0, $activity['receiver']); From e91a1dfa8ea8778926acb05c317761de22d7ea24 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 25 Sep 2018 21:18:37 +0000 Subject: [PATCH 56/97] Cleaned code --- src/Protocol/ActivityPub.php | 136 ++++++++++++----------------------- src/Util/JsonLD.php | 15 ---- src/Util/LDSignature.php | 16 ++--- 3 files changed, 53 insertions(+), 114 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 62d6dac0f8..a41987f122 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -566,7 +566,7 @@ class ActivityPub if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) { $conversation_uri = $conversation['conversation-uri']; } else { - $conversation_uri = $item['parent-uri']; + $conversation_uri = str_replace('/object/', '/context/', $item['parent-uri']); } return $conversation_uri; } @@ -938,6 +938,9 @@ class ActivityPub if (LDSignature::isSigned($activity)) { $ld_signer = LDSignature::getSigner($activity); + if (empty($ld_signer)) { + logger('Invalid JSON-LD signature from ' . $actor, LOGGER_DEBUG); + } if (!empty($ld_signer && ($actor == $http_signer))) { logger('The HTTP and the JSON-LD signature belong to ' . $ld_signer, LOGGER_DEBUG); $trust_source = true; @@ -1005,52 +1008,33 @@ class ActivityPub logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG); - if (is_string($activity['object'])) { - $object_url = $activity['object']; - } elseif (!empty($activity['object']['id'])) { - $object_url = $activity['object']['id']; - } else { + $object_id = JsonLD::fetchElement($activity, 'object', 'id'); + if (empty($object_id)) { logger('No object found', LOGGER_DEBUG); return []; } // Fetch the content only on activities where this matters if (in_array($activity['type'], ['Create', 'Announce'])) { - $object_data = self::fetchObject($object_url, $activity['object'], $trust_source); + $object_data = self::fetchObject($object_id, $activity['object'], $trust_source); if (empty($object_data)) { logger("Object data couldn't be processed", LOGGER_DEBUG); return []; } // We had been able to retrieve the object data - so we can trust the source $trust_source = true; - } elseif ($activity['type'] == 'Update') { - $object_data = []; - $object_data['object_type'] = JsonLD::fetchElement($activity, 'object', 'type'); - $object_data['object'] = $activity['object']; - } elseif ($activity['type'] == 'Accept') { - $object_data = []; - $object_data['object_type'] = JsonLD::fetchElement($activity, 'object', 'type'); - $object_data['object'] = JsonLD::fetchElement($activity, 'object', 'actor'); - } elseif ($activity['type'] == 'Undo') { - $object_data = []; - $object_data['object_type'] = JsonLD::fetchElement($activity, 'object', 'type'); - if ($object_data['object_type'] == 'Follow') { - $object_data['object'] = JsonLD::fetchElement($activity, 'object', 'object'); - } else { - $object_data['object'] = $activity['object']; - } } elseif (in_array($activity['type'], ['Like', 'Dislike'])) { // Create a mostly empty array out of the activity data (instead of the object). // This way we later don't have to check for the existence of ech individual array element. - $object_data = self::processCommonData($activity); + $object_data = self::ProcessObject($activity); $object_data['name'] = $activity['type']; $object_data['author'] = $activity['actor']; - $object_data['object'] = $object_url; - } elseif ($activity['type'] == 'Follow') { - $object_data['id'] = $activity['id']; - $object_data['object'] = $object_url; + $object_data['object'] = $object_id; } else { $object_data = []; + $object_data['id'] = $activity['id']; + $object_data['object'] = $activity['object']; + $object_data['object_type'] = JsonLD::fetchElement($activity, 'object', 'type'); } $object_data = self::addActivityFields($object_data, $activity); @@ -1059,6 +1043,8 @@ class ActivityPub $object_data['owner'] = $actor; $object_data['receiver'] = array_merge(defaults($object_data, 'receiver', []), $receivers); + logger('Processing ' . $object_data['type'] . ' ' . $object_data['object_type'] . ' ' . $object_data['id'], LOGGER_DEBUG); + return $object_data; } @@ -1080,14 +1066,6 @@ class ActivityPub } - // Non standard - // title, atomUri, context_id, statusnetConversationId - - // To-Do? - // context, location, signature; - - logger('Processing activity: ' . $activity['type'], LOGGER_DEBUG); - // $trust_source is called by reference and is set to true if the content was retrieved successfully $object_data = self::prepareObjectData($activity, $uid, $trust_source); if (empty($object_data)) { @@ -1282,18 +1260,18 @@ class ActivityPub return $object_data; } - private static function fetchObject($object_url, $object = [], $trust_source = false) + private static function fetchObject($object_id, $object = [], $trust_source = false) { if (!$trust_source || is_string($object)) { - $data = self::fetchContent($object_url); + $data = self::fetchContent($object_id); if (empty($data)) { - logger('Empty content for ' . $object_url . ', check if content is available locally.', LOGGER_DEBUG); - $data = $object_url; + logger('Empty content for ' . $object_id . ', check if content is available locally.', LOGGER_DEBUG); + $data = $object_id; } else { - logger('Fetched content for ' . $object_url, LOGGER_DEBUG); + logger('Fetched content for ' . $object_id, LOGGER_DEBUG); } } else { - logger('Using original object for url ' . $object_url, LOGGER_DEBUG); + logger('Using original object for url ' . $object_id, LOGGER_DEBUG); $data = $object; } @@ -1303,29 +1281,20 @@ class ActivityPub logger('Object with url ' . $data . ' was not found locally.', LOGGER_DEBUG); return false; } - logger('Using already stored item for url ' . $object_url, LOGGER_DEBUG); + logger('Using already stored item for url ' . $object_id, LOGGER_DEBUG); $data = self::CreateNote($item); } if (empty($data['type'])) { logger('Empty type', LOGGER_DEBUG); return false; - } else { - $type = $data['type']; - logger('Type ' . $type, LOGGER_DEBUG); } - if (in_array($type, ['Note', 'Article', 'Video'])) { - $common = self::processCommonData($data); - } - - switch ($type) { + switch ($data['type']) { case 'Note': - return array_merge($common, self::processNote($data)); case 'Article': - return array_merge($common, self::processArticle($data)); case 'Video': - return array_merge($common, self::processVideo($data)); + return self::ProcessObject($data); case 'Announce': if (empty($data['object'])) { @@ -1343,20 +1312,20 @@ class ActivityPub } } - private static function processCommonData(&$object) + private static function ProcessObject(&$object) { if (empty($object['id'])) { return false; } $object_data = []; - $object_data['type'] = $object['type']; - $object_data['uri'] = $object['id']; + $object_data['object_type'] = $object['type']; + $object_data['id'] = $object['id']; if (!empty($object['inReplyTo'])) { $object_data['reply-to-uri'] = JsonLD::fetchElement($object, 'inReplyTo', 'id'); } else { - $object_data['reply-to-uri'] = $object_data['uri']; + $object_data['reply-to-uri'] = $object_data['id']; } $object_data['published'] = defaults($object, 'published', null); @@ -1366,8 +1335,13 @@ class ActivityPub $object_data['published'] = $object_data['updated']; } + $actor = JsonLD::fetchElement($object, 'attributedTo', 'id'); + if (empty($actor)) { + $actor = defaults($object, 'actor', null); + } + $object_data['uuid'] = defaults($object, 'uuid', null); - $object_data['owner'] = $object_data['author'] = JsonLD::fetchElement($object, 'attributedTo', 'id'); + $object_data['owner'] = $object_data['author'] = $actor; $object_data['context'] = defaults($object, 'context', null); $object_data['conversation'] = defaults($object, 'conversation', null); $object_data['sensitive'] = defaults($object, 'sensitive', null); @@ -1383,18 +1357,15 @@ class ActivityPub $object_data['alternate-url'] = JsonLD::fetchElement($object, 'url', 'href'); $object_data['receiver'] = self::getReceivers($object, $object_data['owner']); + // Common object data: + // Unhandled // @context, type, actor, signature, mediaType, duration, replies, icon // Also missing: (Defined in the standard, but currently unused) // audience, preview, endTime, startTime, generator, image - return $object_data; - } - - private static function processNote($object) - { - $object_data = []; + // Data in Notes: // To-Do? // emoji, atomUri, inReplyToAtomUri @@ -1403,19 +1374,7 @@ class ActivityPub // contentMap, announcement_count, announcements, context_id, likes, like_count // inReplyToStatusId, shares, quoteUrl, statusnetConversationId - return $object_data; - } - - private static function processArticle($object) - { - $object_data = []; - - return $object_data; - } - - private static function processVideo($object) - { - $object_data = []; + // Data in video: // To-Do? // category, licence, language, commentsEnabled @@ -1424,6 +1383,7 @@ class ActivityPub // views, waitTranscoding, state, support, subtitleLanguage // likes, dislikes, shares, comments + return $object_data; } @@ -1448,11 +1408,6 @@ class ActivityPub $tag_text .= ','; } - if (empty($tag['href'])) { - //$tag['href'] - logger('Blubb!'); - } - $tag_text .= substr($tag['name'], 0, 1) . '[url=' . $tag['href'] . ']' . substr($tag['name'], 1) . '[/url]'; } } @@ -1494,7 +1449,7 @@ class ActivityPub $item['verb'] = ACTIVITY_POST; $item['parent-uri'] = $activity['reply-to-uri']; - if ($activity['reply-to-uri'] == $activity['uri']) { + if ($activity['reply-to-uri'] == $activity['id']) { $item['gravity'] = GRAVITY_PARENT; $item['object-type'] = ACTIVITY_OBJ_NOTE; } else { @@ -1502,7 +1457,7 @@ class ActivityPub $item['object-type'] = ACTIVITY_OBJ_COMMENT; } - if (($activity['uri'] != $activity['reply-to-uri']) && !Item::exists(['uri' => $activity['reply-to-uri']])) { + if (($activity['id'] != $activity['reply-to-uri']) && !Item::exists(['uri' => $activity['reply-to-uri']])) { logger('Parent ' . $activity['reply-to-uri'] . ' not found. Try to refetch it.'); self::fetchMissingActivity($activity['reply-to-uri'], $activity); } @@ -1545,7 +1500,7 @@ class ActivityPub $item['private'] = !in_array(0, $activity['receiver']); $item['author-id'] = Contact::getIdForURL($activity['author'], 0, true); $item['owner-id'] = Contact::getIdForURL($activity['owner'], 0, true); - $item['uri'] = $activity['uri']; + $item['uri'] = $activity['id']; $item['created'] = $activity['published']; $item['edited'] = $activity['updated']; $item['guid'] = $activity['uuid']; @@ -1620,7 +1575,8 @@ class ActivityPub private static function followUser($activity) { - $uid = self::getUserOfObject($activity['object']); + $actor = JsonLD::fetchElement($activity, 'object', 'id'); + $uid = self::getUserOfObject($actor); if (empty($uid)) { return; } @@ -1663,7 +1619,8 @@ class ActivityPub private static function acceptFollowUser($activity) { - $uid = self::getUserOfObject($activity['object']); + $actor = JsonLD::fetchElement($activity, 'object', 'actor'); + $uid = self::getUserOfObject($actor); if (empty($uid)) { return; } @@ -1710,7 +1667,8 @@ class ActivityPub private static function undoFollowUser($activity) { - $uid = self::getUserOfObject($activity['object']); + $object = JsonLD::fetchElement($activity, 'object', 'object'); + $uid = self::getUserOfObject($object); if (empty($uid)) { return; } diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 600896715a..d3c101120b 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -40,25 +40,10 @@ class JsonLD return $data; } - private static function objectify($element) - { - if (is_array($element)) { - $keys = array_keys($element); - if (is_int(array_pop($keys))) { - return array_map('objectify', $element); - } else { - return (object)array_map('objectify', $element); - } - } else { - return $element; - } - } - public static function normalize($json) { jsonld_set_document_loader('Friendica\Util\JsonLD::documentLoader'); -// $jsonobj = array_map('Friendica\Util\JsonLD::objectify', $json); $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); return jsonld_normalize($jsonobj, array('algorithm' => 'URDNA2015', 'format' => 'application/nquads')); diff --git a/src/Util/LDSignature.php b/src/Util/LDSignature.php index 6d6dd16f3a..51086ac3e1 100644 --- a/src/Util/LDSignature.php +++ b/src/Util/LDSignature.php @@ -82,25 +82,21 @@ class LDSignature return array_merge($data, ['signature' => $options]); } - private static function signable_data($data) { unset($data['signature']); return $data; } - private static function signable_options($options) { $newopts = ['@context' => 'https://w3id.org/identity/v1']; - if (!empty($options)) { - foreach ($options as $k => $v) { - if (!in_array($k, ['type', 'id', 'signatureValue'])) { - $newopts[$k] = $v; - } - } - } - return $newopts; + + unset($options['type']); + unset($options['id']); + unset($options['signatureValue']); + + return array_merge($newopts, $options); } private static function hash($obj) From 67d2f8594cb7bcf1935fb5b2863f8cd586e7fad9 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 26 Sep 2018 07:42:40 +0000 Subject: [PATCH 57/97] Some more clean up --- src/Protocol/ActivityPub.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index a41987f122..9463c783d1 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -68,7 +68,6 @@ use Friendica\Core\Config; * General: * - Queueing unsucessful deliveries * - Polling the outboxes for missing content? - * - Checking signature fails * - Possibly using the LD-JSON parser */ class ActivityPub @@ -849,6 +848,7 @@ class ActivityPub $apcontact['baseurl'] = Network::unparseURL($parts); } else { $apcontact['addr'] = null; + $apcontact['baseurl'] = null; } if ($apcontact['url'] == $apcontact['alias']) { @@ -872,6 +872,8 @@ class ActivityPub // Update the gcontact table DBA::update('gcontact', $contact_fields, ['nurl' => normalise_link($url)]); + logger('Updated profile for ' . $url, LOGGER_DEBUG); + return $apcontact; } @@ -1030,6 +1032,7 @@ class ActivityPub $object_data['name'] = $activity['type']; $object_data['author'] = $activity['actor']; $object_data['object'] = $object_id; + $object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type } else { $object_data = []; $object_data['id'] = $activity['id']; @@ -1323,9 +1326,9 @@ class ActivityPub $object_data['id'] = $object['id']; if (!empty($object['inReplyTo'])) { - $object_data['reply-to-uri'] = JsonLD::fetchElement($object, 'inReplyTo', 'id'); + $object_data['reply-to-id'] = JsonLD::fetchElement($object, 'inReplyTo', 'id'); } else { - $object_data['reply-to-uri'] = $object_data['id']; + $object_data['reply-to-id'] = $object_data['id']; } $object_data['published'] = defaults($object, 'published', null); @@ -1447,9 +1450,9 @@ class ActivityPub { $item = []; $item['verb'] = ACTIVITY_POST; - $item['parent-uri'] = $activity['reply-to-uri']; + $item['parent-uri'] = $activity['reply-to-id']; - if ($activity['reply-to-uri'] == $activity['id']) { + if ($activity['reply-to-id'] == $activity['id']) { $item['gravity'] = GRAVITY_PARENT; $item['object-type'] = ACTIVITY_OBJ_NOTE; } else { @@ -1457,9 +1460,9 @@ class ActivityPub $item['object-type'] = ACTIVITY_OBJ_COMMENT; } - if (($activity['id'] != $activity['reply-to-uri']) && !Item::exists(['uri' => $activity['reply-to-uri']])) { - logger('Parent ' . $activity['reply-to-uri'] . ' not found. Try to refetch it.'); - self::fetchMissingActivity($activity['reply-to-uri'], $activity); + if (($activity['id'] != $activity['reply-to-id']) && !Item::exists(['uri' => $activity['reply-to-id']])) { + logger('Parent ' . $activity['reply-to-id'] . ' not found. Try to refetch it.'); + self::fetchMissingActivity($activity['reply-to-id'], $activity); } self::postItem($activity, $item, $body); @@ -1490,11 +1493,11 @@ class ActivityPub private static function postItem($activity, $item, $body) { /// @todo What to do with $activity['context']? - if (empty($activity['author'])) - logger('Empty author'); - if (empty($activity['owner'])) - logger('Empty owner'); + if (($item['gravity'] != GRAVITY_PARENT) && !Item::exists(['uri' => $item['parent-uri']])) { + logger('Parent ' . $item['parent-uri'] . ' not found, message will be discarded.', LOGGER_DEBUG); + return; + } $item['network'] = Protocol::ACTIVITYPUB; $item['private'] = !in_array(0, $activity['receiver']); @@ -1614,6 +1617,7 @@ class ActivityPub return; } + logger('Updating profile for ' . $activity['object']['id'], LOGGER_DEBUG); self::fetchprofile($activity['object']['id'], true); } From 4699741f007801e78cf78da13d8c8e57c74ad994 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 26 Sep 2018 13:00:48 +0000 Subject: [PATCH 58/97] Fix delivery only for comments to native networks --- src/Protocol/ActivityPub.php | 32 +++++++++++++++++++++++++------- src/Worker/APDelivery.php | 4 +++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 9463c783d1..f0717b0f09 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -66,6 +66,8 @@ use Friendica\Core\Config; * - Event * * General: + * - Attachments + * - nsfw (sensitive) * - Queueing unsucessful deliveries * - Polling the outboxes for missing content? * - Possibly using the LD-JSON parser @@ -465,7 +467,7 @@ class ActivityPub public static function createActivityFromItem($item_id, $object_mode = false) { - $item = Item::selectFirst([], ['id' => $item_id]); + $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]); if (!DBA::isResult($item)) { return false; @@ -504,7 +506,7 @@ class ActivityPub $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM); } - $data['context'] = self::createConversationURLFromItem($item); + $data['context'] = self::fetchContextURLForItem($item); $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); @@ -527,7 +529,7 @@ class ActivityPub public static function createObjectFromItemID($item_id) { - $item = Item::selectFirst([], ['id' => $item_id]); + $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]); if (!DBA::isResult($item)) { return false; @@ -559,17 +561,32 @@ class ActivityPub return $tags; } - private static function createConversationURLFromItem($item) + private static function fetchConversationURLForItem($item) { - $conversation = DBA::selectFirst('conversation', ['conversation-uri'], ['item-uri' => $item['parent-uri']]); + $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]); if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) { $conversation_uri = $conversation['conversation-uri']; + } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) { + $conversation_uri = $conversation['conversation-href']; } else { $conversation_uri = str_replace('/object/', '/context/', $item['parent-uri']); } return $conversation_uri; } + private static function fetchContextURLForItem($item) + { + $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]); + if (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) { + $context_uri = $conversation['conversation-href']; + } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) { + $context_uri = $conversation['conversation-uri']; + } else { + $context_uri = str_replace('/object/', '/context/', $item['parent-uri']); + } + return $context_uri; + } + private static function CreateNote($item) { if (!empty($item['title'])) { @@ -609,7 +626,8 @@ class ActivityPub $data['attributedTo'] = $item['author-link']; $data['actor'] = $item['author-link']; $data['sensitive'] = false; // - Query NSFW - $data['conversation'] = $data['context'] = self::createConversationURLFromItem($item); + $data['conversation'] = self::fetchConversationURLForItem($item); + $data['context'] = self::fetchContextURLForItem($item); if (!empty($item['title'])) { $data['name'] = BBCode::convert($item['title'], false, 7); @@ -621,7 +639,6 @@ class ActivityPub $data['tag'] = self::createTagList($item); $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); - //$data['emoji'] = []; // Ignore by now return $data; } @@ -1524,6 +1541,7 @@ class ActivityPub $item['protocol'] = Conversation::PARCEL_ACTIVITYPUB; $item['source'] = $body; + $item['conversation-href'] = $activity['context']; $item['conversation-uri'] = $activity['conversation']; foreach ($activity['receiver'] as $receiver) { diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 493bb5fac8..943238a7b4 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -20,7 +20,9 @@ class APDelivery extends BaseObject } elseif ($cmd == Delivery::RELOCATION) { } else { $data = ActivityPub::createActivityFromItem($item_id); - HTTPSignature::transmit($data, $inbox, $uid); + if (!empty($data)) { + HTTPSignature::transmit($data, $inbox, $uid); + } } return; From f3814ae1fcf289dbcdc50f0c968298cba1acb1ce Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 26 Sep 2018 13:12:27 +0000 Subject: [PATCH 59/97] Changed conversation url (used for AP) --- src/Protocol/OStatus.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index ece265c99b..2eb8c55390 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -2004,8 +2004,7 @@ class OStatus } if (intval($item["parent"]) > 0) { - $conversation_href = System::baseUrl()."/display/".$owner["nick"]."/".$item["parent"]; - $conversation_uri = $conversation_href; + $conversation_href = $conversation_uri = str_replace('/object/', '/context/', $item['parent-uri']); if (isset($parent_item)) { $conversation = DBA::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $parent_item]); From 9ec30010c572c0b4e1fd4099f03a94e35be99358 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 26 Sep 2018 17:24:29 +0000 Subject: [PATCH 60/97] APContact stuff is moved to an own class --- src/Model/APContact.php | 175 ++++++++++++++++++++++++++++++++ src/Protocol/ActivityPub.php | 189 ++++------------------------------- src/Util/HTTPSignature.php | 5 +- src/Util/LDSignature.php | 21 +--- 4 files changed, 197 insertions(+), 193 deletions(-) create mode 100644 src/Model/APContact.php diff --git a/src/Model/APContact.php b/src/Model/APContact.php new file mode 100644 index 0000000000..22f168d8f6 --- /dev/null +++ b/src/Model/APContact.php @@ -0,0 +1,175 @@ + 'application/jrd+json,application/json']); + if (!$ret['success'] || empty($ret['body'])) { + return false; + } + + $data = json_decode($ret['body'], true); + + if (empty($data['links'])) { + return false; + } + + foreach ($data['links'] as $link) { + if (empty($link['href']) || empty($link['rel']) || empty($link['type'])) { + continue; + } + + if (($link['rel'] == 'self') && ($link['type'] == 'application/activity+json')) { + return $link['href']; + } + } + + return false; + } + + /** + * Fetches a profile from a given url + * + * @param string $url profile url + * @param boolean $update true = always update, false = never update, null = update when not found + * @return array profile array + */ + public static function getProfileByURL($url, $update = null) + { + if (empty($url)) { + return false; + } + + if (empty($update)) { + $apcontact = DBA::selectFirst('apcontact', [], ['url' => $url]); + if (DBA::isResult($apcontact)) { + return $apcontact; + } + + $apcontact = DBA::selectFirst('apcontact', [], ['alias' => $url]); + if (DBA::isResult($apcontact)) { + return $apcontact; + } + + $apcontact = DBA::selectFirst('apcontact', [], ['addr' => $url]); + if (DBA::isResult($apcontact)) { + return $apcontact; + } + + if (!is_null($update)) { + return false; + } + } + + if (empty(parse_url($url, PHP_URL_SCHEME))) { + $url = self::addrToUrl($url); + if (empty($url)) { + return false; + } + } + + $data = ActivityPub::fetchContent($url); + + if (empty($data) || empty($data['id']) || empty($data['inbox'])) { + return false; + } + + $apcontact = []; + $apcontact['url'] = $data['id']; + $apcontact['uuid'] = defaults($data, 'uuid', null); + $apcontact['type'] = defaults($data, 'type', null); + $apcontact['following'] = defaults($data, 'following', null); + $apcontact['followers'] = defaults($data, 'followers', null); + $apcontact['inbox'] = defaults($data, 'inbox', null); + $apcontact['outbox'] = defaults($data, 'outbox', null); + $apcontact['sharedinbox'] = JsonLD::fetchElement($data, 'endpoints', 'sharedInbox'); + $apcontact['nick'] = defaults($data, 'preferredUsername', null); + $apcontact['name'] = defaults($data, 'name', $apcontact['nick']); + $apcontact['about'] = defaults($data, 'summary', ''); + $apcontact['photo'] = JsonLD::fetchElement($data, 'icon', 'url'); + $apcontact['alias'] = JsonLD::fetchElement($data, 'url', 'href'); + + $parts = parse_url($apcontact['url']); + unset($parts['scheme']); + unset($parts['path']); + $apcontact['addr'] = $apcontact['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts)); + + $apcontact['pubkey'] = trim(JsonLD::fetchElement($data, 'publicKey', 'publicKeyPem')); + + // To-Do + // manuallyApprovesFollowers + + // Unhandled + // @context, tag, attachment, image, nomadicLocations, signature, following, followers, featured, movedTo, liked + + // Unhandled from Misskey + // sharedInbox, isCat + + // Unhandled from Kroeg + // kroeg:blocks, updated + + // Check if the address is resolvable + if (self::addrToUrl($apcontact['addr']) == $apcontact['url']) { + $parts = parse_url($apcontact['url']); + unset($parts['path']); + $apcontact['baseurl'] = Network::unparseURL($parts); + } else { + $apcontact['addr'] = null; + $apcontact['baseurl'] = null; + } + + if ($apcontact['url'] == $apcontact['alias']) { + $apcontact['alias'] = null; + } + + $apcontact['updated'] = DateTimeFormat::utcNow(); + + DBA::update('apcontact', $apcontact, ['url' => $url], true); + + // Update some data in the contact table with various ways to catch them all + $contact_fields = ['name' => $apcontact['name'], 'about' => $apcontact['about']]; + DBA::update('contact', $contact_fields, ['nurl' => normalise_link($url)]); + + $contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => normalise_link($url)]); + while ($contact = DBA::fetch($contacts)) { + Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']); + } + DBA::close($contacts); + + // Update the gcontact table + DBA::update('gcontact', $contact_fields, ['nurl' => normalise_link($url)]); + + logger('Updated profile for ' . $url, LOGGER_DEBUG); + + return $apcontact; + } +} diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index f0717b0f09..0229aaac32 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -12,6 +12,7 @@ use Friendica\Util\HTTPSignature; use Friendica\Core\Protocol; use Friendica\Model\Conversation; use Friendica\Model\Contact; +use Friendica\Model\APContact; use Friendica\Model\Item; use Friendica\Model\Profile; use Friendica\Model\Term; @@ -278,9 +279,9 @@ class ActivityPub $activity = json_decode($conversation['source'], true); $actor = JsonLD::fetchElement($activity, 'actor', 'id'); - $profile = ActivityPub::fetchprofile($actor); + $profile = APContact::getProfileByURL($actor); - $item_profile = ActivityPub::fetchprofile($item['author-link']); + $item_profile = APContact::getProfileByURL($item['author-link']); $exclude[] = $item['author-link']; if ($item['gravity'] == GRAVITY_PARENT) { @@ -316,7 +317,7 @@ class ActivityPub $data = array_merge($data, self::fetchPermissionBlockFromConversation($item)); - $actor_profile = ActivityPub::fetchprofile($item['author-link']); + $actor_profile = APContact::getProfileByURL($item['author-link']); $terms = Term::tagArrayFromItemId($item['id']); @@ -332,7 +333,7 @@ class ActivityPub if ($term['type'] != TERM_MENTION) { continue; } - $profile = self::fetchprofile($term['url'], false); + $profile = APContact::getProfileByURL($term['url'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; $contacts[$profile['url']] = $profile['url']; @@ -371,7 +372,7 @@ class ActivityPub continue; } - $profile = self::fetchprofile($parent['author-link'], false); + $profile = APContact::getProfileByURL($parent['author-link'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; $contacts[$profile['url']] = $profile['url']; @@ -381,7 +382,7 @@ class ActivityPub continue; } - $profile = self::fetchprofile($parent['owner-link'], false); + $profile = APContact::getProfileByURL($parent['owner-link'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; $contacts[$profile['url']] = $profile['url']; @@ -407,9 +408,9 @@ class ActivityPub $inboxes = []; if ($item['gravity'] == GRAVITY_ACTIVITY) { - $item_profile = ActivityPub::fetchprofile($item['author-link']); + $item_profile = APContact::getProfileByURL($item['author-link']); } else { - $item_profile = ActivityPub::fetchprofile($item['owner-link']); + $item_profile = APContact::getProfileByURL($item['owner-link']); } $elements = ['to', 'cc', 'bto', 'bcc']; @@ -428,7 +429,7 @@ class ActivityPub } DBA::close($contacts); } else { - $profile = self::fetchprofile($receiver); + $profile = APContact::getProfileByURL($receiver); if (!empty($profile)) { $target = defaults($profile, 'sharedinbox', $profile['inbox']); $inboxes[$target] = $target; @@ -644,7 +645,7 @@ class ActivityPub public static function transmitActivity($activity, $target, $uid) { - $profile = self::fetchprofile($target); + $profile = APContact::getProfileByURL($target); $owner = User::getOwnerDataById($uid); @@ -663,7 +664,7 @@ class ActivityPub public static function transmitContactAccept($target, $id, $uid) { - $profile = self::fetchprofile($target); + $profile = APContact::getProfileByURL($target); $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', @@ -683,7 +684,7 @@ class ActivityPub public static function transmitContactReject($target, $id, $uid) { - $profile = self::fetchprofile($target); + $profile = APContact::getProfileByURL($target); $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', @@ -703,7 +704,7 @@ class ActivityPub public static function transmitContactUndo($target, $uid) { - $profile = self::fetchprofile($target); + $profile = APContact::getProfileByURL($target); $id = System::baseUrl() . '/activity/' . System::createGUID(); @@ -738,162 +739,6 @@ class ActivityPub return json_decode($ret['body'], true); } - /** - * Resolves the profile url from the address by using webfinger - * - * @param string $addr profile address (user@domain.tld) - * @return string url - */ - private static function addrToUrl($addr) - { - $addr_parts = explode('@', $addr); - if (count($addr_parts) != 2) { - return false; - } - - $webfinger = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr); - - $ret = Network::curl($webfinger, false, $redirects, ['accept_content' => 'application/jrd+json,application/json']); - if (!$ret['success'] || empty($ret['body'])) { - return false; - } - - $data = json_decode($ret['body'], true); - - if (empty($data['links'])) { - return false; - } - - foreach ($data['links'] as $link) { - if (empty($link['href']) || empty($link['rel']) || empty($link['type'])) { - continue; - } - - if (($link['rel'] == 'self') && ($link['type'] == 'application/activity+json')) { - return $link['href']; - } - } - - return false; - } - - /** - * Fetches a profile form a given url - * - * @param string $url profile url - * @param boolean $update true = always update, false = never update, null = update when not found - * @return array profile array - */ - public static function fetchprofile($url, $update = null) - { - if (empty($url)) { - return false; - } - - if (empty($update)) { - $apcontact = DBA::selectFirst('apcontact', [], ['url' => $url]); - if (DBA::isResult($apcontact)) { - return $apcontact; - } - - $apcontact = DBA::selectFirst('apcontact', [], ['alias' => $url]); - if (DBA::isResult($apcontact)) { - return $apcontact; - } - - $apcontact = DBA::selectFirst('apcontact', [], ['addr' => $url]); - if (DBA::isResult($apcontact)) { - return $apcontact; - } - - if (!is_null($update)) { - return false; - } - } - - if (empty(parse_url($url, PHP_URL_SCHEME))) { - $url = self::addrToUrl($url); - if (empty($url)) { - return false; - } - } - - $data = self::fetchContent($url); - - if (empty($data) || empty($data['id']) || empty($data['inbox'])) { - return false; - } - - $apcontact = []; - $apcontact['url'] = $data['id']; - $apcontact['uuid'] = defaults($data, 'uuid', null); - $apcontact['type'] = defaults($data, 'type', null); - $apcontact['following'] = defaults($data, 'following', null); - $apcontact['followers'] = defaults($data, 'followers', null); - $apcontact['inbox'] = defaults($data, 'inbox', null); - $apcontact['outbox'] = defaults($data, 'outbox', null); - $apcontact['sharedinbox'] = JsonLD::fetchElement($data, 'endpoints', 'sharedInbox'); - $apcontact['nick'] = defaults($data, 'preferredUsername', null); - $apcontact['name'] = defaults($data, 'name', $apcontact['nick']); - $apcontact['about'] = defaults($data, 'summary', ''); - $apcontact['photo'] = JsonLD::fetchElement($data, 'icon', 'url'); - $apcontact['alias'] = JsonLD::fetchElement($data, 'url', 'href'); - - $parts = parse_url($apcontact['url']); - unset($parts['scheme']); - unset($parts['path']); - $apcontact['addr'] = $apcontact['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts)); - - $apcontact['pubkey'] = trim(JsonLD::fetchElement($data, 'publicKey', 'publicKeyPem')); - - // To-Do - // manuallyApprovesFollowers - - // Unhandled - // @context, tag, attachment, image, nomadicLocations, signature, following, followers, featured, movedTo, liked - - // Unhandled from Misskey - // sharedInbox, isCat - - // Unhandled from Kroeg - // kroeg:blocks, updated - - // Check if the address is resolvable - if (self::addrToUrl($apcontact['addr']) == $apcontact['url']) { - $parts = parse_url($apcontact['url']); - unset($parts['path']); - $apcontact['baseurl'] = Network::unparseURL($parts); - } else { - $apcontact['addr'] = null; - $apcontact['baseurl'] = null; - } - - if ($apcontact['url'] == $apcontact['alias']) { - $apcontact['alias'] = null; - } - - $apcontact['updated'] = DateTimeFormat::utcNow(); - - DBA::update('apcontact', $apcontact, ['url' => $url], true); - - // Update some data in the contact table with various ways to catch them all - $contact_fields = ['name' => $apcontact['name'], 'about' => $apcontact['about']]; - DBA::update('contact', $contact_fields, ['nurl' => normalise_link($url)]); - - $contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => normalise_link($url)]); - while ($contact = DBA::fetch($contacts)) { - Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']); - } - DBA::close($contacts); - - // Update the gcontact table - DBA::update('gcontact', $contact_fields, ['nurl' => normalise_link($url)]); - - logger('Updated profile for ' . $url, LOGGER_DEBUG); - - return $apcontact; - } - /** * Fetches a profile from the given url into an array that is compatible to Probe::uri * @@ -902,7 +747,7 @@ class ActivityPub */ public static function probeProfile($url) { - $apcontact = self::fetchprofile($url, true); + $apcontact = APContact::getProfileByURL($url, true); if (empty($apcontact)) { return false; } @@ -1158,7 +1003,7 @@ class ActivityPub } if (!empty($actor)) { - $profile = self::fetchprofile($actor); + $profile = APContact::getProfileByURL($actor); $followers = defaults($profile, 'followers', ''); logger('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG); @@ -1636,7 +1481,7 @@ class ActivityPub } logger('Updating profile for ' . $activity['object']['id'], LOGGER_DEBUG); - self::fetchprofile($activity['object']['id'], true); + APContact::getProfileByURL($activity['object']['id'], true); } private static function acceptFollowUser($activity) diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index aba280cf1d..695ef3fb31 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -9,6 +9,7 @@ use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Database\DBA; use Friendica\Model\User; +use Friendica\Model\APContact; use Friendica\Protocol\ActivityPub; /** @@ -393,12 +394,12 @@ class HTTPSignature { $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id); - $profile = ActivityPub::fetchprofile($url); + $profile = APContact::getProfileByURL($url); if (!empty($profile)) { logger('Taking key from id ' . $id, LOGGER_DEBUG); return ['url' => $url, 'pubkey' => $profile['pubkey']]; } elseif ($url != $actor) { - $profile = ActivityPub::fetchprofile($actor); + $profile = APContact::getProfileByURL($actor); if (!empty($profile)) { logger('Taking key from actor ' . $actor, LOGGER_DEBUG); return ['url' => $actor, 'pubkey' => $profile['pubkey']]; diff --git a/src/Util/LDSignature.php b/src/Util/LDSignature.php index 51086ac3e1..51235204fc 100644 --- a/src/Util/LDSignature.php +++ b/src/Util/LDSignature.php @@ -5,6 +5,7 @@ namespace Friendica\Util; use Friendica\Util\JsonLD; use Friendica\Util\DateTimeFormat; use Friendica\Protocol\ActivityPub; +use Friendica\Model\APContact; /** * @brief Implements JSON-LD signatures @@ -24,30 +25,12 @@ class LDSignature return false; } -/* - $creator = $data['signature']['creator']; - $actor = JsonLD::fetchElement($data, 'actor', 'id'); - - $url = (strpos($creator, '#') ? substr($creator, 0, strpos($creator, '#')) : $creator); - - $profile = ActivityPub::fetchprofile($url); - if (!empty($profile)) { - logger('Taking key from creator ' . $creator, LOGGER_DEBUG); - } elseif ($url != $actor) { - $profile = ActivityPub::fetchprofile($actor); - if (empty($profile)) { - return false; - } - logger('Taking key from actor ' . $actor, LOGGER_DEBUG); - } - -*/ $actor = JsonLD::fetchElement($data, 'actor', 'id'); if (empty($actor)) { return false; } - $profile = ActivityPub::fetchprofile($actor); + $profile = APContact::getProfileByURL($actor); if (empty($profile['pubkey'])) { return false; } From 60b0759b5011856b69582d5705ae88d867d3cdc9 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 26 Sep 2018 20:03:46 +0000 Subject: [PATCH 61/97] UUID instead of GUID --- include/api.php | 2 +- mod/item.php | 2 +- mod/photos.php | 6 +++--- mod/poke.php | 2 +- mod/subthread.php | 2 +- mod/tagger.php | 2 +- src/Core/System.php | 12 ++++++++++++ src/Model/Event.php | 2 +- src/Model/Item.php | 8 ++++---- src/Model/Mail.php | 8 ++++---- src/Model/User.php | 2 +- src/Protocol/ActivityPub.php | 37 +++++++++--------------------------- src/Protocol/Diaspora.php | 2 +- 13 files changed, 40 insertions(+), 47 deletions(-) diff --git a/include/api.php b/include/api.php index 5510eddb4f..52f8e7ad8e 100644 --- a/include/api.php +++ b/include/api.php @@ -4534,7 +4534,7 @@ function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $f $owner_record = DBA::selectFirst('contact', [], ['uid' => api_user(), 'self' => true]); $arr = []; - $arr['guid'] = System::createGUID(32); + $arr['guid'] = System::UUID(); $arr['uid'] = intval(api_user()); $arr['uri'] = $uri; $arr['parent-uri'] = $uri; diff --git a/mod/item.php b/mod/item.php index 213a990789..c8207984a9 100644 --- a/mod/item.php +++ b/mod/item.php @@ -240,7 +240,7 @@ function item_post(App $a) { $emailcc = notags(trim(defaults($_REQUEST, 'emailcc' , ''))); $body = escape_tags(trim(defaults($_REQUEST, 'body' , ''))); $network = notags(trim(defaults($_REQUEST, 'network' , Protocol::DFRN))); - $guid = System::createGUID(32); + $guid = System::UUID(); $postopts = defaults($_REQUEST, 'postopts', ''); diff --git a/mod/photos.php b/mod/photos.php index e205d72c6d..9794e9e7c0 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -472,7 +472,7 @@ function photos_post(App $a) $uri = Item::newURI($page_owner_uid); $arr = []; - $arr['guid'] = System::createGUID(32); + $arr['guid'] = System::UUID(); $arr['uid'] = $page_owner_uid; $arr['uri'] = $uri; $arr['parent-uri'] = $uri; @@ -651,7 +651,7 @@ function photos_post(App $a) $uri = Item::newURI($page_owner_uid); $arr = []; - $arr['guid'] = System::createGUID(32); + $arr['guid'] = System::UUID(); $arr['uid'] = $page_owner_uid; $arr['uri'] = $uri; $arr['parent-uri'] = $uri; @@ -889,7 +889,7 @@ function photos_post(App $a) $arr['coord'] = $lat . ' ' . $lon; } - $arr['guid'] = System::createGUID(32); + $arr['guid'] = System::UUID(); $arr['uid'] = $page_owner_uid; $arr['uri'] = $uri; $arr['parent-uri'] = $uri; diff --git a/mod/poke.php b/mod/poke.php index 91f33c0def..46c9d2f4a9 100644 --- a/mod/poke.php +++ b/mod/poke.php @@ -97,7 +97,7 @@ function poke_init(App $a) $arr = []; - $arr['guid'] = System::createGUID(32); + $arr['guid'] = System::UUID(); $arr['uid'] = $uid; $arr['uri'] = $uri; $arr['parent-uri'] = (!empty($parent_uri) ? $parent_uri : $uri); diff --git a/mod/subthread.php b/mod/subthread.php index 1153f2147d..901bb0129b 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -108,7 +108,7 @@ EOT; $arr = []; - $arr['guid'] = System::createGUID(32); + $arr['guid'] = System::UUID(); $arr['uri'] = $uri; $arr['uid'] = $owner_uid; $arr['contact-id'] = $contact['id']; diff --git a/mod/tagger.php b/mod/tagger.php index 959394c078..889ccd16f5 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -115,7 +115,7 @@ EOT; $arr = []; - $arr['guid'] = System::createGUID(32); + $arr['guid'] = System::UUID(); $arr['uri'] = $uri; $arr['uid'] = $owner_uid; $arr['contact-id'] = $contact['id']; diff --git a/src/Core/System.php b/src/Core/System.php index 88b89cda27..4eb6be0809 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -161,6 +161,18 @@ class System extends BaseObject killme(); } + /** + * Generates a random string in the UUID format + * + * @param bool|string $prefix A given prefix (default is empty) + * @return string a generated UUID + */ + public static function UUID($prefix = '') + { + $guid = System::createGUID(32, $prefix); + return substr($guid, 0, 8). '-' . substr($guid, 8, 4) . '-' . substr($guid, 12, 4) . '-' . substr($guid, 16, 4) . '-' . substr($guid, 20, 12); + } + /** * Generates a GUID with the given parameters * diff --git a/src/Model/Event.php b/src/Model/Event.php index 016d1f8d9e..f08e129894 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -314,7 +314,7 @@ class Event extends BaseObject Addon::callHooks('event_updated', $event['id']); } else { - $event['guid'] = defaults($arr, 'guid', System::createGUID(32)); + $event['guid'] = defaults($arr, 'guid', System::UUID()); // New event. Store it. DBA::insert('event', $event); diff --git a/src/Model/Item.php b/src/Model/Item.php index e33cf020d8..d8e814b8e6 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1205,7 +1205,7 @@ class Item extends BaseObject } elseif (!empty($item['uri'])) { $guid = self::guidFromUri($item['uri'], $prefix_host); } else { - $guid = System::createGUID(32, hash('crc32', $prefix_host)); + $guid = System::UUID(hash('crc32', $prefix_host)); } return $guid; @@ -2359,7 +2359,7 @@ class Item extends BaseObject public static function newURI($uid, $guid = "") { if ($guid == "") { - $guid = System::createGUID(32); + $guid = System::UUID(); } return self::getApp()->get_baseurl() . '/object/' . $guid; @@ -2686,7 +2686,7 @@ class Item extends BaseObject } if ($contact['network'] != Protocol::FEED) { - $datarray["guid"] = System::createGUID(32); + $datarray["guid"] = System::UUID(); unset($datarray["plink"]); $datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]); $datarray["parent-uri"] = $datarray["uri"]; @@ -3115,7 +3115,7 @@ class Item extends BaseObject $objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ; $new_item = [ - 'guid' => System::createGUID(32), + 'guid' => System::UUID(), 'uri' => self::newURI($item['uid']), 'uid' => $item['uid'], 'contact-id' => $item_contact_id, diff --git a/src/Model/Mail.php b/src/Model/Mail.php index 24a174b6b5..64a99d4def 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -46,7 +46,7 @@ class Mail return -2; } - $guid = System::createGUID(32); + $guid = System::UUID(); $uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid; $convid = 0; @@ -73,7 +73,7 @@ class Mail $recip_handle = (($contact['addr']) ? $contact['addr'] : $contact['nick'] . '@' . $recip_host); $sender_handle = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3); - $conv_guid = System::createGUID(32); + $conv_guid = System::UUID(); $convuri = $recip_handle . ':' . $conv_guid; $handles = $recip_handle . ';' . $sender_handle; @@ -171,7 +171,7 @@ class Mail $subject = L10n::t('[no subject]'); } - $guid = System::createGUID(32); + $guid = System::UUID(); $uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid; $me = Probe::uri($replyto); @@ -180,7 +180,7 @@ class Mail return -2; } - $conv_guid = System::createGUID(32); + $conv_guid = System::UUID(); $recip_handle = $recipient['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3); diff --git a/src/Model/User.php b/src/Model/User.php index d65e7d8f96..366490bfc8 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -495,7 +495,7 @@ class User $spubkey = $sres['pubkey']; $insert_result = DBA::insert('user', [ - 'guid' => System::createGUID(32), + 'guid' => System::UUID(), 'username' => $username, 'password' => $new_password_encoded, 'email' => $email, diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 0229aaac32..539a7302b7 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -78,9 +78,10 @@ class ActivityPub const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; const CONTEXT = ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', ['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier', - 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag', - 'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation', - 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]; + 'vcard' => 'http://www.w3.org/2006/vcard/ns#', + 'diaspora' => 'https://diasporafoundation.org#', + 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', + 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag']]; public static function isRequest() { @@ -235,12 +236,9 @@ class ActivityPub return []; } - $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', - ['vcard' => 'http://www.w3.org/2006/vcard/ns#', 'uuid' => 'http://schema.org/identifier', - 'sensitive' => 'as:sensitive', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers']]]; - + $data = ['@context' => self::CONTEXT]; $data['id'] = $contact['url']; - $data['uuid'] = $user['guid']; + $data['diaspora:guid'] = $user['guid']; $data['type'] = $accounttype[$user['account-type']]; $data['following'] = System::baseUrl() . '/following/' . $user['nickname']; $data['followers'] = System::baseUrl() . '/followers/' . $user['nickname']; @@ -562,19 +560,6 @@ class ActivityPub return $tags; } - private static function fetchConversationURLForItem($item) - { - $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]); - if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) { - $conversation_uri = $conversation['conversation-uri']; - } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) { - $conversation_uri = $conversation['conversation-href']; - } else { - $conversation_uri = str_replace('/object/', '/context/', $item['parent-uri']); - } - return $conversation_uri; - } - private static function fetchContextURLForItem($item) { $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]); @@ -616,7 +601,7 @@ class ActivityPub $data['inReplyTo'] = null; } - $data['uuid'] = $item['guid']; + $data['diaspora:guid'] = $item['guid']; $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM); if ($item["created"] != $item["edited"]) { @@ -627,7 +612,6 @@ class ActivityPub $data['attributedTo'] = $item['author-link']; $data['actor'] = $item['author-link']; $data['sensitive'] = false; // - Query NSFW - $data['conversation'] = self::fetchConversationURLForItem($item); $data['context'] = self::fetchContextURLForItem($item); if (!empty($item['title'])) { @@ -755,7 +739,7 @@ class ActivityPub $profile = ['network' => Protocol::ACTIVITYPUB]; $profile['nick'] = $apcontact['nick']; $profile['name'] = $apcontact['name']; - $profile['guid'] = $apcontact['uuid']; + $profile['guid'] = $apcontact['diaspora:guid']; $profile['url'] = $apcontact['url']; $profile['addr'] = $apcontact['addr']; $profile['alias'] = $apcontact['alias']; @@ -1232,9 +1216,6 @@ class ActivityPub // Data in Notes: - // To-Do? - // emoji, atomUri, inReplyToAtomUri - // Unhandled // contentMap, announcement_count, announcements, context_id, likes, like_count // inReplyToStatusId, shares, quoteUrl, statusnetConversationId @@ -1368,7 +1349,7 @@ class ActivityPub $item['uri'] = $activity['id']; $item['created'] = $activity['published']; $item['edited'] = $activity['updated']; - $item['guid'] = $activity['uuid']; + $item['guid'] = $activity['diaspora:guid']; $item['title'] = HTML::toBBCode($activity['name']); $item['content-warning'] = HTML::toBBCode($activity['summary']); $item['body'] = self::convertMentions(HTML::toBBCode($activity['content'])); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index e7edcdc490..5239255fee 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -3200,7 +3200,7 @@ class Diaspora $author = self::myHandle($owner); $message = ["author" => $author, - "guid" => System::createGUID(32), + "guid" => System::UUID(), "parent_type" => "Post", "parent_guid" => $item["guid"]]; From dd38b7e3298455b6f57d6427e3700942ea5ae989 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 26 Sep 2018 20:36:47 +0000 Subject: [PATCH 62/97] Avoid warnings --- src/Model/APContact.php | 2 +- src/Protocol/ActivityPub.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 22f168d8f6..c8f8998ae6 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -105,7 +105,7 @@ class APContact extends BaseObject $apcontact = []; $apcontact['url'] = $data['id']; - $apcontact['uuid'] = defaults($data, 'uuid', null); + $apcontact['uuid'] = defaults($data, 'diaspora:guid', null); $apcontact['type'] = defaults($data, 'type', null); $apcontact['following'] = defaults($data, 'following', null); $apcontact['followers'] = defaults($data, 'followers', null); diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 539a7302b7..aa387d9a17 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -739,7 +739,7 @@ class ActivityPub $profile = ['network' => Protocol::ACTIVITYPUB]; $profile['nick'] = $apcontact['nick']; $profile['name'] = $apcontact['name']; - $profile['guid'] = $apcontact['diaspora:guid']; + $profile['guid'] = $apcontact['uuid']; $profile['url'] = $apcontact['url']; $profile['addr'] = $apcontact['addr']; $profile['alias'] = $apcontact['alias']; From f7d7d9411167078364ac57a4483a21e5a1c1b663 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 26 Sep 2018 21:38:37 +0000 Subject: [PATCH 63/97] Added some doxygen headers --- src/Protocol/ActivityPub.php | 303 ++++++++++++++++++++++++++++++++++- 1 file changed, 296 insertions(+), 7 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index aa387d9a17..3bf304adc9 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -83,12 +83,25 @@ class ActivityPub 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag']]; + /** + * @brief Checks if the web request is done for the AP protocol + * + * @return is it AP? + */ public static function isRequest() { return stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json') || stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/ld+json'); } + /** + * @brief collects the lost of followers of the given owner + * + * @param array $owner Owner array + * @param integer $page Page number + * + * @return array of owners + */ public static function getFollowers($owner, $page = null) { $condition = ['rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'], @@ -128,6 +141,14 @@ class ActivityPub return $data; } + /** + * @brief Create list of following contacts + * + * @param array $owner Owner array + * @param integer $page Page numbe + * + * @return array of following contacts + */ public static function getFollowing($owner, $page = null) { $condition = ['rel' => [Contact::SHARING, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'], @@ -167,6 +188,14 @@ class ActivityPub return $data; } + /** + * @brief Public posts for the given owner + * + * @param array $owner Owner array + * @param integer $page Page numbe + * + * @return array of posts + */ public static function getOutbox($owner, $page = null) { $public_contact = Contact::getIdForURL($owner['url'], 0, true); @@ -211,7 +240,7 @@ class ActivityPub * Return the ActivityPub profile of the given user * * @param integer $uid User ID - * @return array + * @return profile array */ public static function profile($uid) { @@ -262,6 +291,13 @@ class ActivityPub return $data; } + /** + * @brief Returns an array with permissions of a given item array + * + * @param array $item + * + * @return array with permissions + */ private static function fetchPermissionBlockFromConversation($item) { if (empty($item['thr-parent'])) { @@ -309,6 +345,13 @@ class ActivityPub return $permissions; } + /** + * @brief + * + * @param array $item + * + * @return + */ public static function createPermissionBlockForItem($item) { $data = ['to' => [], 'cc' => []]; @@ -396,6 +439,14 @@ class ActivityPub return $data; } + /** + * @brief + * + * @param array $item + * @param $uid + * + * @return + */ public static function fetchTargetInboxes($item, $uid) { $permissions = self::createPermissionBlockForItem($item); @@ -439,6 +490,13 @@ class ActivityPub return $inboxes; } + /** + * @brief + * + * @param array $item + * + * @return + */ public static function getTypeOfItem($item) { if ($item['verb'] == ACTIVITY_POST) { @@ -464,6 +522,14 @@ class ActivityPub return $type; } + /** + * @brief + * + * @param $item_id + * @param $object_mode + * + * @return + */ public static function createActivityFromItem($item_id, $object_mode = false) { $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]); @@ -526,6 +592,13 @@ class ActivityPub } } + /** + * @brief + * + * @param $item_id + * + * @return + */ public static function createObjectFromItemID($item_id) { $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]); @@ -540,6 +613,13 @@ class ActivityPub return $data; } + /** + * @brief + * + * @param array $item + * + * @return + */ private static function createTagList($item) { $tags = []; @@ -560,6 +640,13 @@ class ActivityPub return $tags; } + /** + * @brief + * + * @param array $item + * + * @return + */ private static function fetchContextURLForItem($item) { $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]); @@ -573,6 +660,13 @@ class ActivityPub return $context_uri; } + /** + * @brief + * + * @param array $item + * + * @return + */ private static function CreateNote($item) { if (!empty($item['title'])) { @@ -627,6 +721,15 @@ class ActivityPub return $data; } + /** + * @brief + * + * @param array $activity + * @param $target + * @param $uid + * + * @return + */ public static function transmitActivity($activity, $target, $uid) { $profile = APContact::getProfileByURL($target); @@ -646,6 +749,15 @@ class ActivityPub return HTTPSignature::transmit($signed, $profile['inbox'], $uid); } + /** + * @brief + * + * @param $target + * @param $id + * @param $uid + * + * @return + */ public static function transmitContactAccept($target, $id, $uid) { $profile = APContact::getProfileByURL($target); @@ -666,6 +778,15 @@ class ActivityPub return HTTPSignature::transmit($signed, $profile['inbox'], $uid); } + /** + * @brief + * + * @param $target + * @param $id + * @param $uid + * + * @return + */ public static function transmitContactReject($target, $id, $uid) { $profile = APContact::getProfileByURL($target); @@ -686,6 +807,14 @@ class ActivityPub return HTTPSignature::transmit($signed, $profile['inbox'], $uid); } + /** + * @brief + * + * @param $target + * @param $uid + * + * @return + */ public static function transmitContactUndo($target, $uid) { $profile = APContact::getProfileByURL($target); @@ -764,6 +893,13 @@ class ActivityPub return $profile; } + /** + * @brief + * + * @param $body + * @param $header + * @param $uid + */ public static function processInbox($body, $header, $uid) { $http_signer = HTTPSignature::getSigner($body, $header); @@ -813,6 +949,12 @@ class ActivityPub self::processActivity($activity, $body, $uid, $trust_source); } + /** + * @brief + * + * @param $url + * @param $uid + */ public static function fetchOutbox($url, $uid) { $data = self::fetchContent($url); @@ -836,6 +978,15 @@ class ActivityPub } } + /** + * @brief + * + * @param array $activity + * @param $uid + * @param $trust_source + * + * @return + */ private static function prepareObjectData($activity, $uid, &$trust_source) { $actor = JsonLD::fetchElement($activity, 'actor', 'id'); @@ -897,6 +1048,14 @@ class ActivityPub return $object_data; } + /** + * @brief + * + * @param array $activity + * @param $body + * @param $uid + * @param $trust_source + */ private static function processActivity($activity, $body = '', $uid = null, $trust_source = false) { if (empty($activity['type'])) { @@ -973,6 +1132,14 @@ class ActivityPub } } + /** + * @brief + * + * @param array $activity + * @param $actor + * + * @return + */ private static function getReceivers($activity, $actor) { $receivers = []; @@ -1051,6 +1218,13 @@ class ActivityPub return $receivers; } + /** + * @brief + * + * @param $cid + * @param $uid + * @param $url + */ private static function switchContact($cid, $uid, $url) { $profile = ActivityPub::probeProfile($url); @@ -1070,6 +1244,12 @@ class ActivityPub Contact::updateAvatar($photo, $uid, $cid); } + /** + * @brief + * + * @param $receivers + * @param $actor + */ private static function switchContacts($receivers, $actor) { if (empty($actor)) { @@ -1089,6 +1269,14 @@ class ActivityPub } } + /** + * @brief + * + * @param $object_data + * @param array $activity + * + * @return + */ private static function addActivityFields($object_data, $activity) { if (!empty($activity['published']) && empty($object_data['published'])) { @@ -1109,6 +1297,15 @@ class ActivityPub return $object_data; } + /** + * @brief + * + * @param $object_id + * @param $object + * @param $trust_source + * + * @return + */ private static function fetchObject($object_id, $object = [], $trust_source = false) { if (!$trust_source || is_string($object)) { @@ -1161,6 +1358,13 @@ class ActivityPub } } + /** + * @brief + * + * @param $object + * + * @return + */ private static function ProcessObject(&$object) { if (empty($object['id'])) { @@ -1229,10 +1433,16 @@ class ActivityPub // views, waitTranscoding, state, support, subtitleLanguage // likes, dislikes, shares, comments - return $object_data; } + /** + * @brief Converts mentions from Pleroma into the Friendica format + * + * @param string $body + * + * @return converted body + */ private static function convertMentions($body) { $URLSearchString = "^\[\]"; @@ -1241,6 +1451,14 @@ class ActivityPub return $body; } + /** + * @brief Constructs a string with tags for a given tag array + * + * @param array $tags + * @param boolean $sensitive + * + * @return string with tags + */ private static function constructTagList($tags, $sensitive) { if (empty($tags)) { @@ -1263,6 +1481,14 @@ class ActivityPub return $tag_text; } + /** + * @brief + * + * @param $attachments + * @param array $item + * + * @return item array + */ private static function constructAttachList($attachments, $item) { if (empty($attachments)) { @@ -1289,6 +1515,12 @@ class ActivityPub return $item; } + /** + * @brief + * + * @param array $activity + * @param $body + */ private static function createItem($activity, $body) { $item = []; @@ -1311,6 +1543,12 @@ class ActivityPub self::postItem($activity, $item, $body); } + /** + * @brief + * + * @param array $activity + * @param $body + */ private static function likeItem($activity, $body) { $item = []; @@ -1322,6 +1560,12 @@ class ActivityPub self::postItem($activity, $item, $body); } + /** + * @brief + * + * @param array $activity + * @param $body + */ private static function dislikeItem($activity, $body) { $item = []; @@ -1333,6 +1577,13 @@ class ActivityPub self::postItem($activity, $item, $body); } + /** + * @brief + * + * @param array $activity + * @param array $item + * @param $body + */ private static function postItem($activity, $item, $body) { /// @todo What to do with $activity['context']? @@ -1383,6 +1634,12 @@ class ActivityPub } } + /** + * @brief + * + * @param $url + * @param $child + */ private static function fetchMissingActivity($url, $child) { if (Config::get('system', 'ostatus_full_threads')) { @@ -1410,9 +1667,16 @@ class ActivityPub logger('Activity ' . $url . ' had been fetched and processed.'); } - private static function getUserOfObject($object) + /** + * @brief Returns the user id of a given profile url + * + * @param string $profile + * + * @return integer user id + */ + private static function getUserOfProfile($profile) { - $self = DBA::selectFirst('contact', ['uid'], ['nurl' => normalise_link($object), 'self' => true]); + $self = DBA::selectFirst('contact', ['uid'], ['nurl' => normalise_link($profile), 'self' => true]); if (!DBA::isResult($self)) { return false; } else { @@ -1420,10 +1684,15 @@ class ActivityPub } } + /** + * @brief perform a "follow" request + * + * @param array $activity + */ private static function followUser($activity) { $actor = JsonLD::fetchElement($activity, 'object', 'id'); - $uid = self::getUserOfObject($actor); + $uid = self::getUserOfProfile($actor); if (empty($uid)) { return; } @@ -1455,6 +1724,11 @@ class ActivityPub logger('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']); } + /** + * @brief Update the given profile + * + * @param array $activity + */ private static function updatePerson($activity) { if (empty($activity['object']['id'])) { @@ -1465,10 +1739,15 @@ class ActivityPub APContact::getProfileByURL($activity['object']['id'], true); } + /** + * @brief Accept a follow request + * + * @param array $activity + */ private static function acceptFollowUser($activity) { $actor = JsonLD::fetchElement($activity, 'object', 'actor'); - $uid = self::getUserOfObject($actor); + $uid = self::getUserOfProfile($actor); if (empty($uid)) { return; } @@ -1493,6 +1772,11 @@ class ActivityPub logger('Accept contact request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG); } + /** + * @brief Undo activity like "like" or "dislike" + * + * @param array $activity + */ private static function undoActivity($activity) { $activity_url = JsonLD::fetchElement($activity, 'object', 'id'); @@ -1513,10 +1797,15 @@ class ActivityPub Item::delete(['uri' => $activity_url, 'author-id' => $author_id, 'gravity' => GRAVITY_ACTIVITY]); } + /** + * @brief Activity to remove a follower + * + * @param array $activity + */ private static function undoFollowUser($activity) { $object = JsonLD::fetchElement($activity, 'object', 'object'); - $uid = self::getUserOfObject($object); + $uid = self::getUserOfProfile($object); if (empty($uid)) { return; } From 9c62727e1dc11fe9fdd63949840ad36c86ee7485 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 26 Sep 2018 22:02:14 +0000 Subject: [PATCH 64/97] Added doxygen data --- src/Util/HTTPSignature.php | 30 ++++++++++++++++++++++++++++++ src/Util/JsonLD.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 695ef3fb31..7adaa82f78 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -26,6 +26,13 @@ use Friendica\Protocol\ActivityPub; class HTTPSignature { // See draft-cavage-http-signatures-08 + /** + * @brief Verifies a magic request + * + * @param $key + * + * @return array with verification data + */ public static function verifyMagic($key) { $headers = null; @@ -262,6 +269,13 @@ class HTTPSignature * Functions for ActivityPub */ + /** + * @brief Transmit given data to a target for a user + * + * @param $data + * @param $target + * @param $uid + */ public static function transmit($data, $target, $uid) { $owner = User::getOwnerDataById($uid); @@ -294,6 +308,14 @@ class HTTPSignature logger('Transmit to ' . $target . ' returned ' . $return_code); } + /** + * @brief Gets a signer from a given HTTP request + * + * @param $content + * @param $http_headers + * + * @return signer string + */ public static function getSigner($content, $http_headers) { $object = json_decode($content, true); @@ -390,6 +412,14 @@ class HTTPSignature return $key['url']; } + /** + * @brief fetches a key for a given id and actor + * + * @param $id + * @param $actor + * + * @return array with actor url and public key + */ private static function fetchKey($id, $actor) { $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id); diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index d3c101120b..4917c3c015 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -12,6 +12,13 @@ use digitalbazaar\jsonld as DBJsonLD; */ class JsonLD { + /** + * @brief Loader for LD-JSON validation + * + * @param $url + * + * @return the loaded data + */ public static function documentLoader($url) { $recursion = 0; @@ -40,6 +47,13 @@ class JsonLD return $data; } + /** + * @brief Normalises a given JSON array + * + * @param array $json + * + * @return normalized JSON string + */ public static function normalize($json) { jsonld_set_document_loader('Friendica\Util\JsonLD::documentLoader'); @@ -49,6 +63,13 @@ class JsonLD return jsonld_normalize($jsonobj, array('algorithm' => 'URDNA2015', 'format' => 'application/nquads')); } + /** + * @brief Compacts a given JSON array + * + * @param array $json + * + * @return comacted JSON array + */ public static function compact($json) { jsonld_set_document_loader('Friendica\Util\JsonLD::documentLoader'); @@ -66,6 +87,17 @@ class JsonLD return json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true); } + /** + * @brief Fetches an element from a JSON array + * + * @param $array + * @param $element + * @param $key + * @param $type + * @param $type_value + * + * @return fetched element + */ public static function fetchElement($array, $element, $key, $type = null, $type_value = null) { if (empty($array)) { From 897929ad40ef168de9a522825aa6891213b8f701 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 26 Sep 2018 22:45:13 +0000 Subject: [PATCH 65/97] Avoid warnings, added documentation --- src/Protocol/ActivityPub.php | 11 +++++------ src/Util/JsonLD.php | 10 +++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 3bf304adc9..78e7b9bf23 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -77,8 +77,7 @@ class ActivityPub { const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; const CONTEXT = ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', - ['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier', - 'vcard' => 'http://www.w3.org/2006/vcard/ns#', + ['vcard' => 'http://www.w3.org/2006/vcard/ns#', 'diaspora' => 'https://diasporafoundation.org#', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag']]; @@ -346,11 +345,11 @@ class ActivityPub } /** - * @brief + * @brief Creates an array of permissions from an item thread * * @param array $item * - * @return + * @return permission array */ public static function createPermissionBlockForItem($item) { @@ -445,7 +444,7 @@ class ActivityPub * @param array $item * @param $uid * - * @return + * @return array with inboxes */ public static function fetchTargetInboxes($item, $uid) { @@ -1393,7 +1392,7 @@ class ActivityPub $actor = defaults($object, 'actor', null); } - $object_data['uuid'] = defaults($object, 'uuid', null); + $object_data['diaspora:guid'] = defaults($object, 'diaspora:guid', null); $object_data['owner'] = $object_data['author'] = $actor; $object_data['context'] = defaults($object, 'context', null); $object_data['conversation'] = defaults($object, 'conversation', null); diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 4917c3c015..4100b258bb 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -6,6 +6,7 @@ namespace Friendica\Util; use Friendica\Core\Cache; use digitalbazaar\jsonld as DBJsonLD; +use Exception; /** * @brief This class contain methods to work with JsonLD data @@ -60,7 +61,14 @@ class JsonLD $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); - return jsonld_normalize($jsonobj, array('algorithm' => 'URDNA2015', 'format' => 'application/nquads')); + try { + $normalized = jsonld_normalize($jsonobj, array('algorithm' => 'URDNA2015', 'format' => 'application/nquads')); + } + catch (Exception $e) { + logger('normalise error:' . print_r($e, true), LOGGER_DEBUG); + } + + return $normalized; } /** From fa868fbaf217a8031eef4938b0f5b962ada3f411 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 03:28:56 +0000 Subject: [PATCH 66/97] Some more documentation --- src/Protocol/ActivityPub.php | 80 ++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 78e7b9bf23..d01280e906 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -439,10 +439,10 @@ class ActivityPub } /** - * @brief + * @brief Fetches an array of inboxes for the given item and user * * @param array $item - * @param $uid + * @param integer $uid User ID * * @return array with inboxes */ @@ -490,11 +490,11 @@ class ActivityPub } /** - * @brief + * @brief Returns the activity type of a given item * * @param array $item * - * @return + * @return activity type */ public static function getTypeOfItem($item) { @@ -522,12 +522,12 @@ class ActivityPub } /** - * @brief + * @brief Creates an activity array for a given item id * - * @param $item_id - * @param $object_mode + * @param integer $item_id + * @param boolean $object_mode Is the activity item is used inside another object? * - * @return + * @return array of activity */ public static function createActivityFromItem($item_id, $object_mode = false) { @@ -592,11 +592,11 @@ class ActivityPub } /** - * @brief + * @brief Creates an object array for a given item id * - * @param $item_id + * @param integer $item_id * - * @return + * @return object array */ public static function createObjectFromItemID($item_id) { @@ -613,11 +613,11 @@ class ActivityPub } /** - * @brief + * @brief Returns a tag array for a given item array * * @param array $item * - * @return + * @return array of tags */ private static function createTagList($item) { @@ -640,11 +640,11 @@ class ActivityPub } /** - * @brief + * @brief Fetches the "context" value for a givem item array from the "conversation" table * * @param array $item * - * @return + * @return string with context url */ private static function fetchContextURLForItem($item) { @@ -660,11 +660,11 @@ class ActivityPub } /** - * @brief + * @brief Creates a note/article object array * * @param array $item * - * @return + * @return object array */ private static function CreateNote($item) { @@ -721,13 +721,11 @@ class ActivityPub } /** - * @brief + * @brief Transmits a given activity to a target * * @param array $activity - * @param $target - * @param $uid - * - * @return + * @param string $target Target profile + * @param integer $uid User ID */ public static function transmitActivity($activity, $target, $uid) { @@ -745,17 +743,15 @@ class ActivityPub logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG); $signed = LDSignature::sign($data, $owner); - return HTTPSignature::transmit($signed, $profile['inbox'], $uid); + HTTPSignature::transmit($signed, $profile['inbox'], $uid); } /** - * @brief + * @brief Transmit a message that the contact request had been accepted * - * @param $target + * @param string $target Target profile * @param $id - * @param $uid - * - * @return + * @param integer $uid User ID */ public static function transmitContactAccept($target, $id, $uid) { @@ -774,17 +770,15 @@ class ActivityPub logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); $signed = LDSignature::sign($data, $owner); - return HTTPSignature::transmit($signed, $profile['inbox'], $uid); + HTTPSignature::transmit($signed, $profile['inbox'], $uid); } /** * @brief * - * @param $target + * @param string $target Target profile * @param $id - * @param $uid - * - * @return + * @param integer $uid User ID */ public static function transmitContactReject($target, $id, $uid) { @@ -803,16 +797,14 @@ class ActivityPub logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); $signed = LDSignature::sign($data, $owner); - return HTTPSignature::transmit($signed, $profile['inbox'], $uid); + HTTPSignature::transmit($signed, $profile['inbox'], $uid); } /** * @brief * - * @param $target - * @param $uid - * - * @return + * @param string $target Target profile + * @param integer $uid User ID */ public static function transmitContactUndo($target, $uid) { @@ -833,7 +825,7 @@ class ActivityPub logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG); $signed = LDSignature::sign($data, $owner); - return HTTPSignature::transmit($signed, $profile['inbox'], $uid); + HTTPSignature::transmit($signed, $profile['inbox'], $uid); } /** @@ -897,7 +889,7 @@ class ActivityPub * * @param $body * @param $header - * @param $uid + * @param integer $uid User ID */ public static function processInbox($body, $header, $uid) { @@ -952,7 +944,7 @@ class ActivityPub * @brief * * @param $url - * @param $uid + * @param integer $uid User ID */ public static function fetchOutbox($url, $uid) { @@ -981,7 +973,7 @@ class ActivityPub * @brief * * @param array $activity - * @param $uid + * @param integer $uid User ID * @param $trust_source * * @return @@ -1052,7 +1044,7 @@ class ActivityPub * * @param array $activity * @param $body - * @param $uid + * @param integer $uid User ID * @param $trust_source */ private static function processActivity($activity, $body = '', $uid = null, $trust_source = false) @@ -1221,7 +1213,7 @@ class ActivityPub * @brief * * @param $cid - * @param $uid + * @param integer $uid User ID * @param $url */ private static function switchContact($cid, $uid, $url) From f640556f80dcf38839a8b4cd48c64f18be00651a Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 03:41:55 +0000 Subject: [PATCH 67/97] New database version --- boot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot.php b/boot.php index 581bbb1817..b5c9166982 100644 --- a/boot.php +++ b/boot.php @@ -41,7 +41,7 @@ define('FRIENDICA_PLATFORM', 'Friendica'); define('FRIENDICA_CODENAME', 'The Tazmans Flax-lily'); define('FRIENDICA_VERSION', '2018.12-dev'); define('DFRN_PROTOCOL_VERSION', '2.23'); -define('DB_UPDATE_VERSION', 1283); +define('DB_UPDATE_VERSION', 1284); define('NEW_UPDATE_ROUTINE_VERSION', 1170); /** From 563905469958b80848e4bc799a09250a8a3ceb18 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 11:39:17 +0000 Subject: [PATCH 68/97] Diaspora in AP - and changed function name --- src/Protocol/ActivityPub.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index d01280e906..4cf65bd31b 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -78,7 +78,7 @@ class ActivityPub const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; const CONTEXT = ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', ['vcard' => 'http://www.w3.org/2006/vcard/ns#', - 'diaspora' => 'https://diasporafoundation.org#', + 'diaspora' => 'https://diasporafoundation.org/ns/', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag']]; @@ -575,7 +575,7 @@ class ActivityPub $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); if (in_array($data['type'], ['Create', 'Update', 'Announce', 'Delete'])) { - $data['object'] = self::CreateNote($item); + $data['object'] = self::createNote($item); } elseif ($data['type'] == 'Undo') { $data['object'] = self::createActivityFromItem($item_id, true); } else { @@ -607,7 +607,7 @@ class ActivityPub } $data = ['@context' => self::CONTEXT]; - $data = array_merge($data, self::CreateNote($item)); + $data = array_merge($data, self::createNote($item)); return $data; } @@ -666,7 +666,7 @@ class ActivityPub * * @return object array */ - private static function CreateNote($item) + private static function createNote($item) { if (!empty($item['title'])) { $type = 'Article'; @@ -713,6 +713,11 @@ class ActivityPub $data['content'] = BBCode::convert($item['body'], false, 7); $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"]; + + if (!empty($item['signed_text']) && ($item['uri'] != $item['thr-parent'])) { + $data['diaspora:comment'] = $item['signed_text']; + } + $data['attachment'] = []; // @ToDo $data['tag'] = self::createTagList($item); $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item)); @@ -1319,7 +1324,7 @@ class ActivityPub return false; } logger('Using already stored item for url ' . $object_id, LOGGER_DEBUG); - $data = self::CreateNote($item); + $data = self::createNote($item); } if (empty($data['type'])) { From cb9be8a7aba402cfcae9221353a0d830466b354c Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 11:52:15 +0000 Subject: [PATCH 69/97] UUID is now createUUID --- include/api.php | 2 +- mod/item.php | 2 +- mod/photos.php | 6 +++--- mod/poke.php | 2 +- mod/subthread.php | 2 +- mod/tagger.php | 2 +- src/Core/System.php | 2 +- src/Model/Event.php | 2 +- src/Model/Item.php | 8 ++++---- src/Model/Mail.php | 8 ++++---- src/Model/User.php | 2 +- src/Protocol/Diaspora.php | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/include/api.php b/include/api.php index 52f8e7ad8e..cfc0c30564 100644 --- a/include/api.php +++ b/include/api.php @@ -4534,7 +4534,7 @@ function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $f $owner_record = DBA::selectFirst('contact', [], ['uid' => api_user(), 'self' => true]); $arr = []; - $arr['guid'] = System::UUID(); + $arr['guid'] = System::createUUID(); $arr['uid'] = intval(api_user()); $arr['uri'] = $uri; $arr['parent-uri'] = $uri; diff --git a/mod/item.php b/mod/item.php index c8207984a9..20c0aaf747 100644 --- a/mod/item.php +++ b/mod/item.php @@ -240,7 +240,7 @@ function item_post(App $a) { $emailcc = notags(trim(defaults($_REQUEST, 'emailcc' , ''))); $body = escape_tags(trim(defaults($_REQUEST, 'body' , ''))); $network = notags(trim(defaults($_REQUEST, 'network' , Protocol::DFRN))); - $guid = System::UUID(); + $guid = System::createUUID(); $postopts = defaults($_REQUEST, 'postopts', ''); diff --git a/mod/photos.php b/mod/photos.php index 9794e9e7c0..568d6eb537 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -472,7 +472,7 @@ function photos_post(App $a) $uri = Item::newURI($page_owner_uid); $arr = []; - $arr['guid'] = System::UUID(); + $arr['guid'] = System::createUUID(); $arr['uid'] = $page_owner_uid; $arr['uri'] = $uri; $arr['parent-uri'] = $uri; @@ -651,7 +651,7 @@ function photos_post(App $a) $uri = Item::newURI($page_owner_uid); $arr = []; - $arr['guid'] = System::UUID(); + $arr['guid'] = System::createUUID(); $arr['uid'] = $page_owner_uid; $arr['uri'] = $uri; $arr['parent-uri'] = $uri; @@ -889,7 +889,7 @@ function photos_post(App $a) $arr['coord'] = $lat . ' ' . $lon; } - $arr['guid'] = System::UUID(); + $arr['guid'] = System::createUUID(); $arr['uid'] = $page_owner_uid; $arr['uri'] = $uri; $arr['parent-uri'] = $uri; diff --git a/mod/poke.php b/mod/poke.php index 46c9d2f4a9..6ebb8632c1 100644 --- a/mod/poke.php +++ b/mod/poke.php @@ -97,7 +97,7 @@ function poke_init(App $a) $arr = []; - $arr['guid'] = System::UUID(); + $arr['guid'] = System::createUUID(); $arr['uid'] = $uid; $arr['uri'] = $uri; $arr['parent-uri'] = (!empty($parent_uri) ? $parent_uri : $uri); diff --git a/mod/subthread.php b/mod/subthread.php index 901bb0129b..105cf60feb 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -108,7 +108,7 @@ EOT; $arr = []; - $arr['guid'] = System::UUID(); + $arr['guid'] = System::createUUID(); $arr['uri'] = $uri; $arr['uid'] = $owner_uid; $arr['contact-id'] = $contact['id']; diff --git a/mod/tagger.php b/mod/tagger.php index 889ccd16f5..fd79d54150 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -115,7 +115,7 @@ EOT; $arr = []; - $arr['guid'] = System::UUID(); + $arr['guid'] = System::createUUID(); $arr['uri'] = $uri; $arr['uid'] = $owner_uid; $arr['contact-id'] = $contact['id']; diff --git a/src/Core/System.php b/src/Core/System.php index 4eb6be0809..b41f520d77 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -167,7 +167,7 @@ class System extends BaseObject * @param bool|string $prefix A given prefix (default is empty) * @return string a generated UUID */ - public static function UUID($prefix = '') + public static function createUUID($prefix = '') { $guid = System::createGUID(32, $prefix); return substr($guid, 0, 8). '-' . substr($guid, 8, 4) . '-' . substr($guid, 12, 4) . '-' . substr($guid, 16, 4) . '-' . substr($guid, 20, 12); diff --git a/src/Model/Event.php b/src/Model/Event.php index f08e129894..452017e69d 100644 --- a/src/Model/Event.php +++ b/src/Model/Event.php @@ -314,7 +314,7 @@ class Event extends BaseObject Addon::callHooks('event_updated', $event['id']); } else { - $event['guid'] = defaults($arr, 'guid', System::UUID()); + $event['guid'] = defaults($arr, 'guid', System::createUUID()); // New event. Store it. DBA::insert('event', $event); diff --git a/src/Model/Item.php b/src/Model/Item.php index d8e814b8e6..619f5dc349 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1205,7 +1205,7 @@ class Item extends BaseObject } elseif (!empty($item['uri'])) { $guid = self::guidFromUri($item['uri'], $prefix_host); } else { - $guid = System::UUID(hash('crc32', $prefix_host)); + $guid = System::createUUID(hash('crc32', $prefix_host)); } return $guid; @@ -2359,7 +2359,7 @@ class Item extends BaseObject public static function newURI($uid, $guid = "") { if ($guid == "") { - $guid = System::UUID(); + $guid = System::createUUID(); } return self::getApp()->get_baseurl() . '/object/' . $guid; @@ -2686,7 +2686,7 @@ class Item extends BaseObject } if ($contact['network'] != Protocol::FEED) { - $datarray["guid"] = System::UUID(); + $datarray["guid"] = System::createUUID(); unset($datarray["plink"]); $datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]); $datarray["parent-uri"] = $datarray["uri"]; @@ -3115,7 +3115,7 @@ class Item extends BaseObject $objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ; $new_item = [ - 'guid' => System::UUID(), + 'guid' => System::createUUID(), 'uri' => self::newURI($item['uid']), 'uid' => $item['uid'], 'contact-id' => $item_contact_id, diff --git a/src/Model/Mail.php b/src/Model/Mail.php index 64a99d4def..49247ca69d 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -46,7 +46,7 @@ class Mail return -2; } - $guid = System::UUID(); + $guid = System::createUUID(); $uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid; $convid = 0; @@ -73,7 +73,7 @@ class Mail $recip_handle = (($contact['addr']) ? $contact['addr'] : $contact['nick'] . '@' . $recip_host); $sender_handle = $a->user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3); - $conv_guid = System::UUID(); + $conv_guid = System::createUUID(); $convuri = $recip_handle . ':' . $conv_guid; $handles = $recip_handle . ';' . $sender_handle; @@ -171,7 +171,7 @@ class Mail $subject = L10n::t('[no subject]'); } - $guid = System::UUID(); + $guid = System::createUUID(); $uri = 'urn:X-dfrn:' . System::baseUrl() . ':' . local_user() . ':' . $guid; $me = Probe::uri($replyto); @@ -180,7 +180,7 @@ class Mail return -2; } - $conv_guid = System::UUID(); + $conv_guid = System::createUUID(); $recip_handle = $recipient['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3); diff --git a/src/Model/User.php b/src/Model/User.php index 366490bfc8..095bf56e72 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -495,7 +495,7 @@ class User $spubkey = $sres['pubkey']; $insert_result = DBA::insert('user', [ - 'guid' => System::UUID(), + 'guid' => System::createUUID(), 'username' => $username, 'password' => $new_password_encoded, 'email' => $email, diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 5239255fee..847809a36b 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -3200,7 +3200,7 @@ class Diaspora $author = self::myHandle($owner); $message = ["author" => $author, - "guid" => System::UUID(), + "guid" => System::createUUID(), "parent_type" => "Post", "parent_guid" => $item["guid"]]; From e01d5e4b311e043194a42da41343bc3548f090bb Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 11:56:05 +0000 Subject: [PATCH 70/97] Function naming ... --- src/Protocol/ActivityPub.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 4cf65bd31b..c79bca6d7e 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -1021,7 +1021,7 @@ class ActivityPub } elseif (in_array($activity['type'], ['Like', 'Dislike'])) { // Create a mostly empty array out of the activity data (instead of the object). // This way we later don't have to check for the existence of ech individual array element. - $object_data = self::ProcessObject($activity); + $object_data = self::processObject($activity); $object_data['name'] = $activity['type']; $object_data['author'] = $activity['actor']; $object_data['object'] = $object_id; @@ -1336,7 +1336,7 @@ class ActivityPub case 'Note': case 'Article': case 'Video': - return self::ProcessObject($data); + return self::processObject($data); case 'Announce': if (empty($data['object'])) { @@ -1361,7 +1361,7 @@ class ActivityPub * * @return */ - private static function ProcessObject(&$object) + private static function processObject(&$object) { if (empty($object['id'])) { return false; From de8787dd5bb9fadd6388c050bad35ec4c0332e08 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 12:01:16 +0000 Subject: [PATCH 71/97] Changed comment --- src/Util/HTTPSignature.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 7adaa82f78..c02124874f 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -265,7 +265,7 @@ class HTTPSignature return ''; } - /** + /* * Functions for ActivityPub */ From c4994626e924d1e8d4767fbb371e2735e30e413d Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 13:31:32 +0000 Subject: [PATCH 72/97] Corrected function names --- src/Util/LDSignature.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Util/LDSignature.php b/src/Util/LDSignature.php index 51235204fc..ebbffeb1e8 100644 --- a/src/Util/LDSignature.php +++ b/src/Util/LDSignature.php @@ -36,8 +36,8 @@ class LDSignature } $pubkey = $profile['pubkey']; - $ohash = self::hash(self::signable_options($data['signature'])); - $dhash = self::hash(self::signable_data($data)); + $ohash = self::hash(self::signableOptions($data['signature'])); + $dhash = self::hash(self::signableData($data)); $x = Crypto::rsaVerify($ohash . $dhash, base64_decode($data['signature']['signatureValue']), $pubkey); logger('LD-verify: ' . intval($x)); @@ -58,20 +58,20 @@ class LDSignature 'created' => DateTimeFormat::utcNow(DateTimeFormat::ATOM) ]; - $ohash = self::hash(self::signable_options($options)); - $dhash = self::hash(self::signable_data($data)); + $ohash = self::hash(self::signableOptions($options)); + $dhash = self::hash(self::signableData($data)); $options['signatureValue'] = base64_encode(Crypto::rsaSign($ohash . $dhash, $owner['uprvkey'])); return array_merge($data, ['signature' => $options]); } - private static function signable_data($data) + private static function signableData($data) { unset($data['signature']); return $data; } - private static function signable_options($options) + private static function signableOptions($options) { $newopts = ['@context' => 'https://w3id.org/identity/v1']; From 793387e2b5496bf4ffd311250c86f5bed38e554a Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 15:26:20 +0000 Subject: [PATCH 73/97] Only communicate with contacts that aren't pending --- src/Protocol/ActivityPub.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index c79bca6d7e..663b03e939 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -470,7 +470,8 @@ class ActivityPub foreach ($permissions[$element] as $receiver) { if ($receiver == $item_profile['followers']) { $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid, - 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB]); + 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB, + 'archive' => false, 'pending' => false]); while ($contact = DBA::fetch($contacts)) { $contact = defaults($contact, 'batch', $contact['notify']); $inboxes[$contact] = $contact; @@ -1177,7 +1178,8 @@ class ActivityPub if (($receiver == self::PUBLIC) && !empty($actor)) { // This will most likely catch all OStatus connections to Mastodon - $condition = ['alias' => [$actor, normalise_link($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND]]; + $condition = ['alias' => [$actor, normalise_link($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND] + , 'archive' => false, 'pending' => false]; $contacts = DBA::select('contact', ['uid'], $condition); while ($contact = DBA::fetch($contacts)) { if ($contact['uid'] != 0) { @@ -1189,7 +1191,7 @@ class ActivityPub if (in_array($receiver, [$followers, self::PUBLIC]) && !empty($actor)) { $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND], - 'network' => Protocol::ACTIVITYPUB]; + 'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false]; $contacts = DBA::select('contact', ['uid'], $condition); while ($contact = DBA::fetch($contacts)) { if ($contact['uid'] != 0) { From a36d010f8635e74293bb1264f9defb6d8f24b45b Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 21:03:29 +0000 Subject: [PATCH 74/97] Composer-foo --- composer.lock | 586 ++++++++++++++++++++++++++++---------------------- 1 file changed, 325 insertions(+), 261 deletions(-) diff --git a/composer.lock b/composer.lock index 27e0f329e0..1c5c25c0f4 100644 --- a/composer.lock +++ b/composer.lock @@ -41,16 +41,16 @@ }, { "name": "bower-asset/Chart-js", - "version": "v2.7.2", + "version": "v2.7.1", "source": { "type": "git", "url": "https://github.com/chartjs/Chart.js.git", - "reference": "98f104cdd03617f1300b417b3d60c23d4e3e3403" + "reference": "0fead21939b92c15093c1b7d5ee2627fb5900fff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/chartjs/Chart.js/zipball/98f104cdd03617f1300b417b3d60c23d4e3e3403", - "reference": "98f104cdd03617f1300b417b3d60c23d4e3e3403", + "url": "https://api.github.com/repos/chartjs/Chart.js/zipball/0fead21939b92c15093c1b7d5ee2627fb5900fff", + "reference": "0fead21939b92c15093c1b7d5ee2627fb5900fff", "shasum": "" }, "type": "bower-asset-library", @@ -69,7 +69,7 @@ "MIT" ], "description": "Simple HTML5 charts using the canvas element.", - "time": "2018-03-01T21:45:21+00:00" + "time": "2017-10-28T15:01:52+00:00" }, { "name": "bower-asset/base64", @@ -135,16 +135,16 @@ }, { "name": "bower-asset/vue", - "version": "v2.5.17", + "version": "v2.5.16", "source": { "type": "git", "url": "https://github.com/vuejs/vue.git", - "reference": "636c9b4ef17f2062720b677cbbe613f146f4d4db" + "reference": "25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vuejs/vue/zipball/636c9b4ef17f2062720b677cbbe613f146f4d4db", - "reference": "636c9b4ef17f2062720b677cbbe613f146f4d4db", + "url": "https://api.github.com/repos/vuejs/vue/zipball/25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6", + "reference": "25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6", "shasum": "" }, "type": "bower-asset-library" @@ -195,119 +195,30 @@ ], "time": "2016-04-25T04:17:52+00:00" }, - { - "name": "divineomega/do-file-cache", - "version": "v2.0.2", - "source": { - "type": "git", - "url": "https://github.com/DivineOmega/DO-File-Cache.git", - "reference": "261c6e30a0de8cd325f826d08b2e51b2e367a1a3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/DivineOmega/DO-File-Cache/zipball/261c6e30a0de8cd325f826d08b2e51b2e367a1a3", - "reference": "261c6e30a0de8cd325f826d08b2e51b2e367a1a3", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^6.5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "DivineOmega\\DOFileCache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0-only" - ], - "description": "DO File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.", - "keywords": [ - "cache", - "caching", - "caching library", - "file cache", - "library", - "php" - ], - "time": "2018-09-12T23:08:34+00:00" - }, - { - "name": "divineomega/do-file-cache-psr-6", - "version": "v2.0.1", - "source": { - "type": "git", - "url": "https://github.com/DivineOmega/DO-File-Cache-PSR-6.git", - "reference": "18f9807d0491d093e9a12741afb40257d92f017e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/DivineOmega/DO-File-Cache-PSR-6/zipball/18f9807d0491d093e9a12741afb40257d92f017e", - "reference": "18f9807d0491d093e9a12741afb40257d92f017e", - "shasum": "" - }, - "require": { - "divineomega/do-file-cache": "^2.0.0", - "psr/cache": "^1.0" - }, - "require-dev": { - "cache/integration-tests": "^0.16.0", - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5.7" - }, - "type": "library", - "autoload": { - "psr-4": { - "DivineOmega\\DOFileCachePSR6\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0-only" - ], - "authors": [ - { - "name": "Jordan Hall", - "email": "jordan@hall05.co.uk" - } - ], - "description": "PSR-6 adapter for DO File Cache", - "time": "2018-07-13T08:32:36+00:00" - }, { "name": "divineomega/password_exposed", - "version": "v2.5.3", + "version": "v2.5.1", "source": { "type": "git", "url": "https://github.com/DivineOmega/password_exposed.git", - "reference": "1f1b49e3ec55b0f07115d342b145091368b081c4" + "reference": "c928bf722eb02398df11076add60df070cb55581" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/DivineOmega/password_exposed/zipball/1f1b49e3ec55b0f07115d342b145091368b081c4", - "reference": "1f1b49e3ec55b0f07115d342b145091368b081c4", + "url": "https://api.github.com/repos/DivineOmega/password_exposed/zipball/c928bf722eb02398df11076add60df070cb55581", + "reference": "c928bf722eb02398df11076add60df070cb55581", "shasum": "" }, "require": { - "divineomega/do-file-cache-psr-6": "^2.0", "guzzlehttp/guzzle": "^6.3", "paragonie/certainty": "^1", - "php": ">=5.6" + "php": ">=5.6", + "rapidwebltd/rw-file-cache-psr-6": "^1.0" }, "require-dev": { "fzaninotto/faker": "^1.7", - "php-coveralls/php-coveralls": "^2.1", "phpunit/phpunit": "^5.7", + "satooshi/php-coveralls": "^2.0", "vimeo/psalm": "^1" }, "type": "library", @@ -330,7 +241,7 @@ } ], "description": "This PHP package provides a `password_exposed` helper function, that uses the haveibeenpwned.com API to check if a password has been exposed in a data breach.", - "time": "2018-07-12T22:09:43+00:00" + "time": "2018-04-02T18:16:36+00:00" }, { "name": "ezyang/htmlpurifier", @@ -378,16 +289,16 @@ }, { "name": "fxp/composer-asset-plugin", - "version": "v1.4.4", + "version": "v1.4.2", "source": { "type": "git", "url": "https://github.com/fxpio/composer-asset-plugin.git", - "reference": "0d07328eef6e6f3753aa835fd2faef7fed1717bf" + "reference": "61352d99940d2b2392a5d2db83b8c0ef5faf222a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fxpio/composer-asset-plugin/zipball/0d07328eef6e6f3753aa835fd2faef7fed1717bf", - "reference": "0d07328eef6e6f3753aa835fd2faef7fed1717bf", + "url": "https://api.github.com/repos/fxpio/composer-asset-plugin/zipball/61352d99940d2b2392a5d2db83b8c0ef5faf222a", + "reference": "61352d99940d2b2392a5d2db83b8c0ef5faf222a", "shasum": "" }, "require": { @@ -395,7 +306,7 @@ "php": ">=5.3.3" }, "require-dev": { - "composer/composer": "^1.6.0" + "composer/composer": "^1.4.0" }, "type": "composer-plugin", "extra": { @@ -433,20 +344,20 @@ "npm", "package" ], - "time": "2018-07-02T11:37:17+00:00" + "time": "2017-10-20T06:53:56+00:00" }, { "name": "guzzlehttp/guzzle", - "version": "6.3.3", + "version": "6.3.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699", "shasum": "" }, "require": { @@ -456,7 +367,7 @@ }, "require-dev": { "ext-curl": "*", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", + "phpunit/phpunit": "^4.0 || ^5.0", "psr/log": "^1.0" }, "suggest": { @@ -465,7 +376,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "6.3-dev" + "dev-master": "6.2-dev" } }, "autoload": { @@ -498,7 +409,7 @@ "rest", "web service" ], - "time": "2018-04-22T15:46:56+00:00" + "time": "2017-06-22T18:50:49+00:00" }, { "name": "guzzlehttp/promises", @@ -761,16 +672,16 @@ }, { "name": "mobiledetect/mobiledetectlib", - "version": "2.8.33", + "version": "2.8.30", "source": { "type": "git", "url": "https://github.com/serbanghita/Mobile-Detect.git", - "reference": "cd385290f9a0d609d2eddd165a1e44ec1bf12102" + "reference": "5500bbbf312fe77ef0c7223858dad84fe49ee0c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/serbanghita/Mobile-Detect/zipball/cd385290f9a0d609d2eddd165a1e44ec1bf12102", - "reference": "cd385290f9a0d609d2eddd165a1e44ec1bf12102", + "url": "https://api.github.com/repos/serbanghita/Mobile-Detect/zipball/5500bbbf312fe77ef0c7223858dad84fe49ee0c3", + "reference": "5500bbbf312fe77ef0c7223858dad84fe49ee0c3", "shasum": "" }, "require": { @@ -809,7 +720,7 @@ "mobile detector", "php mobile detect" ], - "time": "2018-09-01T15:05:15+00:00" + "time": "2017-12-18T10:38:51+00:00" }, { "name": "npm-asset/cropperjs", @@ -950,16 +861,67 @@ }, { "name": "npm-asset/fullcalendar", - "version": "3.9.0", + "version": "3.8.2", "dist": { "type": "tar", - "url": "https://registry.npmjs.org/fullcalendar/-/fullcalendar-3.9.0.tgz", + "url": "https://registry.npmjs.org/fullcalendar/-/fullcalendar-3.8.2.tgz", "reference": null, - "shasum": "b608a9989f3416f0b1d526c6bdfeeaf2ac79eda5" + "shasum": "ef7dc77b89134bbe6163e51136f7a1f8bfc1d807" }, "require": { "npm-asset/jquery": ">=2,<4.0", - "npm-asset/moment": ">=2.20.1,<3.0.0" + "npm-asset/moment": ">=2.9.0,<3.0.0" + }, + "require-dev": { + "npm-asset/awesome-typescript-loader": ">=3.3.0,<4.0.0", + "npm-asset/bootstrap": ">=3.3.7,<4.0.0", + "npm-asset/components-jqueryui": "dev-github:components/jqueryui", + "npm-asset/css-loader": ">=0.28.7,<0.29.0", + "npm-asset/del": ">=2.2.1,<3.0.0", + "npm-asset/dts-generator": ">=2.1.0,<3.0.0", + "npm-asset/eslint": ">=4.13.1,<5.0.0", + "npm-asset/eslint-config-standard": ">=11.0.0-beta.0,<12.0.0", + "npm-asset/eslint-plugin-import": ">=2.8.0,<3.0.0", + "npm-asset/eslint-plugin-node": ">=5.2.1,<6.0.0", + "npm-asset/eslint-plugin-promise": ">=3.6.0,<4.0.0", + "npm-asset/eslint-plugin-standard": ">=3.0.1,<4.0.0", + "npm-asset/extract-text-webpack-plugin": ">=3.0.2,<4.0.0", + "npm-asset/glob": ">=7.1.2,<8.0.0", + "npm-asset/gulp": ">=3.9.1,<4.0.0", + "npm-asset/gulp-cssmin": ">=0.1.7,<0.2.0", + "npm-asset/gulp-eslint": ">=4.0.0,<5.0.0", + "npm-asset/gulp-filter": ">=4.0.0,<5.0.0", + "npm-asset/gulp-modify-file": ">=1.0.0,<2.0.0", + "npm-asset/gulp-rename": ">=1.2.2,<2.0.0", + "npm-asset/gulp-shell": ">=0.6.5,<0.7.0", + "npm-asset/gulp-tslint": ">=8.1.2,<9.0.0", + "npm-asset/gulp-uglify": ">=2.0.0,<3.0.0", + "npm-asset/gulp-util": ">=3.0.7,<4.0.0", + "npm-asset/gulp-watch": ">=4.3.11,<5.0.0", + "npm-asset/gulp-zip": ">=3.2.0,<4.0.0", + "npm-asset/jasmine-core": "2.5.2", + "npm-asset/jasmine-fixture": ">=2.0.0,<3.0.0", + "npm-asset/jasmine-jquery": ">=2.1.1,<3.0.0", + "npm-asset/jquery-mockjax": ">=2.2.0,<3.0.0", + "npm-asset/jquery-simulate": "dev-github:jquery/jquery-simulate", + "npm-asset/karma": ">=0.13.22,<0.14.0", + "npm-asset/karma-jasmine": ">=1.0.2,<2.0.0", + "npm-asset/karma-phantomjs-launcher": ">=1.0.0,<2.0.0", + "npm-asset/karma-sourcemap-loader": ">=0.3.7,<0.4.0", + "npm-asset/karma-verbose-reporter": "0.0.6", + "npm-asset/moment-timezone": ">=0.5.5,<0.6.0", + "npm-asset/native-promise-only": ">=0.8.1,<0.9.0", + "npm-asset/node-sass": ">=4.7.2,<5.0.0", + "npm-asset/phantomjs-prebuilt": ">=2.1.7,<3.0.0", + "npm-asset/sass-loader": ">=6.0.6,<7.0.0", + "npm-asset/tslib": ">=1.8.0,<2.0.0", + "npm-asset/tslint": ">=5.8.0,<6.0.0", + "npm-asset/tslint-config-standard": ">=7.0.0,<8.0.0", + "npm-asset/types--jquery": "2.0.47", + "npm-asset/typescript": ">=2.6.2,<3.0.0", + "npm-asset/webpack": ">=3.8.1,<4.0.0", + "npm-asset/webpack-stream": ">=4.0.0,<5.0.0", + "npm-asset/yargs": ">=4.8.1,<5.0.0" }, "type": "npm-asset-library", "extra": { @@ -1007,7 +969,7 @@ "full-sized", "jquery-plugin" ], - "time": "2018-03-05T03:30:23+00:00" + "time": "2018-01-30T23:49:01+00:00" }, { "name": "npm-asset/imagesloaded", @@ -1234,12 +1196,12 @@ }, { "name": "npm-asset/jquery-datetimepicker", - "version": "2.5.20", + "version": "2.5.17", "dist": { "type": "tar", - "url": "https://registry.npmjs.org/jquery-datetimepicker/-/jquery-datetimepicker-2.5.20.tgz", + "url": "https://registry.npmjs.org/jquery-datetimepicker/-/jquery-datetimepicker-2.5.17.tgz", "reference": null, - "shasum": "687d6204b90b03dc93f725f8df036e1d061f37ac" + "shasum": "8857a631f248081d4072563bde40fa8c17e407b1" }, "require": { "npm-asset/jquery": ">=1.7.2", @@ -1247,14 +1209,8 @@ "npm-asset/php-date-formatter": ">=1.3.4,<2.0.0" }, "require-dev": { - "npm-asset/chai": ">=4.1.2,<5.0.0", "npm-asset/concat": "dev-github:azer/concat", "npm-asset/concat-cli": ">=4.0.0,<5.0.0", - "npm-asset/karma": ">=2.0.0,<3.0.0", - "npm-asset/karma-chai": ">=0.1.0,<0.2.0", - "npm-asset/karma-firefox-launcher": ">=1.1.0,<2.0.0", - "npm-asset/karma-mocha": ">=1.3.0,<2.0.0", - "npm-asset/mocha": ">=5.0.4,<6.0.0", "npm-asset/uglifycss": ">=0.0.27,<0.0.28", "npm-asset/uglifyjs": ">=2.4.10,<3.0.0" }, @@ -1270,13 +1226,13 @@ "url": "git+https://github.com/xdan/datetimepicker.git" }, "npm-asset-scripts": { - "test": "karma start --browsers Firefox karma.conf.js --single-run", + "test": "echo \"Error: no test specified\" && exit 1", "concat": "concat-cli -f node_modules/php-date-formatter/js/php-date-formatter.min.js jquery.datetimepicker.js node_modules/jquery-mousewheel/jquery.mousewheel.js -o build/jquery.datetimepicker.full.js", "minify": "uglifyjs jquery.datetimepicker.js -c -m -o build/jquery.datetimepicker.min.js && uglifycss jquery.datetimepicker.css > build/jquery.datetimepicker.min.css", "minifyconcat": "uglifyjs build/jquery.datetimepicker.full.js -c -m -o build/jquery.datetimepicker.full.min.js", "github": "git add --all && git commit -m \"New version %npm_package_version% \" && git tag %npm_package_version% && git push --tags origin HEAD:master && npm publish", "build": "npm run minify && npm run concat && npm run minifyconcat", - "public": "npm run test && npm version patch --no-git-tag-version && npm run build && npm run github" + "public": "npm version patch --no-git-tag-version && npm run build && npm run github" } }, "license": [ @@ -1286,7 +1242,7 @@ { "name": "Chupurnov", "email": "chupurnov@gmail.com", - "url": "https://xdsoft.net/" + "url": "http://xdsoft.net/" } ], "description": "jQuery Plugin DateTimePicker it is DatePicker and TimePicker in one", @@ -1300,7 +1256,7 @@ "time", "timepicker" ], - "time": "2018-03-21T16:26:39+00:00" + "time": "2018-01-23T05:56:50+00:00" }, { "name": "npm-asset/jquery-mousewheel", @@ -1359,12 +1315,45 @@ }, { "name": "npm-asset/moment", - "version": "2.22.2", + "version": "2.20.1", "dist": { "type": "tar", - "url": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz", + "url": "https://registry.npmjs.org/moment/-/moment-2.20.1.tgz", "reference": null, - "shasum": "3c257f9839fc0e93ff53149632239eb90783ff66" + "shasum": "d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd" + }, + "require-dev": { + "npm-asset/benchmark": "dev-default|*", + "npm-asset/coveralls": ">=2.11.2,<3.0.0", + "npm-asset/es6-promise": "dev-default|*", + "npm-asset/grunt": "~0.4", + "npm-asset/grunt-benchmark": "dev-default|*", + "npm-asset/grunt-cli": "dev-default|*", + "npm-asset/grunt-contrib-clean": "dev-default|*", + "npm-asset/grunt-contrib-concat": "dev-default|*", + "npm-asset/grunt-contrib-copy": "dev-default|*", + "npm-asset/grunt-contrib-jshint": "dev-default|*", + "npm-asset/grunt-contrib-uglify": "dev-default|*", + "npm-asset/grunt-contrib-watch": "dev-default|*", + "npm-asset/grunt-env": "dev-default|*", + "npm-asset/grunt-exec": "dev-default|*", + "npm-asset/grunt-jscs": "dev-default|*", + "npm-asset/grunt-karma": "dev-default|*", + "npm-asset/grunt-nuget": "dev-default|*", + "npm-asset/grunt-string-replace": "dev-default|*", + "npm-asset/karma": "dev-default|*", + "npm-asset/karma-chrome-launcher": "dev-default|*", + "npm-asset/karma-firefox-launcher": "dev-default|*", + "npm-asset/karma-qunit": "dev-default|*", + "npm-asset/karma-sauce-launcher": "dev-default|*", + "npm-asset/load-grunt-tasks": "dev-default|*", + "npm-asset/nyc": ">=2.1.4,<3.0.0", + "npm-asset/qunit": ">=0.7.5,<0.8.0", + "npm-asset/qunit-cli": ">=0.1.4,<0.2.0", + "npm-asset/rollup": "dev-default|*", + "npm-asset/spacejam": "dev-default|*", + "npm-asset/typescript": ">=1.8.10,<2.0.0", + "npm-asset/uglify-js": "dev-default|*" }, "type": "npm-asset-library", "extra": { @@ -1434,21 +1423,16 @@ "time", "validate" ], - "time": "2018-06-01T06:58:41+00:00" + "time": "2017-12-19T04:44:18+00:00" }, { "name": "npm-asset/php-date-formatter", - "version": "v1.3.5", - "source": { - "type": "git", - "url": "https://github.com/kartik-v/php-date-formatter.git", - "reference": "d842e1c4e6a8d6108017b726321c305bb5ae4fb5" - }, + "version": "1.3.4", "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kartik-v/php-date-formatter/zipball/d842e1c4e6a8d6108017b726321c305bb5ae4fb5", - "reference": "d842e1c4e6a8d6108017b726321c305bb5ae4fb5", - "shasum": "" + "type": "tar", + "url": "https://registry.npmjs.org/php-date-formatter/-/php-date-formatter-1.3.4.tgz", + "reference": null, + "shasum": "09a15ae0766ba0beb1900c27c1ec319ef2e4563e" }, "type": "npm-asset-library", "extra": { @@ -1461,31 +1445,35 @@ }, "npm-asset-repository": { "type": "git", - "url": "https://github.com/kartik-v/php-date-formatter.git" - } + "url": "git+https://github.com/kartik-v/php-date-formatter.git" + }, + "npm-asset-scripts": [] }, "license": [ "BSD-3-Clause" ], "authors": [ - "Kartik Visweswaran " + { + "name": "Kartik Visweswaran", + "email": "kartikv2@gmail.com" + } ], "description": "A Javascript datetime formatting and manipulation library using PHP date-time formats.", "homepage": "https://github.com/kartik-v/php-date-formatter", - "time": "2018-07-13T06:56:46+00:00" + "time": "2016-02-18T15:15:55+00:00" }, { "name": "paragonie/certainty", - "version": "v1.0.4", + "version": "v1.0.2", "source": { "type": "git", "url": "https://github.com/paragonie/certainty.git", - "reference": "d0f22c0fe579cf0e4f8ee301de5bc97ab124faac" + "reference": "a2d14f5b0b85c58329dee248d77d34e7e1202a32" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/certainty/zipball/d0f22c0fe579cf0e4f8ee301de5bc97ab124faac", - "reference": "d0f22c0fe579cf0e4f8ee301de5bc97ab124faac", + "url": "https://api.github.com/repos/paragonie/certainty/zipball/a2d14f5b0b85c58329dee248d77d34e7e1202a32", + "reference": "a2d14f5b0b85c58329dee248d77d34e7e1202a32", "shasum": "" }, "require": { @@ -1532,27 +1520,28 @@ "ssl", "tls" ], - "time": "2018-04-09T07:21:55+00:00" + "time": "2018-03-12T18:34:23+00:00" }, { "name": "paragonie/constant_time_encoding", - "version": "v2.2.2", + "version": "v1.0.2", "source": { "type": "git", "url": "https://github.com/paragonie/constant_time_encoding.git", - "reference": "eccf915f45f911bfb189d1d1638d940ec6ee6e33" + "reference": "6111a38faf6fdebc14e36652d22036f379ba58d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/eccf915f45f911bfb189d1d1638d940ec6ee6e33", - "reference": "eccf915f45f911bfb189d1d1638d940ec6ee6e33", + "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/6111a38faf6fdebc14e36652d22036f379ba58d3", + "reference": "6111a38faf6fdebc14e36652d22036f379ba58d3", "shasum": "" }, "require": { - "php": "^7" + "php": "^5.3|^7" }, "require-dev": { - "phpunit/phpunit": "^6|^7", + "paragonie/random_compat": "^1|^2", + "phpunit/phpunit": "4.*|5.*", "vimeo/psalm": "^1" }, "type": "library", @@ -1594,20 +1583,20 @@ "hex2bin", "rfc4648" ], - "time": "2018-03-10T19:47:49+00:00" + "time": "2018-03-10T19:46:06+00:00" }, { "name": "paragonie/random_compat", - "version": "v2.0.17", + "version": "v2.0.11", "source": { "type": "git", "url": "https://github.com/paragonie/random_compat.git", - "reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d" + "reference": "5da4d3c796c275c55f057af5a643ae297d96b4d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/random_compat/zipball/29af24f25bab834fcbb38ad2a69fa93b867e070d", - "reference": "29af24f25bab834fcbb38ad2a69fa93b867e070d", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/5da4d3c796c275c55f057af5a643ae297d96b4d8", + "reference": "5da4d3c796c275c55f057af5a643ae297d96b4d8", "shasum": "" }, "require": { @@ -1639,28 +1628,27 @@ "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", "keywords": [ "csprng", - "polyfill", "pseudorandom", "random" ], - "time": "2018-07-04T16:31:37+00:00" + "time": "2017-09-27T21:40:39+00:00" }, { "name": "paragonie/sodium_compat", - "version": "v1.7.0", + "version": "v1.6.0", "source": { "type": "git", "url": "https://github.com/paragonie/sodium_compat.git", - "reference": "7b73005be3c224f12c47bd75a23ce24b762e47e8" + "reference": "1f6e5682eff4a5a6a394b14331a1904f1740e432" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/7b73005be3c224f12c47bd75a23ce24b762e47e8", - "reference": "7b73005be3c224f12c47bd75a23ce24b762e47e8", + "url": "https://api.github.com/repos/paragonie/sodium_compat/zipball/1f6e5682eff4a5a6a394b14331a1904f1740e432", + "reference": "1f6e5682eff4a5a6a394b14331a1904f1740e432", "shasum": "" }, "require": { - "paragonie/random_compat": ">=1", + "paragonie/random_compat": "^1|^2", "php": "^5.2.4|^5.3|^5.4|^5.5|^5.6|^7" }, "require-dev": { @@ -1725,7 +1713,7 @@ "secret-key cryptography", "side-channel resistant" ], - "time": "2018-09-22T03:59:58+00:00" + "time": "2018-02-15T05:50:20+00:00" }, { "name": "pear/text_languagedetect", @@ -1867,6 +1855,94 @@ ], "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "rapidwebltd/rw-file-cache", + "version": "v1.2.5", + "source": { + "type": "git", + "url": "https://github.com/rapidwebltd/RW-File-Cache.git", + "reference": "4a1d5aaefa6ffafec8e2d60787f12bcd9890977e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rapidwebltd/RW-File-Cache/zipball/4a1d5aaefa6ffafec8e2d60787f12bcd9890977e", + "reference": "4a1d5aaefa6ffafec8e2d60787f12bcd9890977e", + "shasum": "" + }, + "require": { + "php": ">=5.2.1" + }, + "require-dev": { + "phpunit/phpunit": "^5.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "rapidweb\\RWFileCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-only" + ], + "description": "RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.", + "homepage": "https://github.com/rapidwebltd/RW-File-Cache", + "keywords": [ + "cache", + "caching", + "caching library", + "file cache", + "library", + "php" + ], + "time": "2018-01-23T17:20:58+00:00" + }, + { + "name": "rapidwebltd/rw-file-cache-psr-6", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/rapidwebltd/RW-File-Cache-PSR-6.git", + "reference": "b74ea201d4c964f0e6db0fb036d1ab28a570df66" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rapidwebltd/RW-File-Cache-PSR-6/zipball/b74ea201d4c964f0e6db0fb036d1ab28a570df66", + "reference": "b74ea201d4c964f0e6db0fb036d1ab28a570df66", + "shasum": "" + }, + "require": { + "psr/cache": "^1.0", + "rapidwebltd/rw-file-cache": "^1.2.3" + }, + "require-dev": { + "cache/integration-tests": "^0.16.0", + "phpunit/phpunit": "^5.7" + }, + "type": "library", + "autoload": { + "psr-4": { + "rapidweb\\RWFileCachePSR6\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-only" + ], + "authors": [ + { + "name": "Jordan Hall", + "email": "jordan.hall@rapidweb.biz" + } + ], + "description": "PSR-6 adapter for RW File Cache", + "time": "2018-01-30T19:13:45+00:00" + }, { "name": "seld/cli-prompt", "version": "1.0.3", @@ -1917,16 +1993,16 @@ }, { "name": "smarty/smarty", - "version": "v3.1.33", + "version": "v3.1.31", "source": { "type": "git", "url": "https://github.com/smarty-php/smarty.git", - "reference": "dd55b23121e55a3b4f1af90a707a6c4e5969530f" + "reference": "c7d42e4a327c402897dd587871434888fde1e7a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/smarty-php/smarty/zipball/dd55b23121e55a3b4f1af90a707a6c4e5969530f", - "reference": "dd55b23121e55a3b4f1af90a707a6c4e5969530f", + "url": "https://api.github.com/repos/smarty-php/smarty/zipball/c7d42e4a327c402897dd587871434888fde1e7a9", + "reference": "c7d42e4a327c402897dd587871434888fde1e7a9", "shasum": "" }, "require": { @@ -1966,7 +2042,7 @@ "keywords": [ "templating" ], - "time": "2018-09-12T20:54:16+00:00" + "time": "2016-12-14T21:57:25+00:00" } ], "packages-dev": [ @@ -2115,6 +2191,53 @@ ], "time": "2017-10-19T19:58:43+00:00" }, + { + "name": "phar-io/version", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df", + "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2017-03-05T17:38:23+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "1.0.1", @@ -2263,16 +2386,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.8.0", + "version": "1.7.6", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712", + "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712", "shasum": "" }, "require": { @@ -2284,12 +2407,12 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8.x-dev" + "dev-master": "1.7.x-dev" } }, "autoload": { @@ -2322,7 +2445,7 @@ "spy", "stub" ], - "time": "2018-08-05T17:53:17+00:00" + "time": "2018-04-18T13:57:24+00:00" }, { "name": "phpunit/dbunit", @@ -3282,81 +3405,22 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2016-10-03T07:35:21+00:00" }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.9.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", - "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.9-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "time": "2018-08-06T14:22:27+00:00" - }, { "name": "symfony/yaml", - "version": "v3.4.15", + "version": "v3.4.8", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8" + "reference": "a42f9da85c7c38d59f5e53f076fe81a091f894d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/c2f4812ead9f847cb69e90917ca7502e6892d6b8", - "reference": "c2f4812ead9f847cb69e90917ca7502e6892d6b8", + "url": "https://api.github.com/repos/symfony/yaml/zipball/a42f9da85c7c38d59f5e53f076fe81a091f894d0", + "reference": "a42f9da85c7c38d59f5e53f076fe81a091f894d0", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8", - "symfony/polyfill-ctype": "~1.8" + "php": "^5.5.9|>=7.0.8" }, "conflict": { "symfony/console": "<3.4" @@ -3397,7 +3461,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-08-10T07:34:36+00:00" + "time": "2018-04-03T05:14:20+00:00" }, { "name": "webmozart/assert", From 162233e503c34a942f5093cdaa409644c4445016 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 21:04:56 +0000 Subject: [PATCH 75/97] moved line --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b1fde04eb9..ebf8217e5e 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "php": ">=5.6.1", "ext-xml": "*", "asika/simple-console": "^1.0", + "digitalbazaar/json-ld": "^0.4.7", "divineomega/password_exposed": "^2.4", "ezyang/htmlpurifier": "~4.7.0", "league/html-to-markdown": "~4.8.0", @@ -37,8 +38,7 @@ "npm-asset/jgrowl": "^1.4", "npm-asset/fullcalendar": "^3.0.1", "npm-asset/cropperjs": "1.2.2", - "npm-asset/imagesloaded": "4.1.4", - "digitalbazaar/json-ld": "^0.4.7" + "npm-asset/imagesloaded": "4.1.4" }, "repositories": [ { From 30f67d6e140394eecd23d558b41aff3cd82c08d0 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 21:14:01 +0000 Subject: [PATCH 76/97] removed unneded line --- src/Util/JsonLD.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 4100b258bb..2b6fac4ad4 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -5,7 +5,6 @@ namespace Friendica\Util; use Friendica\Core\Cache; -use digitalbazaar\jsonld as DBJsonLD; use Exception; /** From a5ddcb367bb697516f1fe4c5bebee5cb25a760cc Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 27 Sep 2018 21:19:14 +0000 Subject: [PATCH 77/97] Newly generated messages --- util/messages.po | 1427 +++++++++++++++++++++++----------------------- 1 file changed, 728 insertions(+), 699 deletions(-) diff --git a/util/messages.po b/util/messages.po index 0495cbb86c..c27fb25627 100644 --- a/util/messages.po +++ b/util/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-25 15:34+0000\n" +"POT-Creation-Date: 2018-09-27 21:18+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,47 +18,47 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" -#: index.php:261 mod/apps.php:14 +#: index.php:265 mod/apps.php:14 msgid "You must be logged in to use addons. " msgstr "" -#: index.php:308 mod/fetch.php:20 mod/fetch.php:47 mod/fetch.php:54 +#: index.php:312 mod/fetch.php:20 mod/fetch.php:47 mod/fetch.php:54 #: mod/help.php:62 msgid "Not Found" msgstr "" -#: index.php:313 mod/viewcontacts.php:35 mod/dfrn_poll.php:486 mod/help.php:65 +#: index.php:317 mod/viewcontacts.php:35 mod/dfrn_poll.php:486 mod/help.php:65 #: mod/cal.php:44 msgid "Page not found." msgstr "" -#: index.php:431 mod/group.php:83 mod/profperm.php:29 +#: index.php:435 mod/group.php:83 mod/profperm.php:29 msgid "Permission denied" msgstr "" -#: index.php:432 include/items.php:412 mod/crepair.php:100 +#: index.php:436 include/items.php:413 mod/crepair.php:100 #: mod/wallmessage.php:16 mod/wallmessage.php:40 mod/wallmessage.php:79 -#: mod/wallmessage.php:103 mod/dfrn_confirm.php:66 mod/dirfind.php:27 +#: mod/wallmessage.php:103 mod/dfrn_confirm.php:67 mod/dirfind.php:27 #: mod/manage.php:131 mod/settings.php:43 mod/settings.php:149 #: mod/settings.php:665 mod/common.php:28 mod/network.php:34 mod/group.php:26 #: mod/delegate.php:27 mod/delegate.php:45 mod/delegate.php:56 -#: mod/repair_ostatus.php:16 mod/viewcontacts.php:60 mod/unfollow.php:17 -#: mod/unfollow.php:59 mod/unfollow.php:93 mod/register.php:53 +#: mod/repair_ostatus.php:16 mod/viewcontacts.php:60 mod/unfollow.php:20 +#: mod/unfollow.php:73 mod/unfollow.php:105 mod/register.php:53 #: mod/notifications.php:67 mod/message.php:60 mod/message.php:105 #: mod/ostatus_subscribe.php:17 mod/nogroup.php:23 mod/suggest.php:61 #: mod/wall_upload.php:104 mod/wall_upload.php:107 mod/api.php:35 #: mod/api.php:40 mod/profile_photo.php:29 mod/profile_photo.php:176 #: mod/profile_photo.php:198 mod/wall_attach.php:80 mod/wall_attach.php:83 -#: mod/item.php:166 mod/uimport.php:28 mod/cal.php:306 mod/regmod.php:108 +#: mod/item.php:166 mod/uimport.php:15 mod/cal.php:306 mod/regmod.php:108 #: mod/editpost.php:19 mod/fsuggest.php:80 mod/allfriends.php:23 -#: mod/contacts.php:381 mod/events.php:193 mod/follow.php:54 mod/follow.php:118 -#: mod/attach.php:39 mod/poke.php:145 mod/invite.php:21 mod/invite.php:112 +#: mod/contacts.php:387 mod/events.php:195 mod/follow.php:54 mod/follow.php:118 +#: mod/attach.php:39 mod/poke.php:144 mod/invite.php:21 mod/invite.php:112 #: mod/notes.php:32 mod/profiles.php:179 mod/profiles.php:511 -#: mod/photos.php:183 mod/photos.php:1065 +#: mod/photos.php:183 mod/photos.php:1067 msgid "Permission denied." msgstr "" -#: index.php:460 +#: index.php:464 msgid "toggle mobile" msgstr "" @@ -92,13 +92,13 @@ msgstr "" #: view/theme/duepuntozero/config.php:71 view/theme/quattro/config.php:73 #: view/theme/vier/config.php:119 view/theme/frio/config.php:118 -#: mod/crepair.php:150 mod/install.php:206 mod/install.php:244 +#: mod/crepair.php:150 mod/install.php:204 mod/install.php:242 #: mod/manage.php:184 mod/message.php:264 mod/message.php:430 -#: mod/fsuggest.php:114 mod/contacts.php:630 mod/events.php:533 -#: mod/localtime.php:56 mod/poke.php:195 mod/invite.php:155 -#: mod/profiles.php:577 mod/photos.php:1094 mod/photos.php:1180 -#: mod/photos.php:1452 mod/photos.php:1497 mod/photos.php:1536 -#: mod/photos.php:1596 src/Object/Post.php:795 +#: mod/fsuggest.php:114 mod/contacts.php:631 mod/events.php:560 +#: mod/localtime.php:56 mod/poke.php:194 mod/invite.php:155 +#: mod/profiles.php:577 mod/photos.php:1096 mod/photos.php:1182 +#: mod/photos.php:1454 mod/photos.php:1499 mod/photos.php:1538 +#: mod/photos.php:1598 src/Object/Post.php:795 msgid "Submit" msgstr "" @@ -186,8 +186,8 @@ msgstr "" #: view/theme/vier/theme.php:199 include/conversation.php:881 #: mod/dirfind.php:231 mod/match.php:90 mod/suggest.php:86 -#: mod/allfriends.php:76 mod/contacts.php:604 mod/contacts.php:610 -#: mod/follow.php:143 src/Model/Contact.php:933 src/Content/Widget.php:61 +#: mod/allfriends.php:76 mod/contacts.php:611 mod/follow.php:143 +#: src/Model/Contact.php:944 src/Content/Widget.php:61 msgid "Connect/Follow" msgstr "" @@ -195,7 +195,7 @@ msgstr "" msgid "Examples: Robert Morgenstein, Fishing" msgstr "" -#: view/theme/vier/theme.php:201 mod/directory.php:214 mod/contacts.php:842 +#: view/theme/vier/theme.php:201 mod/directory.php:214 mod/contacts.php:845 #: src/Content/Widget.php:63 msgid "Find" msgstr "" @@ -226,16 +226,16 @@ msgid "Local Directory" msgstr "" #: view/theme/vier/theme.php:251 include/text.php:909 src/Content/Nav.php:151 -#: src/Content/ForumManager.php:125 +#: src/Content/ForumManager.php:130 msgid "Forums" msgstr "" -#: view/theme/vier/theme.php:253 src/Content/ForumManager.php:127 +#: view/theme/vier/theme.php:253 src/Content/ForumManager.php:132 msgid "External link to forum" msgstr "" -#: view/theme/vier/theme.php:256 include/items.php:489 src/Object/Post.php:429 -#: src/App.php:786 src/Content/Widget.php:310 src/Content/ForumManager.php:130 +#: view/theme/vier/theme.php:256 include/items.php:490 src/Object/Post.php:429 +#: src/App.php:799 src/Content/Widget.php:307 src/Content/ForumManager.php:135 msgid "show more" msgstr "" @@ -320,8 +320,8 @@ msgstr "" msgid "End this session" msgstr "" -#: view/theme/frio/theme.php:269 mod/contacts.php:689 mod/contacts.php:877 -#: src/Model/Profile.php:875 src/Content/Nav.php:100 +#: view/theme/frio/theme.php:269 mod/contacts.php:690 mod/contacts.php:880 +#: src/Model/Profile.php:888 src/Content/Nav.php:100 msgid "Status" msgstr "" @@ -331,8 +331,8 @@ msgid "Your posts and conversations" msgstr "" #: view/theme/frio/theme.php:270 mod/newmember.php:24 mod/profperm.php:116 -#: mod/contacts.php:691 mod/contacts.php:893 src/Model/Profile.php:717 -#: src/Model/Profile.php:850 src/Model/Profile.php:883 src/Content/Nav.php:101 +#: mod/contacts.php:692 mod/contacts.php:896 src/Model/Profile.php:730 +#: src/Model/Profile.php:863 src/Model/Profile.php:896 src/Content/Nav.php:101 msgid "Profile" msgstr "" @@ -340,7 +340,7 @@ msgstr "" msgid "Your profile page" msgstr "" -#: view/theme/frio/theme.php:271 mod/fbrowser.php:35 src/Model/Profile.php:891 +#: view/theme/frio/theme.php:271 mod/fbrowser.php:35 src/Model/Profile.php:904 #: src/Content/Nav.php:102 msgid "Photos" msgstr "" @@ -349,8 +349,8 @@ msgstr "" msgid "Your photos" msgstr "" -#: view/theme/frio/theme.php:272 src/Model/Profile.php:899 -#: src/Model/Profile.php:902 src/Content/Nav.php:103 +#: view/theme/frio/theme.php:272 src/Model/Profile.php:912 +#: src/Model/Profile.php:915 src/Content/Nav.php:103 msgid "Videos" msgstr "" @@ -359,7 +359,7 @@ msgid "Your videos" msgstr "" #: view/theme/frio/theme.php:273 view/theme/frio/theme.php:277 mod/cal.php:276 -#: mod/events.php:390 src/Model/Profile.php:911 src/Model/Profile.php:922 +#: mod/events.php:391 src/Model/Profile.php:924 src/Model/Profile.php:935 #: src/Content/Nav.php:104 src/Content/Nav.php:170 msgid "Events" msgstr "" @@ -377,8 +377,8 @@ msgstr "" msgid "Conversations from your friends" msgstr "" -#: view/theme/frio/theme.php:277 src/Model/Profile.php:914 -#: src/Model/Profile.php:925 src/Content/Nav.php:170 +#: view/theme/frio/theme.php:277 src/Model/Profile.php:927 +#: src/Model/Profile.php:938 src/Content/Nav.php:170 msgid "Events and Calendar" msgstr "" @@ -400,8 +400,8 @@ msgid "Account settings" msgstr "" #: view/theme/frio/theme.php:280 include/text.php:906 mod/viewcontacts.php:125 -#: mod/contacts.php:836 mod/contacts.php:905 src/Model/Profile.php:954 -#: src/Model/Profile.php:957 src/Content/Nav.php:147 src/Content/Nav.php:213 +#: mod/contacts.php:839 mod/contacts.php:908 src/Model/Profile.php:967 +#: src/Model/Profile.php:970 src/Content/Nav.php:147 src/Content/Nav.php:213 msgid "Contacts" msgstr "" @@ -459,37 +459,37 @@ msgstr "" msgid "%s: Updating post-type." msgstr "" -#: include/items.php:355 mod/display.php:70 mod/display.php:245 -#: mod/display.php:341 mod/admin.php:283 mod/admin.php:1963 mod/admin.php:2211 +#: include/items.php:356 mod/display.php:71 mod/display.php:254 +#: mod/display.php:350 mod/admin.php:283 mod/admin.php:1963 mod/admin.php:2211 #: mod/notice.php:22 mod/viewsrc.php:22 msgid "Item not found." msgstr "" -#: include/items.php:393 +#: include/items.php:394 msgid "Do you really want to delete this item?" msgstr "" -#: include/items.php:395 mod/settings.php:1100 mod/settings.php:1106 +#: include/items.php:396 mod/settings.php:1100 mod/settings.php:1106 #: mod/settings.php:1113 mod/settings.php:1117 mod/settings.php:1121 #: mod/settings.php:1125 mod/settings.php:1129 mod/settings.php:1133 #: mod/settings.php:1153 mod/settings.php:1154 mod/settings.php:1155 #: mod/settings.php:1156 mod/settings.php:1157 mod/register.php:237 #: mod/message.php:154 mod/suggest.php:40 mod/dfrn_request.php:645 -#: mod/api.php:110 mod/contacts.php:465 mod/follow.php:150 mod/profiles.php:541 +#: mod/api.php:110 mod/contacts.php:471 mod/follow.php:150 mod/profiles.php:541 #: mod/profiles.php:544 mod/profiles.php:566 msgid "Yes" msgstr "" -#: include/items.php:398 include/conversation.php:1179 mod/videos.php:146 -#: mod/settings.php:676 mod/settings.php:702 mod/unfollow.php:120 +#: include/items.php:399 include/conversation.php:1179 mod/videos.php:146 +#: mod/settings.php:676 mod/settings.php:702 mod/unfollow.php:130 #: mod/message.php:157 mod/tagrm.php:19 mod/tagrm.php:91 mod/suggest.php:43 -#: mod/dfrn_request.php:655 mod/editpost.php:140 mod/contacts.php:468 +#: mod/dfrn_request.php:655 mod/editpost.php:146 mod/contacts.php:474 #: mod/follow.php:161 mod/fbrowser.php:104 mod/fbrowser.php:135 #: mod/photos.php:255 mod/photos.php:327 msgid "Cancel" msgstr "" -#: include/items.php:483 src/Content/Feature.php:96 +#: include/items.php:484 src/Content/Feature.php:96 msgid "Archives" msgstr "" @@ -558,35 +558,35 @@ msgstr "" msgid "%1$s marked %2$s's %3$s as favorite" msgstr "" -#: include/conversation.php:545 mod/profiles.php:352 mod/photos.php:1507 +#: include/conversation.php:545 mod/profiles.php:352 mod/photos.php:1509 msgid "Likes" msgstr "" -#: include/conversation.php:545 mod/profiles.php:356 mod/photos.php:1507 +#: include/conversation.php:545 mod/profiles.php:356 mod/photos.php:1509 msgid "Dislikes" msgstr "" #: include/conversation.php:546 include/conversation.php:1492 -#: mod/photos.php:1508 +#: mod/photos.php:1510 msgid "Attending" msgid_plural "Attending" msgstr[0] "" msgstr[1] "" -#: include/conversation.php:546 mod/photos.php:1508 +#: include/conversation.php:546 mod/photos.php:1510 msgid "Not attending" msgstr "" -#: include/conversation.php:546 mod/photos.php:1508 +#: include/conversation.php:546 mod/photos.php:1510 msgid "Might attend" msgstr "" -#: include/conversation.php:626 mod/photos.php:1564 src/Object/Post.php:195 +#: include/conversation.php:626 mod/photos.php:1566 src/Object/Post.php:195 msgid "Select" msgstr "" #: include/conversation.php:627 mod/settings.php:736 mod/admin.php:1906 -#: mod/contacts.php:852 mod/contacts.php:1130 mod/photos.php:1565 +#: mod/contacts.php:855 mod/contacts.php:1133 mod/photos.php:1567 msgid "Delete" msgstr "" @@ -614,7 +614,7 @@ msgstr "" #: include/conversation.php:698 include/conversation.php:1160 #: mod/wallmessage.php:145 mod/message.php:263 mod/message.php:431 -#: mod/editpost.php:115 mod/photos.php:1480 src/Object/Post.php:401 +#: mod/editpost.php:121 mod/photos.php:1482 src/Object/Post.php:401 msgid "Please wait" msgstr "" @@ -626,36 +626,36 @@ msgstr "" msgid "Delete Selected Items" msgstr "" -#: include/conversation.php:867 src/Model/Contact.php:937 +#: include/conversation.php:867 src/Model/Contact.php:948 msgid "View Status" msgstr "" #: include/conversation.php:868 include/conversation.php:884 #: mod/dirfind.php:230 mod/directory.php:164 mod/match.php:89 -#: mod/suggest.php:85 mod/allfriends.php:75 src/Model/Contact.php:877 -#: src/Model/Contact.php:930 src/Model/Contact.php:938 +#: mod/suggest.php:85 mod/allfriends.php:75 src/Model/Contact.php:888 +#: src/Model/Contact.php:941 src/Model/Contact.php:949 msgid "View Profile" msgstr "" -#: include/conversation.php:869 src/Model/Contact.php:939 +#: include/conversation.php:869 src/Model/Contact.php:950 msgid "View Photos" msgstr "" -#: include/conversation.php:870 src/Model/Contact.php:931 -#: src/Model/Contact.php:940 +#: include/conversation.php:870 src/Model/Contact.php:942 +#: src/Model/Contact.php:951 msgid "Network Posts" msgstr "" -#: include/conversation.php:871 src/Model/Contact.php:932 -#: src/Model/Contact.php:941 +#: include/conversation.php:871 src/Model/Contact.php:943 +#: src/Model/Contact.php:952 msgid "View Contact" msgstr "" -#: include/conversation.php:872 src/Model/Contact.php:943 +#: include/conversation.php:872 src/Model/Contact.php:954 msgid "Send PM" msgstr "" -#: include/conversation.php:876 src/Model/Contact.php:944 +#: include/conversation.php:876 src/Model/Contact.php:955 msgid "Poke" msgstr "" @@ -786,85 +786,85 @@ msgid "Share" msgstr "" #: include/conversation.php:1142 mod/wallmessage.php:143 mod/message.php:261 -#: mod/message.php:428 mod/editpost.php:101 +#: mod/message.php:428 mod/editpost.php:107 msgid "Upload photo" msgstr "" -#: include/conversation.php:1143 mod/editpost.php:102 +#: include/conversation.php:1143 mod/editpost.php:108 msgid "upload photo" msgstr "" -#: include/conversation.php:1144 mod/editpost.php:103 +#: include/conversation.php:1144 mod/editpost.php:109 msgid "Attach file" msgstr "" -#: include/conversation.php:1145 mod/editpost.php:104 +#: include/conversation.php:1145 mod/editpost.php:110 msgid "attach file" msgstr "" #: include/conversation.php:1146 mod/wallmessage.php:144 mod/message.php:262 -#: mod/message.php:429 mod/editpost.php:105 +#: mod/message.php:429 mod/editpost.php:111 msgid "Insert web link" msgstr "" -#: include/conversation.php:1147 mod/editpost.php:106 +#: include/conversation.php:1147 mod/editpost.php:112 msgid "web link" msgstr "" -#: include/conversation.php:1148 mod/editpost.php:107 +#: include/conversation.php:1148 mod/editpost.php:113 msgid "Insert video link" msgstr "" -#: include/conversation.php:1149 mod/editpost.php:108 +#: include/conversation.php:1149 mod/editpost.php:114 msgid "video link" msgstr "" -#: include/conversation.php:1150 mod/editpost.php:109 +#: include/conversation.php:1150 mod/editpost.php:115 msgid "Insert audio link" msgstr "" -#: include/conversation.php:1151 mod/editpost.php:110 +#: include/conversation.php:1151 mod/editpost.php:116 msgid "audio link" msgstr "" -#: include/conversation.php:1152 mod/editpost.php:111 +#: include/conversation.php:1152 mod/editpost.php:117 msgid "Set your location" msgstr "" -#: include/conversation.php:1153 mod/editpost.php:112 +#: include/conversation.php:1153 mod/editpost.php:118 msgid "set location" msgstr "" -#: include/conversation.php:1154 mod/editpost.php:113 +#: include/conversation.php:1154 mod/editpost.php:119 msgid "Clear browser location" msgstr "" -#: include/conversation.php:1155 mod/editpost.php:114 +#: include/conversation.php:1155 mod/editpost.php:120 msgid "clear location" msgstr "" -#: include/conversation.php:1157 mod/editpost.php:129 +#: include/conversation.php:1157 mod/editpost.php:135 msgid "Set title" msgstr "" -#: include/conversation.php:1159 mod/editpost.php:131 +#: include/conversation.php:1159 mod/editpost.php:137 msgid "Categories (comma-separated list)" msgstr "" -#: include/conversation.php:1161 mod/editpost.php:116 +#: include/conversation.php:1161 mod/editpost.php:122 msgid "Permission settings" msgstr "" -#: include/conversation.php:1162 mod/editpost.php:146 +#: include/conversation.php:1162 mod/editpost.php:152 msgid "permissions" msgstr "" -#: include/conversation.php:1171 mod/editpost.php:126 +#: include/conversation.php:1171 mod/editpost.php:132 msgid "Public post" msgstr "" -#: include/conversation.php:1175 mod/editpost.php:137 mod/events.php:531 -#: mod/photos.php:1498 mod/photos.php:1537 mod/photos.php:1597 +#: include/conversation.php:1175 mod/editpost.php:143 mod/events.php:558 +#: mod/photos.php:1500 mod/photos.php:1539 mod/photos.php:1599 #: src/Object/Post.php:804 msgid "Preview" msgstr "" @@ -881,11 +881,11 @@ msgstr "" msgid "Private post" msgstr "" -#: include/conversation.php:1191 mod/editpost.php:144 src/Model/Profile.php:344 +#: include/conversation.php:1191 mod/editpost.php:150 src/Model/Profile.php:357 msgid "Message" msgstr "" -#: include/conversation.php:1192 mod/editpost.php:145 +#: include/conversation.php:1192 mod/editpost.php:151 msgid "Browser" msgstr "" @@ -911,7 +911,7 @@ msgid_plural "Not Attending" msgstr[0] "" msgstr[1] "" -#: include/conversation.php:1498 src/Content/ContactSelector.php:122 +#: include/conversation.php:1498 src/Content/ContactSelector.php:127 msgid "Undecided" msgid_plural "Undecided" msgstr[0] "" @@ -1276,7 +1276,7 @@ msgstr[1] "" msgid "View Contacts" msgstr "" -#: include/text.php:889 mod/filer.php:35 mod/editpost.php:100 mod/notes.php:54 +#: include/text.php:889 mod/filer.php:35 mod/editpost.php:106 mod/notes.php:54 msgid "Save" msgstr "" @@ -1349,132 +1349,132 @@ msgstr "" msgid "rebuffed" msgstr "" -#: include/text.php:972 mod/settings.php:941 src/Model/Event.php:388 +#: include/text.php:972 mod/settings.php:941 src/Model/Event.php:389 msgid "Monday" msgstr "" -#: include/text.php:972 src/Model/Event.php:389 +#: include/text.php:972 src/Model/Event.php:390 msgid "Tuesday" msgstr "" -#: include/text.php:972 src/Model/Event.php:390 +#: include/text.php:972 src/Model/Event.php:391 msgid "Wednesday" msgstr "" -#: include/text.php:972 src/Model/Event.php:391 +#: include/text.php:972 src/Model/Event.php:392 msgid "Thursday" msgstr "" -#: include/text.php:972 src/Model/Event.php:392 +#: include/text.php:972 src/Model/Event.php:393 msgid "Friday" msgstr "" -#: include/text.php:972 src/Model/Event.php:393 +#: include/text.php:972 src/Model/Event.php:394 msgid "Saturday" msgstr "" -#: include/text.php:972 mod/settings.php:941 src/Model/Event.php:387 +#: include/text.php:972 mod/settings.php:941 src/Model/Event.php:388 msgid "Sunday" msgstr "" -#: include/text.php:976 src/Model/Event.php:408 +#: include/text.php:976 src/Model/Event.php:409 msgid "January" msgstr "" -#: include/text.php:976 src/Model/Event.php:409 +#: include/text.php:976 src/Model/Event.php:410 msgid "February" msgstr "" -#: include/text.php:976 src/Model/Event.php:410 +#: include/text.php:976 src/Model/Event.php:411 msgid "March" msgstr "" -#: include/text.php:976 src/Model/Event.php:411 +#: include/text.php:976 src/Model/Event.php:412 msgid "April" msgstr "" -#: include/text.php:976 include/text.php:993 src/Model/Event.php:399 -#: src/Model/Event.php:412 +#: include/text.php:976 include/text.php:993 src/Model/Event.php:400 +#: src/Model/Event.php:413 msgid "May" msgstr "" -#: include/text.php:976 src/Model/Event.php:413 +#: include/text.php:976 src/Model/Event.php:414 msgid "June" msgstr "" -#: include/text.php:976 src/Model/Event.php:414 +#: include/text.php:976 src/Model/Event.php:415 msgid "July" msgstr "" -#: include/text.php:976 src/Model/Event.php:415 +#: include/text.php:976 src/Model/Event.php:416 msgid "August" msgstr "" -#: include/text.php:976 src/Model/Event.php:416 +#: include/text.php:976 src/Model/Event.php:417 msgid "September" msgstr "" -#: include/text.php:976 src/Model/Event.php:417 +#: include/text.php:976 src/Model/Event.php:418 msgid "October" msgstr "" -#: include/text.php:976 src/Model/Event.php:418 +#: include/text.php:976 src/Model/Event.php:419 msgid "November" msgstr "" -#: include/text.php:976 src/Model/Event.php:419 +#: include/text.php:976 src/Model/Event.php:420 msgid "December" msgstr "" -#: include/text.php:990 src/Model/Event.php:380 +#: include/text.php:990 src/Model/Event.php:381 msgid "Mon" msgstr "" -#: include/text.php:990 src/Model/Event.php:381 +#: include/text.php:990 src/Model/Event.php:382 msgid "Tue" msgstr "" -#: include/text.php:990 src/Model/Event.php:382 +#: include/text.php:990 src/Model/Event.php:383 msgid "Wed" msgstr "" -#: include/text.php:990 src/Model/Event.php:383 +#: include/text.php:990 src/Model/Event.php:384 msgid "Thu" msgstr "" -#: include/text.php:990 src/Model/Event.php:384 +#: include/text.php:990 src/Model/Event.php:385 msgid "Fri" msgstr "" -#: include/text.php:990 src/Model/Event.php:385 +#: include/text.php:990 src/Model/Event.php:386 msgid "Sat" msgstr "" -#: include/text.php:990 src/Model/Event.php:379 +#: include/text.php:990 src/Model/Event.php:380 msgid "Sun" msgstr "" -#: include/text.php:993 src/Model/Event.php:395 +#: include/text.php:993 src/Model/Event.php:396 msgid "Jan" msgstr "" -#: include/text.php:993 src/Model/Event.php:396 +#: include/text.php:993 src/Model/Event.php:397 msgid "Feb" msgstr "" -#: include/text.php:993 src/Model/Event.php:397 +#: include/text.php:993 src/Model/Event.php:398 msgid "Mar" msgstr "" -#: include/text.php:993 src/Model/Event.php:398 +#: include/text.php:993 src/Model/Event.php:399 msgid "Apr" msgstr "" -#: include/text.php:993 src/Model/Event.php:401 +#: include/text.php:993 src/Model/Event.php:402 msgid "Jul" msgstr "" -#: include/text.php:993 src/Model/Event.php:402 +#: include/text.php:993 src/Model/Event.php:403 msgid "Aug" msgstr "" @@ -1482,15 +1482,15 @@ msgstr "" msgid "Sep" msgstr "" -#: include/text.php:993 src/Model/Event.php:404 +#: include/text.php:993 src/Model/Event.php:405 msgid "Oct" msgstr "" -#: include/text.php:993 src/Model/Event.php:405 +#: include/text.php:993 src/Model/Event.php:406 msgid "Nov" msgstr "" -#: include/text.php:993 src/Model/Event.php:406 +#: include/text.php:993 src/Model/Event.php:407 msgid "Dec" msgstr "" @@ -1499,7 +1499,7 @@ msgstr "" msgid "Content warning: %s" msgstr "" -#: include/text.php:1204 mod/videos.php:375 +#: include/text.php:1204 mod/videos.php:376 msgid "View Video" msgstr "" @@ -1519,7 +1519,7 @@ msgstr "" msgid "view on separate page" msgstr "" -#: include/text.php:1421 include/text.php:1428 src/Model/Event.php:609 +#: include/text.php:1421 include/text.php:1428 src/Model/Event.php:616 msgid "link to source" msgstr "" @@ -1541,30 +1541,30 @@ msgstr "" msgid "Item filed" msgstr "" -#: include/api.php:1138 +#: include/api.php:1140 #, php-format msgid "Daily posting limit of %d post reached. The post was rejected." msgid_plural "Daily posting limit of %d posts reached. The post was rejected." msgstr[0] "" msgstr[1] "" -#: include/api.php:1152 +#: include/api.php:1154 #, php-format msgid "Weekly posting limit of %d post reached. The post was rejected." msgid_plural "Weekly posting limit of %d posts reached. The post was rejected." msgstr[0] "" msgstr[1] "" -#: include/api.php:1166 +#: include/api.php:1168 #, php-format msgid "Monthly posting limit of %d post reached. The post was rejected." msgstr "" -#: include/api.php:4233 mod/profile_photo.php:84 mod/profile_photo.php:93 +#: include/api.php:4240 mod/profile_photo.php:84 mod/profile_photo.php:93 #: mod/profile_photo.php:102 mod/profile_photo.php:211 #: mod/profile_photo.php:300 mod/profile_photo.php:310 mod/photos.php:90 -#: mod/photos.php:198 mod/photos.php:735 mod/photos.php:1169 -#: mod/photos.php:1186 mod/photos.php:1678 src/Model/User.php:595 +#: mod/photos.php:198 mod/photos.php:735 mod/photos.php:1171 +#: mod/photos.php:1188 mod/photos.php:1680 src/Model/User.php:595 #: src/Model/User.php:603 src/Model/User.php:611 msgid "Profile Photos" msgstr "" @@ -1578,7 +1578,7 @@ msgid "Contact update failed." msgstr "" #: mod/crepair.php:112 mod/redir.php:29 mod/redir.php:127 -#: mod/dfrn_confirm.php:127 mod/fsuggest.php:30 mod/fsuggest.php:96 +#: mod/dfrn_confirm.php:128 mod/fsuggest.php:30 mod/fsuggest.php:96 msgid "Contact not found." msgstr "" @@ -1719,143 +1719,143 @@ msgstr "" msgid "Your message:" msgstr "" -#: mod/lockview.php:42 mod/lockview.php:50 +#: mod/lockview.php:46 mod/lockview.php:57 msgid "Remote privacy information not available." msgstr "" -#: mod/lockview.php:59 +#: mod/lockview.php:66 msgid "Visible to:" msgstr "" -#: mod/install.php:100 +#: mod/install.php:98 msgid "Friendica Communications Server - Setup" msgstr "" -#: mod/install.php:106 +#: mod/install.php:104 msgid "Could not connect to database." msgstr "" -#: mod/install.php:110 +#: mod/install.php:108 msgid "Could not create table." msgstr "" -#: mod/install.php:116 +#: mod/install.php:114 msgid "Your Friendica site database has been installed." msgstr "" -#: mod/install.php:121 +#: mod/install.php:119 msgid "" "You may need to import the file \"database.sql\" manually using phpmyadmin " "or mysql." msgstr "" -#: mod/install.php:122 mod/install.php:166 mod/install.php:274 +#: mod/install.php:120 mod/install.php:164 mod/install.php:272 msgid "Please see the file \"INSTALL.txt\"." msgstr "" -#: mod/install.php:134 +#: mod/install.php:132 msgid "Database already in use." msgstr "" -#: mod/install.php:163 +#: mod/install.php:161 msgid "System check" msgstr "" -#: mod/install.php:167 mod/cal.php:279 mod/events.php:394 +#: mod/install.php:165 mod/cal.php:279 mod/events.php:395 msgid "Next" msgstr "" -#: mod/install.php:168 +#: mod/install.php:166 msgid "Check again" msgstr "" -#: mod/install.php:187 +#: mod/install.php:185 msgid "Database connection" msgstr "" -#: mod/install.php:188 +#: mod/install.php:186 msgid "" "In order to install Friendica we need to know how to connect to your " "database." msgstr "" -#: mod/install.php:189 +#: mod/install.php:187 msgid "" "Please contact your hosting provider or site administrator if you have " "questions about these settings." msgstr "" -#: mod/install.php:190 +#: mod/install.php:188 msgid "" "The database you specify below should already exist. If it does not, please " "create it before continuing." msgstr "" -#: mod/install.php:194 +#: mod/install.php:192 msgid "Database Server Name" msgstr "" -#: mod/install.php:195 +#: mod/install.php:193 msgid "Database Login Name" msgstr "" -#: mod/install.php:196 +#: mod/install.php:194 msgid "Database Login Password" msgstr "" -#: mod/install.php:196 +#: mod/install.php:194 msgid "For security reasons the password must not be empty" msgstr "" -#: mod/install.php:197 +#: mod/install.php:195 msgid "Database Name" msgstr "" -#: mod/install.php:198 mod/install.php:235 +#: mod/install.php:196 mod/install.php:233 msgid "Site administrator email address" msgstr "" -#: mod/install.php:198 mod/install.php:235 +#: mod/install.php:196 mod/install.php:233 msgid "" "Your account email address must match this in order to use the web admin " "panel." msgstr "" -#: mod/install.php:200 mod/install.php:238 +#: mod/install.php:198 mod/install.php:236 msgid "Please select a default timezone for your website" msgstr "" -#: mod/install.php:225 +#: mod/install.php:223 msgid "Site settings" msgstr "" -#: mod/install.php:239 +#: mod/install.php:237 msgid "System Language:" msgstr "" -#: mod/install.php:239 +#: mod/install.php:237 msgid "" "Set the default language for your Friendica installation interface and to " "send emails." msgstr "" -#: mod/install.php:255 +#: mod/install.php:253 msgid "" "The database configuration file \"config/local.ini.php\" could not be " "written. Please use the enclosed text to create a configuration file in your " "web server root." msgstr "" -#: mod/install.php:272 +#: mod/install.php:270 msgid "

What next

" msgstr "" -#: mod/install.php:273 +#: mod/install.php:271 msgid "" "IMPORTANT: You will need to [manually] setup a scheduled task for the worker." msgstr "" -#: mod/install.php:276 +#: mod/install.php:274 #, php-format msgid "" "Go to your new Friendica node registration page " @@ -1863,82 +1863,82 @@ msgid "" "administrator email. This will allow you to enter the site admin panel." msgstr "" -#: mod/dfrn_confirm.php:72 mod/profiles.php:38 mod/profiles.php:148 +#: mod/dfrn_confirm.php:73 mod/profiles.php:38 mod/profiles.php:148 #: mod/profiles.php:193 mod/profiles.php:523 msgid "Profile not found." msgstr "" -#: mod/dfrn_confirm.php:128 +#: mod/dfrn_confirm.php:129 msgid "" "This may occasionally happen if contact was requested by both persons and it " "has already been approved." msgstr "" -#: mod/dfrn_confirm.php:238 +#: mod/dfrn_confirm.php:239 msgid "Response from remote site was not understood." msgstr "" -#: mod/dfrn_confirm.php:245 mod/dfrn_confirm.php:251 +#: mod/dfrn_confirm.php:246 mod/dfrn_confirm.php:252 msgid "Unexpected response from remote site: " msgstr "" -#: mod/dfrn_confirm.php:260 +#: mod/dfrn_confirm.php:261 msgid "Confirmation completed successfully." msgstr "" -#: mod/dfrn_confirm.php:272 +#: mod/dfrn_confirm.php:273 msgid "Temporary failure. Please wait and try again." msgstr "" -#: mod/dfrn_confirm.php:275 +#: mod/dfrn_confirm.php:276 msgid "Introduction failed or was revoked." msgstr "" -#: mod/dfrn_confirm.php:280 +#: mod/dfrn_confirm.php:281 msgid "Remote site reported: " msgstr "" -#: mod/dfrn_confirm.php:392 +#: mod/dfrn_confirm.php:382 msgid "Unable to set contact photo." msgstr "" -#: mod/dfrn_confirm.php:450 +#: mod/dfrn_confirm.php:444 #, php-format msgid "No user record found for '%s' " msgstr "" -#: mod/dfrn_confirm.php:460 +#: mod/dfrn_confirm.php:454 msgid "Our site encryption key is apparently messed up." msgstr "" -#: mod/dfrn_confirm.php:471 +#: mod/dfrn_confirm.php:465 msgid "Empty site URL was provided or URL could not be decrypted by us." msgstr "" -#: mod/dfrn_confirm.php:487 +#: mod/dfrn_confirm.php:481 msgid "Contact record was not found for you on our site." msgstr "" -#: mod/dfrn_confirm.php:501 +#: mod/dfrn_confirm.php:495 #, php-format msgid "Site public key not available in contact record for URL %s." msgstr "" -#: mod/dfrn_confirm.php:517 +#: mod/dfrn_confirm.php:511 msgid "" "The ID provided by your system is a duplicate on our system. It should work " "if you try again." msgstr "" -#: mod/dfrn_confirm.php:528 +#: mod/dfrn_confirm.php:522 msgid "Unable to set your contact credentials on our system." msgstr "" -#: mod/dfrn_confirm.php:584 +#: mod/dfrn_confirm.php:578 msgid "Unable to update your contact profile details on our system" msgstr "" -#: mod/dfrn_confirm.php:614 mod/dfrn_request.php:561 src/Model/Contact.php:1891 +#: mod/dfrn_confirm.php:608 mod/dfrn_request.php:561 src/Model/Contact.php:1909 msgid "[Name Withheld]" msgstr "" @@ -1953,7 +1953,7 @@ msgid "Forum Search - %s" msgstr "" #: mod/dirfind.php:221 mod/match.php:105 mod/suggest.php:104 -#: mod/allfriends.php:92 src/Model/Profile.php:292 src/Content/Widget.php:37 +#: mod/allfriends.php:92 src/Model/Profile.php:305 src/Content/Widget.php:37 msgid "Connect" msgstr "" @@ -1985,8 +1985,8 @@ msgstr "" #: mod/videos.php:198 mod/webfinger.php:16 mod/directory.php:42 #: mod/search.php:105 mod/search.php:111 mod/viewcontacts.php:48 -#: mod/display.php:194 mod/dfrn_request.php:599 mod/probe.php:13 -#: mod/community.php:28 mod/photos.php:945 +#: mod/display.php:203 mod/dfrn_request.php:599 mod/probe.php:13 +#: mod/community.php:28 mod/photos.php:947 msgid "Public access denied." msgstr "" @@ -1994,19 +1994,19 @@ msgstr "" msgid "No videos selected" msgstr "" -#: mod/videos.php:307 mod/photos.php:1050 +#: mod/videos.php:307 mod/photos.php:1052 msgid "Access to this item is restricted." msgstr "" -#: mod/videos.php:382 mod/photos.php:1699 +#: mod/videos.php:383 mod/photos.php:1701 msgid "View Album" msgstr "" -#: mod/videos.php:390 +#: mod/videos.php:391 msgid "Recent Videos" msgstr "" -#: mod/videos.php:392 +#: mod/videos.php:393 msgid "Upload New Videos" msgstr "" @@ -2014,27 +2014,27 @@ msgstr "" msgid "Only logged in users are permitted to perform a probing." msgstr "" -#: mod/directory.php:151 mod/notifications.php:253 mod/contacts.php:680 -#: mod/events.php:521 src/Model/Event.php:66 src/Model/Event.php:93 -#: src/Model/Event.php:430 src/Model/Event.php:915 src/Model/Profile.php:417 +#: mod/directory.php:151 mod/notifications.php:248 mod/contacts.php:681 +#: mod/events.php:548 src/Model/Event.php:67 src/Model/Event.php:94 +#: src/Model/Event.php:431 src/Model/Event.php:922 src/Model/Profile.php:430 msgid "Location:" msgstr "" -#: mod/directory.php:156 mod/notifications.php:259 src/Model/Profile.php:420 -#: src/Model/Profile.php:732 +#: mod/directory.php:156 mod/notifications.php:254 src/Model/Profile.php:433 +#: src/Model/Profile.php:745 msgid "Gender:" msgstr "" -#: mod/directory.php:157 src/Model/Profile.php:421 src/Model/Profile.php:756 +#: mod/directory.php:157 src/Model/Profile.php:434 src/Model/Profile.php:769 msgid "Status:" msgstr "" -#: mod/directory.php:158 src/Model/Profile.php:422 src/Model/Profile.php:773 +#: mod/directory.php:158 src/Model/Profile.php:435 src/Model/Profile.php:786 msgid "Homepage:" msgstr "" -#: mod/directory.php:159 mod/notifications.php:255 mod/contacts.php:684 -#: src/Model/Profile.php:423 src/Model/Profile.php:793 +#: mod/directory.php:159 mod/notifications.php:250 mod/contacts.php:685 +#: src/Model/Profile.php:436 src/Model/Profile.php:806 msgid "About:" msgstr "" @@ -2074,7 +2074,7 @@ msgstr "" msgid "Account" msgstr "" -#: mod/settings.php:64 src/Model/Profile.php:372 src/Content/Nav.php:210 +#: mod/settings.php:64 src/Model/Profile.php:385 src/Content/Nav.php:210 msgid "Profiles" msgstr "" @@ -2114,7 +2114,7 @@ msgstr "" msgid "Missing some important data!" msgstr "" -#: mod/settings.php:176 mod/settings.php:701 mod/contacts.php:848 +#: mod/settings.php:176 mod/settings.php:701 mod/contacts.php:851 msgid "Update" msgstr "" @@ -2803,7 +2803,7 @@ msgstr "" msgid "Basic Settings" msgstr "" -#: mod/settings.php:1204 src/Model/Profile.php:725 +#: mod/settings.php:1204 src/Model/Profile.php:738 msgid "Full Name:" msgstr "" @@ -2853,11 +2853,11 @@ msgstr "" msgid "(click to open/close)" msgstr "" -#: mod/settings.php:1224 mod/photos.php:1126 mod/photos.php:1456 +#: mod/settings.php:1224 mod/photos.php:1128 mod/photos.php:1458 msgid "Show to Groups" msgstr "" -#: mod/settings.php:1225 mod/photos.php:1127 mod/photos.php:1457 +#: mod/settings.php:1225 mod/photos.php:1129 mod/photos.php:1459 msgid "Show to Contacts" msgstr "" @@ -3006,7 +3006,7 @@ msgstr "" msgid "Items tagged with: %s" msgstr "" -#: mod/search.php:248 mod/contacts.php:841 +#: mod/search.php:248 mod/contacts.php:844 #, php-format msgid "Results for: %s" msgstr "" @@ -3015,7 +3015,7 @@ msgstr "" msgid "No contacts in common." msgstr "" -#: mod/common.php:142 mod/contacts.php:916 +#: mod/common.php:142 mod/contacts.php:919 msgid "Common Friends" msgstr "" @@ -3023,7 +3023,11 @@ msgstr "" msgid "Login" msgstr "" -#: mod/bookmarklet.php:52 +#: mod/bookmarklet.php:34 +msgid "Bad Request" +msgstr "" + +#: mod/bookmarklet.php:56 msgid "The post was created" msgstr "" @@ -3173,7 +3177,7 @@ msgstr "" msgid "Members" msgstr "" -#: mod/group.php:246 mod/contacts.php:739 +#: mod/group.php:246 mod/contacts.php:742 msgid "All Contacts" msgstr "" @@ -3297,46 +3301,42 @@ msgstr "" msgid "No contacts." msgstr "" -#: mod/viewcontacts.php:106 mod/contacts.php:639 mod/contacts.php:1052 +#: mod/viewcontacts.php:106 mod/contacts.php:640 mod/contacts.php:1055 #, php-format msgid "Visit %s's profile [%s]" msgstr "" -#: mod/unfollow.php:36 -msgid "Contact wasn't found or can't be unfollowed." +#: mod/unfollow.php:38 mod/unfollow.php:88 +msgid "You aren't following this contact." msgstr "" -#: mod/unfollow.php:49 -msgid "Contact unfollowed" -msgstr "" - -#: mod/unfollow.php:67 mod/dfrn_request.php:654 mod/follow.php:62 -msgid "Submit Request" -msgstr "" - -#: mod/unfollow.php:76 -msgid "You aren't a friend of this contact." -msgstr "" - -#: mod/unfollow.php:82 +#: mod/unfollow.php:44 mod/unfollow.php:94 msgid "Unfollowing is currently not supported by your network." msgstr "" -#: mod/unfollow.php:103 mod/contacts.php:601 +#: mod/unfollow.php:65 +msgid "Contact unfollowed" +msgstr "" + +#: mod/unfollow.php:113 mod/contacts.php:607 msgid "Disconnect/Unfollow" msgstr "" -#: mod/unfollow.php:116 mod/dfrn_request.php:652 mod/follow.php:157 +#: mod/unfollow.php:126 mod/dfrn_request.php:652 mod/follow.php:157 msgid "Your Identity Address:" msgstr "" -#: mod/unfollow.php:125 mod/notifications.php:174 mod/notifications.php:263 -#: mod/admin.php:500 mod/admin.php:510 mod/contacts.php:676 mod/follow.php:166 +#: mod/unfollow.php:129 mod/dfrn_request.php:654 mod/follow.php:62 +msgid "Submit Request" +msgstr "" + +#: mod/unfollow.php:135 mod/notifications.php:174 mod/notifications.php:258 +#: mod/admin.php:500 mod/admin.php:510 mod/contacts.php:677 mod/follow.php:166 msgid "Profile URL" msgstr "" -#: mod/unfollow.php:135 mod/contacts.php:888 mod/follow.php:189 -#: src/Model/Profile.php:878 +#: mod/unfollow.php:145 mod/contacts.php:891 mod/follow.php:189 +#: src/Model/Profile.php:891 msgid "Status Messages and Posts" msgstr "" @@ -3370,7 +3370,7 @@ msgstr "" msgid "Your registration is pending approval by the site owner." msgstr "" -#: mod/register.php:191 mod/uimport.php:55 +#: mod/register.php:191 mod/uimport.php:37 msgid "" "This site has exceeded the number of allowed daily account registrations. " "Please try again tomorrow." @@ -3445,7 +3445,7 @@ msgstr "" msgid "Register" msgstr "" -#: mod/register.php:287 mod/uimport.php:70 +#: mod/register.php:287 mod/uimport.php:52 msgid "Import" msgstr "" @@ -3466,36 +3466,44 @@ msgstr "" msgid "Invalid request identifier." msgstr "" -#: mod/notifications.php:44 mod/notifications.php:183 mod/notifications.php:235 +#: mod/notifications.php:44 mod/notifications.php:182 mod/notifications.php:230 #: mod/message.php:114 msgid "Discard" msgstr "" -#: mod/notifications.php:57 mod/notifications.php:182 mod/notifications.php:271 -#: mod/contacts.php:658 mod/contacts.php:850 mod/contacts.php:1113 +#: mod/notifications.php:57 mod/notifications.php:181 mod/notifications.php:266 +#: mod/contacts.php:659 mod/contacts.php:853 mod/contacts.php:1116 msgid "Ignore" msgstr "" -#: mod/notifications.php:93 src/Content/Nav.php:191 +#: mod/notifications.php:90 src/Content/Nav.php:191 msgid "Notifications" msgstr "" -#: mod/notifications.php:101 +#: mod/notifications.php:102 msgid "Network Notifications" msgstr "" -#: mod/notifications.php:106 mod/notify.php:81 +#: mod/notifications.php:107 mod/notify.php:81 msgid "System Notifications" msgstr "" -#: mod/notifications.php:111 +#: mod/notifications.php:112 msgid "Personal Notifications" msgstr "" -#: mod/notifications.php:116 +#: mod/notifications.php:117 msgid "Home Notifications" msgstr "" +#: mod/notifications.php:137 +msgid "Show unread" +msgstr "" + +#: mod/notifications.php:137 +msgid "Show all" +msgstr "" + #: mod/notifications.php:148 msgid "Show Ignored Requests" msgstr "" @@ -3504,7 +3512,7 @@ msgstr "" msgid "Hide Ignored Requests" msgstr "" -#: mod/notifications.php:161 mod/notifications.php:243 +#: mod/notifications.php:161 mod/notifications.php:238 msgid "Notification type:" msgstr "" @@ -3512,85 +3520,77 @@ msgstr "" msgid "Suggested by:" msgstr "" -#: mod/notifications.php:176 mod/notifications.php:260 mod/contacts.php:666 +#: mod/notifications.php:176 mod/notifications.php:255 mod/contacts.php:667 msgid "Hide this contact from others" msgstr "" -#: mod/notifications.php:179 mod/notifications.php:269 mod/admin.php:1904 +#: mod/notifications.php:178 mod/notifications.php:264 mod/admin.php:1904 msgid "Approve" msgstr "" -#: mod/notifications.php:202 +#: mod/notifications.php:198 msgid "Claims to be known to you: " msgstr "" -#: mod/notifications.php:203 +#: mod/notifications.php:199 msgid "yes" msgstr "" -#: mod/notifications.php:203 +#: mod/notifications.php:199 msgid "no" msgstr "" -#: mod/notifications.php:204 mod/notifications.php:209 +#: mod/notifications.php:200 mod/notifications.php:204 msgid "Shall your connection be bidirectional or not?" msgstr "" -#: mod/notifications.php:205 mod/notifications.php:210 +#: mod/notifications.php:201 mod/notifications.php:205 #, php-format msgid "" "Accepting %s as a friend allows %s to subscribe to your posts, and you will " "also receive updates from them in your news feed." msgstr "" -#: mod/notifications.php:206 +#: mod/notifications.php:202 #, php-format msgid "" "Accepting %s as a subscriber allows them to subscribe to your posts, but you " "will not receive updates from them in your news feed." msgstr "" -#: mod/notifications.php:211 +#: mod/notifications.php:206 #, php-format msgid "" "Accepting %s as a sharer allows them to subscribe to your posts, but you " "will not receive updates from them in your news feed." msgstr "" -#: mod/notifications.php:222 +#: mod/notifications.php:217 msgid "Friend" msgstr "" -#: mod/notifications.php:223 +#: mod/notifications.php:218 msgid "Sharer" msgstr "" -#: mod/notifications.php:223 +#: mod/notifications.php:218 msgid "Subscriber" msgstr "" -#: mod/notifications.php:257 mod/contacts.php:686 mod/follow.php:177 -#: src/Model/Profile.php:781 +#: mod/notifications.php:252 mod/contacts.php:687 mod/follow.php:177 +#: src/Model/Profile.php:794 msgid "Tags:" msgstr "" -#: mod/notifications.php:266 mod/contacts.php:76 src/Model/Profile.php:520 +#: mod/notifications.php:261 mod/contacts.php:81 src/Model/Profile.php:533 msgid "Network:" msgstr "" -#: mod/notifications.php:280 +#: mod/notifications.php:274 msgid "No introductions." msgstr "" -#: mod/notifications.php:318 -msgid "Show unread" -msgstr "" - -#: mod/notifications.php:318 -msgid "Show all" -msgstr "" - -#: mod/notifications.php:323 +#: mod/notifications.php:308 #, php-format msgid "No more %s notifications." msgstr "" @@ -3812,7 +3812,7 @@ msgid "On this server the following remote servers are blocked." msgstr "" #: mod/friendica.php:130 mod/admin.php:363 mod/admin.php:381 -#: mod/dfrn_request.php:345 src/Model/Contact.php:1582 +#: mod/dfrn_request.php:345 src/Model/Contact.php:1593 msgid "Blocked domain" msgstr "" @@ -3820,7 +3820,7 @@ msgstr "" msgid "Reason for the block" msgstr "" -#: mod/display.php:303 mod/cal.php:144 mod/profile.php:175 +#: mod/display.php:312 mod/cal.php:144 mod/profile.php:185 msgid "Access to this profile has been restricted." msgstr "" @@ -3830,13 +3830,13 @@ msgstr "" msgid "Invalid request." msgstr "" -#: mod/wall_upload.php:195 mod/profile_photo.php:151 mod/photos.php:776 -#: mod/photos.php:779 mod/photos.php:808 +#: mod/wall_upload.php:195 mod/profile_photo.php:151 mod/photos.php:778 +#: mod/photos.php:781 mod/photos.php:810 #, php-format msgid "Image exceeds size limit of %s" msgstr "" -#: mod/wall_upload.php:209 mod/profile_photo.php:160 mod/photos.php:831 +#: mod/wall_upload.php:209 mod/profile_photo.php:160 mod/photos.php:833 msgid "Unable to process image." msgstr "" @@ -3845,7 +3845,7 @@ msgstr "" msgid "Wall Photos" msgstr "" -#: mod/wall_upload.php:248 mod/profile_photo.php:305 mod/photos.php:860 +#: mod/wall_upload.php:248 mod/profile_photo.php:305 mod/photos.php:862 msgid "Image upload failed." msgstr "" @@ -4156,79 +4156,91 @@ msgstr "" msgid "Your password has been changed at %s" msgstr "" -#: mod/babel.php:22 +#: mod/babel.php:24 msgid "Source input" msgstr "" -#: mod/babel.php:28 +#: mod/babel.php:30 msgid "BBCode::toPlaintext" msgstr "" -#: mod/babel.php:34 +#: mod/babel.php:36 msgid "BBCode::convert (raw HTML)" msgstr "" -#: mod/babel.php:39 +#: mod/babel.php:41 msgid "BBCode::convert" msgstr "" -#: mod/babel.php:45 +#: mod/babel.php:47 msgid "BBCode::convert => HTML::toBBCode" msgstr "" -#: mod/babel.php:51 +#: mod/babel.php:53 msgid "BBCode::toMarkdown" msgstr "" -#: mod/babel.php:57 +#: mod/babel.php:59 msgid "BBCode::toMarkdown => Markdown::convert" msgstr "" -#: mod/babel.php:63 +#: mod/babel.php:65 msgid "BBCode::toMarkdown => Markdown::toBBCode" msgstr "" -#: mod/babel.php:69 +#: mod/babel.php:71 msgid "BBCode::toMarkdown => Markdown::convert => HTML::toBBCode" msgstr "" -#: mod/babel.php:76 -msgid "Source input \\x28Diaspora format\\x29" +#: mod/babel.php:78 +msgid "Source input (Diaspora format)" msgstr "" -#: mod/babel.php:82 -msgid "Markdown::toBBCode" +#: mod/babel.php:84 +msgid "Markdown::convert (raw HTML)" msgstr "" #: mod/babel.php:89 +msgid "Markdown::convert" +msgstr "" + +#: mod/babel.php:95 +msgid "Markdown::toBBCode" +msgstr "" + +#: mod/babel.php:102 msgid "Raw HTML input" msgstr "" -#: mod/babel.php:94 +#: mod/babel.php:107 msgid "HTML Input" msgstr "" -#: mod/babel.php:100 +#: mod/babel.php:113 msgid "HTML::toBBCode" msgstr "" -#: mod/babel.php:106 +#: mod/babel.php:119 +msgid "HTML::toMarkdown" +msgstr "" + +#: mod/babel.php:125 msgid "HTML::toPlaintext" msgstr "" -#: mod/babel.php:114 +#: mod/babel.php:133 msgid "Source text" msgstr "" -#: mod/babel.php:115 +#: mod/babel.php:134 msgid "BBCode" msgstr "" -#: mod/babel.php:116 +#: mod/babel.php:135 msgid "Markdown" msgstr "" -#: mod/babel.php:117 +#: mod/babel.php:136 msgid "HTML" msgstr "" @@ -4488,13 +4500,13 @@ msgstr "" msgid "select none" msgstr "" -#: mod/admin.php:494 mod/admin.php:1907 mod/contacts.php:657 -#: mod/contacts.php:849 mod/contacts.php:1105 +#: mod/admin.php:494 mod/admin.php:1907 mod/contacts.php:658 +#: mod/contacts.php:852 mod/contacts.php:1108 msgid "Block" msgstr "" -#: mod/admin.php:495 mod/admin.php:1909 mod/contacts.php:657 -#: mod/contacts.php:849 mod/contacts.php:1105 +#: mod/admin.php:495 mod/admin.php:1909 mod/contacts.php:658 +#: mod/contacts.php:852 mod/contacts.php:1108 msgid "Unblock" msgstr "" @@ -4675,9 +4687,9 @@ msgstr "" #: mod/admin.php:876 #, php-format msgid "" -"%s is not reachable on your system. This is a servere " -"configuration issue that prevents the communication.. See the " -"installation page for help." +"%s is not reachable on your system. This is a severe " +"configuration issue that prevents server to server communication. See the installation page for help." msgstr "" #: mod/admin.php:882 @@ -4757,7 +4769,7 @@ msgid "Public postings from local users and the federated network" msgstr "" #: mod/admin.php:1353 mod/admin.php:1520 mod/admin.php:1530 -#: mod/contacts.php:577 +#: mod/contacts.php:583 msgid "Disabled" msgstr "" @@ -4837,8 +4849,8 @@ msgstr "" msgid "Policies" msgstr "" -#: mod/admin.php:1431 mod/contacts.php:926 mod/events.php:535 -#: src/Model/Profile.php:852 +#: mod/admin.php:1431 mod/contacts.php:929 mod/events.php:562 +#: src/Model/Profile.php:865 msgid "Advanced" msgstr "" @@ -5241,14 +5253,14 @@ msgid "" msgstr "" #: mod/admin.php:1481 -msgid "Only import OStatus threads from our contacts" +msgid "Only import OStatus/ActivityPub threads from our contacts" msgstr "" #: mod/admin.php:1481 msgid "" -"Normally we import every content from our OStatus contacts. With this option " -"we only store threads that are started by a contact that is known on our " -"system." +"Normally we import every content from our OStatus and ActivityPub contacts. " +"With this option we only store threads that are started by a contact that is " +"known on our system." msgstr "" #: mod/admin.php:1482 @@ -6127,11 +6139,11 @@ msgstr "" msgid "Invalid profile URL." msgstr "" -#: mod/dfrn_request.php:339 src/Model/Contact.php:1577 +#: mod/dfrn_request.php:339 src/Model/Contact.php:1588 msgid "Disallowed profile URL." msgstr "" -#: mod/dfrn_request.php:412 mod/contacts.php:235 +#: mod/dfrn_request.php:412 mod/contacts.php:241 msgid "Failed to update contact record." msgstr "" @@ -6357,32 +6369,36 @@ msgstr "" msgid "Help:" msgstr "" -#: mod/uimport.php:72 +#: mod/uimport.php:28 +msgid "User imports on closed servers can only be done by an administrator." +msgstr "" + +#: mod/uimport.php:54 msgid "Move account" msgstr "" -#: mod/uimport.php:73 +#: mod/uimport.php:55 msgid "You can import an account from another Friendica server." msgstr "" -#: mod/uimport.php:74 +#: mod/uimport.php:56 msgid "" "You need to export your account from the old server and upload it here. We " "will recreate your old account here with all your contacts. We will try also " "to inform your friends that you moved here." msgstr "" -#: mod/uimport.php:75 +#: mod/uimport.php:57 msgid "" "This feature is experimental. We can't import contacts from the OStatus " "network (GNU Social/Statusnet) or from Diaspora" msgstr "" -#: mod/uimport.php:76 +#: mod/uimport.php:58 msgid "Account file" msgstr "" -#: mod/uimport.php:76 +#: mod/uimport.php:58 msgid "" "To export your account, go to \"Settings->Export your personal data\" and " "select \"Export account\"" @@ -6404,34 +6420,34 @@ msgstr "" msgid "All Contacts (with secure profile access)" msgstr "" -#: mod/cal.php:277 mod/events.php:391 +#: mod/cal.php:277 mod/events.php:392 msgid "View" msgstr "" -#: mod/cal.php:278 mod/events.php:393 +#: mod/cal.php:278 mod/events.php:394 msgid "Previous" msgstr "" -#: mod/cal.php:282 mod/events.php:399 src/Model/Event.php:421 +#: mod/cal.php:282 mod/events.php:400 src/Model/Event.php:422 msgid "today" msgstr "" -#: mod/cal.php:283 mod/events.php:400 src/Util/Temporal.php:304 -#: src/Model/Event.php:422 +#: mod/cal.php:283 mod/events.php:401 src/Util/Temporal.php:304 +#: src/Model/Event.php:423 msgid "month" msgstr "" -#: mod/cal.php:284 mod/events.php:401 src/Util/Temporal.php:305 -#: src/Model/Event.php:423 +#: mod/cal.php:284 mod/events.php:402 src/Util/Temporal.php:305 +#: src/Model/Event.php:424 msgid "week" msgstr "" -#: mod/cal.php:285 mod/events.php:402 src/Util/Temporal.php:306 -#: src/Model/Event.php:424 +#: mod/cal.php:285 mod/events.php:403 src/Util/Temporal.php:306 +#: src/Model/Event.php:425 msgid "day" msgstr "" -#: mod/cal.php:286 mod/events.php:403 +#: mod/cal.php:286 mod/events.php:404 msgid "list" msgstr "" @@ -6464,19 +6480,19 @@ msgstr "" msgid "Please login." msgstr "" -#: mod/editpost.php:26 mod/editpost.php:36 +#: mod/editpost.php:27 mod/editpost.php:42 msgid "Item not found" msgstr "" -#: mod/editpost.php:43 +#: mod/editpost.php:49 msgid "Edit post" msgstr "" -#: mod/editpost.php:125 src/Core/ACL.php:304 +#: mod/editpost.php:131 src/Core/ACL.php:304 msgid "CC: email addresses" msgstr "" -#: mod/editpost.php:132 src/Core/ACL.php:305 +#: mod/editpost.php:138 src/Core/ACL.php:305 msgid "Example: bob@example.com, mary@example.com" msgstr "" @@ -6513,21 +6529,21 @@ msgstr "" msgid "System down for maintenance" msgstr "" -#: mod/profile.php:38 src/Model/Profile.php:115 +#: mod/profile.php:39 src/Model/Profile.php:128 msgid "Requested profile is not available." msgstr "" -#: mod/profile.php:79 mod/profile.php:82 src/Protocol/OStatus.php:1275 +#: mod/profile.php:89 mod/profile.php:92 src/Protocol/OStatus.php:1285 #, php-format msgid "%s's timeline" msgstr "" -#: mod/profile.php:80 src/Protocol/OStatus.php:1276 +#: mod/profile.php:90 src/Protocol/OStatus.php:1286 #, php-format msgid "%s's posts" msgstr "" -#: mod/profile.php:81 src/Protocol/OStatus.php:1277 +#: mod/profile.php:91 src/Protocol/OStatus.php:1287 #, php-format msgid "%s's comments" msgstr "" @@ -6536,433 +6552,433 @@ msgstr "" msgid "No friends to display." msgstr "" -#: mod/contacts.php:162 +#: mod/contacts.php:168 #, php-format msgid "%d contact edited." msgid_plural "%d contacts edited." msgstr[0] "" msgstr[1] "" -#: mod/contacts.php:189 mod/contacts.php:395 +#: mod/contacts.php:195 mod/contacts.php:401 msgid "Could not access contact record." msgstr "" -#: mod/contacts.php:199 +#: mod/contacts.php:205 msgid "Could not locate selected profile." msgstr "" -#: mod/contacts.php:233 +#: mod/contacts.php:239 msgid "Contact updated." msgstr "" -#: mod/contacts.php:416 +#: mod/contacts.php:422 msgid "Contact has been blocked" msgstr "" -#: mod/contacts.php:416 +#: mod/contacts.php:422 msgid "Contact has been unblocked" msgstr "" -#: mod/contacts.php:426 +#: mod/contacts.php:432 msgid "Contact has been ignored" msgstr "" -#: mod/contacts.php:426 +#: mod/contacts.php:432 msgid "Contact has been unignored" msgstr "" -#: mod/contacts.php:436 +#: mod/contacts.php:442 msgid "Contact has been archived" msgstr "" -#: mod/contacts.php:436 +#: mod/contacts.php:442 msgid "Contact has been unarchived" msgstr "" -#: mod/contacts.php:460 +#: mod/contacts.php:466 msgid "Drop contact" msgstr "" -#: mod/contacts.php:463 mod/contacts.php:845 +#: mod/contacts.php:469 mod/contacts.php:848 msgid "Do you really want to delete this contact?" msgstr "" -#: mod/contacts.php:481 +#: mod/contacts.php:487 msgid "Contact has been removed." msgstr "" -#: mod/contacts.php:518 +#: mod/contacts.php:524 #, php-format msgid "You are mutual friends with %s" msgstr "" -#: mod/contacts.php:523 +#: mod/contacts.php:529 #, php-format msgid "You are sharing with %s" msgstr "" -#: mod/contacts.php:528 +#: mod/contacts.php:534 #, php-format msgid "%s is sharing with you" msgstr "" -#: mod/contacts.php:552 +#: mod/contacts.php:558 msgid "Private communications are not available for this contact." msgstr "" -#: mod/contacts.php:554 +#: mod/contacts.php:560 msgid "Never" msgstr "" -#: mod/contacts.php:557 +#: mod/contacts.php:563 msgid "(Update was successful)" msgstr "" -#: mod/contacts.php:557 +#: mod/contacts.php:563 msgid "(Update was not successful)" msgstr "" -#: mod/contacts.php:559 mod/contacts.php:1086 +#: mod/contacts.php:565 mod/contacts.php:1089 msgid "Suggest friends" msgstr "" -#: mod/contacts.php:563 +#: mod/contacts.php:569 #, php-format msgid "Network type: %s" msgstr "" -#: mod/contacts.php:568 +#: mod/contacts.php:574 msgid "Communications lost with this contact!" msgstr "" -#: mod/contacts.php:574 +#: mod/contacts.php:580 msgid "Fetch further information for feeds" msgstr "" -#: mod/contacts.php:576 +#: mod/contacts.php:582 msgid "" "Fetch information like preview pictures, title and teaser from the feed " "item. You can activate this if the feed doesn't contain much text. Keywords " "are taken from the meta header in the feed item and are posted as hash tags." msgstr "" -#: mod/contacts.php:578 +#: mod/contacts.php:584 msgid "Fetch information" msgstr "" -#: mod/contacts.php:579 +#: mod/contacts.php:585 msgid "Fetch keywords" msgstr "" -#: mod/contacts.php:580 +#: mod/contacts.php:586 msgid "Fetch information and keywords" msgstr "" -#: mod/contacts.php:617 +#: mod/contacts.php:618 msgid "Profile Visibility" msgstr "" -#: mod/contacts.php:618 +#: mod/contacts.php:619 msgid "Contact Information / Notes" msgstr "" -#: mod/contacts.php:619 +#: mod/contacts.php:620 msgid "Contact Settings" msgstr "" -#: mod/contacts.php:628 +#: mod/contacts.php:629 msgid "Contact" msgstr "" -#: mod/contacts.php:632 +#: mod/contacts.php:633 #, php-format msgid "" "Please choose the profile you would like to display to %s when viewing your " "profile securely." msgstr "" -#: mod/contacts.php:634 +#: mod/contacts.php:635 msgid "Their personal note" msgstr "" -#: mod/contacts.php:636 +#: mod/contacts.php:637 msgid "Edit contact notes" msgstr "" -#: mod/contacts.php:640 +#: mod/contacts.php:641 msgid "Block/Unblock contact" msgstr "" -#: mod/contacts.php:641 +#: mod/contacts.php:642 msgid "Ignore contact" msgstr "" -#: mod/contacts.php:642 +#: mod/contacts.php:643 msgid "Repair URL settings" msgstr "" -#: mod/contacts.php:643 +#: mod/contacts.php:644 msgid "View conversations" msgstr "" -#: mod/contacts.php:648 +#: mod/contacts.php:649 msgid "Last update:" msgstr "" -#: mod/contacts.php:650 +#: mod/contacts.php:651 msgid "Update public posts" msgstr "" -#: mod/contacts.php:652 mod/contacts.php:1096 +#: mod/contacts.php:653 mod/contacts.php:1099 msgid "Update now" msgstr "" -#: mod/contacts.php:658 mod/contacts.php:850 mod/contacts.php:1113 +#: mod/contacts.php:659 mod/contacts.php:853 mod/contacts.php:1116 msgid "Unignore" msgstr "" -#: mod/contacts.php:662 +#: mod/contacts.php:663 msgid "Currently blocked" msgstr "" -#: mod/contacts.php:663 +#: mod/contacts.php:664 msgid "Currently ignored" msgstr "" -#: mod/contacts.php:664 +#: mod/contacts.php:665 msgid "Currently archived" msgstr "" -#: mod/contacts.php:665 +#: mod/contacts.php:666 msgid "Awaiting connection acknowledge" msgstr "" -#: mod/contacts.php:666 +#: mod/contacts.php:667 msgid "" "Replies/likes to your public posts may still be visible" msgstr "" -#: mod/contacts.php:667 +#: mod/contacts.php:668 msgid "Notification for new posts" msgstr "" -#: mod/contacts.php:667 +#: mod/contacts.php:668 msgid "Send a notification of every new post of this contact" msgstr "" -#: mod/contacts.php:670 +#: mod/contacts.php:671 msgid "Blacklisted keywords" msgstr "" -#: mod/contacts.php:670 +#: mod/contacts.php:671 msgid "" "Comma separated list of keywords that should not be converted to hashtags, " "when \"Fetch information and keywords\" is selected" msgstr "" -#: mod/contacts.php:682 src/Model/Profile.php:424 +#: mod/contacts.php:683 src/Model/Profile.php:437 msgid "XMPP:" msgstr "" -#: mod/contacts.php:687 +#: mod/contacts.php:688 msgid "Actions" msgstr "" -#: mod/contacts.php:731 +#: mod/contacts.php:734 msgid "Suggestions" msgstr "" -#: mod/contacts.php:734 +#: mod/contacts.php:737 msgid "Suggest potential friends" msgstr "" -#: mod/contacts.php:742 +#: mod/contacts.php:745 msgid "Show all contacts" msgstr "" -#: mod/contacts.php:747 +#: mod/contacts.php:750 msgid "Unblocked" msgstr "" -#: mod/contacts.php:750 +#: mod/contacts.php:753 msgid "Only show unblocked contacts" msgstr "" -#: mod/contacts.php:755 +#: mod/contacts.php:758 msgid "Blocked" msgstr "" -#: mod/contacts.php:758 +#: mod/contacts.php:761 msgid "Only show blocked contacts" msgstr "" -#: mod/contacts.php:763 +#: mod/contacts.php:766 msgid "Ignored" msgstr "" -#: mod/contacts.php:766 +#: mod/contacts.php:769 msgid "Only show ignored contacts" msgstr "" -#: mod/contacts.php:771 +#: mod/contacts.php:774 msgid "Archived" msgstr "" -#: mod/contacts.php:774 +#: mod/contacts.php:777 msgid "Only show archived contacts" msgstr "" -#: mod/contacts.php:779 +#: mod/contacts.php:782 msgid "Hidden" msgstr "" -#: mod/contacts.php:782 +#: mod/contacts.php:785 msgid "Only show hidden contacts" msgstr "" -#: mod/contacts.php:840 +#: mod/contacts.php:843 msgid "Search your contacts" msgstr "" -#: mod/contacts.php:851 mod/contacts.php:1122 +#: mod/contacts.php:854 mod/contacts.php:1125 msgid "Archive" msgstr "" -#: mod/contacts.php:851 mod/contacts.php:1122 +#: mod/contacts.php:854 mod/contacts.php:1125 msgid "Unarchive" msgstr "" -#: mod/contacts.php:854 +#: mod/contacts.php:857 msgid "Batch Actions" msgstr "" -#: mod/contacts.php:880 +#: mod/contacts.php:883 msgid "Conversations started by this contact" msgstr "" -#: mod/contacts.php:885 +#: mod/contacts.php:888 msgid "Posts and Comments" msgstr "" -#: mod/contacts.php:896 src/Model/Profile.php:886 +#: mod/contacts.php:899 src/Model/Profile.php:899 msgid "Profile Details" msgstr "" -#: mod/contacts.php:908 +#: mod/contacts.php:911 msgid "View all contacts" msgstr "" -#: mod/contacts.php:919 +#: mod/contacts.php:922 msgid "View all common friends" msgstr "" -#: mod/contacts.php:929 +#: mod/contacts.php:932 msgid "Advanced Contact Settings" msgstr "" -#: mod/contacts.php:1019 +#: mod/contacts.php:1022 msgid "Mutual Friendship" msgstr "" -#: mod/contacts.php:1024 +#: mod/contacts.php:1027 msgid "is a fan of yours" msgstr "" -#: mod/contacts.php:1029 +#: mod/contacts.php:1032 msgid "you are a fan of" msgstr "" -#: mod/contacts.php:1046 mod/photos.php:1494 mod/photos.php:1533 -#: mod/photos.php:1593 src/Object/Post.php:792 +#: mod/contacts.php:1049 mod/photos.php:1496 mod/photos.php:1535 +#: mod/photos.php:1595 src/Object/Post.php:792 msgid "This is you" msgstr "" -#: mod/contacts.php:1053 +#: mod/contacts.php:1056 msgid "Edit contact" msgstr "" -#: mod/contacts.php:1107 +#: mod/contacts.php:1110 msgid "Toggle Blocked status" msgstr "" -#: mod/contacts.php:1115 +#: mod/contacts.php:1118 msgid "Toggle Ignored status" msgstr "" -#: mod/contacts.php:1124 +#: mod/contacts.php:1127 msgid "Toggle Archive status" msgstr "" -#: mod/contacts.php:1132 +#: mod/contacts.php:1135 msgid "Delete contact" msgstr "" -#: mod/events.php:103 mod/events.php:105 +#: mod/events.php:105 mod/events.php:107 msgid "Event can not end before it has started." msgstr "" -#: mod/events.php:112 mod/events.php:114 +#: mod/events.php:114 mod/events.php:116 msgid "Event title and start time are required." msgstr "" -#: mod/events.php:392 +#: mod/events.php:393 msgid "Create New Event" msgstr "" -#: mod/events.php:509 +#: mod/events.php:516 msgid "Event details" msgstr "" -#: mod/events.php:510 +#: mod/events.php:517 msgid "Starting date and Title are required." msgstr "" -#: mod/events.php:511 mod/events.php:512 +#: mod/events.php:518 mod/events.php:523 msgid "Event Starts:" msgstr "" -#: mod/events.php:511 mod/events.php:523 mod/profiles.php:607 +#: mod/events.php:518 mod/events.php:550 mod/profiles.php:607 msgid "Required" msgstr "" -#: mod/events.php:513 mod/events.php:529 +#: mod/events.php:531 mod/events.php:556 msgid "Finish date/time is not known or not relevant" msgstr "" -#: mod/events.php:515 mod/events.php:516 +#: mod/events.php:533 mod/events.php:538 msgid "Event Finishes:" msgstr "" -#: mod/events.php:517 mod/events.php:530 +#: mod/events.php:544 mod/events.php:557 msgid "Adjust for viewer timezone" msgstr "" -#: mod/events.php:519 +#: mod/events.php:546 msgid "Description:" msgstr "" -#: mod/events.php:523 mod/events.php:525 +#: mod/events.php:550 mod/events.php:552 msgid "Title:" msgstr "" -#: mod/events.php:526 mod/events.php:527 +#: mod/events.php:553 mod/events.php:554 msgid "Share this event" msgstr "" -#: mod/events.php:534 src/Model/Profile.php:851 +#: mod/events.php:561 src/Model/Profile.php:864 msgid "Basic" msgstr "" -#: mod/events.php:536 mod/photos.php:1112 mod/photos.php:1448 +#: mod/events.php:563 mod/photos.php:1114 mod/photos.php:1450 #: src/Core/ACL.php:307 msgid "Permissions" msgstr "" -#: mod/events.php:555 +#: mod/events.php:579 msgid "Failed to remove event" msgstr "" -#: mod/events.php:557 +#: mod/events.php:581 msgid "Event removed" msgstr "" @@ -6987,8 +7003,8 @@ msgid "The network type couldn't be detected. Contact can't be added." msgstr "" #: mod/fbrowser.php:44 mod/fbrowser.php:69 mod/photos.php:198 -#: mod/photos.php:1076 mod/photos.php:1169 mod/photos.php:1186 -#: mod/photos.php:1652 mod/photos.php:1667 src/Model/Photo.php:243 +#: mod/photos.php:1078 mod/photos.php:1171 mod/photos.php:1188 +#: mod/photos.php:1654 mod/photos.php:1669 src/Model/Photo.php:243 #: src/Model/Photo.php:252 msgid "Contact Photos" msgstr "" @@ -7059,7 +7075,7 @@ msgid "" "not reflect the opinions of this node’s users." msgstr "" -#: mod/localtime.php:19 src/Model/Event.php:34 src/Model/Event.php:829 +#: mod/localtime.php:19 src/Model/Event.php:35 src/Model/Event.php:836 msgid "l F d, Y \\@ g:i A" msgstr "" @@ -7092,23 +7108,23 @@ msgstr "" msgid "Please select your timezone:" msgstr "" -#: mod/poke.php:188 +#: mod/poke.php:187 msgid "Poke/Prod" msgstr "" -#: mod/poke.php:189 +#: mod/poke.php:188 msgid "poke, prod or do other things to somebody" msgstr "" -#: mod/poke.php:190 +#: mod/poke.php:189 msgid "Recipient" msgstr "" -#: mod/poke.php:191 +#: mod/poke.php:190 msgid "Choose what you wish to do to recipient" msgstr "" -#: mod/poke.php:194 +#: mod/poke.php:193 msgid "Make this post private" msgstr "" @@ -7216,7 +7232,7 @@ msgid "" "important, please visit http://friendi.ca" msgstr "" -#: mod/notes.php:42 src/Model/Profile.php:933 +#: mod/notes.php:42 src/Model/Profile.php:946 msgid "Personal Notes" msgstr "" @@ -7320,7 +7336,7 @@ msgstr "" msgid "View all profiles" msgstr "" -#: mod/profiles.php:582 mod/profiles.php:677 src/Model/Profile.php:393 +#: mod/profiles.php:582 mod/profiles.php:677 src/Model/Profile.php:406 msgid "Edit visibility" msgstr "" @@ -7372,7 +7388,7 @@ msgstr "" msgid " Marital Status:" msgstr "" -#: mod/profiles.php:601 src/Model/Profile.php:769 +#: mod/profiles.php:601 src/Model/Profile.php:782 msgid "Sexual Preference:" msgstr "" @@ -7452,11 +7468,11 @@ msgstr "" msgid "Homepage URL:" msgstr "" -#: mod/profiles.php:628 src/Model/Profile.php:777 +#: mod/profiles.php:628 src/Model/Profile.php:790 msgid "Hometown:" msgstr "" -#: mod/profiles.php:629 src/Model/Profile.php:785 +#: mod/profiles.php:629 src/Model/Profile.php:798 msgid "Political Views:" msgstr "" @@ -7480,11 +7496,11 @@ msgstr "" msgid "(Used for searching profiles, never shown to others)" msgstr "" -#: mod/profiles.php:633 src/Model/Profile.php:801 +#: mod/profiles.php:633 src/Model/Profile.php:814 msgid "Likes:" msgstr "" -#: mod/profiles.php:634 src/Model/Profile.php:805 +#: mod/profiles.php:634 src/Model/Profile.php:818 msgid "Dislikes:" msgstr "" @@ -7524,11 +7540,11 @@ msgstr "" msgid "Contact information and Social Networks" msgstr "" -#: mod/profiles.php:674 src/Model/Profile.php:389 +#: mod/profiles.php:674 src/Model/Profile.php:402 msgid "Profile Image" msgstr "" -#: mod/profiles.php:676 src/Model/Profile.php:392 +#: mod/profiles.php:676 src/Model/Profile.php:405 msgid "visible to everybody" msgstr "" @@ -7536,23 +7552,23 @@ msgstr "" msgid "Edit/Manage Profiles" msgstr "" -#: mod/profiles.php:684 src/Model/Profile.php:379 src/Model/Profile.php:401 +#: mod/profiles.php:684 src/Model/Profile.php:392 src/Model/Profile.php:414 msgid "Change profile photo" msgstr "" -#: mod/profiles.php:685 src/Model/Profile.php:380 +#: mod/profiles.php:685 src/Model/Profile.php:393 msgid "Create New Profile" msgstr "" -#: mod/photos.php:112 src/Model/Profile.php:894 +#: mod/photos.php:112 src/Model/Profile.php:907 msgid "Photo Albums" msgstr "" -#: mod/photos.php:113 mod/photos.php:1708 +#: mod/photos.php:113 mod/photos.php:1710 msgid "Recent Photos" msgstr "" -#: mod/photos.php:116 mod/photos.php:1230 mod/photos.php:1710 +#: mod/photos.php:116 mod/photos.php:1232 mod/photos.php:1712 msgid "Upload New Photos" msgstr "" @@ -7564,7 +7580,7 @@ msgstr "" msgid "Album not found." msgstr "" -#: mod/photos.php:239 mod/photos.php:252 mod/photos.php:1181 +#: mod/photos.php:239 mod/photos.php:252 mod/photos.php:1183 msgid "Delete Album" msgstr "" @@ -7572,7 +7588,7 @@ msgstr "" msgid "Do you really want to delete this photo album and all its photos?" msgstr "" -#: mod/photos.php:312 mod/photos.php:324 mod/photos.php:1453 +#: mod/photos.php:312 mod/photos.php:324 mod/photos.php:1455 msgid "Delete Photo" msgstr "" @@ -7589,149 +7605,149 @@ msgstr "" msgid "%1$s was tagged in %2$s by %3$s" msgstr "" -#: mod/photos.php:782 +#: mod/photos.php:784 msgid "Image upload didn't complete, please try again" msgstr "" -#: mod/photos.php:785 +#: mod/photos.php:787 msgid "Image file is missing" msgstr "" -#: mod/photos.php:790 +#: mod/photos.php:792 msgid "" "Server can't accept new file upload at this time, please contact your " "administrator" msgstr "" -#: mod/photos.php:816 +#: mod/photos.php:818 msgid "Image file is empty." msgstr "" -#: mod/photos.php:953 +#: mod/photos.php:955 msgid "No photos selected" msgstr "" -#: mod/photos.php:1104 +#: mod/photos.php:1106 msgid "Upload Photos" msgstr "" -#: mod/photos.php:1108 mod/photos.php:1176 +#: mod/photos.php:1110 mod/photos.php:1178 msgid "New album name: " msgstr "" -#: mod/photos.php:1109 +#: mod/photos.php:1111 msgid "or select existing album:" msgstr "" -#: mod/photos.php:1110 +#: mod/photos.php:1112 msgid "Do not show a status post for this upload" msgstr "" -#: mod/photos.php:1187 +#: mod/photos.php:1189 msgid "Edit Album" msgstr "" -#: mod/photos.php:1192 +#: mod/photos.php:1194 msgid "Show Newest First" msgstr "" -#: mod/photos.php:1194 +#: mod/photos.php:1196 msgid "Show Oldest First" msgstr "" -#: mod/photos.php:1215 mod/photos.php:1693 +#: mod/photos.php:1217 mod/photos.php:1695 msgid "View Photo" msgstr "" -#: mod/photos.php:1256 +#: mod/photos.php:1258 msgid "Permission denied. Access to this item may be restricted." msgstr "" -#: mod/photos.php:1258 +#: mod/photos.php:1260 msgid "Photo not available" msgstr "" -#: mod/photos.php:1333 +#: mod/photos.php:1335 msgid "View photo" msgstr "" -#: mod/photos.php:1333 +#: mod/photos.php:1335 msgid "Edit photo" msgstr "" -#: mod/photos.php:1334 +#: mod/photos.php:1336 msgid "Use as profile photo" msgstr "" -#: mod/photos.php:1340 src/Object/Post.php:151 +#: mod/photos.php:1342 src/Object/Post.php:151 msgid "Private Message" msgstr "" -#: mod/photos.php:1360 +#: mod/photos.php:1362 msgid "View Full Size" msgstr "" -#: mod/photos.php:1421 +#: mod/photos.php:1423 msgid "Tags: " msgstr "" -#: mod/photos.php:1424 +#: mod/photos.php:1426 msgid "[Remove any tag]" msgstr "" -#: mod/photos.php:1439 +#: mod/photos.php:1441 msgid "New album name" msgstr "" -#: mod/photos.php:1440 +#: mod/photos.php:1442 msgid "Caption" msgstr "" -#: mod/photos.php:1441 +#: mod/photos.php:1443 msgid "Add a Tag" msgstr "" -#: mod/photos.php:1441 +#: mod/photos.php:1443 msgid "Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping" msgstr "" -#: mod/photos.php:1442 +#: mod/photos.php:1444 msgid "Do not rotate" msgstr "" -#: mod/photos.php:1443 +#: mod/photos.php:1445 msgid "Rotate CW (right)" msgstr "" -#: mod/photos.php:1444 +#: mod/photos.php:1446 msgid "Rotate CCW (left)" msgstr "" -#: mod/photos.php:1478 src/Object/Post.php:293 +#: mod/photos.php:1480 src/Object/Post.php:293 msgid "I like this (toggle)" msgstr "" -#: mod/photos.php:1479 src/Object/Post.php:294 +#: mod/photos.php:1481 src/Object/Post.php:294 msgid "I don't like this (toggle)" msgstr "" -#: mod/photos.php:1496 mod/photos.php:1535 mod/photos.php:1595 +#: mod/photos.php:1498 mod/photos.php:1537 mod/photos.php:1597 #: src/Object/Post.php:398 src/Object/Post.php:794 msgid "Comment" msgstr "" -#: mod/photos.php:1627 +#: mod/photos.php:1629 msgid "Map" msgstr "" -#: local/test.php:1840 +#: local/test.php:1919 #, php-format msgid "" "%s wrote the following post" msgstr "" -#: local/testshare.php:158 src/Content/Text/BBCode.php:991 +#: local/testshare.php:158 src/Content/Text/BBCode.php:992 #, php-format msgid "%2$s %3$s" msgstr "" @@ -7793,11 +7809,11 @@ msgstr "" msgid "%s: updating %s table." msgstr "" -#: src/Core/Install.php:138 +#: src/Core/Install.php:139 msgid "Could not find a command line version of PHP in the web server PATH." msgstr "" -#: src/Core/Install.php:139 +#: src/Core/Install.php:140 msgid "" "If you don't have a command line version of PHP installed on your server, " "you will not be able to run the background processing. See 'Setup the worker'" msgstr "" -#: src/Core/Install.php:143 +#: src/Core/Install.php:144 msgid "PHP executable path" msgstr "" -#: src/Core/Install.php:143 +#: src/Core/Install.php:144 msgid "" "Enter full path to php executable. You can leave this blank to continue the " "installation." msgstr "" -#: src/Core/Install.php:148 +#: src/Core/Install.php:149 msgid "Command line PHP" msgstr "" -#: src/Core/Install.php:157 +#: src/Core/Install.php:158 msgid "PHP executable is not the php cli binary (could be cgi-fgci version)" msgstr "" -#: src/Core/Install.php:158 +#: src/Core/Install.php:159 msgid "Found PHP version: " msgstr "" -#: src/Core/Install.php:160 +#: src/Core/Install.php:161 msgid "PHP cli binary" msgstr "" -#: src/Core/Install.php:170 +#: src/Core/Install.php:171 msgid "" "The command line version of PHP on your system does not have " "\"register_argc_argv\" enabled." msgstr "" -#: src/Core/Install.php:171 +#: src/Core/Install.php:172 msgid "This is required for message delivery to work." msgstr "" -#: src/Core/Install.php:173 +#: src/Core/Install.php:174 msgid "PHP register_argc_argv" msgstr "" -#: src/Core/Install.php:201 +#: src/Core/Install.php:202 msgid "" "Error: the \"openssl_pkey_new\" function on this system is not able to " "generate encryption keys" msgstr "" -#: src/Core/Install.php:202 +#: src/Core/Install.php:203 msgid "" "If running under Windows, please see \"http://www.php.net/manual/en/openssl." "installation.php\"." msgstr "" -#: src/Core/Install.php:204 +#: src/Core/Install.php:205 msgid "Generate encryption keys" msgstr "" -#: src/Core/Install.php:225 +#: src/Core/Install.php:226 msgid "libCurl PHP module" msgstr "" -#: src/Core/Install.php:226 +#: src/Core/Install.php:227 msgid "GD graphics PHP module" msgstr "" -#: src/Core/Install.php:227 +#: src/Core/Install.php:228 msgid "OpenSSL PHP module" msgstr "" -#: src/Core/Install.php:228 +#: src/Core/Install.php:229 msgid "PDO or MySQLi PHP module" msgstr "" -#: src/Core/Install.php:229 +#: src/Core/Install.php:230 msgid "mb_string PHP module" msgstr "" -#: src/Core/Install.php:230 +#: src/Core/Install.php:231 msgid "XML PHP module" msgstr "" -#: src/Core/Install.php:231 +#: src/Core/Install.php:232 msgid "iconv PHP module" msgstr "" -#: src/Core/Install.php:232 +#: src/Core/Install.php:233 msgid "POSIX PHP module" msgstr "" -#: src/Core/Install.php:236 src/Core/Install.php:238 +#: src/Core/Install.php:237 src/Core/Install.php:239 msgid "Apache mod_rewrite module" msgstr "" -#: src/Core/Install.php:236 +#: src/Core/Install.php:237 msgid "" "Error: Apache webserver mod-rewrite module is required but not installed." msgstr "" -#: src/Core/Install.php:244 +#: src/Core/Install.php:245 msgid "Error: libCURL PHP module required but not installed." msgstr "" -#: src/Core/Install.php:248 +#: src/Core/Install.php:249 msgid "" "Error: GD graphics PHP module with JPEG support required but not installed." msgstr "" -#: src/Core/Install.php:252 +#: src/Core/Install.php:253 msgid "Error: openssl PHP module required but not installed." msgstr "" -#: src/Core/Install.php:256 +#: src/Core/Install.php:257 msgid "Error: PDO or MySQLi PHP module required but not installed." msgstr "" -#: src/Core/Install.php:260 +#: src/Core/Install.php:261 msgid "Error: The MySQL driver for PDO is not installed." msgstr "" -#: src/Core/Install.php:264 +#: src/Core/Install.php:265 msgid "Error: mb_string PHP module required but not installed." msgstr "" -#: src/Core/Install.php:268 +#: src/Core/Install.php:269 msgid "Error: iconv PHP module required but not installed." msgstr "" -#: src/Core/Install.php:272 +#: src/Core/Install.php:273 msgid "Error: POSIX PHP module required but not installed." msgstr "" -#: src/Core/Install.php:282 +#: src/Core/Install.php:283 msgid "Error, XML PHP module required but not installed." msgstr "" -#: src/Core/Install.php:301 +#: src/Core/Install.php:302 msgid "" "The web installer needs to be able to create a file called \"local.ini.php\" " "in the \"config\" folder of your web server and it is unable to do so." msgstr "" -#: src/Core/Install.php:302 +#: src/Core/Install.php:303 msgid "" "This is most often a permission setting, as the web server may not be able " "to write files in your folder - even if you can." msgstr "" -#: src/Core/Install.php:303 +#: src/Core/Install.php:304 msgid "" "At the end of this procedure, we will give you a text to save in a file " "named local.ini.php in your Friendica \"config\" folder." msgstr "" -#: src/Core/Install.php:304 +#: src/Core/Install.php:305 msgid "" "You can alternatively skip this procedure and perform a manual installation. " "Please see the file \"INSTALL.txt\" for instructions." msgstr "" -#: src/Core/Install.php:307 +#: src/Core/Install.php:308 msgid "config/local.ini.php is writable" msgstr "" -#: src/Core/Install.php:325 +#: src/Core/Install.php:326 msgid "" "Friendica uses the Smarty3 template engine to render its web views. Smarty3 " "compiles templates to PHP to speed up rendering." msgstr "" -#: src/Core/Install.php:326 +#: src/Core/Install.php:327 msgid "" "In order to store these compiled templates, the web server needs to have " "write access to the directory view/smarty3/ under the Friendica top level " "folder." msgstr "" -#: src/Core/Install.php:327 +#: src/Core/Install.php:328 msgid "" "Please ensure that the user that your web server runs as (e.g. www-data) has " "write access to this folder." msgstr "" -#: src/Core/Install.php:328 +#: src/Core/Install.php:329 msgid "" "Note: as a security measure, you should give the web server write access to " "view/smarty3/ only--not the template files (.tpl) that it contains." msgstr "" -#: src/Core/Install.php:331 +#: src/Core/Install.php:332 msgid "view/smarty3 is writable" msgstr "" -#: src/Core/Install.php:356 +#: src/Core/Install.php:357 msgid "" "Url rewrite in .htaccess is not working. Check your server configuration." msgstr "" -#: src/Core/Install.php:358 +#: src/Core/Install.php:359 msgid "Error message from Curl when fetching" msgstr "" -#: src/Core/Install.php:362 +#: src/Core/Install.php:363 msgid "Url rewrite is working" msgstr "" -#: src/Core/Install.php:389 +#: src/Core/Install.php:390 msgid "ImageMagick PHP extension is not installed" msgstr "" -#: src/Core/Install.php:391 +#: src/Core/Install.php:392 msgid "ImageMagick PHP extension is installed" msgstr "" -#: src/Core/Install.php:393 +#: src/Core/Install.php:394 msgid "ImageMagick supports GIF" msgstr "" @@ -8051,11 +8067,16 @@ msgstr "" msgid "The contact entries have been archived" msgstr "" -#: src/Core/Console/PostUpdate.php:32 +#: src/Core/Console/PostUpdate.php:49 +#, php-format +msgid "Post update version number has been set to %s." +msgstr "" + +#: src/Core/Console/PostUpdate.php:57 msgid "Execute pending post updates." msgstr "" -#: src/Core/Console/PostUpdate.php:38 +#: src/Core/Console/PostUpdate.php:63 msgid "All pending post updates are done." msgstr "" @@ -8115,20 +8136,20 @@ msgstr "" msgid "%s may attend %s's event" msgstr "" -#: src/Core/NotificationsManager.php:360 +#: src/Core/NotificationsManager.php:372 #, php-format msgid "%s is now friends with %s" msgstr "" -#: src/Core/NotificationsManager.php:626 +#: src/Core/NotificationsManager.php:638 msgid "Friend Suggestion" msgstr "" -#: src/Core/NotificationsManager.php:656 +#: src/Core/NotificationsManager.php:672 msgid "Friend/Connect Request" msgstr "" -#: src/Core/NotificationsManager.php:656 +#: src/Core/NotificationsManager.php:672 msgid "New Follower" msgstr "" @@ -8164,7 +8185,7 @@ msgstr[1] "" msgid "Done. You can now login with your username and password" msgstr "" -#: src/Worker/Delivery.php:423 +#: src/Worker/Delivery.php:425 msgid "(no subject)" msgstr "" @@ -8299,15 +8320,15 @@ msgstr "" msgid "Video" msgstr "" -#: src/App.php:785 +#: src/App.php:798 msgid "Delete this item?" msgstr "" -#: src/App.php:787 +#: src/App.php:800 msgid "show fewer" msgstr "" -#: src/App.php:1385 +#: src/App.php:1416 msgid "No system theme config value set." msgstr "" @@ -8395,43 +8416,47 @@ msgstr "" msgid "Privacy Statement" msgstr "" -#: src/Protocol/OStatus.php:1813 +#: src/Module/Proxy.php:138 +msgid "Bad Request." +msgstr "" + +#: src/Protocol/OStatus.php:1823 #, php-format msgid "%s is now following %s." msgstr "" -#: src/Protocol/OStatus.php:1814 +#: src/Protocol/OStatus.php:1824 msgid "following" msgstr "" -#: src/Protocol/OStatus.php:1817 +#: src/Protocol/OStatus.php:1827 #, php-format msgid "%s stopped following %s." msgstr "" -#: src/Protocol/OStatus.php:1818 +#: src/Protocol/OStatus.php:1828 msgid "stopped following" msgstr "" -#: src/Protocol/DFRN.php:1525 src/Model/Contact.php:1956 +#: src/Protocol/DFRN.php:1528 src/Model/Contact.php:1974 #, php-format msgid "%s's birthday" msgstr "" -#: src/Protocol/DFRN.php:1526 src/Model/Contact.php:1957 +#: src/Protocol/DFRN.php:1529 src/Model/Contact.php:1975 #, php-format msgid "Happy Birthday %s" msgstr "" -#: src/Protocol/Diaspora.php:2417 +#: src/Protocol/Diaspora.php:2434 msgid "Sharing notification from Diaspora network" msgstr "" -#: src/Protocol/Diaspora.php:3514 +#: src/Protocol/Diaspora.php:3531 msgid "Attachments:" msgstr "" -#: src/Util/Temporal.php:147 src/Model/Profile.php:745 +#: src/Util/Temporal.php:147 src/Model/Profile.php:758 msgid "Birthday:" msgstr "" @@ -8500,134 +8525,134 @@ msgstr "" msgid "[no subject]" msgstr "" -#: src/Model/Contact.php:942 +#: src/Model/Contact.php:953 msgid "Drop Contact" msgstr "" -#: src/Model/Contact.php:1399 +#: src/Model/Contact.php:1408 msgid "Organisation" msgstr "" -#: src/Model/Contact.php:1403 +#: src/Model/Contact.php:1412 msgid "News" msgstr "" -#: src/Model/Contact.php:1407 +#: src/Model/Contact.php:1416 msgid "Forum" msgstr "" -#: src/Model/Contact.php:1587 +#: src/Model/Contact.php:1598 msgid "Connect URL missing." msgstr "" -#: src/Model/Contact.php:1596 +#: src/Model/Contact.php:1607 msgid "" "The contact could not be added. Please check the relevant network " "credentials in your Settings -> Social Networks page." msgstr "" -#: src/Model/Contact.php:1635 +#: src/Model/Contact.php:1646 msgid "" "This site is not configured to allow communications with other networks." msgstr "" -#: src/Model/Contact.php:1636 src/Model/Contact.php:1650 +#: src/Model/Contact.php:1647 src/Model/Contact.php:1661 msgid "No compatible communication protocols or feeds were discovered." msgstr "" -#: src/Model/Contact.php:1648 +#: src/Model/Contact.php:1659 msgid "The profile address specified does not provide adequate information." msgstr "" -#: src/Model/Contact.php:1653 +#: src/Model/Contact.php:1664 msgid "An author or name was not found." msgstr "" -#: src/Model/Contact.php:1656 +#: src/Model/Contact.php:1667 msgid "No browser URL could be matched to this address." msgstr "" -#: src/Model/Contact.php:1659 +#: src/Model/Contact.php:1670 msgid "" "Unable to match @-style Identity Address with a known protocol or email " "contact." msgstr "" -#: src/Model/Contact.php:1660 +#: src/Model/Contact.php:1671 msgid "Use mailto: in front of address to force email check." msgstr "" -#: src/Model/Contact.php:1666 +#: src/Model/Contact.php:1677 msgid "" "The profile address specified belongs to a network which has been disabled " "on this site." msgstr "" -#: src/Model/Contact.php:1671 +#: src/Model/Contact.php:1682 msgid "" "Limited profile. This person will be unable to receive direct/personal " "notifications from you." msgstr "" -#: src/Model/Contact.php:1722 +#: src/Model/Contact.php:1733 msgid "Unable to retrieve contact information." msgstr "" -#: src/Model/Event.php:59 src/Model/Event.php:76 src/Model/Event.php:428 -#: src/Model/Event.php:897 +#: src/Model/Event.php:60 src/Model/Event.php:77 src/Model/Event.php:429 +#: src/Model/Event.php:904 msgid "Starts:" msgstr "" -#: src/Model/Event.php:62 src/Model/Event.php:82 src/Model/Event.php:429 -#: src/Model/Event.php:901 +#: src/Model/Event.php:63 src/Model/Event.php:83 src/Model/Event.php:430 +#: src/Model/Event.php:908 msgid "Finishes:" msgstr "" -#: src/Model/Event.php:377 +#: src/Model/Event.php:378 msgid "all-day" msgstr "" -#: src/Model/Event.php:400 +#: src/Model/Event.php:401 msgid "Jun" msgstr "" -#: src/Model/Event.php:403 +#: src/Model/Event.php:404 msgid "Sept" msgstr "" -#: src/Model/Event.php:426 +#: src/Model/Event.php:427 msgid "No events to display" msgstr "" -#: src/Model/Event.php:550 +#: src/Model/Event.php:551 msgid "l, F j" msgstr "" -#: src/Model/Event.php:581 +#: src/Model/Event.php:582 msgid "Edit event" msgstr "" -#: src/Model/Event.php:582 +#: src/Model/Event.php:583 msgid "Duplicate event" msgstr "" -#: src/Model/Event.php:583 +#: src/Model/Event.php:584 msgid "Delete event" msgstr "" -#: src/Model/Event.php:830 +#: src/Model/Event.php:837 msgid "D g:i A" msgstr "" -#: src/Model/Event.php:831 +#: src/Model/Event.php:838 msgid "g:i A" msgstr "" -#: src/Model/Event.php:916 src/Model/Event.php:918 +#: src/Model/Event.php:923 src/Model/Event.php:925 msgid "Show map" msgstr "" -#: src/Model/Event.php:917 +#: src/Model/Event.php:924 msgid "Hide map" msgstr "" @@ -8707,7 +8732,7 @@ msgstr "" msgid "An error occurred creating your self contact. Please try again." msgstr "" -#: src/Model/User.php:561 src/Content/ContactSelector.php:166 +#: src/Model/User.php:561 src/Content/ContactSelector.php:171 msgid "Friends" msgstr "" @@ -8810,129 +8835,129 @@ msgstr "" msgid "Edit groups" msgstr "" -#: src/Model/Profile.php:97 +#: src/Model/Profile.php:110 msgid "Requested account is not available." msgstr "" -#: src/Model/Profile.php:163 src/Model/Profile.php:399 -#: src/Model/Profile.php:846 +#: src/Model/Profile.php:176 src/Model/Profile.php:412 +#: src/Model/Profile.php:859 msgid "Edit profile" msgstr "" -#: src/Model/Profile.php:333 +#: src/Model/Profile.php:346 msgid "Atom feed" msgstr "" -#: src/Model/Profile.php:372 +#: src/Model/Profile.php:385 msgid "Manage/edit profiles" msgstr "" -#: src/Model/Profile.php:550 src/Model/Profile.php:639 +#: src/Model/Profile.php:563 src/Model/Profile.php:652 msgid "g A l F d" msgstr "" -#: src/Model/Profile.php:551 +#: src/Model/Profile.php:564 msgid "F d" msgstr "" -#: src/Model/Profile.php:604 src/Model/Profile.php:690 +#: src/Model/Profile.php:617 src/Model/Profile.php:703 msgid "[today]" msgstr "" -#: src/Model/Profile.php:615 +#: src/Model/Profile.php:628 msgid "Birthday Reminders" msgstr "" -#: src/Model/Profile.php:616 +#: src/Model/Profile.php:629 msgid "Birthdays this week:" msgstr "" -#: src/Model/Profile.php:677 +#: src/Model/Profile.php:690 msgid "[No description]" msgstr "" -#: src/Model/Profile.php:704 +#: src/Model/Profile.php:717 msgid "Event Reminders" msgstr "" -#: src/Model/Profile.php:705 +#: src/Model/Profile.php:718 msgid "Upcoming events the next 7 days:" msgstr "" -#: src/Model/Profile.php:728 +#: src/Model/Profile.php:741 msgid "Member since:" msgstr "" -#: src/Model/Profile.php:736 +#: src/Model/Profile.php:749 msgid "j F, Y" msgstr "" -#: src/Model/Profile.php:737 +#: src/Model/Profile.php:750 msgid "j F" msgstr "" -#: src/Model/Profile.php:752 +#: src/Model/Profile.php:765 msgid "Age:" msgstr "" -#: src/Model/Profile.php:765 +#: src/Model/Profile.php:778 #, php-format msgid "for %1$d %2$s" msgstr "" -#: src/Model/Profile.php:789 +#: src/Model/Profile.php:802 msgid "Religion:" msgstr "" -#: src/Model/Profile.php:797 +#: src/Model/Profile.php:810 msgid "Hobbies/Interests:" msgstr "" -#: src/Model/Profile.php:809 +#: src/Model/Profile.php:822 msgid "Contact information and Social Networks:" msgstr "" -#: src/Model/Profile.php:813 +#: src/Model/Profile.php:826 msgid "Musical interests:" msgstr "" -#: src/Model/Profile.php:817 +#: src/Model/Profile.php:830 msgid "Books, literature:" msgstr "" -#: src/Model/Profile.php:821 +#: src/Model/Profile.php:834 msgid "Television:" msgstr "" -#: src/Model/Profile.php:825 +#: src/Model/Profile.php:838 msgid "Film/dance/culture/entertainment:" msgstr "" -#: src/Model/Profile.php:829 +#: src/Model/Profile.php:842 msgid "Love/Romance:" msgstr "" -#: src/Model/Profile.php:833 +#: src/Model/Profile.php:846 msgid "Work/employment:" msgstr "" -#: src/Model/Profile.php:837 +#: src/Model/Profile.php:850 msgid "School/education:" msgstr "" -#: src/Model/Profile.php:842 +#: src/Model/Profile.php:855 msgid "Forums:" msgstr "" -#: src/Model/Profile.php:936 +#: src/Model/Profile.php:949 msgid "Only You Can See This" msgstr "" -#: src/Model/Profile.php:944 src/Model/Profile.php:947 +#: src/Model/Profile.php:957 src/Model/Profile.php:960 msgid "Tips for New Members" msgstr "" -#: src/Model/Profile.php:1106 +#: src/Model/Profile.php:1119 #, php-format msgid "OpenWebAuth: %1$s welcomes %2$s" msgstr "" @@ -8956,27 +8981,27 @@ msgid_plural "%d invitations available" msgstr[0] "" msgstr[1] "" -#: src/Content/Widget.php:157 +#: src/Content/Widget.php:154 msgid "Networks" msgstr "" -#: src/Content/Widget.php:160 +#: src/Content/Widget.php:157 msgid "All Networks" msgstr "" -#: src/Content/Widget.php:198 src/Content/Feature.php:118 +#: src/Content/Widget.php:195 src/Content/Feature.php:118 msgid "Saved Folders" msgstr "" -#: src/Content/Widget.php:201 src/Content/Widget.php:241 +#: src/Content/Widget.php:198 src/Content/Widget.php:238 msgid "Everything" msgstr "" -#: src/Content/Widget.php:238 +#: src/Content/Widget.php:235 msgid "Categories" msgstr "" -#: src/Content/Widget.php:305 +#: src/Content/Widget.php:302 #, php-format msgid "%d contact in common" msgid_plural "%d contacts in common" @@ -9052,230 +9077,234 @@ msgid "GNU Social Connector" msgstr "" #: src/Content/ContactSelector.php:92 +msgid "ActivityPub" +msgstr "" + +#: src/Content/ContactSelector.php:93 msgid "pnut" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Male" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Female" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Currently Male" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Currently Female" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Mostly Male" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Mostly Female" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Transgender" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Intersex" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Transsexual" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Hermaphrodite" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Neuter" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Non-specific" msgstr "" -#: src/Content/ContactSelector.php:122 +#: src/Content/ContactSelector.php:127 msgid "Other" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Males" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Females" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Gay" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Lesbian" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "No Preference" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Bisexual" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Autosexual" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Abstinent" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Virgin" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Deviant" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Fetish" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Oodles" msgstr "" -#: src/Content/ContactSelector.php:144 +#: src/Content/ContactSelector.php:149 msgid "Nonsexual" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Single" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Lonely" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Available" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Unavailable" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Has crush" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Infatuated" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Dating" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Unfaithful" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Sex Addict" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Friends/Benefits" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Casual" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Engaged" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Married" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Imaginarily married" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Partners" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Cohabiting" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Common law" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Happy" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Not looking" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Swinger" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Betrayed" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Separated" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Unstable" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Divorced" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Imaginarily divorced" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Widowed" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Uncertain" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "It's complicated" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Don't care" msgstr "" -#: src/Content/ContactSelector.php:166 +#: src/Content/ContactSelector.php:171 msgid "Ask me" msgstr "" @@ -9622,27 +9651,27 @@ msgstr "" msgid "Embedded content" msgstr "" -#: src/Content/Text/BBCode.php:423 +#: src/Content/Text/BBCode.php:422 msgid "view full size" msgstr "" -#: src/Content/Text/BBCode.php:853 src/Content/Text/BBCode.php:1626 -#: src/Content/Text/BBCode.php:1627 +#: src/Content/Text/BBCode.php:854 src/Content/Text/BBCode.php:1623 +#: src/Content/Text/BBCode.php:1624 msgid "Image/photo" msgstr "" -#: src/Content/Text/BBCode.php:1553 src/Content/Text/BBCode.php:1575 +#: src/Content/Text/BBCode.php:1550 src/Content/Text/BBCode.php:1572 msgid "$1 wrote:" msgstr "" -#: src/Content/Text/BBCode.php:1635 src/Content/Text/BBCode.php:1636 +#: src/Content/Text/BBCode.php:1632 src/Content/Text/BBCode.php:1633 msgid "Encrypted content" msgstr "" -#: src/Content/Text/BBCode.php:1755 +#: src/Content/Text/BBCode.php:1752 msgid "Invalid source protocol" msgstr "" -#: src/Content/Text/BBCode.php:1766 +#: src/Content/Text/BBCode.php:1763 msgid "Invalid link protocol" msgstr "" From da79566125b28885d82de30d409f445f6843d4c3 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 28 Sep 2018 03:56:41 +0000 Subject: [PATCH 78/97] Relocated function --- src/Model/User.php | 17 +++++++++++++++++ src/Protocol/ActivityPub.php | 23 +++-------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Model/User.php b/src/Model/User.php index 095bf56e72..7432b75774 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -31,6 +31,23 @@ require_once 'include/text.php'; */ class User { + /** + * @brief Returns the user id of a given profile url + * + * @param string $profile + * + * @return integer user id + */ + public static function getIdForURL($url) + { + $self = DBA::selectFirst('contact', ['uid'], ['nurl' => normalise_link($url), 'self' => true]); + if (!DBA::isResult($self)) { + return false; + } else { + return $self['uid']; + } + } + /** * @brief Get owner data by user id * diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 663b03e939..ce960e10d3 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -1665,23 +1665,6 @@ class ActivityPub logger('Activity ' . $url . ' had been fetched and processed.'); } - /** - * @brief Returns the user id of a given profile url - * - * @param string $profile - * - * @return integer user id - */ - private static function getUserOfProfile($profile) - { - $self = DBA::selectFirst('contact', ['uid'], ['nurl' => normalise_link($profile), 'self' => true]); - if (!DBA::isResult($self)) { - return false; - } else { - return $self['uid']; - } - } - /** * @brief perform a "follow" request * @@ -1690,7 +1673,7 @@ class ActivityPub private static function followUser($activity) { $actor = JsonLD::fetchElement($activity, 'object', 'id'); - $uid = self::getUserOfProfile($actor); + $uid = User::getIdForURL($actor); if (empty($uid)) { return; } @@ -1745,7 +1728,7 @@ class ActivityPub private static function acceptFollowUser($activity) { $actor = JsonLD::fetchElement($activity, 'object', 'actor'); - $uid = self::getUserOfProfile($actor); + $uid = User::getIdForURL($actor); if (empty($uid)) { return; } @@ -1803,7 +1786,7 @@ class ActivityPub private static function undoFollowUser($activity) { $object = JsonLD::fetchElement($activity, 'object', 'object'); - $uid = self::getUserOfProfile($object); + $uid = User::getIdForURL($object); if (empty($uid)) { return; } From 357352efcc96be6dde8196e76b372774b04cee61 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 28 Sep 2018 15:04:51 +0000 Subject: [PATCH 79/97] Changed json-ld library --- composer.json | 6 +-- composer.lock | 138 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 94 insertions(+), 50 deletions(-) diff --git a/composer.json b/composer.json index ebf8217e5e..68e5cae99b 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,6 @@ "php": ">=5.6.1", "ext-xml": "*", "asika/simple-console": "^1.0", - "digitalbazaar/json-ld": "^0.4.7", "divineomega/password_exposed": "^2.4", "ezyang/htmlpurifier": "~4.7.0", "league/html-to-markdown": "~4.8.0", @@ -38,12 +37,13 @@ "npm-asset/jgrowl": "^1.4", "npm-asset/fullcalendar": "^3.0.1", "npm-asset/cropperjs": "1.2.2", - "npm-asset/imagesloaded": "4.1.4" + "npm-asset/imagesloaded": "4.1.4", + "friendica/json-ld": "^1.0" }, "repositories": [ { "type": "vcs", - "url": "https://github.com/pear/Text_Highlighter" + "url": "https://git.friendi.ca/friendica/php-json-ld" } ], "autoload": { diff --git a/composer.lock b/composer.lock index 1c5c25c0f4..f163101481 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "36f76191086a7f81370b51d0ff8cea1d", + "content-hash": "ece71ff50417ed5fcc1a439ea554925c", "packages": [ { "name": "asika/simple-console", @@ -149,52 +149,6 @@ }, "type": "bower-asset-library" }, - { - "name": "digitalbazaar/json-ld", - "version": "0.4.7", - "source": { - "type": "git", - "url": "https://github.com/digitalbazaar/php-json-ld.git", - "reference": "dc1bd23f0ee2efd27ccf636d32d2738dabcee182" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/digitalbazaar/php-json-ld/zipball/dc1bd23f0ee2efd27ccf636d32d2738dabcee182", - "reference": "dc1bd23f0ee2efd27ccf636d32d2738dabcee182", - "shasum": "" - }, - "require": { - "ext-json": "*", - "php": ">=5.3.0" - }, - "type": "library", - "autoload": { - "files": [ - "jsonld.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Digital Bazaar, Inc.", - "email": "support@digitalbazaar.com" - } - ], - "description": "A JSON-LD Processor and API implementation in PHP.", - "homepage": "https://github.com/digitalbazaar/php-json-ld", - "keywords": [ - "JSON-LD", - "Linked Data", - "RDF", - "Semantic Web", - "json", - "jsonld" - ], - "time": "2016-04-25T04:17:52+00:00" - }, { "name": "divineomega/password_exposed", "version": "v2.5.1", @@ -287,6 +241,50 @@ ], "time": "2015-08-05T01:03:42+00:00" }, + { + "name": "friendica/json-ld", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://git.friendi.ca/friendica/php-json-ld", + "reference": "a9ac64daf01cfd97e80c36a5104247d37c0ae5ef" + }, + "require": { + "ext-json": "*", + "php": ">=5.4.0" + }, + "type": "library", + "autoload": { + "files": [ + "jsonld.php" + ] + }, + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Digital Bazaar, Inc.", + "email": "support@digitalbazaar.com", + "url": "http://digitalbazaar.com/" + }, + { + "name": "Friendica Team", + "url": "https://friendi.ca/" + } + ], + "description": "A JSON-LD Processor and API implementation in PHP.", + "homepage": "https://git.friendi.ca/friendica/php-json-ld", + "keywords": [ + "JSON", + "JSON-LD", + "Linked Data", + "RDF", + "Semantic Web", + "jsonld" + ], + "time": "2018-09-28T00:01:12+00:00" + }, { "name": "fxp/composer-asset-plugin", "version": "v1.4.2", @@ -2046,6 +2044,52 @@ } ], "packages-dev": [ + { + "name": "digitalbazaar/json-ld", + "version": "0.4.7", + "source": { + "type": "git", + "url": "https://github.com/digitalbazaar/php-json-ld.git", + "reference": "dc1bd23f0ee2efd27ccf636d32d2738dabcee182" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/digitalbazaar/php-json-ld/zipball/dc1bd23f0ee2efd27ccf636d32d2738dabcee182", + "reference": "dc1bd23f0ee2efd27ccf636d32d2738dabcee182", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "files": [ + "jsonld.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Digital Bazaar, Inc.", + "email": "support@digitalbazaar.com" + } + ], + "description": "A JSON-LD Processor and API implementation in PHP.", + "homepage": "https://github.com/digitalbazaar/php-json-ld", + "keywords": [ + "JSON-LD", + "Linked Data", + "RDF", + "Semantic Web", + "json", + "jsonld" + ], + "time": "2016-04-25T04:17:52+00:00" + }, { "name": "doctrine/instantiator", "version": "1.0.5", From b043c7e0f2658e32d19ccd61120df6994d8e555a Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 28 Sep 2018 15:25:20 +0000 Subject: [PATCH 80/97] Changed constant name to keep compatible with PHP 5 --- src/Protocol/ActivityPub.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index ce960e10d3..a02031f003 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -75,7 +75,7 @@ use Friendica\Core\Config; */ class ActivityPub { - const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'; + const PUBLIC_COLLECTION = 'https://www.w3.org/ns/activitystreams#Public'; const CONTEXT = ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1', ['vcard' => 'http://www.w3.org/2006/vcard/ns#', 'diaspora' => 'https://diasporafoundation.org/ns/', @@ -364,7 +364,7 @@ class ActivityPub $contacts[$item['author-link']] = $item['author-link']; if (!$item['private']) { - $data['to'][] = self::PUBLIC; + $data['to'][] = self::PUBLIC_COLLECTION; if (!empty($actor_profile['followers'])) { $data['cc'][] = $actor_profile['followers']; } @@ -1172,11 +1172,11 @@ class ActivityPub } foreach ($activity[$element] as $receiver) { - if ($receiver == self::PUBLIC) { + if ($receiver == self::PUBLIC_COLLECTION) { $receivers['uid:0'] = 0; } - if (($receiver == self::PUBLIC) && !empty($actor)) { + if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) { // This will most likely catch all OStatus connections to Mastodon $condition = ['alias' => [$actor, normalise_link($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND] , 'archive' => false, 'pending' => false]; @@ -1189,7 +1189,7 @@ class ActivityPub DBA::close($contacts); } - if (in_array($receiver, [$followers, self::PUBLIC]) && !empty($actor)) { + if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) { $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false]; $contacts = DBA::select('contact', ['uid'], $condition); From 82987d018ae680cd937c5bdf4ffe71143644988d Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 07:21:57 +0000 Subject: [PATCH 81/97] Some changes for better code quality --- src/Model/Item.php | 5 ++--- src/Model/Profile.php | 2 +- src/Model/Term.php | 4 ++-- src/Module/Outbox.php | 4 ++-- src/Module/Owa.php | 2 +- src/Network/Probe.php | 4 +--- src/Protocol/ActivityPub.php | 19 ++++++++----------- 7 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 619f5dc349..2c9be633a9 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1081,9 +1081,8 @@ class Item extends BaseObject DBA::delete('item-delivery-data', ['iid' => $item['id']]); - //if (!empty($item['iaid']) && !self::exists(['iaid' => $item['iaid'], 'deleted' => false])) { - // DBA::delete('item-activity', ['id' => $item['iaid']], ['cascade' => false]); - //} + // We don't delete the item-activity here, since we need some of the data for ActivityPub + if (!empty($item['icid']) && !self::exists(['icid' => $item['icid'], 'deleted' => false])) { DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]); } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index d25bdd4fad..cb2754cc80 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -35,7 +35,7 @@ class Profile * * @return array Profile data */ - public static function getProfileForUser($uid) + public static function getByUID($uid) { $profile = DBA::selectFirst('profile', [], ['uid' => $uid, 'is-default' => true]); return $profile; diff --git a/src/Model/Term.php b/src/Model/Term.php index 2623125329..fb7670a306 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -33,9 +33,9 @@ class Term return $tag_text; } - public static function tagArrayFromItemId($itemid) + public static function tagArrayFromItemId($itemid, $type = [TERM_HASHTAG, TERM_MENTION]) { - $condition = ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]; + $condition = ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => $type]; $tags = DBA::select('term', ['type', 'term', 'url'], $condition); if (!DBA::isResult($tags)) { return []; diff --git a/src/Module/Outbox.php b/src/Module/Outbox.php index 722315145f..8ddc861836 100644 --- a/src/Module/Outbox.php +++ b/src/Module/Outbox.php @@ -29,10 +29,10 @@ class Outbox extends BaseModule $page = defaults($_REQUEST, 'page', null); - $Outbox = ActivityPub::getOutbox($owner, $page); + $outbox = ActivityPub::getOutbox($owner, $page); header('Content-Type: application/activity+json'); - echo json_encode($Outbox); + echo json_encode($outbox); exit(); } } diff --git a/src/Module/Owa.php b/src/Module/Owa.php index 68f31c59de..7a5fe128c8 100644 --- a/src/Module/Owa.php +++ b/src/Module/Owa.php @@ -54,7 +54,7 @@ class Owa extends BaseModule if (DBA::isResult($contact)) { // Try to verify the signed header with the public key of the contact record // we have found. - $verified = HTTPSignature:verifyMagic($contact['pubkey']); + $verified = HTTPSignature::verifyMagic($contact['pubkey']); if ($verified && $verified['header_signed'] && $verified['header_valid']) { logger('OWA header: ' . print_r($verified, true), LOGGER_DATA); diff --git a/src/Network/Probe.php b/src/Network/Probe.php index b19f34b762..2c84ddb85a 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -338,9 +338,7 @@ class Probe $ap_profile = ActivityPub::probeProfile($uri); if (!empty($ap_profile) && (defaults($data, 'network', '') != Protocol::DFRN)) { - if (!empty($ap_profile) && ($ap_profile['network'] == Protocol::ACTIVITYPUB)) { - $data = $ap_profile; - } + $data = $ap_profile; } if (!isset($data["url"])) { diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index a02031f003..58bd9dcfe1 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -113,7 +113,7 @@ class ActivityPub $data['totalItems'] = $count; // When we hide our friends we will only show the pure number but don't allow more. - $profile = Profile::getProfileForUser($owner['uid']); + $profile = Profile::getByUID($owner['uid']); if (!empty($profile['hide-friends'])) { return $data; } @@ -160,7 +160,7 @@ class ActivityPub $data['totalItems'] = $count; // When we hide our friends we will only show the pure number but don't allow more. - $profile = Profile::getProfileForUser($owner['uid']); + $profile = Profile::getByUID($owner['uid']); if (!empty($profile['hide-friends'])) { return $data; } @@ -323,8 +323,7 @@ class ActivityPub $permissions['to'][] = $actor; - $elements = ['to', 'cc', 'bto', 'bcc']; - foreach ($elements as $element) { + foreach (['to', 'cc', 'bto', 'bcc'] as $element) { if (empty($activity[$element])) { continue; } @@ -359,7 +358,7 @@ class ActivityPub $actor_profile = APContact::getProfileByURL($item['author-link']); - $terms = Term::tagArrayFromItemId($item['id']); + $terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION); $contacts[$item['author-link']] = $item['author-link']; @@ -461,8 +460,7 @@ class ActivityPub $item_profile = APContact::getProfileByURL($item['owner-link']); } - $elements = ['to', 'cc', 'bto', 'bcc']; - foreach ($elements as $element) { + foreach (['to', 'cc', 'bto', 'bcc'] as $element) { if (empty($permissions[$element])) { continue; } @@ -624,7 +622,7 @@ class ActivityPub { $tags = []; - $terms = Term::tagArrayFromItemId($item['id']); + $terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION); foreach ($terms as $term) { if ($term['type'] == TERM_MENTION) { $contact = Contact::getDetailsByURL($term['url']); @@ -1160,13 +1158,12 @@ class ActivityPub $followers = ''; } - $elements = ['to', 'cc', 'bto', 'bcc']; - foreach ($elements as $element) { + foreach (['to', 'cc', 'bto', 'bcc'] as $element) { if (empty($activity[$element])) { continue; } - // The receiver can be an arror or a string + // The receiver can be an array or a string if (is_string($activity[$element])) { $activity[$element] = [$activity[$element]]; } From 2fc79e3886af68463a7851e5cad2c0a968d15e73 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 07:48:13 +0000 Subject: [PATCH 82/97] Superfluous, since we only fetch this data --- src/Protocol/ActivityPub.php | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 58bd9dcfe1..c04347f4e9 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -369,9 +369,6 @@ class ActivityPub } foreach ($terms as $term) { - if ($term['type'] != TERM_MENTION) { - continue; - } $profile = APContact::getProfileByURL($term['url'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; @@ -384,9 +381,6 @@ class ActivityPub $mentioned = []; foreach ($terms as $term) { - if ($term['type'] != TERM_MENTION) { - continue; - } $cid = Contact::getIdForURL($term['url'], $item['uid']); if (!empty($cid) && in_array($cid, $receiver_list)) { $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid, 'network' => Protocol::ACTIVITYPUB]); @@ -624,16 +618,14 @@ class ActivityPub $terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION); foreach ($terms as $term) { - if ($term['type'] == TERM_MENTION) { - $contact = Contact::getDetailsByURL($term['url']); - if (!empty($contact['addr'])) { - $mention = '@' . $contact['addr']; - } else { - $mention = '@' . $term['url']; - } - - $tags[] = ['type' => 'Mention', 'href' => $term['url'], 'name' => $mention]; + $contact = Contact::getDetailsByURL($term['url']); + if (!empty($contact['addr'])) { + $mention = '@' . $contact['addr']; + } else { + $mention = '@' . $term['url']; } + + $tags[] = ['type' => 'Mention', 'href' => $term['url'], 'name' => $mention]; } return $tags; } From e71f4972952e61ae06d0e4970c47cee93e8cb8a1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 08:14:05 +0000 Subject: [PATCH 83/97] Renamed --- src/Model/APContact.php | 2 +- src/Protocol/ActivityPub.php | 32 ++++++++++++++++---------------- src/Util/HTTPSignature.php | 4 ++-- src/Util/LDSignature.php | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index c8f8998ae6..efd6ed0e9d 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -63,7 +63,7 @@ class APContact extends BaseObject * @param boolean $update true = always update, false = never update, null = update when not found * @return array profile array */ - public static function getProfileByURL($url, $update = null) + public static function getByURL($url, $update = null) { if (empty($url)) { return false; diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index c04347f4e9..ab5da4666c 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -312,9 +312,9 @@ class ActivityPub $activity = json_decode($conversation['source'], true); $actor = JsonLD::fetchElement($activity, 'actor', 'id'); - $profile = APContact::getProfileByURL($actor); + $profile = APContact::getByURL($actor); - $item_profile = APContact::getProfileByURL($item['author-link']); + $item_profile = APContact::getByURL($item['author-link']); $exclude[] = $item['author-link']; if ($item['gravity'] == GRAVITY_PARENT) { @@ -356,7 +356,7 @@ class ActivityPub $data = array_merge($data, self::fetchPermissionBlockFromConversation($item)); - $actor_profile = APContact::getProfileByURL($item['author-link']); + $actor_profile = APContact::getByURL($item['author-link']); $terms = Term::tagArrayFromItemId($item['id'], TERM_MENTION); @@ -369,7 +369,7 @@ class ActivityPub } foreach ($terms as $term) { - $profile = APContact::getProfileByURL($term['url'], false); + $profile = APContact::getByURL($term['url'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; $contacts[$profile['url']] = $profile['url']; @@ -405,7 +405,7 @@ class ActivityPub continue; } - $profile = APContact::getProfileByURL($parent['author-link'], false); + $profile = APContact::getByURL($parent['author-link'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; $contacts[$profile['url']] = $profile['url']; @@ -415,7 +415,7 @@ class ActivityPub continue; } - $profile = APContact::getProfileByURL($parent['owner-link'], false); + $profile = APContact::getByURL($parent['owner-link'], false); if (!empty($profile) && empty($contacts[$profile['url']])) { $data['cc'][] = $profile['url']; $contacts[$profile['url']] = $profile['url']; @@ -449,9 +449,9 @@ class ActivityPub $inboxes = []; if ($item['gravity'] == GRAVITY_ACTIVITY) { - $item_profile = APContact::getProfileByURL($item['author-link']); + $item_profile = APContact::getByURL($item['author-link']); } else { - $item_profile = APContact::getProfileByURL($item['owner-link']); + $item_profile = APContact::getByURL($item['owner-link']); } foreach (['to', 'cc', 'bto', 'bcc'] as $element) { @@ -470,7 +470,7 @@ class ActivityPub } DBA::close($contacts); } else { - $profile = APContact::getProfileByURL($receiver); + $profile = APContact::getByURL($receiver); if (!empty($profile)) { $target = defaults($profile, 'sharedinbox', $profile['inbox']); $inboxes[$target] = $target; @@ -725,7 +725,7 @@ class ActivityPub */ public static function transmitActivity($activity, $target, $uid) { - $profile = APContact::getProfileByURL($target); + $profile = APContact::getByURL($target); $owner = User::getOwnerDataById($uid); @@ -751,7 +751,7 @@ class ActivityPub */ public static function transmitContactAccept($target, $id, $uid) { - $profile = APContact::getProfileByURL($target); + $profile = APContact::getByURL($target); $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', @@ -778,7 +778,7 @@ class ActivityPub */ public static function transmitContactReject($target, $id, $uid) { - $profile = APContact::getProfileByURL($target); + $profile = APContact::getByURL($target); $owner = User::getOwnerDataById($uid); $data = ['@context' => 'https://www.w3.org/ns/activitystreams', @@ -804,7 +804,7 @@ class ActivityPub */ public static function transmitContactUndo($target, $uid) { - $profile = APContact::getProfileByURL($target); + $profile = APContact::getByURL($target); $id = System::baseUrl() . '/activity/' . System::createGUID(); @@ -847,7 +847,7 @@ class ActivityPub */ public static function probeProfile($url) { - $apcontact = APContact::getProfileByURL($url, true); + $apcontact = APContact::getByURL($url, true); if (empty($apcontact)) { return false; } @@ -1141,7 +1141,7 @@ class ActivityPub } if (!empty($actor)) { - $profile = APContact::getProfileByURL($actor); + $profile = APContact::getByURL($actor); $followers = defaults($profile, 'followers', ''); logger('Actor: ' . $actor . ' - Followers: ' . $followers, LOGGER_DEBUG); @@ -1706,7 +1706,7 @@ class ActivityPub } logger('Updating profile for ' . $activity['object']['id'], LOGGER_DEBUG); - APContact::getProfileByURL($activity['object']['id'], true); + APContact::getByURL($activity['object']['id'], true); } /** diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index c02124874f..234d896078 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -424,12 +424,12 @@ class HTTPSignature { $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id); - $profile = APContact::getProfileByURL($url); + $profile = APContact::getByURL($url); if (!empty($profile)) { logger('Taking key from id ' . $id, LOGGER_DEBUG); return ['url' => $url, 'pubkey' => $profile['pubkey']]; } elseif ($url != $actor) { - $profile = APContact::getProfileByURL($actor); + $profile = APContact::getByURL($actor); if (!empty($profile)) { logger('Taking key from actor ' . $actor, LOGGER_DEBUG); return ['url' => $actor, 'pubkey' => $profile['pubkey']]; diff --git a/src/Util/LDSignature.php b/src/Util/LDSignature.php index ebbffeb1e8..7776ec96c2 100644 --- a/src/Util/LDSignature.php +++ b/src/Util/LDSignature.php @@ -30,7 +30,7 @@ class LDSignature return false; } - $profile = APContact::getProfileByURL($actor); + $profile = APContact::getByURL($actor); if (empty($profile['pubkey'])) { return false; } From cb44aa83c7983996a586994d8b582a4777f4a989 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 12:21:57 +0000 Subject: [PATCH 84/97] Object instead of Display --- index.php | 4 ---- mod/display.php | 8 ++------ src/Module/Object.php | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 src/Module/Object.php diff --git a/index.php b/index.php index a62b7a2ea1..8b0bd47251 100644 --- a/index.php +++ b/index.php @@ -215,10 +215,6 @@ if (strlen($a->module)) { * First see if we have an addon which is masquerading as a module. */ - if ($a->module == 'object') { - $a->module = 'display'; - } - // Compatibility with the Android Diaspora client if ($a->module == 'stream') { goaway('network?f=&order=post'); diff --git a/mod/display.php b/mod/display.php index ff98e689d3..25bda99d01 100644 --- a/mod/display.php +++ b/mod/display.php @@ -78,13 +78,9 @@ function display_init(App $a) } if (ActivityPub::isRequest()) { - $wall_item = Item::selectFirst(['id', 'uid'], ['guid' => $item['guid'], 'wall' => true]); - if (DBA::isResult($wall_item)) { - $data = ActivityPub::createObjectFromItemID($wall_item['id']); - echo json_encode($data); - exit(); - } + goaway(str_replace('display/', 'object/', $a->query_string)); } + if ($item["id"] != $item["parent"]) { $item = Item::selectFirstForUser(local_user(), $fields, ['id' => $item["parent"]]); } diff --git a/src/Module/Object.php b/src/Module/Object.php new file mode 100644 index 0000000000..557b906d2b --- /dev/null +++ b/src/Module/Object.php @@ -0,0 +1,41 @@ +argv[1])) { + System::httpExit(404); + } + + if (!ActivityPub::isRequest()) { + goaway(str_replace('object/', 'display/', $a->query_string)); + } + + $item = Item::selectFirst(['id'], ['guid' => $a->argv[1], 'wall' => true, 'private' => false]); + if (!DBA::isResult($item)) { + System::httpExit(404); + } + + $data = ActivityPub::createObjectFromItemID($item['id']); + + header('Content-Type: application/activity+json'); + echo json_encode($data); + exit(); + } +} From a8b776c189e92034ecd252e71b0fc9e5fa364a13 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 13:15:10 +0000 Subject: [PATCH 85/97] There is now "rawContent" for technical endpoints --- index.php | 10 ++++++++-- src/Module/Followers.php | 2 +- src/Module/Following.php | 2 +- src/Module/Inbox.php | 2 +- src/Module/Object.php | 2 +- src/Module/Outbox.php | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index 8b0bd47251..46b95c75e4 100644 --- a/index.php +++ b/index.php @@ -342,15 +342,21 @@ if ($a->module_loaded) { $a->page['page_title'] = $a->module; $placeholder = ''; + Addon::callHooks($a->module . '_mod_init', $placeholder); + if ($a->module_class) { - Addon::callHooks($a->module . '_mod_init', $placeholder); call_user_func([$a->module_class, 'init']); } else if (function_exists($a->module . '_init')) { - Addon::callHooks($a->module . '_mod_init', $placeholder); $func = $a->module . '_init'; $func($a); } + // "rawContent" is especially meant for technical endpoints. + // This endpoint doesn't need any theme initialization or other comparable stuff. + if (!$a->error && $a->module_class) { + call_user_func([$a->module_class, 'rawContent']); + } + if (function_exists(str_replace('-', '_', $a->getCurrentTheme()) . '_init')) { $func = str_replace('-', '_', $a->getCurrentTheme()) . '_init'; $func($a); diff --git a/src/Module/Followers.php b/src/Module/Followers.php index 80ad68def4..98e9f1e0ee 100644 --- a/src/Module/Followers.php +++ b/src/Module/Followers.php @@ -14,7 +14,7 @@ use Friendica\Model\User; */ class Followers extends BaseModule { - public static function init() + public static function rawContent() { $a = self::getApp(); diff --git a/src/Module/Following.php b/src/Module/Following.php index 091a505cc9..6023db4cbe 100644 --- a/src/Module/Following.php +++ b/src/Module/Following.php @@ -14,7 +14,7 @@ use Friendica\Model\User; */ class Following extends BaseModule { - public static function init() + public static function rawContent() { $a = self::getApp(); diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 4fc450d85a..c97c3b7afb 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -15,7 +15,7 @@ use Friendica\Util\HTTPSignature; */ class Inbox extends BaseModule { - public static function init() + public static function rawContent() { $a = self::getApp(); diff --git a/src/Module/Object.php b/src/Module/Object.php index 557b906d2b..05aae84f86 100644 --- a/src/Module/Object.php +++ b/src/Module/Object.php @@ -15,7 +15,7 @@ use Friendica\Database\DBA; */ class Object extends BaseModule { - public static function init() + public static function rawContent() { $a = self::getApp(); diff --git a/src/Module/Outbox.php b/src/Module/Outbox.php index 8ddc861836..f6bad56dd6 100644 --- a/src/Module/Outbox.php +++ b/src/Module/Outbox.php @@ -14,7 +14,7 @@ use Friendica\Model\User; */ class Outbox extends BaseModule { - public static function init() + public static function rawContent() { $a = self::getApp(); From 761bdafa34bfdf1b2b43a3f06ae092e0925898ac Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 14:13:07 +0000 Subject: [PATCH 86/97] Correct content type --- mod/profile.php | 1 + src/Protocol/ActivityPub.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mod/profile.php b/mod/profile.php index 8df63705e4..e20836a059 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -55,6 +55,7 @@ function profile_init(App $a) if (DBA::isResult($user)) { $data = ActivityPub::profile($user['uid']); echo json_encode($data); + header('Content-Type: application/activity+json'); exit(); } } diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index ab5da4666c..cf9ca3dd43 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -834,8 +834,9 @@ class ActivityPub { $ret = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json, application/ld+json']); if (!$ret['success'] || empty($ret['body'])) { - return; + return false; } + return json_decode($ret['body'], true); } From 5456ef01855f7f6bda4f137980df5a1793712bb1 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 20:26:30 +0000 Subject: [PATCH 87/97] Profile update and some more is now added --- src/Protocol/ActivityPub.php | 209 +++++++++++++++++++++++++++-------- src/Worker/ProfileUpdate.php | 4 +- 2 files changed, 167 insertions(+), 46 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index cf9ca3dd43..6fdd0795a5 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -44,27 +44,25 @@ use Friendica\Core\Config; * To-do: * * Receiver: - * - Update Note - * - Delete Note - * - Delete Person + * - Update (Image, Video, Article, Note) + + - Event * - Undo Announce - * - Reject Follow - * - Undo Accept - * - Undo Follow + * + * Check what this is meant to do: * - Add - * - Create Image - * - Create Video - * - Event - * - Remove * - Block * - Flag + * - Remove + * - Undo Block + * - Undo Accept (Problem: This could invert a contact accept or an event accept) * * Transmitter: + * - Delete (Application, Group, Organization, Person, Service) + * - Event + * + * Complicated: * - Announce * - Undo Announce - * - Update Person - * - Reject Follow - * - Event * * General: * - Attachments @@ -81,7 +79,9 @@ class ActivityPub 'diaspora' => 'https://diasporafoundation.org/ns/', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag']]; - + const ACCOUNT_TYPES = ['Person', 'Organization', 'Service', 'Group', 'Application']; + const CONTENT_TYPES = ['Note', 'Article', 'Video', 'Image']; + const ACTIVITY_TYPES = ['Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept']; /** * @brief Checks if the web request is done for the AP protocol * @@ -243,7 +243,6 @@ class ActivityPub */ public static function profile($uid) { - $accounttype = ['Person', 'Organization', 'Service', 'Group', 'Application']; $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false, 'account_removed' => false, 'verified' => true]; $fields = ['guid', 'nickname', 'pubkey', 'account-type', 'page-flags']; @@ -267,7 +266,7 @@ class ActivityPub $data = ['@context' => self::CONTEXT]; $data['id'] = $contact['url']; $data['diaspora:guid'] = $user['guid']; - $data['type'] = $accounttype[$user['account-type']]; + $data['type'] = self::ACCOUNT_TYPES[$user['account-type']]; $data['following'] = System::baseUrl() . '/following/' . $user['nickname']; $data['followers'] = System::baseUrl() . '/followers/' . $user['nickname']; $data['inbox'] = System::baseUrl() . '/inbox/' . $user['nickname']; @@ -431,6 +430,29 @@ class ActivityPub return $data; } + /** + * @brief Fetches a list of inboxes of followers of a given user + * + * @param integer $uid User ID + * + * @return array of follower inboxes + */ + private static function fetchTargetInboxesforUser($uid) + { + $inboxes = []; + + $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid, + 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB, + 'archive' => false, 'pending' => false]); + while ($contact = DBA::fetch($contacts)) { + $contact = defaults($contact, 'batch', $contact['notify']); + $inboxes[$contact] = $contact; + } + DBA::close($contacts); + + return $inboxes; + } + /** * @brief Fetches an array of inboxes for the given item and user * @@ -461,14 +483,7 @@ class ActivityPub foreach ($permissions[$element] as $receiver) { if ($receiver == $item_profile['followers']) { - $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid, - 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB, - 'archive' => false, 'pending' => false]); - while ($contact = DBA::fetch($contacts)) { - $contact = defaults($contact, 'batch', $contact['notify']); - $inboxes[$contact] = $contact; - } - DBA::close($contacts); + $inboxes = self::fetchTargetInboxesforUser($uid); } else { $profile = APContact::getByURL($receiver); if (!empty($profile)) { @@ -716,6 +731,36 @@ class ActivityPub return $data; } + /** + * @brief Transmits a profile change to the followers + * + * @param integer $uid User ID + */ + public static function transmitProfileUpdate($uid) + { + $owner = User::getOwnerDataById($uid); + $profile = APContact::getByURL($owner['url']); + + $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => System::baseUrl() . '/activity/' . System::createGUID(), + 'type' => 'Update', + 'actor' => $owner['url'], + 'object' => self::profile($uid), + 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), + 'to' => [$profile['followers']], + 'cc' => []]; + + logger('Sending profile update to followers for user ' . $uid, LOGGER_DEBUG); + + $signed = LDSignature::sign($data, $owner); + + $inboxes = self::fetchTargetInboxesforUser($uid); + + foreach ($inboxes as $inbox) { + logger('Deliver profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); + HTTPSignature::transmit($signed, $inbox, $uid); + } + } /** * @brief Transmits a given activity to a target * @@ -1088,12 +1133,19 @@ class ActivityPub break; case 'Update': - if (in_array($object_data['object_type'], ['Person', 'Organization', 'Service', 'Group', 'Application'])) { + if (in_array($object_data['object_type'], self::CONTENT_TYPES)) { + /// @todo + } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) { self::updatePerson($object_data, $body); } break; case 'Delete': + if ($object_data['object_type'] == 'Tombstone') { + self::deleteItem($object_data, $body); + } elseif (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) { + self::deletePerson($object_data, $body); + } break; case 'Follow': @@ -1106,10 +1158,16 @@ class ActivityPub } break; + case 'Reject': + if ($object_data['object_type'] == 'Follow') { + self::rejectFollowUser($object_data); + } + break; + case 'Undo': if ($object_data['object_type'] == 'Follow') { self::undoFollowUser($object_data); - } elseif (in_array($object_data['object_type'], ['Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept'])) { + } elseif (in_array($object_data['object_type'], self::ACTIVITY_TYPES)) { self::undoActivity($object_data); } break; @@ -1324,26 +1382,18 @@ class ActivityPub return false; } - switch ($data['type']) { - case 'Note': - case 'Article': - case 'Video': - return self::processObject($data); - - case 'Announce': - if (empty($data['object'])) { - return false; - } - return self::fetchObject($data['object']); - - case 'Person': - case 'Tombstone': - break; - - default: - logger('Unknown object type: ' . $data['type'], LOGGER_DEBUG); - break; + if (in_array($data['type'], self::CONTENT_TYPES)) { + return self::processObject($data); } + + if ($data['type'] == 'Announce') { + if (empty($data['object'])) { + return false; + } + return self::fetchObject($data['object']); + } + + logger('Unhandled object type: ' . $data['type'], LOGGER_DEBUG); } /** @@ -1548,6 +1598,20 @@ class ActivityPub self::postItem($activity, $item, $body); } + /** + * @brief Delete items + * + * @param array $activity + * @param $body + */ + private static function deleteItem($activity) + { + $owner = Contact::getIdForURL($activity['owner']); + $object = JsonLD::fetchElement($activity, 'object', 'id'); + logger('Deleting item ' . $object . ' from ' . $owner, LOGGER_DEBUG); + Item::delete(['uri' => $object, 'owner-id' => $owner]); + } + /** * @brief * @@ -1710,6 +1774,32 @@ class ActivityPub APContact::getByURL($activity['object']['id'], true); } + /** + * @brief Delete the given profile + * + * @param array $activity + */ + private static function deletePerson($activity) + { + if (empty($activity['object']['id']) || empty($activity['object']['actor'])) { + logger('Empty object id or actor.', LOGGER_DEBUG); + return; + } + + if ($activity['object']['id'] != $activity['object']['actor']) { + logger('Object id does not match actor.', LOGGER_DEBUG); + return; + } + + $contacts = DBA::select('contact', ['id'], ['nurl' => normalise_link($activity['object']['id'])]); + while ($contact = DBA::fetch($contacts)) { + Contact::remove($contact["id"]); + } + DBA::close($contacts); + + logger('Deleted contact ' . $activity['object']['id'], LOGGER_DEBUG); + } + /** * @brief Accept a follow request * @@ -1743,6 +1833,35 @@ class ActivityPub logger('Accept contact request from contact ' . $cid . ' for user ' . $uid, LOGGER_DEBUG); } + /** + * @brief Reject a follow request + * + * @param array $activity + */ + private static function rejectFollowUser($activity) + { + $actor = JsonLD::fetchElement($activity, 'object', 'actor'); + $uid = User::getIdForURL($actor); + if (empty($uid)) { + return; + } + + $owner = User::getOwnerDataById($uid); + + $cid = Contact::getIdForURL($activity['owner'], $uid); + if (empty($cid)) { + logger('No contact found for ' . $activity['owner'], LOGGER_DEBUG); + return; + } + + if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING, 'pending' => true])) { + Contact::remove($cid); + logger('Rejected contact request from contact ' . $cid . ' for user ' . $uid . ' - contact had been removed.', LOGGER_DEBUG); + } else { + logger('Rejected contact request from contact ' . $cid . ' for user ' . $uid . '.', LOGGER_DEBUG); + } + } + /** * @brief Undo activity like "like" or "dislike" * diff --git a/src/Worker/ProfileUpdate.php b/src/Worker/ProfileUpdate.php index e33aa5d9a8..9123f77e06 100644 --- a/src/Worker/ProfileUpdate.php +++ b/src/Worker/ProfileUpdate.php @@ -1,12 +1,13 @@ Date: Sun, 30 Sep 2018 20:40:40 +0000 Subject: [PATCH 88/97] Avoiding a notice --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 46b95c75e4..f535bcc0d1 100644 --- a/index.php +++ b/index.php @@ -353,7 +353,7 @@ if ($a->module_loaded) { // "rawContent" is especially meant for technical endpoints. // This endpoint doesn't need any theme initialization or other comparable stuff. - if (!$a->error && $a->module_class) { + if (!$a->error && $a->module_class && method_exists($a->module_class, 'rawContent')) { call_user_func([$a->module_class, 'rawContent']); } From fdc396e197be0f9bd42bd1919a3dd9d157b27386 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 20:47:28 +0000 Subject: [PATCH 89/97] "rawcontent" is now a baseobject method --- index.php | 2 +- src/BaseModule.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index f535bcc0d1..46b95c75e4 100644 --- a/index.php +++ b/index.php @@ -353,7 +353,7 @@ if ($a->module_loaded) { // "rawContent" is especially meant for technical endpoints. // This endpoint doesn't need any theme initialization or other comparable stuff. - if (!$a->error && $a->module_class && method_exists($a->module_class, 'rawContent')) { + if (!$a->error && $a->module_class) { call_user_func([$a->module_class, 'rawContent']); } diff --git a/src/BaseModule.php b/src/BaseModule.php index 3ad4a4f055..1da9397a78 100644 --- a/src/BaseModule.php +++ b/src/BaseModule.php @@ -21,7 +21,16 @@ abstract class BaseModule extends BaseObject */ public static function init() { + } + /** + * @brief Module GET method to display raw content from technical endpoints + * + * Extend this method if the module is supposed to return communication data, + * e.g. from protocol implementations. + */ + public static function rawContent() + { } /** From 9f481c1f5e427645d96deb4153db2ae4ba77f2b6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 20:48:29 +0000 Subject: [PATCH 90/97] + is * --- src/Protocol/ActivityPub.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 6fdd0795a5..5bad98eb4c 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -45,7 +45,7 @@ use Friendica\Core\Config; * * Receiver: * - Update (Image, Video, Article, Note) - + - Event + * - Event * - Undo Announce * * Check what this is meant to do: From 93ccca58074ed79954f428fb5cf67df379f9e691 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Sep 2018 21:23:40 +0000 Subject: [PATCH 91/97] AP hast to be enabled here as well --- mod/item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/item.php b/mod/item.php index 20c0aaf747..d73bbc25d9 100644 --- a/mod/item.php +++ b/mod/item.php @@ -159,7 +159,7 @@ function item_post(App $a) { } // Allow commenting if it is an answer to a public post - $allow_comment = local_user() && ($profile_uid == 0) && $parent && in_array($parent_item['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]); + $allow_comment = local_user() && ($profile_uid == 0) && $parent && in_array($parent_item['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]); // Now check that valid personal details have been provided if (!can_write_wall($profile_uid) && !$allow_comment) { From 72c3a62e7f1ba5679b6503d760409d5345f5a4de Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 1 Oct 2018 05:44:56 +0000 Subject: [PATCH 92/97] Profile update is now done via APDelivery --- src/Protocol/ActivityPub.php | 20 ++++++++------------ src/Worker/APDelivery.php | 2 ++ src/Worker/Delivery.php | 15 ++++++++------- src/Worker/ProfileUpdate.php | 13 ++++++++++++- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 5bad98eb4c..4c77c8dff9 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -437,7 +437,7 @@ class ActivityPub * * @return array of follower inboxes */ - private static function fetchTargetInboxesforUser($uid) + public static function fetchTargetInboxesforUser($uid) { $inboxes = []; @@ -732,11 +732,12 @@ class ActivityPub } /** - * @brief Transmits a profile change to the followers + * @brief Transmits a profile change to a given inbox * * @param integer $uid User ID + * @param string $inbox Target inbox */ - public static function transmitProfileUpdate($uid) + public static function transmitProfileUpdate($uid, $inbox) { $owner = User::getOwnerDataById($uid); $profile = APContact::getByURL($owner['url']); @@ -750,17 +751,12 @@ class ActivityPub 'to' => [$profile['followers']], 'cc' => []]; - logger('Sending profile update to followers for user ' . $uid, LOGGER_DEBUG); - $signed = LDSignature::sign($data, $owner); - $inboxes = self::fetchTargetInboxesforUser($uid); - - foreach ($inboxes as $inbox) { - logger('Deliver profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); - HTTPSignature::transmit($signed, $inbox, $uid); - } + logger('Deliver profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); + HTTPSignature::transmit($signed, $inbox, $uid); } + /** * @brief Transmits a given activity to a target * @@ -1403,7 +1399,7 @@ class ActivityPub * * @return */ - private static function processObject(&$object) + private static function processObject($object) { if (empty($object['id'])) { return false; diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 943238a7b4..eb0b3d9b15 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -18,6 +18,8 @@ class APDelivery extends BaseObject if ($cmd == Delivery::MAIL) { } elseif ($cmd == Delivery::SUGGESTION) { } elseif ($cmd == Delivery::RELOCATION) { + } elseif ($cmd == Delivery::PROFILEUPDATE) { + ActivityPub::transmitProfileUpdate($uid, $inbox); } else { $data = ActivityPub::createActivityFromItem($item_id); if (!empty($data)) { diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 3a93d92f7b..3585b39989 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -22,13 +22,14 @@ require_once 'include/items.php'; class Delivery extends BaseObject { - const MAIL = 'mail'; - const SUGGESTION = 'suggest'; - const RELOCATION = 'relocate'; - const DELETION = 'drop'; - const POST = 'wall-new'; - const COMMENT = 'comment-new'; - const REMOVAL = 'removeme'; + const MAIL = 'mail'; + const SUGGESTION = 'suggest'; + const RELOCATION = 'relocate'; + const DELETION = 'drop'; + const POST = 'wall-new'; + const COMMENT = 'comment-new'; + const REMOVAL = 'removeme'; + const PROFILEUPDATE = 'profileupdate'; public static function execute($cmd, $item_id, $contact_id) { diff --git a/src/Worker/ProfileUpdate.php b/src/Worker/ProfileUpdate.php index 9123f77e06..7fab86cbfd 100644 --- a/src/Worker/ProfileUpdate.php +++ b/src/Worker/ProfileUpdate.php @@ -6,8 +6,10 @@ namespace Friendica\Worker; +use Friendica\BaseObject; use Friendica\Protocol\Diaspora; use Friendica\Protocol\ActivityPub; +use Friendica\Core\Worker; class ProfileUpdate { public static function execute($uid = 0) { @@ -15,7 +17,16 @@ class ProfileUpdate { return; } - ActivityPub::transmitProfileUpdate($uid); + $a = BaseObject::getApp(); + + $inboxes = ActivityPub::fetchTargetInboxesforUser($uid); + + foreach ($inboxes as $inbox) { + logger('Profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); + Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true], + 'APDelivery', Delivery::PROFILEUPDATE, '', $inbox, $uid); + } + Diaspora::sendProfile($uid); } } From 6020605d5c0cedfe96a7ccc8087887e4d362db1e Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 1 Oct 2018 19:22:13 +0000 Subject: [PATCH 93/97] Account deletion could work now. --- src/Protocol/ActivityPub.php | 37 ++++++++++++++++++++++++++++++++---- src/Worker/APDelivery.php | 2 ++ src/Worker/Notifier.php | 8 ++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 4c77c8dff9..b5cd102a51 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -57,7 +57,6 @@ use Friendica\Core\Config; * - Undo Accept (Problem: This could invert a contact accept or an event accept) * * Transmitter: - * - Delete (Application, Group, Organization, Person, Service) * - Event * * Complicated: @@ -441,9 +440,13 @@ class ActivityPub { $inboxes = []; - $contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid, - 'rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::ACTIVITYPUB, - 'archive' => false, 'pending' => false]); + $condition = ['uid' => $uid, 'network' => Protocol::ACTIVITYPUB, 'archive' => false, 'pending' => false]; + + if (!empty($uid)) { + $condition['rel'] = [Contact::FOLLOWER, Contact::FRIEND]; + } + + $contacts = DBA::select('contact', ['notify', 'batch'], $condition); while ($contact = DBA::fetch($contacts)) { $contact = defaults($contact, 'batch', $contact['notify']); $inboxes[$contact] = $contact; @@ -731,6 +734,32 @@ class ActivityPub return $data; } + /** + * @brief Transmits a profile deletion to a given inbox + * + * @param integer $uid User ID + * @param string $inbox Target inbox + */ + public static function transmitProfileDeletion($uid, $inbox) + { + $owner = User::getOwnerDataById($uid); + $profile = APContact::getByURL($owner['url']); + + $data = ['@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => System::baseUrl() . '/activity/' . System::createGUID(), + 'type' => 'Delete', + 'actor' => $owner['url'], + 'object' => self::profile($uid), + 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), + 'to' => [self::PUBLIC_COLLECTION], + 'cc' => []]; + + $signed = LDSignature::sign($data, $owner); + + logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); + HTTPSignature::transmit($signed, $inbox, $uid); + } + /** * @brief Transmits a profile change to a given inbox * diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index eb0b3d9b15..22b8c8f0ff 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -18,6 +18,8 @@ class APDelivery extends BaseObject if ($cmd == Delivery::MAIL) { } elseif ($cmd == Delivery::SUGGESTION) { } elseif ($cmd == Delivery::RELOCATION) { + } elseif ($cmd == Delivery::REMOVAL) { + ActivityPub::transmitProfileDeletion($uid, $inbox); } elseif ($cmd == Delivery::PROFILEUPDATE) { ActivityPub::transmitProfileUpdate($uid, $inbox); } else { diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index b457b78008..3ab238422a 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -99,6 +99,14 @@ class Notifier foreach ($r as $contact) { Contact::terminateFriendship($user, $contact, true); } + + $inboxes = ActivityPub::fetchTargetInboxesforUser(0); + foreach ($inboxes as $inbox) { + logger('Account removal for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); + Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true], + 'APDelivery', Delivery::REMOVAL, '', $inbox, $uid); + } + return; } elseif ($cmd == Delivery::RELOCATION) { $normal_mode = false; From 7e9499ac132629e9cfa101c1829f8ee9cbb063c0 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 1 Oct 2018 21:09:08 +0000 Subject: [PATCH 94/97] AP contacts are now tagged upon commenting --- mod/item.php | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/mod/item.php b/mod/item.php index d73bbc25d9..5a0658b020 100644 --- a/mod/item.php +++ b/mod/item.php @@ -343,20 +343,11 @@ function item_post(App $a) { $tags = get_tags($body); - // Add a tag if the parent contact is from OStatus (This will notify them during delivery) - if ($parent) { - if ($thr_parent_contact['network'] == Protocol::OSTATUS) { - $contact = '@[url=' . $thr_parent_contact['url'] . ']' . $thr_parent_contact['nick'] . '[/url]'; - if (!stripos(implode($tags), '[url=' . $thr_parent_contact['url'] . ']')) { - $tags[] = $contact; - } - } - - if ($parent_contact['network'] == Protocol::OSTATUS) { - $contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]'; - if (!stripos(implode($tags), '[url=' . $parent_contact['url'] . ']')) { - $tags[] = $contact; - } + // Add a tag if the parent contact is from ActivityPub or OStatus (This will notify them) + if ($parent && in_array($thr_parent_contact['network'], [Protocol::OSTATUS, Protocol::ACTIVITYPUB])) { + $contact = '@[url=' . $thr_parent_contact['url'] . ']' . $thr_parent_contact['nick'] . '[/url]'; + if (!stripos(implode($tags), '[url=' . $thr_parent_contact['url'] . ']')) { + $tags[] = $contact; } } @@ -1026,8 +1017,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n $alias = $contact["alias"]; $newname = $contact["nick"]; - if (($newname == "") || (($contact["network"] != Protocol::OSTATUS) && ($contact["network"] != Protocol::TWITTER) - && ($contact["network"] != Protocol::STATUSNET))) { + if (($newname == "") || !in_array($contact["network"], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::TWITTER, Protocol::STATUSNET])) { $newname = $contact["name"]; } } From d4f6261b8177d22e7bac1d7fdda24d73a360a74a Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 Oct 2018 08:31:58 +0000 Subject: [PATCH 95/97] Avoid notice --- src/Util/JsonLD.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 2b6fac4ad4..ddf8d93533 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -64,6 +64,7 @@ class JsonLD $normalized = jsonld_normalize($jsonobj, array('algorithm' => 'URDNA2015', 'format' => 'application/nquads')); } catch (Exception $e) { + $normalized = false; logger('normalise error:' . print_r($e, true), LOGGER_DEBUG); } From fcfd04bcc9813e3bb59fa73765f1687cfa2bb978 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 Oct 2018 09:04:32 +0000 Subject: [PATCH 96/97] Normalize the mentions and ensure to not have duplicates --- src/Model/Term.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Model/Term.php b/src/Model/Term.php index fb7670a306..6042091c9b 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -130,12 +130,26 @@ class Term $term = substr($tag, 1); } elseif (substr(trim($tag), 0, 1) == '@') { $type = TERM_MENTION; - $term = substr($tag, 1); + + $contact = Contact::getDetailsByURL($link, 0); + if (!empty($contact['name'])) { + $term = $contact['name']; + } else { + $term = substr($tag, 1); + } + + if (!empty($contact['url'])) { + $link = $contact['url']; + } } else { // This shouldn't happen $type = TERM_HASHTAG; $term = $tag; } + if (DBA::exists('term', ['uid' => $message['uid'], 'otype' => TERM_OBJ_POST, 'oid' => $itemid, 'url' => $link])) { + continue; + } + if ($message['uid'] == 0) { $global = true; DBA::update('term', ['global' => true], ['otype' => TERM_OBJ_POST, 'guid' => $message['guid']]); From 3020b0fdc4f4ccdfc1deccc23b8748066a7c9979 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 2 Oct 2018 14:48:57 +0000 Subject: [PATCH 97/97] Fix missing mentions --- src/Model/Term.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Model/Term.php b/src/Model/Term.php index 6042091c9b..854861ccb5 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -110,6 +110,18 @@ class Term $pattern = '/\W([\#@])\[url\=(.*?)\](.*?)\[\/url\]/ism'; if (preg_match_all($pattern, $data, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { + + if ($match[1] == '@') { + $contact = Contact::getDetailsByURL($match[2], 0); + if (!empty($contact['addr'])) { + $match[3] = $contact['addr']; + } + + if (!empty($contact['url'])) { + $match[2] = $contact['url']; + } + } + $tags[$match[1] . trim($match[3], ',.:;[]/\"?!')] = $match[2]; } } @@ -137,10 +149,6 @@ class Term } else { $term = substr($tag, 1); } - - if (!empty($contact['url'])) { - $link = $contact['url']; - } } else { // This shouldn't happen $type = TERM_HASHTAG; $term = $tag;