DiceBridge.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. class DiceBridge extends BridgeAbstract {
  3. const MAINTAINER = 'rogerdc';
  4. const NAME = 'Dice Unofficial RSS';
  5. const URI = 'https://www.dice.com/';
  6. const DESCRIPTION = 'The Unofficial Dice RSS';
  7. // const CACHE_TIMEOUT = 86400; // 1 day
  8. const PARAMETERS = array(array(
  9. 'for_one' => array(
  10. 'name' => 'With at least one of the words',
  11. 'required' => false,
  12. ),
  13. 'for_all' => array(
  14. 'name' => 'With all of the words',
  15. 'required' => false,
  16. ),
  17. 'for_exact' => array(
  18. 'name' => 'With the exact phrase',
  19. 'required' => false,
  20. ),
  21. 'for_none' => array(
  22. 'name' => 'With none of these words',
  23. 'required' => false,
  24. ),
  25. 'for_jt' => array(
  26. 'name' => 'Within job title',
  27. 'required' => false,
  28. ),
  29. 'for_com' => array(
  30. 'name' => 'Within company name',
  31. 'required' => false,
  32. ),
  33. 'for_loc' => array(
  34. 'name' => 'City, State, or ZIP code',
  35. 'required' => false,
  36. ),
  37. 'radius' => array(
  38. 'name' => 'Radius in miles',
  39. 'type' => 'list',
  40. 'required' => false,
  41. 'values' => array(
  42. 'Exact Location' => 'El',
  43. 'Within 5 miles' => '5',
  44. 'Within 10 miles' => '10',
  45. 'Within 20 miles' => '20',
  46. 'Within 30 miles' => '0',
  47. 'Within 40 miles' => '40',
  48. 'Within 50 miles' => '50',
  49. 'Within 75 miles' => '75',
  50. 'Within 100 miles' => '100',
  51. ),
  52. 'defaultValue' => '0',
  53. ),
  54. 'jtype' => array(
  55. 'name' => 'Job type',
  56. 'type' => 'list',
  57. 'required' => false,
  58. 'values' => array(
  59. 'Full-Time' => 'Full Time',
  60. 'Part-Time' => 'Part Time',
  61. 'Contract - Independent' => 'Contract Independent',
  62. 'Contract - W2' => 'Contract W2',
  63. 'Contract to Hire - Independent' => 'C2H Independent',
  64. 'Contract to Hire - W2' => 'C2H W2',
  65. 'Third Party - Contract - Corp-to-Corp' => 'Contract Corp-To-Corp',
  66. 'Third Party - Contract to Hire - Corp-to-Corp' => 'C2H Corp-To-Corp',
  67. ),
  68. 'defaultValue' => 'Full Time',
  69. ),
  70. 'telecommute' => array(
  71. 'name' => 'Telecommute',
  72. 'type' => 'checkbox',
  73. ),
  74. ));
  75. public function collectData() {
  76. $uri = 'https://www.dice.com/jobs/advancedResult.html';
  77. $uri .= '?for_one=' . urlencode($this->getInput('for_one'));
  78. $uri .= '&for_all=' . urlencode($this->getInput('for_all'));
  79. $uri .= '&for_exact=' . urlencode($this->getInput('for_exact'));
  80. $uri .= '&for_none=' . urlencode($this->getInput('for_none'));
  81. $uri .= '&for_jt=' . urlencode($this->getInput('for_jt'));
  82. $uri .= '&for_com=' . urlencode($this->getInput('for_com'));
  83. $uri .= '&for_loc=' . urlencode($this->getInput('for_loc'));
  84. if ($this->getInput('jtype')) {
  85. $uri .= '&jtype=' . urlencode($this->getInput('jtype'));
  86. }
  87. $uri .= '&sort=date&limit=100';
  88. $uri .= '&radius=' . urlencode($this->getInput('radius'));
  89. if ($this->getInput('telecommute')) {
  90. $uri .= '&telecommute=true';
  91. }
  92. $html = getSimpleHTMLDOM($uri)
  93. or returnServerError('Could not request Dice.');
  94. foreach($html->find('div.complete-serp-result-div') as $element) {
  95. $item = array();
  96. // Title
  97. $masterLink = $element->find('a[id^=position]', 0);
  98. $item['title'] = $masterLink->title;
  99. // URL
  100. $uri = $masterLink->href;
  101. // $uri = substr($uri, 0, strrpos($uri, '?'));
  102. $item['uri'] = substr($uri, 0, strrpos($uri, '?'));
  103. // ID
  104. $item['id'] = $masterLink->value;
  105. // Image
  106. $image = $element->find('img', 0);
  107. if ($image)
  108. $item['image'] = $image->getAttribute('src');
  109. // Content
  110. $shortdesc = $element->find('.shortdesc', '0');
  111. $shortdesc = ($shortdesc) ? $shortdesc->innertext : '';
  112. $item['content'] = $shortdesc;
  113. $this->items[] = $item;
  114. }
  115. }
  116. }