1
0

SteamBridge.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. class SteamBridge extends BridgeAbstract {
  3. const NAME = 'Steam Bridge';
  4. const URI = 'https://steamcommunity.com/';
  5. const CACHE_TIMEOUT = 3600; // 1h
  6. const DESCRIPTION = 'Returns games list';
  7. const MAINTAINER = 'jacknumber';
  8. const PARAMETERS = array(
  9. 'Wishlist' => array(
  10. 'username' => array(
  11. 'name' => 'Username',
  12. 'required' => true,
  13. ),
  14. 'currency' => array(
  15. 'name' => 'Currency',
  16. 'type' => 'list',
  17. 'values' => array(
  18. // source: http://steam.steamlytics.xyz/currencies
  19. 'USD' => 'us',
  20. 'GBP' => 'gb',
  21. 'EUR' => 'fr',
  22. 'CHF' => 'ch',
  23. 'RUB' => 'ru',
  24. 'BRL' => 'br',
  25. 'JPY' => 'jp',
  26. 'SEK' => 'se',
  27. 'IDR' => 'id',
  28. 'MYR' => 'my',
  29. 'PHP' => 'ph',
  30. 'SGD' => 'sg',
  31. 'THB' => 'th',
  32. 'KRW' => 'kr',
  33. 'TRY' => 'tr',
  34. 'MXN' => 'mx',
  35. 'CAD' => 'ca',
  36. 'NZD' => 'nz',
  37. 'CNY' => 'cn',
  38. 'INR' => 'in',
  39. 'CLP' => 'cl',
  40. 'PEN' => 'pe',
  41. 'COP' => 'co',
  42. 'ZAR' => 'za',
  43. 'HKD' => 'hk',
  44. 'TWD' => 'tw',
  45. 'SRD' => 'sr',
  46. 'AED' => 'ae',
  47. ),
  48. ),
  49. 'sort' => array(
  50. 'name' => 'Sort by',
  51. 'type' => 'list',
  52. 'values' => array(
  53. 'Rank' => 'rank',
  54. 'Date Added' => 'added',
  55. 'Name' => 'name',
  56. 'Price' => 'price',
  57. )
  58. ),
  59. 'only_discount' => array(
  60. 'name' => 'Only discount',
  61. 'type' => 'checkbox',
  62. )
  63. )
  64. );
  65. public function collectData(){
  66. $username = $this->getInput('username');
  67. $params = array(
  68. 'sort' => $this->getInput('sort'),
  69. 'cc' => $this->getInput('currency')
  70. );
  71. $url = self::URI . 'id/' . $username . '/wishlist?' . http_build_query($params);
  72. $html = '';
  73. $html = getSimpleHTMLDOM($url)
  74. or returnServerError("Could not request Steam Wishlist. Tried:\n - $url");
  75. foreach($html->find('#wishlist_items .wishlistRow') as $element) {
  76. $gameTitle = $element->find('h4', 0)->plaintext;
  77. $gameUri = $element->find('.storepage_btn_ctn a', 0)->href;
  78. $gameImg = $element->find('.gameListRowLogo img', 0)->src;
  79. $discountBlock = $element->find('.discount_block', 0);
  80. if($element->find('.discount_block', 0)) {
  81. $gameHasPromo = 1;
  82. } else {
  83. if($this->getInput('only_discount')) {
  84. continue;
  85. }
  86. $gameHasPromo = 0;
  87. }
  88. if($gameHasPromo) {
  89. $gamePromoValue = $discountBlock->find('.discount_pct', 0)->plaintext;
  90. $gameOldPrice = $discountBlock->find('.discount_original_price', 0)->plaintext;
  91. $gameNewPrice = $discountBlock->find('.discount_final_price', 0)->plaintext;
  92. $gamePrice = $gameNewPrice;
  93. } else {
  94. $gamePrice = $element->find('.gameListPriceData .price', 0)->plaintext;
  95. }
  96. $item = array();
  97. $item['uri'] = $gameUri;
  98. $item['title'] = $gameTitle;
  99. $item['price'] = $gamePrice;
  100. $item['hasPromo'] = $gameHasPromo;
  101. if($gameHasPromo) {
  102. $item['promoValue'] = $gamePromoValue;
  103. $item['oldPrice'] = $gameOldPrice;
  104. $item['newPrice'] = $gameNewPrice;
  105. }
  106. $this->items[] = $item;
  107. }
  108. }
  109. }