Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FlashbackBridge] Add new bridge #2343

Merged
merged 5 commits into from
Dec 2, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions bridges/FlashbackBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?php

class FlashbackBridge extends BridgeAbstract
{
const MAINTAINER = 'fatuus';
const NAME = 'Flashback forum';
const URI = 'https://www.flashback.org';
const DESCRIPTION = 'Returns post from forum';
const CACHE_TIMEOUT = 10800; // 3h

const PARAMETERS = array(
'Category' => array(
'c' => array(
'name' => 'Category number',
'type' => 'number',
'exampleValue' => '249',
'required' => true
)
),
'Tag' => array(
'a' => array(
'name' => 'Tag',
'type' => 'text',
'exampleValue' => 'stockholm',
'required' => true
)
),
'Thread' => array(
't' => array(
'name' => 'Thread number',
'type' => 'number',
'exampleValue' => '1420554',
'required' => true
)
),
/*'User' => array(
'u' => array(
'name' => 'User number',
'type' => 'text',
'exampleValue' => 'not working, need login',
'required' => true
)
),*/
'Search string' => array(
's' => array(
'name' => 'Words',
'type' => 'text',
'exampleValue' => 'sök',
'required' => true
),
'type' => array(
'name' => 'Type of search',
'type' => 'list',
'defaultValue' => 'Posts',
'values' => array(
'Posts' => 'posts',
'Subjects' => 'subjects'
)
)
)
);

public function getName()
{
if ($this->getInput('c')) {
$category = $this->getInput('c');
return 'Category ' . $category . ' - Flashback';
} elseif ($this->getInput('a')) {
$tag = $this->getInput('a');
return 'Tag: ' . $tag . ' - Flashback';
} elseif ($this->getInput('t')) {
$thread = $this->getInput('t');
return 'Thread ' . $thread . ' - Flashback';
} elseif ($this->getInput('u')) {
$user = $this->getInput('u');
return 'User ' . $user . ' - Flashback';
} elseif ($this->getInput('s')) {
$search = $this->getInput('s');
return 'Search: ' . $search . ' - Flashback';
}

return self::NAME;
}

public function collectData()
{
if ($this->getInput('c')) {
$page = self::URI . '/f' . $this->getInput('c');
} elseif ($this->getInput('a')) {
$page = self::URI . '/find_threads_by_tag.php?tag=' . $this->getInput('a');
} elseif ($this->getInput('t')) {
$page = self::URI . '/t' . $this->getInput('t');
$page = $page . 's'; // last-page
} elseif ($this->getInput('u')) {
$page = self::URI . '/find_posts_by_user.php?userid=' . $this->getInput('u');
} elseif ($this->getInput('s')) {
if ($this->getInput('type') == 'posts') {
$page = self::URI . '/sok/?query=' . $this->getInput('s') . '&search_post=1&sp=1&so=pd';
} else {
$page = self::URI . '/sok/?query=' . $this->getInput('s') . '&search_post=0&sp=1&so=pd';
}
}

$html = getSimpleHTMLDOM($page)
or returnServerError('Could not request Flashback page.');

if ($this->getInput('c') || $this->getInput('a')) {
$category = $this->getInput('c');
$array = $html->find('table#threadslist tbody tr');
foreach ($array as $key => $element) {
$item = array();
$item['uri'] = self::URI . $element->find('td.td_title a', 0)->href;
$item['title'] = trim(utf8_encode($element->find('td.td_title a', 0)->innertext));
$item['author'] = trim(utf8_encode(
$element->find('td.td_title span.thread-poster span', 0)->innertext)
);
$timestamp = $element->find('td.td_last_post div', 0);
if (isset($timestamp->plaintext)) {
$item['timestamp'] = strtotime(str_replace(array('Ig&aring;r', 'Idag'),
array('yesterday', 'today'), trim($timestamp->plaintext)));
}
$item['content'] = $item['title'] . '<br />' . trim(preg_replace('/\t+/', '',
$element->find('td.td_replies', 0)->innertext));
$item['uid'] = preg_split('/(\/)/', $element->find('td.td_title a', 0)->href)[1];
$this->items[] = $item;
}
} elseif ($this->getInput('t')) {
$tags = $html->find('div.hidden-xs a.tag');
$array = $html->find('div.post');

foreach ($array as $key => $element) {
$item = array();
$item['uri_post'] = self::URI . $element->find('div.post-heading a', 2)->href;
$item['uri'] = self::URI . '/' . preg_split('/(\/s)/', $item['uri_post'])[1] . '#' .
preg_split('/(\/s)/', $item['uri_post'])[1];
$item['uri_thread'] = $page;
$item['author'] = utf8_encode($element->find('div.post-user ul li', 0)->innertext);
$item['author_link'] = self::URI . $element->find('div.post-user ul li a', 0)->href;
$item['post_nr'] = $element->find('div.post-heading a strong', 0)->innertext;
$item['timestamp'] = strtotime(
str_replace(
array('Ig&aring;r', 'Idag'), array('yesterday', 'today'), \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trailing \ is a syntax error on PHP 8.

[Tue Jan  4 22:54:11 2022] [::1]:57496 [200]: GET / - syntax error, unexpected token "\", expecting ")" in rss-bridge/bridges/FlashbackBridge.php on line 141
$  php --version
PHP 8.0.14 (cli) (built: Dec 17 2021 14:16:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.14, Copyright (c) Zend Technologies

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, was going to report this as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is already fixed in #2405, never mind.

current(explode("\t", str_replace("\t\t", "\t", trim(
$element->find('div.post-heading', 0)->plaintext)
)))
)
);
if ($element->find('div.smallfont strong', 0)) {
$item['title'] = trim(utf8_encode($element->find('div.smallfont strong', 0)->innertext));
}
if (empty($item['title'])) {
$item['title'] = date('D j M y H:i', $item['timestamp']);
}
$item['content'] = trim(preg_replace('/\t+/', '', $element->find('div.post_message', 0)));
$item['uid'] = preg_split('/(\#|\/)/', $element->find('div.post-heading a', 2)->href)[1];
foreach ($tags as $tag_key => $tag) {
$item['categories'][] = trim(utf8_encode($tag->innertext));
}
$this->items[] = $item;
}
// } elseif ( $this->getInput('u') ) {

} elseif ($this->getInput('s')) {
$array = $html->find('div.post');
foreach ($array as $key => $element) {
$item = array();
$item['uri'] = self::URI . $element->find('div.post-body a', 0)->href;
$item['uri_thread'] = $page . $element->find('div.post-heading a', 0)->href . 's';
$item['author'] = $element->find('div.post-body a', 1)->innertext;
$item['author_link'] = self::URI . $element->find('div.post-body a', 1)->href;
$time = preg_split('/(\>)/', $element->find('div.post-heading', 0)->innertext);
$item['timestamp'] = strtotime(trim(end($time)));
$item['title'] = trim(utf8_encode($element->find('div.post-body strong', 0)->innertext));
if (empty($item['title'])) {
$item['title'] = date('D j M y H:i', $item['timestamp']);
}

$item['datetime'] = (trim(end($time)));
$item['categories'][] = trim(utf8_encode($element->find('div.post-heading a', 0)->innertext));
$item['content'] = trim(preg_replace('/\t+/', '', $element->find('div.post_message', 0)));
$item['uid'] = preg_split('/(\#|\/)/', $element->find('div.post-body a', 0)->href)[1];
$this->items[] = $item;
}
}
}
}