| Commit | Line | Data |
|---|---|---|
| f09f952a | 1 | <?php |
| cebd6800 | 2 | // $Id$ |
| f09f952a BB |
3 | |
| 4 | /** | |
| 5 | * @file | |
| 6 | * GMap Macro Builder | |
| 7 | * | |
| 8 | * A dynamic interface to assist in the creation of gmap macro tags. | |
| 9 | */ | |
| 10 | ||
| 11 | /** | |
| 67341ff6 BB |
12 | * Implemenation of hook_help(). |
| 13 | */ | |
| 14 | function gmap_macro_builder_help($section) { | |
| 15 | switch ($section) { | |
| 16 | case 'map/macro': | |
| 17 | return t('You can use this interface to create a map macro suitable for pasting into a node or any other place that accepts a GMap macro.'); | |
| 18 | } | |
| 19 | } | |
| 20 | ||
| 67341ff6 BB |
21 | /** |
| 22 | * Implementation of hook_perm(). | |
| f09f952a BB |
23 | */ |
| 24 | function gmap_macro_builder_perm() { | |
| a59f8092 | 25 | return array('create gmap macro'); |
| f09f952a BB |
26 | } |
| 27 | ||
| 67341ff6 BB |
28 | /** |
| 29 | * Implementation of hook_menu(). | |
| 30 | */ | |
| f09f952a | 31 | function gmap_macro_builder_menu($may_cache) { |
| f09f952a | 32 | if ($may_cache) { |
| 42e8bec6 | 33 | $items = array(); |
| f09f952a BB |
34 | $items[] = array( |
| 35 | 'path' => 'map/macro', | |
| 36 | 'type' => MENU_NORMAL_ITEM, | |
| 37 | 'title' => t('Build a GMap macro'), | |
| a59f8092 | 38 | 'access' => user_access('create gmap macro'), |
| f09f952a BB |
39 | 'callback' => 'drupal_get_form', |
| 40 | 'callback arguments' => 'gmap_macro_builder_form', | |
| 41 | ); | |
| 42e8bec6 | 42 | return $items; |
| f09f952a | 43 | } |
| f09f952a BB |
44 | } |
| 45 | ||
| 67341ff6 BB |
46 | /** |
| 47 | * Macro builder form. | |
| 4cb48f33 BB |
48 | * @param &$form_state |
| 49 | * The $form_state array. | |
| ca1fab76 BB |
50 | * @param $settings |
| 51 | * Additional settings to apply to the macro map. | |
| b08677a4 BB |
52 | * @param $hide |
| 53 | * Fields to hide from the map. (See code for details.) | |
| 54 | * Suggestions for better ways of doing this welcome! | |
| 67341ff6 | 55 | */ |
| b08677a4 | 56 | function gmap_macro_builder_form($settings = array(), $hide = array()) { |
| f09f952a BB |
57 | $form['macroform'] = array( |
| 58 | '#type' => 'fieldset', | |
| 59 | '#title' => t('Gmap macro creation'), | |
| 60 | '#theme' => 'gmap_macro', | |
| 61 | ); | |
| 62 | ||
| 63 | $form['macroform']['mapdiv'] = array( | |
| 64 | '#type' => 'gmap', | |
| 67341ff6 | 65 | '#map' => 'macro_map', |
| ca1fab76 | 66 | '#settings' => array_merge(array( |
| f09f952a BB |
67 | 'points' => array(), |
| 68 | 'pointsOverlays' => array(), | |
| ed370523 BB |
69 | 'behavior' => array( |
| 70 | 'dynmarkers' => TRUE, | |
| 71 | ), | |
| ca1fab76 | 72 | ), $settings), |
| f09f952a BB |
73 | ); |
| 74 | ||
| b08677a4 | 75 | $defaults = array_merge(gmap_defaults(), $settings); |
| f09f952a BB |
76 | |
| 77 | $form['macroform']['overlayedit'] = array( | |
| 78 | '#type' => 'gmap_overlay_edit', | |
| 67341ff6 | 79 | '#map' => 'macro_map', |
| f09f952a BB |
80 | ); |
| 81 | $form['macroform']['mapid'] = array( | |
| 82 | '#type' => 'textfield', | |
| f09f952a | 83 | '#title' => t('Map id attribute'), |
| be7d02ac BB |
84 | '#description' => t('If you need to access this map from a script, you can assign a map ID here.'), |
| 85 | '#default_value' => '', | |
| f09f952a | 86 | ); |
| 82ca3415 | 87 | gmap_widget_setup($form['macroform']['mapid'], 'mapid', 'macro_map'); |
| 67341ff6 | 88 | |
| 0dedcb95 BB |
89 | // @@@ TODO: Roll this next section into an element, it's duplicated from the settings ui. |
| 90 | $baselayers = array(); | |
| 91 | ||
| 92 | foreach (module_implements('gmap') as $module) { | |
| 93 | call_user_func_array($module .'_gmap', array('baselayers', &$baselayers)); | |
| 94 | } | |
| 95 | ||
| 96 | $options = array(); | |
| 97 | foreach ($baselayers as $name => $layers) { | |
| 98 | $options[$name] = array(); | |
| 99 | foreach ($layers as $k => $v) { | |
| 100 | // @@@TODO: Only show the enabled ones? | |
| 101 | $options[$name][$k] = $v['title']; | |
| 102 | } | |
| 103 | } | |
| 104 | ||
| f09f952a | 105 | $form['macroform']['maptype'] = array( |
| cebd6800 BB |
106 | '#type' => 'select', |
| 107 | '#title' => t('Map type'), | |
| f09f952a | 108 | '#default_value' => $defaults['maptype'], |
| 0dedcb95 | 109 | '#options' => $options, |
| f09f952a | 110 | ); |
| 82ca3415 | 111 | gmap_widget_setup($form['macroform']['maptype'], 'maptype', 'macro_map'); |
| 67341ff6 | 112 | |
| 0dedcb95 BB |
113 | // @@@TODO: We need to allow choosing an alternate set of baselayers... |
| 114 | ||
| f09f952a | 115 | $form['macroform']['controltype'] = array( |
| cebd6800 BB |
116 | '#type' => 'select', |
| 117 | '#title' => t('Controls'), | |
| 118 | '#options' => drupal_map_assoc(array('None', 'Small', 'Large')), | |
| f09f952a BB |
119 | '#required' => FALSE, |
| 120 | '#default_value' => $defaults['controltype'], | |
| f09f952a | 121 | ); |
| 82ca3415 | 122 | gmap_widget_setup($form['macroform']['controltype'], 'controltype', 'macro_map'); |
| 67341ff6 | 123 | |
| f09f952a BB |
124 | $form['macroform']['address'] = array( |
| 125 | '#type' => 'gmap_address', | |
| 67341ff6 | 126 | '#map' => 'macro_map', |
| f09f952a BB |
127 | '#title' => t('Address'), |
| 128 | '#default_value' => '', | |
| 129 | ); | |
| 130 | $form['macroform']['latlong'] = array( | |
| 131 | '#type' => 'gmap_latlon', | |
| 67341ff6 | 132 | '#map' => 'macro_map', |
| f09f952a BB |
133 | '#title' => t('The Latitude and Longitude of the centre of the map'), |
| 134 | '#default_value' => $defaults['latlong'], | |
| 135 | '#size' => 50, | |
| 136 | ); | |
| 137 | $form['macroform']['width'] = array( | |
| 138 | '#type' => 'textfield', | |
| f09f952a BB |
139 | '#title' => t('Map width'), |
| 140 | '#default_value' => $defaults['width'], | |
| 141 | '#size' => 25, | |
| 63755d6d BB |
142 | '#maxlength' => 25, |
| 143 | '#description' => t('The map width, as a CSS length or percentage. Examples: <em>50px</em>, <em>5em</em>, <em>2.5in</em>, <em>95%</em>'), | |
| 67341ff6 | 144 | ); |
| 63755d6d | 145 | gmap_widget_setup($form['macroform']['width'], 'width', 'macro_map'); |
| 67341ff6 | 146 | |
| f09f952a BB |
147 | $form['macroform']['height'] = array( |
| 148 | '#type' => 'textfield', | |
| f09f952a BB |
149 | '#title' => t('Map height'), |
| 150 | '#default_value' => $defaults['height'], | |
| 151 | '#size' => 25, | |
| 63755d6d BB |
152 | '#maxlength' => 25, |
| 153 | '#description' => t('The map height, as a CSS length or percentage. Examples: <em>50px</em>, <em>5em</em>, <em>2.5in</em>, <em>95%</em>'), | |
| f09f952a | 154 | ); |
| 63755d6d | 155 | gmap_widget_setup($form['macroform']['height'], 'height', 'macro_map'); |
| 67341ff6 | 156 | |
| f09f952a BB |
157 | $form['macroform']['alignment'] = array( |
| 158 | '#type' => 'gmap_align', | |
| 67341ff6 | 159 | '#map' => 'macro_map', |
| f09f952a BB |
160 | '#title' => t('Alignment'), |
| 161 | ); | |
| 67341ff6 | 162 | |
| f09f952a BB |
163 | $form['macroform']['zoom'] = array( |
| 164 | '#type' => 'select', | |
| f09f952a BB |
165 | '#title' => t('The current magnification of the map'), |
| 166 | '#default_value' => $defaults['zoom'], | |
| 167 | '#options' => drupal_map_assoc(range(0, 17)), | |
| f09f952a | 168 | ); |
| 82ca3415 | 169 | gmap_widget_setup($form['macroform']['zoom'], 'zoom', 'macro_map'); |
| 67341ff6 | 170 | |
| f09f952a BB |
171 | $form['macroform']['macro'] = array( |
| 172 | '#type' => 'gmap_macrotext', | |
| 67341ff6 | 173 | '#map' => 'macro_map', |
| f09f952a BB |
174 | '#default_value' => '', |
| 175 | '#title' => t('Macro text'), | |
| 176 | ); | |
| b08677a4 BB |
177 | |
| 178 | foreach ($hide as $field => $mode) { | |
| 179 | if (isset($form['macroform'][$field])) { | |
| 180 | if ($mode == 1) { | |
| 181 | $form['macroform'][$field]['#type'] = 'hidden'; | |
| 182 | $form['macroform'][$field]['#value'] = $form['macroform'][$field]['#default_value']; | |
| 183 | } | |
| 184 | else if ($mode == 2) { | |
| 185 | $form['macroform'][$field]['#prefix'] = '<div style="display: none;">'; | |
| 186 | $form['macroform'][$field]['#suffix'] = '</div>'; | |
| 187 | } | |
| 188 | } | |
| 189 | } | |
| 190 | ||
| f09f952a BB |
191 | return $form; |
| 192 | } |