forked from grumpydevelop/federator
		
	outobx WIP, almost complete
This commit is contained in:
		
							parent
							
								
									d208afe899
								
							
						
					
					
						commit
						a79209fbd4
					
				
					 5 changed files with 154 additions and 54 deletions
				
			
		
							
								
								
									
										12
									
								
								lang/federator/de/vote.inc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								lang/federator/de/vote.inc
									
										
									
									
									
										Normal 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.',
 | 
			
		||||
];
 | 
			
		||||
| 
						 | 
				
			
			@ -8,5 +8,5 @@
 | 
			
		|||
 | 
			
		||||
$l = [
 | 
			
		||||
    'image' => 'article image',
 | 
			
		||||
    'newarticle' => 'A new Artikel was published',
 | 
			
		||||
    'newarticle' => 'A new article was published',
 | 
			
		||||
];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										12
									
								
								lang/federator/en/vote.inc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								lang/federator/en/vote.inc
									
										
									
									
									
										Normal 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.',
 | 
			
		||||
];
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue