/[drupal]/contributions/modules/georss/georss.module
ViewVC logotype

Contents of /contributions/modules/georss/georss.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Tue Sep 22 18:53:33 2009 UTC (2 months ago) by rsoden
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +86 -130 lines
File MIME type: text/x-php
merging fixes from 6-1 into HEAD
1 <?php
2 // $Id: georss.module,v 1.9.2.4 2009/09/22 18:49:57 rsoden Exp $
3
4 /**
5 * @file
6 * GeoRSS module to add geo data from CCK fields to the RSS feed
7 */
8
9 /**
10 * Implementation of hook_menu().
11 */
12 function georss_menu() {
13 $items = array();
14 $items['admin/settings/georss'] = array(
15 'title' => 'GeoRSS Settings',
16 'page callback' => 'drupal_get_form',
17 'page arguments' => array('georss_settings_form'),
18 'access callback' => 'user_access',
19 'access arguments' => array('administer nodes'),
20 'type' => MENU_NORMAL_ITEM,
21 );
22 return $items;
23 }
24
25 /**
26 * Implementation of hook_theme().
27 */
28 function georss_theme() {
29 return array(
30 'georss_point' => array(),
31 );
32 }
33
34 /**
35 * GeoRSS settings form
36 */
37 function georss_settings_form(&$form_state) {
38 $settings = variable_get('georss_forms', array());
39 $fields = content_fields();
40 $options = array();
41 foreach ($fields as $field) {
42 $options[$field['field_name']] = $field['widget']['label'];
43 }
44 if (empty($options)) {
45 drupal_set_message(t('To use the module, first you need to !createfields on the desired content-type to store latitude and longitude data.', array('!createfields' => l('create CCK fields', 'admin/content/types'))), 'warning');
46 }
47
48 $form = array();
49 $form['georss_forms'] = array(
50 '#type' => 'fieldset',
51 '#title' => t('Sources of Geo Data for RSS Feeds'),
52 '#tree' => TRUE,
53 );
54 $form['georss_forms']['format'] = array(
55 '#type' => 'select',
56 '#title' => t('Format'),
57 '#options' => array('simple' => t('GeoRSS-Simple'), 'gml' => t('GeoRSS-GML')),
58 '#default_value' => isset($settings['format']) ? $settings['format'] : 'simple',
59 );
60 $form['georss_forms']['field_lat'] = array(
61 '#type' => 'select',
62 '#title' => t('Latitude'),
63 '#options' => $options,
64 '#default_value' => isset($settings['field_lat']) ? $settings['field_lat'] : '',
65 );
66 $form['georss_forms']['field_lon'] = array(
67 '#type' => 'select',
68 '#title' => t('Longitude'),
69 '#options' => $options,
70 '#default_value' => isset($settings['field_lon']) ? $settings['field_lon'] : '',
71 );
72 return system_settings_form($form);
73 }
74
75 /**
76 * Implementation of hook_nodeapi().
77 */
78 function georss_nodeapi($node, $op) {
79 switch ($op) {
80 case 'rss item':
81 $georss_settings = variable_get('georss_forms', FALSE);
82 if ($georss_settings !== FALSE) {
83 if (isset($node->$georss_settings['field_lat']) && isset($node->$georss_settings['field_lon'])) {
84 $lon = $node->$georss_settings['field_lon'];
85 $lat = $node->$georss_settings['field_lat'];
86 if (!is_null($node->$georss_settings['field_lon']) && !is_null($node->$georss_settings['field_lat'])) {
87 $items[] = theme_georss_point($lat['0']['value'], $lon['0']['value'], $georss_settings['format']);
88 }
89
90 unset($node->content[$georss_settings['field_lon']]);
91 unset($node->content[$georss_settings['field_lat']]);
92
93 return $items;
94 }
95 }
96 break;
97 }
98 }
99
100 /**
101 * Theme GeoRSS points
102 */
103 function theme_georss_point($lat, $lon, $format) {
104 $output = array();
105 switch ($format) {
106 case 'gml':
107 $output['key'] = 'georss:where';
108 $output['namespace'] = array(
109 'xmlns:georss' => 'http://www.georss.org/georss',
110 'xmlns:gml' => 'http://www.opengis.net/gml'
111 );
112 $output['value'] = array(
113 'gml:Point' => array(
114 'gml:pos' => "$lat $lon"
115 ),
116 );
117 break;
118 case 'simple':
119 $output['key'] = 'georss:point';
120 $output['namespace'] = array('xmlns:georss' => 'http://www.georss.org/georss');
121 $output['value'] = "$lat $lon";
122 break;
123 }
124 return $output;
125 }

  ViewVC Help
Powered by ViewVC 1.1.2