From 70456abca749e56bc4b730fe799b472b8204cd65 Mon Sep 17 00:00:00 2001 From: jNullj Date: Sat, 8 Jan 2022 23:46:53 +0200 Subject: [PATCH 1/3] [ExplosmBridge] Rewrite to work without feedburner re-wrote the bridge to scrap from the new explosm site as the old method of using feedburner is not working anymore, feedburner is stuck on dec/22 when the explosm site changed. --- bridges/ExplosmBridge.php | 58 +++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/bridges/ExplosmBridge.php b/bridges/ExplosmBridge.php index 876f10e546b..79a70841e6f 100644 --- a/bridges/ExplosmBridge.php +++ b/bridges/ExplosmBridge.php @@ -1,22 +1,58 @@ 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'] = ''; - - 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'] = ''; + $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'] = ''; + $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 + } } } From a4ed47c1a8b7124b23e33ab8707187e1b4acc4d9 Mon Sep 17 00:00:00 2001 From: jNullj Date: Sun, 9 Jan 2022 19:45:23 +0200 Subject: [PATCH 2/3] Fixed linting --- bridges/ExplosmBridge.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bridges/ExplosmBridge.php b/bridges/ExplosmBridge.php index 79a70841e6f..f202135002a 100644 --- a/bridges/ExplosmBridge.php +++ b/bridges/ExplosmBridge.php @@ -30,15 +30,16 @@ public function collectData(){ $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['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'] = ''; $this->items[] = $item; - - $next_comic = substr($this::URI, 0, -1) . $latest->find('div[class*=MainComic__Selector]', 0)->find('a', 0)->getAttribute('href'); + + $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); @@ -47,12 +48,13 @@ public function collectData(){ $item = array(); $item['uri'] = $next_comic; $item['uid'] = $next_comic; - $item['title'] = "Comic for " . $date_string; + $item['title'] = 'Comic for ' . $date_string; $item['timestamp'] = strtotime($date_string); $item['author'] = $this_comic->find('p[class*=Author__P]', 2)->innertext; $item['content'] = ''; $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 + $next_comic = substr($this::URI, 0, -1) + . $this_comic->find('div[class*=MainComic__Selector]', 0)->find('a', 0)->getAttribute('href'); // get next comic link } } } From 9f93bc3b401355370dc3c435d57c831e5ef4a40a Mon Sep 17 00:00:00 2001 From: jNullj Date: Sun, 9 Jan 2022 19:54:52 +0200 Subject: [PATCH 3/3] Remove post limit requirment For backwards compatibility with links used by the previous version of this bridge assume default of 1 posts if the parameter is missing. --- bridges/ExplosmBridge.php | 1 - 1 file changed, 1 deletion(-) diff --git a/bridges/ExplosmBridge.php b/bridges/ExplosmBridge.php index f202135002a..cfe42195206 100644 --- a/bridges/ExplosmBridge.php +++ b/bridges/ExplosmBridge.php @@ -11,7 +11,6 @@ class ExplosmBridge extends BridgeAbstract { 'limit' => array( 'name' => 'Posts limit', 'type' => 'number', - 'required' => true, 'title' => 'Maximum number of items to return', 'defaultValue' => 5 )