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');
$apArticle = new \Federator\Data\ActivityPub\Common\Article(); switch ($activity['type']) {
if (array_key_exists('tags', $article)) { case 'Article':
foreach ($article['tags'] as $tag) { $create->setURL('https://'.$host . '/' . $activity['language'] . '/' . $userId . '/'
$href = 'https://' . $host . '/' . $article['language'] . $activity['name']);
. '/search.htm?tagsearch=' . urlencode($tag); $apArticle = new \Federator\Data\ActivityPub\Common\Article();
$tagObj = new \Federator\Data\ActivityPub\Common\Tag(); if (array_key_exists('tags', $activity)) {
$tagObj->setHref($href) foreach ($activity['tags'] as $tag) {
->setName('#' . urlencode(str_replace(' ', '', $tag))) $href = 'https://' . $host . '/' . $activity['language']
->setType('Hashtag'); . '/search.htm?tagsearch=' . urlencode($tag);
$article->addTag($tagObj); $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; return $posts;