From 12ce8192ed7c2724f35911d8d1e64123e66d8ac7 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Thu, 2 Oct 2025 17:33:59 +0200 Subject: [PATCH] =?UTF-8?q?Neue=20Bridge=20f=C3=BCr=20Humble=20Bundle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HumbleBundlesBridge.php | 122 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 HumbleBundlesBridge.php diff --git a/HumbleBundlesBridge.php b/HumbleBundlesBridge.php new file mode 100644 index 0000000..68c332e --- /dev/null +++ b/HumbleBundlesBridge.php @@ -0,0 +1,122 @@ + [ + 'name' => 'Category', + 'type' => 'list', + 'values' => [ + 'All' => 'all', + 'Games' => 'games', + 'Books' => 'books', + 'Software' => 'software', + ], + 'defaultValue' => 'all', + ], + ], + ]; + + public function collectData() { + $html = getSimpleHTMLDOM(self::URI . 'bundles'); + if (!$html) return; + + // Find the script tag with id "landingPage-json-data" + $scriptTag = $html->find('script#landingPage-json-data', 0); + if (!$scriptTag) return; + + $jsonData = $scriptTag->innertext; + $data = json_decode($jsonData, true); + if (!$data) return; + + $category = $this->getInput('category'); + $bundles = []; + + // Get bundles based on category + if ($category === 'all') { + // Collect all bundles from all categories + if (isset($data['data']['games']['mosaic'][0]['products'])) { + $bundles = array_merge($bundles, $data['data']['games']['mosaic'][0]['products']); + } + if (isset($data['data']['books']['mosaic'][0]['products'])) { + $bundles = array_merge($bundles, $data['data']['books']['mosaic'][0]['products']); + } + if (isset($data['data']['software']['mosaic'][0]['products'])) { + $bundles = array_merge($bundles, $data['data']['software']['mosaic'][0]['products']); + } + + // Sort by start date (newest first) + usort($bundles, function($a, $b) { + $timeA = isset($a['start_date|datetime']) ? strtotime($a['start_date|datetime']) : 0; + $timeB = isset($b['start_date|datetime']) ? strtotime($b['start_date|datetime']) : 0; + return $timeB - $timeA; + }); + } else { + // Get bundles for specific category + if (isset($data['data'][$category]['mosaic'][0]['products'])) { + $bundles = $data['data'][$category]['mosaic'][0]['products']; + } + } + + foreach ($bundles as $bundle) { + $item = []; + + $item['title'] = $bundle['tile_name'] ?? $bundle['tile_short_name'] ?? 'Unknown Bundle'; + $item['uri'] = self::URI . ltrim($bundle['product_url'], '/'); + $item['uid'] = $bundle['machine_name']; + + // Author + if (isset($bundle['author'])) { + $item['author'] = $bundle['author']; + } + + // Timestamp + if (isset($bundle['start_date|datetime'])) { + $item['timestamp'] = strtotime($bundle['start_date|datetime']); + } + + // Build content + $content = ''; + + // Add image + if (isset($bundle['tile_image'])) { + $content .= '
' . htmlspecialchars($item['title']) . '

'; + $item['enclosures'][] = $bundle['tile_image']; + } + + // Add marketing blurb + if (isset($bundle['detailed_marketing_blurb'])) { + $content .= '

' . $bundle['marketing_blurb'] . '


'; + $content .= '

' . $bundle['detailed_marketing_blurb'] . '

'; + } elseif (isset($bundle['marketing_blurb'])) { + $content .= '

' . $bundle['marketing_blurb'] . '

'; + } + + // Add highlights + if (isset($bundle['highlights']) && is_array($bundle['highlights'])) { + $content .= '

Details:

'; + } + + $item['content'] = $content; + + $this->items[] = $item; + } + } +}