Automatically exported from code.google.com/p/planningalerts
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
16 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
17 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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['top_right_lat'], $_GET['top_right_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. case "areaos":
  98. //validation
  99. if(!isset($_GET['bottom_left_easting']) || !isset($_GET['bottom_left_northing']) || !isset($_GET['top_right_easting']) || !isset($_GET['top_right_northing'])){
  100. array_push($this->warnings, "Bounding box was not specified");
  101. }
  102. //all good, get the data
  103. if(sizeof($this->warnings) == 0){
  104. $this->applications = Applications::query_area($_GET['bottom_left_easting'], $_GET['bottom_left_northing'], $_GET['top_right_easting'], $_GET['top_right_easting']);
  105. }
  106. break;
  107. case "latest":
  108. $this->applications = Applications::query_latest(500);
  109. break;
  110. default:
  111. $this->warnings = "No call type specified";
  112. }
  113. }
  114. //setup old (maintains the original mini api)
  115. function setup_old (){
  116. //Grab the postcode and area size from the get string
  117. if (!isset($_GET['area_size'])){ //check is_numeric and isn't too big
  118. array_push($this->warnings, "No area size specified");
  119. }
  120. if (sizeof($this->warnings) == 0){
  121. //Get OS ref from postcode
  122. if (isset($_GET['postcode'])) {
  123. $xy = postcode_to_location($_GET['postcode']);
  124. $this->easting = $xy[0];
  125. $this->northing = $xy[1];
  126. } else {
  127. $latlng = new LatLng($_GET['lat'], $_GET['lng']);
  128. $xy = $latlng->toOSRef();
  129. $this->easting = $xy->easting;
  130. $this->northing = $xy->northing;
  131. }
  132. $this->area_size = $_GET['area_size'];
  133. $this->applications = Applications::query($this->easting, $this->northing, alert_size_to_meters($this->area_size));
  134. }
  135. }
  136. //Bind
  137. function bind () {
  138. //page vars
  139. $form_action = $_SERVER['PHP_SELF'];
  140. header("Content-Type: text/xml");
  141. //smarty
  142. $smarty = new Smarty;
  143. $smarty->force_compile = true;
  144. $smarty->compile_dir = SMARTY_COMPILE_DIRECTORY;
  145. $smarty->assign("warnings", $this->warnings);
  146. $smarty->assign("applications", $this->applications);
  147. //Render
  148. $smarty->display('rss.tpl');
  149. }
  150. //howto
  151. function howto() {
  152. $form_action = $_SERVER['PHP_SELF'];
  153. $smarty = new Smarty;
  154. $smarty->force_compile = true;
  155. $smarty->compile_dir = SMARTY_COMPILE_DIRECTORY;
  156. $smarty->assign("page_title","API");
  157. $smarty->assign("menu_item","api");
  158. $smarty->display('apihowto.tpl');
  159. }
  160. }
  161. ?>