diff --git a/lang/federator/de/vote.inc b/lang/federator/de/vote.inc new file mode 100644 index 0000000..976468e --- /dev/null +++ b/lang/federator/de/vote.inc @@ -0,0 +1,12 @@ + '$0 hat ein Like gegeben.', + 'dislike' => '$0 hat ein Dislike gegeben.', +]; diff --git a/lang/federator/en/article.inc b/lang/federator/en/article.inc index 6b63d4b..0067dc1 100644 --- a/lang/federator/en/article.inc +++ b/lang/federator/en/article.inc @@ -8,5 +8,5 @@ $l = [ 'image' => 'article image', - 'newarticle' => 'A new Artikel was published', + 'newarticle' => 'A new article was published', ]; diff --git a/lang/federator/en/vote.inc b/lang/federator/en/vote.inc new file mode 100644 index 0000000..486c640 --- /dev/null +++ b/lang/federator/en/vote.inc @@ -0,0 +1,12 @@ + '$0 gave a like.', + 'dislike' => '$0 gave a dislike.', +]; diff --git a/php/federator/data/activitypub/common/activity.php b/php/federator/data/activitypub/common/activity.php index 9137d6c..b1ce4a4 100644 --- a/php/federator/data/activitypub/common/activity.php +++ b/php/federator/data/activitypub/common/activity.php @@ -14,9 +14,16 @@ class Activity extends APObject /** * actor * - * @var string $actor + * @var APObject $actor */ - private $actor = ''; + private $actor = null; + + /** + * aactor + * + * @var string $aactor + */ + private $aactor = ''; /** * constructor @@ -36,13 +43,25 @@ class Activity extends APObject */ public function setAActor(string $actor) { - $this->actor = $actor; + $this->aactor = $actor; return $this; } public function getAActor() : string { - return $this->actor; + return $this->aactor; + } + + /** + * set actor + * + * @param APObject $actor new actor + * @return Activity + */ + public function setActor($actor) + { + $this->actor = $actor; + return $this; } /** @@ -71,9 +90,12 @@ class Activity extends APObject public function toObject() { $return = parent::toObject(); - if ($this->actor !== '') { + if ($this->actor !== null) { $return['actor'] = $this->actor; } + if ($this->aactor !== '') { + $return['actor'] = $this->aactor; + } return $return; } diff --git a/plugins/federator/contentnation.php b/plugins/federator/contentnation.php index 6ce0383..3b871de 100644 --- a/plugins/federator/contentnation.php +++ b/plugins/federator/contentnation.php @@ -76,60 +76,114 @@ class ContentNation implements Connector return false; } $posts = []; - if (array_key_exists('articles', $r)) { - $articles = $r['articles']; + if (array_key_exists('activities', $r)) { + $activities = $r['activities']; $host = $_SERVER['SERVER_NAME']; $imgpath = $this->config['userdata']['path']; $userdata = $this->config['userdata']['url']; - foreach ($articles as $article) { + foreach ($activities as $activity) { $create = new \Federator\Data\ActivityPub\Common\Create(); - $create->setAActor('https://' . $host .'/' . $article['profilename']); - $create->setID($article['id']) - ->setURL('https://'.$host.'/' . $article['profilename'] - . '/statuses/' . $article['id'] . '/activity') - ->setPublished(max($article['published'], $article['modified'])) + $create->setAActor('https://' . $host .'/' . $userId); + $create->setID($activity['id']) + ->setPublished($activity['timestamp']) ->addTo("https://www.w3.org/ns/activitystreams#Public") - ->addCC('https://' . $host . '/' . $article['profilename'] . '/followers.json'); - $apArticle = new \Federator\Data\ActivityPub\Common\Article(); - if (array_key_exists('tags', $article)) { - foreach ($article['tags'] as $tag) { - $href = 'https://' . $host . '/' . $article['language'] - . '/search.htm?tagsearch=' . urlencode($tag); - $tagObj = new \Federator\Data\ActivityPub\Common\Tag(); - $tagObj->setHref($href) - ->setName('#' . urlencode(str_replace(' ', '', $tag))) - ->setType('Hashtag'); - $article->addTag($tagObj); - } + ->addCC('https://' . $host . '/' . $userId . '/followers.json'); + switch ($activity['type']) { + case 'Article': + $create->setURL('https://'.$host . '/' . $activity['language'] . '/' . $userId . '/' + . $activity['name']); + $apArticle = new \Federator\Data\ActivityPub\Common\Article(); + if (array_key_exists('tags', $activity)) { + foreach ($activity['tags'] as $tag) { + $href = 'https://' . $host . '/' . $activity['language'] + . '/search.htm?tagsearch=' . urlencode($tag); + $tagObj = new \Federator\Data\ActivityPub\Common\Tag(); + $tagObj->setHref($href) + ->setName('#' . urlencode(str_replace(' ', '', $tag))) + ->setType('Hashtag'); + $apArticle->addTag($tagObj); + } + } + $apArticle->setPublished($activity['published']) + ->setName($activity['title']) + ->setAttributedTo('https://' . $host .'/' . $activity['profilename']) + ->setContent( + $activity['teaser'] ?? + $this->main->translate( + $activity['language'], + 'article', + 'newarticle' + ) + ) + ->addTo("https://www.w3.org/ns/activitystreams#Public") + ->addCC('https://' . $host . '/' . $userId . '/followers.json'); + $articleimage = $activity['imagealt'] ?? + $this->main->translate($activity['language'], 'article', 'image'); + $idurl = 'https://' . $host . '/' . $activity['language'] + . '/' . $userId . '/'. $activity['name']; + $apArticle->setID($idurl) + ->setURL($idurl); + $image = $activity['image'] ?? $activity['profileimg']; + $mediaType = @mime_content_type($imgpath . $activity['profile'] . '/' . $image) | 'text/plain'; + $img = new \Federator\Data\ActivityPub\Common\Image(); + $img->setMediaType($mediaType) + ->setName($articleimage) + ->setURL($userdata . '/' . $activity['profile'] . $image); + $apArticle->addImage($img); + $create->setObject($apArticle); + $posts[] = $create; + break; // Article + case 'Comment': +// echo "comment\n"; +// print_r($activity); + break; // Comment + case 'Vote': + $url = 'https://'.$host . '/' . $activity['articlelang'] . $userId . '/' + . $activity['articlename']; + $url .= '/vote/' . $activity['id']; + $create->setURL($url); + if ($activity['upvote'] === true) { + $like = new \Federator\Data\ActivityPub\Common\Activity('Like'); + $like->setSummary( + $this->main->translate( + $activity['articlelang'], + 'vote', + 'like', + [$activity['username']] + ) + ); + } else { + $like = new \Federator\Data\ActivityPub\Common\Activity('Dislike'); + $like->setSummary( + $this->main->translate( + $activity['articlelang'], + 'vote', + 'dislike', + [$activity['username']] + ) + ); + } + $actor = new \Federator\Data\ActivityPub\Common\APObject('Person'); + $actor->setName($activity['username']); + $like->setActor($actor); + $url = 'https://' . $host . '/' . $activity['articlelang'] + . '/' . $userId . '/'. $activity['articlename']; + if ($activity['comment'] !== '') { + $url .= '/comment/' . $activity['comment']; + } + $type = 'Article'; + switch ($activity['votetype']) { + case 'comment': + $type = 'Comment'; + break; + } + $object = new \Federator\Data\ActivityPub\Common\APObject($type); + $object->setHref($url); + $like->setObject($object); + $create->setObject($like); + $posts[] = $create; + break; // Vote } - $apArticle->setPublished($article['published']) - ->setName($article['title']) - ->setAttributedTo('https://' . $host .'/' . $article['profilename']) - ->setContent( - $article['teaser'] ?? - $this->main->translate( - $article['language'], - 'article', - 'newarticle' - ) - ) - ->addTo("https://www.w3.org/ns/activitystreams#Public") - ->addCC('https://' . $host . '/' . $article['profilename'] . '/followers.json'); - $articleimage = $article['imagealt'] ?? - $this->main->translate($article['language'], 'article', 'image'); - $idurl = 'https://' . $host . '/' . $article['language'] - . '/' . $article['profilename'] . '/'. $article['name']; - $apArticle->setID($idurl) - ->setURL($idurl); - $image = $article['image'] !== "" ? $article['image'] : $article['profileimg']; - $mediaType = @mime_content_type($imgpath . $article['profile'] . '/' . $image) | 'text/plain'; - $img = new \Federator\Data\ActivityPub\Common\Image(); - $img->setMediaType($mediaType) - ->setName($articleimage) - ->setURL($userdata . $article['profile'] . '/' . $image); - $apArticle->addImage($img); - $create->setObject($apArticle); - $posts[] = $create; } } return $posts;