| 1 |
<?php // $Id: geo.module,v 1.24 2009/06/25 19:07:54 vauxialwExp $ |
<?php // $Id: geo.module,v 1.25 2009/08/05 02:15:54 vauxia Exp $ |
| 2 |
|
|
| 3 |
/** |
/** |
| 4 |
* Geo: Geospatial storage and retrieval. |
* Geo: Geospatial storage and retrieval. |
| 65 |
'arguments' => array('element' => NULL), |
'arguments' => array('element' => NULL), |
| 66 |
'file' => 'geo.formatters.inc', |
'file' => 'geo.formatters.inc', |
| 67 |
'path' => $file_path, |
'path' => $file_path, |
| 68 |
|
'gis input' => 'wkt', |
| 69 |
), |
), |
| 70 |
'geo_formatter_lat' => array( |
'geo_formatter_lat' => array( |
| 71 |
'arguments' => array('element' => NULL), |
'arguments' => array('element' => NULL), |
| 72 |
'file' => 'geo.formatters.inc', |
'file' => 'geo.formatters.inc', |
| 73 |
'path' => $file_path, |
'path' => $file_path, |
| 74 |
|
'gis input' => 'array', |
| 75 |
), |
), |
| 76 |
'geo_formatter_lon' => array( |
'geo_formatter_lon' => array( |
| 77 |
'arguments' => array('element' => NULL), |
'arguments' => array('element' => NULL), |
| 78 |
'file' => 'geo.formatters.inc', |
'file' => 'geo.formatters.inc', |
| 79 |
'path' => $file_path, |
'path' => $file_path, |
| 80 |
|
'gis input' => 'array', |
| 81 |
), |
), |
| 82 |
'geo_formatter_georss' => array( |
'geo_formatter_georss' => array( |
| 83 |
'arguments' => array('element' => NULL), |
'arguments' => array('element' => NULL), |
| 84 |
'file' => 'geo.formatters.inc', |
'file' => 'geo.formatters.inc', |
| 85 |
'path' => $file_path, |
'path' => $file_path, |
| 86 |
|
'gis input' => 'array', |
| 87 |
), |
), |
| 88 |
'geo_formatter_svg' => array( |
'geo_formatter_svg' => array( |
| 89 |
'arguments' => array('element' => NULL), |
'arguments' => array('element' => NULL), |
| 243 |
* Implementation of hook_nodeapi(). |
* Implementation of hook_nodeapi(). |
| 244 |
*/ |
*/ |
| 245 |
function geo_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
function geo_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { |
|
if ($op == 'view') { |
|
|
if (isset($node->geo_fields)) { |
|
|
$types = _content_type_info(); |
|
|
$types = $types['field types']; |
|
|
foreach ($node->geo_fields as $f => $type) { |
|
|
// #formatter is in field['items'] for CONTENT_HANDLE_MODULE |
|
|
if (!$formatter = $node->content[$f]['field']['items']['#formatter']) { |
|
|
// #formatter is in field['items'][$delta] for CONTENT_HANDLE_CORE |
|
|
$formatter = $node->content[$f]['field']['items'][0]['#formatter']; |
|
|
} |
|
|
|
|
|
if ($input = $types[$type]['formatters'][$formatter]['gis input']) { |
|
|
foreach ($node->content[$f]['field']['items'] as $i => $item) { |
|
|
if (!is_array($item)) continue; |
|
|
if (!isset($item['#item'][$input])) { |
|
|
$data = geo_wkb_get_data($item['#item']['wkb'], $input); |
|
|
$node->content[$f]['field']['items'][$i]['#item']['gis type'] = $data['type']; |
|
|
$node->content[$f]['field']['items'][$i]['#item'][$input] = $data['value']; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
| 246 |
// Append microformats onto geo node feeds. |
// Append microformats onto geo node feeds. |
| 247 |
if ($op == 'rss item' && isset($node->geo_fields)) { |
if ($op == 'rss item' && isset($node->geo_fields)) { |
| 248 |
$rss = array(); |
$rss = array(); |
| 353 |
); |
); |
| 354 |
return $inputs; |
return $inputs; |
| 355 |
} |
} |
| 356 |
|
|
| 357 |
|
function geo_set_pre_render(&$element) { |
| 358 |
|
if (!isset($element['#pre_render']) |
| 359 |
|
|| !in_array('geo_field_convert_value', $element['#pre_render'])) { |
| 360 |
|
$element['#pre_render'][] = 'geo_field_convert_value'; |
| 361 |
|
} |
| 362 |
|
} |
| 363 |
|
|
| 364 |
|
function geo_field_convert_value($element) { |
| 365 |
|
foreach (element_children($element) as $key) { |
| 366 |
|
if (isset($element[$key]['field']) && $element[$key]['field']['#access']) { |
| 367 |
|
$field = $element[$key]['field']; |
| 368 |
|
$theme = $field['#single'] ? $field['items'][0]['#theme'] : $field['items']['#theme']; |
| 369 |
|
foreach ($field['items'] as $i => $item) { |
| 370 |
|
if (is_array($item) && isset($item['#item'])) { |
| 371 |
|
$element[$key]['field']['items'][$i]['#item'] = geo_set_value($item['#item'], $theme); |
| 372 |
|
} |
| 373 |
|
} |
| 374 |
|
} |
| 375 |
|
} |
| 376 |
|
return $element; |
| 377 |
|
} |
| 378 |
|
|
| 379 |
|
function geo_set_value($item, $theme) { |
| 380 |
|
$registry = theme_get_registry(); |
| 381 |
|
if ($format = $registry[$theme]['gis input']) { |
| 382 |
|
$value = geo_wkb_get_data($item['wkb'], $format); |
| 383 |
|
$item[$format] = $value['value']; |
| 384 |
|
} |
| 385 |
|
return $item; |
| 386 |
|
} |