rss-bridge/bridges/ParlerBridge.php

54 lines
1.8 KiB
PHP
Raw Normal View History

2022-04-13 00:39:32 +03:00
<?php
final class ParlerBridge extends BridgeAbstract
{
const NAME = 'Parler.com bridge';
const URI = 'https://parler.com';
const DESCRIPTION = 'Fetches the latest posts from a parler user';
const MAINTAINER = 'dvikan';
const CACHE_TIMEOUT = 60 * 15; // 15m
const PARAMETERS = [
[
'user' => [
'name' => 'User',
'type' => 'text',
'required' => true,
'exampleValue' => 'NigelFarage',
],
'limit' => self::LIMIT,
]
];
2022-04-13 00:39:32 +03:00
public function collectData()
{
$user = trim($this->getInput('user'));
if (preg_match('#^https?://parler\.com/(\w+)#i', $user, $m)) {
$user = $m[1];
}
2022-09-24 01:02:19 +03:00
$json = getContents(sprintf('https://api.parler.com/v0/public/user/%s/feed/?page=1&limit=20&media_only=0', $user));
$response = Json::decode($json, false);
$data = $response->data ?? null;
if (!$data) {
throw new \Exception('The returned data is empty');
}
foreach ($data as $post) {
$item = [
2022-09-24 01:02:19 +03:00
'title' => $post->body,
'uri' => sprintf('https://parler.com/feed/%s', $post->postuuid),
'author' => $post->user->username,
'uid' => $post->postuuid,
'content' => $post->body,
];
2022-09-24 01:02:19 +03:00
$date = $post->date_created;
$createdAt = date_create($date);
if ($createdAt) {
$item['timestamp'] = $createdAt->getTimestamp();
}
2022-09-24 01:02:19 +03:00
if (isset($post->image)) {
$item['content'] .= sprintf('<img loading="lazy" src="%s">', $post->image);
}
$this->items[] = $item;
}
}
2022-04-13 00:39:32 +03:00
}