mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-10 17:08:47 +00:00
fix: use parlers new api (#3061)
This commit is contained in:
parent
aacba5b1a8
commit
8cc5e44be6
@ -22,59 +22,32 @@ final class ParlerBridge extends BridgeAbstract
|
|||||||
public function collectData()
|
public function collectData()
|
||||||
{
|
{
|
||||||
$user = trim($this->getInput('user'));
|
$user = trim($this->getInput('user'));
|
||||||
|
|
||||||
if (preg_match('#^https?://parler\.com/(\w+)#i', $user, $m)) {
|
if (preg_match('#^https?://parler\.com/(\w+)#i', $user, $m)) {
|
||||||
$user = $m[1];
|
$user = $m[1];
|
||||||
}
|
}
|
||||||
|
$json = getContents(sprintf('https://api.parler.com/v0/public/user/%s/feed/?page=1&limit=20&media_only=0', $user));
|
||||||
$posts = $this->fetchParlerProfileFeed($user);
|
$response = Json::decode($json, false);
|
||||||
|
$data = $response->data ?? null;
|
||||||
foreach ($posts as $post) {
|
if (!$data) {
|
||||||
// For some reason, the post data is placed inside primary attribute
|
throw new \Exception('The returned data is empty');
|
||||||
$primary = $post->primary;
|
}
|
||||||
|
foreach ($data as $post) {
|
||||||
$item = [
|
$item = [
|
||||||
'title' => mb_substr($primary->body, 0, 100),
|
'title' => $post->body,
|
||||||
'uri' => sprintf('https://parler.com/feed/%s', $primary->uuid),
|
'uri' => sprintf('https://parler.com/feed/%s', $post->postuuid),
|
||||||
'author' => $primary->username,
|
'author' => $post->user->username,
|
||||||
'uid' => $primary->uuid,
|
'uid' => $post->postuuid,
|
||||||
'content' => nl2br($primary->full_body),
|
'content' => $post->body,
|
||||||
];
|
];
|
||||||
|
$date = $post->date_created;
|
||||||
$date = DateTimeImmutable::createFromFormat('m/d/YH:i A', $primary->date_str . $primary->time_str);
|
$createdAt = date_create($date);
|
||||||
if ($date) {
|
if ($createdAt) {
|
||||||
$item['timestamp'] = $date->getTimestamp();
|
$item['timestamp'] = $createdAt->getTimestamp();
|
||||||
} else {
|
|
||||||
Debug::log(sprintf('Unable to parse data from Parler.com: "%s"', $date));
|
|
||||||
}
|
}
|
||||||
|
if (isset($post->image)) {
|
||||||
if (isset($primary->image)) {
|
$item['content'] .= sprintf('<img loading="lazy" src="%s">', $post->image);
|
||||||
$item['enclosures'][] = $primary->image;
|
|
||||||
$item['content'] .= sprintf('<img loading="lazy" src="%s">', $primary->image);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function fetchParlerProfileFeed(string $user): array
|
|
||||||
{
|
|
||||||
$json = getContents('https://parler.com/open-api/ProfileFeedEndpoint.php', [], [
|
|
||||||
CURLOPT_POSTFIELDS => http_build_query([
|
|
||||||
'user' => $user,
|
|
||||||
'page' => '1',
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
$response = json_decode($json);
|
|
||||||
if ($response === false) {
|
|
||||||
throw new \Exception('Unable to decode json from Parler');
|
|
||||||
}
|
|
||||||
if ($response->status !== 'ok') {
|
|
||||||
throw new \Exception('Did not get OK from Parler');
|
|
||||||
}
|
|
||||||
if ($response->data === []) {
|
|
||||||
throw new \Exception('Unknown Parler username');
|
|
||||||
}
|
|
||||||
return $response->data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user