[
'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);
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 = '';
// Text
if (isset($post->txt)) {
$isRepost = $this->getInput('user') !== $post->uid;
if ($isRepost) {
$content .= 'Reposted by ' . $this->getInput('user') . '@gettr.com
';
}
$content .= "$post->txt
";
}
// Preview image
if (isset($post->previmg)) {
$content .= <<
HTML;
}
// Images
foreach ($post->imgs ?? [] as $imageUrl) {
$content .= <<
HTML;
}
// Video
if (isset($post->ovid)) {
$mainImage = $post->main;
$content .= <<