outobx WIP, almost complete

develop
Sascha Nitsch 2024-08-03 19:55:50 +02:00
parent d208afe899
commit a79209fbd4
5 changed files with 154 additions and 54 deletions

View File

@ -0,0 +1,12 @@
<?php
/**
* SPDX-FileCopyrightText: 2024 Sascha Nitsch (grumpydeveloper) https://contentnation.net/@grumpydevelop
* SPDX-License-Identifier: GPL-3.0-or-later
*
* @author Sascha Nitsch (grumpydeveloper)
**/
$l = [
'like' => '$0 hat ein Like gegeben.',
'dislike' => '$0 hat ein Dislike gegeben.',
];

View File

@ -8,5 +8,5 @@
$l = [ $l = [
'image' => 'article image', 'image' => 'article image',
'newarticle' => 'A new Artikel was published', 'newarticle' => 'A new article was published',
]; ];

View File

@ -0,0 +1,12 @@
<?php
/**
* SPDX-FileCopyrightText: 2024 Sascha Nitsch (grumpydeveloper) https://contentnation.net/@grumpydevelop
* SPDX-License-Identifier: GPL-3.0-or-later
*
* @author Sascha Nitsch (grumpydeveloper)
**/
$l = [
'like' => '$0 gave a like.',
'dislike' => '$0 gave a dislike.',
];

View File

@ -14,9 +14,16 @@ class Activity extends APObject
/** /**
* actor * actor
* *
* @var string $actor * @var APObject $actor
*/ */
private $actor = ''; private $actor = null;
/**
* aactor
*
* @var string $aactor
*/
private $aactor = '';
/** /**
* constructor * constructor
@ -36,13 +43,25 @@ class Activity extends APObject
*/ */
public function setAActor(string $actor) public function setAActor(string $actor)
{ {
$this->actor = $actor; $this->aactor = $actor;
return $this; return $this;
} }
public function getAActor() : string 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() public function toObject()
{ {
$return = parent::toObject(); $return = parent::toObject();
if ($this->actor !== '') { if ($this->actor !== null) {
$return['actor'] = $this->actor; $return['actor'] = $this->actor;
} }
if ($this->aactor !== '') {
$return['actor'] = $this->aactor;
}
return $return; return $return;
} }

View File

@ -76,60 +76,114 @@ class ContentNation implements Connector
return false; return false;
} }
$posts = []; $posts = [];
if (array_key_exists('articles', $r)) { if (array_key_exists('activities', $r)) {
$articles = $r['articles']; $activities = $r['activities'];
$host = $_SERVER['SERVER_NAME']; $host = $_SERVER['SERVER_NAME'];
$imgpath = $this->config['userdata']['path']; $imgpath = $this->config['userdata']['path'];
$userdata = $this->config['userdata']['url']; $userdata = $this->config['userdata']['url'];
foreach ($articles as $article) { foreach ($activities as $activity) {
$create = new \Federator\Data\ActivityPub\Common\Create(); $create = new \Federator\Data\ActivityPub\Common\Create();
$create->setAActor('https://' . $host .'/' . $article['profilename']); $create->setAActor('https://' . $host .'/' . $userId);
$create->setID($article['id']) $create->setID($activity['id'])
->setURL('https://'.$host.'/' . $article['profilename'] ->setPublished($activity['timestamp'])
. '/statuses/' . $article['id'] . '/activity')
->setPublished(max($article['published'], $article['modified']))
->addTo("https://www.w3.org/ns/activitystreams#Public") ->addTo("https://www.w3.org/ns/activitystreams#Public")
->addCC('https://' . $host . '/' . $article['profilename'] . '/followers.json'); ->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(); $apArticle = new \Federator\Data\ActivityPub\Common\Article();
if (array_key_exists('tags', $article)) { if (array_key_exists('tags', $activity)) {
foreach ($article['tags'] as $tag) { foreach ($activity['tags'] as $tag) {
$href = 'https://' . $host . '/' . $article['language'] $href = 'https://' . $host . '/' . $activity['language']
. '/search.htm?tagsearch=' . urlencode($tag); . '/search.htm?tagsearch=' . urlencode($tag);
$tagObj = new \Federator\Data\ActivityPub\Common\Tag(); $tagObj = new \Federator\Data\ActivityPub\Common\Tag();
$tagObj->setHref($href) $tagObj->setHref($href)
->setName('#' . urlencode(str_replace(' ', '', $tag))) ->setName('#' . urlencode(str_replace(' ', '', $tag)))
->setType('Hashtag'); ->setType('Hashtag');
$article->addTag($tagObj); $apArticle->addTag($tagObj);
} }
} }
$apArticle->setPublished($article['published']) $apArticle->setPublished($activity['published'])
->setName($article['title']) ->setName($activity['title'])
->setAttributedTo('https://' . $host .'/' . $article['profilename']) ->setAttributedTo('https://' . $host .'/' . $activity['profilename'])
->setContent( ->setContent(
$article['teaser'] ?? $activity['teaser'] ??
$this->main->translate( $this->main->translate(
$article['language'], $activity['language'],
'article', 'article',
'newarticle' 'newarticle'
) )
) )
->addTo("https://www.w3.org/ns/activitystreams#Public") ->addTo("https://www.w3.org/ns/activitystreams#Public")
->addCC('https://' . $host . '/' . $article['profilename'] . '/followers.json'); ->addCC('https://' . $host . '/' . $userId . '/followers.json');
$articleimage = $article['imagealt'] ?? $articleimage = $activity['imagealt'] ??
$this->main->translate($article['language'], 'article', 'image'); $this->main->translate($activity['language'], 'article', 'image');
$idurl = 'https://' . $host . '/' . $article['language'] $idurl = 'https://' . $host . '/' . $activity['language']
. '/' . $article['profilename'] . '/'. $article['name']; . '/' . $userId . '/'. $activity['name'];
$apArticle->setID($idurl) $apArticle->setID($idurl)
->setURL($idurl); ->setURL($idurl);
$image = $article['image'] !== "" ? $article['image'] : $article['profileimg']; $image = $activity['image'] ?? $activity['profileimg'];
$mediaType = @mime_content_type($imgpath . $article['profile'] . '/' . $image) | 'text/plain'; $mediaType = @mime_content_type($imgpath . $activity['profile'] . '/' . $image) | 'text/plain';
$img = new \Federator\Data\ActivityPub\Common\Image(); $img = new \Federator\Data\ActivityPub\Common\Image();
$img->setMediaType($mediaType) $img->setMediaType($mediaType)
->setName($articleimage) ->setName($articleimage)
->setURL($userdata . $article['profile'] . '/' . $image); ->setURL($userdata . '/' . $activity['profile'] . $image);
$apArticle->addImage($img); $apArticle->addImage($img);
$create->setObject($apArticle); $create->setObject($apArticle);
$posts[] = $create; $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
}
} }
} }
return $posts; return $posts;