| 1 |
<?php // $Id: geo.module,v 1.29 2009/11/17 19:07:21 vauxia Exp $ |
<?php // $Id: geo.module,v 1.30 2009/11/17 22:09:57 vauxia Exp $ |
| 2 |
|
|
| 3 |
/** |
/** |
| 4 |
* Geo: Geospatial storage and retrieval. |
* Geo: Geospatial storage and retrieval. |
| 109 |
} |
} |
| 110 |
|
|
| 111 |
/** |
/** |
| 112 |
|
* API Function: Return a list of CCK fields that contain geospatial data. |
| 113 |
|
*/ |
| 114 |
|
function geo_fields($reset = FALSE) { |
| 115 |
|
static $fields; |
| 116 |
|
if (!$reset || !isset($fields)) { |
| 117 |
|
$field_types = geo_field_types(); |
| 118 |
|
$fields = array(); |
| 119 |
|
if (function_exists('content_fields')) { |
| 120 |
|
foreach (content_fields() as $field) { |
| 121 |
|
if (in_array($field['type'], $field_types)) { |
| 122 |
|
$fields[$field['field_name']] = array( |
| 123 |
|
'label' => $field['widget']['label'], |
| 124 |
|
'gis type' => $field['geo_type'], |
| 125 |
|
'srid' => $field['srid'] ? $field['srid'] : GEO_SRID_DEFAULT, |
| 126 |
|
'module' => $field['module'], |
| 127 |
|
'gis format' => 'wkb', // TODO hard-coded. |
| 128 |
|
); |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
|
} |
| 132 |
|
} |
| 133 |
|
return $fields; |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
/** |
| 137 |
* Implementation of hook_content_fieldapi(). |
* Implementation of hook_content_fieldapi(). |
| 138 |
*/ |
*/ |
| 139 |
function geo_content_fieldapi($op, $field) { |
function geo_content_fieldapi($op, $field) { |
| 232 |
* Implementation of hook_nodeapi(). |
* Implementation of hook_nodeapi(). |
| 233 |
*/ |
*/ |
| 234 |
function geo_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
function geo_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
| 235 |
// Append microformats onto geo node feeds. |
|
| 236 |
if ($op == 'rss item' && isset($node->geo_fields)) { |
switch ($op) { |
| 237 |
$rss = array(); |
|
| 238 |
foreach ($node->geo_fields as $field_name => $type) { |
case 'rss item': |
| 239 |
foreach ($node->$field_name as $item) { |
// Append microformats on geo node feeds. |
| 240 |
$rss[] = geo('rss_item', $item['wkb']); |
$rss = array(); |
| 241 |
|
foreach (geo_fields() as $field_name => $field) { |
| 242 |
|
if (!isset($node->$field_name)) continue; |
| 243 |
|
|
| 244 |
|
foreach ($node->$field_name as $item) { |
| 245 |
|
$rss[] = geo('rss_item', $item['wkb']); |
| 246 |
|
} |
| 247 |
} |
} |
| 248 |
} |
return $rss; |
| 249 |
return $rss; |
|
| 250 |
|
case 'view': |
| 251 |
|
// Add a #pre_render callback to convert geo values to a format |
| 252 |
|
// understood by the theme function in use by that field. |
| 253 |
|
$node->content['#pre_render'][] = 'geo_field_convert_value'; |
| 254 |
|
return; |
| 255 |
} |
} |
| 256 |
} |
} |
| 257 |
|
|
| 267 |
); |
); |
| 268 |
} |
} |
| 269 |
|
|
|
function theme_geo_fields($element) { |
|
|
return isset($element['#children']) ? $element['#children'] : ''; |
|
|
} |
|
|
|
|
| 270 |
/** |
/** |
| 271 |
* A #process handler for the latlon element. |
* A #process handler for the latlon element. |
| 272 |
*/ |
*/ |
| 290 |
return $element; |
return $element; |
| 291 |
} |
} |
| 292 |
|
|
|
function theme_geo_latlon($element) { |
|
|
$output = '<div class="container-inline">'. $element['#children'] .'</div>'; |
|
|
return theme('form_element', $element, $output); |
|
|
} |
|
|
|
|
| 293 |
function geo_value_convert($value, $in = 'array', $out = 'wkt') { |
function geo_value_convert($value, $in = 'array', $out = 'wkt') { |
| 294 |
// TODO We are taking the element's requested input and output formats, and |
// TODO We are taking the element's requested input and output formats, and |
| 295 |
// making the necessary adjustments. This needs to be refactored and set up |
// making the necessary adjustments. This needs to be refactored and set up |
| 333 |
return $inputs; |
return $inputs; |
| 334 |
} |
} |
| 335 |
|
|
| 336 |
function geo_set_pre_render(&$element) { |
function geo_field_convert_value(&$element) { |
|
if (!isset($element['#pre_render']) |
|
|
|| !in_array('geo_field_convert_value', $element['#pre_render'])) { |
|
|
$element['#pre_render'][] = 'geo_field_convert_value'; |
|
|
} |
|
|
} |
|
|
|
|
|
function geo_field_convert_value($element) { |
|
| 337 |
foreach (element_children($element) as $key) { |
foreach (element_children($element) as $key) { |
| 338 |
if (isset($element[$key]['field']) && $element[$key]['field']['#access']) { |
if (isset($element[$key]['field']) && $element[$key]['field']['#access']) { |
| 339 |
$field = $element[$key]['field']; |
$field = $element[$key]['field']; |