/[drupal]/contributions/modules/location/location_node.module
ViewVC logotype

Contents of /contributions/modules/location/location_node.module

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


Revision 1.6 - (show annotations) (download) (as text)
Mon Aug 31 22:09:35 2009 UTC (2 months, 3 weeks ago) by bdragon
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +77 -45 lines
File MIME type: text/x-php
WARNING -- PORT IN PROGRESS -- WARNING
This is a very very very preliminary port of some pieces of Location to D7.
There's a lot of work to do before this is remotely usable.
WARNING -- PORT IN PROGRESS -- WARNING


commit 9acd11c864797596209d5c12916e25e209a074cd
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 16:51:59 2009 -0500

    D7: Fix instance saving. I have now successfully put a location on a node in D7. (Of course there's a LOT to do still, but huzzah!)

commit 868ed6352debce3720e4093b50c42397e66cf991
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 16:40:22 2009 -0500

    Fix another class bug. Fix location fieldset theming (for a given value of "fix" of course)

commit d10a646b73da9c8b00c002a13483b986f0018340
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 16:31:43 2009 -0500

    D7: fix call to private api function that got renamed.

commit b79cea16e3c74d0cc7941cd4abcd3b616b793c9f
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 16:28:00 2009 -0500

    D7: Put locative information into the vertical tabs thingie.

commit bf4df441e08a2ba1a0b6164a3688aa2275607f79
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 16:19:10 2009 -0500

    D7: Fix class arrayness and remove a stray & to make PHP stop crashing.

commit be9d1114797319f0015c266f3f6d4a6d398fea2f
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 15:22:13 2009 -0500

    D7: files[] for location_node.

commit f6c32c64cb43f06fc5baca569826ccaf88b931c3
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 15:19:30 2009 -0500

    Fix infinite loops with drupal_render_children(). Remove the drupal_render() call at the end as well as it's nonsensical now and ALSO loops.

commit 125639604c4e5c29d03b3da9265b5fc766347794
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 15:18:10 2009 -0500

    D7 does not have an implicit #theme for elements anymore.

commit 4dcf85adcd30c0a53417fa3c53b2a4882b3cadf4
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 15:08:51 2009 -0500

    Use core's country list. (Which was pulled from location in the first place, hee hee)

commit ebb58524f2b9ef2eca7513971afbb9029743290f
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Mon Aug 31 14:59:53 2009 -0500

    D7: Remove location_default_country variable and use core's site_default_country variable instead.

commit 4cf3950e1a3fa1369ad5bdecac4c3649b2783f2a
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 17:34:26 2009 -0500

    Add warning.

commit 934fdd3aecb4435b7215705d72998b13439b0920
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 17:14:51 2009 -0500

    D7: hook_node split, some of location_node.module, add file to track API changes.

commit 9e69f25d971fa6b5623fb026d5cfd6dba2cc2d70
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 16:17:18 2009 -0500

    D7: 'file' / 'file_path' stuff got rolled back.

commit 80cbd3b688c4a46dc349d449a1abc265894d619f
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 15:42:45 2009 -0500

    D7: [#161301]

commit 35f82a0845ef020411a351fb307f821f78c5e397
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 15:38:53 2009 -0500

    bit more dbtngification.

commit 161280467e70664822e397405f3892628de7acdd
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 15:26:38 2009 -0500

    dbtngify uninstall hook. The rest I'll do later.

commit d6596a08f7a6a424df5109eafae3d7a5b7ce5522
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Fri Aug 28 15:20:52 2009 -0500

    DBTNGify location.module.
    Hopefully I didn't introduce bugs.

commit 6986ba94148c19d461808d61441c0033a4abfe31
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 16:02:59 2009 -0500

    Start a todo list.

commit 397adf2c619de9708e4135442204328aac7ae2d8
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 15:57:30 2009 -0500

    D7: Use '#markup' not '#value' for markup

commit c3fbd82f21e1af2f024871b247c01bc01ca71a7e
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 15:53:17 2009 -0500

    D7: The hook_menu() and hook_theme() "file" and "file path" keys have
    been removed.

commit cf8acf59887f73b997e50aedec95aa5a9784df84
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 15:51:55 2009 -0500

    D7: Module .info files must now specify all loadable code files
    explicitly.

commit f4cf33530c11406157745db44cfab0069287da36
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 15:51:01 2009 -0500

    D7: Permissions are required to have titles and descriptions.

commit 4a29c6fbafdc1ab106c95ed74df27f7dcfe03bca
Author: Brandon Bergren <bdragon@rtk0.net>
Date:   Wed Aug 19 15:41:46 2009 -0500

    Location HEAD starting point.
    Aug 19 2009 15:42
1 <?php
2 // $Id: location_node.module,v 1.5 2009/04/03 20:17:53 bdragon Exp $
3
4 /**
5 * @file
6 * Associate locations with nodes.
7 */
8
9 /**
10 * Implementation of hook_form_alter().
11 */
12 function location_node_form_alter(&$form, &$form_state, $form_id) {
13 if (!empty($form['#node_edit_form'])) {
14 // Add the Location fields on the Node edit form
15 $node = $form['#node'];
16 $settings = variable_get('location_settings_node_'. $node->type, array());
17 if (isset($settings['multiple']['max']) && $settings['multiple']['max'] > 0) {
18 $locations = isset($node->locations) ? $node->locations : array();
19 $form['locations'] = location_form($settings, $locations);
20 }
21 }
22 }
23
24 /**
25 * Implementation of hook_node_delete_revision().
26 */
27 function location_node_node_delete_revision($node) {
28 $locations = array();
29 location_save_locations($locations, array('vid' => $node->vid));
30 }
31
32 /**
33 * Implementation of hook_node_delete().
34 */
35 function location_node_node_delete($node) {
36 $locations = array();
37 location_save_locations($locations, array('nid' => $node->nid));
38 }
39
40 /**
41 * Implementation of hook_node_load().
42 */
43 function location_node_node_load($nodes, $types) {
44 // @@@ Resurrect the behavior from way back (1.x/2.x) that disabled existing
45 // locations when the content type wasn't enabled for locations?
46 // @@@TODO 7.x -- multiload version!
47 foreach (array_keys($nodes) as $nid) {
48 $nodes[$nid]->locations = location_load_locations($nodes[$nid]->vid);
49 // @@@TODO 7.x -- Either reimplement or cut $node->location.
50 }
51 }
52
53 /**
54 * Implementation of hook_node_insert().
55 */
56 function location_node_node_insert($node) {
57 if (!empty($node->locations)) {
58 location_save_locations($node->locations, array('nid' => $node->nid, 'vid' => $node->vid));
59 }
60 }
61
62 /**
63 * Implementation of hook_node_update().
64 */
65 function location_node_node_update($node) {
66 return location_node_node_insert($node);
67 }
68
69 /**
70 * Implementation of hook_node_view().
71 */
72 function location_node_node_view($node, $build_mode) {
73 // @@@TODO 7.x Switch to a pure "fields" approach?
74 if (empty($node->locations)) {
75 return;
76 }
77
78 // @@@TODO 7.x -- TEST THIS!
79 if ($build_mode == 'rss') {
80 $settings = variable_get('location_settings_node_'. $node->type, array());
81 $mode = isset($settings['rss']['mode']) ? $settings['rss']['mode'] : 'simple';
82 if ($mode == 'none') {
83 return;
84 }
85 if (is_array($node->locations) && !empty($node->locations)) {
86 require_once(drupal_get_path('module', 'location') .'/location.georss.inc');
87 $node->rss_namespaces += location_rss_namespaces($mode);
88 foreach ($node->locations as $location) {
89 if (($item = location_rss_item($location, $mode))) {
90 $node->rss_elements[] = $item;
91 }
92 }
93 }
94 }
95 else {
96 // @@@TODO 7.x -- location_display_location is idiotic. KILL IT.
97 if (variable_get('location_display_location', 1)) {
98 $settings = variable_get('location_settings_node_'. $node->type, array());
99 if (isset($settings['display']['teaser']) && isset($settings['display']['full'])) {
100 if (($a3 && $settings['display']['teaser']) || (!$a3 && $settings['display']['full'])) {
101 $node->content['locations'] = location_display($settings, $node->locations);
102 }
103 }
104 }
105 }
106
107 }
108
109 /**
110 * Implementation of hook_locationapi().
111 */
112 function location_node_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
113 switch ($op) {
114 case 'instance_links':
115 foreach ($obj as $k => $v) {
116 if ($v['nid'] != 0) {
117 $node = node_load($v['nid']);
118 $obj[$k]['href'] = 'node/'. $v['nid'];
119 $obj[$k]['title'] = $node->title;
120 $obj[$k]['type'] = t('Node location');
121 }
122 }
123 }
124 }
125
126 /**
127 * Alter the node_type_form form.
128 */
129 function location_node_form_node_type_form_alter(&$form, &$form_state) {
130 $type = $form['#node_type']->type;
131
132 // Hook the form handlers so we can correctly extract our information;
133 // the node type form doesn't handle nested values correctly.
134 array_unshift($form['#validate'], 'location_node_settings_validate');
135 //array_unshift($form['#submit'], 'node_type_form_submit');
136 array_unshift($form['#submit'], '_location_node_type_save_submit');
137
138 $settings = variable_get('location_settings_node_'. $type, array());
139 $form['location_settings'] = location_settings($settings);
140 $form['location_settings']['#group'] = 'additional_settings';
141
142 // Tack on customizations for node settings.
143 $form['location_settings']['display']['teaser'] = array(
144 '#type' => 'checkbox',
145 '#title' => t('Display location in teaser view'),
146 '#default_value' => isset($settings['display']['teaser']) ? $settings['display']['teaser'] : TRUE,
147 '#weight' => -2,
148 );
149 $form['location_settings']['display']['full'] = array(
150 '#type' => 'checkbox',
151 '#title' => t('Display location in full view'),
152 '#default_value' => isset($settings['display']['full']) ? $settings['display']['full'] : TRUE,
153 '#weight' => -1,
154 );
155 $form['location_settings']['rss'] = array(
156 '#type' => 'fieldset',
157 '#title' => t('RSS Settings'),
158 '#description' => t('Here, you can change how locative data affects RSS feeds on nodes.'),
159 '#collapsible' => TRUE,
160 '#collapsed' => TRUE,
161 '#tree' => TRUE,
162 '#weight' => 5,
163 );
164 $form['location_settings']['rss']['mode'] = array(
165 '#type' => 'select',
166 '#title' => t('RSS mode'),
167 '#description' => t('Select how to use locations in RSS feeds for this content type.'),
168 '#options' => array(
169 'none' => t('None (Do not put locational data in RSS feeds)'),
170 'w3c' => t('W3C Geo (deprecated)'),
171 'w3c_bugcompat' => t('Location 1.x-2.x compatible (buggy W3C)'),
172 'simple' => t('GeoRSS-Simple'),
173 'gml' => t('GeoRSS GML'),
174 ),
175 '#default_value' => isset($settings['rss']['mode']) ? $settings['rss']['mode'] : 'simple',
176 );
177
178 // Make the weights inaccessible if CCK is being used.
179 if (module_exists('content')) {
180 $form['location_settings']['form']['weight']['#type'] = 'value';
181 $form['location_settings']['form']['weight']['#value'] = $form['location_settings']['form']['weight']['#default_value'];
182 $form['location_settings']['display']['weight']['#type'] = 'value';
183 $form['location_settings']['display']['weight']['#value'] = $form['location_settings']['display']['weight']['#default_value'];
184 }
185
186 // @@@ THIS IS NOT GOOD. --Bdragon
187 // clear the views cache in case anything was changed
188 if (function_exists('views_invalidate_cache')) {
189 views_invalidate_cache();
190 }
191 }
192
193 /**
194 * Validation function for node settings form.
195 * Logically, the default number of locations per node cannot
196 * be bigger than the max locations.
197 *
198 * @ingroup $form
199 */
200 function location_node_settings_validate($form, &$form_state) {
201 if (!empty($form_state['values']['location_settings']['multiple']['max']) && empty($form_state['values']['location_settings']['multiple']['add'])) {
202 form_error($form['location_settings']['multiple']['add'], t("You must have at least one empty location form enabled if you are going to allow locations to be submitted for nodes of this content type. If you don't intend to allow locations to be submitted for nodes of this content type, set the maximum number of locations allowed for this content type to 0."));
203 }
204 elseif ($form_state['values']['location_settings']['multiple']['max'] > 0) {
205 if ($form_state['values']['location_settings']['multiple']['add'] > $form_state['values']['location_settings']['multiple']['max']) {
206 form_error($form['location_settings']['multiple']['add'], t("You can't show more empty location forms than the maximum number of locations allowed for this content type."));
207 }
208 }
209 }
210
211 /**
212 * Custom submit function to save location settings properly.
213 */
214 function _location_node_type_save_submit($form, &$form_state) {
215 variable_set('location_settings_node_'. $form_state['values']['type'], $form_state['values']['location_settings']);
216
217 // @@@ Backwards compatibility variables.
218 // There are a few places in contrib where these variables are checked.
219 variable_set('location_maxnum_'. $form_state['values']['type'], $form_state['values']['location_settings']['multiple']['max']);
220 variable_set('location_defaultnum_'. $form_state['values']['type'], $form_state['values']['location_settings']['multiple']['add']);
221
222 // Prevent the "normal" submit handler from stomping our variable.
223 unset($form_state['values']['location_settings']);
224 }
225
226 /**
227 * Alter the content_field_overview_form form.
228 */
229 function location_node_form_content_field_overview_form_alter(&$form, &$form_state) {
230 $form['#submit'][] = 'location_node_content_extra_save';
231 }
232
233 /**
234 * Implementation of hook_content_extra_fields().
235 *
236 * For being able to edit location weight in node forms and node view.
237 */
238 function location_node_content_extra_fields($type_name) {
239 $settings = variable_get('location_settings_node_'. $type_name, array());
240 if (isset($settings['multiple']) && $settings['multiple']['max'] > 0) {
241 $weight = isset($settings['form']['weight']) ? $settings['form']['weight'] : 0;
242 $extra['locations'] = array(
243 'label' => t('Locations'),
244 'description' => t('Node Locations module form.'),
245 'weight' => $weight,
246 );
247 return $extra;
248 }
249 }
250
251 /**
252 * Saving the fields management's weight for location node data in forms and node view
253 *
254 * @param $form
255 * @param $form_state
256 */
257 function location_node_content_extra_save($form, &$form_state) {
258 $type = $form['#type_name'];
259 // We need to stay in sync with CCK's idea of the weight.
260 $settings = variable_get('location_settings_node_'. $type, array());
261 if (isset($form_state['values']['locations'])) {
262 $settings['form']['weight'] = $form_state['values']['locations']['weight'];
263 $settings['display']['weight'] = $form_state['values']['locations']['weight'];
264 }
265 variable_set('location_settings_node_'. $type, $settings);
266 }

  ViewVC Help
Powered by ViewVC 1.1.2