2019-07-06 13:29:36 +03:00
|
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
class FicbookBridge extends BridgeAbstract
|
|
|
|
|
{
|
|
|
|
|
const NAME = 'Ficbook Bridge';
|
|
|
|
|
const URI = 'https://ficbook.net/';
|
|
|
|
|
const DESCRIPTION = 'No description provided';
|
|
|
|
|
const MAINTAINER = 'logmanoriginal';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
const PARAMETERS = [
|
|
|
|
|
'Site News' => [],
|
|
|
|
|
'Fiction Updates' => [
|
|
|
|
|
'fiction_id' => [
|
|
|
|
|
'name' => 'Fanfiction ID',
|
|
|
|
|
'type' => 'text',
|
|
|
|
|
'pattern' => '[0-9]+',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'title' => 'Insert fanfiction ID',
|
|
|
|
|
'exampleValue' => '5783919',
|
|
|
|
|
],
|
|
|
|
|
'include_contents' => [
|
|
|
|
|
'name' => 'Include contents',
|
|
|
|
|
'type' => 'checkbox',
|
|
|
|
|
'title' => 'Activate to include contents in the feed',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'Fiction Comments' => [
|
|
|
|
|
'fiction_id' => [
|
|
|
|
|
'name' => 'Fanfiction ID',
|
|
|
|
|
'type' => 'text',
|
|
|
|
|
'pattern' => '[0-9]+',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'title' => 'Insert fanfiction ID',
|
|
|
|
|
'exampleValue' => '5783919',
|
2022-07-01 16:10:30 +03:00
|
|
|
|
],
|
2019-07-06 13:29:36 +03:00
|
|
|
|
],
|
|
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2020-10-09 22:39:35 +03:00
|
|
|
|
protected $titleName;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
public function getURI()
|
|
|
|
|
{
|
|
|
|
|
switch ($this->queriedContext) {
|
2022-06-24 19:29:35 +03:00
|
|
|
|
case 'Site News':
|
2019-07-06 13:29:36 +03:00
|
|
|
|
// For some reason this is not HTTPS
|
|
|
|
|
return 'http://ficbook.net/sitenews';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-06-24 19:29:35 +03:00
|
|
|
|
case 'Fiction Updates':
|
2019-07-06 13:29:36 +03:00
|
|
|
|
return self::URI
|
|
|
|
|
. 'readfic/'
|
|
|
|
|
. urlencode($this->getInput('fiction_id'));
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-06-24 19:29:35 +03:00
|
|
|
|
case 'Fiction Comments':
|
2019-07-06 13:29:36 +03:00
|
|
|
|
return self::URI
|
|
|
|
|
. 'readfic/'
|
|
|
|
|
. urlencode($this->getInput('fiction_id'))
|
|
|
|
|
. '/comments#content';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
default:
|
|
|
|
|
return parent::getURI();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2020-10-09 22:39:35 +03:00
|
|
|
|
public function getName()
|
|
|
|
|
{
|
|
|
|
|
switch ($this->queriedContext) {
|
2022-06-24 19:29:35 +03:00
|
|
|
|
case 'Site News':
|
2020-10-09 22:39:35 +03:00
|
|
|
|
return $this->queriedContext . ' | ' . self::NAME;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-06-24 19:29:35 +03:00
|
|
|
|
case 'Fiction Updates':
|
2020-10-09 22:39:35 +03:00
|
|
|
|
return $this->titleName . ' | ' . self::NAME;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-06-24 19:29:35 +03:00
|
|
|
|
case 'Fiction Comments':
|
2020-10-09 22:39:35 +03:00
|
|
|
|
return $this->titleName . ' | Comments | ' . self::NAME;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2020-10-09 22:39:35 +03:00
|
|
|
|
default:
|
|
|
|
|
return self::NAME;
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
public function collectData()
|
|
|
|
|
{
|
|
|
|
|
$header = ['Accept-Language: en-US'];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
|
$html = getSimpleHTMLDOM($this->getURI(), $header);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
$html = defaultLinkTo($html, self::URI);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2020-10-15 10:53:19 +03:00
|
|
|
|
if ($this->queriedContext == 'Fiction Updates' or $this->queriedContext == 'Fiction Comments') {
|
2020-10-09 22:39:35 +03:00
|
|
|
|
$this->titleName = $html->find('.fanfic-main-info > h1', 0)->innertext;
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
switch ($this->queriedContext) {
|
|
|
|
|
case 'Site News':
|
|
|
|
|
return $this->collectSiteNews($html);
|
|
|
|
|
case 'Fiction Updates':
|
|
|
|
|
return $this->collectUpdatesData($html);
|
|
|
|
|
case 'Fiction Comments':
|
|
|
|
|
return $this->collectCommentsData($html);
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
private function collectSiteNews($html)
|
|
|
|
|
{
|
|
|
|
|
foreach ($html->find('.news_view') as $news) {
|
|
|
|
|
$this->items[] = [
|
|
|
|
|
'title' => $news->find('h1.title', 0)->plaintext,
|
|
|
|
|
'timestamp' => strtotime($this->fixDate($news->find('span[title]', 0)->title)),
|
|
|
|
|
'content' => $news->find('.news_text', 0),
|
|
|
|
|
];
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
private function collectCommentsData($html)
|
|
|
|
|
{
|
2020-09-28 12:02:40 +03:00
|
|
|
|
foreach ($html->find('article.comment-container') as $article) {
|
2019-07-06 13:29:36 +03:00
|
|
|
|
$this->items[] = [
|
|
|
|
|
'uri' => $article->find('.comment_link_to_fic > a', 0)->href,
|
|
|
|
|
'title' => $article->find('.comment_author', 0)->plaintext,
|
|
|
|
|
'author' => $article->find('.comment_author', 0)->plaintext,
|
|
|
|
|
'timestamp' => strtotime($this->fixDate($article->find('time[datetime]', 0)->datetime)),
|
|
|
|
|
'content' => $article->find('.comment_message', 0),
|
|
|
|
|
'enclosures' => [$article->find('img', 0)->src],
|
|
|
|
|
];
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
private function collectUpdatesData($html)
|
|
|
|
|
{
|
2020-09-28 12:02:40 +03:00
|
|
|
|
foreach ($html->find('ul.list-of-fanfic-parts > li') as $chapter) {
|
2019-07-06 13:29:36 +03:00
|
|
|
|
$item = [
|
|
|
|
|
'uri' => $chapter->find('a', 0)->href,
|
|
|
|
|
'title' => $chapter->find('a', 0)->plaintext,
|
|
|
|
|
'timestamp' => strtotime($this->fixDate($chapter->find('span[title]', 0)->title)),
|
|
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
if ($this->getInput('include_contents')) {
|
2023-03-04 18:12:46 +03:00
|
|
|
|
$content = getSimpleHTMLDOMCached($item['uri'], 86400, [], [], true, true, DEFAULT_TARGET_CHARSET, false);
|
|
|
|
|
$item['content'] = str_replace("\n", '<br>', $content->find('#content', 0)->innertext);
|
2019-07-06 13:29:36 +03:00
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
// Sort by time, descending
|
|
|
|
|
usort($this->items, function ($a, $b) {
|
|
|
|
|
return $b['timestamp'] - $a['timestamp'];
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
private function fixDate($date)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: This list was generated using Google tranlator. Someone who
|
|
|
|
|
// actually knows russian should check this list! Please keep in mind
|
|
|
|
|
// that month names must match exactly the names returned by Ficbook.
|
|
|
|
|
$ru_month = [
|
|
|
|
|
'января',
|
|
|
|
|
'февраля',
|
|
|
|
|
'марта',
|
|
|
|
|
'апреля',
|
|
|
|
|
'мая',
|
|
|
|
|
'июня',
|
|
|
|
|
'июля',
|
|
|
|
|
'августа',
|
2020-09-28 12:02:40 +03:00
|
|
|
|
'сентября',
|
2019-07-06 13:29:36 +03:00
|
|
|
|
'октября',
|
2020-09-28 12:02:40 +03:00
|
|
|
|
'ноября',
|
|
|
|
|
'декабря',
|
2019-07-06 13:29:36 +03:00
|
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
$en_month = [
|
|
|
|
|
'January',
|
|
|
|
|
'February',
|
|
|
|
|
'March',
|
|
|
|
|
'April',
|
|
|
|
|
'May',
|
|
|
|
|
'June',
|
|
|
|
|
'July',
|
|
|
|
|
'August',
|
|
|
|
|
'September',
|
|
|
|
|
'October',
|
|
|
|
|
'November',
|
|
|
|
|
'December',
|
|
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
$fixed_date = str_replace($ru_month, $en_month, $date);
|
2023-10-15 16:24:07 +03:00
|
|
|
|
$fixed_date = str_replace(' г.', '', $fixed_date);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
if ($fixed_date === $date) {
|
|
|
|
|
Debug::log('Unable to fix date: ' . $date);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
|
2019-07-06 13:29:36 +03:00
|
|
|
|
return $fixed_date;
|
|
|
|
|
}
|
|
|
|
|
}
|