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 = [
'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
*
* @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;
}

View File

@ -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');
->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', $article)) {
foreach ($article['tags'] as $tag) {
$href = 'https://' . $host . '/' . $article['language']
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');
$article->addTag($tagObj);
$apArticle->addTag($tagObj);
}
}
$apArticle->setPublished($article['published'])
->setName($article['title'])
->setAttributedTo('https://' . $host .'/' . $article['profilename'])
$apArticle->setPublished($activity['published'])
->setName($activity['title'])
->setAttributedTo('https://' . $host .'/' . $activity['profilename'])
->setContent(
$article['teaser'] ??
$activity['teaser'] ??
$this->main->translate(
$article['language'],
$activity['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'];
->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 = $article['image'] !== "" ? $article['image'] : $article['profileimg'];
$mediaType = @mime_content_type($imgpath . $article['profile'] . '/' . $image) | 'text/plain';
$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 . $article['profile'] . '/' . $image);
->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
}
}
}
return $posts;