2019-08-28 17:28:39 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
class PirateCommunityBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'Pirate-Community Bridge';
|
|
|
|
const URI = 'https://raymanpc.com/';
|
|
|
|
const CACHE_TIMEOUT = 300; // 5min
|
|
|
|
const DESCRIPTION = 'Returns replies to topics';
|
|
|
|
const MAINTAINER = 'Roliga';
|
|
|
|
const PARAMETERS = [ [
|
|
|
|
't' => [
|
|
|
|
'name' => 'Topic ID',
|
|
|
|
'type' => 'number',
|
2022-03-24 13:59:34 +03:00
|
|
|
'exampleValue' => '12651',
|
2019-08-28 17:28:39 +03:00
|
|
|
'title' => 'Topic ID from topic URL. If the URL contains t=12 the ID is 12.',
|
|
|
|
'required' => true
|
|
|
|
]]];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
private $feedName = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
public function detectParameters($url)
|
|
|
|
{
|
|
|
|
$parsed_url = parse_url($url);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-08-06 23:46:28 +03:00
|
|
|
$host = $parsed_url['host'] ?? null;
|
|
|
|
|
|
|
|
if ($host !== 'raymanpc.com') {
|
2019-08-28 17:28:39 +03:00
|
|
|
return null;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
parse_str($parsed_url['query'], $parsed_query);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
if (
|
|
|
|
$parsed_url['path'] === '/forum/viewtopic.php'
|
|
|
|
&& array_key_exists('t', $parsed_query)
|
|
|
|
) {
|
|
|
|
return ['t' => $parsed_query['t']];
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
return null;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
if (!empty($this->feedName)) {
|
|
|
|
return $this->feedName;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
return parent::getName();
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
if (!is_null($this->getInput('t'))) {
|
|
|
|
return self::URI
|
|
|
|
. 'forum/viewtopic.php?t='
|
|
|
|
. $this->getInput('t')
|
|
|
|
. '&sd=d'; // sort posts decending by ate so first page has latest posts
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
return parent::getURI();
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($this->getURI());
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
$this->feedName = $html->find('head title', 0)->plaintext;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
foreach ($html->find('.post') as $reply) {
|
|
|
|
$item = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
$item['uri'] = $this->getURI()
|
|
|
|
. $reply->find('h3 a', 0)->getAttribute('href');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
$item['title'] = $reply->find('h3 a', 0)->plaintext;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
$author_html = $reply->find('.author', 0);
|
|
|
|
// author_html contains the timestamp as text directly inside it,
|
|
|
|
// so delete all other child elements
|
|
|
|
foreach ($author_html->children as $child) {
|
|
|
|
$child->outertext = '';
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2019-08-28 17:28:39 +03:00
|
|
|
// Timestamps are always in UTC+1
|
|
|
|
$item['timestamp'] = trim($author_html->innertext) . ' +01:00';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
$item['author'] = $reply
|
|
|
|
->find('.username, .username-coloured', 0)
|
|
|
|
->plaintext;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
$item['content'] = defaultLinkTo(
|
|
|
|
$reply->find('.content', 0)->innertext,
|
|
|
|
$this->getURI()
|
|
|
|
);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
$item['enclosures'] = [];
|
|
|
|
foreach ($reply->find('.attachbox img.postimage') as $img) {
|
|
|
|
$item['enclosures'][] = urljoin($this->getURI(), $img->src);
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2019-08-28 17:28:39 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|