Initial version for TYPO3 GitHub feed

This commit is contained in:
Daniel Siepmann 2023-02-16 08:33:59 +01:00
parent 37e34d9d58
commit 98f2b208d6
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
11 changed files with 1922 additions and 3 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/vendor/

View file

@ -1,3 +0,0 @@
# fediverse-feed-wrappers
I'll mirror some feeds (Atom/RSS) into Fediverse via friendica. Some feeds don't deliver content as expected and will be adjusted.

17
README.rst Normal file
View file

@ -0,0 +1,17 @@
Fediverse Feed Wrappers
=======================
I'll mirror some feeds (Atom/RSS) into Fediverse via Friendi.ca.
Some feeds don't deliver content as expected and will be adjusted.
This is a small set of PHP files, one for each Feed.
Each will adjust the Feed and can be used as a wrapper.
Friendi.ca will import the wrapped feeds.
GitHub
======
GitHub provides a feed for all commits.
I mirror the commits for TYPO3 CMS main branch as this helps to keep up to date.
But GitHub adds the whole commit message, which is way too much for a social media feed.
We therefore shorten the feed content.

23
composer.json Normal file
View file

@ -0,0 +1,23 @@
{
"name": "danielsiepmann/fediverse-feed-wrappers",
"description": "Wraps existing feeds and modifies them for mirroring into fediverse.",
"type": "project",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Daniel Siepmann",
"email": "coding@daniel-siepmann.de"
}
],
"autoload": {
"psr-4": {
"DanielSiepmann\\FediverseFeedWrappers\\": "src/"
}
},
"require": {
"php": "8.2.*"
},
"require-dev": {
"phpunit/phpunit": "^10.0"
}
}

1623
composer.lock generated Normal file

File diff suppressed because it is too large Load diff

13
public/index.php Normal file
View file

@ -0,0 +1,13 @@
<?php
use DanielSiepmann\FediverseFeedWrappers\RequestHandler;
use DanielSiepmann\FediverseFeedWrappers\WrapperRegistry;
use DanielSiepmann\FediverseFeedWrappers\Wrapper\GitHubTypo3;
require_once __DIR__ . '/../vendor/autoload.php';
(new RequestHandler(
new WrapperRegistry([
'GitHubTypo3' => GitHubTypo3::class,
])
))->handleRequest();

63
shell.nix Normal file
View file

@ -0,0 +1,63 @@
{ pkgs ? import <nixpkgs> { } }:
let
projectInstall = pkgs.writeShellApplication {
name = "project-install";
runtimeInputs = [
pkgs.php82
pkgs.php82Packages.composer
];
text = ''
composer install --working-dir="$PROJECT_ROOT"
'';
};
projectDeploy = pkgs.writeShellApplication {
name = "project-deploy";
runtimeInputs = [
pkgs.git
pkgs.rsync
# Missing ssh
pkgs.php82
pkgs.php82Packages.composer
projectInstall
];
text = ''
echo "Clean file system"
git clean -dfx
echo "Install project"
project-install
echo "Install project for production"
composer install --no-dev --optimize-autoloader
echo "Sync project to production"
rsync \
-vaz \
--copy-dirlinks \
--delete \
--exclude vendor/**/.git \
src vendor public \
daniel-siepmann.de:webs/fediverse-feed-wrappers/htdocs/
echo "Clean file system"
git clean -dfx
echo "Install project"
project-install
'';
};
in pkgs.mkShell {
name = "Fediverse-Feed-Wrappers";
buildInputs = [
pkgs.php82
pkgs.php82Packages.composer
projectInstall
projectDeploy
];
shellHook = ''
export PROJECT_ROOT="$(pwd)"
export PATH="$(pwd)/:$PATH"
'';
}

45
src/RequestHandler.php Normal file
View file

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
/*
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
namespace DanielSiepmann\FediverseFeedWrappers;
class RequestHandler
{
private WrapperRegistry $wrapperRegistry;
public function __construct(
WrapperRegistry $wrapperRegistry
) {
$this->wrapperRegistry = $wrapperRegistry;
}
/**
* Handles incoming request and creates response.
*/
public function handleRequest(): void
{
$content = $this->wrapperRegistry->get($_GET['feed'] ?? '')->handle();
header('content-type: application/xml;charset=utf-8');
echo $content;
}
}

View file

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
/*
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
namespace DanielSiepmann\FediverseFeedWrappers\Wrapper;
use DOMDocument;
use DanielSiepmann\FediverseFeedWrappers\WrapperInterface;
class GitHubTypo3 implements WrapperInterface
{
/**
* We don't want the full commit messag within each feed item.
*
* Instead we are only interested in first row.
* Interested people can head over to the actual URL for full info.
*/
public function handle(): string
{
$content = new DOMDocument();
$content->loadXML(file_get_contents('https://github.com/TYPO3/typo3/commits.atom'));
$itemContentElements = $content->getElementsByTagName('content');
foreach ($itemContentElements as $itemContent) {
$itemContent->nodeValue = strip_tags(
strtok($itemContent->textContent, "\n") ?: ''
);
}
return $content->saveXML();
}
}

29
src/WrapperInterface.php Normal file
View file

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
/*
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
namespace DanielSiepmann\FediverseFeedWrappers;
interface WrapperInterface
{
public function handle(): string;
}

57
src/WrapperRegistry.php Normal file
View file

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
/*
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
namespace DanielSiepmann\FediverseFeedWrappers;
class WrapperRegistry
{
private array $wrappers;
public function __construct(
array $wrappers
) {
$this->wrappers = $wrappers;
}
public function get(string $identifier): WrapperInterface
{
$wrapper = null;
$className = $this->wrappers[$identifier] ?? '';
if (class_exists($className)) {
$wrapper = new $className();
}
if ($wrapper instanceof WrapperInterface) {
return $wrapper;
}
throw new \InvalidArgumentException(
sprintf(
'No wrapper found for "%s", only available: %s.',
$identifier,
implode(array_keys($this->wrappers))
),
1676531371
);
}
}