Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. //
  3. // Scraper for Reigate & Banstead
  4. // Created by Matt Ford on Tue 2nd September 2008
  5. //
  6. // The script works according to requirements of PlanningAlerts.com
  7. //
  8. //Check a day is set and is valid
  9. $day = (isset($_GET['day']) && !empty($_GET['day']) && $_GET['day'] > 0 && $_GET['day'] < 32) ? $_GET['day'] : 1;
  10. //Check a month is set and is valid
  11. $month = (isset($_GET['month']) && !empty($_GET['month']) && $_GET['month'] > 0 && $_GET['month'] < 13) ? $_GET['month'] : 1;
  12. //Check a year is set and is valid
  13. $year = (isset($_GET['year']) && !empty($_GET['year']) && $_GET['year'] > 2003 && $_GET['year'] <= gmdate('Y')) ? $_GET['year'] : gmdate('Y');
  14. $xml = array( 'name' => 'Reigate and Banstead',
  15. 'full_name' => 'Reigate and Banstead Borough Council',
  16. 'url' => 'http://www.reigate-banstead.gov.uk/Planit2/planit2.jsp',
  17. 'detail_url' => 'http://www.reigate-banstead.gov.uk/Planit2/planit2.jsp?Controller=p2Controller&Action=FindApplicationByRefvalAction&REFVAL=',
  18. 'comments' => 'http://www.reigate-banstead.gov.uk/Planit2/planit2.jsp?Controller=p2Controller&Action=ShowCommentFormAction&REFVAL=');
  19. $months = array(
  20. '1' => 'JAN',
  21. '2' => 'FEB',
  22. '3' => 'MAR',
  23. '4' => 'APR',
  24. '5' => 'MAY',
  25. '6' => 'JUN',
  26. '7' => 'JUL',
  27. '8' => 'AUG',
  28. '9' => 'SEP',
  29. '10' => 'OCT',
  30. '11' => 'NOV',
  31. '12' => 'DEC');
  32. $month = $months[$month];
  33. $applications = array();
  34. function fetch_page($url) {
  35. if(!isset($ch)) {
  36. $ch = curl_init();
  37. }
  38. curl_setopt($ch, CURLOPT_URL, $url);
  39. curl_setopt($ch, CURLOPT_HEADER, 0);
  40. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  41. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  42. curl_setopt($ch, CURLOPT_REFERER, $url);
  43. $data = curl_exec($ch);
  44. return $data;
  45. }
  46. function parse_search($page = 1) {
  47. global $applications,$day,$month,$year,$xml;
  48. $start = ($page * 10) - 19;
  49. if($start < 0) $start = 1;
  50. if($page == '2') {
  51. $shown = 'Y';
  52. $start = 1;
  53. } else {
  54. $shown = 'N';
  55. }
  56. $url = $xml['url'].'?Controller=p2Controller&Action=FindApplicationsByDatesAction&START_DD='.$day.'&START_MMM='.$month.'&START_YYYY='.$year.'&END_DD='.$day.'&END_MMM='.$month.'&END_YYYY='.$year.'&WARD=ALL&CURR=&DECSN=&START_ROW='.$start.'&FIRST_TEN_SHOWN='.$shown.'&SEARCH_DIRECTION=F';
  57. //echo 'Loading page '.$page.' of data from URL:'.$url.'<br />';
  58. $data = explode('<div class="result">',fetch_page($url));
  59. unset($data[0]);
  60. foreach($data as $app) {
  61. $app = explode('</span>',$app);
  62. $AppNo = trim(strip_tags($app[0]));
  63. $applications[$AppNo]['AppNo'] = $AppNo;
  64. list($info,$address) = explode('<br/>',$app[2]);
  65. $applications[$AppNo]['Info'] = trim(strip_tags($info));
  66. $applications[$AppNo]['Address'] = trim(strip_tags($address));
  67. preg_match("/([A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2})/",$address,$PostCode);
  68. if(isset($PostCode[1])) {
  69. $applications[$AppNo]['PostCode'] = $PostCode[1];
  70. } else {
  71. $applications[$AppNo]['PostCode'] = false;
  72. }
  73. parse_detail($AppNo);
  74. }
  75. if(strpos($app[2],'alt="Next 10 applications"')) {
  76. parse_search($page+1);
  77. }
  78. }
  79. function parse_detail($AppNo) {
  80. global $applications,$xml;
  81. $url = $xml['detail_url'].$AppNo;
  82. list($junk,$DateRec) = explode('<th class="type">Date Received</th>',fetch_page($url));
  83. list($DateRec,$junk) = explode('</td>',$DateRec,2);
  84. $applications[$AppNo]['DateRec'] = date('d/m/Y',strtotime(trim(strip_tags($DateRec))));
  85. }
  86. parse_search();
  87. header("Content-Type: text/xml");
  88. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  89. echo "<planning>\n";
  90. echo "\t<authority_name>".$xml['full_name']."</authority_name>\n";
  91. echo "\t<authority_short_name>".$xml['name']."</authority_short_name>\n";
  92. echo "\t<applications>\n";
  93. foreach($applications as $application) {
  94. echo "\t\t<application>\n";
  95. echo "\t\t\t<council_reference>".$application['AppNo']."</council_reference>\n";
  96. echo "\t\t\t<address><![CDATA[".$application['Address']."]]></address>\n";
  97. echo "\t\t\t<postcode>".$application['PostCode']."</postcode>\n";
  98. echo "\t\t\t<description><![CDATA[".$application['Info']."]]></description>\n";
  99. echo "\t\t\t<info_url><![CDATA[".$xml['detail_url'].$application['AppNo']."]]></info_url>\n";
  100. echo "\t\t\t<comment_url><![CDATA[".$xml['comments'].$application['AppNo']."]]></comment_url>\n";
  101. echo "\t\t\t<date_received>".$application['DateRec']."</date_received>\n";
  102. echo "\t\t</application>\n";
  103. }
  104. echo "\t</applications>\n";
  105. echo "</planning>";
  106. ?>