mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-04 23:57:29 +02:00
[HumbleBundleBridge] Overhaul to include more information (#4621)
* [HumbleBundleBridge] Overhaul to include more information * [HumbleBundleBridge] Remove use of named args in calls PHP 7.4 lacks named arg support and fails unit tests
This commit is contained in:
@@ -34,25 +34,90 @@ class HumbleBundleBridge extends BridgeAbstract
|
||||
}
|
||||
|
||||
foreach ($products as $element) {
|
||||
$item = [];
|
||||
$item['author'] = $element['author'];
|
||||
$item['timestamp'] = $element['start_date|datetime'];
|
||||
$item['title'] = $element['tile_short_name'];
|
||||
$item['uid'] = $element['machine_name'];
|
||||
$item['uri'] = parent::getURI() . $element['product_url'];
|
||||
$dom = new simple_html_dom();
|
||||
$body = $dom->createElement('div');
|
||||
$item = [
|
||||
'author' => $element['author'],
|
||||
'categories' => $element['hover_highlights'],
|
||||
'content' => $body,
|
||||
'timestamp' => $element['start_date|datetime'],
|
||||
'title' => $element['tile_short_name'],
|
||||
'uid' => $element['machine_name'],
|
||||
'uri' => parent::getURI() . $element['product_url'],
|
||||
];
|
||||
|
||||
$item['content'] = $element['marketing_blurb'];
|
||||
$item['content'] .= '<br>' . $element['detailed_marketing_blurb'];
|
||||
|
||||
$item['categories'] = $element['hover_highlights'];
|
||||
array_unshift($item['categories'], explode(':', $element['tile_name'])[0]);
|
||||
array_unshift($item['categories'], $element['tile_stamp']);
|
||||
|
||||
$item['enclosures'] = [$element['tile_logo'], $element['high_res_tile_image']];
|
||||
$this->items[] = $item;
|
||||
$this->createChild($dom, $body, 'img', null, ['src' => $element['tile_logo']]);
|
||||
$this->createChild($dom, $body, 'img', null, ['src' => $element['high_res_tile_image']]);
|
||||
$this->createChild($dom, $body, 'h2', $element['short_marketing_blurb']);
|
||||
$this->createChild($dom, $body, 'p', $element['detailed_marketing_blurb']);
|
||||
|
||||
$this->items[] = $this->processBundle($item, $dom, $body);
|
||||
}
|
||||
}
|
||||
|
||||
private function createChild($dom, $body, $name = null, $val = null, $args = [])
|
||||
{
|
||||
if ($name == null) {
|
||||
$elem = $dom->createTextNode($val);
|
||||
} else {
|
||||
$elem = $dom->createElement($name, $val);
|
||||
}
|
||||
foreach ($args as $arg => $val) {
|
||||
$elem->setAttribute($arg, $val);
|
||||
}
|
||||
$body->appendChild($elem);
|
||||
return $elem;
|
||||
}
|
||||
|
||||
private function processBundle($item, $dom, $body)
|
||||
{
|
||||
$page = getSimpleHTMLDOMCached($item['uri']);
|
||||
$json_text = $page->find('#webpack-bundle-page-data', 0)->innertext;
|
||||
$json = json_decode(html_entity_decode($json_text), true)['bundleData'];
|
||||
$tiers = $json['tier_display_data'];
|
||||
ksort($tiers, SORT_NATURAL);
|
||||
# `initial` element gets sorted to the end as bt# (bundle tiers) precede it alphabetically
|
||||
array_unshift($tiers, array_pop($tiers));
|
||||
|
||||
$seen = [];
|
||||
$toc = $this->createChild($dom, $body, 'ul');
|
||||
foreach ($tiers as $tiername => $tier) {
|
||||
$this->createChild($dom, $body, 'h2', $tier['header'], ['id' => $tiername]);
|
||||
$li = $this->createChild($dom, $toc, 'li');
|
||||
$this->createChild($dom, $li, 'a', $tier['header'], ['href' => "#$tiername"]);
|
||||
$toc_tier = $this->createChild($dom, $toc, 'ul');
|
||||
foreach ($tier['tier_item_machine_names'] as $name) {
|
||||
if (in_array($name, $seen)) {
|
||||
continue;
|
||||
}
|
||||
array_push($seen, $name);
|
||||
|
||||
$element = $json['tier_item_data'][$name];
|
||||
$head = $this->createChild($dom, $body, 'h3', null, ['id' => $name]);
|
||||
$head_link = $this->createChild($dom, $head, 'a', $element['human_name'], ['id' => $name]);
|
||||
$li = $this->createChild($dom, $toc_tier, 'li');
|
||||
$this->createChild($dom, $li, 'a', $element['human_name'], ['href' => "#$name"]);
|
||||
$this->createChild($dom, $body, 'img', null, ['src' => $element['resolved_paths']['featured_image']]);
|
||||
$this->createChild($dom, $body, 'img', null, ['src' => $element['resolved_paths']['preview_image']]);
|
||||
$this->createChild($dom, $body, 'br');
|
||||
if ($element['description_text']) {
|
||||
$body->appendChild(str_get_html($element['description_text'])->root);
|
||||
}
|
||||
if ($element['youtube_link']) {
|
||||
$head_link->href = 'https://youtu.be/' . $element['youtube_link'];
|
||||
}
|
||||
if ($element['book_preview']) {
|
||||
$head_link->href = $element['book_preview']['preview_file_link'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
$name = parent::getName();
|
||||
|
Reference in New Issue
Block a user