-
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
[ExplosmBridge] Rewrite to work without feedburner #2417
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -1,22 +1,58 @@ | ||
<?php | ||
class ExplosmBridge extends FeedExpander { | ||
class ExplosmBridge extends BridgeAbstract { | ||
|
||
const MAINTAINER = 'bockiii'; | ||
const NAME = 'Explosm Bridge'; | ||
const URI = 'https://www.explosm.net/'; | ||
const CACHE_TIMEOUT = 4800; //2hours | ||
const DESCRIPTION = 'Returns the last 5 comics'; | ||
const PARAMETERS = array( | ||
'Get latest posts' => array( | ||
'limit' => array( | ||
'name' => 'Posts limit', | ||
'type' => 'number', | ||
'required' => true, | ||
'title' => 'Maximum number of items to return', | ||
'defaultValue' => 5 | ||
) | ||
) | ||
); | ||
|
||
public function collectData(){ | ||
$this->collectExpandableDatas('https://feeds.feedburner.com/Explosm'); | ||
} | ||
|
||
protected function parseItem($feedItem){ | ||
$item = parent::parseItem($feedItem); | ||
$comicpage = getSimpleHTMLDOM($item['uri']); | ||
$image = $comicpage->find('div[id=comic-wrap]', 0)->find('img', 0)->getAttribute('src'); | ||
$item['content'] = '<img src="https:' . $image . '" />'; | ||
|
||
return $item; | ||
$limit = $this->getInput('limit'); | ||
$latest = getSimpleHTMLDOM('https://explosm.net/comics/latest'); | ||
$image = $latest->find('div[id=comic]', 0)->find('img', 0)->getAttribute('src'); | ||
$date_string = $latest->find('p[class*=Author__P]', 0)->innertext; | ||
$next_data_string = $latest->find('script[id=__NEXT_DATA__]', 0)->innertext; | ||
$exp = '/{\\\"latest\\\":\[{\\\"slug\\\":\\\"(.*?)\\ /'; | ||
$reg_array = array(); | ||
preg_match($exp, $next_data_string, $reg_array); | ||
$comic_id = $reg_array[1]; | ||
$comic_id = substr($comic_id, 0, strpos($comic_id, '\\')); | ||
$item = array(); | ||
$item['uri'] = $this::URI . "comics/" . $comic_id; | ||
$item['uid'] = $this::URI . "comics/" . $comic_id; | ||
$item['title'] = "Comic for " . $date_string; | ||
$item['timestamp'] = strtotime($date_string); | ||
$item['author'] = $latest->find('p[class*=Author__P]', 2)->innertext; | ||
$item['content'] = '<img src="' . $image . '" />'; | ||
$this->items[] = $item; | ||
|
||
$next_comic = substr($this::URI, 0, -1) . $latest->find('div[class*=MainComic__Selector]', 0)->find('a', 0)->getAttribute('href'); | ||
// use index 1 as the latest comic was already found | ||
for ($i = 1; $i <= $limit; $i++) { | ||
$this_comic = getSimpleHTMLDOM($next_comic); | ||
$image = $this_comic->find('div[id=comic]', 0)->find('img', 0)->getAttribute('src'); | ||
$date_string = $this_comic->find('p[class*=Author__P]', 0)->innertext; | ||
$item = array(); | ||
$item['uri'] = $next_comic; | ||
$item['uid'] = $next_comic; | ||
$item['title'] = "Comic for " . $date_string; | ||
$item['timestamp'] = strtotime($date_string); | ||
$item['author'] = $this_comic->find('p[class*=Author__P]', 2)->innertext; | ||
$item['content'] = '<img src="' . $image . '" />'; | ||
$this->items[] = $item; | ||
$next_comic = substr($this::URI, 0, -1) . $this_comic->find('div[class*=MainComic__Selector]', 0)->find('a', 0)->getAttribute('href'); // get next comic link | ||
} | ||
} | ||
} |
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.
Do we need "required" here?
This setting will break previous usage, where "/?action=display&bridge=Explosm&format=Html" worked. If I apply this change, users need to reedit their rss feeds.
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.
I did not think about it, this is a great insight. I makred it required becouse a limit is required. I could make it so the default is 5 which is the number of posts the bridge returned when it used feedburner before this change. Does the
'defaultValue' => 5
will take care of that, im not sure.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.
Tested myself, i fixed this and tested for old feed urls to work.