location.de.inc 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. function location_province_list_de() {
  3. return array(
  4. 'BB' => 'Brandenburg',
  5. 'BE' => 'Berlin',
  6. 'BW' => 'Baden-Württemberg',
  7. 'BY' => 'Bayern',
  8. 'HB' => 'Bremen',
  9. 'HE' => 'Hessen',
  10. 'HH' => 'Hamburg',
  11. 'MV' => 'Mecklenburg-Vorpommern',
  12. 'NI' => 'Niedersachsen',
  13. 'NW' => 'Nordrhein-Westfalen',
  14. 'RP' => 'Rheinland-Pfalz',
  15. 'SH' => 'Schleswig-Holstein',
  16. 'SL' => 'Saarland',
  17. 'SN' => 'Sachsen',
  18. 'ST' => 'Sachsen-Anhalt',
  19. 'TH' => 'Thüringen'
  20. );
  21. }
  22. /**
  23. * Parameters:
  24. * -> $location_a is an associative array that represents a full location where
  25. * 'street' => the street portions of the location
  26. * 'supplemental' => additional street portion of the location
  27. * 'province' => the province, state, or territory
  28. * 'country' => lower-cased two-letter ISO code (REQUIRED)
  29. * -> $location_b is associative array that represents a full location in the same way that
  30. * parameter $location_b does.
  31. *
  32. * Returns: a link to driving directions
  33. */
  34. function location_map_link_de($location = array(), $hide = array()) {
  35. $map_links = array();
  36. // For now, just call the suchen (tinfo) function. May want to make this configurable on some level
  37. // in order to maintain freedom of choice so users and site-admins don't have to be slaves
  38. // to tinfo!.... not that I have anything personal against tinfo!.
  39. if ($link = _location_map_link_de_suchen($location)) {
  40. $map_links['suchen'] = $link;
  41. }
  42. return $map_links;
  43. }
  44. function _location_map_link_de_suchen($location = array()) {
  45. $get_query = '?';
  46. $get_query .= 'where=';
  47. $query_parts = array();
  48. if (isset($location['street'])) {
  49. $query_parts[] = $location['street'];
  50. }
  51. if ($location['postal_code'] != '') {
  52. $query_parts[] = $location['postal_code'];
  53. }
  54. if ($location['city'] != '') {
  55. $query_parts[] = $location['city'];
  56. }
  57. // if ($location['number'] != '') {
  58. // $query_parts[] = $location['number'];
  59. // }
  60. $get_query .= urlencode(implode(', ', $query_parts));
  61. return ('http://www.suchen.de/lokalmap'. $get_query);
  62. }
  63. function location_map_link_de_providers() {
  64. return array(
  65. 'suchen' => array(
  66. 'name' => 'suchen.de (T-Info)',
  67. 'url' => 'http://www.suchen.de/',
  68. 'tos' => 'http://www.suchen.de/agb',
  69. ),
  70. 'google' => array(
  71. 'name' => 'Google Maps',
  72. 'url' => 'http://maps.google.com',
  73. 'tos' => 'http://www.google.com/help/terms_local.html',
  74. ),
  75. );
  76. }
  77. function location_map_link_de_default_providers() {
  78. return array('google');
  79. }
  80. /**
  81. * Parameters:
  82. * -> $location_a is an associative array that represents a full location where
  83. * 'street' => the street portions of the location
  84. * 'supplemental' => additional street portion of the location
  85. * 'province' => the province, state, or territory
  86. * 'country' => lower-cased two-letter ISO code (REQUIRED)
  87. * -> $location_b is associative array that represents a full location in the same way that
  88. * parameter $location_b does.
  89. *
  90. * Returns: a link to driving directions
  91. *
  92. * For now, assume site-admin wants driving directions linked to tinfo!
  93. * Maybe later, we can add some kind of country-specific settings page that allows the site-admin to
  94. * decide which site to link to for driving directions.
  95. */
  96. function location_driving_directions_link_de($location_a, $location_b) {
  97. return _location_driving_directions_link_de_suchen($location_a, $location_b);
  98. }
  99. /**
  100. * Parameters:
  101. * Function that is called by location_driving_directions_link_ca() under assumption that it
  102. * is the chosen function
  103. *
  104. * Returns:
  105. * a URL with HTTP GET variables
  106. * Depending on how full the locationes are, the URL will either point to the driving directions
  107. * on tinfo! or, if only partial locationes are provided, a URL that points to the *form* for
  108. * tinfo! driving directions where the form is filled with whatever fields have been provided
  109. * for the partial location(es).
  110. */
  111. function _location_driving_directions_link_de_suchen($location_a, $location_b) {
  112. foreach ($location_a as $field => $value) {
  113. $location_a[$field] = trim($value);
  114. }
  115. foreach ($location_b as $field => $value) {
  116. $location_b[$field] = trim($value);
  117. }
  118. if ($location_a['country'] == 'de' and $location_b['country'] == 'de') {
  119. $get_query = '?';
  120. // VON
  121. $query_parts = array();
  122. if (isset($location_a['street'])) {
  123. $query_parts[] = $location_a['street'];
  124. }
  125. if ($location_a['postal_code'] != '') {
  126. $query_parts[] = $location_a['postal_code'];
  127. }
  128. if ($location_a['city'] != '') {
  129. $query_parts[] = $location_a['city'];
  130. }
  131. $get_query .= 'route_from='. urlencode(implode(', ', $query_parts));
  132. // NACH
  133. $query_parts = array();
  134. if (isset($location_b['street'])) {
  135. $query_parts[] = $location_b['street'];
  136. }
  137. if ($location_b['postal_code'] != '') {
  138. $query_parts[] = $location_b['postal_code'];
  139. }
  140. if ($location_b['city'] != '') {
  141. $query_parts[] = $location_b['city'];
  142. }
  143. $get_query .= '&amp;route_to='. urlencode(implode(', ', $query_parts));
  144. return ('http://www.suchen.de/route'. $get_query);
  145. }
  146. }
  147. function location_map_link_de_google($location = array()) {
  148. $query_params = array();
  149. foreach (array('street', 'postal_code', 'city', 'country') as $field) {
  150. if (isset($location[$field])) {
  151. $query_params[] = $location[$field];
  152. }
  153. }
  154. if (count($query_params)) {
  155. return ('http://maps.google.com?q='. urlencode(implode(', ', $query_params)));
  156. }
  157. else {
  158. return NULL;
  159. }
  160. }
  161. function theme_location_de($location = array(), $hide = array()) {
  162. $output = '';
  163. if (count($location)) {
  164. $output .= "\n";
  165. $output .= '<div class="location vcard"><div class="adr">'."\n";
  166. if (!empty($location['name']) && !in_array('name', $hide)) {
  167. $output .= '<div class="fn">'. $location['name'] .'</div>';
  168. }
  169. if (!empty($location['street']) && !in_array('street', $hide)) {
  170. $output .= '<div class="street-address">'. $location['street'];
  171. if (!empty($location['additional']) && !in_array('street', $hide)) {
  172. $output .= ' '. $location['additional'];
  173. }
  174. $output .='</div>';
  175. }
  176. if ((!empty($location['city']) && !in_array('city', $hide)) ||
  177. (!empty($location['postal_codet']) && !in_array('postal_code', $hide))) {
  178. $city_postal = array();
  179. if (!empty($location['postal_code']) && !in_array('postal_code', $hide)) {
  180. $city_postal[] = '<span class="postal-code">'. $location['postal_code'] .'</span>';
  181. }
  182. if (!empty($location['city']) && !in_array('city', $hide)) {
  183. $city_postal[] = '<span class="locality">'. $location['city'] .'</span>';
  184. }
  185. $output .= '<div>'. implode(' ', $city_postal) .'</div>';
  186. }
  187. if (!in_array('country', $hide)) {
  188. $output .= '<div class="country-name">'. t('Germany') .'</div>';
  189. }
  190. if (location_has_coordinates($location)) {
  191. $output .= '<div class="geo"><abbr class="latitude" title="'. $location['latitude'] .'" /><abbr class="longitude" title="'. $location['latitude'] .'" /></div>';
  192. }
  193. $output .= '</div></div>';
  194. }
  195. return $output;
  196. }
  197. /**
  198. * Returns a lat/lon pair of the approximate center of the given postal code in the given country
  199. *
  200. * @param $location
  201. * An associative array $location where only postal code and country are necessary, but can have the keys:
  202. * 'street' => the street portion of the location
  203. * 'supplemental' => additional street portion of the location
  204. * 'province' => the province, state, or territory
  205. * 'country' => lower-cased two-letter ISO code (REQUIRED)
  206. * 'postal_code' => the international postal code for this location (REQUIRED)
  207. *
  208. * @return
  209. * An associative array where
  210. * 'lat' => approximate latitude of the center of the postal code's area
  211. * 'lon' => approximate longitude of the center of the postal code's area
  212. *
  213. */
  214. function location_get_postalcode_data_de($location = array()) {
  215. $dash_index = strpos($location['postal_code'], '-');
  216. // First we strip slash off if we're dealing with a 9-digit US zipcode
  217. if ($dash_index === FALSE) {
  218. $location['postal_code'] = substr($location['postal_code'], 0, $dash_index);
  219. }
  220. // Now we pad the thing and query.
  221. $row = db_query("SELECT * FROM {zipcodes} where country = :country AND zip = :zip", array(':country' => $location['country'], ':zip' => str_pad($location['postal_code'], 5, "0", STR_PAD_LEFT)))->fetchObject();
  222. if ($row) {
  223. return array('lat' => $row->latitude, 'lon' => $row->longitude, 'city' => $row->city, 'province' => $row->state, 'country' => $row->country);
  224. }
  225. else {
  226. return NULL;
  227. }
  228. }
  229. /**
  230. * Returns minimum and maximum latitude and longitude needed to create a bounding box.
  231. */
  232. function location_bounds_de() {
  233. return array(
  234. 'minlng' => 5.87225,
  235. 'minlat' => 47.2249,
  236. 'maxlng' => 15.04765,
  237. 'maxlat' => 55.0839,
  238. );
  239. }