2019-02-06 20:20:25 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class GlowficBridge extends BridgeAbstract
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2019-02-06 20:20:25 +03:00
|
|
|
const MAINTAINER = 'l1n';
|
|
|
|
const NAME = 'Glowfic Bridge';
|
|
|
|
const URI = 'https://www.glowfic.com';
|
|
|
|
const CACHE_TIMEOUT = 3600; // 1 hour
|
|
|
|
const DESCRIPTION = 'Returns the latest replies on a glowfic post.';
|
|
|
|
const PARAMETERS = [
|
|
|
|
'global' => [],
|
|
|
|
'Thread' => [
|
|
|
|
'post_id' => [
|
|
|
|
'name' => 'Post ID',
|
|
|
|
'title' => 'https://www.glowfic.com/posts/POST ID',
|
2022-03-24 13:59:34 +03:00
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => '2756',
|
2019-02-06 20:20:25 +03:00
|
|
|
'type' => 'number'
|
2022-07-01 16:10:30 +03:00
|
|
|
],
|
2019-02-06 20:20:25 +03:00
|
|
|
'start_page' => [
|
|
|
|
'name' => 'Start Page',
|
|
|
|
'title' => 'To start from an offset page',
|
|
|
|
'type' => 'number'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2019-02-06 20:20:25 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
public function collectData()
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2019-02-06 20:20:25 +03:00
|
|
|
$url = $this->getAPIURI();
|
|
|
|
$metadata = get_headers($url . '/replies', true) or returnClientError('Post did not return reply headers.');
|
|
|
|
$metadata['Last-Page'] = ceil($metadata['Total'] / $metadata['Per-Page']);
|
2022-07-01 16:10:30 +03:00
|
|
|
if (
|
2019-02-06 20:20:25 +03:00
|
|
|
!is_null($this->getInput('start_page')) &&
|
|
|
|
$this->getInput('start_page') < 1 && $metadata['Last-Page'] - $this->getInput('start_page') > 0
|
2022-07-01 16:10:30 +03:00
|
|
|
) {
|
2019-02-06 20:20:25 +03:00
|
|
|
$first_page = $metadata['Last-Page'] - $this->getInput('start_page');
|
|
|
|
} elseif (!is_null($this->getInput('start_page')) && $this->getInput('start_page') <= $metadata['Last-Page']) {
|
|
|
|
$first_page = $this->getInput('start_page');
|
2022-07-01 16:10:30 +03:00
|
|
|
} else {
|
2019-02-06 20:20:25 +03:00
|
|
|
$first_page = 1;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2019-02-06 20:20:25 +03:00
|
|
|
for ($page_offset = $first_page; $page_offset <= $metadata['Last-Page']; $page_offset++) {
|
2024-07-31 18:30:06 +03:00
|
|
|
$jsonContents = getContents($url . '/replies?page=' . $page_offset);
|
2019-02-06 20:20:25 +03:00
|
|
|
$replies = json_decode($jsonContents);
|
|
|
|
foreach ($replies as $reply) {
|
|
|
|
$item = [];
|
|
|
|
|
|
|
|
$item['content'] = $reply->{'content'};
|
|
|
|
$item['uri'] = $this->getURI() . '?page=' . $page_offset . '#reply-' . $reply->{'id'};
|
|
|
|
if ($reply->{'icon'}) {
|
|
|
|
$item['enclosures'] = [$reply->{'icon'}->{'url'}];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2019-02-06 20:20:25 +03:00
|
|
|
$item['author'] = $reply->{'character'}->{'screenname'} . ' (' . $reply->{'character'}->{'name'} . ')';
|
|
|
|
$item['timestamp'] = date('r', strtotime($reply->{'created_at'}));
|
|
|
|
$item['title'] = 'Tag by ' . $reply->{'user'}->{'username'} . ' updated at ' . $reply->{'updated_at'};
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 20:20:25 +03:00
|
|
|
|
|
|
|
private function getAPIURI()
|
|
|
|
{
|
|
|
|
$url = parent::getURI() . '/api/v1/posts/' . $this->getInput('post_id');
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
$url = parent::getURI() . '/posts/' . $this->getInput('post_id');
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPost()
|
|
|
|
{
|
|
|
|
$url = $this->getAPIURI();
|
2024-07-31 18:30:06 +03:00
|
|
|
$jsonPost = getContents($url);
|
2019-02-06 20:20:25 +03:00
|
|
|
$post = json_decode($jsonPost);
|
2024-07-31 18:30:06 +03:00
|
|
|
|
2019-02-06 20:20:25 +03:00
|
|
|
return $post;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
if (!is_null($this->getInput('post_id'))) {
|
|
|
|
$post = $this->getPost();
|
|
|
|
return $post->{'subject'} . ' - ' . parent::getName();
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2019-02-06 20:20:25 +03:00
|
|
|
return parent::getName();
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2019-02-06 20:20:25 +03:00
|
|
|
public function getDescription()
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2019-02-06 20:20:25 +03:00
|
|
|
if (!is_null($this->getInput('post_id'))) {
|
|
|
|
$post = $this->getPost();
|
|
|
|
return $post->{'content'};
|
|
|
|
}
|
|
|
|
return parent::getName();
|
|
|
|
}
|
|
|
|
}
|