Project

General

Profile

Download (71.8 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?php
2
/**
3
 * @file
4
 * Module to provide a CDM Dataportal.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 *   - Wouter Addink <w.addink@eti.uva.nl> (migration from Drupal 5 to Drupal7)
18
 */
19
20
module_load_include('php', 'cdm_dataportal', 'node_types');
21
module_load_include('php', 'cdm_dataportal', 'settings');
22
module_load_include('php', 'cdm_dataportal', 'help');
23
module_load_include('php', 'cdm_dataportal', 'cdm_dataportal.search');
24
25
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.common');
26
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.descriptions');
27
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.media');
28
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.occurrence');
29
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.page');
30
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.taxon');
31
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.name');
32
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.references');
33
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.bibliography');
34
35
module_load_include('php', 'cdm_dataportal', 'classes/footnotemanager');
36
module_load_include('php', 'cdm_dataportal', 'classes/footnote');
37
module_load_include('php', 'cdm_dataportal', 'classes/footnotekey');
38
module_load_include('php', 'cdm_dataportal', 'classes/renderhints');
39
40
/**
41
* loads external java script files asynchronously.
42
*
43
* @param unknown_type $script_url
44
*/
45
function drupal_add_js_async($script_url, $callback){
46
47
  drupal_add_js("
48
        jQuery(document).ready(function() {
49
          jQuery.ajax({
50
            url: '" . $script_url . "',
51
            dataType: 'script',
52
            cache: true, // otherwise will get fresh copy every page load
53
            success: function() {
54
                  " . $callback . "
55
            }
56
          });
57
        });"
58
  , 'inline');
59
}
60
61
/**
62
 * @param unknown_type $link_element_selector
63
 * @param unknown_type $progress_element_selector
64
 */
65
function _add_js_cdm_ws_progressbar($link_element_selector, $progress_element_selector){
66
67
  $callback = "jQuery('" . $link_element_selector . "').cdm_ws_progress('" . $progress_element_selector . "');";
68
69
  drupal_add_js_async(variable_get('cdm_webservice_url', '').'js/cdm_ws_progress.js', $callback);
70
71
  //   drupal_add_js("
72
  //   	  if (Drupal.jsEnabled) {
73
  //         $(document).ready(function() {
74
  //       		$('" . $link_element_selector . "').cdm_ws_progress('" . $progress_element_selector . "');
75
  //         });
76
  //       }", 'inline');
77
  }
78
79
/**
80
 * @todo Please document this function.
81
 * @see http://drupal.org/node/1354
82
 */
83
function _add_js_treeselector() {
84
  // drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/treeselector.js');
85
  drupal_add_js("
86
      jQuery(document).ready(function() {
87
         jQuery('#cdm-taxonomictree-selector-form #edit-val').change(function () {
88
              jQuery('#cdm-taxonomictree-selector-form').submit();
89
          });
90
91
      });
92 78e178e2 Andreas Kohlbecker
    ",
93
    array(
94
      'type' => 'inline',
95
      'scope' => 'footer'
96
    )
97
  );
98 6657531f Andreas Kohlbecker
}
99
100
/**
101
 * @todo Please document this function.
102
 * @see http://drupal.org/node/1354
103
 */
104
function _add_js_openlayers_map() {
105
106 e7505114 Andreas Kohlbecker
  $openlayers = '/js/OpenLayers-2.11/OpenLayers.js';
107
108
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . $openlayers, array(
109
      'type' => 'file',
110
      'weight' => JS_LIBRARY,
111
      'cache' => FALSE,
112 6657531f Andreas Kohlbecker
  ));
113 e7505114 Andreas Kohlbecker
114 6657531f Andreas Kohlbecker
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/openlayers_map.js');
115
116
  $gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
117
118
  $baseLayers = variable_get('baselayers', array());
119
  if (!is_array($baseLayers) || count($baseLayers) == 0) {
120
    $baseLayers = array(
121
      'metacarta_vmap0' => 'Metacarta Vmap0',
122
      'PREFERRED' => 'metacarta_vmap0',
123
    );
124
  }
125
  $layerNames = '';
126
  foreach ($baseLayers as $layerName => $layerLabel) {
127
    if ($layerName == 'PREFERRED') {
128
      $preferredLayer = $baseLayers['PREFERRED'];
129
    }
130
    else {
131
      $layerNames .= ($layerNames ? ', ' : '') . "'$layerName'";
132
    }
133
  }
134
135
  if (isset($baseLayers['gmap']) || isset($baseLayers['gsat']) || isset($baseLayers['ghyb'])) {
136
    drupal_add_html_head('<script src=http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=' . $gmap_api_key . '" type="text/javascript"></script>', $key = NULL /* TODO Set this variable. */);
137
    drupal_add_js('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1', array('type' => 'external'));
138
  }
139
140 e7505114 Andreas Kohlbecker
  // window.onload - is executed when the document and images etc is fully loaded
141
  // Query(document).ready - is executed much earlier, when the DOM is loaded
142 6657531f Andreas Kohlbecker
  drupal_add_js("
143
          jQuery(document).ready(function() {
144 e7505114 Andreas Kohlbecker
145
                window.onload = function () {
146
    			  // ---
147
                  jQuery('#openlayers_map').cdm_openlayers_map('"
148
                  . getEDITMapServiceURI() . "', {
149
                    legendPosition: 3,
150
                    displayWidth: '" . variable_get('cdm_dataportal_geoservice_display_width', FALSE) . "',
151
                    boundingBox: '" . variable_get('cdm_dataportal_geoservice_bounding_box', FALSE) . "',
152
                    distributionOpacity: '" . variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5') . "',
153
                    legendOpacity: '" . variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5') . "',
154
                    showLayerSwitcher: " . (variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE) ? 'true' : 'false') . ",
155
                    baseLayerNames: [" . $layerNames . "],
156
                    defaultBaseLayerName: '" . $preferredLayer . "',
157
               	  });
158
               	  // ---
159
				};
160 6657531f Andreas Kohlbecker
          });
161
        ", array('type' => 'inline'));
162
163
}
164
165
/**
166
 * @todo Enter description here ...
167
 *
168
 * @param unknown_type $width
169
 * @param unknown_type $bounding_box
170
 * @param unknown_type $occurrenceQuery
171
 * @param unknown_type $distributionQuery
172
 * @param unknown_type $legendFormatQuery
173
 * @param unknown_type $map_caption
174
 *
175
 * @return unknown
176
 */
177
function get_image_map($width, $bounding_box = FALSE, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE) {
178
179
  $server = getEDITMapServiceURI();
180
181
  if (!$server) {
182
    // Warning message.
183
    drupal_set_message(t(
184
      "No 'Geoservice Access Point' has been set so far.
185
      Please configure the variable 'Geoservice Access Point' here !url", array(
186
        '!url' => l(t('CDM Dataportal Settings'), 'admin/config/cdm_dataportal/geo'),
187
      )), 'warning');
188
189
    // Message to render.
190
    return '<p>' . t('No geoservice specified') . '</p>';
191
  }
192
193
  // Additional query parameters as set in the data portal admin section.
194
  $labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
195
196
  $query_string = '&image=true&recalculate=false&legend=1&ms=' . $width
197
    . ($bounding_box ? '&bbox=' . $bounding_box : '')
198
    . ($labels_on ? '&label=' . $labels_on : '');
199
200
  if ($map_caption) {
201
    $query_string .= '&mlp=3&mc_s=Georgia,15,blue&mc=' . $map_caption;
202
  }
203
204
  if (getEDITMapServiceVersionNumber() >= 1.1) {
205
206
    // Either occurrence or distribution - combined maps will be possible
207
    // in the future.
208
    if ($occurrenceQuery) {
209
      // @todo Fix $occurrenceQuery.
210
      $occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery);
211
      // $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
212
      // Will be replaced below.. HACK!!!
213
      $occurrenceQuery .= '&l=tdwg4&as=';
214
215
      $query_string .= "&" . $occurrenceQuery;
216
    }
217
    elseif ($distributionQuery) {
218
      $query_string .= "&" . $distributionQuery;
219
    }
220
221
    // Apply Plain Image map settings special for version >= 1.1.
222
    /*
223
    example : title=a:Naturalized++non-invasive
224
    &ad=cyprusdivs:bdcode:a:5&as=a:ff9900,,0.1,&l=tdwg4
225
    &ms=500&bbox=32,34,35,36&img=true&legend=1&mlp=3
226
    &mc_s=Georgia,15,blue&mc=&recalculate=false
227
228
    http://edit.br.fgov.be/edit_wp5/v1/rest_gen.php?
229
    l=background_gis:b,cyprusdivs&ad=cyprusdivs%3Abdcode%3Aa%3A8%2C4
230
    &as=a%3A339966%2C%2C0.1%2C|b:0000ff,,
231
    &bbox=32%2C34%2C35%2C36&img=true&legend=1&mc=&mc_s=Georgia%2C15%2Cblue
232
    &mlp=3&ms=500&recalculate=false&title=a%3Aindigenous
233
    */
234
235
    $map_service_script_name = "rest_gen.php";
236
237
    $bgcolor_areaStyleId = "y";
238
    $baselayer_areaStyleId = "z";
239
    $bgcolor_layer = '';
240
    $additional_area_styles = array();
241
242
    // Background color:
243
    if (variable_get('map_bg_color', '')) {
244
      $bgcolor_layer = "background_gis:" . $bgcolor_areaStyleId;
245
      $additional_area_styles[] = $bgcolor_areaStyleId . ":" . variable_get('map_bg_color', '') . ",,";
246
    }
247
248
    // TODO HACK to replace the default base layer which currently is tdwg4 !!!
249
    // only needed for distribution maps.
250
    if (strpos($query_string, "?l=") !== FALSE) {
251
      $layer_param_token = "?l=";
252
    }
253
    else {
254
      $layer_param_token = "&l=";
255
    }
256
    if (strpos($query_string, "?as=") !== FALSE) {
257
      $areystyle_param_token = "?as=";
258
    }
259
    else {
260
      $areystyle_param_token = "&as=";
261
    }
262
    if (variable_get('map_base_layer', '')) {
263
      $query_string = str_replace($layer_param_token . "tdwg4", "$layer_param_token" . variable_get('map_base_layer', '') . ":" . $baselayer_areaStyleId, $query_string);
264
    }
265
    else {
266
      $query_string = str_replace($layer_param_token . "tdwg4", $layer_param_token . "tdwg4:" . $baselayer_areaStyleId . ",", $query_string);
267
    }
268
269
    if ($bgcolor_layer) {
270
      $query_string = str_replace($layer_param_token, $layer_param_token . $bgcolor_layer . ",", $query_string);
271
    }
272
273
    if (variable_get('map_base_layer_style', '')) {
274
      $additional_area_styles[] = $baselayer_areaStyleId . ":" . variable_get('map_base_layer_style', '');
275
    }
276
277
    foreach ($additional_area_styles as $as) {
278
      $query_string = str_replace($areystyle_param_token, $areystyle_param_token . $as . "|", $query_string);
279
    }
280
281
  }
282
  else {
283
    // Pre 1.1. version of map service.
284
    if ($occurrenceQuery) {
285
286
      $map_service_script_name = "point.php";
287
288
      // Fix $occurrenceQuery.
289
      $occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery);
290
      // $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
291
      $occurrenceQuery .= '&l=v:e_w_0';
292
      $query_string .= "&" . $occurrenceQuery;
293
    }
294
    elseif ($distributionQuery) {
295
      $query_string .= "&" . $distributionQuery;
296
      $map_service_script_name = "areas.php";
297
    }
298
  }
299
300
  $mapUri = url("$server/$map_service_script_name?$query_string");
301
  $out = '<img class="distribution_map" src="' . $mapUri . '" alt="Map" />';
302
  // Showing map caption.
303
  if ($map_caption) {
304
    // FIXME: replace <br> by according css style.
305
    $out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />';
306
    $out .= '</div>';
307
  }
308
309
  return $out;
310
}
311
312
/**
313
 * @todo Enter description here ...
314
 *
315
 * @param unknown_type $width
316
 * @param unknown_type $bounding_box
317
 * @param unknown_type $occurrenceQuery
318
 * @param unknown_type $distributionQuery
319
 * @param unknown_type $legendFormatQuery
320
 * @param unknown_type $map_caption
321
 *
322
 * @return unknown
323
 */
324
function get_openlayers_map($width, $bounding_box = FALSE, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE) {
325
326
  _add_js_openlayers_map();
327
328
  $out = '<div id="openlayers">';
329
  $out .= '<div id="openlayers_map" class="smallmap"';
330
  $out .= ' style="width: ' . $width . 'px; height:' . ($width / 2) . 'px"';
331
332
  // Additional query parameters as set in the data portal admin section.
333
  $labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
334
335
  $openlayers_map_query_string = '&img=false&ms=' . $width
336
    . ($bounding_box ? '&bbox=' . $bounding_box : '')
337
    . ($labels_on ? '&label=' . $labels_on : '');
338
339
  if ($occurrenceQuery) {
340
    // @todo Fix $occurrenceQuery.
341
    $occurrenceQuery .= '&bbox=-180,-90,180,90';
342
    $occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
343
    // $occurrenceQuery .= '&l=v:e_w_0';
344
    // TODO add to cdm service?
345
    $occurrenceQuery .= '&legend=0';
346
347
    $out .= ' occurrenceQuery="' . $occurrenceQuery . '&' . $openlayers_map_query_string . '"';
348
  }
349
350
  if ($distributionQuery) {
351
    $out .= ' distributionQuery="' . $distributionQuery . '&' . $openlayers_map_query_string . '"';
352
  }
353
354
  if ($legendFormatQuery) {
355
    $out .= ' legendFormatQuery="' . $legendFormatQuery . '"';
356
  }
357
358
  $out .= '></div></div>';
359
360
  // Showing map caption.
361
  if ($map_caption) {
362
    // FIXME: replace <br> by according css style.
363
    $out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />';
364
    $out .= '</div>';
365
  }
366
  return $out;
367
}
368
369
/* ====================== hook implementations ====================== */
370
/**
371
 * Implements hook_permission().
372
 *
373
 * Valid permissions for this module.
374
 *
375
 * @return array
376
 *   An array of valid permissions for the portfolio module.
377
 */
378
function cdm_dataportal_permission() {
379
  return array(
380
    'administer cdm_dataportal' => array(
381
      'title' => t('administer cdm_dataportal'),
382
      'description' => t("TODO Add a description for 'administer cdm_dataportal'"),
383
    ),
384
    'cdm_dataportal view notes' => array(
385
      'title' => t('cdm_dataportal view notes'),
386
      'description' => t("TODO Add a description for 'cdm_dataportal view notes'"),
387
    ),
388
    // TODO Which other permissions are required?
389
    // -> check the WP6 requirements document.
390
  );
391
}
392
393
/**
394
 * Implements hook_menu().
395
 */
396
function cdm_dataportal_menu() {
397
  $items = array();
398
399
  // @see settings.php.
400
  cdm_dataportal_menu_admin($items);
401
  cdm_dataportal_menu_help($items);
402
403
  $items['cdm_dataportal/names'] = array(
404
    'page callback' => 'cdm_dataportal_view_names',
405
    'access arguments' => array('access content'),
406
    'type' => MENU_CALLBACK,
407
  );
408
409
  // Optional callback arguments: page.
410
  $items['cdm_dataportal/taxon'] = array(
411
    'page callback' => 'cdm_dataportal_taxon_page_view',
412
    'access arguments' => array('access content'),
413
    'type' => MENU_CALLBACK,
414
    // Expected callback arguments: uuid.
415
  );
416
417
  $items['cdm_dataportal/name'] = array(
418
    'page callback' => 'cdm_dataportal_name_page_view',
419
      /*
420
    'page arguments' => array(
421
       'taxon_name_uuid',
422
       'taxon_to_hide_uuid',
423
       'synonym_uuid' => NULL
424
      ),
425
      */
426
    'access arguments' => array('access content'),
427
    'type' => MENU_CALLBACK,
428
    // Expected callback arguments: uuid.
429
  );
430
431
  $items['cdm_dataportal/reference'] = array(
432
    'page callback' => 'cdm_dataportal_view_reference',
433
    'access arguments' => array('access content'),
434
    'type' => MENU_CALLBACK,
435
    // Expected callback arguments: uuid.
436
  );
437
438
  $items['cdm_dataportal/reference/list'] = array(
439
    'page callback' => 'cdm_dataportal_view_reference_list',
440
    'access arguments' => array('access content'),
441
    'type' => MENU_CALLBACK,
442
    // Expected callback arguments: uuid.
443
  );
444
445
  $items['cdm_dataportal/media'] = array(
446
    'page callback' => 'cdm_dataportal_view_media',
447
    'access arguments' => array('access content'),
448
    'type' => MENU_CALLBACK,
449
    // Expected callback arguments:
450
    // uuid, mediarepresentation_uuid, part_uuid or part#.
451
  );
452
453
  $items['cdm_dataportal/polytomousKey'] = array(
454
    'page callback' => 'cdm_dataportal_view_polytomousKey',
455
    'access arguments' => array('access content'),
456
    'type' => MENU_CALLBACK,
457
    // Expected callback arguments: polytomousKey->uuid.
458
  );
459
460
  $items['cdm_dataportal/search'] = array(
461
    'page callback' => 'cdm_dataportal_view_search_advanced',
462
    'access arguments' => array('access content'),
463
    'type' => MENU_CALLBACK,
464
  );
465
466
  $items['cdm_dataportal/search/advanced'] = array(
467
    'title' => 'Advanced',
468
    'page callback' => 'cdm_dataportal_view_search_advanced',
469
    'access arguments' => array('access content'),
470
    'type' => MENU_DEFAULT_LOCAL_TASK,
471
  );
472
473
  $items['cdm_dataportal/search/taxon_by_description'] = array(
474
    'title' => 'By description full text',
475
    'page callback' => 'cdm_dataportal_view_search_taxon_by_description',
476
    'access arguments' => array('access content'),
477
    'type' => MENU_LOCAL_TASK,
478
  );
479
480
  $items['cdm_dataportal/search/results/taxon'] = array(
481
    'page callback' => 'cdm_dataportal_view_search_results_taxon',
482
    'access arguments' => array('access content'),
483
    'type' => MENU_CALLBACK,
484
  );
485
  /*
486
   $items['cdm/xml2json'] = array(
487
   'page callback' => 'cdm_view_xml2json',
488
   'access arguments' => array('access content'),
489
   'type' => MENU_CALLBACK,
490
   );
491
   */
492
493
  // if (arg(0)=='user' && ($uid=arg(1)) && is_numeric($uid)) {
494
  // User configuration of cdm_dataportal.
495
  $items['user/%/cdm_dataportal'] = array(
496
    'title' => 'cdm_dataportal',
497
    'access arguments' => array('access content'),
498
    'page callback' => 'drupal_get_form',
499
    'page arguments' => array('cdm_dataportal_user_form'),
500
    'type' => MENU_LOCAL_TASK,
501
    'weight' => 10,
502
  );
503
  // }
504
505
  // 'May not cache' in D5.
506
  // --- Local tasks for Taxon.
507
  $items['cdm_dataportal/name/%'] = array(
508
    // 'page callback' => 'cdm_dataportal_view_name',
509
    'page callback' => 'cdm_dataportal_name_page_view',
510
    'page arguments' => array(2, 3, 4),
511
    'access arguments' => array('access content'),
512
    'type' => MENU_CALLBACK,
513
  );
514
515
  if (variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
516
    $items['cdm_dataportal/taxon/%'] = array(
517
      'title' => theme('cdm_taxonpage_tab', array('tabname' => 'General')),
518
      'page callback' => 'cdm_dataportal_taxon_page_view',
519
      'access arguments' => array('access content'),
520
      'type' => MENU_CALLBACK,
521
      'weight' => 1,
522
      'page arguments' => array(2, "description")
523
      , // Expected callback arguments: name_uuid.
524
    );
525
526
    $items['cdm_dataportal/taxon/%/all'] = array(
527
      'title' => theme('cdm_taxonpage_tab', array('tabname' => 'General')),
528
      'page callback' => 'cdm_dataportal_taxon_page_view',
529
      'access arguments' => array('access content'),
530
      'type' => MENU_CALLBACK,
531
      'weight' => 2,
532
      'page arguments' => array(2, "all")
533
      , // Expected callback arguments: name_uuid.
534
    );
535
536
    $items['cdm_dataportal/taxon/%/description'] = array(
537
      'title' => theme('cdm_taxonpage_tab', array('tabname' => 'General')),
538
      'page callback' => 'cdm_dataportal_taxon_page_view',
539
      'access arguments' => array('access content'),
540
      'type' => MENU_DEFAULT_LOCAL_TASK,
541
      'weight' => 2,
542
      'page arguments' => array(2, "description")
543
      , // Expected callback arguments: name_uuid.
544
    );
545
546
    $items['cdm_dataportal/taxon/%/synonymy'] = array(
547
      'title' => theme('cdm_taxonpage_tab', array('tabname' => 'Synonymy')),
548
      'page callback' => 'cdm_dataportal_taxon_page_view',
549
      'access arguments' => array('access content'),
550
      'type' => MENU_LOCAL_TASK,
551
      'weight' => 4,
552
      'page arguments' => array(2, "synonymy", 4)
553
      , // Expected callback arguments: name_uuid.
554
    );
555
    $items['cdm_dataportal/taxon/%/images'] = array(
556
      'title' => theme('cdm_taxonpage_tab', array('tabname' => 'Images')),
557
      'page callback' => 'cdm_dataportal_taxon_page_view',
558
      'access arguments' => array('access content'),
559
      'type' => MENU_LOCAL_TASK,
560
      'weight' => 5,
561
      'page arguments' => array(2, "images")
562
      , // Expected callback arguments: name_uuid.
563
    );
564
565
    $items['cdm_dataportal/taxon/%/specimens'] = array(
566
      'title' => theme('cdm_taxonpage_tab', array('tabname' => 'Specimens')),
567
      'page callback' => 'cdm_dataportal_taxon_page_view',
568
      'access arguments' => array('access content'),
569
      'type' => MENU_LOCAL_TASK,
570
      'weight' => 6,
571
      'page arguments' => array(2, "specimens")
572
      , // Expected callback arguments: name_uuid.
573
    );
574
575
    $items['cdm_dataportal/taxon/%/keys'] = array(
576
      'title' => theme('cdm_taxonpage_tab', array('tabname' => 'Keys')),
577
      'page callback' => 'cdm_dataportal_taxon_page_view',
578
      'access arguments' => array('access content'),
579
      'type' => MENU_LOCAL_TASK,
580
      'weight' => 6,
581
      'page arguments' => array(2, "keys")
582
      , // Expected callback arguments: name_uuid.
583
    );
584
  }
585
586
  return $items;
587
}
588
589
/**
590
 * @todo Please document this function.
591
 * @see http://drupal.org/node/1354
592
 */
593
function cdm_dataportal_init() {
594
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal.css');
595
  // drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
596
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_screen.css', array('type' => 'screen'));
597
}
598
599
/**
600
 * The function generate form for own user cdm dataportal configurations.
601
 */
602
function cdm_dataportal_user_form($form, &$form_state) {
603
  global $user;
604
  $checkbox_value = 'cdm_dataportal_' . $user->uid . '_default_tab_active';
605
606
  $form['check'] = array(
607
    '#type' => 'checkbox',
608
    '#title' => t('Activate user default configuration'),
609
    '#default_value' => variable_get($checkbox_value, 0),
610
    '#description' => t('Check this if you want configure your own default tab from the below menu.'),
611
  );
612
613
  $form['cdm_dataportal_user_form'] = array(
614
    '#type' => 'select',
615
    '#title' => t('Default tab to display'),
616
    '#default_value' => get_default_taxon_tab(TRUE),
617
    '#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
618
    '#description' => t('<p>Select the default tab to display when visiting a taxon page. Only available if Tabbed Taxon Page is enable.</p>
619
              <strong>Note:</strong> After performing a search and clicking in any synonym, the taxon tab
620
              to be renderized will be the synonymy of the accepted taxon and not the above selected tab.'),
621
  );
622
623
  $form['submit'] = array(
624
    '#type' => 'submit',
625
    '#value' => t('Submit'),
626
  );
627
628
  return $form;
629
}
630
631
/**
632
 * Form submission handler for user_form().
633
 *
634
 * Submits the user cdm dataportal configurations.
635
 */
636
function cdm_dataportal_user_form_submit($form, &$form_state) {
637
  global $user;
638
  $msg_type = 'status';
639
  $username = $user->name;
640
  $variable_to_use = 'cdm_dataportal_' . $user->uid . '_default_tab';
641
642
  // If is the right user the variables are setted.
643
  if (arg(0) == 'user' && ($uid = arg(1)) && is_numeric($uid) && $user->uid == $uid) {
644
    $variable = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
645
    variable_set($variable_to_use . '_active', $form_state['values']['check']);
646
    variable_set($variable_to_use, $form_state['values']['cdm_dataportal_user_form']);
647
    if ($form_state['values']['check']) {
648
      drupal_set_message(check_plain(t('The user default tab will be used for the next taxon site visit.')));
649
      drupal_set_message(check_plain(t('The user default tab has been changed to: !tab for the user !user', array(
650
        '!tab' => $variable[variable_get($variable_to_use, 0)],
651
        '!user' => $username,
652
      ))), $msg_type);
653
    }
654
    else {
655
      drupal_set_message(check_plain(t('The user default tab wont be used for
656
        the next taxon site, check the box if you want to use the user default configuration.')));
657
    }
658
    // Problem with the user id => variables wont be saved.
659
  }
660
  else {
661
    $msg_type = 'warning';
662
    drupal_set_message(check_plain(t('Default tab has not been saved due to user id problems')), $msg_type);
663
  }
664
}
665
666
/**
667
 * Implements hook_block_info().
668
 */
669
function cdm_dataportal_block_info() {
670
671
    // $block[0]["info"] = t("CDM DataPortal DevLinks");
672
    // $block[1]["info"] = t("CDM DataPortal Credits");
673
    $block["2"]["info"] = t("CDM Search Taxa");
674
    // $block[3]["info"] = t("CDM Filters");
675
    $block["4"]["info"] = t("CDM Dataportal Print");
676
    $block["keys"]["info"] = t("CDM identification keys");
677
    $block["uses"]["info"] = t("CDM Uses");
678
    $block["fundedByEDIT"]["info"] = t('Funded by EDIT');
679
680
    return $block;
681
}
682
683
/**
684
 * Implements hook_block_view().
685
 */
686
function cdm_dataportal_block_view($delta) {
687
  // TODO Rename block deltas (e.g. '2') to readable strings.
688
  switch ($delta) {
689
    // case 'delta-1':
690
    // $block['subject'] = t('Credits');
691
    // $block['content'] = theme('cdm_credits');
692
    // return $block;
693 191f88fd Andreas Kohlbecker
    case '2':
694
      $block['subject'] = t('Search taxa');
695 6657531f Andreas Kohlbecker
      $form = drupal_get_form('cdm_dataportal_search_taxon_form');
696
      $block['content'] = drupal_render($form);
697
698
      if (variable_get('cdm_dataportal_show_advanced_search', 1)) {
699
        $block['content'] .= '<div>' . l(t('Advanced Search'), 'cdm_dataportal/search') . '</div>';
700
      }
701
      return $block;
702
    case '4':
703
      $block['subject'] = t('<none>');
704
      $block['content'] = theme('cdm_print_button');
705
      return $block;
706
    case "keys":
707
      $block['subject'] = t('Identification Keys');
708
      $block['content'] = theme('cdm_block_IdentificationKeys', array('taxonUuid' => NULL));
709
      return $block;
710
      // Creating a block specific for the Use Interface.
711
    case "uses":
712
      $block['subject'] = t('Uses');
713
      $block['content'] = theme('cdm_block_uses', array('taxonUuid' => NULL));
714
      return $block;
715
    case "fundedByEDIT":
716
      // t('Funded by EDIT');
717
      $text = '<none>';
718
      $block['subject'] = $text;
719
      $img_tag = '<img src="' . drupal_get_path('module', 'cdm_dataportal') . '/images/funded_by_EDIT.png' . '" alt="' . $text . '"/>';
720
      $block['content'] = l($img_tag, "http://www.e-taxonomy.eu/", array(
721
        'attributes' => array("target" => "EDIT"),
722
        'absolute' => TRUE,
723
        'html' => TRUE,
724
      ));
725
      return $block;
726
  }
727
}
728
729
/*
730
 function cdm_dataportal_session_clear($cdm_ws_uri_update = FALSE){
731
 $_SESSION['cdm'] = NULL;
732
 if(is_string($cdm_ws_uri_update)){
733
 $_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
734
 }
735
 }
736
737
 function cdm_dataportal_session_validate(){
738
 if(!isset($_SESSION['cdm']['ws_uri'])){
739
 $_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', FALSE));
740
 } else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', FALSE)){
741
 cdm_dataportal_session_clear(variable_get('cdm_webservice_url', FALSE));
742
 }
743
 }
744
 */
745
746
/**
747
 * @todo Please document this function.
748
 * @see http://drupal.org/node/1354
749
 */
750
function cdm_taxonomictree_selector() {
751 a8a8f23c Andreas Kohlbecker
  _add_js_treeselector();
752
753 6657531f Andreas Kohlbecker
  $form = drupal_get_form('cdm_taxonomictree_selector_form');
754
  $out = drupal_render($form);
755
  return $out;
756
}
757
758
/**
759
 * @todo Please document this function.
760
 * @see http://drupal.org/node/1354
761
 */
762
function cdm_taxonomictree_selector_form($form, &$form_state) {
763
764
  $url = url('cdm_api/setvalue/session', array('query' => NULL));
765
  $form['#action'] = $url;
766
767
  $form['var'] = array(
768
    '#weight' => -3,
769
    '#type' => 'hidden',
770
    '#value' => '[cdm][taxonomictree_uuid]',
771
  );
772
773
  $destination_array = drupal_get_destination();
774
  $destination = $destination_array['destination'];
775
776
  $form['destination'] = array(
777
    '#weight' => -3,
778
    '#type' => 'hidden',
779
    '#value' =>  $destination,
780
  );
781
782
  $form['val'] = array(
783
    '#type' => 'select',
784
    '#title' => t('Available classifications'),
785
    '#default_value' => get_taxonomictree_uuid_selected(),
786
    '#options' => cdm_get_taxontrees_as_options(),
787
  );
788
789
  return $form;
790
791
}
792
793
/**
794
 * Implements hook_theme().
795
 *
796
 * Registering themes with a theme hook is needed since Drupal 6.
797
 *
798
 * @author W. Addink <w.addink@eti.uva.nl>
799
 */
800
function cdm_dataportal_theme() {
801
  return array(
802
    // Themes in help.php.
803
    'cdm_dataportal_admin_config_cdm_dataportal_general' => array('variables' => array()),
804
    'cdm_dataportal_admin_config_cdm_dataportal_geo' => array('variables' => array()),
805
    'cdm_dataportal_admin_config_cdm_dataportal_layout' => array('variables' => array()),
806
    'cdm_dataportal_admin_config_cdm_dataportal_cachesite' => array('variables' => array()),
807
    'cdm_dataportal_admin_config_more_help_link' => array('variables' => array()),
808
809
    // Themes in settings.php.
810
    'checkboxes_preferred' => array('render element' => 'element'),
811
812
    // Themes in cdm_dataportal.common.theme.
813
    'cdm_taggedtext2html' => array('variables' => array(
814
      'taggedtxt' => array(),
815
      'tag' => 'span',
816
      'glue' => ' ',
817
      'skiptags' => array(),
818
      )),
819
    'cdm_annotations_as_footnotekeys' => array('variables' => array('cdmBase_list' => NULL, 'footnote_list_key' => NULL)),
820
    'cdm_annotation_footnotes' => array('variables' => array('footnoteListKey' => NULL, 'enclosingTag' => 'span')),
821
    'cdm_annotation_content' => array('variables' => array('AnnotationTO' => NULL)),
822
    'cdm_list_of_annotations' => array('variables' => array('annotationElements' => NULL)),
823
    'cdm_footnote_key' => array('variables' => array(
824
      'footnoteKey' => NULL,
825
      'separator' => '',
826
      'highlightable' => TRUE,
827
      'separator_off' => FALSE,
828
      )),
829
    'cdm_footnote' => array('variables' => array('footnoteKey' => NULL, 'footnoteText' => NULL)),
830
    'cdm_footnotes' => array('variables' => array(
831
      'footnoteListKey' => NULL,
832
      'enclosingTag' => 'span',
833
      )),
834
    'cdm_annotations' => array('variables' => array('annotations' => NULL, 'enclosingTag' => 'span')),
835
    'cdm_pager' => array('variables' => array('pager' => NULL, 'path' => NULL, 'parameters' => NULL)),
836
    'cdm_pager_link' => array('variables' => array(
837
      'text' => NULL,
838
      'linkIndex' => NULL,
839
      'pager' => NULL,
840
      'path' => NULL,
841
      'parameters' => array(),
842
      'attributes' => NULL,
843
      )),
844
    'cdm_back_to_search_result_button' => array('variables' => array()),
845
    'cdm_back_to_image_gallery_button' => array('variables' => array()),
846
    'cdm_print_button' => array('variables' => array()),
847
848
    // Themes in cdm_dataportal.descriptions.theme.
849
    'cdm_feature_nodesTOC' => array('variables' => array('featureNodes' => NULL)),
850
    'cdm_feature_name' => array('variables' => array('feature_name' => NULL)),
851
    'cdm_featureTrees' => array('variables' => array('mergedTrees' => NULL, 'taxon' => NULL)),
852
    'cdm_featureTreeTOCs' => array('variables' => array('mergedTrees' => NULL)),
853
    'cdm_feature_nodes' => array('variables' => array('mergedFeatureNodes' => NULL, 'taxon' => NULL)),
854
    'FeatureTree_hierarchy' => array('variables' => array('FeatureTreeUuid' => NULL)),
855
    'FeatureTree_hierarchy_children' => array('variables' => array('node' => NULL)),
856
    'cdm_descriptionElementArray' => array('variables' => array(
857
      'elementArray' => array(),
858
      'feature' => NULL,
859
      'glue' => '',
860
      'sortArray' => FALSE,
861
      'enclosingHtml' => 'ul',
862
      )),
863
    'cdm_descriptionElement_CommonTaxonName' => array('render element' => 'element'),
864
    'cdm_descriptionElement_CategoricalData' => array('render element' => 'element'),
865
    'cdm_descriptionElementTextData' => array('variables' => array(
866
      'element' => NULL,
867
      'asListElement' => NULL,
868
      'feature_uuid' => NULL,
869
      )),
870
    'cdm_common_names' => array('render element' => 'elements'),
871
    'cdm_descriptionElements' => array('variables' => array(
872
      'descriptionElements' => NULL,
873
      'featureUuid' => NULL,
874
      'taxon_uuid' => NULL,
875
      )),
876
    'cdm_description_element_image_source' => array('variables' => array(
877
      'image_sources' => NULL,
878
      'asListElement' => NULL,
879
      )),
880
    'cdm_descriptionElementDistribution' => array('variables' => array(
881
      'descriptionElements' => NULL,
882
      'enclosingTag' => 'span',
883
      )),
884
    'cdm_description_ordered_distributions' => array('variables' => array(
885
      'taxon_uuid' => NULL,
886
      'descriptionElements' => NULL,
887
      )),
888
    'cdm_DescriptionElementSource' => array('variables' => array('descriptionElementSource' => NULL, 'doLink' => TRUE)),
889
    'cdm_IdentifieableSource' => array('variables' => array('source' => NULL, 'doLink' => TRUE)),
890
    'cdm_distribution_map' => array('variables' => array('taxon' => NULL)),
891
    'cdm_IdentificationKey' => array('variables' => array(
892
      'identificationKey' => NULL,
893
      'doLinkToKeyPage' => TRUE,
894
      'showIdentificationKeyTitle' => TRUE,
895
      )),
896
    'cdm_polytomousKey' => array('variables' => array('polytomousKey' => NULL)),
897
    'cdm_polytomousKey_linkedStyle_subgraph' => array('variables' => array('polytomousKeyNode' => NULL)),
898
    'cdm_poytomousKeyNode_modifyingText' => array('variables' => array('modifyingText' => NULL)),
899
    'cdm_list_IdentificationKeys' => array('variables' => array('type' => NULL, 'taxonUuid' => NULL)),
900
    'cdm_block_IdentificationKeys' => array('variables' => array('taxonUuid' => NULL)),
901
    'cdm_UseDescription' => array('variables' => array('description' => NULL, 'taxonUuid' => NULL)),
902
    'cdm_block_Uses' => array('variables' => array('taxonUuid' => NULL)),
903
904
    // Themes in cdm_dataportal.media.theme.
905
    'cdm_media' => array('variables' => array('descriptionElement' => NULL, 'mimeTypePreference' => NULL)),
906
    'cdm_mediaTypeTerm' => array('variables' => array('feature' => NULL, 'mediaUrl' => FALSE)),
907
    'cdm_media_mime_application' => array('variables' => array('mediaRepresentation' => NULL, 'feature' => NULL)),
908
    'cdm_media_mime_image' => array('variables' => array('mediaRepresentation' => NULL, 'feature' => NULL)),
909
    'cdm_media_mime_text' => array('variables' => array('representation' => NULL, 'feature' => NULL)),
910
    'cdm_media_caption' => array('variables' => array(
911
      'media' => NULL,
912
      'elements' => array('title', 'description', 'artist', 'location', 'rights'),
913
      )),
914
    'cdm_media_gallerie' => array('variables' => array(
915
      'mediaList' => NULL,
916
      'galleryName' => NULL,
917
      'maxExtend' => 150,
918
      'cols' => 4,
919
      'maxRows' => FALSE,
920
      'captionElements' => array('title'),
921
      'mediaLinkType' => 'LIGHTBOX',
922
      'alternativeMediaUri' => NULL,
923
      'galleryLinkUri' => NULL,
924
      'showCaption' => TRUE,
925
      )),
926
    'cdm_media_gallerie_image' => array('variables' => array(
927
      'mediaRepresentationPart' => NULL,
928
      'maxExtend' => NULL,
929
      'addPassePartout' => FALSE,
930
      'attributes' => NULL,
931
      )),
932
    'cdm_media_gallerie_application' => array('variables' => array(
933
      'mediaRepresentationPart' => NULL,
934
      'maxExtend' => NULL,
935
      'addPassePartout' => FALSE,
936
      'attributes' => NULL,
937
      )),
938
    'cdm_media_gallerie_text' => array('variables' => array(
939
      'mediaRepresentationPart' => NULL,
940
      'maxExtend' => NULL,
941
      'addPassePartout' => FALSE,
942
      'attributes' => NULL,
943
      )),
944
    'cdm_openlayers_image' => array('variables' => array('mediaRepresentationPart' => NULL, 'maxExtend' => NULL)),
945
    'cdm_preferredImage' => array('variables' => array(
946
      'media' => NULL,
947
      'defaultRepresentationPart' => NULL,
948
      'imageMaxExtend' => NULL,
949
      'parameters' => '',
950
      )),
951
952
    // Themes in cdm_dataportal.name.theme.
953
    'cdm_taxonName' => array('variables' => array(
954
      'taxonName' => NULL,
955
      'nameLink' => NULL,
956
      'refenceLink' => NULL,
957
      'show_annotations' => TRUE,
958
      'is_type_designation' => FALSE,
959
      'skiptags' => array(),
960
      )),
961
    'cdm_typedesignations' => array('variables' => array('typeDesignations' => array())),
962
    'cdm_nameRelationships' => array('variables' => array('nameRelationships' => NULL, 'skipTypes' => FALSE)),
963
    'cdm_homotypicSynonymLine' => array('variables' => array('taxon' => NULL)),
964
    'cdm_heterotypicSynonymyGroup' => array('variables' => array('homotypicalGroup' => NULL)),
965
    'cdm_homotypicSynonymyGroup' => array('variables' => array(
966
      'synonymList' => NULL,
967
      'accepted_taxon_uuid' => NULL,
968
      'prependedSynonyms' => array(),
969
      )),
970
    'get_nameRenderTemplate' => array('variables' => array('renderPath' => NULL)),
971
    'get_partDefinition' => array('variables' => array('nameType' => NULL)),
972
    'get_nameRenderTemplate' => array('variables' => array('renderPath' => NULL)),
973
974
    // Themes in cdm_dataportal.occurrence.theme.
975
    'cdm_specimen' => array('variables' => array('specimenTypeDesignation' => NULL)),
976
    'cdm_derivedUnitFacade' => array('variables' => array('derivedUnitFacade' => NULL)),
977
978
    // Themes in cdm_dataportal.page.theme.
979
    'cdm_taxon_page_title' => array('variables' => array('taxon' => NULL, 'uuid' => NULL)),
980
    'cdm_name_page_title' => array('variables' => array('taxon_name' => NULL)),
981
    'cdm_taxon_page' => array('variables' => array('taxon' => NULL, 'page_part' => 'description')),
982
    'cdm_taxon_page_profile' => array('variables' => array(
983
      'taxon' => NULL,
984
      'mergedTrees' => NULL,
985
      'media' => NULL,
986
      'hideImages' => FALSE,
987
      )),
988
    'cdm_taxon_page_specimens' => array('variables' => array('taxon' => NULL)),
989
    'cdm_taxon_page_synonymy' => array('variables' => array('taxon' => NULL, 'addAcceptedTaxon' => NULL)),
990
    'cdm_reference_page' => array('variables' => array('reference' => NULL)),
991
    'cdm_media_page' => array('variables' => array(
992
      'media' => NULL,
993
      'mediarepresentation_uuid' => FALSE,
994
      'partId' => FALSE,
995
      )),
996
    'cdm_polytomousKey_page' => array('variables' => array('polytomousKey' => NULL)),
997
    'cdm_taxonpage_tab' => array('variables' => array('tabname' => NULL)),
998
999
    // Themes in cdm_dataportal.references.theme.
1000
    'cdm_reference_pager' => array('variables' => array(
1001
      'referencePager' => NULL,
1002
      'path' => NULL,
1003
      'parameters' => array(),
1004
      )),
1005
    'cdm_reference' => array('variables' => array(
1006
      'reference' => NULL,
1007
      'microReference' => NULL,
1008
      'doLink' => FALSE,
1009
      'referenceStyle' => NULL,
1010
      )),
1011
1012
    // Themes in cdm_dataportal.taxon.theme.
1013
    'cdm_search_results' => array('variables' => array(
1014
      'pager' => NULL,
1015
      'path' => NULL,
1016
      'query_parameters' => NULL,
1017
      )),
1018
    'cdm_taxonRelationships' => array('variables' => array('taxonRelationships' => NULL, 'focusedTaxon' => NULL)),
1019
    'cdm_acceptedFor' => array('variables' => array()),
1020
    'cdm_list_of_taxa' => array('variables' => array('records' => NULL, 'freetextSearchResults' => array())),
1021
    'cdm_taxon_list_thumbnails' => array('variables' => array('taxon' => NULL)),
1022
1023
    // Themes in cdm_dataportal.bibliography.theme.
1024
    'cdm_descriptionElementBibliography' => array('variables' => array('descriptionElementsBibliography' => array())),
1025
  );
1026
}
1027
1028
/* UNREACHABLE since action of form directly links to view.
1029
 function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
1030
1031
 $_SESSION['cdm']['search'] = $form_values;
1032
 //return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
1033
 return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
1034
 //$paramstr = compose_url_prameterstr($form_values);
1035
 //return url('/cdm_dataportal/search/taxon/', array('query' => $paramstr));
1036
 }
1037
 */
1038
/* ====================== menu callback functions ====================== */
1039
/**
1040
 * @todo Please document this function.
1041
 * @see http://drupal.org/node/1354
1042
 */
1043
/*
1044
function cdm_dataportal_form_alter(&$form, &$form_state, $form_id) {
1045
  static $comment_node_disabled =  0;
1046
  static $comment_node_read_only =  1;
1047
  static $comment_node_read_write =  2;
1048
1049
  if ($form_id == 'node_type_form'
1050
   && isset($form['identity']['type'])
1051
   && array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
1052
  ) {
1053
    $form['workflow']['comment'] = array(
1054
      '#type' => 'radios',
1055
      '#title' => t('Default comment setting'),
1056
      '#default_value' => variable_get('comment__' . $node->type . $form['#node_type']->type, $comment_node_disabled),
1057
      '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
1058
      '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
1059
    );
1060
  }
1061
}
1062
*/
1063
1064
/**
1065
 * Displays a list of the known taxonomic names.
1066
 *
1067
 * When the list of taxonomic names is displayed, long lists are split up into
1068
 * multiple pages.
1069
 *
1070
 * TODO: Parameters are still preliminary.
1071
 *
1072
 * @param string $beginsWith
1073
 * @param string $page
1074
 *   Page number to diplay defaults to page 1.
1075
 * @param bool $onlyAccepted
1076
 */
1077
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = FALSE) {
1078
1079
  $out = t('<h3>Sorry, the name list feature is not yet available in this version of the DataPortal software<h3>');
1080
1081
  /*
1082
  // FIXME the filter for accepted names will be a form element, thus this
1083
  // widget should be generated via form api preferably as block.
1084
  $out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
1085
  $out .= theme('cdm_dataportal_widget_names_list', $names, $page);
1086
  $out .= theme('cdm_listof_taxa', $taxonPager);
1087
  return $out;
1088
  */
1089
}
1090
1091
/**
1092
 * @todo Please document this function.
1093
 * @see http://drupal.org/node/1354
1094
 */
1095
function cdm_dataportal_view_reference($uuid, $arg2 = NULL) {
1096
  $reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
1097
  return theme('cdm_reference_page', array('reference' => $reference));
1098
}
1099
1100
/**
1101
 * @todo Please document this function.
1102
 * @see http://drupal.org/node/1354
1103
 */
1104
function cdm_dataportal_view_reference_list($pageNumber) {
1105
  $referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
1106
  return theme('cdm_reference_pager', array(
1107
    'referencePager' => $referencePager,
1108
    'path' => 'cdm_dataportal/reference/list/',
1109
    ));
1110
}
1111
1112
/**
1113
 * @todo Please document this function.
1114
 * @see http://drupal.org/node/1354
1115
 */
1116
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = FALSE, $part = 0) {
1117
  $media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
1118
  return theme('cdm_media_page', array(
1119
    'media' => $media,
1120
    'mediarepresentation_uuid' => $mediarepresentation_uuid,
1121
    'partId' => $part,
1122
    ));
1123
}
1124
1125
/**
1126
 * @todo Please document this function.
1127
 * @see http://drupal.org/node/1354
1128
 */
1129
function _load_taxonBase(&$taxonBase) {
1130
  if (isset($taxonBase->uuid)) {
1131
    $taxonBase->name = cdm_ws_get(CDM_WS_TAXON, array($taxonBase->uuid, "name"));
1132
    $taxonBase->name->taggedName = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "taggedName"));
1133
    $taxonBase->name->nomenclaturalReference = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "nomenclaturalReference"));
1134
  }
1135
}
1136
1137
/**
1138
 * Gets a Drupal variable, string or array and returns it.
1139
 *
1140
 * Similar to the variable_get() function of Drupal, except that this function
1141
 * is able to handle arrays correctly. This function is especially useful
1142
 * when dealing with collections of setting form elements (#tree = TRUE).
1143
 *
1144
 * @param string $variableKey
1145
 *   The Unique key of the Drupal variable in the Drupal variables table.
1146
 * @param string $defaultValueString
1147
 *   A string as for example derived from a CONSTANT.
1148
 *
1149
 * @return mixed
1150
 *   Returns usally an array, depending on the nature of the variable.
1151
 */
1152
function mixed_variable_get($variableKey, $defaultValueString) {
1153
  $systemDefaults = unserialize($defaultValueString);
1154
  $storedSettings = variable_get($variableKey, array());
1155
  if (is_array($storedSettings)) {
1156
    $settings = array_merge($systemDefaults, $storedSettings);
1157
  }
1158
  else {
1159
    $settings = $systemDefaults;
1160
  }
1161
  return $settings;
1162
}
1163
1164
/**
1165
 * Loads the subgraph of a given PolytomousKeyNode.
1166
 *
1167
 * Loads the subgraph of the given PolytomousKeyNode recursively from
1168
 * the CDM REST service.
1169
 *
1170
 * @param mixed $polytomousKeyNode
1171
 *   PolytomousKeyNode passed by reference.
1172
 *
1173
 * @return void
1174
 */
1175
function _load_polytomousKeySubGraph(&$polytomousKeyNode) {
1176
1177
  if (!$polytomousKeyNode) {
1178
    return;
1179
  }
1180
  if ($polytomousKeyNode->class != "PolytomousKeyNode") {
1181
    drupal_set_message(_load_polytomousKeySubGraph() . t('invalid type given.'), 'error');
1182
    return;
1183
  }
1184
  if (!is_uuid($polytomousKeyNode->uuid)) {
1185
    drupal_set_message(_load_polytomousKeySubGraph() . t('invalid type given.'), 'error');
1186
    return;
1187
  }
1188
1189
  $polytomousKeyNode = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid);
1190
1191
  if (!$polytomousKeyNode) {
1192
    // drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error");
1193
    return;
1194
  }
1195
1196
  // Load children.
1197
  foreach ($polytomousKeyNode->children as &$childNode) {
1198
    _load_polytomousKeySubGraph($childNode);
1199
  }
1200
1201
  // Load subkey.
1202
  $polytomousKeyNode->subkey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "subkey"));
1203
1204
  // Load taxon.
1205
  $polytomousKeyNode->taxon = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "taxon"));
1206
  _load_taxonBase($polytomousKeyNode->taxon);
1207
  return;
1208
}
1209
1210
/**
1211
 * @todo Please document this function.
1212
 * @see http://drupal.org/node/1354
1213
 */
1214
function cdm_dataportal_view_polytomousKey($polytomousKeyUuid) {
1215
  $polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid);
1216
1217
  $sourcePager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources'));
1218
  if (is_array($sourcePager->records)) {
1219
    $polytomousKey->sources = $sourcePager->records;
1220
    // $polytomousKey->sources->citation = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources'));
1221
  }
1222
1223
  $annotationPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'annotations'));
1224
  if (is_array($annotationPager->records)) {
1225
    $polytomousKey->annotations = $annotationPager->records;
1226
  }
1227
1228
  _load_polytomousKeySubGraph($polytomousKey->root);
1229
  return theme('cdm_polytomousKey_page', array('polytomousKey' => $polytomousKey));
1230
}
1231
1232
/**
1233
 * Creates a taxon page view or a chapter of it.
1234
 *
1235
 * The taxon page gives detailed information on a taxon, it shows:
1236
 *  - Taxon name.
1237
 *  - Full list of synonyms homotypic synonyms on top, followed by the
1238
 *    heterotypic and finally followed by misapplied names.
1239
 *    The list is ordered historically.
1240
 *  - All description associated with the taxon.
1241
 *
1242
 * @param string $uuid
1243
 * @param string $chapter
1244
 *   Name of the part to display, valid values are:
1245
 *   'description', 'images', 'synonymy', 'specimens', 'all'.
1246
 *
1247
 * @return unknown_type
1248
 */
1249
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all', $synonym_uuid = NULL) {
1250
  // Display the page for the taxon defined by $uuid.
1251
  // set_last_taxon_page_tab(arg(3));
1252
  $taxonpage = cdm_dataportal_taxon_view($uuid, $chapter, $synonym_uuid);
1253
  if (!empty($taxonpage)) {
1254
    return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title, $taxonpage->content);
1255
  }
1256
  else {
1257
    return '';
1258
  }
1259
}
1260
1261
/**
1262
 * @todo improve documentation for this function.
1263
 *
1264
 * @param string $uuid
1265
 * @param string $chapter
1266
 *   Name of the part to display, valid values are:
1267
 *   'description', 'images', 'synonymy', 'all'.
1268
 *
1269
 * @return unknown_type
1270
 */
1271
function cdm_dataportal_taxon_view($uuid, $chapter = 'all', $synonym_uuid = NULL) {
1272
  // Taxon object.
1273
  $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1274
  if (empty($taxon)) {
1275
    drupal_set_title(t('Taxon does not exist'), PASS_THROUGH);
1276
    return FALSE;
1277
  }
1278
  $taxonpage = new stdClass();
1279
1280
  $taxonpage->title = theme('cdm_taxon_page_title', array(
1281
    'taxon' => $taxon,
1282
    'uuid' => $uuid,
1283
    'synonym_uuid' => $synonym_uuid,
1284
  ));
1285
1286
  // Check if the taxon id contained in the currently selected tree.
1287
  $taxon_in_current_tree = taxon_in_current_tree($uuid);
1288
  $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $uuid);
1289
  if (!$taxon_in_current_tree) {
1290
    if (count($taxon_nodes) == 0) {
1291
      drupal_set_message(check_plain(t('This concept of the taxon !taxonname is not contained any classification.', array(
1292
        '!taxonname' => theme('cdm_taxonName', array('taxonName' => $taxon->name)),
1293
      ))), 'warning');
1294
    }
1295
    else {
1296
      $trees = '';
1297
      foreach ($taxon_nodes as $node) {
1298
        if (isset($node->classification->titleCache)) {
1299
          $trees .= ($trees ? ', ' : '') . '<strong>' . $node->classification->titleCache . '</strong>';
1300
        }
1301
      }
1302
1303
      drupal_set_message(format_plural(count($taxon_nodes),
1304
          'This concept of the taxon !taxonname is not contained in the currently chosen classification, but in this one: !trees',
1305
          'This concept of the taxon !taxonname is not contained in the currently chosen classification, but in one of these: !trees',
1306
          array('!taxonname' => theme('cdm_taxonName', array('taxonName' => $taxon->name)), '!trees' => $trees)) , 'warning');
1307
    }
1308
  }
1309
1310
  // Render the taxon page.
1311
  $taxonpage->content = theme('cdm_taxon_page', array(
1312
    'taxon' => $taxon,
1313
    'page_part' => $chapter,
1314
  ));
1315
1316
  return $taxonpage;
1317
}
1318
1319
/**
1320
 * Returns a name page as a Drupal node ready to be renderized by Drupal.
1321
 *
1322
 * The node page shows the taxon name title and the list of taxon related
1323
 * with such taxon. Name on the tree already in use.
1324
 *
1325
 * @param string $taxon_name_uuid
1326
 *   A taxon name UUID.
1327
 *
1328
 * @return mixed
1329
 *   The formatted name page as node.
1330
 */
1331
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = NULL) {
1332
1333
  $taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid);
1334
  if (!empty($taxonname_page)) {
1335
    return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title, $taxonname_page->content);
1336
  }
1337
  else {
1338
    return '';
1339
  }
1340
}
1341
1342
/**
1343
 * Generates an object ready to be transformated to a node.
1344
 *
1345
 * This is a preparation in order to show it as a Drupal node.
1346
 *
1347
 * @param string $taxon_name_uuid
1348
 *
1349
 * @return mixed
1350
 *   The object with the page content and title.
1351
 */
1352
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = NULL) {
1353
  // Getting the full taxonname object from the server.
1354
  $taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
1355
  if (!$taxon_name) {
1356
    drupal_set_title(t('Taxon name does not exist'), PASS_THROUGH);
1357
    return FALSE;
1358
  }
1359
  // Searching for all the taxa connected with the taxon name on the tree
1360
  // in use.
1361
  $name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1362
  $request_params = array();
1363
  $request_params['query'] = $name_cache;
1364
  $request_params['tree'] = get_taxonomictree_uuid_selected();
1365
  $request_params['doTaxa'] = 1;
1366
  $request_params['doSynonyms'] = 1;
1367
  $request_params['doTaxaByCommonNames'] = 0;
1368
  $request_params['matchMode'] = "EXACT";
1369
  $taxon_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, NULL, queryString($request_params));
1370
1371
  // Removing the name where we come from.
1372
  foreach ($taxon_pager->records as $k => &$taxon) {
1373
    if ($taxon->uuid == $taxon_to_hide_uuid) {
1374
      unset($taxon_pager->records[$k]);
1375
    }
1376
  }
1377
  // Show the taxa list or go to the singular taxon.
1378
  if (sizeof($taxon_pager->records) == 1) {// Single taxon case.
1379
    reset($taxon_pager->records);
1380
    $singleTaxon = $taxon_pager->records[0];
1381
    if ($singleTaxon->class != "Taxon") {
1382
      // It is a Synonym -> look for the accepted.
1383
      $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($singleTaxon->uuid, get_taxonomictree_uuid_selected()));
1384
      if (!empty($synonym_uuid)) {
1385
        drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', array('query' => array('highlite' => $synonym_uuid)));
1386
      }
1387
      else {
1388
        drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', array('query' => array('highlite' => $singleTaxon->uuid)));
1389
      }
1390
    }
1391
    else {
1392
      // It is an accepted taxon.
1393
      if (!empty($synonym_uuid)) {
1394
        drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid . '/synonymy', array('query' => array('highlite' => $synonym_uuid)));
1395
      }
1396
      else {
1397
        drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid);
1398
      }
1399
    }
1400
  }
1401
  else {// More than one taxa case.
1402
    $taxon_name_page = new stdClass();
1403
    $taxon_name_page->title = theme('cdm_name_page_title', array('taxon_name' => $taxon_name . ''));
1404
    if ($taxon_pager->records) {
1405
      $taxon_name_page->content = theme_cdm_list_of_taxa($taxon_pager->records, FALSE);
1406
    }
1407
    else {
1408
      $taxon_name_page->content = 'This name has no taxa';
1409
    }
1410
    return $taxon_name_page;
1411
  }
1412
}
1413
1414
/**
1415
 * @todo Please document this function.
1416
 * @see http://drupal.org/node/1354
1417
 */
1418
function cdm_dataportal_view_search_advanced() {
1419
1420
  drupal_set_title(t('Advanced search'), PASS_THROUGH);
1421
  $form = array();
1422
  $form_state = array();
1423
  $searchForm = cdm_dataportal_search_taxon_form($form, $form_state, TRUE);
1424
1425
  return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
1426
1427
}
1428
1429
/**
1430
 * @todo Please document this function.
1431
 * @see http://drupal.org/node/1354
1432
 */
1433
function cdm_dataportal_view_search_taxon_by_description() {
1434
  drupal_set_title(t('Search by description full text'), PASS_THROUGH);
1435
  // $form_state = false;
1436
  // $searchForm = cdm_dataportal_search_taxon_by_description_form($form_state);
1437
  $searchForm = cdm_dataportal_search_taxon_by_description_form();
1438
1439
  return drupal_get_form('cdm_dataportal_search_taxon_by_description_form');
1440
}
1441
1442
/**
1443
 * Executes the search and generates the result list of taxa.
1444
 */
1445
function cdm_dataportal_view_search_results_taxon() {
1446
1447 78e178e2 Andreas Kohlbecker
  $taxonPager = cdm_dataportal_search_execute();
1448
1449
  $showThumbnails = do_showThumbnails();
1450
1451
  $setSessionUri = url('cdm_api/setvalue/session', array(
1452
      'query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => ''),
1453
  ));
1454
1455
  drupal_add_js('jQuery(document).ready(function() {
1456
1457
      // init
1458
      if(' . $showThumbnails . ' == 1){
1459
      jQuery(\'.media_gallery\').show(20);
1460
  } else {
1461
      jQuery(\'.media_gallery\').hide(20);
1462
  }
1463
      // add change hander
1464
      jQuery(\'#showThumbnails\').change(
1465
      function(event){
1466
      var state = 0;
1467
      if(jQuery(this).is(\':checked\')){
1468
      jQuery(\'.media_gallery\').show(20);
1469
      state = 1;
1470
  } else {
1471
      jQuery(\'.media_gallery\').hide(20);
1472
  }
1473
      // store state in session variable
1474
      var uri = \'' . $setSessionUri . '\' + state;
1475
      jQuery.get(uri);
1476
  });
1477
  });',
1478
  array('type' => "inline", 'scope' => JS_DEFAULT));
1479
1480 6657531f Andreas Kohlbecker
  drupal_set_title(t('Search results'), PASS_THROUGH);
1481
1482
  return theme('cdm_search_results', array(
1483
    'pager' => $taxonPager,
1484
    'path' => 'cdm_dataportal/search/results/taxon',
1485
    'query_parameters' => $_REQUEST,
1486
    ));
1487 78e178e2 Andreas Kohlbecker
}
1488
1489
/**
1490
 * Returns the state of the the showThumbnails flag set in the
1491
 * users session ($_SESSION['pageoption']['searchtaxa']['showThumbnails']).
1492
 *
1493
 * @return Ambigous <boolean, number>
1494
 *    returns 1 if the flag is set
1495
 */
1496
function do_showThumbnails() {
1497
  static $showThumbnails = null;
1498
1499
  if($showThumbnails == null) {
1500
    $showThumbnails = FALSE;
1501
    if (isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
1502
      $showThumbnails = $_SESSION['pageoption']['searchtaxa']['showThumbnails'];
1503
    }
1504
    if (!is_numeric($showThumbnails)) {
1505
      $showThumbnails = 1;
1506
    }
1507
  }
1508
1509
  return $showThumbnails;
1510 6657531f Andreas Kohlbecker
}
1511
1512
/**
1513
 * View which transforms XML output from a given webservice endpoint into JSON.
1514
 */
1515
/*
1516
 function cdm_view_xml2json(){
1517
 $file = arg(2);
1518
 $datastr = file_get_contents(variable_get('cdm_webservice_url', '').$file);
1519
 return  xml2json::transformXmlStringToJson($datastr);
1520
 }
1521
 */
1522
1523
/* ====================== other functions ====================== */
1524
/**
1525
 * Creates a URL to the taxon page specified by the $uuid parameter.
1526
 *
1527
 * The URL will be prepended with a path element to a specific taxon page tab.
1528
 *
1529
 * This tab is either taken from the CDM_DATAPORTAL_DEFAULT_TAXON_TAB which can
1530
 * be set globally in the administrative settings or individually in the user
1531
 * profile. If the CDM_DATAPORTAL_DEFAULT_TAXON_TAB value is set to LAST_VISITED_TAB
1532
 * the last portal will stay on this last tab.
1533
 *
1534
 * A third option is offerered by the $page_tab parameter which allows overwriting this
1535
 * internal mechanism by a specific value.
1536
 *
1537
 * @param string $uuid
1538
 *   The UUID of the taxon.
1539
 * @param string $page_tab
1540
 *   Overwriting the preset mechanism by defining specific value for the
1541
 *   taxon page tab.
1542
 *
1543
 * @return string
1544
 *   The created URL.
1545
 */
1546
function path_to_taxon($uuid, $page_tab = FALSE) {
1547
1548
  $tab = get_default_taxon_tab();
1549
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
1550
1551
  if (!$uuid) {
1552
    return FALSE;
1553
  }
1554
1555
  if ($page_tab) {
1556
    return 'cdm_dataportal/taxon/' . $uuid . '/' . $page_tab;
1557
  }
1558
  elseif (!$tab || strtolower($tab) == 'general') {
1559
    return 'cdm_dataportal/taxon/' . $uuid;
1560
  }
1561
  elseif (get_last_taxon_page_tab() &&   $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]) {
1562
    return 'cdm_dataportal/taxon/' . $uuid . '/' . get_last_taxon_page_tab();
1563
  }
1564
  else {
1565
    return 'cdm_dataportal/taxon/' . $uuid . '/' . strtolower($tab);
1566
  }
1567
}
1568
1569
/**
1570
 * @todo Please document this function.
1571
 * @see http://drupal.org/node/1354
1572
 */
1573
function uri_to_synonym($synonymUuid, $acceptedUuid) {
1574
  $acceptedPath = path_to_taxon($acceptedUuid, "synonymy");
1575
  return url($acceptedPath, array('query' => array('highlite' => $synonymUuid)));
1576
}
1577
1578
/**
1579
 * @todo Please document this function.
1580
 * @see http://drupal.org/node/1354
1581
 */
1582
function path_to_key($keyType, $keyUuid) {
1583
  if (!$keyUuid || !$keyType) {
1584
    return FALSE;
1585
  }
1586
  $keyType{0} = strtolower($keyType{0});
1587
  return "cdm_dataportal/" . $keyType . "/$keyUuid";
1588
}
1589
1590
/**
1591
 * @todo Please document this function.
1592
 * @see http://drupal.org/node/1354
1593
 */
1594
function path_to_reference($uuid) {
1595
  if (!$uuid) {
1596
    return FALSE;
1597
  }
1598
  return 'cdm_dataportal/reference/' . $uuid;
1599
}
1600
1601
/**
1602
 * @todo Please document this function.
1603
 * @see http://drupal.org/node/1354
1604
 */
1605
function path_to_name($name_uuid) {
1606
  $res = FALSE;
1607
  if ($name_uuid) {
1608
    $res = 'cdm_dataportal/name/' . $name_uuid;
1609
  }
1610
  return $res;
1611
}
1612
1613
/**
1614
 * @todo Please document this function.
1615
 * @see http://drupal.org/node/1354
1616
 */
1617
function path_to_media($uuid, $representaion_uuid = FALSE, $partId = FALSE) {
1618
  if (!$uuid) {
1619
    return FALSE;
1620
  }
1621
  $out = 'cdm_dataportal/media/' . $uuid;
1622
  if ($representaion_uuid) {
1623
    $out .= '/' . $representaion_uuid;
1624
    if ($partId !== FALSE) {
1625
      $out .= '/' . $partId;
1626
    }
1627
  }
1628
  return $out;
1629
}
1630
1631
/**
1632
 * Compares thisRank with thatRank.
1633
 *
1634
 * Returns a negative integer, zero, or a positive integer
1635
 * as the of thisRank is higher than, equal to, or lower than thatRank.
1636
 * e.g:
1637
 * <ul>
1638
 * <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
1639
 * <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
1640
 * <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
1641
 * </ul>
1642
 * <p>
1643
 * This compare logic of the underlying webservice is the
1644
 * <b>inverse logic</b> of the the one implemented in
1645
 * java.lang.Comparable#compareTo(java.lang.Object)
1646
 *
1647
 * @param $thisRankUuid
1648
 * @param $thatRankUuid
1649
 *
1650
 * @return int
1651
 *   A negative integer, zero, or a positive integer
1652
 *   as the thisRank is lower than, equal to, or higher than thatRank.
1653
 */
1654
function rank_compare($thisRankUuid, $thatRankUuid) {
1655
  $result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
1656
  return $result->Integer;
1657
}
1658
1659
/**
1660
 * Composes an HTML element class attribute value composed of
1661
 * the shortname of the cdm class and the uuid of the entity.
1662
 * This class attribute should be used whereever an cdm-entity is rendered.
1663
 *
1664
 * These according class selectors in css must be escaped, eg:
1665
 *    .cdm\:TextData
1666
 *
1667
 * @param $cdmEntity
1668
 */
1669
function html_class_atttibute_ref($cdmEntity) {
1670
1671
  if (is_cdm_entity($cdmEntity)) {
1672
    return "cdm:" . $cdmEntity->class . " uuid:" . $cdmEntity->uuid;
1673
  }
1674
}
1675
1676
/**
1677
 * Preprocess the taggedName to normalize newly introduced tagtypes like hybridSign, separator, .. more?
1678
 *
1679
 * @param unknown_type $taggedTextList
1680
 */
1681
function normalize_TaggedName(&$taggedTextList) {
1682
1683
  if (is_array($taggedTextList)) {
1684
1685
    // First pass: rename.
1686
    for ($i = 0; $i < count($taggedTextList); $i++) {
1687
1688
      if ($taggedTextList[$i]->type == "hybridSign") {
1689
        $taggedTextList[$i]->type = "name";
1690
      }
1691
    }
1692
1693
    // Second pass: resolve separators.
1694
    $taggedNameListNew = array();
1695
    for ($i = 0; $i < count($taggedTextList); $i++) {
1696
1697
      if ($i + 1 < count($taggedTextList) && $taggedTextList[$i + 1]->type == "separator") {
1698
1699
        if ($taggedTextList[$i]->type == $taggedTextList[$i + 2]->type) {
1700
          $taggedName = $taggedTextList[$i];
1701
          $taggedName->text = $taggedName->text . $taggedTextList[$i + 1]->text . $taggedTextList[$i + 2]->text;
1702
          $taggedNameListNew[] = $taggedName;
1703
          ++$i;
1704
          ++$i;
1705
        }
1706
      }
1707
      else {
1708
        $taggedNameListNew[] = $taggedTextList[$i];
1709
      }
1710
    }
1711
    $taggedTextList = $taggedNameListNew;
1712
  }
1713
}
1714
1715
/**
1716
 * Creates a short taxonname.
1717
 *
1718
 * The short name is created by using the taggename field of
1719
 * NameSTO or NameTO instances.
1720
 * If the taggename if empty the fullname will be returned.
1721
 *
1722
 * @param unknown_type $name
1723
 *   Name or TreeNode.
1724
 *
1725
 * @return string
1726
 */
1727
function cdm_dataportal_shortname_of($name) {
1728
  $nameStr = '';
1729
1730
  normalize_TaggedName($name->taggedTitle);
1731
1732
  // Get all tagged text tokens of the scientific name.
1733
  foreach ($name->taggedTitle as $tagtxt) {
1734
    if ($tagtxt->type == 'name' || $tagtxt->type == 'rank') {
1735
      $nameStr .= ($nameStr ? ' ' : '') . $tagtxt->text;
1736
    }
1737
  }
1738
  $nameStr = trim($nameStr);
1739
1740
  if ($nameStr) {
1741
1742
    // Do not return short names for these.
1743
    if ($name->unplaced || $name->excluded) {
1744
      return $nameStr;
1745
    }
1746
1747
    /*
1748
    1st capture group (^[a-zA-Z]): First letter of uninomial.
1749
    Second capture group ([\p{L}]+): remaining letters of uninomial ([\p{L} = an UTF-8 letter).
1750
    Third capture group (\s+[^(\x2E]+\s+.+$|\s+[a-zA-Z]+$): letters of name,
1751
    but only matching if no '(' or '.' in second word of name,        ( \x2E = '.')
1752
    OR only one specific epithet \s+[\p{L}\x22\x2D\xD7]+$             (\x22= '"', \x2D='-', \xD7='×' )
1753
    */
1754
    $pattern = '/(^[a-zA-Z])([\p{L}]+)(\s+[^(\x2E]+\s+.+$|\s+[\p{L}\x22\x2D\xD7]+$)/u';
1755
    if (preg_match($pattern, $nameStr, $matches, PREG_OFFSET_CAPTURE)) {
1756
      return $matches[1][0] . "." . $matches[3][0];
1757
    }
1758
    else {
1759
      return $nameStr;
1760
    }
1761
  }
1762
  else {
1763
    return $name->titleCache;
1764
  }
1765
}
1766
1767
/**
1768
 * Check if a taxon is accepted by the current taxonomic tree.
1769
 *
1770
 * @param mixed $taxon
1771
 *   The Taxon obkect to check.
1772
 *
1773
 * @return bool
1774
 *   Returns TRUE if $taxon is accepted, FALSE otherwise.
1775
 */
1776
function _cdm_dataportal_acceptedByCurrentView($taxon) {
1777
1778
  $defaultTreeUuid = get_taxonomictree_uuid_selected();
1779
1780
  if (isset($taxon->taxonNodes)) {
1781
    $taxonNodes = $taxon->taxonNodes;
1782
  }
1783
  else {
1784
    $taxonNodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon->uuid);
1785
  }
1786
1787
  if ($taxon->class == "Taxon" && isset($taxonNodes)) {
1788
    foreach ($taxonNodes as $node) {
1789
      if (is_object($node->classification)) {
1790
        if ($node->classification->uuid == $defaultTreeUuid) {
1791
          return TRUE;
1792
        }
1793
      }
1794
      else {
1795
        if ($node->classification == $defaultTreeUuid) {
1796
          return TRUE;
1797
        }
1798
      }
1799
    }
1800
  }
1801
1802
  return FALSE;
1803
}
1804
1805
/**
1806
 * @deprecated
1807
 */
1808
function compose_url_prameterstr($parameters = array(), $parentPropertyName = FALSE) {
1809
  $pstr = '';
1810
  foreach ($parameters as $key => $value) {
1811
    if (is_array($value)) {
1812
1813
    }
1814
    else {
1815
      $pstr .= ($pstr ? '&' : '') . $key . '=' . urlencode($value);
1816
    }
1817
  }
1818
  return $pstr;
1819
}
1820
1821
/**
1822
 * Workaround for missing original source type.
1823
 *
1824
 * idNamespace is always set in these cases.
1825
 * @todo improve documentation of this function.
1826
 *
1827
 * @param unknown_type $source
1828
 *
1829
 * @return unknown_type
1830
 */
1831
function _is_original_source_type($source) {
1832
  return !$source->idNamespace && strlen($source->idNamespace) == 0;
1833
}
1834
1835
/**
1836
 * @todo Please document this function.
1837
 * @see http://drupal.org/node/1354
1838
 */
1839
function _is_invers_taxonRelationship($taxonRelationship, $focusedTaxon) {
1840
  return $taxonRelationship->toTaxon->uuid == $focusedTaxon->uuid;
1841
}
1842
1843
/**
1844
 * Gets the metadata info such as title or artist of a media file.
1845
 *
1846
 * The function tries at first to get all the info from the file metadata
1847
 * and if it is not avaible look at the media file info stored at the database.
1848
 *
1849
 * @param mixed $media
1850
 *   The media file object for which to get the metadata.
1851
 *
1852
 * @return array
1853
 *   The array with the available specified metadata info.
1854
 * TODO rename to read_media_metadata() and move to *.module.
1855
 */
1856
function cdm_read_media_metadata($media) {
1857
1858
  $metadata_caption = array(
1859
    'title' => '',// Media_metadata and media.
1860
    'artist' => '',// Media_metadata and media.
1861
    'rights',// Media_metadata and media.
1862
    'location',// Media_metadata.
1863
    'filename' => '',// Media.
1864
    'mediacreated' => '',// Media.
1865
    'description' => '',
1866
  );// Media.
1867
1868
  // Getting the media metadata.
1869
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
1870
  $media_metadata_aux = (array) $media_metadata;
1871
1872
  // Filename.
1873
  if (isset($media->representations[0]->parts[0]->uri)) {
1874
    $fileUri = $media->representations[0]->parts[0]->uri;
1875
    $filename = substr($fileUri, strrpos($fileUri, "/") + 1);
1876
    $metadata_caption['filename'] = $filename;
1877
  }
1878
  else {
1879
    $metadata_caption['filename'] = '';
1880
  }
1881
1882
  // Title.
1883
  if (!empty($media_metadata->ObjectName)) {
1884
    $metadata_caption['title'] = $media_metadata->ObjectName;
1885
  }
1886
  elseif ($media_metadata_aux['Object Name']) {
1887
    $metadata_caption['title'] = $media_metadata_aux['Object Name'];
1888
  }
1889
  elseif ($media->title_L10n) {
1890
    $metadata_caption['title'] = $media->title_L10n;
1891
  }
1892
  elseif ($media->titleCache) {
1893
    $metadata_caption['title'] = $media->titleCache;
1894
  }
1895
1896
  // Append description to title.
1897
  if (!empty($media->description_L10n)) {
1898
    $metadata_caption['title'] .= '<span class="media-description">' . $media->description_L10n . '<span>';
1899
  }
1900
1901
  // Artist.
1902
  if ($media_metadata->Artist) {
1903
    $metadata_caption['artist'] = ($media_metadata->Artist ? '' . $media_metadata->Artist : '');
1904
  }
1905
  elseif ($media->artist->titleCache) {
1906
    $metadata_caption['artist'] = $media->artist->titleCache;
1907
  }
1908
1909
  // Copyright.
1910
  $metadata_caption['rights'] = array(
1911
    'copyright' => array('agentNames' => array()),
1912
    'license' => array(
1913
      'agentNames' => array(),
1914
      'types' => array(),
1915
      'abbreviatedTexts' => array(),
1916
      'uris' => array(),
1917
    ),
1918
  );
1919
  if ($media_metadata->Copyright) {
1920
    $metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
1921
  }
1922
  elseif (isset($media->rights) && is_array($media->rights)) {
1923
    foreach ($media->rights as $right) {
1924
      switch ($right->term->uuid) {
1925
        case UUID_RIGHTS_LICENCE:
1926
          $metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? '' . $right->agent->firstname . ' ' . $right->agent->lastname : '');
1927
          $metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? '' . $right->representation_L10n : '');
1928
          $metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? '' . $right->abbreviatedText : '');
1929
          $metadata_caption['rights']['license']['uris'][] = ($right->uri ? '' . $right->uri : '');
1930
          break;
1931
        case UUID_RIGHTS_COPYRIGHT:
1932
          $metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
1933
          break;
1934
      }
1935
    }
1936
  }
1937
  else {
1938
    $metadata_caption['rights']['agentNames'][] = '';
1939
  }
1940
1941
  // Filling the description (though there is no description in the db???).
1942
  // $metadata_caption['description'] = $media->description_L10n;
1943
1944
  // Location.
1945
  $metadata_caption['location'] = array();
1946
  $metadata_caption['location']['sublocation'] = !empty($media_metadata->Sublocation) ? $media_metadata->Sublocation : FALSE;
1947
  $metadata_caption['location']['city'] = !empty($media_metadata->City) ? $media_metadata->City : FALSE;
1948
  $metadata_caption['location']['province'] = !empty($media_metadata->Province) ? $media_metadata->Province : FALSE;
1949
  $metadata_caption['location']['country'] = !empty($media_metadata->Country)? $media_metadata->Country : FALSE;
1950
1951
  /*
1952
   // Creation date.
1953
   if($media_metadata["Modify Date"])
1954
   $metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
1955
   else
1956
   $metadata_caption['mediacreated'] = $media->created;
1957
   */
1958
1959
  // Returned value.
1960
  return $metadata_caption;
1961
}
1962
1963
/**
1964
 * Collects all the media from a list of description elements.
1965
 *
1966
 * @param array $descriptionElements
1967
 *   The description elements from which to collect the media.
1968
 *
1969
 * @return array
1970
 *   The output with all the collected media.
1971
 */
1972
function cdm_dataportal_media_from_descriptionElements($descriptionElements) {
1973
1974
  $outArrayOfMedia = array();
1975
1976
  // Avoiding a warning box in Drupal for Flora Malesiana.
1977
  if (isset($descriptionElements) && is_array($descriptionElements)) {
1978
    foreach ($descriptionElements as $descriptionElement) {
1979
      if (isset($descriptionElement->media) && is_array($descriptionElement->media)) {
1980
        foreach ($descriptionElement->media as $media) {
1981
          if (is_object($media)) {
1982
            $outArrayOfMedia[] = $media;
1983
          }
1984
        }
1985
      }
1986
    }
1987
  }
1988
  return $outArrayOfMedia;
1989
}
1990
1991
/**
1992
 * @todo Please document this function.
1993
 * @see http://drupal.org/node/1354
1994
 *
1995
 * @param array $cdmBase_list
1996
 *   An array of CdmBase instances or a single instance.
1997
 * @param string $footnote_list_key
1998
 *
1999
 * @return unknown
2000
 */
2001
function cdm_annotations_as_footnotekeys($cdmBase_list, $footnote_list_key = NULL) {
2002
  // Comment @WA: undefined variable.
2003
  /*
2004
   static $annotations_types_filter;
2005
   if(!$annotations_types_filter) {
2006
   unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT);
2007
   }
2008
   */
2009
  unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT);
2010
2011
  $footNoteKeys = array();
2012
2013
  // Is argument cdmBase an array?
2014
  if (!is_array($cdmBase_list)) {
2015
    $cdmBase_array = array();
2016
    $cdmBase_array[] = $cdmBase_list;
2017
  }
2018
  else {
2019
    $cdmBase_array = $cdmBase_list;
2020
  }
2021
2022
  // Getting the key for the footnotemanager.
2023
  if (isset($footnote_list_key)) {
2024
    $footnoteListKey = $footnote_list_key;
2025
  }
2026
  else {
2027
    $footnoteListKey = RenderHints::getFootnoteListKey() . '-annotations';
2028
  }
2029
2030
  // Adding the footnotes keys.
2031
  $annotations_types_filter = unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT);
2032
  foreach ($cdmBase_array as $cdmBase_element) {
2033
    $annotations = cdm_ws_getAnnotationsFor($cdmBase_element, variable_get('annotations_types_as_footnotes', $annotations_types_filter));
2034
    if (is_array($annotations)) {
2035
      foreach ($annotations as $annotation) {
2036
        $footNoteKeys[] = FootnoteManager::addNewFootnote($footnoteListKey, $annotation->text);
2037
      }
2038
    }
2039
  }
2040
2041
  return $footNoteKeys;
2042
}
2043
2044
// @WA Comment: should this not be a theme function?
2045
/**
2046
 *  Creates a CDM Dynabox.
2047
 *
2048
 * @param string $label
2049
 *   The clickable text to show.
2050
 * @param string $content_url
2051
 *   The cdm REST service request url wich will deliver the content to be shown
2052
 *   once the dynabox toggles open.
2053
 * @param string $theme
2054
 *   The theme to be used for rendering the cdm REST service reponse with is
2055
 *   returned from the $content_url.
2056
 * @param string $link_alt_text
2057
 *   The value for the alt attribute of the dynabox link.
2058
 * @param array $enclosingtags
2059
 *   An array with two elements: $enclosingtags[0] will be used for the dynabox
2060
 *   element itself, $enclosingtags[1] is the tag to be used for the
2061
 *   dynabox_content.
2062
 *
2063
 * @return string
2064
 *   Returns HTML for a dynabox.
2065
 */
2066
function cdm_dynabox($label, $content_url, $theme, $link_alt_text, $enclosingtags = array('li', 'ul')) {
2067
  $out = '';
2068
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cdm_dynabox.js');
2069
2070
  $cdm_proxy_url = url('cdm_api/proxy/' . urlencode($content_url) . "/$theme");
2071
  $out .= '<!-- ' . $content_url . ' -->';
2072
  $out .= '<' . $enclosingtags[0] . ' class="dynabox"><a href="#" class="label" alt="' . t($link_alt_text) . '">' . $label . '</a>';
2073
  $out .= '<' . $enclosingtags[1] . ' class="dynabox_content" title="' . $cdm_proxy_url . '"><' . $enclosingtags[0] . '><img class="loading" src="' . drupal_get_path('module', 'cdm_dataportal') . '/images/loading_circle_grey_16.gif" style="display:none;"></' . $enclosingtags[0] . '></' . $enclosingtags[1] . '>';
2074
  $out .= '</' . $enclosingtags[0] . '>';
2075
  return $out;
2076
}
2077
2078
/**
2079
 * Checks whether a feature has any description elements.
2080
 *
2081
 * @param mixed $featureNode
2082
 *   A feature node as produced by the function _mergeFeatureTreeDescriptions().
2083
 *
2084
 * @see _mergeFeatureTreeDescriptions()
2085
 *
2086
 * @return bool
2087
 *   Returns TRUE if the given $featureNode or any of its subordinate nodes
2088
 *   contains at least one non empty TextData or at least one DescriptionElement
2089
 *   of an other type. A TextData element holding a multilanguageText or a
2090
 *   source reference is considered to be not empty.
2091
 */
2092
function hasFeatureNodeDescriptionElements($featureNode) {
2093
2094
  if (isset($featureNode->descriptionElements) && is_array($featureNode->descriptionElements) && count($featureNode->descriptionElements) > 0) {
2095
    foreach ($featureNode->descriptionElements as $descriptionElement) {
2096
      if ($descriptionElement->class != "TextData" || isset($descriptionElement->multilanguageText_L10n->text) && $descriptionElement->multilanguageText_L10n->text != '' || isset($descriptionElement->sources[0])) {
2097
        return TRUE;
2098
      }
2099
    }
2100
  }
2101
  elseif (isset($featureNode->children) && is_array($featureNode->children)) {
2102
    foreach ($featureNode->children as $child) {
2103
      if (hasFeatureNodeDescriptionElements($child)) {
2104
        return TRUE;
2105
      }
2106
    }
2107
  }
2108
  return FALSE;
2109
}