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

Diff of /contributions/modules/cck_gmapaddress/cck_gmapaddress.module

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

revision 1.2, Tue Jul 1 06:31:25 2008 UTC revision 1.3, Tue Jul 1 06:31:56 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  /**  /**
4   * Implementation of hook_field_info().   * Implementation of hook_field_info().
5   */   */
6  function cck_gmapaddress_field_info() {  function cck_gmapaddress_field_info() {
7    return array(    return array(
8      'cck_gmapaddress' => array('label' => t('Google Map Address')),      'cck_gmapaddress' => array('label' => t('Google Map Address')),
9    );    );
10  }  }
11    
12  /**  /**
13   * Implementation of cck hook_field_settings   * Implementation of cck hook_field_settings
14   */   */
15  function cck_gmapaddress_field_settings($op, $field) {  function cck_gmapaddress_field_settings($op, $field) {
16    switch ($op) {    switch ($op) {
17      case 'form':      case 'form':
18        $form = array();        $form = array();
19            $form['tld'] = array(            $form['tld'] = array(
20                  '#type' => 'textfield',                  '#type' => 'textfield',
21                  '#title' => t('Top Level Domain'),                  '#title' => t('Top Level Domain'),
22                  '#description' => t("The Domain of the Google Map to use for validation."),                  '#description' => t("The Domain of the Google Map to use for validation."),
23                  '#default_value' => ($field['tld'])?$field['tld']:'com',                  '#default_value' => ($field['tld'])?$field['tld']:'com',
24                    );                    );
25            $form['accuracy'] = array(            $form['accuracy'] = array(
26                  '#type' => 'select',                  '#type' => 'select',
27                  '#title' => t('Minimum Accuracy'),                  '#title' => t('Minimum Accuracy'),
28                  '#description' => t("The accuracy of gmap validation."),                  '#description' => t("The accuracy of gmap validation."),
29                  '#default_value' => $widget['accuracy'],                  '#default_value' => $widget['accuracy'],
30                          '#options'=> _cck_gmapaddress_accuracy(),                          '#options'=> _cck_gmapaddress_accuracy(),
31                  );                  );
32            //GMAP SIMPLE            //GMAP SIMPLE
33            $form['gmap_simple'] = array( '#type'=>'fieldset',            $form['gmap_simple'] = array( '#type'=>'fieldset',
34                                                                          '#title'=>t('GMap - Single'),                                                                          '#title'=>t('GMap - Single'),
35                                                                          '#tree'=>TRUE,                                                                          '#tree'=>TRUE,
36                                                                          '#collapsible'=>TRUE,                                                                          '#collapsible'=>TRUE,
37                                                                          '#collapsed'=>TRUE,                                                                          '#collapsed'=>TRUE,
38                                                                          '#description'=> '',                                                                          '#description'=> '',
39                                                                          );                                                                          );
40            $form['gmap_simple']['width'] = array(        '#type'=> 'textfield',            $form['gmap_simple']['width'] = array(        '#type'=> 'textfield',
41                                                                                          '#title' => t('Width'),                                                                                          '#title' => t('Width'),
42                                                                                          '#default_value' =>$field['gmap_simple']['width'],                                                                                          '#default_value' =>$field['gmap_simple']['width'],
43                                                                                          '#description' => '"" = default gmap setting, prepend v=,t=, f= or b= with  for views,teaser, full or block view settings, separate with ; <br/> example "600;v=200;t=300"',                                                                                          '#description' => '"" = default gmap setting, prepend v=,t=, f= or b= with  for views,teaser, full or block view settings, separate with ; <br/> example "600;v=200;t=300"',
44                                                                                          );                                                                                          );
45            $form['gmap_simple']['height'] = array(       '#type'=> 'textfield',            $form['gmap_simple']['height'] = array(       '#type'=> 'textfield',
46                                                                                          '#title' => t('Height'),                                                                                          '#title' => t('Height'),
47                                                                                          '#default_value' =>$field['gmap_simple']['height'],                                                                                          '#default_value' =>$field['gmap_simple']['height'],
48                                                                                          '#description' => '"" = default gmap setting, prepend v=,t=, f= or b= with  for views,teaser, full or block view settings, separate with ; <br/> example "600;v=200;t=300"',                                                                                          '#description' => '"" = default gmap setting, prepend v=,t=, f= or b= with  for views,teaser, full or block view settings, separate with ; <br/> example "600;v=200;t=300"',
49                                                                                          );                                                                                          );
50            $form['gmap_simple']['zoom'] = array( '#type'=> 'textfield',            $form['gmap_simple']['zoom'] = array( '#type'=> 'textfield',
51                                                                                          '#title' => t('Zoom'),                                                                                          '#title' => t('Zoom'),
52                                                                                          '#default_value' =>$field['gmap_simple']['zoom'],                                                                                          '#default_value' =>$field['gmap_simple']['zoom'],
53                                                                                          '#description' => '"" = default gmap setting, "auto" = Autozoom, integer (1,2,3...) for custom zoom',                                                                                          '#description' => '"" = default gmap setting, "auto" = Autozoom, integer (1,2,3...) for custom zoom',
54                                                                                          );                                                                                          );
55            $form['gmap_simple']['mtc'] = array(  '#type'=> 'textfield',            $form['gmap_simple']['mtc'] = array(  '#type'=> 'textfield',
56                                                                                          '#title' => t('Map Type Control'),                                                                                          '#title' => t('Map Type Control'),
57                                                                                          '#default_value' =>$field['gmap_simple']['mtc'],                                                                                          '#default_value' =>$field['gmap_simple']['mtc'],
58                                                                                          '#description' => '"" = default gmap setting, "0" = none, "1" = Standard, "2" = Hierarchical, "3" = Dropdown <br/> contains view-control like width',//none,standard,hier,menu                                                                                          '#description' => '"" = default gmap setting, "0" = none, "1" = Standard, "2" = Hierarchical, "3" = Dropdown <br/> contains view-control like width',//none,standard,hier,menu
59                                                                                          );                                                                                          );
60            $form['gmap_simple']['address'] = array(      '#type'=> 'textfield',            $form['gmap_simple']['address'] = array(      '#type'=> 'textfield',
61                                                                                          '#title' => t('Show address'),                                                                                          '#title' => t('Show address'),
62                                                                                          '#default_value' =>$field['gmap_simple']['address'],                                                                                          '#default_value' =>$field['gmap_simple']['address'],
63                                                                                          '#description' => '1 for show address, prepend v=,t= or f= with  for views,teaser or full view settings, separate with ; <br/> example "1;v=0;t=0',                                                                                          '#description' => '1 for show address, prepend v=,t= or f= with  for views,teaser or full view settings, separate with ; <br/> example "1;v=0;t=0',
64                                                                                          );                                                                                          );
65            $form['gmap_simple']['routelink'] = array('#type'=> 'select',            $form['gmap_simple']['routelink'] = array('#type'=> 'select',
66                                                                                          '#title' => t('Link to route'),                                                                                          '#title' => t('Link to route'),
67                                                                                          '#multiple'=>TRUE,                                                                                          '#multiple'=>TRUE,
68                                                                                          '#required'=>FALSE,                                                                                          '#required'=>FALSE,
69                                                                                          '#default_value' => $field['gmap_simple']['routelink'],                                                                                          '#default_value' => $field['gmap_simple']['routelink'],
70                                                                                          '#options'=>array('full'=>t('Full'),'teaser'=>t('Teaser'),'views'=>t('Views'),'block'=>t('Block')),                                                                                          '#options'=>array('full'=>t('Full'),'teaser'=>t('Teaser'),'views'=>t('Views'),'block'=>t('Block')),
71                                                                                          );                                                                                          );
72    
73            //GMAP ALL            //GMAP ALL
74            $form['gmap_all'] = array(    '#type'=>'fieldset',            $form['gmap_all'] = array(    '#type'=>'fieldset',
75                                                                          '#title'=>t('GMap - All addresses in one'),                                                                          '#title'=>t('GMap - All addresses in one'),
76                                                                          '#tree'=>TRUE,                                                                          '#tree'=>TRUE,
77                                                                          '#collapsible'=>TRUE,                                                                          '#collapsible'=>TRUE,
78                                                                          '#collapsed'=>TRUE,                                                                          '#collapsed'=>TRUE,
79                                                                          '#description'=> '',                                                                          '#description'=> '',
80                                                                          );                                                                          );
81            $form['gmap_all']['width'] = array(   '#type'=> 'textfield',            $form['gmap_all']['width'] = array(   '#type'=> 'textfield',
82                                                                                          '#title' => t('Width'),                                                                                          '#title' => t('Width'),
83                                                                                          '#default_value' =>$field['gmap_all']['width'],                                                                                          '#default_value' =>$field['gmap_all']['width'],
84                                                                                          );                                                                                          );
85            $form['gmap_all']['height'] = array(  '#type'=> 'textfield',            $form['gmap_all']['height'] = array(  '#type'=> 'textfield',
86                                                                                          '#title' => t('Height'),                                                                                          '#title' => t('Height'),
87                                                                                          '#default_value' =>$field['gmap_all']['height'],                                                                                          '#default_value' =>$field['gmap_all']['height'],
88                                                                                          );                                                                                          );
89            $form['gmap_all']['zoom'] = array(    '#type'=> 'textfield',            $form['gmap_all']['zoom'] = array(    '#type'=> 'textfield',
90                                                                                          '#title' => t('Zoom'),                                                                                          '#title' => t('Zoom'),
91                                                                                          '#default_value' =>$field['gmap_all']['zoom'],                                                                                          '#default_value' =>$field['gmap_all']['zoom'],
92                                                                                          );                                                                                          );
93            $form['gmap_all']['mtc'] = array(     '#type'=> 'textfield',            $form['gmap_all']['mtc'] = array(     '#type'=> 'textfield',
94                                                                                          '#title' => t('Map Type Control'),                                                                                          '#title' => t('Map Type Control'),
95                                                                                          '#default_value' =>$field['gmap_all']['mtc'],                                                                                          '#default_value' =>$field['gmap_all']['mtc'],
96                                                                                          '#description' => '"" = default gmap setting, 0 = none, 1 = Standard, 2 = Hierarchical, 3 = Dropdown',//none,standard,hier,menu                                                                                          '#description' => '"" = default gmap setting, 0 = none, 1 = Standard, 2 = Hierarchical, 3 = Dropdown',//none,standard,hier,menu
97                                                                                          );                                                                                          );
98            $form['gmap_all']['address'] = array( '#type'=> 'textfield',            $form['gmap_all']['address'] = array( '#type'=> 'textfield',
99                                                                                          '#title' => t('Show address'),                                                                                          '#title' => t('Show address'),
100                                                                                          '#default_value' =>$field['gmap_all']['address'],                                                                                          '#default_value' =>$field['gmap_all']['address'],
101                                                                                          );                                                                                          );
102            $form['gmap_all']['routelink'] = array('#type'=> 'select',            $form['gmap_all']['routelink'] = array('#type'=> 'select',
103                                                                                          '#title' => t('Link to route'),                                                                                          '#title' => t('Link to route'),
104                                                                                          '#multiple'=>TRUE,                                                                                          '#multiple'=>TRUE,
105                                                                                          '#required'=>FALSE,                                                                                          '#required'=>FALSE,
106                                                                                          '#default_value' => $field['gmap_all']['routelink'],                                                                                          '#default_value' => $field['gmap_all']['routelink'],
107                                                                                          '#options'=>array('full'=>t('Full'),'teaser'=>t('Teaser'),'views'=>t('Views'),'block'=>t('Block')),                                                                                          '#options'=>array('full'=>t('Full'),'teaser'=>t('Teaser'),'views'=>t('Views'),'block'=>t('Block')),
108                                                                                          );                                                                                          );
109            //ROUTE SINGLE            //ROUTE SINGLE
110            $form['route_single'] = array(        '#type'=>'fieldset',            $form['route_single'] = array(        '#type'=>'fieldset',
111                                                                          '#title'=>t('Route Link - Single'),                                                                          '#title'=>t('Route Link - Single'),
112                                                                          '#tree'=>TRUE,                                                                          '#tree'=>TRUE,
113                                                                          '#collapsible'=>TRUE,                                                                          '#collapsible'=>TRUE,
114                                                                          '#collapsed'=>TRUE,                                                                          '#collapsed'=>TRUE,
115                                                                          '#description'=> '',                                                                          '#description'=> '',
116                                                                          );                                                                          );
117            $form['route_single']['text'] = array(        '#type'=> 'textfield',            $form['route_single']['text'] = array(        '#type'=> 'textfield',
118                                                                                          '#title' => t('Route text'),                                                                                          '#title' => t('Route text'),
119                                                                                          '#default_value' =>$field['route_single']['text'],                                                                                          '#default_value' =>$field['route_single']['text'],
120                                                                                          );                                                                                          );
121            $form['route_single']['start'] = array('#type'=> 'select',            $form['route_single']['start'] = array('#type'=> 'select',
122                                                                                          '#title' => t('Start address'),                                                                                          '#title' => t('Start address'),
123                                                                                          '#multiple'=>FALSE,                                                                                          '#multiple'=>FALSE,
124                                                                                          '#default_value' =>$field['route_single']['start'],                                                                                          '#default_value' =>$field['route_single']['start'],
125                                                                                          '#options'=>_cck_gmapaddress_routestartend(0),                                                                                          '#options'=>_cck_gmapaddress_routestartend(0),
126                                                                                          );                                                                                          );
127            $form['route_single']['start_opt'] = array(   '#type'=> 'textfield',            $form['route_single']['start_opt'] = array(   '#type'=> 'textfield',
128                                                                                          '#title' => t('Start options'),                                                                                          '#title' => t('Start options'),
129                                                                                          '#default_value' =>$field['route_single']['start_opt'],                                                                                          '#default_value' =>$field['route_single']['start_opt'],
130                                                                                          );                                                                                          );
131            $form['route_single']['end'] = array('#type'=> 'select',            $form['route_single']['end'] = array('#type'=> 'select',
132                                                                                          '#title' => t('Destination address'),                                                                                          '#title' => t('Destination address'),
133                                                                                          '#multiple'=>FALSE,                                                                                          '#multiple'=>FALSE,
134                                                                                          '#default_value' =>$field['route_single']['end'],                                                                                          '#default_value' =>$field['route_single']['end'],
135                                                                                          '#options'=>_cck_gmapaddress_routestartend(1),                                                                                          '#options'=>_cck_gmapaddress_routestartend(1),
136                                                                                          );                                                                                          );
137            $form['route_single']['end_opt'] = array(     '#type'=> 'textfield',            $form['route_single']['end_opt'] = array(     '#type'=> 'textfield',
138                                                                                          '#title' => t('Destination options'),                                                                                          '#title' => t('Destination options'),
139                                                                                          '#default_value' =>$field['route_single']['end_opt'],                                                                                          '#default_value' =>$field['route_single']['end_opt'],
140                                                                                          );                                                                                          );
141            //ROUTE ALL            //ROUTE ALL
142            $form['route_all'] = array(   '#type'=>'fieldset',            $form['route_all'] = array(   '#type'=>'fieldset',
143                                                                          '#title'=>t('Route Link - All addresses in one'),                                                                          '#title'=>t('Route Link - All addresses in one'),
144                                                                          '#tree'=>TRUE,                                                                          '#tree'=>TRUE,
145                                                                          '#collapsible'=>TRUE,                                                                          '#collapsible'=>TRUE,
146                                                                          '#collapsed'=>TRUE,                                                                          '#collapsed'=>TRUE,
147                                                                          '#description'=> '',                                                                          '#description'=> '',
148                                                                          );                                                                          );
149            $form['route_all']['text'] = array(   '#type'=> 'textfield',            $form['route_all']['text'] = array(   '#type'=> 'textfield',
150                                                                                          '#title' => t('Route text'),                                                                                          '#title' => t('Route text'),
151                                                                                          '#default_value' =>$field['route_all']['text'],                                                                                          '#default_value' =>$field['route_all']['text'],
152                                                                                          );                                                                                          );
153            $form['route_all']['start'] = array('#type'=> 'select',            $form['route_all']['start'] = array('#type'=> 'select',
154                                                                                          '#title' => t('Start address'),                                                                                          '#title' => t('Start address'),
155                                                                                          '#multiple'=>FALSE,                                                                                          '#multiple'=>FALSE,
156                                                                                          '#default_value' =>$field['route_all']['start'],                                                                                          '#default_value' =>$field['route_all']['start'],
157                                                                                          '#options'=>_cck_gmapaddress_routestartend(0),                                                                                          '#options'=>_cck_gmapaddress_routestartend(0),
158                                                                                          );                                                                                          );
159            $form['route_all']['start_opt'] = array(      '#type'=> 'textfield',            $form['route_all']['start_opt'] = array(      '#type'=> 'textfield',
160                                                                                          '#title' => t('Start options'),                                                                                          '#title' => t('Start options'),
161                                                                                          '#default_value' =>$field['route_all']['start_opt'],                                                                                          '#default_value' =>$field['route_all']['start_opt'],
162                                                                                          );                                                                                          );
163            $form['route_all']['end'] = array('#type'=> 'select',            $form['route_all']['end'] = array('#type'=> 'select',
164                                                                                          '#title' => t('Destination address'),                                                                                          '#title' => t('Destination address'),
165                                                                                          '#multiple'=>FALSE,                                                                                          '#multiple'=>FALSE,
166                                                                                          '#default_value' =>$field['route_all']['end'],                                                                                          '#default_value' =>$field['route_all']['end'],
167                                                                                          '#options'=>_cck_gmapaddress_routestartend(1),                                                                                          '#options'=>_cck_gmapaddress_routestartend(1),
168                                                                                          );                                                                                          );
169            $form['route_all']['end_opt'] = array(        '#type'=> 'textfield',            $form['route_all']['end_opt'] = array(        '#type'=> 'textfield',
170                                                                                          '#title' => t('Destination options'),                                                                                          '#title' => t('Destination options'),
171                                                                                          '#default_value' =>$field['route_all']['end_opt'],                                                                                          '#default_value' =>$field['route_all']['end_opt'],
172                                                                                          );                                                                                          );
173    
174        return $form;        return $form;
175      case 'validate':      case 'validate':
176        break;        break;
177      case 'save':      case 'save':
178        return array('tld','accuracy','gmap_all','gmap_simple','route_single','route_all');        return array('tld','accuracy','gmap_all','gmap_simple','route_single','route_all');
179      case 'database columns':      case 'database columns':
180            $columns = array();            $columns = array();
181            $columns = array(            $columns = array(
182                          'longitude' => array('type' => 'decimal', 'length' => '18,15', 'unsigned' => FALSE, 'not null' => TRUE, 'default' => 0),                          'longitude' => array('type' => 'decimal', 'length' => '18,15', 'unsigned' => FALSE, 'not null' => TRUE, 'default' => 0),
183                          'latitude' => array('type' => 'decimal', 'length' => '18,15', 'unsigned' => FALSE, 'not null' => TRUE, 'default' => 0),                          'latitude' => array('type' => 'decimal', 'length' => '18,15', 'unsigned' => FALSE, 'not null' => TRUE, 'default' => 0),
184                          'accuracy' => array('type' => 'int', 'length' => 1, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),                          'accuracy' => array('type' => 'int', 'length' => 1, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
185                          'address' => array('type' => 'varchar', 'length' => 255,'not null' => TRUE, 'default' => "''"),                          'address' => array('type' => 'varchar', 'length' => 255,'not null' => TRUE, 'default' => "''"),
186                          'delta' => array('type' => 'int', 'length' => 1, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),                          'delta' => array('type' => 'int', 'length' => 1, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
187                  );                  );
188            return $columns;            return $columns;
189      case 'filters':      case 'filters':
190        return array(        return array(
191          'default' => array(          'default' => array(
192            'name' => t('Default'),            'name' => t('Default'),
193            'operator' => 'views_handler_operator_gtlt',            'operator' => 'views_handler_operator_gtlt',
194          ),          ),
195        );        );
196          /**case 'arguments':          /**case 'arguments':
197        return FALSE;**/        return FALSE;**/
198      case 'callbacks':      case 'callbacks':
199        return array(        return array(
200          'view' => CONTENT_CALLBACK_NONE,          'view' => CONTENT_CALLBACK_NONE,
201        );        );
202    }    }
203  }  }
204    
205  /**  /**
206   * Implementation of cck hook_field   * Implementation of cck hook_field
207   */   */
208  function cck_gmapaddress_field($op, &$node, $field, &$node_field, $teaser, $page) {  function cck_gmapaddress_field($op, &$node, $field, &$node_field, $teaser, $page) {
209    switch ($op) {    switch ($op) {
210      case 'load':      case 'load':
211        break;        break;
212      case 'view':      case 'view':
213        break;        break;
214      case 'validate':      case 'validate':
215            foreach ($node_field as $key=>$item){            foreach ($node_field as $key=>$item){
216                  //Prüfung ob leer??                  //Prüfung ob leer??
217                  //Proofs on valid geo location in gmap                  //Proofs on valid geo location in gmap
218                  if (!$item['status']){                  if (!$item['status']){
219                          $gc = gmap_geocode($item['address'],$field['tld']);                          $gc = gmap_geocode($item['address'],$field['tld']);
220                          $item = array_merge($item,$gc);                          $item = array_merge($item,$gc);
221                  }                  }
222                  if ($item['status'] == 610){                  if ($item['status'] == 610){
223                          form_set_error($field['field_name'].']['.$key.'][address',t('No valid Google Map Key! Set correct key in !link',array('!link'=>l('GMap Admin',base_path().'admin/settings/gmap'))));                          form_set_error($field['field_name'].']['.$key.'][address',t('No valid Google Map Key! Set correct key in !link',array('!link'=>l('GMap Admin',base_path().'admin/settings/gmap'))));
224                  } elseif ($item['status']!= 200){                  } elseif ($item['status']!= 200){
225                          form_set_error($field['field_name'].']['.$key.'][address',t('The address in %field could not be validated as correct address!',array('%field'=>$field['field_name']."[$key]")));                          form_set_error($field['field_name'].']['.$key.'][address',t('The address in %field could not be validated as correct address!',array('%field'=>$field['field_name']."[$key]")));
226                  } elseif($item['accuracy']<$field['accuracy']) {                  } elseif($item['accuracy']<$field['accuracy']) {
227                          form_set_error($field['field_name'].']['.$key.'][address',t('The address in %field does not have satisfying accuracy!',array('%field'=>$field['field_name']."[$key]")));                          form_set_error($field['field_name'].']['.$key.'][address',t('The address in %field does not have satisfying accuracy!',array('%field'=>$field['field_name']."[$key]")));
228                  }                  }
229            }            }
230        break;        break;
231      case 'insert':      case 'insert':
232      case 'update':      case 'update':
233    
234            foreach ($node_field as $key => $item){            foreach ($node_field as $key => $item){
235                  $node_field[$key]['delta'] = $key;                  $node_field[$key]['delta'] = $key;
236            }            }
237        break;        break;
238    }    }
239  }  }
240    
241  /**  /**
242   * Implementation of cck hook_widget_info   * Implementation of cck hook_widget_info
243   */   */
244  function cck_gmapaddress_widget_info() {  function cck_gmapaddress_widget_info() {
245    return array(    return array(
246      'gmapaddress_textfield' => array(      'gmapaddress_textfield' => array(
247        'label' => t('GMap Address - Text Field'),        'label' => t('GMap Address - Text Field'),
248        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
249      ),      ),
250    );    );
251  }  }
252    
253  /**  /**
254   * Implementation of cck hook_widget_settings()   * Implementation of cck hook_widget_settings()
255   */   */
256  function cck_gmapaddress_widget_settings($op, $widget){  function cck_gmapaddress_widget_settings($op, $widget){
257          // $ops save,callbacks,validate get $field instead of $widget          // $ops save,callbacks,validate get $field instead of $widget
258          switch ($op) {          switch ($op) {
259                  case 'form':                  case 'form':
260                    $form = array();                    $form = array();
261                    return $form;                    return $form;
262                  case 'validate':                  case 'validate':
263                    break;                    break;
264                  case 'callbacks':                  case 'callbacks':
265                    return array(                    return array(
266                          'default value' => CONTENT_CALLBACK_NONE,                          'default value' => CONTENT_CALLBACK_NONE,
267                    );                    );
268                  case 'save':                  case 'save':
269                    return array();                    return array();
270          }          }
271  }  }
272    
273  /**  /**
274   * hook_widget()   * hook_widget()
275   */   */
276  function cck_gmapaddress_widget($op, &$node, $field, &$node_field) {  function cck_gmapaddress_widget($op, &$node, $field, &$node_field) {
277    switch ($op) {    switch ($op) {
278      case 'prepare form values':      case 'prepare form values':
279        break;        break;
280    
281      case 'form':      case 'form':
282        $form = array();        $form = array();
283        $form[$field['field_name']] = array('#tree' => TRUE,        $form[$field['field_name']] = array('#tree' => TRUE,
284                                                                                    '#type' => 'fieldset',                                                                                    '#type' => 'fieldset',
285                                                                                    '#title'=>t($field['widget']['label']),                                                                                    '#title'=>t($field['widget']['label']),
286                                                                                    '#description' => t($field['widget']['description']),                                                                                    '#description' => t($field['widget']['description']),
287                                                                                    );                                                                                    );
288            $key = -1;            $key = -1;
289            foreach ($node_field as $key => $item){            foreach ($node_field as $key => $item){
290                  if ($field['#multiple'] || $key == 0){                  if ($field['#multiple'] || $key == 0){
291                          $form[$field['field_name']][$key] = array('#tree' => TRUE);                          $form[$field['field_name']][$key] = array('#tree' => TRUE);
292                          $form[$field['field_name']][$key]['address'] = array(                          $form[$field['field_name']][$key]['address'] = array(
293                                  '#type' => 'textfield',                                  '#type' => 'textfield',
294                                  '#default_value' => $item['address'],                                  '#default_value' => $item['address'],
295                                  '#required' => ($field['required'] && $key == 0),                                  '#required' => ($field['required'] && $key == 0),
296                          );                          );
297                  }                  }
298            }            }
299            $key++;            $key++;
300            for ($i = $key;$i < 1 - $key + (($field['#multiple'])?3:0);$i++){            for ($i = $key;$i < 1 - $key + (($field['#multiple'])?3:0);$i++){
301                  $form[$field['field_name']][$i] = array('#tree' => TRUE);                  $form[$field['field_name']][$i] = array('#tree' => TRUE);
302                  $form[$field['field_name']][$i]['address'] = array(                  $form[$field['field_name']][$i]['address'] = array(
303                                  '#type' => 'textfield',                                  '#type' => 'textfield',
304                                  '#default_value' => $item['address'],                                  '#default_value' => $item['address'],
305                                  '#required' => ($field['required'] && $i == 0),                                  '#required' => ($field['required'] && $i == 0),
306                  );                  );
307            }            }
308    
309        return $form;        return $form;
310    
311      case 'process form values':      case 'process form values':
312            foreach ($node_field as $key => $item){            foreach ($node_field as $key => $item){
313                  if ($item['address']){                  if ($item['address']){
314                          $gc = gmap_geocode($item['address'],$field['tld']);                          $gc = gmap_geocode($item['address'],$field['tld']);
315                                                          $node_field[$key] = array_merge($item,$gc);                                                          $node_field[$key] = array_merge($item,$gc);
316    
317                  } else {                  } else {
318                    unset($node_field[$key]);                    unset($node_field[$key]);
319                  }                  }
320            }            }
321            $node_field = array_values($node_field);            $node_field = array_values($node_field);
322        break;        break;
323    }    }
324  }  }
325    
326  /**  /**
327   * Implemantation of cck hook_field_formatter_info()   * Implemantation of cck hook_field_formatter_info()
328   */   */
329  function cck_gmapaddress_field_formatter_info() {  function cck_gmapaddress_field_formatter_info() {
330    return array(    return array(
331      'address' => array(      'address' => array(
332        'label' => t('Address'),        'label' => t('Address'),
333        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
334      ),      ),
335          'longitude' => array(          'longitude' => array(
336        'label' => t('Longitude'),        'label' => t('Longitude'),
337        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
338      ),      ),
339          'latitude' => array(          'latitude' => array(
340        'label' => t('Latidude'),        'label' => t('Latidude'),
341        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
342      ),      ),
343      'lonlat' => array(      'lonlat' => array(
344        'label' => t('Longitude and Latidude'),        'label' => t('Longitude and Latidude'),
345        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
346      ),      ),
347          'accuracy' => array(          'accuracy' => array(
348        'label' => t('Accuracy'),        'label' => t('Accuracy'),
349        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
350      ),      ),
351          'gmap_simple' => array(          'gmap_simple' => array(
352        'label' => t('GMap - Single'),        'label' => t('GMap - Single'),
353        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
354      ),      ),
355          'gmap_all' => array(//Only processed by delta = 0          'gmap_all' => array(//Only processed by delta = 0
356        'label' => t('GMap - All addresses in one'),        'label' => t('GMap - All addresses in one'),
357        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
358      ),      ),
359          'route_single' => array(//Only processed by delta = 0          'route_single' => array(//Only processed by delta = 0
360        'label' => t('Route Link - Single'),        'label' => t('Route Link - Single'),
361        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
362      ),      ),
363          'route_all' => array(          'route_all' => array(
364        'label' => t('Route Link - All addresses in one'),        'label' => t('Route Link - All addresses in one'),
365        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
366      ),      ),
367          /**'gmap_route' => array(          /**'gmap_route' => array(
368        'label' => t('GMap Route'),        'label' => t('GMap Route'),
369        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
370      ),      ),
371          'gmap_route_user' => array(  //Options to come: to first, to last, to every place, from user over first and others to last, $user->field mit lonlat or addresse          'gmap_route_user' => array(  //Options to come: to first, to last, to every place, from user over first and others to last, $user->field mit lonlat or addresse
372        'label' => t('GMap User-Route'),        'label' => t('GMap User-Route'),
373        'field types' => array('cck_gmapaddress'),        'field types' => array('cck_gmapaddress'),
374      ),  */      ),  */
375    );    );
376  }  }
377    
378  /**  /**
379   * hook_field_formatter()   * hook_field_formatter()
380   */   */
381  function cck_gmapaddress_field_formatter($field, $item, $formatter, $node,$block = FALSE) {  function cck_gmapaddress_field_formatter($field, $item, $formatter, $node,$block = FALSE) {
382    //get view-type    //get view-type
383    if ($block){    if ($block){
384          $view = 'block';          $view = 'block';
385    } elseif($node->node_type){    } elseif(isset($node->node_type)){
386      $view = 'views';      $view = 'views';
387    } elseif (strlen($node->teaser) > strlen($node->body)){    } elseif (strlen($node->teaser) > strlen($node->body)){
388      $view = 'teaser';      $view = 'teaser';
389    } else {    } else {
390      $view = 'full';      $view = 'full';
391    }    }
392    switch ($formatter) {    switch ($formatter) {
393      case 'address':      case 'address':
394        return check_plain($item['address']);        return check_plain($item['address']);
395    
396      case 'longitude':      case 'longitude':
397        return check_plain($item['longitude']);        return check_plain($item['longitude']);
398          case 'latitude':          case 'latitude':
399        return check_plain($item['latitude']);        return check_plain($item['latitude']);
400          case 'lonlat':          case 'lonlat':
401        return t('lon: %lon - lat: %lat',array('%lon'=>$item['longitude'],'%lat'=>$item['latitude']));        return t('lon: %lon - lat: %lat',array('%lon'=>$item['longitude'],'%lat'=>$item['latitude']));
402    
403          case 'accuracy':          case 'accuracy':
404            return _cck_gmapaddress_accuracy($item['accuracy']);            return _cck_gmapaddress_accuracy($item['accuracy']);
405          case 'gmap_simple':          case 'gmap_simple':
406            //this view is processed for every delta            //this view is processed for every delta
407            if ($item['longitude'] && $item['latitude']){            if ($item['longitude'] && $item['latitude']){
408                  //Height & Width                  //Height & Width
409                  $height = (strlen($field['gmap_simple']['height'])>0)?_cck_gmapaddress_addpx(_cck_gmapaddress_arrhelper($field['gmap_simple']['height'],$view)):'default';                  $height = (strlen($field['gmap_simple']['height'])>0)?_cck_gmapaddress_addpx(_cck_gmapaddress_arrhelper($field['gmap_simple']['height'],$view)):'default';
410                  $width = (strlen($field['gmap_simple']['width'])>0)?_cck_gmapaddress_addpx(_cck_gmapaddress_arrhelper($field['gmap_simple']['width'],$view)):'default';                  $width = (strlen($field['gmap_simple']['width'])>0)?_cck_gmapaddress_addpx(_cck_gmapaddress_arrhelper($field['gmap_simple']['width'],$view)):'default';
411    
412                  //Zoom                  //Zoom
413                  $zoom = _cck_gmapaddress_arrhelper($field['gmap_simple']['zoom'],$view);                  $zoom = _cck_gmapaddress_arrhelper($field['gmap_simple']['zoom'],$view);
414                  $map['behavior']=array('autozoom'=>($zoom == 'auto'));                  $map['behavior']=array('autozoom'=>($zoom == 'auto'));
415    
416                  //Map Type Control                  //Map Type Control
417                  if (strlen($field['gmap_simple']['mtc'])>0){                  if (strlen($field['gmap_simple']['mtc'])>0){
418                          $map['mtc'] = _cck_gmapaddress_mtc(_cck_gmapaddress_arrhelper($field['gmap_simple']['mtc'],$view));                          $map['mtc'] = _cck_gmapaddress_mtc(_cck_gmapaddress_arrhelper($field['gmap_simple']['mtc'],$view));
419                  }                  }
420                  //Address                  //Address
421                  $address = (_cck_gmapaddress_arrhelper($field['gmap_simple']['address'],$view))?cck_gmapaddress_field_formatter($field,$item,'address',$node):'';                  $address = (_cck_gmapaddress_arrhelper($field['gmap_simple']['address'],$view))?cck_gmapaddress_field_formatter($field,$item,'address',$node):'';
422    
423                  //Route Link                  //Route Link
424                  $link='';                  $link='';
425                  if (in_array($view,$field['gmap_simple']['routelink'])){                  if (in_array($view,$field['gmap_simple']['routelink'])){
426                    $link = cck_gmapaddress_field_formatter($field,$item,'route_single',$node);                    $link = cck_gmapaddress_field_formatter($field,$item,'route_single',$node);
427                  }                  }
428    
429                  return $address.gmap_simple_map($item['latitude'], $item['longitude'],'',$item['address'],$zoom,$width,$height, FALSE, $map).$link;                  return $address.gmap_simple_map($item['latitude'], $item['longitude'],'',$item['address'],$zoom,$width,$height, FALSE, $map).$link;
430            }            }
431          case 'gmap_all':          case 'gmap_all':
432            //to avoid multiple view fo same map, view is only processed for delta = 0            //to avoid multiple view fo same map, view is only processed for delta = 0
433            if ($item['longitude'] && $item['latitude'] && $item['delta']==0){            if ($item['longitude'] && $item['latitude'] && $item['delta']==0){
434              if (empty($node->{$field['field_name']})){              if (empty($node->{$field['field_name']})){
435                          $node = node_load($node->nid);                          $node = node_load($node->nid);
436                  }                  }
437                  //Markers                  //Markers
438                  $markers = array();                  $markers = array();
439                  $mlon = array();                  $mlon = array();
440                  $mlat = array();                  $mlat = array();
441                  $addresses = array();                  $addresses = array();
442                  foreach ($node->{$field['field_name']} as $key=>$el){                  foreach ($node->{$field['field_name']} as $key=>$el){
443                          $markers[] = array(     'longitude'=>$el['longitude'],                          $markers[] = array(     'longitude'=>$el['longitude'],
444                                                                  'latitude'=>$el['latitude'],                                                                  'latitude'=>$el['latitude'],
445                                                                  'text'=>$el['address'],                                                                  'text'=>$el['address'],
446                                                                  'offset'=>$key,                                                                  'offset'=>$key,
447                                                   );                                                   );
448                          $mlon[] = $el['longitude'];                          $mlon[] = $el['longitude'];
449                          $mlat[] = $el['latitude'];                          $mlat[] = $el['latitude'];
450                          $addresses[] = $el['address'];                          $addresses[] = $el['address'];
451                  }                  }
452                  $settings = array('markers'=>$markers);                  $settings = array('markers'=>$markers);
453                  //Position                  //Position
454                  $settings['longitude'] = (min($mlon)+max($mlon))/2;                  $settings['longitude'] = (min($mlon)+max($mlon))/2;
455                  $settings['latitude'] = (min($mlat)+max($mlat))/2;                  $settings['latitude'] = (min($mlat)+max($mlat))/2;
456                  //Zoom                  //Zoom
457                  $zoom = _cck_gmapaddress_arrhelper($field['gmap_all']['zoom'],$view);                  $zoom = _cck_gmapaddress_arrhelper($field['gmap_all']['zoom'],$view);
458                  if ($zoom=='auto'){                  if ($zoom=='auto'){
459                          $settings['behavior'] = array('autozoom' => TRUE);                          $settings['behavior'] = array('autozoom' => TRUE);
460                  } elseif ($zoom > 0 && $zoom < 20) {                  } elseif ($zoom > 0 && $zoom < 20) {
461                          $settings['zoom'] = $zoom;                          $settings['zoom'] = $zoom;
462                  }                  }
463                  //Height & Width                  //Height & Width
464                  if (strlen($field['gmap_all']['height'])>0){                  if (strlen($field['gmap_all']['height'])>0){
465                          $settings['height'] = _cck_gmapaddress_addpx(_cck_gmapaddress_arrhelper($field['gmap_all']['height'],$view));                          $settings['height'] = _cck_gmapaddress_addpx(_cck_gmapaddress_arrhelper($field['gmap_all']['height'],$view));
466                  }                  }
467                  if (strlen($field['gmap_all']['width'])>0){                  if (strlen($field['gmap_all']['width'])>0){
468                          $settings['width'] = _cck_gmapaddress_addpx(_cck_gmapaddress_arrhelper($field['gmap_all']['width'],$view));                          $settings['width'] = _cck_gmapaddress_addpx(_cck_gmapaddress_arrhelper($field['gmap_all']['width'],$view));
469                  }                  }
470                  //Map Type Control                  //Map Type Control
471                  if (strlen($field['gmap_all']['mtc'])>0){                  if (strlen($field['gmap_all']['mtc'])>0){
472                          $settings['mtc'] = _cck_gmapaddress_mtc(_cck_gmapaddress_arrhelper($field['gmap_all']['mtc'],$view));                          $settings['mtc'] = _cck_gmapaddress_mtc(_cck_gmapaddress_arrhelper($field['gmap_all']['mtc'],$view));
473                  }                  }
474    
475                  //Address                  //Address
476                  $address = (_cck_gmapaddress_arrhelper($field['gmap_all']['address'],$view))?check_plain(implode(' | ',$addresses)):'';                  $address = (_cck_gmapaddress_arrhelper($field['gmap_all']['address'],$view))?check_plain(implode(' | ',$addresses)):'';
477    
478                  //Route Link                  //Route Link
479                  $link='';                  $link='';
480                  if (in_array($view,$field['gmap_all']['routelink'])){                  if (in_array($view,$field['gmap_all']['routelink'])){
481                    $link = cck_gmapaddress_field_formatter($field,$item,'route_all',$node);                    $link = cck_gmapaddress_field_formatter($field,$item,'route_all',$node);
482                  }                  }
483    
484                  return $address.theme_gmap(array('#settings'=>$settings)).$link;                  return $address.theme_gmap(array('#settings'=>$settings)).$link;
485            } else {            } else {
486                  return '';                  return '';
487            }            }
488          case 'route_single':          case 'route_single':
489                  if (!empty($item['address'])){                  if (!empty($item['address'])){
490                          $addresses = array($item['address']);                          $addresses = array($item['address']);
491                          _cck_gmapaddress_addroutestartend($field[$formatter]['start'],&$addresses,$field[$formatter]['start_opt'],0);                          _cck_gmapaddress_addroutestartend($field[$formatter]['start'],&$addresses,$field[$formatter]['start_opt'],0);
492                          _cck_gmapaddress_addroutestartend($field[$formatter]['end'],&$addresses,$field[$formatter]['end_opt'],1);                          _cck_gmapaddress_addroutestartend($field[$formatter]['end'],&$addresses,$field[$formatter]['end_opt'],1);
493                          return _cck_gmapaddress_routelink($addresses,$field,$field[$formatter]['text']);                          return _cck_gmapaddress_routelink($addresses,$field,$field[$formatter]['text']);
494                  }                  }
495                  return '';                  return '';
496          case 'route_all':          case 'route_all':
497                  //fetches all addresses from node, only in run 1/delta==0                  //fetches all addresses from node, only in run 1/delta==0
498                  if ($item['address'] && $item['delta']==0){                  if ($item['address'] && $item['delta']==0){
499                      if (empty($node->{$field['field_name']})){                      if (empty($node->{$field['field_name']})){
500                                  $node = node_load($node->nid);                                  $node = node_load($node->nid);
501                          }                          }
502                          $addresses=array();                          $addresses=array();
503                          foreach ($node->{$field['field_name']} as $key=>$el){                          foreach ($node->{$field['field_name']} as $key=>$el){
504                                  $addresses[] = $el['address'];                                  $addresses[] = $el['address'];
505                          }                          }
506                          _cck_gmapaddress_addroutestartend($field[$formatter]['start'],$addresses,$field[$formatter]['start_opt'],0);                          _cck_gmapaddress_addroutestartend($field[$formatter]['start'],$addresses,$field[$formatter]['start_opt'],0);
507                          _cck_gmapaddress_addroutestartend($field[$formatter]['end'],$addresses,$field[$formatter]['end_opt'],1);                          _cck_gmapaddress_addroutestartend($field[$formatter]['end'],$addresses,$field[$formatter]['end_opt'],1);
508                          return _cck_gmapaddress_routelink($addresses,$field,$field[$formatter]['text']);                          return _cck_gmapaddress_routelink($addresses,$field,$field[$formatter]['text']);
509                  }                  }
510                  return '';                  return '';
511    }    }
512    return '';    return '';
513  }  }
514    
515    
516  function _cck_gmapaddress_accuracy($nr = -1){  function _cck_gmapaddress_accuracy($nr = -1){
517   $arr = array(   $arr = array(
518                                  0=>t('0 Unknown location'),                                  0=>t('0 Unknown location'),
519                                  1=>t('1 Country level accuracy'),                                  1=>t('1 Country level accuracy'),
520                                  2=>t('2 Region (state, province, prefecture, etc.) level accuracy'),                                  2=>t('2 Region (state, province, prefecture, etc.) level accuracy'),
521                                  3=>t('3 Sub-region (county, municipality, etc.) level accuracy'),                                  3=>t('3 Sub-region (county, municipality, etc.) level accuracy'),
522                                  4=>t('4 Town (city, village) level accuracy'),                                  4=>t('4 Town (city, village) level accuracy'),
523                                  5=>t('5 Post code (zip code) level accuracy'),                                  5=>t('5 Post code (zip code) level accuracy'),
524                                  6=>t('6 Street level accuracy'),                                  6=>t('6 Street level accuracy'),
525                                  7=>t('7 Intersection level accuracy'),                                  7=>t('7 Intersection level accuracy'),
526                                  8=>t('8 Address level accuracy'),                                  8=>t('8 Address level accuracy'),
527                                  9=>t('9 Premise (building name, property name, shopping center, etc.) level accuracy'),                                  9=>t('9 Premise (building name, property name, shopping center, etc.) level accuracy'),
528                          );                          );
529   return ($nr >= 0 && $nr <= 10)?$arr[$nr]:$arr;   return ($nr >= 0 && $nr <= 10)?$arr[$nr]:$arr;
530  }  }
531    
532  function _cck_gmapaddress_arrhelper($str,$view='full'){  function _cck_gmapaddress_arrhelper($str,$view='full'){
533          $temp = explode(';',$str);          $temp = explode(';',$str);
534          $arr = array();          $arr = array();
535          foreach ($temp as $k=>$el){          foreach ($temp as $k=>$el){
536                  $el = explode('=',$el);                  $el = explode('=',$el);
537                  if (strlen($el[1])==0){                  if (strlen($el[1])==0){
538                          $arr[0]=$el[0];                          $arr[0]=$el[0];
539                  } else {                  } else {
540                          $arr[$el[0]]=$el[1];                          $arr[$el[0]]=$el[1];
541                  }                  }
542          }          }
543          switch ($view){          switch ($view){
544                  case 'v':                  case 'v':
545                  case 'views':                  case 'views':
546                          return ($arr['v'])?$arr['v']:$arr[0];                          return ($arr['v'])?$arr['v']:$arr[0];
547                  case 't':                  case 't':
548                  case 'teaser':                  case 'teaser':
549                          return ($arr['t'])?$arr['t']:$arr[0];                          return ($arr['t'])?$arr['t']:$arr[0];
550                  case 'f':                  case 'f':
551                  case 'full':                  case 'full':
552                          return ($arr['f'])?$arr['f']:$arr[0];                          return ($arr['f'])?$arr['f']:$arr[0];
553                  case 'b':                  case 'b':
554                  case 'block':                  case 'block':
555                          return ($arr['b'])?$arr['b']:$arr[0];                          return ($arr['b'])?$arr['b']:$arr[0];
556                  default:                  default:
557                          return (!$arr[0])?$arr['f']:$arr[0];                          return (!$arr[0])?$arr['f']:$arr[0];
558          }          }
559  }  }
560    
561  function _cck_gmapaddress_routestartend($end){  function _cck_gmapaddress_routestartend($end){
562    return array('0'=>t('!nr address',array('!nr'=>($end)?t('Last'):t('First'))),    return array('0'=>t('!nr address',array('!nr'=>($end)?t('Last'):t('First'))),
563                            'empty'=>t('Empty Address'),                            'empty'=>t('Empty Address'),
564                            'fix'=>t('Fix Address'),                            'fix'=>t('Fix Address'),
565                            'user' =>t('User field'),                            'user' =>t('User field'),
566                            );                            );
567  }  }
568    
569  function _cck_gmapaddress_addroutestartend($key,&$addresses,$opt,$end=FALSE){  function _cck_gmapaddress_addroutestartend($key,&$addresses,$opt,$end=FALSE){
570          switch ($key) {          switch ($key) {
571                  case 'empty':                  case 'empty':
572                          $val = '-';                          $val = '-';
573                          break;                          break;
574                  case 'fix':                  case 'fix':
575                          $val = $opt;                          $val = $opt;
576                          break;                          break;
577                  case 'user':                  case 'user':
578                          GLOBAL $user;                          GLOBAL $user;
579                          $array = array();                          $array = array();
580                          user_module_invoke('load', &$array, &$user, $category = NULL);                          user_module_invoke('load', &$array, &$user, $category = NULL);
581                          $val = _cck_gmapaddress_userfield($opt,$user);                          $val = _cck_gmapaddress_userfield($opt,$user);
582                          $val = str_replace(array("\r\n", "\n", "\r"), ", ", $val);                          $val = str_replace(array("\r\n", "\n", "\r"), ", ", $val);
583                          break;                          break;
584                  default:                  default:
585                          return FALSE;                          return FALSE;
586          }          }
587    
588          return ($end)?array_push(&$addresses,$val):array_unshift(&$addresses,$val);          return ($end)?array_push(&$addresses,$val):array_unshift(&$addresses,$val);
589  }  }
590    
591  //Add multiple userfields to Address String  //Add multiple userfields to Address String
592  function _cck_gmapaddress_userfield($str,&$user,$sep=array(", ",","," ")){  function _cck_gmapaddress_userfield($str,&$user,$sep=array(", ",","," ")){
593          $vals = array($str);          $vals = array($str);
594          $seps = array(0=>"");          $seps = array(0=>"");
595    
596          foreach ($sep as $k=>$s){          foreach ($sep as $k=>$s){
597                  $vals2 = array();                  $vals2 = array();
598                  $seps2 = array();                  $seps2 = array();
599                  foreach($vals as $n=>$v){                  foreach($vals as $n=>$v){
600                          $arr = explode($s,$v);                          $arr = explode($s,$v);
601                          foreach ($arr as $i=>$v2){                          foreach ($arr as $i=>$v2){
602                            $vals2[]=$v2;                            $vals2[]=$v2;
603                            $seps2[]=($i>0)?$s:$seps[$n];                            $seps2[]=($i>0)?$s:$seps[$n];
604                          }                          }
605                  }                  }
606                  $vals = $vals2;                  $vals = $vals2;
607                  $seps = $seps2;                  $seps = $seps2;
608          }          }
609          $return = '';          $return = '';
610          foreach($vals as $k=>$val){          foreach($vals as $k=>$val){
611            if (strlen($val)>0){            if (strlen($val)>0){
612                  $val = "user->$val";                  $val = "user->$val";
613                  $return .= $seps[$k].eval("return \$$val;");                  $return .= $seps[$k].eval("return \$$val;");
614            }            }
615          }          }
616          return check_plain((strlen($return)>0)?$return:'-');          return check_plain((strlen($return)>0)?$return:'-');
617  }  }
618    
619  //Append 'px', if no string  //Append 'px', if no string
620  function _cck_gmapaddress_addpx($str){  function _cck_gmapaddress_addpx($str){
621          return (is_int($str))?$str:$str.'px';          return (is_int($str))?$str:$str.'px';
622  }  }
623    
624  function _cck_gmapaddress_mtc($val = '-1'){  function _cck_gmapaddress_mtc($val = '-1'){
625  $arr = array(0 => 'none',  $arr = array(0 => 'none',
626                           1 => 'standard',                           1 => 'standard',
627                           2 => 'hier',                           2 => 'hier',
628                           3 => 'menu',                           3 => 'menu',
629                  );                  );
630   return $arr[$val];   return $arr[$val];
631  }  }
632    
633  /**  /**
634   * Generate GMap Rout Link   * Generate GMap Rout Link
635   **/   **/
636  function _cck_gmapaddress_routelink($addresses,$field,$text='',$attributes = array()){  function _cck_gmapaddress_routelink($addresses,$field,$text='',$attributes = array()){
637  $addresses= array_values($addresses);  $addresses= array_values($addresses);
638  $text = ($text)?$text:'Route';  $text = ($text)?$text:'Route';
639    
640  $path = "http://maps.google.".$field['tld']."/maps";  $path = "http://maps.google.".$field['tld']."/maps";
641  $saddr = '';  $saddr = '';
642  $daddr = array();  $daddr = array();
643    
644   foreach ($addresses as $nr=>$adr){   foreach ($addresses as $nr=>$adr){
645          if ($nr>0){          if ($nr>0){
646                  $daddr[]=$adr;                  $daddr[]=$adr;
647          } else {          } else {
648                  $saddr = $adr;                  $saddr = $adr;
649          }          }
650   }   }
651    
652   return l($text, $path, $attributes, "f=d&saddr=$saddr&daddr=".implode('+to:',$daddr), NULL, TRUE, FALSE);   return l($text, $path, $attributes, "f=d&saddr=$saddr&daddr=".implode('+to:',$daddr), NULL, TRUE, FALSE);
653    
654  /** http://maps.google.de/maps?  /** http://maps.google.de/maps?
655                                          f=d                                          f=d
656                                          &hl=de                                          &hl=de
657                                          &geocode=                                          &geocode=
658                                          &saddr=Holzminden                                          &saddr=Holzminden
659                                          &daddr=Karlsruhe                                          &daddr=Karlsruhe
660                                                  +to:bozen                                                  +to:bozen
661                                          &mra=pi                                          &mra=pi
662                                          &mrcr=1                                          &mrcr=1
663                                          &sll=50.41419,9.002155                                          &sll=50.41419,9.002155
664                                          &sspn=4.809747,14.018555                                          &sspn=4.809747,14.018555
665                                          &ie=UTF8                                          &ie=UTF8
666                                          &z=6                                          &z=6
667  */  */
668  }  }
669    
670  /**  /**
671   * Hook_block()   * Hook_block()
672   *   *
673   * Provides some blocks for showing an address or google map in a separate Block.   * Provides some blocks for showing an address or google map in a separate Block.
674   */   */
675   function cck_gmapaddress_block($op = 'list', $delta = 0, $edit = array()) {   function cck_gmapaddress_block($op = 'list', $delta = 0, $edit = array()) {
676    $count = variable_get('cck_gmapaddress_count',  1);    $count = variable_get('cck_gmapaddress_count',  1);
677    switch ($op) {    switch ($op) {
678      case 'list':      case 'list':
679            for ($i=0;$i < $count;$i++){            for ($i=0;$i < $count;$i++){
680                  $blocks[$i]['info'] =  t('Gmap Address #@nr',array('@nr'=>$i+1));                  $blocks[$i]['info'] =  t('Gmap Address #@nr',array('@nr'=>$i+1));
681            }            }
682        return $blocks;        return $blocks;
683          case 'configure':          case 'configure':
684        $form = array();        $form = array();
685        if ($delta == 0) {        if ($delta == 0) {
686                  $form['cck_gmapaddress_count'] = array(                  $form['cck_gmapaddress_count'] = array(
687            '#type' => 'select',            '#type' => 'select',
688            '#title' => t('Numbers of GMap Address blocks'),            '#title' => t('Numbers of GMap Address blocks'),
689            '#description' => t('Select, how many blocks shall be configurable.'),            '#description' => t('Select, how many blocks shall be configurable.'),
690            '#default_value' => variable_get('cck_gmapaddress_count',  1),            '#default_value' => variable_get('cck_gmapaddress_count',  1),
691                    '#options' => array_combine(range(1,9),range(1,9)),                    '#options' => array_combine(range(1,9),range(1,9)),
692          );          );
693            }            }
694        $form['cck_gmapaddress_field'] = array(        $form['cck_gmapaddress_field'] = array(
695            '#type' => 'select',            '#type' => 'select',
696            '#title' => t('Node Reference Field'),            '#title' => t('Node Reference Field'),
697            '#description' => t('The name of the cck GMapAddress field, which content should be presented.'),            '#description' => t('The name of the cck GMapAddress field, which content should be presented.'),
698            '#default_value' => variable_get("cck_gmapaddress_field_$delta",  ''),            '#default_value' => variable_get("cck_gmapaddress_field_$delta",  ''),
699                    '#options' => _cck_gmapaddress_fields(),                    '#options' => _cck_gmapaddress_fields(),
700        );        );
701            $form['cck_gmapaddress_formatter'] = array(            $form['cck_gmapaddress_formatter'] = array(
702            '#type' => 'select',            '#type' => 'select',
703            '#title' => t('Formatter'),            '#title' => t('Formatter'),
704            '#description' => t('Select a formatter for block view.'),            '#description' => t('Select a formatter for block view.'),
705            '#default_value' => variable_get("cck_gmapaddress_formatter_$delta",  ''),            '#default_value' => variable_get("cck_gmapaddress_formatter_$delta",  ''),
706                    '#options'=>_cck_gmapaddress_formatters(),                    '#options'=>_cck_gmapaddress_formatters(),
707        );        );
708        return $form;        return $form;
709      case 'save':      case 'save':
710        if ($delta == 0) {        if ($delta == 0) {
711          variable_set("cck_gmapaddress_count", $edit['cck_gmapaddress_count']);          variable_set("cck_gmapaddress_count", $edit['cck_gmapaddress_count']);
712            }            }
713            variable_set("cck_gmapaddress_field_$delta", $edit['cck_gmapaddress_field']);            variable_set("cck_gmapaddress_field_$delta", $edit['cck_gmapaddress_field']);
714            variable_set("cck_gmapaddress_formatter_$delta", $edit['cck_gmapaddress_formatter']);            variable_set("cck_gmapaddress_formatter_$delta", $edit['cck_gmapaddress_formatter']);
715        return;        return;
716      case 'view':      case 'view':
717        //Zeige GMapAddress in gewähltem Format, falls node        //Zeige GMapAddress in gewähltem Format, falls node
718            $fieldname = variable_get("cck_gmapaddress_field_$delta",  '');            $fieldname = variable_get("cck_gmapaddress_field_$delta",  '');
719            if (strlen($fieldname)==0){return '';}            if (strlen($fieldname)==0){return '';}
720            $nid = _cck_gmapaddress_getnid($delta);            $nid = _cck_gmapaddress_getnid($delta);
721            if (!$nid){return '';}            if (!$nid){return '';}
722            $node = node_load($nid);            $node = node_load($nid);
723            $field = content_fields($fieldname,$node->type);            $field = content_fields($fieldname,$node->type);
724            $node_field = $node->$fieldname;            $node_field = $node->$fieldname;
725            $formatter = variable_get("cck_gmapaddress_formatter_$delta",  '');            $formatter = variable_get("cck_gmapaddress_formatter_$delta",  '');
726            if (!empty($node_field)){            if (!empty($node_field)){
727                    foreach ($node_field as $i => $item) {                    foreach ($node_field as $i => $item) {
728              $node_field[$i]['view'] = cck_gmapaddress_field_formatter($field, $item, $formatter, $node, TRUE);              $node_field[$i]['view'] = cck_gmapaddress_field_formatter($field, $item, $formatter, $node, TRUE);
729            }            }
730                    $block['subject'] = $field['label'];                    $block['subject'] = $field['label'];
731                $block['content'] = theme('field', $node, $field, $node_field,NULL,NULL);                $block['content'] = theme('field', $node, $field, $node_field,NULL,NULL);
732            }            }
733        return $block;        return $block;
734    }    }
735  }  }
736    
737  function _cck_gmapaddress_fields(){  function _cck_gmapaddress_fields(){
738          $fields = content_fields();          $fields = content_fields();
739          $return = array();          $return = array();
740          foreach ($fields as $field) {          foreach ($fields as $field) {
741                  if ($field['type'] == 'cck_gmapaddress'){                  if ($field['type'] == 'cck_gmapaddress'){
742                          $return[] = $field['field_name'];                          $return[] = $field['field_name'];
743                  }                  }
744          }          }
745          return array_combine($return,$return);          return array_combine($return,$return);
746  }  }
747    
748  function _cck_gmapaddress_formatters(){  function _cck_gmapaddress_formatters(){
749          $return = array();          $return = array();
750          $formatters = cck_gmapaddress_field_formatter_info();          $formatters = cck_gmapaddress_field_formatter_info();
751          foreach ($formatters as $f=>$info){          foreach ($formatters as $f=>$info){
752                  $return[$f]=$info['label'];                  $return[$f]=$info['label'];
753          }          }
754          return $return;          return $return;
755  }  }
756    
757  function _cck_gmapaddress_getblock($delta=0){  function _cck_gmapaddress_getblock($delta=0){
758          return db_fetch_array(db_query("SELECT pages, visibility, custom, title FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'cck_gmapaddress', $delta));          return db_fetch_array(db_query("SELECT pages, visibility, custom, title FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'cck_gmapaddress', $delta));
759  }  }
760    
761  function _cck_gmapaddress_getnid($delta){  function _cck_gmapaddress_getnid($delta){
762          $block = _cck_gmapaddress_getblock($delta);          $block = _cck_gmapaddress_getblock($delta);
763          $vis = $block['visibility'];          $vis = $block['visibility'];
764          $pages = $block['pages'];          $pages = $block['pages'];
765          if ($vis == 2){ //php-code          if ($vis == 2){ //php-code
766                  // take returned int as nid                  // take returned int as nid
767                  return drupal_eval($pages);                  return drupal_eval($pages);
768          } else {//only listed          } else {//only listed
769                  //fetch first integer with *-replacement                  //fetch first integer with *-replacement
770                  $pages = explode('||',str_replace(array("\r\n", "\n", "\r"), "||", $pages));                  $pages = explode('||',str_replace(array("\r\n", "\n", "\r"), "||", $pages));
771                  $nid = 0;                  $nid = 0;
772                  foreach ($pages as $nr=>$page){                  foreach ($pages as $nr=>$page){
773                          $page = explode('/',$page);                          $page = explode('/',$page);
774                          $nid = 0;                          $nid = 0;
775                          foreach($page as $n=>$p){                          foreach($page as $n=>$p){
776  //                              print "<br/>P:$p-".arg($n);  //                              print "<br/>P:$p-".arg($n);
777                                  if ($p== '$'){                                  if ($p== '$'){
778                                          $nid = 1*arg($n);                                          $nid = 1*arg($n);
779                                  } elseif ($p == '*' && $nid == 0){                                  } elseif ($p == '*' && $nid == 0){
780                                    $nid = 1*arg($n);                                    $nid = 1*arg($n);
781                                  } elseif ($p != arg($n)){                                  } elseif ($p != arg($n)){
782                                    $nid = 0;                                    $nid = 0;
783                                    break;                                    break;
784                                  }                                  }
785                          }                          }
786                          if (is_int($nid) && $nid>0 && $vis == 1){                          if (is_int($nid) && $nid>0 && $vis == 1){
787                                  return $nid;                                  return $nid;
788                          } elseif (is_int($nid) && $nid>0 && $vis == 0) {                          } elseif (is_int($nid) && $nid>0 && $vis == 0) {
789                              break;  //break, because query is in banned list                              break;  //break, because query is in banned list
790                          }                          }
791                  }                  }
792          }          }
793          if ($nid != 0){return 0;}          if ($nid != 0){return 0;}
794          //fetch first integer as nid, for sites that were not banned          //fetch first integer as nid, for sites that were not banned
795          if ($vis == 0) {          if ($vis == 0) {
796                  for ($i=0;$i<=5;$i++){                  for ($i=0;$i<=5;$i++){
797                          $nid = 1*arg($i);                          $nid = 1*arg($i);
798                          if ($nid !== ''){                          if ($nid !== ''){
799                                  $nid *= (is_int($nid) && $nid > 0);                                  $nid *= (is_int($nid) && $nid > 0);
800                                  if ($nid>0){ return $nid;}                                  if ($nid>0){ return $nid;}
801                          }                          }
802                  }                  }
803          }          }
804    
805          return $nid;          return $nid;
806  }  }
807    
808  ?>  ?>

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2