/[drupal]/contributions/modules/location/location.admin.inc
ViewVC logotype

Contents of /contributions/modules/location/location.admin.inc

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


Revision 1.21 - (show annotations) (download) (as text)
Mon Aug 31 22:09:34 2009 UTC (2 months, 3 weeks ago) by bdragon
Branch: MAIN
CVS Tags: HEAD
Changes since 1.20: +16 -25 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.admin.inc,v 1.20 2009/04/17 19:09:53 bdragon Exp $
3
4 /**
5 * @file
6 * Admin forms for Location.
7 */
8
9 /**
10 * Admin settings form.
11 *
12 * @ingroup form
13 */
14 function location_admin_settings() {
15 // Recalculate the supported countries.
16 cache_clear_all('location:supported-countries', 'cache');
17 _location_supported_countries();
18
19 $iso_list_sorted = location_get_iso3166_list();
20 array_multisort($iso_list_sorted);
21 $iso_list_sorted = array_merge(array('' => ''), $iso_list_sorted);
22
23 $form = array();
24
25 // @@@TODO 7.x -- Verify integrity of site_default_country and direct user
26 // to the appropriate place to change it if necessary.
27
28 $form['location_display_location'] = array(
29 '#type' => 'radios',
30 '#title' => t('Toggle location display'),
31 '#default_value' => variable_get('location_display_location', 1),
32 '#options' => array(
33 0 => t('Disable the display of locations.'),
34 1 => t('Enable the display of locations.')
35 ),
36 '#description' => t('If you are interested in turning off locations and having a custom theme control their display, you may want to disable the display of locations so your theme can take that function.')
37 );
38
39 $form['location_usegmap'] = array(
40 '#type' => 'checkbox',
41 '#title' => t('Use a Google Map to set latitude and longitude '),
42 '#default_value' => variable_get('location_usegmap', FALSE),
43 '#description' => t('If the gmap.module is installed and <a href="@enabled">enabled</a>, and this setting is also turned on, users that are allowed to manually enter latitude/longitude coordinates will be able to do so with an interactive Google Map. You should also make sure you have entered a <a href="@google_maps_api_key">Google Maps API key</a> into your <a href="@gmap_module_settings">gmap module settings</a>.', array('@enabled' => url('admin/build/modules'), '@google_maps_api_key' => 'http://www.google.com/apis/maps', '@gmap_module_settings' => url('admin/settings/gmap'))),
44 // @@@ megapatch This is an idea, but I'd opt more for a warning here...
45 // '#disabled' => !module_exists('gmap'),
46 );
47
48 $form['location_locpick_macro'] = array(
49 '#type' => 'textfield',
50 '#title' => t('Location chooser macro'),
51 '#size' => 50,
52 '#maxlength' => 500,
53 '#default_value' => variable_get('location_locpick_macro', '[gmap]'),
54 '#description' => t('If you would like to change the macro used to generate the location chooser map, you can do so here. Note: Behaviors <em>locpick</em> and <em>collapsehack</em> are forced to be enabled and cannot be changed.'),
55 );
56
57 $form['location_jit_geocoding'] = array(
58 '#type' => 'checkbox',
59 '#title' => t('Enable JIT geocoding'),
60 '#default_value' => variable_get('location_jit_geocoding', FALSE),
61 '#description' => t('If you are going to be importing locations in bulk directly into the database, you may wish to enable JIT geocoding and load the locations with source set to 4 (LOCATION_LATLON_JIT_GEOCODING). The system will automatically geocode locations as they are loaded.'),
62 );
63
64 return system_settings_form($form);
65 }
66
67 /**
68 * Settings page for map links.
69 */
70 function location_map_link_options_form() {
71 $form = array();
72
73 $form['countries'] = array(
74 '#type' => 'markup',
75 '#markup' => ''
76 );
77
78 foreach (_location_supported_countries() as $country_iso => $country_name) {
79 location_load_country($country_iso);
80
81 $form['countries'][$country_iso] = array(
82 '#type' => 'markup',
83 '#markup' => ''
84 );
85
86 $form['countries'][$country_iso]['label_'. $country_iso] = array(
87 '#type' => 'markup',
88 '#markup' => $country_name
89 );
90
91 // Set up '#options' array for mapping providers for the current country
92 $mapping_options = array();
93 $provider_function = 'location_map_link_'. $country_iso .'_providers';
94 $default_provider_function = 'location_map_link_'. $country_iso .'_default_providers';
95 $checked = variable_get('location_map_link_'. $country_iso, function_exists($default_provider_function) ? $default_provider_function() : array());
96 //print "Calling provider function $provider_function";
97 if (function_exists($provider_function)) {
98 foreach ($provider_function() as $name => $details) {
99 $mapping_options[$name] = '<a href="'. $details['url'] .'">'. $details['name'] .'</a> (<a href="'. $details['tos'] .'">Terms of Use</a>)';
100 }
101 }
102
103 if (count($mapping_options)) {
104 $form['countries'][$country_iso]['location_map_link_'. $country_iso] = array(
105 '#title' => '',
106 '#type' => 'checkboxes',
107 '#default_value' => $checked,
108 '#options' => $mapping_options
109 );
110 }
111 else {
112 $form['countries'][$country_iso]['location_map_link_'. $country_iso] = array(
113 '#type' => 'markup',
114 '#markup' => t('None supported.')
115 );
116 }
117 }
118
119 $form = system_settings_form($form);
120 $form['#theme'] = 'location_map_link_options';
121 return $form;
122 }
123
124 function location_geocoding_options_form() {
125 $form = array();
126
127 $form['countries'] = array();
128
129 // First, we build two arrays to help us figure out on the fly whether a specific country is covered by a multi-country geocoder,
130 // and what the details of the multi-country geocoder are
131 // (1) Get list of geocoders
132 $general_geocoders_list = location_get_general_geocoder_list();
133
134 // (2) get data about each geocoder and the list of coutnries covered by each geocoder
135 $general_geocoders_data = array();
136 $general_geocoders_countries = array();
137 foreach ($general_geocoders_list as $geocoder_name) {
138 location_load_geocoder($geocoder_name);
139 $info_function = $geocoder_name .'_geocode_info';
140 if (function_exists($info_function)) {
141 $general_geocoders_data[$geocoder_name] = $info_function();
142 }
143
144 $countries_function = $geocoder_name .'_geocode_country_list';
145 if (function_exists($countries_function)) {
146 $general_geocoders_countries[$geocoder_name] = $countries_function();
147 }
148 }
149
150 foreach (_location_supported_countries() as $country_iso => $country_name) {
151 location_load_country($country_iso);
152
153 $geocoding_options = array();
154
155 $form['countries'][$country_iso] = array(
156 '#type' => 'markup',
157 '#value' => ''
158 );
159
160 $form['countries'][$country_iso]['label_'. $country_iso] = array(
161 '#type' => 'markup',
162 '#value' => '<div id="'. $country_iso .'">'. $country_name .'</div>'
163 );
164
165 // Next, we look for options presented by country specific providers
166 $country_specific_provider_function = 'location_geocode_'. $country_iso .'_providers';
167 if (function_exists($country_specific_provider_function)) {
168 foreach ($country_specific_provider_function() as $name => $details) {
169 $geocoding_options[$name .'|'. $country_iso] = '<a href="'. $details['url'] .'">'. $details['name'] .'</a> (<a href="'. $details['tos'] .'">Terms of Use</a>)';
170 }
171 }
172
173 foreach ($general_geocoders_list as $geocoder_name) {
174 if (in_array($country_iso, $general_geocoders_countries[$geocoder_name])) {
175 $geocoding_options[$geocoder_name] = '<a href="'. $general_geocoders_data[$geocoder_name]['url'] .'">'. $general_geocoders_data[$geocoder_name]['name'] .'</a> (<a href="'. $general_geocoders_data[$geocoder_name]['tos'] .'">Terms of Use</a>)';
176 }
177 }
178
179 if (count($geocoding_options)) {
180 $geocoding_options = array_merge(array('none' => t('None')), $geocoding_options);
181
182 $form['countries'][$country_iso]['location_geocode_'. $country_iso] = array(
183 '#type' => 'radios',
184 '#default_value' => variable_get('location_geocode_'. $country_iso, 'none'),
185 '#options' => $geocoding_options
186 );
187 }
188 else {
189 $form['countries'][$country_iso]['location_geocode_'. $country_iso] = array(
190 '#type' => 'markup',
191 '#markup' => t('None supported.')
192 );
193 }
194
195 $current_value = variable_get('location_geocode_'. $country_iso, 'none');
196 if ($current_value == 'none') {
197 $form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
198 '#type' => 'markup',
199 '#markup' => t('No service selected for country.')
200 );
201 }
202 else {
203 $current_val_chopped = substr($current_value, 0, strpos($current_value, '|'));
204 $geocode_settings_form_function_specific = 'location_geocode_'. $country_iso .'_'. $current_val_chopped .'_settings';
205 $geocode_settings_form_function_general = $current_value .'_geocode_settings';
206
207 if (function_exists($geocode_settings_form_function_specific)) {
208 $form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
209 '#type' => 'markup',
210 '#markup' => l(t('Configure parameters'), 'admin/settings/location/geocoding/'. $country_iso .'/'. $current_val_chopped)
211 );
212 }
213 elseif (function_exists($geocode_settings_form_function_general)) {
214 $form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
215 '#type' => 'markup',
216 '#markup' => l(t('Configure parameters'), 'admin/settings/location/geocoding/'. $country_iso .'/'. $current_value)
217 );
218 }
219 else {
220 $form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
221 '#type' => 'markup',
222 '#markup' => t('No configuration necessary for selected service.')
223 );
224 }
225 }
226 }
227 $form = system_settings_form($form);
228 $form['#theme'] = 'location_geocoding_options';
229 array_unshift($form['#submit'], 'location_geocoding_options_form_submit');
230
231 return $form;
232 }
233
234 function location_geocoding_options_form_submit($form, &$form_state) {
235 $general_geocoders = location_get_general_geocoder_list();
236 $general_geocoders_in_use = array();
237
238 foreach ($form_state['values'] as $key => $value) {
239 if (substr($key, 0, 17) == 'location_geocode_') {
240 if (in_array($value, $general_geocoders)) {
241 $general_geocoders_in_use[$value] = $value;
242 variable_set($key, $value);
243 }
244 }
245 }
246
247 variable_set('location_general_geocoders_in_use', $general_geocoders_in_use);
248 }
249
250 function theme_location_map_link_options(&$form) {
251 $header = array(array('align' => 'center', 'data' => '<center>'. t('Country') .'</center>'), array('align' => 'center', 'data' => '<center>'. t('Options') .'</center>'));
252 $rows = array();
253 foreach (element_children($form['countries']) as $country_iso) {
254 $row = array();
255 $row[] = array(
256 'data' => drupal_render($form['countries'][$country_iso]['label_'. $country_iso])
257 );
258 $row[] = array(
259 'data' => drupal_render($form['countries'][$country_iso]['location_map_link_'. $country_iso])
260 );
261 $rows[] = $row;
262 }
263 $output = theme('table', $header, $rows);
264 $output .= drupal_render_children($form);
265 return $output;
266 }
267
268 function theme_location_geocoding_options(&$form) {
269 $header = array(
270 array('align' => 'center', 'data' => '<center>'. t('Country') .'</center>'),
271 array('align' => 'center', 'data' => '<center>'. t('Options') .'</center>'),
272 array('align' => 'center', 'data' => '<center>'. t('Configure') .'</center>')
273 );
274 $rows = array();
275 foreach (element_children($form['countries']) as $country_iso) {
276 $row = array();
277 $row[] = array(
278 'data' => drupal_render($form['countries'][$country_iso]['label_'. $country_iso])
279 );
280 $row[] = array(
281 'data' => drupal_render($form['countries'][$country_iso]['location_geocode_'. $country_iso])
282 );
283 $row[] = array(
284 'data' => drupal_render($form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso])
285 );
286 $rows[] = $row;
287 }
288 $output = theme('table', $header, $rows);
289 $output .= drupal_render_children($form);
290 return $output;
291 }
292
293 /**
294 * Location Utilities form.
295 */
296 function location_util_form() {
297 $form['province_clear'] = array(
298 '#type' => 'fieldset',
299 '#title' => t('Clear province cache'),
300 '#description' => t('If you have modified location.xx.inc files, you will need to clear the province cache to get Location to recognize the modifications.'),
301 );
302 $form['province_clear']['province_clear_submit'] = array(
303 '#type' => 'submit',
304 '#value' => t('Clear province cache'),
305 '#submit' => array('location_util_form_clear_province_cache_submit'),
306 );
307
308 $form['supported_countries_clear'] = array(
309 '#type' => 'fieldset',
310 '#title' => t('Clear supported country list'),
311 '#description' => t('If you have added support for a new country, you will need to clear the supported country list to get Location to recognize the modifications.'),
312 );
313 $form['supported_countries_clear']['supported_countries_clear_submit'] = array(
314 '#type' => 'submit',
315 '#value' => t('Clear supported country list'),
316 '#submit' => array('location_util_form_clear_supported_countries_submit'),
317 );
318 return $form;
319 }
320
321 /**
322 * Location utilities form: Clear province cache.
323 */
324 function location_util_form_clear_province_cache_submit() {
325 drupal_set_message(t('Location province cache cleared.'));
326 cache_clear_all('provinces:', 'cache_location', TRUE);
327 }
328
329 /**
330 * Location utilities form: Clear supported countries cache.
331 */
332 function location_util_form_clear_supported_countries_submit() {
333 drupal_set_message(t('Location supported country list cleared.'));
334 cache_clear_all('location:supported-countries', 'cache_location');
335 }

  ViewVC Help
Powered by ViewVC 1.1.2