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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. default:
  108. $this->warnings = "No call type specified";
  109. }
  110. }
  111. //setup old (maintains the original mini api)
  112. function setup_old (){
  113. //Grab the postcode and area size from the get string
  114. if (!isset($_GET['area_size'])){ //check is_numeric and isn't too big
  115. array_push($this->warnings, "No area size specified");
  116. }
  117. if (sizeof($this->warnings) == 0){
  118. //Get OS ref from postcode
  119. if (isset($_GET['postcode'])) {
  120. $xy = postcode_to_location($_GET['postcode']);
  121. $this->easting = $xy[0];
  122. $this->northing = $xy[1];
  123. } else {
  124. $latlng = new LatLng($_GET['lat'], $_GET['lng']);
  125. $xy = $latlng->toOSRef();
  126. $this->easting = $xy->easting;
  127. $this->northing = $xy->northing;
  128. }
  129. $this->area_size = $_GET['area_size'];
  130. $this->applications = Applications::query($this->easting, $this->northing, alert_size_to_meters($this->area_size));
  131. }
  132. }
  133. //Bind
  134. function bind () {
  135. //page vars
  136. $form_action = $_SERVER['PHP_SELF'];
  137. header("Content-Type: text/xml");
  138. //smarty
  139. $smarty = new Smarty;
  140. $smarty->force_compile = true;
  141. $smarty->compile_dir = SMARTY_COMPILE_DIRECTORY;
  142. $smarty->assign("warnings", $this->warnings);
  143. $smarty->assign("applications", $this->applications);
  144. //Render
  145. $smarty->display('rss.tpl');
  146. }
  147. //howto
  148. function howto() {
  149. $form_action = $_SERVER['PHP_SELF'];
  150. $smarty = new Smarty;
  151. $smarty->force_compile = true;
  152. $smarty->compile_dir = SMARTY_COMPILE_DIRECTORY;
  153. $smarty->assign("page_title","API");
  154. $smarty->assign("menu_item","api");
  155. $smarty->display('apihowto.tpl');
  156. }
  157. }
  158. ?>