1
0

HumbleStoreDiscountBridge.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * RssBridgeHumbleStoreDiscount
  4. * Returns the 10 first sales from the Humble Store
  5. * Enjoy your indie games :)
  6. *
  7. * @name Humble Store Discount Bridge
  8. * @homepage https://www.humblebundle.com/store
  9. * @description Returns the 10 first sales from the Humble Store
  10. * @maintainer 16mhz
  11. * @update 2014-07-18
  12. */
  13. class HumbleStoreDiscountBridge extends BridgeAbstract{
  14. public function collectData(array $param){
  15. $result = file_get_html('https://www.humblebundle.com/store/api/humblebundle?request=2&page_size=20&sort=discount&page=0')
  16. or $this->returnError('Could not request the Humble Store.', 404);
  17. $string = json_decode($result, true);
  18. $items = $string['results'];
  19. $store_link = 'https://www.humblebundle.com/store/p/';
  20. $limit = 0;
  21. foreach ($items as $key => $value) {
  22. if ($limit < 10) {
  23. $new_price = $value['current_price'][0] . ' ' . $value['current_price'][1];
  24. $full_price = $value['full_price'][0] . ' ' . $value['full_price'][1];
  25. $product_name = $value['human_name'];
  26. $sale_end = (int)$value['sale_end'];
  27. $product_uri = $store_link . $value['machine_name'];
  28. $platforms = str_replace('\'', '', implode("','", $value['platforms']));
  29. $delivery_methods = str_replace('\'', '', implode("','", $value['delivery_methods']));
  30. $thumbnail = 'https://www.humblebundle.com' . $value['storefront_featured_image_small'];
  31. $content = '<img src="' . $thumbnail . '" alt="' . $value['storefront_featured_image_small'] . '"><br/><br/><b>' . $product_name
  32. . '</b><br/><br/><b>Current price:</b> ' . $new_price . '<br/><b>Full price:</b> ' . $full_price .'<br/><b>Sale ends:</b> '. date(DATE_ATOM, $sale_end)
  33. . '<br/><b>Developer:</b> ' . $value['developer_name'] . '<br/><b>Delivery methods:</b> ' . $delivery_methods
  34. . '<br/><b>Platforms:</b> ' . $platforms . '<br/>' . $value['description'];
  35. $item = new \Item();
  36. $item->title = $product_name . ' - ' . $new_price;
  37. $item->uri = $product_uri;
  38. $item->timestamp = $sale_end - 10*24*3600; // just a hack, stamping game as 10 days before sales end (better than no timestamp)
  39. $item->content = $content;
  40. $this->items[] = $item;
  41. $limit++;
  42. }
  43. }
  44. }
  45. public function getName(){
  46. return 'HumbleStoreDiscount';
  47. }
  48. public function getURI(){
  49. return 'https://www.humblebundle.com/store';
  50. }
  51. public function getCacheDuration(){
  52. return 21600; // 6 hours
  53. }
  54. }