Reformat codebase v4 (#2872)

Reformat code base to PSR12

Co-authored-by: rssbridge <noreply@github.com>
This commit is contained in:
Dag 2022-07-01 15:10:30 +02:00 committed by GitHub
parent 66568e3a39
commit 4f75591060
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
398 changed files with 58607 additions and 56442 deletions

View file

@ -2,72 +2,72 @@
class GettrBridge extends BridgeAbstract
{
const NAME = 'Gettr.com bridge';
const URI = 'https://gettr.com';
const DESCRIPTION = 'Fetches the latest posts from a GETTR user';
const MAINTAINER = 'dvikan';
const CACHE_TIMEOUT = 60 * 15; // 15m
const PARAMETERS = [
[
'user' => [
'name' => 'User',
'type' => 'text',
'required' => true,
'exampleValue' => 'joerogan',
],
'limit' => [
'name' => 'Limit',
'type' => 'number',
'title' => 'Maximum number of items to return (maximum 20)',
'defaultValue' => 5,
'required' => true,
],
]
];
const NAME = 'Gettr.com bridge';
const URI = 'https://gettr.com';
const DESCRIPTION = 'Fetches the latest posts from a GETTR user';
const MAINTAINER = 'dvikan';
const CACHE_TIMEOUT = 60 * 15; // 15m
const PARAMETERS = [
[
'user' => [
'name' => 'User',
'type' => 'text',
'required' => true,
'exampleValue' => 'joerogan',
],
'limit' => [
'name' => 'Limit',
'type' => 'number',
'title' => 'Maximum number of items to return (maximum 20)',
'defaultValue' => 5,
'required' => true,
],
]
];
public function collectData()
{
$api = sprintf(
'https://api.gettr.com/u/user/%s/posts?offset=0&max=%s&dir=fwd&incl=posts&fp=f_uo',
$this->getInput('user'),
min($this->getInput('limit'), 20)
);
$data = json_decode(getContents($api), false);
public function collectData()
{
$api = sprintf(
'https://api.gettr.com/u/user/%s/posts?offset=0&max=%s&dir=fwd&incl=posts&fp=f_uo',
$this->getInput('user'),
min($this->getInput('limit'), 20)
);
$data = json_decode(getContents($api), false);
foreach ($data->result->aux->post as $post) {
$this->items[] = [
'title' => mb_substr($post->txt ?? $post->uid . '@gettr.com', 0, 100),
'uri' => sprintf('https://gettr.com/post/%s', $post->_id),
'author' => $post->uid,
// Convert from ms to s
'timestamp' => substr($post->cdate, 0, strlen($post->cdate) - 3),
'uid' => $post->_id,
// Hashtags found within post text
'categories' => $post->htgs ?? [],
'content' => $this->createContent($post),
];
}
}
foreach ($data->result->aux->post as $post) {
$this->items[] = [
'title' => mb_substr($post->txt ?? $post->uid . '@gettr.com', 0, 100),
'uri' => sprintf('https://gettr.com/post/%s', $post->_id),
'author' => $post->uid,
// Convert from ms to s
'timestamp' => substr($post->cdate, 0, strlen($post->cdate) - 3),
'uid' => $post->_id,
// Hashtags found within post text
'categories' => $post->htgs ?? [],
'content' => $this->createContent($post),
];
}
}
/**
* Collect text, image and video, if they exist
*/
private function createContent(\stdClass $post): string
{
$content = '';
/**
* Collect text, image and video, if they exist
*/
private function createContent(\stdClass $post): string
{
$content = '';
// Text
if (isset($post->txt)) {
$isRepost = $this->getInput('user') !== $post->uid;
if ($isRepost) {
$content .= 'Reposted by ' . $this->getInput('user') . '@gettr.com<br><br>';
}
$content .= "$post->txt <br><br>";
}
// Text
if (isset($post->txt)) {
$isRepost = $this->getInput('user') !== $post->uid;
if ($isRepost) {
$content .= 'Reposted by ' . $this->getInput('user') . '@gettr.com<br><br>';
}
$content .= "$post->txt <br><br>";
}
// Preview image
if (isset($post->previmg)) {
$content .= <<<HTML
// Preview image
if (isset($post->previmg)) {
$content .= <<<HTML
<a href="$post->prevsrc" target="_blank">
<img
src='$post->previmg'
@ -77,11 +77,11 @@ class GettrBridge extends BridgeAbstract
</a>
<br><br>
HTML;
}
}
// Images
foreach ($post->imgs ?? [] as $imageUrl) {
$content .= <<<HTML
// Images
foreach ($post->imgs ?? [] as $imageUrl) {
$content .= <<<HTML
<img
src='https://media.gettr.com/$imageUrl'
alt='Unable to load image'
@ -89,13 +89,13 @@ HTML;
>
<br><br>
HTML;
}
}
// Video
if (isset($post->ovid)) {
$mainImage = $post->main;
// Video
if (isset($post->ovid)) {
$mainImage = $post->main;
$content .= <<<HTML
$content .= <<<HTML
<video
style="max-width: 100%"
controls
@ -106,30 +106,30 @@ HTML;
Your browser does not support the video element. Kindly update it to latest version.
</video >
HTML;
// This is typically a m3u8 which I don't know how to present in a browser
$streamingUrl = $post->vid;
}
$this->processMetadata($post);
// This is typically a m3u8 which I don't know how to present in a browser
$streamingUrl = $post->vid;
}
$this->processMetadata($post);
return $content;
}
return $content;
}
public function getIcon()
{
return 'https://gettr.com/favicon.ico';
}
public function getIcon()
{
return 'https://gettr.com/favicon.ico';
}
/**
* @param stdClass $post
*/
private function processMetadata(stdClass $post): void
{
// Unused metadata, maybe used later
$textLanguage = $post->txt_lang ?? 'en';
$replies = $post->cm ?? 0;
$likes = $post->lkbpst ?? 0;
$reposts = $post->shbpst ?? 0;
// I think a visibility of "p" means that it's public
$visibility = $post->vis ?? 'p';
}
/**
* @param stdClass $post
*/
private function processMetadata(stdClass $post): void
{
// Unused metadata, maybe used later
$textLanguage = $post->txt_lang ?? 'en';
$replies = $post->cm ?? 0;
$likes = $post->lkbpst ?? 0;
$reposts = $post->shbpst ?? 0;
// I think a visibility of "p" means that it's public
$visibility = $post->vis ?? 'p';
}
}