Automatically exported from code.google.com/p/planningalerts
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
17 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. require_once ("config.php");
  3. require_once ("phpcoord.php");
  4. $api = new api;
  5. class api {
  6. //Properties
  7. var $warnings = array();
  8. var $applications;
  9. //Constructor
  10. function api() {
  11. if (isset($_GET['howto'])){
  12. redirect("apihowto.php");//this handles old links to this page
  13. exit;
  14. } else {
  15. if(isset($_GET['call'])){
  16. $this->setup();
  17. }else{
  18. $this->setup_old();
  19. }
  20. $this->bind();
  21. }
  22. }
  23. //setup
  24. function setup(){
  25. //get the call type
  26. $call = $_GET['call'];
  27. switch ($call) {
  28. case "postcode":
  29. if(!isset($_GET['area_size']) || !is_postcode($_GET['postcode'])){
  30. array_push($this->warnings, "No valid postcode specified");
  31. }
  32. if(!isset($_GET['area_size'])){
  33. array_push($this->warnings, "Area size specified");
  34. }
  35. //all good, get the data
  36. if(sizeof($this->warnings) == 0){
  37. $xy = postcode_to_location($_GET['postcode']);
  38. $easting = $xy[0];
  39. $northing = $xy[1];
  40. $this->applications = Applications::query($easting, $northing, alert_size_to_meters($_GET['area_size']));
  41. }
  42. break;
  43. case "point":
  44. //validation
  45. if(!isset($_GET['lat']) || !isset($_GET['lng'])){
  46. array_push($this->warnings, "No longitude or latitude was specified");
  47. }
  48. if(!isset($_GET['area_size'])){
  49. array_push($this->warnings, "Area size specified");
  50. }
  51. //all good, get the data
  52. if(sizeof($this->warnings) == 0){
  53. $latlng = new LatLng($_GET['lat'], $_GET['lng']);
  54. $xy = $latlng->toOSRef();
  55. $easting = $xy->easting;
  56. $northing = $xy->northing;
  57. $this->applications = Applications::query($easting, $northing, alert_size_to_meters($_GET['area_size']));
  58. }
  59. break;
  60. case "pointos":
  61. //validation
  62. if(!isset($_GET['easting']) || !isset($_GET['northing'])){
  63. array_push($this->warnings, "No easting or northing was specified");
  64. }
  65. if(!isset($_GET['area_size'])){
  66. array_push($this->warnings, "Area size specified");
  67. }
  68. //all good, get the data
  69. if(sizeof($this->warnings) == 0){
  70. $this->applications = Applications::query($_GET['easting'], $_GET['northing'], alert_size_to_meters($_GET['area_size']));
  71. }
  72. break;
  73. case "authority":
  74. //validation
  75. if(!isset($_GET['authority'])){
  76. array_push($this->warnings, "No authority name specified");
  77. }
  78. //all good, get the data
  79. if(sizeof($this->warnings) == 0){
  80. $this->applications = Applications::query_authority($_GET['authority']);
  81. }
  82. break;
  83. case "area":
  84. //validation
  85. if(!isset($_GET['bottom_left_lat']) || !isset($_GET['bottom_left_lng']) || !isset($_GET['top_right_lat']) || !isset($_GET['top_right_lng'])){
  86. array_push($this->warnings, "Bounding box was not specified");
  87. }
  88. //all good, get the data
  89. if(sizeof($this->warnings) == 0){
  90. $bottom_left_latlng = new LatLng($_GET['bottom_left_lat'], $_GET['bottom_left_lng']);
  91. $bottom_left_xy = $bottom_left_latlng->toOSRef();
  92. $top_right_latlng = new LatLng($_GET['bottom_left_lat'], $_GET['bottom_left_lng']);
  93. $top_right_xy = $top_right_latlng->toOSRef();
  94. $this->applications = Applications::query_area($bottom_left_xy->easting, $bottom_left_xy->northing, $top_right_xy->easting, $top_right_xy->northing);
  95. }
  96. break;
  97. default:
  98. $this->warnings = "No call type specified";
  99. }
  100. }
  101. //setup old (maintains the original mini api)
  102. function setup_old (){
  103. //Grab the postcode and area size from the get string
  104. if (!isset($_GET['area_size'])){ //check is_numeric and isn't too big
  105. array_push($this->warnings, "No area size specified");
  106. }
  107. if (sizeof($this->warnings) == 0){
  108. //Get OS ref from postcode
  109. if (isset($_GET['postcode'])) {
  110. $xy = postcode_to_location($_GET['postcode']);
  111. $this->easting = $xy[0];
  112. $this->northing = $xy[1];
  113. } else {
  114. $latlng = new LatLng($_GET['lat'], $_GET['lng']);
  115. $xy = $latlng->toOSRef();
  116. $this->easting = $xy->easting;
  117. $this->northing = $xy->northing;
  118. }
  119. $this->area_size = $_GET['area_size'];
  120. $this->applications = Applications::query($this->easting, $this->northing, alert_size_to_meters($this->area_size));
  121. }
  122. }
  123. //Bind
  124. function bind () {
  125. //page vars
  126. $form_action = $_SERVER['PHP_SELF'];
  127. header("Content-Type: text/xml");
  128. //smarty
  129. $smarty = new Smarty;
  130. $smarty->force_compile = true;
  131. $smarty->compile_dir = SMARTY_COMPILE_DIRECTORY;
  132. $smarty->assign("warnings", $this->warnings);
  133. $smarty->assign("applications", $this->applications);
  134. //Render
  135. $smarty->display('rss.tpl');
  136. }
  137. //howto
  138. function howto() {
  139. $form_action = $_SERVER['PHP_SELF'];
  140. $smarty = new Smarty;
  141. $smarty->force_compile = true;
  142. $smarty->compile_dir = SMARTY_COMPILE_DIRECTORY;
  143. $smarty->assign("page_title","API");
  144. $smarty->assign("menu_item","api");
  145. $smarty->display('apihowto.tpl');
  146. }
  147. }
  148. ?>