-
Notifications
You must be signed in to change notification settings - Fork 1k
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
+185
−0
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aba0df2
Add FlashbackBridge
fatuuse f0f07ac
phpcs changes
fatuuse e6e99ad
[WulffmorgenthalerBridge] Add new bridge
fatuuse aa5111b
[WulffmorgenthalerBridge] Remove bridge. Found rss. http://wumo.com/w…
fatuuse d791767
Update FlashbackBridge.php
em92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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å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år', 'Idag'), array('yesterday', 'today'), \ | ||
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; | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.