Project

General

Profile

Download (88.5 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 38b27a36 Andreas Kohlbecker
  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('inc', 'cdm_dataportal', 'includes/common');
26 2e31ea9e Andreas Kohlbecker
  module_load_include('inc', 'cdm_dataportal', 'includes/name');
27 b7a20282 Andreas Kohlbecker
  module_load_include('inc', 'cdm_dataportal', 'includes/taxon');
28
  module_load_include('inc', 'cdm_dataportal', 'includes/references');
29 38b27a36 Andreas Kohlbecker
  module_load_include('inc', 'cdm_dataportal', 'includes/pages');
30
  module_load_include('inc', 'cdm_dataportal', 'includes/media');
31
  module_load_include('inc', 'cdm_dataportal', 'includes/maps');
32
  module_load_include('inc', 'cdm_dataportal', 'includes/occurrences');
33
  module_load_include('inc', 'cdm_dataportal', 'includes/descriptions');
34
  module_load_include('inc', 'cdm_dataportal', 'includes/pre-drupal8');
35
36
  module_load_include('inc', 'cdm_dataportal', 'theme/theme_registry');
37
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.common');
38
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.descriptions');
39
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.media');
40
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.occurrence');
41
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.page');
42
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.taxon');
43
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.name');
44
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.references');
45
46
  module_load_include('php', 'cdm_dataportal', 'classes/footnotemanager');
47
  module_load_include('php', 'cdm_dataportal', 'classes/footnote');
48
  module_load_include('php', 'cdm_dataportal', 'classes/footnotekey');
49
  module_load_include('php', 'cdm_dataportal', 'classes/renderhints');
50
51
52
  /* ============================ java script functions ============================= */
53
54
55
  /**
56
  * loads external java script files asynchronously.
57
  *
58
  * @param unknown_type $script_url
59
  */
60
  function drupal_add_js_async($script_url, $callback){
61
62
    drupal_add_js("
63
          jQuery(document).ready(function() {
64
            jQuery.ajax({
65
              url: '" . $script_url . "',
66
              dataType: 'script',
67
              cache: true, // otherwise will get fresh copy every page load
68
              success: function() {
69
                    " . $callback . "
70
              }
71
            });
72
          });"
73
    , 'inline');
74 6657531f Andreas Kohlbecker
  }
75
76 38b27a36 Andreas Kohlbecker
  /**
77
   */
78
  function drupal_add_js_rowToggle($tableId){
79 6657531f Andreas Kohlbecker
80 38b27a36 Andreas Kohlbecker
      drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/table_modification.js');
81
      drupal_add_js('jQuery(document).ready(function(){
82
          addRowToggle("' . $tableId . '");
83 6657531f Andreas Kohlbecker
      });
84 38b27a36 Andreas Kohlbecker
      ', array('type' => 'inline'));
85
  }
86 d2fd2a4c Andreas Kohlbecker
87 38b27a36 Andreas Kohlbecker
  /**
88
   * @param unknown_type $link_element_selector
89
   * @param unknown_type $progress_element_selector
90
   */
91
  function _add_js_cdm_ws_progressbar($link_element_selector, $progress_element_selector){
92
93
    $callback = "jQuery('" . $link_element_selector . "').cdm_ws_progress('" . $progress_element_selector . "');";
94
95
    drupal_add_js_async(variable_get('cdm_webservice_url', '').'js/cdm_ws_progress.js', $callback);
96
97
    //   drupal_add_js("
98
    //   	  if (Drupal.jsEnabled) {
99
    //         $(document).ready(function() {
100
    //       		$('" . $link_element_selector . "').cdm_ws_progress('" . $progress_element_selector . "');
101
    //         });
102
    //       }", 'inline');
103
    }
104
105
  /**
106
   * @todo Please document this function.
107
   * @see http://drupal.org/node/1354
108
   */
109
  function _add_js_treeselector() {
110
    // drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/treeselector.js');
111
    drupal_add_js("
112
        jQuery(document).ready(function() {
113
           jQuery('#cdm-taxonomictree-selector-form #edit-val').change(function () {
114
                jQuery('#cdm-taxonomictree-selector-form').submit();
115
            });
116
117
        });
118
      ",
119
      array(
120
        'type' => 'inline',
121
        'scope' => 'footer'
122
      )
123
    );
124 5ea8b301 Andreas Kohlbecker
  }
125
126 6b605d3b Andreas Kohlbecker
  function _add_js_resizable_element($selector, $y_axis_only) {
127
128
    _add_jquery_ui();
129
    $options = "";
130
    if($y_axis_only) {
131
      $options = "resize: function(event, ui) {
132
        ui.size.width = ui.originalSize.width;
133
        },
134
        handles: \"s\"";
135
136
    }
137
    drupal_add_js("
138
          jQuery(document).ready(function() {
139
             jQuery('" . $selector . "').resizable({". $options ."});
140
          });
141
        ",
142
      array(
143
        'type' => 'inline',
144
        'scope' => 'footer'
145
      )
146
    );
147
  }
148
149 38b27a36 Andreas Kohlbecker
  function _add_js_openlayers() {
150
151
    $openlayers = '/js/map/OpenLayers-2.13.1/OpenLayers.js';
152
    $proj4js = '/js/map/proj4js-1.1.0/proj4js-compressed.js';
153
154
    if(variable_get('cdm_js_devel_mode', FALSE)){
155
      // develooper mode libs
156
  //     $openlayers = '/js/map/OpenLayers-2.13.1/lib/OpenLayers.js';
157
      $openlayers = '/js/map/OpenLayers-2.13.1/OpenLayers.debug.js';
158
      $proj4js = '/js/map/proj4js-1.1.0/proj4js-combined.js';
159
    }
160
161
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . $openlayers,
162
      array(
163
        'type' => 'file',
164 4c21ffdb Andreas Kohlbecker
        'group' => JS_LIBRARY,
165
        'weight' => 0,
166 38b27a36 Andreas Kohlbecker
        'cache' => TRUE,
167
        'preprocess' => FALSE
168
      )
169
    );
170
171
    // see https://github.com/proj4js/proj4js
172
    // http://openlayers.org/dev/examples/using-proj4js.html
173
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . $proj4js,
174
      array(
175
        'type' => 'file',
176 4c21ffdb Andreas Kohlbecker
        'group' => JS_LIBRARY,
177
        'weight' => -1, // before open layers
178 38b27a36 Andreas Kohlbecker
        'cache' => TRUE,
179
      )
180
    );
181
182
    // configure the theme
183
    $openlayers_theme_path = drupal_get_path('module', 'cdm_dataportal') . '/js/map/OpenLayers-2.13.1/theme/default/';
184
    $openlayers_imp_path = drupal_get_path('module', 'cdm_dataportal') . '/js/map/img/dark/';
185
    drupal_add_js('OpenLayers.ImgPath="' . base_path() . $openlayers_imp_path . '";', array(
186
        'type' => 'inline',
187 4c21ffdb Andreas Kohlbecker
        'group' => JS_LIBRARY,
188
        'weight' => 1, // after openlayers
189 38b27a36 Andreas Kohlbecker
        'cache' => TRUE,
190
        'preprocess' => FALSE
191
      ));
192
193
    drupal_add_css($openlayers_theme_path . 'style.tidy.css',
194
      array(
195
        'type' => 'file',
196
        'cache' => TRUE,
197
        'preprocess' => FALSE
198
      )
199
    );
200 e3026d72 Andreas Kohlbecker
201 38b27a36 Andreas Kohlbecker
  }
202 e3026d72 Andreas Kohlbecker
203 38b27a36 Andreas Kohlbecker
  /**
204
   * @todo Please document this function.
205
   * @see http://drupal.org/node/1354
206
   */
207
  function _add_js_thickbox() {
208
    // ---- jQuery thickbox:
209
    /*
210
    * bug: compat-1.0.js && thickbox.js line 237 .trigger("unload") -> event is
211
    * not triggered because of problems with compat-1.0.js' see INSTALL.txt
212
    */
213
    // drupal_add_js(drupal_get_path('module',
214
    // 'cdm_dataportal').'/js/jquery.imagetool.min.js');
215
    //
216
    // Add a setting for the path to cdm_dataportal module, used to find the path
217
    // for the loading animation image in thickbox.
218
    drupal_add_js(array(
219
    'cdm_dataportal' => array(
220
    'cdm_dataportal_path' => base_path() . drupal_get_path('module', 'cdm_dataportal'),
221 10f6aa4b Andreas Kohlbecker
    )
222 38b27a36 Andreas Kohlbecker
    ),
223
    'setting'
224
        );
225
        drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/thickbox/thickbox.js');
226
        drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/js/thickbox/cdm_thickbox.css');
227
  }
228 94550ff9 Andreas Kohlbecker
229 38b27a36 Andreas Kohlbecker
  /**
230
   * @todo Please document this function.
231
   * @see http://drupal.org/node/1354
232
   */
233
  function _add_js_lightbox($galleryID) {
234
    /*
235
     * Important Notice: The jquery.lightbox-0.5.js has been modified in order to
236 fe19a89b Andreas Kohlbecker
     * allow using the "alt" attribute for captions instead of the "title"
237
     * attribute
238
     */
239 38b27a36 Andreas Kohlbecker
    $lightbox_base_path =  drupal_get_path('module', 'cdm_dataportal') . '/js/jquery-lightbox-0.5';
240
    $lightbox_image_path = base_path() . $lightbox_base_path . '/images/';
241
    drupal_add_js($lightbox_base_path . '/js/jquery.lightbox-0.5.js');
242
    drupal_add_css($lightbox_base_path . '/css/jquery.lightbox-0.5.css');
243
    drupal_add_js('jQuery(document).ready(function() {
244
        jQuery(\'#' . $galleryID . ' a.lightbox\').lightBox({
245
          fixedNavigation:  true,
246
          imageLoading:     \'' . $lightbox_image_path . 'lightbox-ico-loading.gif\',
247
          imageBtnPrev:     \'' . $lightbox_image_path . 'lightbox-btn-prev.gif\',
248
          imageBtnNext:     \'' . $lightbox_image_path . 'lightbox-btn-next.gif\',
249
          imageBtnClose:    \'' . $lightbox_image_path . 'lightbox-btn-close.gif\',
250
          imageBlank:       \'' . $lightbox_image_path . 'lightbox-blank.gif\',
251
          adjustToWindow: true
252
        });
253 94550ff9 Andreas Kohlbecker
      });
254 38b27a36 Andreas Kohlbecker
      ', array('type' => 'inline'));
255
  }
256 94550ff9 Andreas Kohlbecker
257 38b27a36 Andreas Kohlbecker
  /**
258
   * @todo Please document this function.
259
   * @see http://drupal.org/node/1354
260
   */
261
  function _add_js_footnotes() {
262
    _add_js_domEvent();
263
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/footnotes.js');
264
  }
265 94550ff9 Andreas Kohlbecker
266 38b27a36 Andreas Kohlbecker
  /**
267
   * @todo Please document this function.
268
   * @see http://drupal.org/node/1354
269
   */
270
  function _add_js_ahah() {
271 b386ae48 Andreas Kohlbecker
272 38b27a36 Andreas Kohlbecker
    _add_js_domEvent(); // requires domEvent.js
273
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/ahah-content.js');
274
  }
275 94550ff9 Andreas Kohlbecker
276 d0d23caa Andreas Kohlbecker
/**
277
 * @todo Please document this function.
278
 * @see http://drupal.org/node/1354
279
 */
280
function _add_js_taxonomic_children($jquery_selector) {
281 b0adfd32 Andreas Kohlbecker
282
  global $base_url;
283
284
285
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/jquery.cdm.taxonomic_children.js');
286 faf4f771 Andreas Kohlbecker
  
287 d0d23caa Andreas Kohlbecker
  drupal_add_js('jQuery(document).ready(function() {
288 b0adfd32 Andreas Kohlbecker
        jQuery(\'' . $jquery_selector . '\').taxonomic_children({
289 09edee9a Andreas Kohlbecker
          // hoverClass: "fa-rotate-90",
290
          // activeClass: "fa-rotate-90",
291 b0adfd32 Andreas Kohlbecker
          classificationUuid: "' . get_current_classification_uuid() . '",
292 0af3ce28 Andreas Kohlbecker
          taxonUuid: "' . get_current_taxon_uuid() . '",
293 38da4e54 Andreas Kohlbecker
          cdmWebappBaseUri: "' . variable_get('cdm_webservice_url', '') . '",
294 b0adfd32 Andreas Kohlbecker
          proxyBaseUri: "' . $base_url . '",
295
          
296
        });
297 d0d23caa Andreas Kohlbecker
      });
298
      ', array('type' => 'inline'));
299
}
300
301 38b27a36 Andreas Kohlbecker
  /**
302
   * Adds the external javascript file for domEvent.js.
303
   *
304
   * @see drupal_add_js()
305
   */
306
  function _add_js_domEvent() {
307
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/domEvent.js');
308
  }
309 b386ae48 Andreas Kohlbecker
310 087bb473 Andreas Kohlbecker
  function _add_jquery_ui()
311
  {
312
    drupal_add_css(drupal_get_path('module',
313
        'cdm_dataportal') . '/js/jquery-ui-1.8.24/themes/base/jquery.ui.all.css');
314
    drupal_add_js(drupal_get_path('module',
315
        'cdm_dataportal') . '/js/jquery-ui-1.8.24/ui/jquery-ui.js',
316
      array(
317
        'type' => 'file',
318
        'weight' => JS_LIBRARY,
319
        'cache' => TRUE,
320
        'preprocess' => FALSE
321
      )
322
    );
323
  }
324
325 b18d70f6 Andreas Kohlbecker
  function _add_js_ui_accordion(){
326
    _add_jquery_ui();
327
    drupal_add_js('jQuery(document).ready(function() {
328
        jQuery( "#accordion" ).accordion();
329
      });',
330
      array('type' => 'inline')
331
    );
332
  }
333
334 38b27a36 Andreas Kohlbecker
  /**
335
   * Provides the markup for an font awesome icon.
336
   *
337
   * The icons is created in default size without any extra features.
338
   *
339
   * The available icons are listed here http://fontawesome.io/cheatsheet/
340 ef12d0c6 Andreas Kohlbecker
   * fontawesome icons have much more features than implemented here in this function,
341
   * for spinning icons, fixed width icons, rotation, etc please checkout the
342 38b27a36 Andreas Kohlbecker
   * examples at http://fontawesome.io/examples/
343
   *
344
   * @parameter $icon_name
345
   *  The name of the icon which starts with 'fa-'
346
   *
347
   * @return String
348
   *    the markup for the icon in an <i> tag
349
   *
350
   */
351 b0aa9a8f Andreas Kohlbecker
  function font_awesome_icon_markup($icon_name = NULL, $attributes = array()){
352 6d9071b7 Andreas Kohlbecker
    _add_font_awesome_font();
353 38b27a36 Andreas Kohlbecker
354
355 b0aa9a8f Andreas Kohlbecker
    if($icon_name){
356
      if(!isset($attributes['class'])){
357
        $attributes['class'] = array();
358
      }
359
      $attributes['class'][] = 'fa';
360
      $attributes['class'][] = $icon_name;
361
362
      return '<i ' . drupal_attributes($attributes) . '></i>';
363 38b27a36 Andreas Kohlbecker
    }
364
365 b0aa9a8f Andreas Kohlbecker
    return '';
366 38b27a36 Andreas Kohlbecker
  }
367 94550ff9 Andreas Kohlbecker
368 6d9071b7 Andreas Kohlbecker
/**
369
 * Adds the css  containing the font awesome icons to the html header.
370
 */
371
function _add_font_awesome_font()
372
{
373
//<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
374
375
  $font_awesome_css_uri = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/fonts/font-awesome-4.6.3/css/font-awesome.min.css';
376
  //$font_awesome_css_uri="//maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css";
377
378
  drupal_add_html_head_link(
379
    array(
380
      'href' => $font_awesome_css_uri,
381
      'rel' => 'stylesheet'
382
    )
383
  );
384
}
385
386 38b27a36 Andreas Kohlbecker
387 6d9071b7 Andreas Kohlbecker
/* ====================== hook implementations ====================== */
388 38b27a36 Andreas Kohlbecker
  /**
389
   * Implements hook_permission().
390
   *
391
   * Valid permissions for this module.
392
   *
393
   * @return array
394 8385a9f2 Andreas Kohlbecker
   *   An array of valid permissions for the cdm_dataportal module.
395 38b27a36 Andreas Kohlbecker
   */
396
  function cdm_dataportal_permission() {
397
    return array(
398
      'administer cdm_dataportal' => array(
399 8385a9f2 Andreas Kohlbecker
        'title' => t('Administer CDM DataPortal settings'),
400
        'description' => t("Access the settings pages specific for the cdm_dataportal module"),
401 c6fe437b Andreas Kohlbecker
      ),
402
      'access cdm content' => array(
403
        'title' => t('Access CDM content'),
404
        'description' => t("Access content (taxa, names, specimens, etc.) served by the CDM web service."),
405
      ),
406 38b27a36 Andreas Kohlbecker
    );
407
  }
408 6657531f Andreas Kohlbecker
409
/**
410 f19f47fa Andreas Kohlbecker
 * Implements hook_menu().
411
 */
412 6657531f Andreas Kohlbecker
function cdm_dataportal_menu() {
413
  $items = array();
414
415
  // @see settings.php.
416
  cdm_dataportal_menu_admin($items);
417
  cdm_dataportal_menu_help($items);
418
419
  $items['cdm_dataportal/names'] = array(
420
    'page callback' => 'cdm_dataportal_view_names',
421 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
422 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
423
  );
424
425
  // Optional callback arguments: page.
426
  $items['cdm_dataportal/taxon'] = array(
427
    'page callback' => 'cdm_dataportal_taxon_page_view',
428 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
429 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
430
    // Expected callback arguments: uuid.
431
  );
432
433 a1ce57ce Katja Luther
  $items['cdm_dataportal/occurrence'] = array(
434 6eaec849 Katja Luther
        'page callback' => 'cdm_dataportal_specimen_page_view',
435
        'access arguments' => array('access cdm content'),
436
        'type' => MENU_CALLBACK,
437
        // Expected callback arguments: uuid.
438
    );
439 30845bda Andreas Kohlbecker
440 6eaec849 Katja Luther
    $items['cdm_dataportal/specimen/accession_number'] = array(
441
        'page callback' => 'cdm_dataportal_specimen_by_accession_number_page_view',
442
        'access arguments' => array('access cdm content'),
443
        'type' => MENU_CALLBACK,
444
        // Expected callback arguments: accession number.
445
    );
446 30845bda Andreas Kohlbecker
  $items['cdm_dataportal/named_area'] = array(
447
    'page callback' => 'cdm_dataportal_named_area_page_view',
448
    'access arguments' => array('access cdm content'),
449
    'type' => MENU_CALLBACK,
450
    // Expected callback arguments: uuid.
451
  );
452 9d37c9d9 Patric Plitzner
453 6657531f Andreas Kohlbecker
  $items['cdm_dataportal/name'] = array(
454
    'page callback' => 'cdm_dataportal_name_page_view',
455
      /*
456
    'page arguments' => array(
457
       'taxon_name_uuid',
458
       'taxon_to_hide_uuid',
459
       'synonym_uuid' => NULL
460
      ),
461
      */
462 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
463 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
464
    // Expected callback arguments: uuid.
465
  );
466
467
  $items['cdm_dataportal/reference'] = array(
468
    'page callback' => 'cdm_dataportal_view_reference',
469 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
470 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
471
    // Expected callback arguments: uuid.
472
  );
473
474
  $items['cdm_dataportal/reference/list'] = array(
475
    'page callback' => 'cdm_dataportal_view_reference_list',
476 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
477 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
478
    // Expected callback arguments: uuid.
479
  );
480
481
  $items['cdm_dataportal/media'] = array(
482
    'page callback' => 'cdm_dataportal_view_media',
483 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
484 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
485
    // Expected callback arguments:
486
    // uuid, mediarepresentation_uuid, part_uuid or part#.
487
  );
488
489
  $items['cdm_dataportal/polytomousKey'] = array(
490
    'page callback' => 'cdm_dataportal_view_polytomousKey',
491 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
492 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
493
    // Expected callback arguments: polytomousKey->uuid.
494
  );
495
496
  $items['cdm_dataportal/search'] = array(
497
    'page callback' => 'cdm_dataportal_view_search_advanced',
498 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
499 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
500
  );
501
502
  $items['cdm_dataportal/search/advanced'] = array(
503 29077ee5 Andreas Kohlbecker
    'title' => 'Advanced', // will be passed through t()
504 6657531f Andreas Kohlbecker
    'page callback' => 'cdm_dataportal_view_search_advanced',
505 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
506 6657531f Andreas Kohlbecker
    'type' => MENU_DEFAULT_LOCAL_TASK,
507
  );
508 6eaec849 Katja Luther
if (variable_get(CDM_BLAST)) {
509 a1ce57ce Katja Luther
    $items['cdm_dataportal/search/blast'] = array(
510
        'title' => 'Blast', // will be passed through t()
511
        'page callback' => 'cdm_dataportal_view_search_blast',
512
        'access arguments' => array('access cdm content'),
513
        'type' => MENU_DEFAULT_LOCAL_TASK,
514
    );
515 6eaec849 Katja Luther
}
516 6657531f Andreas Kohlbecker
  $items['cdm_dataportal/search/taxon_by_description'] = array(
517 579c485d Andreas Kohlbecker
    'title' => 'By content category', // will be passed through t()
518 6657531f Andreas Kohlbecker
    'page callback' => 'cdm_dataportal_view_search_taxon_by_description',
519 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
520 6657531f Andreas Kohlbecker
    'type' => MENU_LOCAL_TASK,
521
  );
522
  $items['cdm_dataportal/search/results/taxon'] = array(
523
    'page callback' => 'cdm_dataportal_view_search_results_taxon',
524 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
525 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
526
  );
527 a1ce57ce Katja Luther
528
529
    $items['cdm_dataportal/search/results/specimen'] = array(
530
        'page callback' => 'cdm_dataportal_view_search_results_specimen',
531
        'access arguments' => array('access cdm content'),
532
        'type' => MENU_CALLBACK,
533
    );
534 efbff4b3 Andreas Kohlbecker
  /*
535
   * MENU_CALLBACK at cdm_dataportal/registration-search is needed to make the
536
   * tabs in the subordinate paths work, accessing this 'page' will cause the
537
   * MENU_DEFAULT_LOCAL_TASK being displayed
538
   */
539
  $items['cdm_dataportal/registration-search'] = array(
540
    'title' => 'Search', // will be passed through t()
541 a6ae799b Andreas Kohlbecker
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
542 efbff4b3 Andreas Kohlbecker
    'page arguments' => array("filter"),
543 a6ae799b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
544
    'type' => MENU_CALLBACK,
545
  );
546 efbff4b3 Andreas Kohlbecker
  /*
547
   * the MENU_DEFAULT_LOCAL_TASK creates a tab for the MENU_CALLBACK
548
   * defined at a higher level of the path (cdm_dataportal/registration-search)
549
   */
550
  $items['cdm_dataportal/registration-search/filter'] = array(
551
    'title' => 'Search', // will be passed through t()
552
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
553
    'page arguments' => array("filter"),
554
    'access arguments' => array('access cdm content'),
555
    'type' => MENU_DEFAULT_LOCAL_TASK,
556
  );
557
  /*
558
   * the MENU_LOCAL_TASK creates another tab
559
   */
560
  $items['cdm_dataportal/registration-search/taxongraph'] = array(
561
    'title' => 'Taxonomic search', // will be passed through t()
562
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
563
    'page arguments' => array("taxongraph"),
564
    'access arguments' => array('access cdm content'),
565
    'type' => MENU_LOCAL_TASK,
566
  );
567
568 e0d3e148 Andreas Kohlbecker
  // Optional callback arguments: page.
569
  $items['cdm_dataportal/registration'] = array(
570
    'page callback' => 'cdm_dataportal_registration_page_view',
571
    'access arguments' => array('access cdm content'),
572
    'type' => MENU_CALLBACK,
573
    // Expected callback arguments: uuid.
574
  );
575 a6ae799b Andreas Kohlbecker
576 6657531f Andreas Kohlbecker
  /*
577
   $items['cdm/xml2json'] = array(
578
   'page callback' => 'cdm_view_xml2json',
579 c6fe437b Andreas Kohlbecker
   'access arguments' => array('access cdm content'),
580 6657531f Andreas Kohlbecker
   'type' => MENU_CALLBACK,
581
   );
582
   */
583
584
  // 'May not cache' in D5.
585
  $items['cdm_dataportal/name/%'] = array(
586
    // 'page callback' => 'cdm_dataportal_view_name',
587
    'page callback' => 'cdm_dataportal_name_page_view',
588
    'page arguments' => array(2, 3, 4),
589 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
590 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
591
  );
592
593 6f1a217c Andreas Kohlbecker
  // --- Local tasks for Taxon.
594
  // --- tabbed taxon page
595 6657531f Andreas Kohlbecker
  if (variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
596
    $items['cdm_dataportal/taxon/%'] = array(
597 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('General'),
598 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
599 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
600 6657531f Andreas Kohlbecker
      'type' => MENU_CALLBACK,
601
      'weight' => 1,
602
      'page arguments' => array(2, "description")
603 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
604 6657531f Andreas Kohlbecker
    );
605
606
    $items['cdm_dataportal/taxon/%/all'] = array(
607 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('General'),
608 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
609 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
610 6657531f Andreas Kohlbecker
      'type' => MENU_CALLBACK,
611
      'weight' => 2,
612
      'page arguments' => array(2, "all")
613 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
614 6657531f Andreas Kohlbecker
    );
615
616
    $items['cdm_dataportal/taxon/%/description'] = array(
617 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('General'),
618 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
619 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
620 6657531f Andreas Kohlbecker
      'type' => MENU_DEFAULT_LOCAL_TASK,
621
      'weight' => 2,
622
      'page arguments' => array(2, "description")
623 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
624 6657531f Andreas Kohlbecker
    );
625
626
    $items['cdm_dataportal/taxon/%/synonymy'] = array(
627 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('Synonymy'),
628 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
629 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
630 6657531f Andreas Kohlbecker
      'type' => MENU_LOCAL_TASK,
631
      'weight' => 4,
632
      'page arguments' => array(2, "synonymy", 4)
633 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid and ...
634 6657531f Andreas Kohlbecker
    );
635 7cc085da Andreas Kohlbecker
    $items['cdm_dataportal/taxon/%/images'] = array( // Images
636 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('Images'),
637 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
638 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
639 6657531f Andreas Kohlbecker
      'type' => MENU_LOCAL_TASK,
640
      'weight' => 5,
641
      'page arguments' => array(2, "images")
642 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
643 6657531f Andreas Kohlbecker
    );
644
645 7cc085da Andreas Kohlbecker
    $items['cdm_dataportal/taxon/%/specimens'] = array( // Specimens
646 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('Specimens'),
647 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
648 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
649 6657531f Andreas Kohlbecker
      'type' => MENU_LOCAL_TASK,
650
      'weight' => 6,
651
      'page arguments' => array(2, "specimens")
652 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
653 6657531f Andreas Kohlbecker
    );
654
655 7cc085da Andreas Kohlbecker
    $items['cdm_dataportal/taxon/%/keys'] = array( // Keys
656 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('Keys'),
657 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
658 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
659 6657531f Andreas Kohlbecker
      'type' => MENU_LOCAL_TASK,
660
      'weight' => 6,
661
      'page arguments' => array(2, "keys")
662 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
663
    );
664
665 7cc085da Andreas Kohlbecker
    $items['cdm_dataportal/taxon/%/experts'] = array( // Experts
666 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('Experts'),
667 7663cd0b Andreas Kohlbecker
        'page callback' => 'cdm_dataportal_taxon_page_view',
668 c6fe437b Andreas Kohlbecker
        'access arguments' => array('access cdm content'),
669 7663cd0b Andreas Kohlbecker
        'type' => MENU_LOCAL_TASK,
670
        'weight' => 6,
671
        'page arguments' => array(2, "experts")
672
    , // Expected callback arguments: taxon_uuid.
673 6657531f Andreas Kohlbecker
    );
674 93ae67cc Patrick Plitzner
675 51cc509a Patrick Plitzner
    $items['cdm_dataportal/taxon/autosuggest/%/%/%/'] = array(
676 04a1d647 Patrick Plitzner
        'page callback' => 'cdm_dataportal_taxon_autosuggest',
677 c6fe437b Andreas Kohlbecker
        'access arguments' => array('access cdm content'),
678 51cc509a Patrick Plitzner
        'page arguments' => array(3,4,5),
679 93ae67cc Patrick Plitzner
        'type' => MENU_CALLBACK
680
    );
681 6657531f Andreas Kohlbecker
  }
682
683 6f1a217c Andreas Kohlbecker
  // --- refresh link for all cdmnode types
684
  foreach (cdm_get_nodetypes() as $type=>$name) {
685
    $items['cdm_dataportal/' . $name . '/%/refresh'] = array(
686 7cc085da Andreas Kohlbecker
        'title' => 'Refresh',
687 6f1a217c Andreas Kohlbecker
        'page callback' => 'cdm_dataportal_refresh_node',
688 3113db26 Andreas Kohlbecker
        'access arguments' => array('administer cdm_dataportal'),
689 6f1a217c Andreas Kohlbecker
        'type' => MENU_LOCAL_TASK,
690
        'weight' => 100,
691
        'page arguments' => array($name, 2)
692
    );
693
  }
694
695 6657531f Andreas Kohlbecker
  return $items;
696
}
697
698
/**
699 b85ab055 Andreas Kohlbecker
 * Implements hook_init().
700
 *
701 6657531f Andreas Kohlbecker
 */
702
function cdm_dataportal_init() {
703 8fc089e1 Saskia Gennrich
  if (!path_is_admin(current_path())) {
704
    //FIXME To add CSS or JS that should be present on all pages, modules
705
    //      should not implement this hook, but declare these files in their .info file.
706
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal.css');
707
    // drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
708
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_screen.css', array('type' => 'screen'));
709 63f6d312 Saskia Gennrich
  } else {
710
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_settings.css');
711 8fc089e1 Saskia Gennrich
  }
712 2dd59bb5 Andreas Kohlbecker
713
  if(variable_get('cdm_debug_mode', FALSE)){
714
    $file = 'temporary://drupal_debug.txt';
715
    file_put_contents($file, 'CDM DEBUG LOG for ' . $_GET['q']. "\n"); // will overwrite the file
716
  }
717 5611d467 Andreas Kohlbecker
718
  $bibliography_settings = get_bibliography_settings();
719 57d513cb Andreas Kohlbecker
  $enclosing_tag = $bibliography_settings['enabled'] == 1 ? 'div' : 'span';
720
  FootnoteManager::registerFootnoteSet('BIBLIOGRAPHY', $enclosing_tag, $bibliography_settings['key_format']);
721 6657531f Andreas Kohlbecker
}
722
723 6f1a217c Andreas Kohlbecker
function cdm_dataportal_refresh_node($cdm_node_name, $uuid, $parameters = array()){
724
725
  $base_path = 'cdm_dataportal/' . $cdm_node_name . '/' . $uuid;
726
727
  if($cdm_node_name == 'taxon' && variable_get('cdm_dataportal_taxonpage_tabs', 1)){
728
    // force reloading of all and notify user about this special loading
729
    drupal_set_message(t('The level 2 cache has been cleared for all tabs of this taxon page at once, please click here to return to the tabbed page: ')
730
        . l('Back to tabbed taxon page', $base_path));
731
    $base_path .= '/all';
732
  } else {
733
    drupal_set_message(t('The level 2 cache has been cleared for this page'));
734
  }
735
736
  $parameters['cacheL2_refresh'] ='1';
737
738
739
  drupal_goto($base_path, array('query' => $parameters));
740
}
741
742 102f8c26 Andreas Kohlbecker
/**
743
 * Implements hook_requirements($phase)
744
 */
745
function cdm_dataportal_requirements($phase) {
746
    $requirements = array();
747
    if($phase == 'runtime'){
748
749
    }
750
    return $requirements;
751
}
752
753 6657531f Andreas Kohlbecker
/**
754
 * Implements hook_block_info().
755
 */
756
function cdm_dataportal_block_info() {
757
758
    // $block[0]["info"] = t("CDM DataPortal DevLinks");
759
    // $block[1]["info"] = t("CDM DataPortal Credits");
760 fc13aa30 Andreas Kohlbecker
    $block["2"] = array(
761 beb914ef Andreas Kohlbecker
        "info" => t("CDM - Search Taxa"),
762 fc13aa30 Andreas Kohlbecker
        "cache" => DRUPAL_NO_CACHE
763
      );
764 6657531f Andreas Kohlbecker
    // $block[3]["info"] = t("CDM Filters");
765 beb914ef Andreas Kohlbecker
    $block["4"]["info"] = t("CDM  - Dataportal Print");
766
    $block["keys"]["info"] = t("CDM - Identification keys");
767 46a02272 Andreas Kohlbecker
    $block["fundedByEDIT"]["info"] = t('CDM - Powered by EDIT');
768 f9a3d0f6 Andreas Kohlbecker
    $block["classification_breadcrumbs"] =  array(
769 beb914ef Andreas Kohlbecker
        'info' => t('CDM - Classification breadcrumbs'),
770 f9a3d0f6 Andreas Kohlbecker
        'cache' => DRUPAL_CACHE_PER_PAGE
771
      );
772 bc400a17 Andreas Kohlbecker
    $block["taxonomic_children"] =  array(
773 beb914ef Andreas Kohlbecker
      'info' => t('CDM - Taxonomic children'),
774 bc400a17 Andreas Kohlbecker
      'cache' => DRUPAL_CACHE_PER_PAGE
775
    );
776 beb914ef Andreas Kohlbecker
    $block["back_to_search_results"] =  array(
777
      'title' => '<none>',
778
      'info' => t('CDM - Back to search Results'),
779
      'cache' => DRUPAL_CACHE_PER_PAGE,
780
      'visibility' => BLOCK_VISIBILITY_LISTED,
781
      'pages' => "cdm_dataportal/taxon/*", // multiple page paths separated by "\n"!!!
782
    );
783 a6ae799b Andreas Kohlbecker
  $block['registrations_search_filter'] =  array(
784 b18d70f6 Andreas Kohlbecker
    'title' => 'Filter registrations',
785 a6ae799b Andreas Kohlbecker
    'info' => t('CDM - Registrations search filter'),
786
    'cache' => DRUPAL_CACHE_PER_PAGE,
787 810710a0 Andreas Kohlbecker
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
788 b18d70f6 Andreas Kohlbecker
    'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!!
789 a6ae799b Andreas Kohlbecker
  );
790 efbff4b3 Andreas Kohlbecker
  $block['registrations_search_taxongraph'] =  array(
791
    'title' => 'Taxonomic registration search',
792
    'info' => t('CDM - Registrations search by taxon graph'),
793
    'cache' => DRUPAL_CACHE_PER_PAGE,
794
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
795 b18d70f6 Andreas Kohlbecker
    'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!!
796
  );
797
  $block['registrations_search'] =  array(
798
    'title' => 'Search',
799
    'info' => t('CDM - Registrations search combining filter and taxon graph search' ),
800
    'cache' => DRUPAL_CACHE_PER_PAGE,
801
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
802
    'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!!
803 efbff4b3 Andreas Kohlbecker
  );
804
  return $block;
805 6657531f Andreas Kohlbecker
}
806
807
/**
808
 * Implements hook_block_view().
809
 */
810
function cdm_dataportal_block_view($delta) {
811
  // TODO Rename block deltas (e.g. '2') to readable strings.
812
  switch ($delta) {
813
    // case 'delta-1':
814
    // $block['subject'] = t('Credits');
815
    // $block['content'] = theme('cdm_credits');
816
    // return $block;
817
    case '2':
818
      $block['subject'] = t('Search taxa');
819 191f88fd Andreas Kohlbecker
      $form = drupal_get_form('cdm_dataportal_search_taxon_form');
820
      $block['content'] = drupal_render($form);
821 6657531f Andreas Kohlbecker
822
      if (variable_get('cdm_dataportal_show_advanced_search', 1)) {
823
        $block['content'] .= '<div>' . l(t('Advanced Search'), 'cdm_dataportal/search') . '</div>';
824 6eaec849 Katja Luther
      }
825
      if (variable_get(CDM_BLAST)){
826
          $block['content'] .= '<div>' . l(t('Blast Search'), 'cdm_dataportal/search/blast') . '</div>';
827 6657531f Andreas Kohlbecker
      }
828
      return $block;
829
    case '4':
830 c8234bdf Andreas Kohlbecker
      $block['subject'] = '';
831 6657531f Andreas Kohlbecker
      $block['content'] = theme('cdm_print_button');
832
      return $block;
833
    case "keys":
834
      $block['subject'] = t('Identification Keys');
835
      $block['content'] = theme('cdm_block_IdentificationKeys', array('taxonUuid' => NULL));
836
      return $block;
837
    case "fundedByEDIT":
838
      // t('Funded by EDIT');
839
      $text = '<none>';
840
      $block['subject'] = $text;
841 889c74b7 Andreas Kohlbecker
      $img_tag = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/powered_by_edit.png' . '" alt="' . $text . '"/>';
842
      $block['content'] = l($img_tag, "http://cybertaxonomy.org/", array(
843 6657531f Andreas Kohlbecker
        'attributes' => array("target" => "EDIT"),
844
        'absolute' => TRUE,
845
        'html' => TRUE,
846
      ));
847
      return $block;
848 f9a3d0f6 Andreas Kohlbecker
    case 'classification_breadcrumbs':
849 0af3ce28 Andreas Kohlbecker
      $taxon_uuid = get_current_taxon_uuid();
850 38da4e54 Andreas Kohlbecker
      $block['subject'] = '<none>';
851
      $block['content'] = compose_classification_breadcrumbs($taxon_uuid);
852
      return $block;
853 bc400a17 Andreas Kohlbecker
    case 'taxonomic_children':
854
      $taxon_uuid = get_current_taxon_uuid();
855
      $block['subject'] = '<none>';
856
      $block['content'] = compose_taxonomic_children($taxon_uuid);
857
      return $block;
858 beb914ef Andreas Kohlbecker
    case 'back_to_search_results':
859
      $block['subject'] = '<none>';
860
      if (isset($_SESSION['cdm']['search'])) {
861
        $block['content'] = l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search']);
862
      }
863
      return $block;
864 a6ae799b Andreas Kohlbecker
    case 'registrations_search_filter':
865
      $block['subject'] = '<none>';
866 efbff4b3 Andreas Kohlbecker
      $block['content'] = drupal_get_form('cdm_dataportal_search_registration_filter_form'); // see cdm_dataportal_search_registration_filter_form($form, &$form_state)
867
      return $block;
868
    case 'registrations_search_taxongraph':
869
      $block['subject'] = '<none>';
870
      $block['content'] = drupal_get_form('cdm_dataportal_search_registration_taxongraph_form'); // see cdm_dataportal_search_registration_taxongraph_form($form, &$form_state)
871 a6ae799b Andreas Kohlbecker
      return $block;
872 b18d70f6 Andreas Kohlbecker
    case 'registrations_search':
873
      _add_js_ui_accordion();
874
      _add_font_awesome_font();
875
      $block['subject'] = '<none>';
876
      $filter_form = drupal_get_form('cdm_dataportal_search_registration_filter_form');
877
      $filter_form['#prefix'] = '<div>';
878
      $filter_form['#suffix'] = '</div>';
879
      $taxongraph_form = drupal_get_form('cdm_dataportal_search_registration_taxongraph_form');
880
      $taxongraph_form['#prefix'] = '<div>';
881
      $taxongraph_form['#suffix'] = '</div>';
882
      $block['content'] = array(
883
        'accordion' => array(
884
          '#markup' => '',
885
          '#prefix' => '<div id="accordion">',
886
          '#suffix' => '</div>',
887
          'content' => array(
888
            array('#markup' => '<h3>Filter</h3>'),
889
            $filter_form,
890
            array('#markup' => '<h3>Taxon graph</h3>'),
891
            $taxongraph_form,
892
          )
893
        )
894
    );
895
       return $block;
896 beb914ef Andreas Kohlbecker
    default:
897
      return null;
898 6657531f Andreas Kohlbecker
  }
899
}
900
901 0af3ce28 Andreas Kohlbecker
/**
902
 * Provides the uuid of the taxon for pages with the path ./taxon/{taxon_uuid}
903
 *
904
 * @return string
905
 *   the taxon uuid or NULL
906
 */
907
function get_current_taxon_uuid()
908
{
909
  static $taxon_uuid;
910
911
  if(!isset($taxon_uuid)){
912
    if(isset($_REQUEST['currentTaxon']) && is_uuid($_REQUEST['currentTaxon'])) {
913
      $taxon_uuid = $_REQUEST['currentTaxon'];
914
    } else if (arg(1) == 'taxon' && is_uuid(arg(2))) {
915
      $taxon_uuid = arg(2);
916
    } else {
917
      $taxon_uuid = null;
918
    }
919
  }
920
921
  return $taxon_uuid;
922
}
923
924
/**
925
 * Returns the currently classification tree in use.
926
 *
927
 * @return string
928
 *   The uuid of the currently focused classification
929
 */
930
function get_current_classification_uuid() {
931
  if (isset($_SESSION['cdm']['taxonomictree_uuid']) && is_uuid($_SESSION['cdm']['taxonomictree_uuid'])) {
932
    return $_SESSION['cdm']['taxonomictree_uuid'];
933
  }
934
  else {
935
    return variable_get(CDM_TAXONOMICTREE_UUID, FALSE);
936
  }
937
}
938
939 6657531f Andreas Kohlbecker
/*
940
 function cdm_dataportal_session_clear($cdm_ws_uri_update = FALSE){
941
 $_SESSION['cdm'] = NULL;
942
 if(is_string($cdm_ws_uri_update)){
943
 $_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
944
 }
945
 }
946
947
 function cdm_dataportal_session_validate(){
948
 if(!isset($_SESSION['cdm']['ws_uri'])){
949
 $_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', FALSE));
950
 } else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', FALSE)){
951
 cdm_dataportal_session_clear(variable_get('cdm_webservice_url', FALSE));
952
 }
953
 }
954
 */
955
956
/**
957 d7588d36 Andreas Kohlbecker
 * creates a  selector form for taxonomic trees.
958
 *
959 0af3ce28 Andreas Kohlbecker
 * @return array
960
 *  a drupal form array
961 6657531f Andreas Kohlbecker
 */
962
function cdm_taxonomictree_selector() {
963
  _add_js_treeselector();
964
965 a8a8f23c Andreas Kohlbecker
  $form = drupal_get_form('cdm_taxonomictree_selector_form');
966 d7588d36 Andreas Kohlbecker
  return $form;
967 6657531f Andreas Kohlbecker
}
968
969
/**
970
 * @todo Please document this function.
971
 * @see http://drupal.org/node/1354
972 0af3ce28 Andreas Kohlbecker
 *
973
 * @deprecated use compose_classification_selector instead
974 6657531f Andreas Kohlbecker
 */
975
function cdm_taxonomictree_selector_form($form, &$form_state) {
976
977
  $url = url('cdm_api/setvalue/session', array('query' => NULL));
978
  $form['#action'] = $url;
979
980
  $form['var'] = array(
981
    '#weight' => -3,
982
    '#type' => 'hidden',
983
    '#value' => '[cdm][taxonomictree_uuid]',
984
  );
985
986
  $destination_array = drupal_get_destination();
987
  $destination = $destination_array['destination'];
988
989
  $form['destination'] = array(
990
    '#weight' => -3,
991
    '#type' => 'hidden',
992
    '#value' =>  $destination,
993
  );
994
995 26fb3778 Andreas Kohlbecker
  $options = cdm_get_taxontrees_as_options();
996
  $taxontree_includes = variable_get(CDM_TAXONTREE_INCLUDES, null);
997
  if($taxontree_includes){
998
    $filtered_options = array();
999
    foreach($options as $uuid=>$label){
1000
      if(!empty($taxontree_includes[$uuid])){
1001
        $filtered_options[$uuid] = $label;
1002
      }
1003
    }
1004
    $options = $filtered_options;
1005
  }
1006
1007 6657531f Andreas Kohlbecker
  $form['val'] = array(
1008
    '#type' => 'select',
1009
    '#title' => t('Available classifications'),
1010 7663cd0b Andreas Kohlbecker
    '#default_value' => get_current_classification_uuid(),
1011 26fb3778 Andreas Kohlbecker
    '#options' => $options,
1012 0af3ce28 Andreas Kohlbecker
    '#attributes' => array('class' => array('highlite-first-child')),
1013 6657531f Andreas Kohlbecker
  );
1014
1015
  return $form;
1016
1017
}
1018
1019 0af3ce28 Andreas Kohlbecker
/**
1020
 *
1021
 * @ingroup compose
1022
 */
1023
function compose_classification_selector() {
1024
1025
  $destination_array = drupal_get_destination();
1026
  $destination = $destination_array['destination'];
1027
1028
  $options = cdm_get_taxontrees_as_options();
1029
  $items = array();
1030
  $taxontree_includes = variable_get(CDM_TAXONTREE_INCLUDES, null);
1031
1032
  $current_classification_uuid = get_current_classification_uuid();
1033
1034
1035
  foreach($options as $uuid=>$label){
1036
    if(!$taxontree_includes || !empty($taxontree_includes[$uuid])){
1037
1038
      $class_attributes = '';
1039
      if($current_classification_uuid == $uuid){
1040
        $class_attributes  = array('focused');
1041
      }
1042
      $items[] = array(
1043
        'data' => l($label,
1044
          'cdm_api/setvalue/session',
1045
          array(
1046
            'query' => array(
1047
              'destination' => $destination,
1048
              'val' => $uuid,
1049
              'var' => '[cdm][taxonomictree_uuid]'
1050
            ),
1051
          )
1052
        ),
1053
        'class' => $class_attributes
1054
      );
1055
    }
1056
  }
1057
1058
  $render_array = array(
1059
    '#theme' => 'item_list',
1060
    '#type' => 'ul',
1061
    '#items' => $items
1062
  );
1063
1064
  return $render_array;
1065
}
1066
1067
1068 6657531f Andreas Kohlbecker
/* UNREACHABLE since action of form directly links to view.
1069
 function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
1070
1071
 $_SESSION['cdm']['search'] = $form_values;
1072
 //return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
1073
 return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
1074
 //$paramstr = compose_url_prameterstr($form_values);
1075
 //return url('/cdm_dataportal/search/taxon/', array('query' => $paramstr));
1076
 }
1077
 */
1078
/* ====================== menu callback functions ====================== */
1079
/**
1080
 * @todo Please document this function.
1081
 * @see http://drupal.org/node/1354
1082
 */
1083
/*
1084
function cdm_dataportal_form_alter(&$form, &$form_state, $form_id) {
1085
  static $comment_node_disabled =  0;
1086
  static $comment_node_read_only =  1;
1087
  static $comment_node_read_write =  2;
1088
1089
  if ($form_id == 'node_type_form'
1090
   && isset($form['identity']['type'])
1091
   && array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
1092
  ) {
1093
    $form['workflow']['comment'] = array(
1094
      '#type' => 'radios',
1095
      '#title' => t('Default comment setting'),
1096
      '#default_value' => variable_get('comment__' . $node->type . $form['#node_type']->type, $comment_node_disabled),
1097
      '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
1098
      '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
1099
    );
1100
  }
1101
}
1102
*/
1103
1104
/**
1105
 * Displays a list of the known taxonomic names.
1106
 *
1107
 * When the list of taxonomic names is displayed, long lists are split up into
1108
 * multiple pages.
1109
 *
1110
 * TODO: Parameters are still preliminary.
1111
 *
1112
 * @param string $beginsWith
1113
 * @param string $page
1114
 *   Page number to diplay defaults to page 1.
1115
 * @param bool $onlyAccepted
1116
 */
1117
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = FALSE) {
1118
1119
  $out = t('<h3>Sorry, the name list feature is not yet available in this version of the DataPortal software<h3>');
1120
1121
  /*
1122
  // FIXME the filter for accepted names will be a form element, thus this
1123
  // widget should be generated via form api preferably as block.
1124
  $out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
1125
  $out .= theme('cdm_dataportal_widget_names_list', $names, $page);
1126
  $out .= theme('cdm_listof_taxa', $taxonPager);
1127
  return $out;
1128
  */
1129
}
1130
1131
/**
1132
 * @todo Please document this function.
1133
 * @see http://drupal.org/node/1354
1134 c0223d83 Andreas Kohlbecker
 * @throws Exception
1135 6657531f Andreas Kohlbecker
 */
1136
function cdm_dataportal_view_reference($uuid, $arg2 = NULL) {
1137 f26245c8 Andreas Kohlbecker
1138
  cdm_check_valid_portal_page();
1139
1140 6cbefddc Andreas Kohlbecker
  return compose_cdm_reference_page($uuid);
1141 6657531f Andreas Kohlbecker
}
1142
1143
/**
1144 b2ebf0d3 Andreas Kohlbecker
 * Creates a view on a all references contained in the portal.
1145 b5dca1e2 Andreas Kohlbecker
 *
1146
 * This function is used at the path cdm_dataportal/reference/list
1147 6657531f Andreas Kohlbecker
 */
1148
function cdm_dataportal_view_reference_list($pageNumber) {
1149
  $referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
1150 b2ebf0d3 Andreas Kohlbecker
  cdm_reference_pager($referencePager, 'cdm_dataportal/reference/list/');
1151 6657531f Andreas Kohlbecker
}
1152
1153
/**
1154
 * @todo Please document this function.
1155
 * @see http://drupal.org/node/1354
1156
 */
1157
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = FALSE, $part = 0) {
1158 f26245c8 Andreas Kohlbecker
1159
  cdm_check_valid_portal_page();
1160
1161 6657531f Andreas Kohlbecker
  $media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
1162
  return theme('cdm_media_page', array(
1163
    'media' => $media,
1164
    'mediarepresentation_uuid' => $mediarepresentation_uuid,
1165
    'partId' => $part,
1166
    ));
1167
}
1168
1169
/**
1170
 * @todo Please document this function.
1171
 * @see http://drupal.org/node/1354
1172
 */
1173
function _load_taxonBase(&$taxonBase) {
1174
  if (isset($taxonBase->uuid)) {
1175
    $taxonBase->name = cdm_ws_get(CDM_WS_TAXON, array($taxonBase->uuid, "name"));
1176
    $taxonBase->name->taggedName = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "taggedName"));
1177
    $taxonBase->name->nomenclaturalReference = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "nomenclaturalReference"));
1178
  }
1179
}
1180
1181 9438ad3a Andreas Kohlbecker
/**
1182
 * Loads the media associated to the given taxon from the cdm server.
1183
 * The aggregation settings regarding taxon relathionships and
1184
 * taxonnomic childen are taken into account.
1185
 *
1186
 * The media lists are cached in a static variable.
1187
 *
1188
 * @param Taxon $taxon
1189
 *   A CDM Taxon entitiy
1190
 *
1191
 * @return array
1192
 *   An array of CDM Media entities
1193
 *
1194
 */
1195
function _load_media_for_taxon($taxon) {
1196
1197
  static $media = NULL;
1198
1199
  if(!isset($media)) {
1200
    $media = array();
1201
  }
1202
  if (!isset($media[$taxon->uuid])) {
1203
1204 f19f47fa Andreas Kohlbecker
    // --- GET Images --- //
1205
    $mediaQueryParameters = array(
1206
        "type" => "ImageFile",
1207
    );
1208
1209
    $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1210
    $mediaQueryParameters['relationships'] = implode(',', get_selection($relationship_choice['direct']));
1211 a950f2f9 Andreas Kohlbecker
    $mediaQueryParameters['relationshipsInvers'] = implode(',', get_selection($relationship_choice['invers']));
1212
1213
    $taxon_media_filter_choice = variable_get(CDM_TAXON_MEDIA_FILTER, unserialize(CDM_TAXON_MEDIA_FILTER_DEFAULT));
1214
    $mediaQueryParameters['includeTaxonDescriptions'] = (boolean) $taxon_media_filter_choice['includeTaxonDescriptions'] != 0;
1215
    $mediaQueryParameters['includeOccurrences'] = (boolean) $taxon_media_filter_choice['includeOccurrences'] != 0;
1216
    $mediaQueryParameters['includeTaxonNameDescriptions'] = (boolean) $taxon_media_filter_choice['includeTaxonNameDescriptions'] != 0;
1217 9438ad3a Andreas Kohlbecker
1218 f19f47fa Andreas Kohlbecker
    $ws_endpoint = NULL;
1219 9438ad3a Andreas Kohlbecker
    if ( variable_get('cdm_images_include_children', 0) == 0) {
1220
      $ws_endpoint = CDM_WS_PORTAL_TAXON_MEDIA;
1221
    } else {
1222
      $ws_endpoint = CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA;
1223
    }
1224 f19f47fa Andreas Kohlbecker
1225
    $media[$taxon->uuid] = cdm_ws_get($ws_endpoint,
1226
        array(
1227
            $taxon->uuid,
1228
        ),
1229 9438ad3a Andreas Kohlbecker
        queryString($mediaQueryParameters)
1230
       );
1231
  }
1232
1233
  return $media[$taxon->uuid];
1234
}
1235
1236
/**
1237
 *
1238
 * @param Taxon $taxon
1239
 *   A CDM Taxon entitiy
1240
 *
1241
 * @return array
1242
 *   An array of CDM SpecimenOrObservation entities
1243
 *
1244
function _load_occurences_for_taxon($taxon){
1245
1246
  static $occurences = NULL;
1247 f19f47fa Andreas Kohlbecker
1248
  if(!isset($occurences)) {
1249
    $occurences = array();
1250
  }
1251 9438ad3a Andreas Kohlbecker
1252
  if (!isset($occurences[$taxon->uuid])){
1253
1254
    $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1255
    $relationship_choice['direct'] = get_selection($relationship_choice['direct']);
1256 f19f47fa Andreas Kohlbecker
    $relationship_choice['invers'] = get_selection($relationship_choice['invers']);
1257
1258
    $by_associatedtaxon_query = http_build_query(array(
1259
        'relationshipsInvers' => implode(',', $relationship_choice['invers']),
1260
        'relationships' => implode(',', $relationship_choice['direct']),
1261
        'pageSize' => null // all hits in one page
1262
    )
1263
    );
1264
1265
    $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
1266
        null,
1267
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
1268
    );
1269
1270
1271
    if(isset($pager->records[0])){
1272
      $occurences[$taxon->uuid] =  $pager->records;
1273
    }
1274
  }
1275 9438ad3a Andreas Kohlbecker
  return $occurences[$taxon->uuid];
1276
}
1277
 */
1278
1279 6657531f Andreas Kohlbecker
/**
1280
 * Gets a Drupal variable, string or array and returns it.
1281
 *
1282
 * Similar to the variable_get() function of Drupal, except that this function
1283
 * is able to handle arrays correctly. This function is especially useful
1284 8c962983 Andreas Kohlbecker
 * when dealing with collections of settings form elements (#tree = TRUE).
1285 6657531f Andreas Kohlbecker
 *
1286
 * @param string $variableKey
1287
 *   The Unique key of the Drupal variable in the Drupal variables table.
1288
 * @param string $defaultValueString
1289
 *   A string as for example derived from a CONSTANT.
1290
 *
1291
 * @return mixed
1292 8c962983 Andreas Kohlbecker
 *   usually an array, depending on the nature of the variable.
1293
 *
1294
 * TODO compare with get_array_variable_merged() duplicate functions?
1295 0f7c9d15 Andreas Kohlbecker
 * @deprecated rather use get_array_variable_merged() since this function
1296
 * used an array as second parameter
1297 6657531f Andreas Kohlbecker
 */
1298
function mixed_variable_get($variableKey, $defaultValueString) {
1299
  $systemDefaults = unserialize($defaultValueString);
1300
  $storedSettings = variable_get($variableKey, array());
1301
  if (is_array($storedSettings)) {
1302 8c962983 Andreas Kohlbecker
    // TODO better use drupal_array_merge_deep() ?
1303 6657531f Andreas Kohlbecker
    $settings = array_merge($systemDefaults, $storedSettings);
1304
  }
1305
  else {
1306
    $settings = $systemDefaults;
1307
  }
1308
  return $settings;
1309
}
1310
1311 b5519d3a Andreas Kohlbecker
/**
1312 0f7c9d15 Andreas Kohlbecker
 * Recursive function to convert an object into an array.
1313 b5519d3a Andreas Kohlbecker
 * also subordinate objects will be converted.
1314
 *
1315
 * @param object $object
1316 db725031 Andreas Kohlbecker
 *  the object to be converted
1317
 * @return array
1318
 *  The array
1319 b5519d3a Andreas Kohlbecker
 */
1320 db725031 Andreas Kohlbecker
function object_to_array($object) {
1321 b5519d3a Andreas Kohlbecker
  if(is_object($object) || is_array($object)) {
1322
    $array = (array)$object;
1323
    foreach ($array as $key=>$value){
1324 db725031 Andreas Kohlbecker
      $array[$key] = object_to_array($value);
1325 b5519d3a Andreas Kohlbecker
    }
1326
    return $array;
1327
  } else {
1328
    return $object;
1329
  }
1330
}
1331
1332 2fd6da0b Andreas Kohlbecker
/**
1333
 * Searches the $collection for the cdm entitiy given as $element.
1334
 *
1335
 * The elements are compared by their UUID.
1336
 *
1337
 * @param $element
1338
 *  the CDM entitiy to search for
1339
 * @param $collection
1340
 *  the list of CDM entities to search in
1341
 *
1342
 * @return boolean TRUE if the $collection contains the $element, otheriwse FALSE
1343
 *
1344
 */
1345
function contains_cdm_entitiy($element, $collection) {
1346
  $result = FALSE;
1347
  foreach ($collection as $a) {
1348
    if ($a->uuid == $element->uuid) {
1349
      $result = TRUE;
1350
    }
1351
  }
1352
  return $result;
1353
}
1354
1355
/**
1356
 * Fiters the array $entity_list of CDM entities by the list
1357
 * of $excludes. Any element contained in the $excludes will be removed
1358
 * from included int the retuned list.
1359
 *
1360
 * If the $entity_list is not an array the $excludes will be returned.
1361
 */
1362
function filter_cdm_entity_list($entity_list, $excludes) {
1363
  if (is_array($entity_list)) {
1364
    $result = $entity_list;
1365
    if ($excludes) {
1366
      foreach ($excludes as $exclude) {
1367
        if (!contains_cdm_entitiy($exclude, $entity_list)) {
1368
          $result[] = $exclude;
1369
        }
1370
      }
1371
    }
1372
  }
1373
  else {
1374
    $result = $excludes;
1375
  }
1376
  return $result;
1377
}
1378
1379 0a1151a4 Andreas Kohlbecker
/**
1380 6f5c7f2a Andreas Kohlbecker
 * Wraps the given $html string into a render array suitable for drupal_render()
1381 0a1151a4 Andreas Kohlbecker
 *
1382 65345976 Andreas Kohlbecker
 * @param $html
1383 0a1151a4 Andreas Kohlbecker
 *   the html string, see
1384
 *   http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#markup
1385 65345976 Andreas Kohlbecker
 * @param $weight
1386 0a1151a4 Andreas Kohlbecker
 *   A positive or negative number (integer or decimal).
1387
 *   see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#weightval
1388 65345976 Andreas Kohlbecker
 * @param $prefix
1389
 *   Optional markup for the '#prefix' element of the render array
1390
 * @param $suffix
1391
 *   Optional markup for the '#suffix' element of the render array
1392 0a1151a4 Andreas Kohlbecker
 *
1393 65345976 Andreas Kohlbecker
 * @return array
1394 0a1151a4 Andreas Kohlbecker
 *   A render array
1395
 *
1396
 */
1397 65345976 Andreas Kohlbecker
function markup_to_render_array($html, $weight = FALSE, $prefix = NULL, $suffix = NULL) {
1398 6f5c7f2a Andreas Kohlbecker
  $render_array = array(
1399
    '#markup' => $html
1400 1ce9afb7 Patric Plitzner
      );
1401 6f5c7f2a Andreas Kohlbecker
  if (is_numeric($weight)) {
1402
    $render_array['#weight'] = $weight;
1403 65345976 Andreas Kohlbecker
  }
1404
  if($prefix){
1405
    $render_array['#prefix'] = $prefix;
1406
  }
1407
  if($suffix) {
1408
    $render_array['#suffix'] = $suffix;
1409
  }
1410 6f5c7f2a Andreas Kohlbecker
  return $render_array;
1411 0a1151a4 Andreas Kohlbecker
}
1412
1413 6657531f Andreas Kohlbecker
/**
1414
 * Loads the subgraph of a given PolytomousKeyNode.
1415
 *
1416
 * Loads the subgraph of the given PolytomousKeyNode recursively from
1417
 * the CDM REST service.
1418
 *
1419
 * @param mixed $polytomousKeyNode
1420
 *   PolytomousKeyNode passed by reference.
1421
 *
1422
 * @return void
1423
 */
1424
function _load_polytomousKeySubGraph(&$polytomousKeyNode) {
1425
1426
  if (!$polytomousKeyNode) {
1427
    return;
1428
  }
1429
  if ($polytomousKeyNode->class != "PolytomousKeyNode") {
1430 f19f47fa Andreas Kohlbecker
    drupal_set_message('_load_polytomousKeySubGraph(): ' . t('invalid type given.'), 'error');
1431 6657531f Andreas Kohlbecker
    return;
1432
  }
1433
  if (!is_uuid($polytomousKeyNode->uuid)) {
1434 f19f47fa Andreas Kohlbecker
    drupal_set_message('_load_polytomousKeySubGraph(): ' . t('invalid type given.'), 'error');
1435 6657531f Andreas Kohlbecker
    return;
1436
  }
1437
1438
  $polytomousKeyNode = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid);
1439
1440
  if (!$polytomousKeyNode) {
1441
    // drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error");
1442
    return;
1443
  }
1444
1445
  // Load children.
1446
  foreach ($polytomousKeyNode->children as &$childNode) {
1447
    _load_polytomousKeySubGraph($childNode);
1448
  }
1449
1450
  // Load subkey.
1451
  $polytomousKeyNode->subkey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "subkey"));
1452
1453
  // Load taxon.
1454
  $polytomousKeyNode->taxon = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "taxon"));
1455
  _load_taxonBase($polytomousKeyNode->taxon);
1456
  return;
1457
}
1458
1459
/**
1460
 * @todo Please document this function.
1461
 * @see http://drupal.org/node/1354
1462
 */
1463
function cdm_dataportal_view_polytomousKey($polytomousKeyUuid) {
1464 f26245c8 Andreas Kohlbecker
1465
  cdm_check_valid_portal_page();
1466
1467 6657531f Andreas Kohlbecker
  $polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid);
1468
1469
  $sourcePager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources'));
1470
  if (is_array($sourcePager->records)) {
1471
    $polytomousKey->sources = $sourcePager->records;
1472
    // $polytomousKey->sources->citation = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources'));
1473
  }
1474
1475
  $annotationPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'annotations'));
1476
  if (is_array($annotationPager->records)) {
1477
    $polytomousKey->annotations = $annotationPager->records;
1478
  }
1479
1480
  _load_polytomousKeySubGraph($polytomousKey->root);
1481
  return theme('cdm_polytomousKey_page', array('polytomousKey' => $polytomousKey));
1482
}
1483
1484
/**
1485
 * Creates a taxon page view or a chapter of it.
1486
 *
1487
 * The taxon page gives detailed information on a taxon, it shows:
1488
 *  - Taxon name.
1489
 *  - Full list of synonyms homotypic synonyms on top, followed by the
1490
 *    heterotypic and finally followed by misapplied names.
1491
 *    The list is ordered historically.
1492
 *  - All description associated with the taxon.
1493
 *
1494
 * @param string $uuid
1495
 * @param string $chapter
1496
 *   Name of the part to display, valid values are:
1497
 *   'description', 'images', 'synonymy', 'specimens', 'all'.
1498
 *
1499 793dae0a Andreas Kohlbecker
 * @return string
1500 6657531f Andreas Kohlbecker
 */
1501 0c5a23b6 Andreas Kohlbecker
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all') {
1502 5ea8b301 Andreas Kohlbecker
1503 f26245c8 Andreas Kohlbecker
  cdm_check_valid_taxon_page($chapter);
1504 2dd59bb5 Andreas Kohlbecker
  cdm_dd("START OF TAXON PAGE [" . $chapter . "] " . $uuid . ' for ' . $_GET['q']);
1505 5ea8b301 Andreas Kohlbecker
  // show a warning in case the javascript development mode is anabled
1506
  if(variable_get('cdm_js_devel_mode', FALSE)) {
1507
    drupal_set_message(t('The !url1 is enabled.
1508
        WARNING: this is a performance penalty and must be turned off on production websites.', array(
1509
          '!url1' => l('java-script development mode', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-cdm-js-devel-mode'))
1510
    )),
1511
    'warning'
1512
        );
1513
  }
1514
1515 6657531f Andreas Kohlbecker
  // Display the page for the taxon defined by $uuid.
1516
  // set_last_taxon_page_tab(arg(3));
1517 0c5a23b6 Andreas Kohlbecker
  $taxonpage = cdm_dataportal_taxon_view($uuid, $chapter);
1518 6657531f Andreas Kohlbecker
  if (!empty($taxonpage)) {
1519 2dd59bb5 Andreas Kohlbecker
    cdm_dd("END OF TAXON PAGE [" . $chapter . "] " . $uuid);
1520 6657531f Andreas Kohlbecker
    return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title, $taxonpage->content);
1521
  }
1522
  else {
1523 2dd59bb5 Andreas Kohlbecker
    cdm_dd("END OF TAXON PAGE [" . $chapter . "] " . $uuid . ' !!! PAGE IS EMPTY !!!');
1524 6657531f Andreas Kohlbecker
    return '';
1525
  }
1526
}
1527
1528
/**
1529 59f6da42 Andreas Kohlbecker
 * This function will genreate the taxon page part ($chapter) and returns a taxonpage object
1530
 * which has two fields, one for the page title and one for the content. Later on in the
1531
 * process chain the value contained in these fields will be passed to the cdm_node_show()
1532
 * function as the function parameters $title and $content.
1533 6657531f Andreas Kohlbecker
 *
1534
 * @param string $uuid
1535 59f6da42 Andreas Kohlbecker
 *   the uuid of the taxon to show
1536 6657531f Andreas Kohlbecker
 * @param string $chapter
1537
 *   Name of the part to display, valid values are:
1538
 *   'description', 'images', 'synonymy', 'all'.
1539
 *
1540 0c5a23b6 Andreas Kohlbecker
 * @return object with the following fields:
1541 59f6da42 Andreas Kohlbecker
 *   - title : the title of the page
1542
 *   - content: the content of the page
1543
 *
1544 8a1b451e Andreas Kohlbecker
 * @throws Exception
1545
 *
1546 6657531f Andreas Kohlbecker
 */
1547 8cf9238f Andreas Kohlbecker
function cdm_dataportal_taxon_view($uuid, $chapter = 'all') {
1548 6657531f Andreas Kohlbecker
  // Taxon object.
1549
  $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1550
  if (empty($taxon)) {
1551
    drupal_set_title(t('Taxon does not exist'), PASS_THROUGH);
1552 8a1b451e Andreas Kohlbecker
    return null;
1553 6657531f Andreas Kohlbecker
  }
1554
  $taxonpage = new stdClass();
1555
1556
  $taxonpage->title = theme('cdm_taxon_page_title', array(
1557 8cf9238f Andreas Kohlbecker
    'taxon' => $taxon
1558 6657531f Andreas Kohlbecker
  ));
1559
1560
  // Check if the taxon id contained in the currently selected tree.
1561 7663cd0b Andreas Kohlbecker
  $taxon_in_current_classification = taxon_in_current_classification($uuid);
1562 61b6ee11 Andreas Kohlbecker
1563 7663cd0b Andreas Kohlbecker
  if (!$taxon_in_current_classification) {
1564 61b6ee11 Andreas Kohlbecker
    $classifications = get_classifications_for_taxon($taxon);
1565 e24d373b Andreas Kohlbecker
    RenderHints::pushToRenderStack('not_in_current_classification');
1566
    $taxon_name_markup = render_taxon_or_name($taxon);
1567
1568 61b6ee11 Andreas Kohlbecker
    if (count($classifications) == 0) {
1569 e24d373b Andreas Kohlbecker
      drupal_set_message(t('This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification.',
1570 fba00a4f Andreas Kohlbecker
        array(
1571 e24d373b Andreas Kohlbecker
        '!taxonname' => $taxon_name_markup,
1572 fba00a4f Andreas Kohlbecker
        )
1573
      ), 'warning');
1574 6657531f Andreas Kohlbecker
    }
1575
    else {
1576
      $trees = '';
1577 61b6ee11 Andreas Kohlbecker
      foreach ($classifications as $classification) {
1578
        if (isset($classification->titleCache)) {
1579
          $trees .= ($trees ? ', ' : '') . '<strong>' . $classification->titleCache . '</strong>';
1580 6657531f Andreas Kohlbecker
        }
1581
      }
1582
1583 15b7c460 Andreas Kohlbecker
      drupal_set_message(format_plural(count($trees),
1584 e24d373b Andreas Kohlbecker
          'This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification, but in this one: !trees',
1585
          'This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification, but in one of these: !trees',
1586
          array('!taxonname' => $taxon_name_markup, '!trees' => $trees)
1587 fba00a4f Andreas Kohlbecker
        ) ,
1588
        'warning');
1589 6657531f Andreas Kohlbecker
    }
1590 e24d373b Andreas Kohlbecker
    RenderHints::popFromRenderStack();
1591 6657531f Andreas Kohlbecker
  }
1592
1593
  // Render the taxon page.
1594 9a607f17 Andreas Kohlbecker
  $render_array = compose_cdm_taxon_page($taxon, $chapter);
1595
  $taxonpage->content = drupal_render($render_array);
1596 6657531f Andreas Kohlbecker
1597
  return $taxonpage;
1598
}
1599 6eaec849 Katja Luther
function cdm_dataportal_specimen_by_accession_number_page_view($accession_number)
1600
{
1601
    if (isset($accession_number)) {
1602
        $specimen_or_observation = cdm_ws_get(CDM_WS_OCCURRENCE_ACCESSION_NUMBER, null, 'accessionNumber=' . $accession_number);
1603
1604
        if (isset($specimen_or_observation) && $specimen_or_observation){
1605
            cdm_dataportal_specimen_page_view($specimen_or_observation->uuid, $specimen_or_observation);
1606
        }
1607 6657531f Andreas Kohlbecker
1608 6eaec849 Katja Luther
    }
1609
}
1610 9d37c9d9 Patric Plitzner
/**
1611
 * Creates a specimen page view.
1612
 * @param string $uuid the UUID of the specimen
1613
 * @return array|string
1614
 */
1615
function cdm_dataportal_specimen_page_view($uuid) {
1616
1617
    //cdm_check_valid_taxon_page($chapter);
1618
    //cdm_dd("START OF TAXON PAGE [" . $chapter . "] " . $uuid . ' for ' . $_GET['q']);
1619
    // show a warning in case the javascript development mode is anabled
1620
    if(variable_get('cdm_js_devel_mode', FALSE)) {
1621
        drupal_set_message(t('The !url1 is enabled.
1622
        WARNING: this is a performance penalty and must be turned off on production websites.', array(
1623
            '!url1' => l('java-script development mode', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-cdm-js-devel-mode'))
1624
        )),
1625
            'warning'
1626
        );
1627
    }
1628
1629
    // Display the page for the specimen defined by $uuid.
1630
    $specimenpage = cdm_dataportal_specimen_view($uuid);
1631
    if (!empty($specimenpage)) {
1632
        return cdm_node_show(NODETYPE_TAXON, $uuid, $specimenpage->title, $specimenpage->content);
1633
    }
1634
    else {
1635
        return '';
1636
    }
1637
}
1638
1639
/**
1640
 *
1641
 * Creates a specimen view.
1642
 * @param string $uuid the UUID of the specimen
1643
 * @return array|string
1644
 */
1645
function cdm_dataportal_specimen_view($uuid) {
1646 a2acff0a Katja Luther
    //TODO: get the derivateDTO and don't call the webservice a second time in compose_cdm_specimen_page
1647 907cc9b4 Patrick Plitzner
    $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, $uuid);
1648 9d37c9d9 Patric Plitzner
    if (empty($specimen)) {
1649
        drupal_set_title(t('Specimen does not exist'), PASS_THROUGH);
1650
        return FALSE;
1651
    }
1652
    $specimenpage = new stdClass();
1653
1654
    $specimenpage->title = theme('cdm_specimen_page_title', array(
1655
        'specimen' => $specimen
1656
    ));
1657
1658 b810158e Patric Plitzner
    // Render the specimen page.
1659 a2acff0a Katja Luther
    $render_array = compose_cdm_specimen_page($specimen);
1660 9d37c9d9 Patric Plitzner
    $specimenpage->content = drupal_render($render_array);
1661
1662
    return $specimenpage;
1663
}
1664
1665 30845bda Andreas Kohlbecker
/**
1666
 *
1667
 * Creates a named area view.
1668
 * @param string $uuid the UUID of the specimen
1669
 *  * @return object
1670
 *   An object with two fields:
1671
 *     - title: the page title
1672
 *     - content: the page content
1673
 */
1674
1675
function cdm_dataportal_named_area_view($uuid) {
1676
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, $uuid);
1677
  if (empty($named_area) || $named_area->class !== 'NamedArea') {
1678
    drupal_set_title(t('Named area does not exist'), PASS_THROUGH);
1679
    return FALSE;
1680
  }
1681
  $named_area_page = new stdClass();
1682
1683
  $named_area_page->title = $named_area->representation_L10n;
1684
1685
  // Render the specimen page.
1686
  $render_array = compose_cdm_named_area_page($uuid);
1687
  $named_area_page->content = drupal_render($render_array);
1688
1689
  return $named_area_page;
1690
}
1691
1692
function cdm_dataportal_named_area_page_view($uuid) {
1693
1694
  cdm_check_valid_portal_page();
1695
1696
  $named_area_page = cdm_dataportal_named_area_view($uuid);
1697
  if (!empty($named_area_page)) {
1698
    return cdm_node_show(NODETYPE_NAME, $uuid, $named_area_page->title, $named_area_page->content);
1699
  }
1700
  else {
1701
    return '';
1702
  }
1703
1704
1705
}
1706
1707 6657531f Andreas Kohlbecker
/**
1708
 * Returns a name page as a Drupal node ready to be renderized by Drupal.
1709
 *
1710
 * The node page shows the taxon name title and the list of taxon related
1711
 * with such taxon. Name on the tree already in use.
1712
 *
1713 d4ea0dd9 Andreas Kohlbecker
 * @param string $taxon_name_uuid
1714 102f8c26 Andreas Kohlbecker
 *   The uuid of the CDM TaxonName to show a name page for
1715 d4ea0dd9 Andreas Kohlbecker
 * @param string $taxon_to_hide_uuid
1716 51b04faf Andreas Kohlbecker
 *   A taxon which should not be displayed in the taxon list
1717 d4ea0dd9 Andreas Kohlbecker
 * @param string $highlite_synonym_uuid
1718 51b04faf Andreas Kohlbecker
 *   Optinal parameter wich takes another taxon uuid, if given the
1719
 *   target taxon pages will show the syonymy tab where the taxon
1720
 *   refenrenced by the $highlite_synonym_uuid will be highlighted
1721
 *   in case it is found on this page.
1722 6657531f Andreas Kohlbecker
 *
1723
 * @return mixed
1724
 *   The formatted name page as node.
1725
 */
1726
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = NULL) {
1727
1728 f26245c8 Andreas Kohlbecker
  cdm_check_valid_portal_page();
1729
1730 6657531f Andreas Kohlbecker
  $taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid);
1731
  if (!empty($taxonname_page)) {
1732
    return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title, $taxonname_page->content);
1733
  }
1734
  else {
1735
    return '';
1736
  }
1737
}
1738
1739
/**
1740 102f8c26 Andreas Kohlbecker
 * View function for a TaxonName page.
1741 6657531f Andreas Kohlbecker
 *
1742 e3001c8d Andreas Kohlbecker
 * The name page lists all taxa for which the name specified by the
1743
 * $taxon_name_uuid is being used. I case there is only one name the
1744
 * page automatically redirects ti the according taxon page. Otherwise
1745
 * the list of names is displayed.
1746 6657531f Andreas Kohlbecker
 *
1747 e3001c8d Andreas Kohlbecker
 * The parameter $taxon_to_hide_uuid allows to exclude a taxon from the
1748
 * list of taxa. This is useful for example when referencing from a taxon
1749
 * to the name page and the referring taxon should not be repeaded in the
1750
 * name page.
1751 6657531f Andreas Kohlbecker
 *
1752 e3001c8d Andreas Kohlbecker
 *
1753 d4ea0dd9 Andreas Kohlbecker
 * @param string $taxon_name_uuid
1754 102f8c26 Andreas Kohlbecker
 *   The uuid of the CDM TaxonName to show a name page for
1755 d4ea0dd9 Andreas Kohlbecker
 * @param string $taxon_to_hide_uuid
1756 e3001c8d Andreas Kohlbecker
 *   A taxon which should not be displayed in the taxon list
1757 d4ea0dd9 Andreas Kohlbecker
 * @param string $highlite_synonym_uuid
1758 e3001c8d Andreas Kohlbecker
 *   Optinal parameter wich takes another taxon uuid, if given the
1759
 *   target taxon pages will show the syonymy tab where the taxon
1760
 *   refenrenced by the $highlite_synonym_uuid will be highlighted
1761
 *   in case it is found on this page.
1762
 *
1763
 * @return object
1764
 *   An object with two fields:
1765
 *     - title: the page title
1766
 *     - content: the page content
1767 6657531f Andreas Kohlbecker
 */
1768 e3001c8d Andreas Kohlbecker
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $highlite_synonym_uuid = NULL) {
1769 6657531f Andreas Kohlbecker
  // Getting the full taxonname object from the server.
1770 d0d068e9 Andreas Kohlbecker
  $taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, array($taxon_name_uuid));
1771 6657531f Andreas Kohlbecker
  if (!$taxon_name) {
1772
    drupal_set_title(t('Taxon name does not exist'), PASS_THROUGH);
1773
    return FALSE;
1774
  }
1775
  // Searching for all the taxa connected with the taxon name on the tree
1776
  // in use.
1777
  $name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
1778
  $request_params = array();
1779
  $request_params['query'] = $name_cache;
1780 7663cd0b Andreas Kohlbecker
  $request_params['tree'] = get_current_classification_uuid();
1781 6657531f Andreas Kohlbecker
  $request_params['doTaxa'] = 1;
1782
  $request_params['doSynonyms'] = 1;
1783
  $request_params['doTaxaByCommonNames'] = 0;
1784
  $request_params['matchMode'] = "EXACT";
1785
  $taxon_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, NULL, queryString($request_params));
1786
1787 d0d068e9 Andreas Kohlbecker
  // Removing the name where we came from.
1788 6657531f Andreas Kohlbecker
  foreach ($taxon_pager->records as $k => &$taxon) {
1789
    if ($taxon->uuid == $taxon_to_hide_uuid) {
1790
      unset($taxon_pager->records[$k]);
1791
    }
1792
  }
1793
  // Show the taxa list or go to the singular taxon.
1794
  if (sizeof($taxon_pager->records) == 1) {// Single taxon case.
1795 e3001c8d Andreas Kohlbecker
    $singleTaxon = array_pop($taxon_pager->records);
1796 6657531f Andreas Kohlbecker
    if ($singleTaxon->class != "Taxon") {
1797
      // It is a Synonym -> look for the accepted.
1798 7635cc7d Andreas Kohlbecker
      $accepted_taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($singleTaxon->uuid), 'classificationFilter=' . get_current_classification_uuid());
1799 e3001c8d Andreas Kohlbecker
      if (!empty($highlite_synonym_uuid)) {
1800 7635cc7d Andreas Kohlbecker
        drupal_goto('cdm_dataportal/taxon/' . $accepted_taxon->uuid . '/synonymy', array('query' => array('highlite' => $highlite_synonym_uuid)));
1801 6657531f Andreas Kohlbecker
      }
1802
      else {
1803 7635cc7d Andreas Kohlbecker
        drupal_goto('cdm_dataportal/taxon/' . $accepted_taxon->uuid . '/synonymy', array('query' => array('highlite' => $singleTaxon->uuid)));
1804 6657531f Andreas Kohlbecker
      }
1805
    }
1806
    else {
1807
      // It is an accepted taxon.
1808 e3001c8d Andreas Kohlbecker
      if (!empty($highlite_synonym_uuid)) {
1809
        drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid . '/synonymy', array('query' => array('highlite' => $highlite_synonym_uuid)));
1810 6657531f Andreas Kohlbecker
      }
1811
      else {
1812
        drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid);
1813
      }
1814
    }
1815
  }
1816
  else {// More than one taxa case.
1817
    $taxon_name_page = new stdClass();
1818 4f225a0f Andreas Kohlbecker
    $taxon_name_page->title = theme('cdm_name_page_title', array('taxon_name' => $taxon_name));
1819 6657531f Andreas Kohlbecker
    if ($taxon_pager->records) {
1820 7272d19c Andreas Kohlbecker
      $taxon_name_page->content = compose_list_of_taxa($taxon_pager->records);
1821 6657531f Andreas Kohlbecker
    }
1822
    else {
1823 6b294c11 Andreas Kohlbecker
      $taxon_name_page->content = 'This name is not assigned to a taxon.';
1824 6657531f Andreas Kohlbecker
    }
1825
    return $taxon_name_page;
1826
  }
1827
}
1828
1829 e0d3e148 Andreas Kohlbecker
/**
1830
 * Returns a registration page as a Drupal node to be rendered by Drupal.
1831
 *
1832
 * @param string  $registration_identifier_encoded
1833
 *   The persistent identifier of the registration urlencoded.
1834
 * @return mixed
1835
 *   The formatted registration page as node.
1836
 */
1837
function cdm_dataportal_registration_page_view($registration_identifier_encoded) {
1838
1839
  cdm_check_valid_portal_page("/\/cdm_dataportal\/registration\/.*$/");
1840
  $registration_page = cdm_dataportal_registration_view($registration_identifier_encoded);
1841
  return cdm_node_show_simulate($registration_page);
1842
}
1843
1844
function cdm_dataportal_registration_view($registration_identifier_encoded) {
1845
1846
  $registration_identifier = urldecode($registration_identifier_encoded);
1847
1848 6cbefddc Andreas Kohlbecker
  $render_array = array();
1849 1e7459da Andreas Kohlbecker
  $registration_dto = cdm_ws_get(CDM_WS_REGISTRATION_DTO_BY_IDENTIFIER . $registration_identifier_encoded);
1850 e0d3e148 Andreas Kohlbecker
  if($registration_dto){
1851 f8283d8a Andreas Kohlbecker
    drupal_set_title(t('Registration Id:') . ' ' . $registration_identifier, PASS_THROUGH);
1852 e0d3e148 Andreas Kohlbecker
1853 26b8a1bc Andreas Kohlbecker
    $render_array = compose_registration_dto_full($registration_dto, true);
1854 e0d3e148 Andreas Kohlbecker
1855
  } else {
1856 1e7459da Andreas Kohlbecker
    $status_text = cdm_ws_get(CDM_WS_REGISTRATION_STATUS_BY_IDENTIFIER, array($registration_identifier));
1857 6c9d417d Andreas Kohlbecker
    if(isset($status_text->String)) {
1858 1e7459da Andreas Kohlbecker
      $status_text = strtolower($status_text->String);
1859
      if($status_text == 'preparation' || $status_text == 'curation'){
1860
        $status_text = 'in ' . $status_text;
1861
      }
1862
      drupal_set_title(t('Registration ' . $status_text), PASS_THROUGH);
1863
      //$status_message;
1864 5fdcad30 Andreas Kohlbecker
      drupal_set_message("A registration with the identifier  " . $registration_identifier . " is " . $status_text, "status");
1865 1e7459da Andreas Kohlbecker
    } else {
1866
      drupal_set_title(t('Registration not found'), PASS_THROUGH);
1867 e42db5b0 Andreas Kohlbecker
      drupal_set_message("A registration with the identifier  " . $registration_identifier . " does not exist", "warning");
1868 1e7459da Andreas Kohlbecker
    }
1869 e0d3e148 Andreas Kohlbecker
  }
1870
1871 5446f047 Andreas Kohlbecker
  $render_array = array(
1872 5fdcad30 Andreas Kohlbecker
    '#prefix' => '<div id="registration">',
1873 5446f047 Andreas Kohlbecker
    'registration' => $render_array,
1874
    '#suffix' => '</div>',
1875
  );
1876
1877 e0d3e148 Andreas Kohlbecker
  return $render_array ;
1878
}
1879
1880
1881 6657531f Andreas Kohlbecker
/**
1882 84b13813 Andreas Kohlbecker
 * Creates a page with the advance search form.
1883
 *
1884
 * NOTE: The advance search form allows searching for taxa.
1885 6657531f Andreas Kohlbecker
 */
1886 a1ce57ce Katja Luther
function cdm_dataportal_view_search_advanced($arg) {
1887
    if (isset($arg)){
1888
        if ($arg == 'blast'){
1889
            return cdm_dataportal_view_search_blast();
1890
        }
1891
    }
1892 6657531f Andreas Kohlbecker
  drupal_set_title(t('Advanced search'), PASS_THROUGH);
1893
  return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
1894
}
1895
1896 a1ce57ce Katja Luther
/**
1897
 * Creates a page with the blast search form.
1898
 *
1899
 * NOTE: The advance search form allows searching for specimen in blast DB.
1900
 */
1901
function cdm_dataportal_view_search_blast() {
1902
    drupal_set_title(t('Blast search'), PASS_THROUGH);
1903
    return drupal_get_form('cdm_dataportal_search_blast_form');
1904
}
1905
1906 6657531f Andreas Kohlbecker
/**
1907 84b13813 Andreas Kohlbecker
 * Creates a page with the search form for searching by taxon descriptions.
1908 6657531f Andreas Kohlbecker
 */
1909
function cdm_dataportal_view_search_taxon_by_description() {
1910 6441ddfb Andreas Kohlbecker
  drupal_set_title(t('Search by factual data'), PASS_THROUGH);
1911 6657531f Andreas Kohlbecker
  return drupal_get_form('cdm_dataportal_search_taxon_by_description_form');
1912
}
1913
1914
/**
1915
 * Executes the search and generates the result list of taxa.
1916
 */
1917
function cdm_dataportal_view_search_results_taxon() {
1918
1919 24797d7f Andreas Kohlbecker
  $taxonPager = cdm_dataportal_search_taxon_execute();
1920 6657531f Andreas Kohlbecker
1921 f19f47fa Andreas Kohlbecker
  $showThumbnails = do_showThumbnails();
1922
1923
  $setSessionUri = url('cdm_api/setvalue/session', array(
1924
      'query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => ''),
1925
  ));
1926
1927
  drupal_add_js('jQuery(document).ready(function() {
1928
1929
      // init
1930
      if(' . $showThumbnails . ' == 1){
1931 1d69a96c Andreas Kohlbecker
          jQuery(\'.media_gallery\').show(20);
1932
      } else {
1933
          jQuery(\'.media_gallery\').hide(20);
1934
      }
1935
1936
      // add change handler
1937
      jQuery(\'#showThumbnails input.showThumbnails\').change(
1938 f19f47fa Andreas Kohlbecker
      function(event){
1939 1d69a96c Andreas Kohlbecker
        var state = 0;
1940
        if(jQuery(this).is(\':checked\')){
1941
          jQuery(\'.media_gallery\').show(20);
1942
          state = 1;
1943
        } else {
1944
          jQuery(\'.media_gallery\').hide(20);
1945
        }
1946
        // store state in session variable
1947
        var uri = \'' . $setSessionUri . '\' + state;
1948
        jQuery.get(uri);
1949
      });
1950 78e178e2 Andreas Kohlbecker
  });',
1951 f19f47fa Andreas Kohlbecker
  array('type' => "inline", 'scope' => JS_DEFAULT));
1952
1953 78e178e2 Andreas Kohlbecker
  drupal_set_title(t('Search results'), PASS_THROUGH);
1954
1955 0a1dc066 Andreas Kohlbecker
  return theme('cdm_search_taxa_results', array(
1956 6657531f Andreas Kohlbecker
    'pager' => $taxonPager,
1957
    'path' => 'cdm_dataportal/search/results/taxon',
1958
    ));
1959
}
1960
1961 a1ce57ce Katja Luther
/**
1962
 * Executes the blast search and generates the result list of specimen.
1963
 */
1964
function cdm_dataportal_view_search_results_specimen() {
1965
1966
    $specimenPager = cdm_dataportal_search_blast_execute();
1967
1968
    return theme('cdm_search_specimen_results', array(
1969
        'pager' => $specimenPager,
1970
        'path' => 'cdm_dataportal/search/results/specimen',
1971
    ));
1972
}
1973
1974
1975 a6ae799b Andreas Kohlbecker
/**
1976
 * Executes the search for registrations and generates the result list..
1977
 */
1978 efbff4b3 Andreas Kohlbecker
function cdm_dataportal_view_search_registrations_results($mode = 'filter') {
1979
1980
  switch($mode ){
1981
    case 'taxongraph':
1982
      $block = block_load('cdm_dataportal', 'registrations_search_taxongraph');
1983
      $registration_pager = cdm_dataportal_search_registrations_taxongraph_execute();
1984
      break;
1985
    case 'filter':
1986
    default:
1987
      $block = block_load('cdm_dataportal', 'registrations_search_filter');
1988
      $registration_pager = cdm_dataportal_search_registrations_filter_execute();
1989
  }
1990
  $block->title = null;
1991 a6ae799b Andreas Kohlbecker
1992
  drupal_set_title(t('Search registrations'), PASS_THROUGH);
1993
1994 efbff4b3 Andreas Kohlbecker
  $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
1995 24797d7f Andreas Kohlbecker
  $registrations_pager_array = compose_registrations_search_results($registration_pager);
1996 a6ae799b Andreas Kohlbecker
  $render_array = array_merge($render_array, $registrations_pager_array);
1997
1998
  return $render_array;
1999
}
2000
2001
2002 94550ff9 Andreas Kohlbecker
/**
2003
 * Provides the standart image wich indicated a loading process
2004
 *
2005
 * @return string
2006
 *  The img html tag
2007
 */
2008
function loading_image_html() {
2009
  return '<img class="loading" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal')
2010
    . '/images/loading_circle_grey_16.gif" style="display:none;">';
2011
}
2012
2013 78e178e2 Andreas Kohlbecker
/**
2014
 * Returns the state of the the showThumbnails flag set in the
2015
 * users session ($_SESSION['pageoption']['searchtaxa']['showThumbnails']).
2016
 *
2017 c5ed6357 Andreas Kohlbecker
 * @return boolean
2018 78e178e2 Andreas Kohlbecker
 *    returns 1 if the flag is set
2019
 */
2020
function do_showThumbnails() {
2021
  static $showThumbnails = null;
2022
2023
  if($showThumbnails == null) {
2024 c5ed6357 Andreas Kohlbecker
    $showThumbnails = 0;
2025
    if (!isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2026
      $showThumbnails = 0;
2027
      $search_gallery_settings = variable_get(CDM_DATAPORTAL_SEARCH_GALLERY_NAME, null);
2028
      $showThumbnails = is_array($search_gallery_settings)
2029
        && isset($search_gallery_settings['cdm_dataportal_show_taxon_thumbnails'])
2030
        && (
2031
            $search_gallery_settings['cdm_dataportal_show_taxon_thumbnails'] +
2032
            $search_gallery_settings['cdm_dataportal_show_synonym_thumbnails'] +
2033
            $search_gallery_settings['cdm_dataportal_show_thumbnail_captions'] > 0
2034
            )
2035
         ? 1 : 0;
2036 f19f47fa Andreas Kohlbecker
2037 c5ed6357 Andreas Kohlbecker
       drupal_array_set_nested_value($_SESSION, array('pageoption', 'searchtaxa', 'showThumbnails'), $showThumbnails);
2038
    }
2039 f19f47fa Andreas Kohlbecker
    $showThumbnails = $_SESSION['pageoption']['searchtaxa']['showThumbnails'];
2040
    if (!is_numeric($showThumbnails)) {
2041
      $showThumbnails = 1;
2042
    }
2043 78e178e2 Andreas Kohlbecker
  }
2044
2045
  return $showThumbnails;
2046
}
2047
2048 6657531f Andreas Kohlbecker
2049 a6ae799b Andreas Kohlbecker
2050 6657531f Andreas Kohlbecker
/* ====================== other functions ====================== */
2051
/**
2052
 * Creates a URL to the taxon page specified by the $uuid parameter.
2053
 *
2054
 * The URL will be prepended with a path element to a specific taxon page tab.
2055
 *
2056
 * This tab is either taken from the CDM_DATAPORTAL_DEFAULT_TAXON_TAB which can
2057
 * be set globally in the administrative settings or individually in the user
2058
 * profile. If the CDM_DATAPORTAL_DEFAULT_TAXON_TAB value is set to LAST_VISITED_TAB
2059
 * the last portal will stay on this last tab.
2060
 *
2061
 * A third option is offerered by the $page_tab parameter which allows overwriting this
2062
 * internal mechanism by a specific value.
2063
 *
2064
 * @param string $uuid
2065
 *   The UUID of the taxon.
2066
 * @param string $page_tab
2067
 *   Overwriting the preset mechanism by defining specific value for the
2068
 *   taxon page tab.
2069
 *
2070
 * @return string
2071
 *   The created URL.
2072
 */
2073
function path_to_taxon($uuid, $page_tab = FALSE) {
2074
2075
  $tab = get_default_taxon_tab();
2076
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
2077
2078
  if (!$uuid) {
2079
    return FALSE;
2080
  }
2081
2082
  if ($page_tab) {
2083
    return 'cdm_dataportal/taxon/' . $uuid . '/' . $page_tab;
2084
  }
2085
  elseif (!$tab || strtolower($tab) == 'general') {
2086
    return 'cdm_dataportal/taxon/' . $uuid;
2087
  }
2088
  elseif (get_last_taxon_page_tab() &&   $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]) {
2089
    return 'cdm_dataportal/taxon/' . $uuid . '/' . get_last_taxon_page_tab();
2090
  }
2091
  else {
2092
    return 'cdm_dataportal/taxon/' . $uuid . '/' . strtolower($tab);
2093
  }
2094
}
2095
2096 9d37c9d9 Patric Plitzner
function path_to_specimen($uuid) {
2097
2098
    if (!$uuid) {
2099
        return FALSE;
2100
    }
2101
    else {
2102 a1ce57ce Katja Luther
        return 'cdm_dataportal/occurrence/' . $uuid;
2103 9d37c9d9 Patric Plitzner
    }
2104
}
2105
2106 6eaec849 Katja Luther
function path_to_specimen_by_accession_number($accession_number) {
2107
2108
    if (!$accession_number) {
2109
        return FALSE;
2110
    }
2111
    else {
2112
        return 'cdm_dataportal/specimen/accession_number/' . $accession_number;
2113
    }
2114
}
2115
2116 30845bda Andreas Kohlbecker
function path_to_named_area($uuid) {
2117
2118
  if (!$uuid) {
2119
    return FALSE;
2120
  }
2121
  else {
2122
    return 'cdm_dataportal/named_area/' . $uuid;
2123
  }
2124
}
2125
2126 6657531f Andreas Kohlbecker
/**
2127 630c7044 Andreas Kohlbecker
 * Creates a URL to show a synonmy in the according taxon page.
2128
 *
2129
 * The URL will point to the synonymy tab of the taxon page of the accepted taxon given as parameter $acceptedUuid.
2130
 * The resulting URI will include query parameters to highlight the synonym, and to optionally display
2131
 * the accepted taxons name in aform like "Foo bar is accepted taxon for Ree doo". The URI will also
2132
 * include the sysnonym uuid as fragment in order to let the browser scroll to the according location
2133
 * in the page
2134
 *
2135
 * @param string $synonymUuid
2136
 *    The uuid of the synonym
2137
 * @param string $acceptedUuid
2138
 *    The uuid of the according accepted taxon
2139
 * @return string
2140
 *    The URL to show a synonmy in the according taxon page
2141 6657531f Andreas Kohlbecker
 */
2142
function uri_to_synonym($synonymUuid, $acceptedUuid) {
2143
  $acceptedPath = path_to_taxon($acceptedUuid, "synonymy");
2144 d071bed7 Andreas Kohlbecker
  return url($acceptedPath, array(
2145
      'query' => array(
2146
        // highlite the synony in the synonymy
2147
        'highlite' => $synonymUuid,
2148
        // the taxon page is refered from a synonym and the synonym can optionally be named in the page title
2149
        // see theme_taxon_page_title()
2150
        'acceptedFor' => $synonymUuid
2151 630c7044 Andreas Kohlbecker
      ),
2152
      'fragment' => $synonymUuid
2153 d071bed7 Andreas Kohlbecker
  ));
2154
2155 6657531f Andreas Kohlbecker
}
2156
2157
/**
2158 e0d3e148 Andreas Kohlbecker
 * Composes the drupal path to the key identified by the uuid.
2159 b8bfa4bd Andreas Kohlbecker
 *
2160
 * @param string $keyType
2161
 *    the key typer corresponds to the specific class of the CDM
2162
 *    IdentificationKey. Possible values are
2163
 *      -PolytomousKey
2164
 *      -MultimediaKey
2165
 *      - ...
2166 e0d3e148 Andreas Kohlbecker
 * @param string $keyUuid
2167 b8bfa4bd Andreas Kohlbecker
 *   The UUID of the key
2168 6657531f Andreas Kohlbecker
 */
2169
function path_to_key($keyType, $keyUuid) {
2170
  if (!$keyUuid || !$keyType) {
2171
    return FALSE;
2172
  }
2173
  $keyType{0} = strtolower($keyType{0});
2174
  return "cdm_dataportal/" . $keyType . "/$keyUuid";
2175
}
2176
2177
/**
2178 e0d3e148 Andreas Kohlbecker
 * Composes the drupal path to the reference identified by the uuid.
2179
 *
2180
 * @param $uuid string String representation of the registration entity uuid.
2181
 *
2182
 * @return string
2183
 *  The drupal path
2184
 *
2185 6657531f Andreas Kohlbecker
 */
2186
function path_to_reference($uuid) {
2187
  if (!$uuid) {
2188
    return FALSE;
2189
  }
2190
  return 'cdm_dataportal/reference/' . $uuid;
2191
}
2192
2193 e0d3e148 Andreas Kohlbecker
/**
2194
 * Composes the drupal path to the reference identified by the uuid.
2195
 *
2196
 * @param string $identifier
2197
 *  The persistent identifier of the registration entity (Registration.identifier).
2198
 * @return string
2199
 *  The drupal path
2200
 */
2201
function path_to_registration($identifier) {
2202
2203 977bba78 Andreas Kohlbecker
  if(variable_get(CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK)){
2204
    return $identifier;
2205
  } else {
2206
    return 'cdm_dataportal/registration/' . urlencode($identifier);
2207
  }
2208 e0d3e148 Andreas Kohlbecker
}
2209
2210 6657531f Andreas Kohlbecker
/**
2211 51b04faf Andreas Kohlbecker
 * Creates the path to a cdm_dataportal taxon name page.
2212
 *
2213 e0d3e148 Andreas Kohlbecker
 * @param string $taxon_name_uuid
2214
 *   The uuid as string of the CDM TaxonName to show a name page for
2215
 * @param string $taxon_to_hide_uuid
2216
 *   The uuid as string of a taxon which should not be displayed in the taxon list
2217 d4ea0dd9 Andreas Kohlbecker
 * @param string $highlited_synonym_uuid
2218 e0d3e148 Andreas Kohlbecker
 *   Optional parameter which takes another taxon uuid, if given the
2219
 *   target taxon pages will show the synonymy tab where the taxon
2220
 *   referenced by the $highlite_synonym_uuid will be highlighted
2221 51b04faf Andreas Kohlbecker
 *   in case it is found on this page.
2222
 *
2223 e0d3e148 Andreas Kohlbecker
 * @return string
2224
 *  URI path element as string
2225 6657531f Andreas Kohlbecker
 */
2226 d4ea0dd9 Andreas Kohlbecker
function path_to_name($name_uuid, $taxon_to_hide_uuid = NULL, $highlited_synonym_uuid  = NULL) {
2227 6657531f Andreas Kohlbecker
  $res = FALSE;
2228
  if ($name_uuid) {
2229
    $res = 'cdm_dataportal/name/' . $name_uuid;
2230
  }
2231 51b04faf Andreas Kohlbecker
  if($taxon_to_hide_uuid){
2232
    $res .= '/' . $taxon_to_hide_uuid;
2233 d4ea0dd9 Andreas Kohlbecker
    if($highlited_synonym_uuid){
2234
      $res .= '/' . $highlited_synonym_uuid;
2235 51b04faf Andreas Kohlbecker
    }
2236
  }
2237 6657531f Andreas Kohlbecker
  return $res;
2238
}
2239
2240
/**
2241 e0d3e148 Andreas Kohlbecker
 * Composes the drupal path to the media entity identified by the uuid.
2242
 *
2243
 * @param string $uuid
2244
 *  The persistent identifier of the entity entity
2245
 * @return string
2246
 *  The drupal path
2247 6657531f Andreas Kohlbecker
 */
2248
function path_to_media($uuid, $representaion_uuid = FALSE, $partId = FALSE) {
2249
  if (!$uuid) {
2250
    return FALSE;
2251
  }
2252
  $out = 'cdm_dataportal/media/' . $uuid;
2253
  if ($representaion_uuid) {
2254
    $out .= '/' . $representaion_uuid;
2255 a867b774 Andreas Kohlbecker
    if (is_numeric($partId)) {
2256 6657531f Andreas Kohlbecker
      $out .= '/' . $partId;
2257
    }
2258
  }
2259
  return $out;
2260
}
2261
2262
/**
2263
 * Compares thisRank with thatRank.
2264
 *
2265
 * Returns a negative integer, zero, or a positive integer
2266
 * as the of thisRank is higher than, equal to, or lower than thatRank.
2267
 * e.g:
2268
 * <ul>
2269
 * <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
2270
 * <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
2271
 * <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
2272
 * </ul>
2273
 * <p>
2274
 * This compare logic of the underlying webservice is the
2275
 * <b>inverse logic</b> of the the one implemented in
2276
 * java.lang.Comparable#compareTo(java.lang.Object)
2277
 *
2278
 * @param $thisRankUuid
2279
 * @param $thatRankUuid
2280
 *
2281
 * @return int
2282
 *   A negative integer, zero, or a positive integer
2283
 *   as the thisRank is lower than, equal to, or higher than thatRank.
2284
 */
2285
function rank_compare($thisRankUuid, $thatRankUuid) {
2286
  $result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
2287
  return $result->Integer;
2288
}
2289
2290
/**
2291
 * Composes an HTML element class attribute value composed of
2292 4b3be949 Andreas Kohlbecker
 * the short-name of the cdm class and the uuid of the entity.
2293
 * This class attribute should be used wherever an cdm-entity is rendered.
2294
 *
2295
 * In case of Taxon entities or TaxonNodeDTOs the secReference is also added
2296
 * to the class attributes as 'sec_uuid:<uuid>'. In case of TaxonNodeDTOs the
2297
 * Taxon uuid is added also as taxon_uuid:<uuid>
2298 6657531f Andreas Kohlbecker
 *
2299
 * These according class selectors in css must be escaped, eg:
2300
 *    .cdm\:TextData
2301
 *
2302 a6ae799b Andreas Kohlbecker
 * @param $cdm_entity
2303
 *    A CDM entity, TaxonNodeDTO or TypedEntityReference
2304 6657531f Andreas Kohlbecker
 */
2305 a6ae799b Andreas Kohlbecker
function html_class_attribute_ref($cdm_entity) {
2306 6657531f Andreas Kohlbecker
2307 4b3be949 Andreas Kohlbecker
  $attributes = '';
2308 a6ae799b Andreas Kohlbecker
  if (is_cdm_entity($cdm_entity)) {
2309
    $attributes =  "cdm:" . $cdm_entity->class . " uuid:" . $cdm_entity->uuid;
2310
  } else if($cdm_entity->class == 'TypedEntityReference') {
2311
    $attributes =  "cdm:" . $cdm_entity->type . " uuid:" . $cdm_entity->uuid;
2312 4b3be949 Andreas Kohlbecker
  }
2313 a6ae799b Andreas Kohlbecker
  if($cdm_entity->class == 'TaxonNodeDto'){
2314
    $attributes .= " taxon_uuid:"  . $cdm_entity->taxonUuid . " sec_uuid:"  . $cdm_entity->secUuid;;
2315 4b3be949 Andreas Kohlbecker
  }
2316 a6ae799b Andreas Kohlbecker
  if($cdm_entity->class == 'Taxon' && isset($cdm_entity->sec->uuid)){
2317
    $attributes .= " sec_uuid:"  . $cdm_entity->sec->uuid;
2318 6657531f Andreas Kohlbecker
  }
2319 4b3be949 Andreas Kohlbecker
  return $attributes;
2320 6657531f Andreas Kohlbecker
}
2321
2322
2323
/**
2324 a0e3ae5c Andreas Kohlbecker
 * Creates a short version of a taxonname.
2325 6657531f Andreas Kohlbecker
 *
2326 e90899ac Andreas Kohlbecker
 * The short name is created by using the taggedTitle field of
2327 a0e3ae5c Andreas Kohlbecker
 * TaxonNodeDTO instances.
2328 e90899ac Andreas Kohlbecker
 * If the taggedTitle if empty the fullname will be returned.
2329 6657531f Andreas Kohlbecker
 *
2330 a0e3ae5c Andreas Kohlbecker
 * @param object $taxonNodeDTO
2331
 *   A TaxonNodeDTO object
2332 6657531f Andreas Kohlbecker
 *
2333
 * @return string
2334
 */
2335 a0e3ae5c Andreas Kohlbecker
function cdm_dataportal_shortname_of($taxonNodeDTO) {
2336
2337 6657531f Andreas Kohlbecker
  $nameStr = '';
2338
2339 a0e3ae5c Andreas Kohlbecker
  normalize_tagged_text($taxonNodeDTO->taggedTitle);
2340 6657531f Andreas Kohlbecker
2341
  // Get all tagged text tokens of the scientific name.
2342 a0e3ae5c Andreas Kohlbecker
  foreach ($taxonNodeDTO->taggedTitle as $tagtxt) {
2343 6657531f Andreas Kohlbecker
    if ($tagtxt->type == 'name' || $tagtxt->type == 'rank') {
2344
      $nameStr .= ($nameStr ? ' ' : '') . $tagtxt->text;
2345
    }
2346
  }
2347
  $nameStr = trim($nameStr);
2348
2349
  if ($nameStr) {
2350
2351
    // Do not return short names for these.
2352 a0e3ae5c Andreas Kohlbecker
    if ($taxonNodeDTO->unplaced || $taxonNodeDTO->excluded) {
2353 6657531f Andreas Kohlbecker
      return $nameStr;
2354
    }
2355
2356
    /*
2357
    1st capture group (^[a-zA-Z]): First letter of uninomial.
2358
    Second capture group ([\p{L}]+): remaining letters of uninomial ([\p{L} = an UTF-8 letter).
2359
    Third capture group (\s+[^(\x2E]+\s+.+$|\s+[a-zA-Z]+$): letters of name,
2360
    but only matching if no '(' or '.' in second word of name,        ( \x2E = '.')
2361
    OR only one specific epithet \s+[\p{L}\x22\x2D\xD7]+$             (\x22= '"', \x2D='-', \xD7='×' )
2362
    */
2363
    $pattern = '/(^[a-zA-Z])([\p{L}]+)(\s+[^(\x2E]+\s+.+$|\s+[\p{L}\x22\x2D\xD7]+$)/u';
2364
    if (preg_match($pattern, $nameStr, $matches, PREG_OFFSET_CAPTURE)) {
2365
      return $matches[1][0] . "." . $matches[3][0];
2366
    }
2367
    else {
2368
      return $nameStr;
2369
    }
2370
  }
2371
  else {
2372 a0e3ae5c Andreas Kohlbecker
    return $taxonNodeDTO->titleCache;
2373 6657531f Andreas Kohlbecker
  }
2374
}
2375
2376
/**
2377
 * Check if a taxon is accepted by the current taxonomic tree.
2378
 *
2379
 * @param mixed $taxon
2380
 *   The Taxon obkect to check.
2381
 *
2382
 * @return bool
2383
 *   Returns TRUE if $taxon is accepted, FALSE otherwise.
2384
 */
2385
function _cdm_dataportal_acceptedByCurrentView($taxon) {
2386
2387 7663cd0b Andreas Kohlbecker
  $defaultTreeUuid = get_current_classification_uuid();
2388 6657531f Andreas Kohlbecker
2389
  if (isset($taxon->taxonNodes)) {
2390
    $taxonNodes = $taxon->taxonNodes;
2391
  }
2392
  else {
2393
    $taxonNodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon->uuid);
2394
  }
2395
2396
  if ($taxon->class == "Taxon" && isset($taxonNodes)) {
2397
    foreach ($taxonNodes as $node) {
2398 586fc780 Andreas Kohlbecker
      if (isset($node->classification)){
2399
        if(is_object($node->classification)) {
2400
          if ($node->classification->uuid == $defaultTreeUuid) {
2401
            return TRUE;
2402
          }
2403 6657531f Andreas Kohlbecker
        }
2404 586fc780 Andreas Kohlbecker
        else {
2405
          if ($node->classification == $defaultTreeUuid) {
2406
            return TRUE;
2407
          }
2408 6657531f Andreas Kohlbecker
        }
2409
      }
2410
    }
2411
  }
2412
2413
  return FALSE;
2414
}
2415
2416
/**
2417 54cfa718 Andreas Kohlbecker
 * Checks is the source has one of the given types.
2418
 *
2419
 * @param object $source
2420
 *   The original source entity
2421
 * @param array $types
2422
 *   An array of elementd of the OriginalSourceType enumeration
2423
 *   If not set the default will be used which is:
2424
 *    - Lineage
2425
 *    - PrimaryMediaSource
2426
 *    - PrimaryTaxonomicSource
2427
 *    - Unknown
2428
 *    - Other
2429
 * @return boolean
2430 6657531f Andreas Kohlbecker
 */
2431 54cfa718 Andreas Kohlbecker
  function _is_original_source_type($source, $types = null) {
2432
    // this is the default
2433
    // maybe this should also be put into the settings
2434
    static $default = array(
2435
      OriginalSourceType::Lineage,
2436
      OriginalSourceType::PrimaryMediaSource,
2437
      OriginalSourceType::PrimaryTaxonomicSource,
2438
      OriginalSourceType::Unknown,
2439
      OriginalSourceType::Other,
2440
    );
2441
2442
    if(!$types){
2443
      $types = $default;
2444
    }
2445
    return isset($source->type) && in_array($source->type, $types);
2446
  }
2447 6657531f Andreas Kohlbecker
2448
/**
2449
 * Collects all the media from a list of description elements.
2450
 *
2451
 * @param array $descriptionElements
2452
 *   The description elements from which to collect the media.
2453
 *
2454
 * @return array
2455
 *   The output with all the collected media.
2456
 */
2457
function cdm_dataportal_media_from_descriptionElements($descriptionElements) {
2458
2459
  $outArrayOfMedia = array();
2460
2461
  // Avoiding a warning box in Drupal for Flora Malesiana.
2462
  if (isset($descriptionElements) && is_array($descriptionElements)) {
2463
    foreach ($descriptionElements as $descriptionElement) {
2464
      if (isset($descriptionElement->media) && is_array($descriptionElement->media)) {
2465
        foreach ($descriptionElement->media as $media) {
2466
          if (is_object($media)) {
2467
            $outArrayOfMedia[] = $media;
2468
          }
2469
        }
2470
      }
2471
    }
2472
  }
2473
  return $outArrayOfMedia;
2474
}
2475
2476
/**
2477 7370f4f7 Andreas Kohlbecker
 * Fetches the list of visible annotations for each of the cdm entities and returns the footnote keys for them.
2478
 *
2479
 * The footnotes are passed to the FootnoteManager in order to store the annotations and to create the footnote keys.
2480
 *
2481
 * @see cdm_fetch_visible_annotations()
2482 6657531f Andreas Kohlbecker
 *
2483 65345976 Andreas Kohlbecker
 * @param array $cdm_entities
2484 6657531f Andreas Kohlbecker
 *   An array of CdmBase instances or a single instance.
2485 28c5c87a Andreas Kohlbecker
 * @param string $footnote_list_key_suggestion
2486 6657531f Andreas Kohlbecker
 *
2487 7370f4f7 Andreas Kohlbecker
 * @return array of footnote keys
2488 6657531f Andreas Kohlbecker
 */
2489 65345976 Andreas Kohlbecker
function cdm_annotations_as_footnotekeys($cdm_entities, $footnote_list_key_suggestion = NULL) {
2490 90597e37 Andreas Kohlbecker
2491 6657531f Andreas Kohlbecker
  $footNoteKeys = array();
2492
2493
  // Is argument cdmBase an array?
2494 65345976 Andreas Kohlbecker
  if (!is_array($cdm_entities)) {
2495 6657531f Andreas Kohlbecker
    $cdmBase_array = array();
2496 65345976 Andreas Kohlbecker
    $cdmBase_array[] = $cdm_entities;
2497 6657531f Andreas Kohlbecker
  }
2498
  else {
2499 65345976 Andreas Kohlbecker
    $cdmBase_array = $cdm_entities;
2500 6657531f Andreas Kohlbecker
  }
2501
2502
  // Getting the key for the footnotemanager.
2503 28c5c87a Andreas Kohlbecker
  if (isset($footnote_list_key_suggestion)) {
2504
    $footnote_list_key = $footnote_list_key_suggestion;
2505 6657531f Andreas Kohlbecker
  }
2506
  else {
2507 28c5c87a Andreas Kohlbecker
    $footnote_list_key = RenderHints::getFootnoteListKey() . '-annotations';
2508 6657531f Andreas Kohlbecker
  }
2509
2510
  // Adding the footnotes keys.
2511
  foreach ($cdmBase_array as $cdmBase_element) {
2512 7370f4f7 Andreas Kohlbecker
    $annotations = cdm_fetch_visible_annotations($cdmBase_element);
2513 6657531f Andreas Kohlbecker
    if (is_array($annotations)) {
2514
      foreach ($annotations as $annotation) {
2515 28c5c87a Andreas Kohlbecker
        $footNoteKeys[] = FootnoteManager::addNewFootnote($footnote_list_key, $annotation->text);
2516 6657531f Andreas Kohlbecker
      }
2517
    }
2518
  }
2519
2520
  return $footNoteKeys;
2521
}
2522
2523 d9763fd3 Andreas Kohlbecker
2524 6657531f Andreas Kohlbecker
/**
2525 d9763fd3 Andreas Kohlbecker
 * Creates a CDM Dynabox.
2526
 *
2527 c1f5d897 Andreas Kohlbecker
 * @param string $dynabox_id
2528 d9763fd3 Andreas Kohlbecker
 *   a uninque name for tha dynabox, using a cdm entity uuid as id is good practice.
2529 6657531f Andreas Kohlbecker
 * @param string $label
2530
 *   The clickable text to show.
2531
 * @param string $content_url
2532
 *   The cdm REST service request url wich will deliver the content to be shown
2533
 *   once the dynabox toggles open.
2534
 * @param string $theme
2535 1ce9afb7 Patric Plitzner
 *   The theme to be used for rendering the cdm REST service response with is
2536 6657531f Andreas Kohlbecker
 *   returned from the $content_url.
2537
 * @param string $link_alt_text
2538
 *   The value for the alt attribute of the dynabox link.
2539
 * @param array $enclosingtags
2540
 *   An array with two elements: $enclosingtags[0] will be used for the dynabox
2541
 *   element itself, $enclosingtags[1] is the tag to be used for the
2542 c1f5d897 Andreas Kohlbecker
 *   dynabox_content (optional)
2543 d9763fd3 Andreas Kohlbecker
 * @param array $attributes
2544
 * @param $content_element_selector
2545
 *   Optional jQuery selector which can be used to reference a dom element which should
2546
 *   be used as container for the content to be shown. The dynabox-<dynabox id>-content
2547
 *  element will be placed in this container.
2548
 *
2549 c1f5d897 Andreas Kohlbecker
 * @param string $open_callback
2550 1ce9afb7 Patric Plitzner
 *   optional javascript call back function to be triggered after toggling the box to
2551 c1f5d897 Andreas Kohlbecker
 *   the open state.
2552
 * @param string $close_callback
2553 1ce9afb7 Patric Plitzner
 *   optional javascript call back function to be triggered after toggling the box to
2554 c1f5d897 Andreas Kohlbecker
 *   the closed state.
2555 d9763fd3 Andreas Kohlbecker
 * @return string Returns HTML for a dynabox.
2556
 * Returns HTML for a dynabox.
2557 6657531f Andreas Kohlbecker
 */
2558 d9763fd3 Andreas Kohlbecker
function cdm_dynabox($dynabox_id, $label, $content_url, $theme, $link_alt_text,
2559
                     $enclosingtags = array('li', 'ul'), $attributes = array(),
2560
                     $content_element_selector = null,
2561
                     $open_callback = 'function(){}', $close_callback = 'function(){}' ) {
2562 6657531f Andreas Kohlbecker
  $out = '';
2563 c1f5d897 Andreas Kohlbecker
2564
  // check for plain class attribute string
2565
  $dynabox_id = preg_replace('/[^a-zA-Z0-9\-]/', '', $dynabox_id);
2566
2567 9c9d11f7 Andreas Kohlbecker
  if(!array_key_exists('class', $attributes)) {
2568
    $attributes['class'] = array();
2569
  }
2570 d9763fd3 Andreas Kohlbecker
  $attributes['id'][] = 'dynabox-' . $dynabox_id;
2571 9c9d11f7 Andreas Kohlbecker
  $dynabox_attributes = drupal_attributes($attributes);
2572
2573
2574 b386ae48 Andreas Kohlbecker
  _add_js_domEvent(); // requires domEvent.js
2575 6657531f Andreas Kohlbecker
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cdm_dynabox.js');
2576 c1f5d897 Andreas Kohlbecker
  drupal_add_js("
2577 94bb8db6 Andreas Kohlbecker
  jQuery(document).ready(
2578
      function() {
2579
        dynabox('". $dynabox_id ."',
2580
          {
2581
            open_callback: " . $open_callback .",
2582 d9763fd3 Andreas Kohlbecker
            close_callback: " . $close_callback .
2583
            ($content_element_selector ? ",\n content_container_selector: '" . $content_element_selector . "'" : "") . "
2584 94bb8db6 Andreas Kohlbecker
          }
2585
        );
2586
      }
2587
   );",
2588
   array(
2589
    'type'=>'inline',
2590
    'scope'=>'footer'
2591
    )
2592
  );
2593 6657531f Andreas Kohlbecker
2594 9c9d11f7 Andreas Kohlbecker
2595 6657531f Andreas Kohlbecker
  $cdm_proxy_url = url('cdm_api/proxy/' . urlencode($content_url) . "/$theme");
2596 9c9d11f7 Andreas Kohlbecker
  $out .= '<!-- dynabox for ' . $content_url . ' -->';
2597 7cc085da Andreas Kohlbecker
  $out .= '<' . $enclosingtags[0] . ' ' .  $dynabox_attributes. '><a href="' . $cdm_proxy_url . '" class="label" alt="' . t('@link-alt-text', array('@link-alt-text' => $link_alt_text)) . '">' . $label . '</a>';
2598 d9763fd3 Andreas Kohlbecker
  $out .= '  <' . $enclosingtags[1] . ' id="dynabox-' . $dynabox_id . '-content">';
2599
  $out .= '    <' . $enclosingtags[0] . ' class="dynabox-content-inner">' . loading_image_html() . '</' . $enclosingtags[0] . '>';
2600
  $out .= '    </' . $enclosingtags[1] . '>';
2601
  $out .= '  </' . $enclosingtags[0] . '>';
2602 9c9d11f7 Andreas Kohlbecker
  $out .= '<!-- dynabox end -->';
2603 6657531f Andreas Kohlbecker
  return $out;
2604
}
2605
2606
/**
2607
 * Checks whether a feature has any description elements.
2608
 *
2609
 * @param mixed $featureNode
2610
 *   A feature node as produced by the function _mergeFeatureTreeDescriptions().
2611
 *
2612
 * @see _mergeFeatureTreeDescriptions()
2613
 *
2614
 * @return bool
2615
 *   Returns TRUE if the given $featureNode or any of its subordinate nodes
2616
 *   contains at least one non empty TextData or at least one DescriptionElement
2617
 *   of an other type. A TextData element holding a multilanguageText or a
2618
 *   source reference is considered to be not empty.
2619 159cd9bb Andreas Kohlbecker
 *
2620
 * @TODO this function may have become obsolete by the new method of detecting empty blocks,
2621 1b756c5f Andreas Kohlbecker
 *       see $block_content_is_not_empty in make_feature_block_list() and
2622 0ebb6efc Andreas Kohlbecker
 *       $feature_block_has_content in compose_feature_block_items_generic
2623 6657531f Andreas Kohlbecker
 */
2624 f19f47fa Andreas Kohlbecker
function has_feature_node_description_elements($featureNode) {
2625 6657531f Andreas Kohlbecker
2626
  if (isset($featureNode->descriptionElements) && is_array($featureNode->descriptionElements) && count($featureNode->descriptionElements) > 0) {
2627 092744e1 Andreas Kohlbecker
    if(!isset($featureNode->descriptionElements['#type'])){ // #type is used to identify e.g. DTO elements: '#type' => 'DTO'
2628
      foreach ($featureNode->descriptionElements as $descriptionElement) {
2629 159cd9bb Andreas Kohlbecker
        if ($descriptionElement->class != "TextData" || isset($descriptionElement->multilanguageText_L10n->text)
2630
          && $descriptionElement->multilanguageText_L10n->text != ''
2631
          || isset($descriptionElement->sources[0])
2632
          || isset($descriptionElement->media[0]) ) {
2633 092744e1 Andreas Kohlbecker
          return TRUE;
2634
        }
2635 6657531f Andreas Kohlbecker
      }
2636
    }
2637
  }
2638 092744e1 Andreas Kohlbecker
  else if (isset($featureNode->childNodes) && is_array($featureNode->childNodes)) {
2639 fae36a2a Andreas Kohlbecker
    foreach ($featureNode->childNodes as $child) {
2640 f19f47fa Andreas Kohlbecker
      if (has_feature_node_description_elements($child)) {
2641 6657531f Andreas Kohlbecker
        return TRUE;
2642
      }
2643
    }
2644
  }
2645
  return FALSE;
2646
}
2647 f26245c8 Andreas Kohlbecker
2648
/**
2649
 * Checks if the current page is a valid taxon portal page and responds with HTTP status 404 (not found) otherwise
2650
 *
2651
 * @param $chapter
2652
 *   The taxon page chapter or part
2653
 */
2654
function cdm_check_valid_taxon_page($chapter){
2655
  static $taxon_tabs = null;
2656
2657
  cdm_check_valid_portal_page();
2658
2659
  if($taxon_tabs == null){
2660
    $taxon_tabs = array('all', 'description');
2661
    foreach(get_taxon_tabs_list() as $tab){
2662
      $taxon_tabs[] = strtolower($tab);
2663
    }
2664
  }
2665
2666
  if(!in_array($chapter, $taxon_tabs)){
2667
    // oops this is not a valid chapter name
2668 b4a5c2be Andreas Kohlbecker
    http_response_code(404); // 404 = Not Found
2669 f26245c8 Andreas Kohlbecker
  }
2670
2671
}
2672
2673
/**
2674 e0d3e148 Andreas Kohlbecker
 * Checks if the current page is a valid portal page and responds with HTTP status 404 (not found) otherwise.
2675
 * The test applied by default it a check for the query parameter 'q' ending with a file suffix like '*.*'
2676 f26245c8 Andreas Kohlbecker
 *
2677 e0d3e148 Andreas Kohlbecker
 * @param $preg_pattern
2678
 *   Optional regular expression pattern to be used in preg_match().
2679 f26245c8 Andreas Kohlbecker
 */
2680 e0d3e148 Andreas Kohlbecker
function cdm_check_valid_portal_page($preg_pattern = null){
2681 595de9f0 Andreas Kohlbecker
  $ends_with_file_suffix_pattern = '/\/[^\.\/]*[\.][^\.\/]*$/';
2682 e0d3e148 Andreas Kohlbecker
  if($preg_pattern === null){
2683
    $preg_pattern = $ends_with_file_suffix_pattern;
2684
  }
2685
  if(preg_match($preg_pattern, $_GET['q'])){
2686 f26245c8 Andreas Kohlbecker
    // oops this urls ends with a file_suffix and thus does not refer to a portal page
2687 b4a5c2be Andreas Kohlbecker
    http_response_code(404); // 404 = Not Found
2688 595de9f0 Andreas Kohlbecker
    exit('HTTP 404');
2689 f26245c8 Andreas Kohlbecker
  }
2690
}
2691 b2b9e057 Andreas Kohlbecker
2692
/**
2693
 * Generates the diff of the texts and presents it in a HTML diff viewer.
2694
 *
2695
 * @param $text_a
2696
 * @param $text_b
2697
 * @return string
2698
 */
2699
function diff_viewer($text_a, $text_b) {
2700
2701
  static $diff_viewer_count = 0;
2702
2703
  $element_id = 'part_definitions_diff_' . $diff_viewer_count++;
2704
2705
  // http://code.stephenmorley.org/php/diff-implementation/
2706
  module_load_include('php', 'cdm_dataportal', 'lib/class.Diff');
2707
  drupal_add_css(drupal_get_path('module',
2708
      'cdm_dataportal') . '/css/diff.css');
2709 087bb473 Andreas Kohlbecker
  _add_jquery_ui();
2710 b2b9e057 Andreas Kohlbecker
  drupal_add_js(
2711
    'jQuery(document).ready( function(){
2712
        jQuery(\'#' . $element_id . '\').accordion({
2713
        collapsible: true,
2714
        active: false,
2715
        fillSpace: true,
2716
        }).children(\'div\').css({ \'height\': \'auto\' });
2717
        jQuery(\'#' . $element_id . ' table.diff\').prepend(\'<thead><tr><th>Default</th><th>User defined<th></th><tr></thead>\');
2718
     });'
2719
    , array(
2720
    'type' => 'inline',
2721
    'scope' => 'footer'
2722
  ));
2723
2724
  $diff = Diff::compare($text_a,
2725
    $text_b);
2726
  $diff_viewer_markup = '<div id="' . $element_id . '"><h3>View Diff</h3><div>'
2727
    . Diff::toTable($diff, '', '')
2728
    . '</div></div>';
2729
  return $diff_viewer_markup;
2730
}
2731