Project

General

Profile

Download (96.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Module to provide a CDM Dataportal.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 *   - Wouter Addink <w.addink@eti.uva.nl> (migration from Drupal 5 to Drupal7)
18
 */
19

    
20
  module_load_include('php', 'cdm_dataportal', 'node_types');
21
  module_load_include('php', 'cdm_dataportal', 'settings');
22
  module_load_include('php', 'cdm_dataportal', 'help');
23
  module_load_include('php', 'cdm_dataportal', 'cdm_dataportal.search');
24

    
25
  module_load_include('inc', 'cdm_dataportal', 'includes/common');
26
  module_load_include('inc', 'cdm_dataportal', 'includes/footnotes');
27
  module_load_include('inc', 'cdm_dataportal', 'includes/agent');
28
  module_load_include('inc', 'cdm_dataportal', 'includes/name');
29
  module_load_include('inc', 'cdm_dataportal', 'includes/taxon');
30
  module_load_include('inc', 'cdm_dataportal', 'includes/taxon-node');
31
  module_load_include('inc', 'cdm_dataportal', 'includes/references');
32
  module_load_include('inc', 'cdm_dataportal', 'includes/pages');
33
  module_load_include('inc', 'cdm_dataportal', 'includes/media');
34
  module_load_include('inc', 'cdm_dataportal', 'includes/maps');
35
  module_load_include('inc', 'cdm_dataportal', 'includes/occurrences');
36
  module_load_include('inc', 'cdm_dataportal', 'includes/occurrences_new'); // tmp file, shoud be merged later with occurrences.inc
37
  module_load_include('inc', 'cdm_dataportal', 'includes/descriptions');
38
  module_load_include('inc', 'cdm_dataportal', 'includes/pre-drupal8');
39

    
40
  module_load_include('inc', 'cdm_dataportal', 'theme/theme_registry');
41
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.common');
42
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.descriptions');
43
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.media');
44
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.page');
45
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.taxon');
46
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.name');
47
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.references');
48

    
49
  module_load_include('php', 'cdm_dataportal', 'classes/footnotemanager');
50
  module_load_include('php', 'cdm_dataportal', 'classes/footnote');
51
  module_load_include('php', 'cdm_dataportal', 'classes/footnotekey');
52
  module_load_include('php', 'cdm_dataportal', 'classes/renderhints');
53

    
54

    
55
  /* ============================ java script functions ============================= */
56

    
57

    
58
  /**
59
  * loads external java script files asynchronously.
60
  *
61
  * @param unknown_type $script_url
62
  */
63
  function drupal_add_js_async($script_url, $callback){
64

    
65
    drupal_add_js("
66
          jQuery(document).ready(function() {
67
            jQuery.ajax({
68
              url: '" . $script_url . "',
69
              dataType: 'script',
70
              cache: true, // otherwise will get fresh copy every page load
71
              success: function() {
72
                    " . $callback . "
73
              }
74
            });
75
          });"
76
    , 'inline');
77
  }
78

    
79
  /**
80
   */
81
  function drupal_add_js_rowToggle($tableId){
82

    
83
      drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/table_modification.js');
84
      drupal_add_js('jQuery(document).ready(function(){
85
          addRowToggle("' . $tableId . '");
86
      });
87
      ', array('type' => 'inline'));
88
  }
89

    
90
  /**
91
   * @param unknown_type $link_element_selector
92
   * @param unknown_type $progress_element_selector
93
   */
94
  function _add_js_cdm_ws_progressbar($link_element_selector, $progress_element_selector){
95

    
96
    $callback = "jQuery('" . $link_element_selector . "').cdm_ws_progress('" . $progress_element_selector . "');";
97

    
98
    drupal_add_js_async(variable_get('cdm_webservice_url', '').'js/cdm_ws_progress.js', $callback);
99

    
100
    //   drupal_add_js("
101
    //   	  if (Drupal.jsEnabled) {
102
    //         $(document).ready(function() {
103
    //       		$('" . $link_element_selector . "').cdm_ws_progress('" . $progress_element_selector . "');
104
    //         });
105
    //       }", 'inline');
106
    }
107

    
108
  /**
109
   * @todo Please document this function.
110
   * @see http://drupal.org/node/1354
111
   */
112
  function _add_js_treeselector() {
113
    // drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/treeselector.js');
114
    drupal_add_js("
115
        jQuery(document).ready(function() {
116
           jQuery('#cdm-taxonomictree-selector-form #edit-val').change(function () {
117
                jQuery('#cdm-taxonomictree-selector-form').submit();
118
            });
119

    
120
        });
121
      ",
122
      array(
123
        'type' => 'inline',
124
        'scope' => 'footer'
125
      )
126
    );
127
  }
128

    
129
  function _add_js_resizable_element($selector, $y_axis_only) {
130

    
131
    _add_jquery_ui();
132
    $options = "";
133
    if($y_axis_only) {
134
      $options = "resize: function(event, ui) {
135
        ui.size.width = ui.originalSize.width;
136
        },
137
        handles: \"s\"";
138

    
139
    }
140
    drupal_add_js("
141
          jQuery(document).ready(function() {
142
             jQuery('" . $selector . "').resizable({". $options ."});
143
          });
144
        ",
145
      array(
146
        'type' => 'inline',
147
        'scope' => 'footer'
148
      )
149
    );
150
  }
151

    
152
  function _add_js_openlayers() {
153

    
154
    $openlayers = '/js/map/OpenLayers-2.13.1/OpenLayers.js';
155
    $proj4js = '/js/map/proj4js-1.1.0/proj4js-compressed.js';
156

    
157
    if(variable_get('cdm_js_devel_mode', FALSE)){
158
      // develooper mode libs
159
  //     $openlayers = '/js/map/OpenLayers-2.13.1/lib/OpenLayers.js';
160
      $openlayers = '/js/map/OpenLayers-2.13.1/OpenLayers.debug.js';
161
      $proj4js = '/js/map/proj4js-1.1.0/proj4js-combined.js';
162
    }
163

    
164
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . $openlayers,
165
      array(
166
        'type' => 'file',
167
        'group' => JS_LIBRARY,
168
        'weight' => 0,
169
        'cache' => TRUE,
170
        'preprocess' => FALSE
171
      )
172
    );
173

    
174

    
175
    // see https://github.com/proj4js/proj4js
176
    // http://openlayers.org/dev/examples/using-proj4js.html
177
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . $proj4js,
178
      array(
179
        'type' => 'file',
180
        'group' => JS_LIBRARY,
181
        'weight' => -1, // before open layers
182
        'cache' => TRUE,
183
      )
184
    );
185

    
186
    // configure the theme
187
    $openlayers_theme_path = drupal_get_path('module', 'cdm_dataportal') . '/js/map/OpenLayers-2.13.1/theme/default/';
188
    $openlayers_imp_path = drupal_get_path('module', 'cdm_dataportal') . '/js/map/img/dark/';
189
    drupal_add_js('OpenLayers.ImgPath="' . base_path() . $openlayers_imp_path . '";', array(
190
        'type' => 'inline',
191
        'group' => JS_LIBRARY,
192
        'weight' => 1, // after openlayers
193
        'cache' => TRUE,
194
        'preprocess' => FALSE
195
      ));
196

    
197
    drupal_add_css($openlayers_theme_path . 'style.tidy.css',
198
      array(
199
        'type' => 'file',
200
        'cache' => TRUE,
201
        'preprocess' => FALSE
202
      )
203
    );
204

    
205
  }
206

    
207
  /**
208
   * @todo Please document this function.
209
   * @see http://drupal.org/node/1354
210
   */
211
  function _add_js_thickbox() {
212
    // ---- jQuery thickbox:
213
    /*
214
    * bug: compat-1.0.js && thickbox.js line 237 .trigger("unload") -> event is
215
    * not triggered because of problems with compat-1.0.js' see INSTALL.txt
216
    */
217
    // drupal_add_js(drupal_get_path('module',
218
    // 'cdm_dataportal').'/js/jquery.imagetool.min.js');
219
    //
220
    // Add a setting for the path to cdm_dataportal module, used to find the path
221
    // for the loading animation image in thickbox.
222
    drupal_add_js(array(
223
    'cdm_dataportal' => array(
224
    'cdm_dataportal_path' => base_path() . drupal_get_path('module', 'cdm_dataportal'),
225
    )
226
    ),
227
    'setting'
228
        );
229
        drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/thickbox/thickbox.js');
230
        drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/js/thickbox/cdm_thickbox.css');
231
  }
232

    
233
  /**
234
   * @todo Please document this function.
235
   * @see http://drupal.org/node/1354
236
   */
237
  function _add_js_lightbox($galleryID) {
238
    /*
239
     * Important Notice: The jquery.lightbox-0.5.js has been modified in order to
240
     * allow using the "alt" attribute for captions instead of the "title"
241
     * attribute
242
     */
243
    $lightbox_base_path =  drupal_get_path('module', 'cdm_dataportal') . '/js/jquery-lightbox-0.5';
244
    $lightbox_image_path = base_path() . $lightbox_base_path . '/images/';
245
    drupal_add_js($lightbox_base_path . '/js/jquery.lightbox-0.5.js');
246
    drupal_add_css($lightbox_base_path . '/css/jquery.lightbox-0.5.css');
247
    drupal_add_js('jQuery(document).ready(function() {
248
        jQuery(\'#' . $galleryID . ' a.lightbox\').lightBox({
249
          fixedNavigation:  true,
250
          imageLoading:     \'' . $lightbox_image_path . 'lightbox-ico-loading.gif\',
251
          imageBtnPrev:     \'' . $lightbox_image_path . 'lightbox-btn-prev.gif\',
252
          imageBtnNext:     \'' . $lightbox_image_path . 'lightbox-btn-next.gif\',
253
          imageBtnClose:    \'' . $lightbox_image_path . 'lightbox-btn-close.gif\',
254
          imageBlank:       \'' . $lightbox_image_path . 'lightbox-blank.gif\',
255
          adjustToWindow: true
256
        });
257
      });
258
      ', array('type' => 'inline'));
259
  }
260

    
261
  /**
262
   * @todo Please document this function.
263
   * @see http://drupal.org/node/1354
264
   */
265
  function _add_js_footnotes() {
266
    _add_js_domEvent();
267
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/footnotes.js');
268
  }
269

    
270
  /**
271
   * @todo Please document this function.
272
   * @see http://drupal.org/node/1354
273
   */
274
  function _add_js_ahah() {
275

    
276
    _add_js_domEvent(); // requires domEvent.js
277
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/ahah-content.js');
278
  }
279

    
280
/**
281
 * @todo Please document this function.
282
 * @see http://drupal.org/node/1354
283
 */
284
function _add_js_taxonomic_children($jquery_selector) {
285

    
286
  global $base_url;
287

    
288

    
289
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/jquery.cdm.taxonomic_children.js');
290
  
291
  drupal_add_js('jQuery(document).ready(function() {
292
        jQuery(\'' . $jquery_selector . '\').taxonomic_children({
293
          // hoverClass: "fa-rotate-90",
294
          // activeClass: "fa-rotate-90",
295
          classificationUuid: "' . get_current_classification_uuid() . '",
296
          taxonUuid: "' . get_current_taxon_uuid() . '",
297
          cdmWebappBaseUri: "' . variable_get('cdm_webservice_url', '') . '",
298
          proxyBaseUri: "' . $base_url . '",
299
          
300
        });
301
      });
302
      ', array('type' => 'inline'));
303
}
304

    
305
  /**
306
   * Adds the external javascript file for domEvent.js.
307
   *
308
   * @see drupal_add_js()
309
   */
310
  function _add_js_domEvent() {
311
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/domEvent.js');
312
  }
313

    
314
  function _add_jquery_ui()
315
  {
316
    drupal_add_css(drupal_get_path('module',
317
        'cdm_dataportal') . '/js/jquery-ui-1.8.24/themes/base/jquery.ui.all.css');
318
    drupal_add_js(drupal_get_path('module',
319
        'cdm_dataportal') . '/js/jquery-ui-1.8.24/ui/jquery-ui.js',
320
      array(
321
        'type' => 'file',
322
        'weight' => JS_LIBRARY,
323
        'cache' => TRUE,
324
        'preprocess' => FALSE
325
      )
326
    );
327
  }
328

    
329
function _add_js_ui_accordion(){
330
  _add_jquery_ui();
331
  drupal_add_js('jQuery(document).ready(function() {
332
      jQuery( "#accordion" ).accordion();
333
    });',
334
    array('type' => 'inline')
335
  );
336
}
337

    
338

    
339
function _add_js_utis_client($jquery_selector){
340

    
341
  drupal_add_js(drupal_get_path('module',
342
      'cdm_dataportal') . '/js/utis-client/utis-client.js',
343
    array(
344
      'type' => 'file',
345
      'weight' => JS_LIBRARY,
346
      'cache' => TRUE,
347
      'preprocess' => FALSE
348
    )
349
  );
350

    
351
  drupal_add_js('jQuery(document).ready(function() {
352
        jQuery( "' . $jquery_selector . '" ).utis_client(
353
        {
354
          spinnerIcon: \'' . font_awesome_icon_markup('fa-sync', array('class' => array('fa-3x',  'fa-spin'), 'style' => array('opacity: 0.3;'))) . '\',
355
          externalLinkIcon: \'' . font_awesome_icon_markup('fa-external-link-alt') . '\'
356
        });
357
      });',
358
    array('type' => 'inline')
359
  );
360
}
361

    
362
function _add_js_universalviewer($jquery_selector, $manifest_uri){
363

    
364
  $universalviewer_path  = drupal_get_path('module',    'cdm_dataportal') . '/js/universalviewer';
365

    
366
  drupal_add_css($universalviewer_path . '/uv/uv.css');
367
  drupal_add_css($universalviewer_path . '/uv-fix.css');
368

    
369
  // offline.js is all of these dependencies concatenated (jQuery, CoreJS, and JSViews)
370
  drupal_add_js($universalviewer_path . '/uv/lib/offline.js',
371
      array(
372
      'type' => 'file',
373
      'group' => JS_LIBRARY,
374
      'cache' => TRUE,
375
      'preprocess' => FALSE
376
    )
377
  );
378
  drupal_add_js($universalviewer_path . '/uv/helpers.js',
379
    array(
380
      'type' => 'file',
381
      'group' => JS_LIBRARY,
382
      'cache' => TRUE,
383
      'preprocess' => FALSE
384
    )
385
  );
386
  // from UV 3.x documentation:
387
  // "root:
388
  // The path to the uv directory. Use a relative path e.g. root: '../../uv'
389
  // Don't start your path with a / otherwise requirejs will not append .js to
390
  // dependencies and they won't load."
391
  //
392
  // universalviewerPath will be used to build the root config variable.
393
  $iCleanUrlRequest = strpos($_SERVER['REQUEST_URI'], 'q=cdm_dataportal/') === false;
394
  if($iCleanUrlRequest){
395
    $folders_up = preg_replace('/[^\/]+/', '..', $_GET['q']);
396
    $folders_up = preg_replace('/\.\.$/', '', $folders_up);
397
  } else {
398
    $folders_up = '';
399
  }
400
  $basePath = base_path();
401
  $config_file = 'uv-config.json';
402
  drupal_add_js('
403
      console.log(\'jQuery inline: \' + jQuery.fn.jquery);
404
      jQuery(window).on(\'uvLoaded\', function() {
405
        jQuery( "' . $jquery_selector . '" ).jqUniversalviewer(
406
        {
407
          root: \'' . $folders_up . $universalviewer_path . '/uv\',
408
          configUri: \'' . $basePath . $universalviewer_path . '/'. $config_file . '\',
409
          manifestUri: \'' . $manifest_uri . '\'
410
        }
411
        );
412
      });',
413
    array(
414
      'type' => 'inline',
415
      'scope' => 'footer',
416
      'group' => JS_DEFAULT,
417
      'weight' => 0,
418
    )
419
  );
420
  drupal_add_js($universalviewer_path . '/jq-universalviewer.js',
421
    array(
422
      'type' => 'file',
423
      'scope' => 'footer',
424
      'group' => JS_DEFAULT,
425
      'weight' => 10,
426
      'cache' => TRUE,
427
      'preprocess' => FALSE
428
    )
429
  );
430
  // ui.js must be last
431
  drupal_add_js($universalviewer_path . '/uv/uv.js',
432
    array(
433
      'type' => 'file',
434
      'scope' => 'footer',
435
      'group' => 300, // IMPORTANT!
436
      'cache' => TRUE,
437
      'preprocess' => FALSE
438
    )
439
  );
440
}
441

    
442
function _add_js_derivation_tree($jquery_selector){
443
  drupal_add_js(drupal_get_path('module','cdm_dataportal') . '/js/derivation-tree.js');
444
  drupal_add_js('jQuery(document).ready(function() {
445
      jQuery( "' . $jquery_selector . '" ).derivationTree();
446
    });',
447
    array('type' => 'inline')
448
  );
449
}
450

    
451
  /**
452
   * Provides the markup for an font awesome icon.
453
   *
454
   * The icons is created in default size without any extra features.
455
   *
456
   * The available icons are listed here http://fontawesome.io/cheatsheet/
457
   * fontawesome icons have much more features than implemented here in this function,
458
   * for spinning icons, fixed width icons, rotation, etc please checkout the
459
   * examples at http://fontawesome.io/examples/
460
   *
461
   * @parameter $icon_name
462
   *  The name of the icon which starts with 'fa-'
463
   *
464
   * @return String
465
   *    the markup for the icon in an <i> tag
466
   *
467
   */
468
  function font_awesome_icon_markup($icon_name = NULL, $attributes = array()){
469
    _add_font_awesome_font();
470

    
471

    
472
    if($icon_name){
473
      if(!isset($attributes['class'])){
474
        $attributes['class'] = array();
475
      }
476
      $attributes['class'][] = 'fa';
477
      $attributes['class'][] = $icon_name;
478

    
479
      return '<i ' . drupal_attributes($attributes) . '></i>';
480
    }
481

    
482
    return '';
483
  }
484

    
485
/**
486
 * @param string $glyph_name
487
 *   The name of the gloyph (e.g. 'icon-interal-link-alt-solid') for the foll list please
488
 *   refer to modules/cdm_dataportal/fonts/custom-icon-font
489
 * @param array $attributes
490
 * @return string
491
 */
492
  function custom_icon_font_markup($glyph_name = NULL, $attributes = array()){
493
    _add_font_custom_icon_font();
494

    
495

    
496
    if($glyph_name){
497
      if(!isset($attributes['class'])){
498
        $attributes['class'] = array();
499
      }
500
      $attributes['class'][] = $glyph_name;
501

    
502
      return '<i ' . drupal_attributes($attributes) . '></i>';
503
    }
504

    
505
    return '';
506
  }
507

    
508
/**
509
 * Adds the css  containing the font awesome icons to the html header.
510
 */
511
function _add_font_awesome_font()
512
{
513
  // $fa_font_version = 'font-awesome-4.6.3/css/font-awesome.min.css';
514
  $fa_font_version = 'fontawesome-free-5.9.0-web/css/all.css';
515
  $font_awesome_css_uri = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/fonts/' . $fa_font_version;
516

    
517
  drupal_add_html_head_link(
518
    array(
519
      'href' => $font_awesome_css_uri,
520
      'rel' => 'stylesheet'
521
    )
522
  );
523
}
524

    
525
/**
526
 * Adds the css  containing the font awesome icons to the html header.
527
 */
528
function _add_font_custom_icon_font()
529
{
530

    
531
  $custom_icon_font_css_uri = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/fonts/custom-icon-font/style.css';
532

    
533
  drupal_add_html_head_link(
534
    array(
535
      'href' => $custom_icon_font_css_uri,
536
      'rel' => 'stylesheet'
537
    )
538
  );
539
}
540

    
541
/* ====================== hook implementations ====================== */
542
  /**
543
   * Implements hook_permission().
544
   *
545
   * Valid permissions for this module.
546
   *
547
   * @return array
548
   *   An array of valid permissions for the cdm_dataportal module.
549
   */
550
  function cdm_dataportal_permission() {
551
    return array(
552
      'administer cdm_dataportal' => array(
553
        'title' => t('Administer CDM DataPortal settings'),
554
        'description' => t("Access the settings pages specific for the cdm_dataportal module"),
555
      ),
556
      'access cdm content' => array(
557
        'title' => t('Access CDM content'),
558
        'description' => t("Access content (taxa, names, specimens, etc.) served by the CDM web service."),
559
      ),
560
    );
561
  }
562

    
563
/**
564
 * Implements hook_menu().
565
 */
566
function cdm_dataportal_menu() {
567
  $items = array();
568

    
569
  // @see settings.php.
570
  cdm_dataportal_menu_admin($items);
571
  cdm_dataportal_menu_help($items);
572

    
573
  $items['cdm_dataportal/names'] = array(
574
    'page callback' => 'cdm_dataportal_view_names',
575
    'access arguments' => array('access cdm content'),
576
    'type' => MENU_CALLBACK,
577
  );
578

    
579
  // Optional callback arguments: page.
580
  $items['cdm_dataportal/taxon'] = array(
581
    'page callback' => 'cdm_dataportal_taxon_page_view',
582
    'access arguments' => array('access cdm content'),
583
    'type' => MENU_CALLBACK,
584
    // Expected callback arguments: uuid.
585
  );
586

    
587
  $items['cdm_dataportal/occurrence'] = array(
588
        'page callback' => 'cdm_dataportal_specimen_page_view',
589
        'access arguments' => array('access cdm content'),
590
        'type' => MENU_CALLBACK,
591
        // Expected callback arguments: uuid.
592
    );
593

    
594
  $items['cdm_dataportal/description'] = array(
595
        'page callback' => 'cdm_dataportal_description_page_view',
596
        'access arguments' => array('access cdm content'),
597
        'type' => MENU_CALLBACK,
598
        // Expected callback arguments: uuid.
599
    );
600

    
601
   $items['cdm_dataportal/specimen/accession_number'] = array(
602
        'page callback' => 'cdm_dataportal_specimen_by_accession_number_page_view',
603
        'access arguments' => array('access cdm content'),
604
        'type' => MENU_CALLBACK,
605
        // Expected callback arguments: accession number.
606
    );
607
  $items['cdm_dataportal/named_area'] = array(
608
    'page callback' => 'cdm_dataportal_named_area_page_view',
609
    'access arguments' => array('access cdm content'),
610
    'type' => MENU_CALLBACK,
611
    // Expected callback arguments: uuid.
612
  );
613

    
614
  $items['cdm_dataportal/name'] = array(
615
    'page callback' => 'cdm_dataportal_name_page_view',
616
      /*
617
    'page arguments' => array(
618
       'taxon_name_uuid',
619
       'taxon_to_hide_uuid',
620
       'synonym_uuid' => NULL
621
      ),
622
      */
623
    'access arguments' => array('access cdm content'),
624
    'type' => MENU_CALLBACK,
625
    // Expected callback arguments: uuid.
626
  );
627

    
628
  $items['cdm_dataportal/reference'] = array(
629
    'page callback' => 'cdm_dataportal_view_reference',
630
    'access arguments' => array('access cdm content'),
631
    'type' => MENU_CALLBACK,
632
    // Expected callback arguments: uuid.
633
  );
634

    
635
  $items['cdm_dataportal/reference/list'] = array(
636
    'page callback' => 'cdm_dataportal_view_reference_list',
637
    'access arguments' => array('access cdm content'),
638
    'type' => MENU_CALLBACK,
639
    // Expected callback arguments: uuid.
640
  );
641

    
642
  $items['cdm_dataportal/media'] = array(
643
    'page callback' => 'cdm_dataportal_view_media',
644
    'access arguments' => array('access cdm content'),
645
    'type' => MENU_CALLBACK,
646
    // Expected callback arguments:
647
    // uuid, mediarepresentation_uuid, part_uuid or part#.
648
  );
649

    
650
  $items['cdm_dataportal/polytomousKey'] = array(
651
    'page callback' => 'cdm_dataportal_view_polytomousKey',
652
    'access arguments' => array('access cdm content'),
653
    'type' => MENU_CALLBACK,
654
    // Expected callback arguments: polytomousKey->uuid.
655
  );
656

    
657
  $items['cdm_dataportal/search'] = array(
658
    'page callback' => 'cdm_dataportal_view_search_advanced',
659
    'access arguments' => array('access cdm content'),
660
    'type' => MENU_CALLBACK,
661
  );
662

    
663
  // Optional callback arguments: page.
664
  $items['cdm_dataportal/registration'] = array(
665
    'page callback' => 'cdm_dataportal_registration_page_view',
666
    'access arguments' => array('access cdm content'),
667
    'type' => MENU_CALLBACK,
668
    // Expected callback arguments: uuid.
669
  );
670

    
671
  // ------------ SEARCH -----------
672
  $items['cdm_dataportal/search/advanced'] = array(
673
    'title' => 'Advanced', // will be passed through t()
674
    'page callback' => 'cdm_dataportal_view_search_advanced',
675
    'access arguments' => array('access cdm content'),
676
    'type' => MENU_DEFAULT_LOCAL_TASK,
677
  );
678
  $items['cdm_dataportal/search/blast'] = array(
679
    'title' => 'Blast', // will be passed through t()
680
    'page callback' => 'cdm_dataportal_view_search_blast',
681
    'access arguments' => array('access cdm content'),
682
    'type' => MENU_LOCAL_TASK,
683
  );
684

    
685
  $items['cdm_dataportal/search/taxon_by_description'] = array(
686
    'title' => 'By content category', // will be passed through t()
687
    'page callback' => 'cdm_dataportal_view_search_taxon_by_description',
688
    'access arguments' => array('access cdm content'),
689
    'type' => MENU_LOCAL_TASK,
690
  );
691
  $items['cdm_dataportal/search/results/taxon'] = array(
692
    'page callback' => 'cdm_dataportal_view_search_results_taxon',
693
    'access arguments' => array('access cdm content'),
694
    'type' => MENU_CALLBACK,
695
  );
696

    
697
  $items['cdm_dataportal/search/results/specimen'] = array(
698
      'page callback' => 'cdm_dataportal_view_search_results_specimen',
699
      'access arguments' => array('access cdm content'),
700
      'type' => MENU_CALLBACK,
701
  );
702

    
703
  /*
704
   * MENU_CALLBACK at cdm_dataportal/registration-search is needed to make the
705
   * tabs in the subordinate paths work, accessing this 'page' will cause the
706
   * MENU_DEFAULT_LOCAL_TASK being displayed
707
   */
708
  $items['cdm_dataportal/registration-search'] = array(
709
    'title' => 'Search', // will be passed through t()
710
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
711
    'page arguments' => array("filter"),
712
    'access arguments' => array('access cdm content'),
713
    'type' => MENU_CALLBACK,
714
  );
715
  /*
716
   * the MENU_DEFAULT_LOCAL_TASK creates a tab for the MENU_CALLBACK
717
   * defined at a higher level of the path (cdm_dataportal/registration-search)
718
   */
719
  $items['cdm_dataportal/registration-search/filter'] = array(
720
    'title' => 'Search', // will be passed through t()
721
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
722
    'page arguments' => array("filter"),
723
    'access arguments' => array('access cdm content'),
724
    'type' => MENU_DEFAULT_LOCAL_TASK,
725
  );
726
  /*
727
   * the MENU_LOCAL_TASK creates another tab
728
   */
729
  $items['cdm_dataportal/registration-search/taxongraph'] = array(
730
    'title' => 'Taxon graph search', // will be passed through t()
731
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
732
    'page arguments' => array("taxongraph"),
733
    'access arguments' => array('access cdm content'),
734
    'type' => MENU_LOCAL_TASK,
735
  );
736

    
737
  // Optional callback arguments: page.
738
  $items['cdm_dataportal/search/agent'] = array(
739
    'page callback' => 'cdm_dataportal_view_search_agent',
740
    'access arguments' => array('access cdm content'),
741
    'type' => MENU_CALLBACK,
742
    // Expected callback arguments: uuid.
743
  );
744

    
745
  // ------------ menu items with variable path elements -----------
746

    
747
  // 'May not cache' in D5.
748
  $items['cdm_dataportal/name/%'] = array(
749
    // 'page callback' => 'cdm_dataportal_view_name',
750
    'page callback' => 'cdm_dataportal_name_page_view',
751
    'page arguments' => array(2, 3, 4, 5),
752
    'access arguments' => array('access cdm content'),
753
    'type' => MENU_CALLBACK,
754
  );
755

    
756
  // --- Local tasks for Taxon.
757
  // --- tabbed taxon page
758
  if (variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
759
    $items['cdm_dataportal/taxon/%'] = array(
760
      'title' => cdm_taxonpage_tab_label('General'),
761
      'page callback' => 'cdm_dataportal_taxon_page_view',
762
      'access arguments' => array('access cdm content'),
763
      'type' => MENU_CALLBACK,
764
      'weight' => 1,
765
      'page arguments' => array(2, "description")
766
      , // Expected callback arguments: taxon_uuid.
767
    );
768

    
769
    $items['cdm_dataportal/taxon/%/all'] = array(
770
      'title' => cdm_taxonpage_tab_label('General'),
771
      'page callback' => 'cdm_dataportal_taxon_page_view',
772
      'access arguments' => array('access cdm content'),
773
      'type' => MENU_CALLBACK,
774
      'weight' => 2,
775
      'page arguments' => array(2, "all")
776
      , // Expected callback arguments: taxon_uuid.
777
    );
778

    
779
    $items['cdm_dataportal/taxon/%/description'] = array(
780
      'title' => cdm_taxonpage_tab_label('General'),
781
      'page callback' => 'cdm_dataportal_taxon_page_view',
782
      'access arguments' => array('access cdm content'),
783
      'type' => MENU_DEFAULT_LOCAL_TASK,
784
      'weight' => 2,
785
      'page arguments' => array(2, "description")
786
      , // Expected callback arguments: taxon_uuid.
787
    );
788

    
789
    $items['cdm_dataportal/taxon/%/synonymy'] = array(
790
      'title' => cdm_taxonpage_tab_label('Synonymy'),
791
      'page callback' => 'cdm_dataportal_taxon_page_view',
792
      'access arguments' => array('access cdm content'),
793
      'type' => MENU_LOCAL_TASK,
794
      'weight' => 4,
795
      'page arguments' => array(2, "synonymy", 4)
796
      , // Expected callback arguments: taxon_uuid and ...
797
    );
798
    $items['cdm_dataportal/taxon/%/images'] = array( // Images
799
      'title' => cdm_taxonpage_tab_label('Images'),
800
      'page callback' => 'cdm_dataportal_taxon_page_view',
801
      'access arguments' => array('access cdm content'),
802
      'type' => MENU_LOCAL_TASK,
803
      'weight' => 5,
804
      'page arguments' => array(2, "images")
805
      , // Expected callback arguments: taxon_uuid.
806
    );
807

    
808
    $items['cdm_dataportal/taxon/%/specimens'] = array( // Specimens
809
      'title' => cdm_taxonpage_tab_label('Specimens'),
810
      'page callback' => 'cdm_dataportal_taxon_page_view',
811
      'access arguments' => array('access cdm content'),
812
      'type' => MENU_LOCAL_TASK,
813
      'weight' => 6,
814
      'page arguments' => array(2, "specimens")
815
      , // Expected callback arguments: taxon_uuid.
816
    );
817

    
818
    $items['cdm_dataportal/taxon/%/keys'] = array( // Keys
819
      'title' => cdm_taxonpage_tab_label('Keys'),
820
      'page callback' => 'cdm_dataportal_taxon_page_view',
821
      'access arguments' => array('access cdm content'),
822
      'type' => MENU_LOCAL_TASK,
823
      'weight' => 6,
824
      'page arguments' => array(2, "keys")
825
      , // Expected callback arguments: taxon_uuid.
826
    );
827

    
828
    $items['cdm_dataportal/taxon/%/experts'] = array( // Experts
829
      'title' => cdm_taxonpage_tab_label('Experts'),
830
        'page callback' => 'cdm_dataportal_taxon_page_view',
831
        'access arguments' => array('access cdm content'),
832
        'type' => MENU_LOCAL_TASK,
833
        'weight' => 6,
834
        'page arguments' => array(2, "experts")
835
    , // Expected callback arguments: taxon_uuid.
836
    );
837

    
838
    $items['cdm_dataportal/taxon/autosuggest/%/%/%/'] = array(
839
        'page callback' => 'cdm_dataportal_taxon_autosuggest',
840
        'access arguments' => array('access cdm content'),
841
        'page arguments' => array(3,4,5),
842
        'type' => MENU_CALLBACK
843
    );
844
  }
845

    
846
  // --- refresh link for all cdmnode types
847
  foreach (cdm_get_nodetypes() as $type=>$name) {
848
    $items['cdm_dataportal/' . $name . '/%/refresh'] = array(
849
        'title' => 'Refresh',
850
        'page callback' => 'cdm_dataportal_refresh_node',
851
        'access arguments' => array('administer cdm_dataportal'),
852
        'type' => MENU_LOCAL_TASK,
853
        'weight' => 100,
854
        'page arguments' => array($name, 2)
855
    );
856
  }
857

    
858
  return $items;
859
}
860

    
861
/**
862
 * Implements hook_init().
863
 *
864
 */
865
function cdm_dataportal_init() {
866
  if (!path_is_admin(current_path())) {
867
    //FIXME To add CSS or JS that should be present on all pages, modules
868
    //      should not implement this hook, but declare these files in their .info file.
869
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal.css');
870
    // drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
871
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_screen.css', array('type' => 'screen'));
872
  } else {
873
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_settings.css');
874
  }
875

    
876
  if(variable_get('cdm_debug_mode', FALSE)){
877
    $file = 'temporary://drupal_debug.txt';
878
    file_put_contents($file, 'CDM DEBUG LOG for ' . $_GET['q']. "\n"); // will overwrite the file
879
  }
880

    
881
  $bibliography_settings = get_bibliography_settings();
882
  $enclosing_tag = $bibliography_settings['enabled'] == 1 ? 'div' : 'span';
883
  FootnoteManager::registerFootnoteSet('BIBLIOGRAPHY', $enclosing_tag, $bibliography_settings['key_format']);
884
}
885

    
886
function cdm_dataportal_refresh_node($cdm_node_name, $uuid, $parameters = array()){
887

    
888
  $base_path = 'cdm_dataportal/' . $cdm_node_name . '/' . $uuid;
889

    
890
  if($cdm_node_name == 'taxon' && variable_get('cdm_dataportal_taxonpage_tabs', 1)){
891
    // force reloading of all and notify user about this special loading
892
    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: ')
893
        . l('Back to tabbed taxon page', $base_path));
894
    $base_path .= '/all';
895
  } else {
896
    drupal_set_message(t('The level 2 cache has been cleared for this page'));
897
  }
898

    
899
  $parameters['cacheL2_refresh'] ='1';
900

    
901

    
902
  drupal_goto($base_path, array('query' => $parameters));
903
}
904

    
905
/**
906
 * Implements hook_requirements($phase)
907
 */
908
function cdm_dataportal_requirements($phase) {
909
    $requirements = array();
910
    if($phase == 'runtime'){
911

    
912
    }
913
    return $requirements;
914
}
915

    
916
/**
917
 * Implements hook_block_info().
918
 */
919
function cdm_dataportal_block_info() {
920

    
921
    // $block[0]["info"] = t("CDM DataPortal DevLinks");
922
    // $block[1]["info"] = t("CDM DataPortal Credits");
923
    $block["2"] = array(
924
        "info" => t("CDM - Search Taxa"),
925
        "cache" => DRUPAL_NO_CACHE
926
      );
927
    // $block[3]["info"] = t("CDM Filters");
928
    $block["4"]["info"] = t("CDM  - Dataportal Print");
929
    $block["keys"]["info"] = t("CDM - Identification keys");
930
    $block["fundedByEDIT"]["info"] = t('CDM - Powered by EDIT');
931
    $block["classification_breadcrumbs"] =  array(
932
        'info' => t('CDM - Classification breadcrumbs'),
933
        'cache' => DRUPAL_CACHE_PER_PAGE
934
      );
935
    $block["taxonomic_children"] =  array(
936
      'info' => t('CDM - Taxonomic children'),
937
      'cache' => DRUPAL_CACHE_PER_PAGE
938
    );
939
    $block["back_to_search_results"] =  array(
940
      'title' => '<none>',
941
      'info' => t('CDM - Back to search Results'),
942
      'cache' => DRUPAL_CACHE_PER_PAGE,
943
      'visibility' => BLOCK_VISIBILITY_LISTED,
944
      'pages' => "cdm_dataportal/taxon/*", // multiple page paths separated by "\n"!!!
945
    );
946
  $block['registrations_search_filter'] =  array(
947
    'title' => 'Filter registrations',
948
    'info' => t('CDM - Registrations search filter'),
949
    'cache' => DRUPAL_CACHE_PER_PAGE,
950
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
951
    'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!!
952
  );
953
  $block['registrations_search_taxongraph'] =  array(
954
    'title' => 'Taxonomic registration search',
955
    'info' => t('CDM - Registrations search by taxon graph'),
956
    'cache' => DRUPAL_CACHE_PER_PAGE,
957
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
958
    'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!!
959
  );
960
  $block['registrations_search'] =  array(
961
    'title' => 'Search',
962
    'info' => t('CDM - Registrations search combining filter and taxon graph search' ),
963
    'cache' => DRUPAL_CACHE_PER_PAGE,
964
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
965
    'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!!
966
  );
967
  $block['utis_search'] =  array(
968
    'title' => 'UTIS Search',
969
    'info' => t('Query the Unified Taxonomic Information Service (UTIS)' ),
970
    'cache' => DRUPAL_CACHE_PER_PAGE,
971
    'visibility' => BLOCK_VISIBILITY_NOTLISTED
972
  );
973
  return $block;
974
}
975

    
976
/**
977
 * Implements hook_block_view().
978
 */
979
function cdm_dataportal_block_view($delta) {
980
  // TODO Rename block deltas (e.g. '2') to readable strings.
981
  switch ($delta) {
982
    // case 'delta-1':
983
    // $block['subject'] = t('Credits');
984
    // $block['content'] = theme('cdm_credits');
985
    // return $block;
986
    case '2':
987
      $block['subject'] = t('Search taxa');
988
      $form = drupal_get_form('cdm_dataportal_search_taxon_form');
989
      $block['content'] = drupal_render($form);
990

    
991
      if (variable_get('cdm_dataportal_show_advanced_search', 1)) {
992
        $block['content'] .= '<div>' . l(t('Advanced Search'), 'cdm_dataportal/search') . '</div>';
993
      }
994
      if (variable_get(CDM_SEARCH_BLAST_ENABLED)){
995
          $block['content'] .= '<div>' . l(t('Blast Search'), 'cdm_dataportal/search/blast') . '</div>';
996
      }
997
      return $block;
998
    case '4':
999
      $block['subject'] = '';
1000
      $block['content'] = theme('cdm_print_button');
1001
      return $block;
1002
    case "keys":
1003
      $block['subject'] = t('Identification Keys');
1004
      $block['content'] = theme('cdm_block_IdentificationKeys', array('taxonUuid' => NULL));
1005
      return $block;
1006
    case "fundedByEDIT":
1007
      // t('Funded by EDIT');
1008
      $text = '<none>';
1009
      $block['subject'] = $text;
1010
      $img_tag = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/powered_by_edit.png' . '" alt="' . $text . '"/>';
1011
      $block['content'] = l($img_tag, "http://cybertaxonomy.org/", array(
1012
        'attributes' => array("target" => "EDIT"),
1013
        'absolute' => TRUE,
1014
        'html' => TRUE,
1015
      ));
1016
      return $block;
1017
    case 'classification_breadcrumbs':
1018
      $taxon_uuid = get_current_taxon_uuid();
1019
      $block['subject'] = '<none>';
1020
      $block['content'] = compose_classification_breadcrumbs($taxon_uuid);
1021
      return $block;
1022
    case 'taxonomic_children':
1023
      $taxon_uuid = get_current_taxon_uuid();
1024
      $block['subject'] = '<none>';
1025
      $block['content'] = compose_taxonomic_children($taxon_uuid);
1026
      return $block;
1027
    case 'back_to_search_results':
1028
      $block['subject'] = '<none>';
1029
      if (isset($_SESSION['cdm']['search'])) {
1030
        $block['content'] = l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search']);
1031
      }
1032
      return $block;
1033
    case 'registrations_search_filter':
1034
      $block['subject'] = '<none>';
1035
      $block['content'] = drupal_get_form('cdm_dataportal_search_registration_filter_form'); // see cdm_dataportal_search_registration_filter_form($form, &$form_state)
1036
      return $block;
1037
    case 'registrations_search_taxongraph':
1038
      $block['subject'] = '<none>';
1039
      $block['content'] = drupal_get_form('cdm_dataportal_search_registration_taxongraph_form'); // see cdm_dataportal_search_registration_taxongraph_form($form, &$form_state)
1040
      return $block;
1041
    case 'registrations_search':
1042
      _add_js_ui_accordion();
1043
      _add_font_awesome_font();
1044
      $block['subject'] = '<none>';
1045
      $filter_form = drupal_get_form('cdm_dataportal_search_registration_filter_form');
1046
      $filter_form['#prefix'] = '<div>';
1047
      $filter_form['#suffix'] = '</div>';
1048
      $taxongraph_form = drupal_get_form('cdm_dataportal_search_registration_taxongraph_form');
1049
      $taxongraph_form['#prefix'] = '<div>';
1050
      $taxongraph_form['#suffix'] = '</div>';
1051
      $block['content'] = array(
1052
        'accordion' => array(
1053
          '#markup' => '',
1054
          '#prefix' => '<div id="accordion">',
1055
          '#suffix' => '</div>',
1056
          'content' => array(
1057
            array('#markup' => '<h3>Filter</h3>'),
1058
            $filter_form,
1059
            array('#markup' => '<h3>Taxon graph</h3>'),
1060
            $taxongraph_form,
1061
          )
1062
        )
1063
    );
1064
       return $block;
1065
    case 'utis_search':
1066
      _add_js_utis_client('.utis_client');
1067
      $block['subject'] = '<none>';
1068
      $block['content'] = '<div class="utis_client"></div>';
1069
      return $block;
1070
    default:
1071
      return null;
1072
  }
1073
}
1074

    
1075

    
1076
/**
1077
 * Provides the uuid of the taxon for pages with the path ./taxon/{taxon_uuid}
1078
 *
1079
 * @return string
1080
 *   the taxon uuid or NULL
1081
 */
1082
function get_current_taxon_uuid()
1083
{
1084
  static $taxon_uuid;
1085

    
1086
  if(!isset($taxon_uuid)){
1087
    if(isset($_REQUEST['currentTaxon']) && is_uuid($_REQUEST['currentTaxon'])) {
1088
      $taxon_uuid = $_REQUEST['currentTaxon'];
1089
    } else if (arg(1) == 'taxon' && is_uuid(arg(2))) {
1090
      $taxon_uuid = arg(2);
1091
    } else {
1092
      $taxon_uuid = null;
1093
    }
1094
  }
1095

    
1096
  return $taxon_uuid;
1097
}
1098

    
1099
/**
1100
 * Returns the currently classification tree in use.
1101
 *
1102
 * @return string
1103
 *   The uuid of the currently focused classification
1104
 */
1105
function get_current_classification_uuid() {
1106
  if (isset($_SESSION['cdm']['taxonomictree_uuid']) && is_uuid($_SESSION['cdm']['taxonomictree_uuid'])) {
1107
    return $_SESSION['cdm']['taxonomictree_uuid'];
1108
  }
1109
  else {
1110
    return variable_get(CDM_TAXONOMICTREE_UUID, FALSE);
1111
  }
1112
}
1113

    
1114
/*
1115
 function cdm_dataportal_session_clear($cdm_ws_uri_update = FALSE){
1116
 $_SESSION['cdm'] = NULL;
1117
 if(is_string($cdm_ws_uri_update)){
1118
 $_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
1119
 }
1120
 }
1121

    
1122
 function cdm_dataportal_session_validate(){
1123
 if(!isset($_SESSION['cdm']['ws_uri'])){
1124
 $_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', FALSE));
1125
 } else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', FALSE)){
1126
 cdm_dataportal_session_clear(variable_get('cdm_webservice_url', FALSE));
1127
 }
1128
 }
1129
 */
1130

    
1131
/**
1132
 * creates a  selector form for taxonomic trees.
1133
 *
1134
 * @return array
1135
 *  a drupal form array
1136
 */
1137
function cdm_taxonomictree_selector() {
1138
  _add_js_treeselector();
1139

    
1140
  $form = drupal_get_form('cdm_taxonomictree_selector_form');
1141
  return $form;
1142
}
1143

    
1144
/**
1145
 * @todo Please document this function.
1146
 * @see http://drupal.org/node/1354
1147
 *
1148
 * used by cdm_taxonomictree_selector()
1149
 *
1150
 * @deprecated use compose_classification_selector instead
1151
 */
1152
function cdm_taxonomictree_selector_form($form, &$form_state) {
1153

    
1154
  $url = url('cdm_api/setvalue/session', array('query' => NULL));
1155
  $form['#action'] = $url;
1156

    
1157
  $form['var'] = array(
1158
    '#weight' => -3,
1159
    '#type' => 'hidden',
1160
    '#value' => '[cdm][taxonomictree_uuid]',
1161
  );
1162

    
1163
  $destination_array = drupal_get_destination();
1164
  $destination = $destination_array['destination'];
1165

    
1166
  $form['destination'] = array(
1167
    '#weight' => -3,
1168
    '#type' => 'hidden',
1169
    '#value' =>  $destination,
1170
  );
1171
  $options = cdm_get_taxontrees_as_options(
1172
    FALSE,
1173
    variable_get(CDM_TAXONTREE_INCLUDES, [])
1174
  );
1175
  $form['val'] = array(
1176
    '#type' => 'select',
1177
    '#title' => t('Available classifications'),
1178
    '#default_value' => get_current_classification_uuid(),
1179
    '#options' => $options,
1180
    '#attributes' => array('class' => array('highlite-first-child')),
1181
  );
1182

    
1183
  return $form;
1184

    
1185
}
1186

    
1187
/**
1188
 *
1189
 * @ingroup compose
1190
 */
1191
function compose_classification_selector() {
1192

    
1193
  $destination_array = drupal_get_destination();
1194
  $destination = $destination_array['destination'];
1195

    
1196
  $options = cdm_get_taxontrees_as_options(
1197
    FALSE,
1198
    variable_get(CDM_TAXONTREE_INCLUDES, [])
1199
  );
1200
  $items = array();
1201

    
1202
  $current_classification_uuid = get_current_classification_uuid();
1203

    
1204

    
1205
  foreach($options as $uuid=>$label){
1206
    $class_attributes = '';
1207
    if($current_classification_uuid == $uuid){
1208
      $class_attributes  = array('focused');
1209
    }
1210
    $items[] = array(
1211
      'data' => l($label,
1212
        'cdm_api/setvalue/session',
1213
        array(
1214
          'query' => array(
1215
            'destination' => $destination,
1216
            'val' => $uuid,
1217
            'var' => '[cdm][taxonomictree_uuid]'
1218
          ),
1219
        )
1220
      ),
1221
      'class' => $class_attributes
1222
    );
1223
  }
1224

    
1225
  $render_array = array(
1226
    '#theme' => 'item_list',
1227
    '#type' => 'ul',
1228
    '#items' => $items
1229
  );
1230

    
1231
  return $render_array;
1232
}
1233

    
1234

    
1235
/* ====================== menu callback functions ====================== */
1236
/**
1237
 * @todo Please document this function.
1238
 * @see http://drupal.org/node/1354
1239
 */
1240
/*
1241
function cdm_dataportal_form_alter(&$form, &$form_state, $form_id) {
1242
  static $comment_node_disabled =  0;
1243
  static $comment_node_read_only =  1;
1244
  static $comment_node_read_write =  2;
1245

    
1246
  if ($form_id == 'node_type_form'
1247
   && isset($form['identity']['type'])
1248
   && array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
1249
  ) {
1250
    $form['workflow']['comment'] = array(
1251
      '#type' => 'radios',
1252
      '#title' => t('Default comment setting'),
1253
      '#default_value' => variable_get('comment__' . $node->type . $form['#node_type']->type, $comment_node_disabled),
1254
      '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
1255
      '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
1256
    );
1257
  }
1258
}
1259
*/
1260

    
1261
/**
1262
 * Displays a list of the known taxonomic names.
1263
 *
1264
 * When the list of taxonomic names is displayed, long lists are split up into
1265
 * multiple pages.
1266
 *
1267
 * TODO: Parameters are still preliminary.
1268
 *
1269
 * @param string $beginsWith
1270
 * @param string $page
1271
 *   Page number to diplay defaults to page 1.
1272
 * @param bool $onlyAccepted
1273
 */
1274
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = FALSE) {
1275

    
1276
  $out = t('<h3>Sorry, the name list feature is not yet available in this version of the DataPortal software<h3>');
1277

    
1278
  /*
1279
  // FIXME the filter for accepted names will be a form element, thus this
1280
  // widget should be generated via form api preferably as block.
1281
  $out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
1282
  $out .= theme('cdm_dataportal_widget_names_list', $names, $page);
1283
  $out .= theme('cdm_listof_taxa', $taxonPager);
1284
  return $out;
1285
  */
1286
}
1287

    
1288
/**
1289
 * @todo Please document this function.
1290
 * @see http://drupal.org/node/1354
1291
 * @throws Exception
1292
 */
1293
function cdm_dataportal_view_reference($uuid, $arg2 = NULL) {
1294

    
1295
  cdm_check_valid_portal_page();
1296

    
1297
  return compose_cdm_reference_page($uuid);
1298
}
1299

    
1300
/**
1301
 * Creates a view on a all references contained in the portal.
1302
 *
1303
 * This function is used at the path cdm_dataportal/reference/list
1304
 */
1305
function cdm_dataportal_view_reference_list($pageNumber) {
1306
  $referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get(CDM_SEARCH_RESULT_PAGE_SIZE, CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT), $pageNumber);
1307
  cdm_reference_pager($referencePager, 'cdm_dataportal/reference/list/');
1308
}
1309

    
1310
/**
1311
 * @todo Please document this function.
1312
 * @see http://drupal.org/node/1354
1313
 */
1314
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = FALSE, $part = 0) {
1315

    
1316
  cdm_check_valid_portal_page();
1317

    
1318
  $media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
1319
  if (!$media) {
1320
    drupal_set_title(t('Media does not exist'), PASS_THROUGH);
1321
    return "";
1322
  }
1323
  return theme('cdm_media_page', array(
1324
    'media' => $media,
1325
    'mediarepresentation_uuid' => $mediarepresentation_uuid,
1326
    'partId' => $part,
1327
    ));
1328
}
1329

    
1330
/**
1331
 * Loads the media associated to the given taxon from the cdm server.
1332
 * The aggregation settings regarding taxon relathionships and
1333
 * taxonnomic childen are taken into account.
1334
 *
1335
 * The media lists are cached in a static variable.
1336
 *
1337
 * @param Taxon $taxon
1338
 *   A CDM Taxon entity
1339
 *
1340
 * @return array
1341
 *   An array of CDM Media entities
1342
 *
1343
 */
1344
  function _load_media_for_taxon($taxon) {
1345

    
1346
  static $media = NULL;
1347

    
1348
  if(!isset($media)) {
1349
    $media = array();
1350
  }
1351
  if (!isset($media[$taxon->uuid])) {
1352

    
1353

    
1354
    $mediaQueryParameters = taxon_media_query_parameters();
1355

    
1356
    $ws_endpoint = NULL;
1357
    if ( $mediaQueryParameters['includeTaxonomicChildren']) {
1358
      $ws_endpoint = CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA;
1359
    } else {
1360
      $ws_endpoint = CDM_WS_PORTAL_TAXON_MEDIA;
1361
    }
1362
    // this parameter is not yet used by the CDM_WS_PORTAL_TAXON_*MEDIA
1363
    // services
1364
    unset($mediaQueryParameters['includeTaxonomicChildren']);
1365

    
1366
    $media[$taxon->uuid] = cdm_ws_get($ws_endpoint,
1367
        array(
1368
            $taxon->uuid,
1369
        ),
1370
        queryString($mediaQueryParameters)
1371
       );
1372
  }
1373

    
1374
  return $media[$taxon->uuid];
1375
}
1376

    
1377
/**
1378
 *
1379
 * @param Taxon $taxon
1380
 *   A CDM Taxon entitiy
1381
 *
1382
 * @return array
1383
 *   An array of CDM SpecimenOrObservation entities
1384
 *
1385
function _load_occurences_for_taxon($taxon){
1386

    
1387
  static $occurences = NULL;
1388

    
1389
  if(!isset($occurences)) {
1390
    $occurences = array();
1391
  }
1392

    
1393
  if (!isset($occurences[$taxon->uuid])){
1394

    
1395
    $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1396
    $relationship_choice['direct'] = get_selection($relationship_choice['direct']);
1397
    $relationship_choice['invers'] = get_selection($relationship_choice['invers']);
1398

    
1399
    $by_associatedtaxon_query = http_build_query(array(
1400
        'relationshipsInvers' => implode(',', $relationship_choice['invers']),
1401
        'relationships' => implode(',', $relationship_choice['direct']),
1402
        'pageSize' => null // all hits in one page
1403
    )
1404
    );
1405

    
1406
    $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
1407
        null,
1408
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
1409
    );
1410

    
1411

    
1412
    if(isset($pager->records[0])){
1413
      $occurences[$taxon->uuid] =  $pager->records;
1414
    }
1415
  }
1416
  return $occurences[$taxon->uuid];
1417
}
1418
 */
1419

    
1420
/**
1421
 * Gets a Drupal variable, string or array and returns it.
1422
 *
1423
 * Similar to the variable_get() function of Drupal, except that this function
1424
 * is able to handle arrays correctly. This function is especially useful
1425
 * when dealing with collections of settings form elements (#tree = TRUE).
1426
 *
1427
 * @param string $variableKey
1428
 *   The Unique key of the Drupal variable in the Drupal variables table.
1429
 * @param string $defaultValueString
1430
 *   A string as for example derived from a CONSTANT.
1431
 *
1432
 * @return mixed
1433
 *   usually an array, depending on the nature of the variable.
1434
 *
1435
 * TODO compare with get_array_variable_merged() duplicate functions?
1436
 * @deprecated rather use get_array_variable_merged() since this function
1437
 * used an array as second parameter
1438
 */
1439
function mixed_variable_get($variableKey, $defaultValueString) {
1440
  $systemDefaults = unserialize($defaultValueString);
1441
  $storedSettings = variable_get($variableKey, array());
1442
  if (is_array($storedSettings)) {
1443
    // TODO better use drupal_array_merge_deep() ?
1444
    $settings = array_merge($systemDefaults, $storedSettings);
1445
  }
1446
  else {
1447
    $settings = $systemDefaults;
1448
  }
1449
  return $settings;
1450
}
1451

    
1452
/**
1453
 * Recursive function to convert an object into an array.
1454
 * also subordinate objects will be converted.
1455
 *
1456
 * @param object $object
1457
 *  the object to be converted
1458
 * @return array
1459
 *  The array
1460
 */
1461
function object_to_array($object) {
1462
  if(is_object($object) || is_array($object)) {
1463
    $array = (array)$object;
1464
    foreach ($array as $key=>$value){
1465
      $array[$key] = object_to_array($value);
1466
    }
1467
    return $array;
1468
  } else {
1469
    return $object;
1470
  }
1471
}
1472

    
1473
/**
1474
 * Searches the $collection for the cdm entitiy given as $element.
1475
 *
1476
 * The elements are compared by their UUID.
1477
 *
1478
 * @param $element
1479
 *  the CDM entitiy to search for
1480
 * @param $collection
1481
 *  the list of CDM entities to search in
1482
 *
1483
 * @return boolean TRUE if the $collection contains the $element, otheriwse FALSE
1484
 *
1485
 */
1486
function contains_cdm_entitiy($element, $collection) {
1487
  $result = FALSE;
1488
  foreach ($collection as $a) {
1489
    if ($a->uuid == $element->uuid) {
1490
      $result = TRUE;
1491
    }
1492
  }
1493
  return $result;
1494
}
1495

    
1496
/**
1497
 * Filters the array $entity_list of CDM entities by the list
1498
 * of $excludes. Any element contained in the $excludes will be removed
1499
 * from included int the returned list.
1500
 *
1501
 * If the $entity_list is not an array the $excludes will be returned.
1502
 */
1503
function filter_cdm_entity_list($entity_list, $excludes) {
1504
  if (is_array($entity_list)) {
1505
    $result = $entity_list;
1506
    if ($excludes) {
1507
      foreach ($excludes as $exclude) {
1508
        if (!contains_cdm_entitiy($exclude, $entity_list)) {
1509
          $result[] = $exclude;
1510
        }
1511
      }
1512
    }
1513
  }
1514
  else {
1515
    $result = $excludes;
1516
  }
1517
  return $result;
1518
}
1519

    
1520
/**
1521
 * Wraps the given $html string into a render array suitable for drupal_render()
1522
 *
1523
 * @param $html
1524
 *   the html string, see
1525
 *   http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#markup
1526
 * @param $weight
1527
 *   A positive or negative number (integer or decimal).
1528
 *   see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#weightval
1529
 * @param $prefix
1530
 *   Optional markup for the '#prefix' element of the render array
1531
 * @param $suffix
1532
 *   Optional markup for the '#suffix' element of the render array
1533
 *
1534
 * @return array
1535
 *   A render array
1536
 *
1537
 */
1538
function markup_to_render_array($html, $weight = FALSE, $prefix = NULL, $suffix = NULL) {
1539
  $render_array = array(
1540
    '#markup' => $html
1541
      );
1542
  if (is_numeric($weight)) {
1543
    $render_array['#weight'] = $weight;
1544
  }
1545
  if($prefix){
1546
    $render_array['#prefix'] = $prefix;
1547
  }
1548
  if($suffix) {
1549
    $render_array['#suffix'] = $suffix;
1550
  }
1551
  return $render_array;
1552
}
1553

    
1554
/**
1555
 * Loads the subgraph of a given PolytomousKeyNode.
1556
 *
1557
 * Loads the subgraph of the given PolytomousKeyNode recursively from
1558
 * the CDM REST service.
1559
 *
1560
 * @param mixed $polytomousKeyNode
1561
 *   PolytomousKeyNode passed by reference.
1562
 *
1563
 * @return void
1564
 */
1565
function _load_polytomousKeySubGraph(&$polytomousKeyNode) {
1566

    
1567
  if (!$polytomousKeyNode) {
1568
    return;
1569
  }
1570
  if ($polytomousKeyNode->class != "PolytomousKeyNode") {
1571
    drupal_set_message('_load_polytomousKeySubGraph(): ' . t('invalid type given.'), 'error');
1572
    return;
1573
  }
1574
  if (!is_uuid($polytomousKeyNode->uuid)) {
1575
    drupal_set_message('_load_polytomousKeySubGraph(): ' . t('invalid type given.'), 'error');
1576
    return;
1577
  }
1578

    
1579
  $polytomousKeyNode = cdm_ws_get(CDM_WS_PORTAL_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid);
1580

    
1581
  if (!$polytomousKeyNode) {
1582
    // drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error");
1583
    return;
1584
  }
1585

    
1586
  // Load children.
1587
  foreach ($polytomousKeyNode->children as &$childNode) {
1588
    _load_polytomousKeySubGraph($childNode);
1589
  }
1590
  return;
1591
}
1592

    
1593
/**
1594
 * @todo Please document this function.
1595
 * @see http://drupal.org/node/1354
1596
 */
1597
function cdm_dataportal_view_polytomousKey($polytomousKeyUuid) {
1598

    
1599
  cdm_check_valid_portal_page();
1600

    
1601
  $polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid);
1602
  if (!$polytomousKey) {
1603
    drupal_set_title(t('Polytomous key does not exist'), PASS_THROUGH);
1604
    return "";
1605
  }
1606

    
1607
  $sourcePager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources'));
1608
  if (is_array($sourcePager->records)) {
1609
    $polytomousKey->sources = $sourcePager->records;
1610
    // $polytomousKey->sources->citation = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources'));
1611
  }
1612

    
1613
  $annotationPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'annotations'));
1614
  if (is_array($annotationPager->records)) {
1615
    $polytomousKey->annotations = $annotationPager->records;
1616
  }
1617

    
1618
  _load_polytomousKeySubGraph($polytomousKey->root);
1619
  return theme('cdm_polytomousKey_page', array('polytomousKey' => $polytomousKey));
1620
}
1621

    
1622
/**
1623
 * Creates a taxon page view or a chapter of it.
1624
 *
1625
 * The taxon page gives detailed information on a taxon, it shows:
1626
 *  - Taxon name.
1627
 *  - Full list of synonyms homotypic synonyms on top, followed by the
1628
 *    heterotypic and finally followed by misapplied names.
1629
 *    The list is ordered historically.
1630
 *  - All description associated with the taxon.
1631
 *
1632
 * @param string $uuid
1633
 * @param string $chapter
1634
 *   Name of the part to display, valid values are:
1635
 *   'description', 'images', 'synonymy', 'specimens', 'all'.
1636
 *
1637
 * @return string
1638
 */
1639
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all') {
1640

    
1641
  cdm_check_valid_taxon_page($chapter);
1642
  cdm_dd("START OF TAXON PAGE [" . $chapter . "] " . $uuid . ' for ' . $_GET['q']);
1643

    
1644

    
1645
  // Display the page for the taxon defined by $uuid.
1646
  // set_last_taxon_page_tab(arg(3));
1647
  $taxonpage = cdm_dataportal_taxon_view($uuid, $chapter);
1648
  if (!empty($taxonpage)) {
1649
    cdm_dd("END OF TAXON PAGE [" . $chapter . "] " . $uuid);
1650
    return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title, $taxonpage->content);
1651
  }
1652
  else {
1653
    cdm_dd("END OF TAXON PAGE [" . $chapter . "] " . $uuid . ' !!! PAGE IS EMPTY !!!');
1654
    return '';
1655
  }
1656
}
1657

    
1658
/**
1659
 * This function will generate the taxon page part ($chapter) and returns a taxonpage object
1660
 * which has two fields, one for the page title and one for the content. Later on in the
1661
 * process chain the value contained in these fields will be passed to the cdm_node_show()
1662
 * function as the function parameters $title and $content.
1663
 *
1664
 * @param string $uuid
1665
 *   the uuid of the taxon to show
1666
 * @param string $chapter
1667
 *   Name of the part to display, valid values are:
1668
 *   'description', 'images', 'synonymy', 'all'.
1669
 *
1670
 * @return object with the following fields:
1671
 *   - title : the title of the page
1672
 *   - content: the content of the page
1673
 *
1674
 * @throws Exception
1675
 *
1676
 */
1677
function cdm_dataportal_taxon_view($uuid, $chapter = 'all') {
1678
  // Taxon object.
1679
  $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1680
  if (empty($taxon)) {
1681
    drupal_set_title(t('Taxon does not exist'), PASS_THROUGH);
1682
    return null;
1683
  }
1684
  $taxonpage = new stdClass();
1685

    
1686
  $taxonpage->title = theme('cdm_taxon_page_title', array(
1687
    'taxon' => $taxon
1688
  ));
1689

    
1690
  // Check if the taxon id contained in the currently selected tree.
1691
  $taxon_in_current_classification = taxon_in_current_classification($uuid);
1692

    
1693
  if (!$taxon_in_current_classification) {
1694
    $classifications = get_classifications_for_taxon($taxon);
1695
    RenderHints::pushToRenderStack('not_in_current_classification');
1696
    RenderHints::setFootnoteListKey('not_in_current_classification');
1697
    FootnoteManager::blockFootnotesFor('not_in_current_classification');
1698
    $taxon_name_markup = render_taxon_or_name($taxon);
1699
    FootnoteManager::unblockFootnotesFor('not_in_current_classification');
1700
    RenderHints::clearFootnoteListKey();
1701

    
1702
    if (count($classifications) == 0) {
1703
      drupal_set_message(t('This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification.',
1704
        array(
1705
        '!taxonname' => $taxon_name_markup,
1706
        )
1707
      ), 'warning');
1708
    }
1709
    else {
1710
      $trees = '';
1711
      foreach ($classifications as $classification) {
1712
        if (isset($classification->titleCache)) {
1713
          $trees .= ($trees ? ', ' : '') . '<strong>' . $classification->titleCache . '</strong>';
1714
        }
1715
      }
1716

    
1717
      drupal_set_message(format_plural(count($trees),
1718
          'This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification, but in this one: !trees',
1719
          'This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification, but in one of these: !trees',
1720
          array('!taxonname' => $taxon_name_markup, '!trees' => $trees)
1721
        ) ,
1722
        'warning');
1723
    }
1724
    RenderHints::popFromRenderStack();
1725
  }
1726

    
1727
  // Render the taxon page.
1728
  $render_array = compose_cdm_taxon_page($taxon, $chapter);
1729
  $taxonpage->content = drupal_render($render_array);
1730

    
1731
  return $taxonpage;
1732
}
1733

    
1734

    
1735
function cdm_dataportal_specimen_by_accession_number_page_view($accession_number)
1736
{
1737
  cdm_check_valid_portal_page();
1738

    
1739
  $specimenpage = specimen_by_accession_number_view($accession_number);
1740

    
1741
  if (!empty($specimenpage)) {
1742
    return cdm_node_show_simulate($specimenpage->content);
1743
  }
1744
  else {
1745
    return '';
1746
  }
1747

    
1748

    
1749
}
1750

    
1751
/**
1752
 * Creates a specimen page view.
1753
 * @param string $uuid the UUID of the specimen
1754
 * @return array|string
1755
 */
1756
function cdm_dataportal_specimen_page_view($uuid) {
1757

    
1758
    cdm_check_valid_portal_page();
1759
    $specimenpage = cdm_dataportal_specimen_view($uuid);
1760
    if (!empty($specimenpage)) {
1761
        return cdm_node_show_simulate($specimenpage->content);
1762
    }
1763
    else {
1764
        return '';
1765
    }
1766
}
1767

    
1768

    
1769
/**
1770
 * Creates a specimen page view.
1771
 * @param string $uuid the UUID of the specimen
1772
 * @return object
1773
 *  The page object with the following fields:
1774
 *   - 'title': the page title
1775
 *   - 'content' : the page content rendered as markup
1776
 */
1777
function specimen_by_accession_number_view($accession_number = null) {
1778

    
1779
  $field_unit_dto = cdm_ws_get(CDM_WS_OCCURRENCE_ACCESSION_NUMBER, null, 'accessionNumber=' . $accession_number);
1780

    
1781
  // Display the page for the specimen defined by $uuid.
1782
  if (isset($field_unit_dto)){
1783
    $dto_array = array($field_unit_dto);
1784
    $specimen_array = specimen_render_array_items($dto_array);
1785
    $specimen_table = array(
1786
      '#theme' => 'table',
1787
      '#weight' => 2,
1788
      // prefix attributes and rows with '#' to let it pass toF the theme function,
1789
      // otherwise it is handled as child render array
1790
      '#attributes' => array('class' => 'specimens'),
1791
      '#rows' => array(),
1792
      '#prefix' => '<div id="specimens">',
1793
      '#suffix' => '</div>',
1794
    );
1795
    foreach($specimen_array as $value){
1796
      $renderArray = array(
1797
        '#theme' => 'item_list',
1798
        '#items' => array($value),
1799
        '#type' => 'ul');
1800
      $output = drupal_render($renderArray);
1801
      $specimen_table['#rows'][] = array(
1802
        // An array of table rows. Every row is an array of cells, or an associative array
1803
        'data' => array($output),
1804
        'class' =>  array(
1805
          'descriptionElement',
1806
          'descriptionElement_IndividualsAssociation'
1807
        ),
1808
      );
1809

    
1810

    
1811
    }
1812
    $specimenpage = new stdClass();
1813

    
1814
    $specimenpage->title = render_cdm_specimen_dto_page_title($field_unit_dto);
1815

    
1816
     $render_array['markup'] = $specimen_table;
1817
     $specimenpage->content = drupal_render($render_array);
1818
  }
1819

    
1820
  return $specimenpage;
1821
}
1822

    
1823

    
1824
/**
1825
 *
1826
 * Creates a specimen view.
1827
 * @param string $uuid the UUID of the specimen
1828
 * @return object
1829
 *    Page object with the fields
1830
 *    - title
1831
 *    - content
1832
 */
1833
function cdm_dataportal_specimen_view($uuid) {
1834

    
1835
    $sob_dto = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE_AS_DTO, $uuid);
1836
    if (empty($sob_dto)) {
1837
        drupal_set_title(t('Specimen does not exist'), PASS_THROUGH);
1838
        return FALSE;
1839
    }
1840
    $specimenpage = new stdClass();
1841
    $specimenpage->title = render_specimen_page_title($sob_dto);
1842

    
1843
    // Render the specimen page.
1844
    $render_array = compose_cdm_specimen_page($sob_dto);
1845
    $specimenpage->content = drupal_render($render_array);
1846

    
1847
    return $specimenpage;
1848
}
1849

    
1850
/**
1851
 *
1852
 * Creates a description view.
1853
 *
1854
 * @param string $uuid the UUID of the description
1855
 * @param null $descriptive_dataset_uuid the uuid of the data set which defines
1856
 * the display of the description detail page
1857
 *
1858
 * @return object Page object with the fields
1859
 * Page object with the fields
1860
 * - title
1861
 * - content
1862
 */
1863
function cdm_dataportal_description_view($uuid, $descriptive_dataset_uuid = NULL) {
1864
    $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $uuid);
1865
    $description_page = new stdClass();
1866
    if (empty($description)) {
1867
      $description_page->title = t('Description does not exist');
1868
      drupal_set_title($description_page->title, PASS_THROUGH); // not necessary if correctly implemented as drupal node
1869
      $description_page->content = "";
1870

    
1871
    } else {
1872
      $description_page->title = $description->titleCache;
1873
      drupal_set_title($description_page->title); // not necessary if correctly implemented as drupal node
1874

    
1875
      // Render the description page.
1876
      $render_array = compose_description_table($description->uuid, $descriptive_dataset_uuid);
1877
      if($render_array['title']){
1878
        $page_title = strip_tags($render_array['title']['#markup']);
1879
        drupal_set_title($page_title);
1880
        unset($render_array['title']);
1881
      }
1882
      $description_page->content = drupal_render($render_array);
1883
    }
1884

    
1885
    return $description_page;
1886
}
1887

    
1888
function cdm_dataportal_description_page_view($uuid, $descriptive_dataset_uuid = NULL) {
1889

    
1890
  cdm_check_valid_portal_page();
1891
  $descriptionpage = cdm_dataportal_description_view($uuid, $descriptive_dataset_uuid);
1892
  if (!empty($descriptionpage)) {
1893
    return cdm_node_show_simulate($descriptionpage->content);
1894
  }
1895
  else {
1896
    return NULL;
1897
  }
1898
}
1899

    
1900
/**
1901
 *
1902
 * Creates a named area view.
1903
 * @param string $uuid the UUID of the specimen
1904
 *  * @return object
1905
 *   An object with two fields:
1906
 *     - title: the page title
1907
 *     - content: the page content
1908
 */
1909

    
1910
function cdm_dataportal_named_area_view($uuid) {
1911
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, $uuid);
1912
  if (empty($named_area) || $named_area->class !== 'NamedArea') {
1913
    drupal_set_title(t('Named area does not exist'), PASS_THROUGH);
1914
    return null;
1915
  }
1916
  $named_area_page = new stdClass();
1917

    
1918
  $named_area_page->title = $named_area->representation_L10n;
1919

    
1920
  // Render the specimen page.
1921
  $render_array = compose_cdm_named_area_page($uuid);
1922
  $named_area_page->content = drupal_render($render_array);
1923

    
1924
  return $named_area_page;
1925
}
1926

    
1927
function cdm_dataportal_named_area_page_view($uuid) {
1928

    
1929
  cdm_check_valid_portal_page();
1930

    
1931
  $named_area_page = cdm_dataportal_named_area_view($uuid);
1932
  if (!empty($named_area_page)) {
1933
    return cdm_node_show(NODETYPE_NAME, $uuid, $named_area_page->title, $named_area_page->content);
1934
  }
1935
  else {
1936
    return '';
1937
  }
1938

    
1939

    
1940
}
1941

    
1942
/**
1943
 * Returns a name page as a Drupal node ready to be renderized by Drupal.
1944
 *
1945
 * The node page shows the taxon name title and the list of taxon related
1946
 * with such taxon. Name on the tree already in use.
1947
 *
1948
 * @param string $taxon_name_uuid
1949
 *   The uuid of the CDM TaxonName to show a name page for
1950
 * @param string $taxon_to_hide_uuid
1951
 *   A taxon which should not be displayed in the taxon list
1952
 * @param $redirect_to_taxon
1953
 *   Automatically redirect to the related taxon if there is only one
1954
 *   accepted taxon for this name.
1955
 * @param string $highlite_synonym_uuid
1956
 *   Optinal parameter wich takes another taxon uuid, if given the
1957
 *   target taxon pages will show the syonymy tab where the taxon
1958
 *   refenrenced by the $highlite_synonym_uuid will be highlighted
1959
 *   in case it is found on this page.
1960
 *
1961
 * @return mixed
1962
 *   The formatted name page as node.
1963
 */
1964
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = NULL, $redirect_to_taxon = false) {
1965

    
1966
  cdm_check_valid_portal_page();
1967

    
1968
  $taxonname_page = cdm_dataportal_name_view(
1969
    is_uuid($taxon_name_uuid) ? $taxon_name_uuid : null,
1970
    is_uuid($taxon_to_hide_uuid) ? $taxon_to_hide_uuid : null,
1971
    $redirect_to_taxon == 'redirect_to_taxon',
1972
    is_uuid($synonym_uuid) ? $synonym_uuid : null);
1973
  if (!empty($taxonname_page)) {
1974
    return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title, $taxonname_page->content);
1975
  }
1976
  else {
1977
    return '';
1978
  }
1979
}
1980

    
1981
/**
1982
 * View function for a TaxonName page.
1983
 *
1984
 * The name page lists all taxa for which the name specified by the
1985
 * $taxon_name_uuid is being used. I case there is only one name the
1986
 * page automatically redirects ti the according taxon page. Otherwise
1987
 * the list of names is displayed.
1988
 *
1989
 * The parameter $taxon_to_hide_uuid allows to exclude a taxon from the
1990
 * list of taxa. This is useful for example when referencing from a taxon
1991
 * to the name page and the referring taxon should not be repeaded in the
1992
 * name page.
1993
 *
1994
 *
1995
 * @param string $taxon_name_uuid
1996
 *   The uuid of the CDM TaxonName to show a name page for
1997
 * @param string $taxon_to_hide_uuid
1998
 *   A taxon which should not be displayed in the taxon list
1999
 * @param $redirect_to_taxon
2000
 *   Automatically redirect to the related taxon if there is only one
2001
 *   accepted taxon for this name.
2002
 * @param string $highlite_synonym_uuid
2003
 *   Optional parameter which takes another taxon uuid, if given the
2004
 *   target taxon pages will show the synonymy tab where the taxon
2005
 *   referenced by the $highlite_synonym_uuid will be highlighted
2006
 *   in case it is found on this page.
2007
 *
2008
 * @return object|boolean
2009
 *   An object with two fields:
2010
 *     - title: the page title
2011
 *     - content: the page content
2012
 *   or FALSE
2013
 *
2014
 */
2015
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $redirect_to_taxon, $highlite_synonym_uuid = NULL) {
2016
  // Getting the full taxonname object from the server.
2017
  $taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, array($taxon_name_uuid));
2018
  if (!$taxon_name) {
2019
    drupal_set_title(t('Taxon name does not exist'), PASS_THROUGH);
2020
    return FALSE;
2021
  }
2022
  cdm_load_tagged_full_title($taxon_name);
2023
  // Searching for all the taxa connected with the taxon name on the tree
2024
  // in use.
2025
  $name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
2026
  $restrictions = array(new Restriction("name.titleCache","EXACT", array($name->titleCache), 'AND'));
2027
  $init_strategy = array(
2028
    "name.titleCache",
2029
    "name.nomenclaturalReference.authorship",
2030
    "name.nomenclaturalReference.inReference.authorship",
2031
    "name.nomenclaturalReference.inReference.inReference.authorship",
2032
    "name.nomenclaturalReference.inReference.inReference.inReference.authorship"
2033
  );
2034
  $taxa = cdm_ws_fetch_all_by_restriction("Taxon", NULL, $restrictions, $init_strategy);
2035

    
2036
  // Removing the name where we came from.
2037
  foreach ($taxa as $k => &$taxon) {
2038
    if ($taxon->uuid == $taxon_to_hide_uuid) {
2039
      unset($taxa[$k]);
2040
    }
2041
  }
2042
  // Show the taxa list or go to the singular taxon.
2043
  if (sizeof($taxa) == 1 && $redirect_to_taxon) {
2044
    // redirect to the taxon if there is only one.
2045
    $singleTaxon = array_pop($taxa);
2046
    if ($singleTaxon->class != "Taxon") {
2047
      // It is a Synonym -> look for the accepted.
2048
      $accepted_taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($singleTaxon->uuid), 'classificationFilter=' . get_current_classification_uuid());
2049
      if (!empty($highlite_synonym_uuid)) {
2050
        drupal_goto('cdm_dataportal/taxon/' . $accepted_taxon->uuid . '/synonymy', array('query' => array('highlite' => $highlite_synonym_uuid)));
2051
      }
2052
      else {
2053
        drupal_goto('cdm_dataportal/taxon/' . $accepted_taxon->uuid . '/synonymy', array('query' => array('highlite' => $singleTaxon->uuid)));
2054
      }
2055
    }
2056
    else {
2057
      // It is an accepted taxon.
2058
      if (!empty($highlite_synonym_uuid)) {
2059
        drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid . '/synonymy', array('query' => array('highlite' => $highlite_synonym_uuid)));
2060
      }
2061
      else {
2062
        drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid);
2063
      }
2064
    }
2065
  }
2066
  else {
2067
    // display the name page content
2068
    $taxon_name_page = new stdClass();
2069
    $taxon_name_page->title = theme('cdm_name_page_title', array('taxon_name' => $taxon_name));
2070
    $content = array();
2071

    
2072
    RenderHints::pushToRenderStack('name_page');
2073
    RenderHints::setFootnoteListKey('name_page');
2074
    $content['taxon_name'] = markup_to_render_array(render_taxon_or_name($taxon_name), null, '<div class="name-page-name">', '</div>');
2075

    
2076

    
2077
    // name relationships
2078
    $name_relations = cdm_ws_fetch_all(str_replace("$0", $taxon_name->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
2079
    if(count($name_relations) > 0){
2080
      $content['name_relationships'] = compose_name_relationships_list($name_relations, $taxon_name->uuid, null);
2081
    }
2082

    
2083
    // type designations
2084
    $type_designations_render_array = compose_type_designations($taxon_name->uuid);
2085
    $content = array_merge($content, $type_designations_render_array);
2086
    // registrations
2087
    $registrationDTOs= cdm_ws_fetch_all(CDM_WS_REGISTRATION_DTO,  array('nameUuid' => $taxon_name_uuid));
2088
    if(isset($registrationDTOs) && count($registrationDTOs ) > 0 ){
2089
      $content['registrations'][] = markup_to_render_array('<h2>' . t("Registrations") . '</h2>') ;
2090
      foreach ($registrationDTOs as $regDTO){
2091
        $content['registrations'][] = compose_registration_dto_compact($regDTO);
2092
      }
2093
    }
2094

    
2095

    
2096
    // related taxa
2097
    $show_taxa_section = variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT);
2098
    if($show_taxa_section){
2099
      if ($taxa) {
2100
        $content['related_taxa_header'] = markup_to_render_array("<h2>" . count($taxa) > 1 ? t("Taxa for this name") :  t("Taxon for this name") . "</h2>");
2101
        $content['related_taxa'] = compose_list_of_taxa($taxa);
2102
      }
2103
      else {
2104
        $content['related_taxa'] = markup_to_render_array('This name is not assigned to any taxon.', null, '<div class="no-taxon-message">', '</div>');
2105
      }
2106
    }
2107

    
2108
    $content['footnotes'] = markup_to_render_array(render_footnotes());
2109

    
2110
    $taxon_name_page->content = $content;
2111
    RenderHints::popFromRenderStack();
2112
    RenderHints::clearFootnoteListKey();
2113
    return $taxon_name_page;
2114
  }
2115
}
2116

    
2117

    
2118
/**
2119
 * Returns a registration page as a Drupal node to be rendered by Drupal.
2120
 *
2121
 * @param string  $registration_identifie
2122
 *   The persistent identifier of the registration urlencoded.
2123
 * @return mixed
2124
 *   The formatted registration page as node.
2125
 */
2126
function cdm_dataportal_registration_page_view() {
2127

    
2128
  cdm_check_valid_portal_page("/\/cdm_dataportal\/registration/");
2129
  $registration_identifier = $_REQUEST['identifier'];
2130
  $registration_page = cdm_dataportal_registration_view($registration_identifier);
2131
  return cdm_node_show_simulate($registration_page);
2132
}
2133

    
2134
/**
2135
 * @param $registration_identifier
2136
 * @return array
2137
 *   The drupal render array for the registration view.
2138
 */
2139
function cdm_dataportal_registration_view($registration_identifier) {
2140

    
2141
  RenderHints::pushToRenderStack('registration_page');
2142
  RenderHints::setFootnoteListKey('registration_page');
2143

    
2144
  $render_array = array();
2145
  $registration_dto = cdm_ws_get(CDM_WS_REGISTRATION_DTO, null, 'identifier=' . $registration_identifier);
2146
  if($registration_dto){
2147

    
2148
    drupal_set_title(t('Registration Id:') . ' ' . $registration_identifier, PASS_THROUGH);
2149
    $render_array = compose_registration_dto_full($registration_dto, true);
2150

    
2151
  } else {
2152
    $status_text = cdm_ws_get(CDM_WS_REGISTRATION_STATUS, null, 'identifier=' . $registration_identifier);
2153
    if(isset($status_text->String)) {
2154
      $status_text = strtolower($status_text->String);
2155
      if($status_text == 'preparation' || $status_text == 'curation'){
2156
        $status_text = 'in ' . $status_text;
2157
      }
2158
      drupal_set_title(t('Registration ' . $status_text), PASS_THROUGH);
2159
      //$status_message;
2160
      drupal_set_message("A registration with the identifier  " . $registration_identifier . " is " . $status_text, "status");
2161
    } else {
2162
      drupal_set_title(t('Registration not found'), PASS_THROUGH);
2163
      drupal_set_message("A registration with the identifier  " . $registration_identifier . " does not exist", "warning");
2164
    }
2165
  }
2166

    
2167
  $render_array = array(
2168
    '#prefix' => '<div id="registration">',
2169
    'registration' => $render_array,
2170
    '#suffix' => '</div>',
2171
  );
2172

    
2173
  RenderHints::popFromRenderStack();
2174
  RenderHints::clearFootnoteListKey();
2175

    
2176
  return $render_array ;
2177
}
2178

    
2179

    
2180
/**
2181
 * Creates a page with the advance search form.
2182
 *
2183
 * NOTE: The advance search form allows searching for taxa.
2184
 */
2185
function cdm_dataportal_view_search_advanced() {
2186
  drupal_set_title(t('Advanced search'), PASS_THROUGH);
2187
  return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
2188
}
2189

    
2190
/**
2191
 * Creates a page with the blast search form.
2192
 *
2193
 * NOTE: The advance search form allows searching for specimen in blast DB.
2194
 */
2195
function cdm_dataportal_view_search_blast() {
2196
    drupal_set_title(t('Blast search'), PASS_THROUGH);
2197
    return drupal_get_form('cdm_dataportal_search_blast_form');
2198
}
2199

    
2200
/**
2201
 * Creates a page with the search form for searching by taxon descriptions.
2202
 */
2203
function cdm_dataportal_view_search_taxon_by_description() {
2204
  drupal_set_title(t('Search by factual data'), PASS_THROUGH);
2205
  return drupal_get_form('cdm_dataportal_search_taxon_by_description_form');
2206
}
2207

    
2208
/**
2209
 * Executes the search and generates the result list of taxa.
2210
 */
2211
function cdm_dataportal_view_search_results_taxon() {
2212

    
2213
  $taxonPager = cdm_dataportal_search_taxon_execute();
2214

    
2215
  $showThumbnails = do_showThumbnails();
2216

    
2217
  $setSessionUri = url('cdm_api/setvalue/session', array(
2218
      'query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => ''),
2219
  ));
2220

    
2221
  drupal_add_js('jQuery(document).ready(function() {
2222

    
2223
      // init
2224
      if(' . $showThumbnails . ' == 1){
2225
          jQuery(\'.media_gallery\').show(20);
2226
      } else {
2227
          jQuery(\'.media_gallery\').hide(20);
2228
      }
2229

    
2230
      // add change handler
2231
      jQuery(\'#showThumbnails input.showThumbnails\').change(
2232
      function(event){
2233
        var state = 0;
2234
        if(jQuery(this).is(\':checked\')){
2235
          jQuery(\'.media_gallery\').show(20);
2236
          state = 1;
2237
        } else {
2238
          jQuery(\'.media_gallery\').hide(20);
2239
        }
2240
        // store state in session variable
2241
        var uri = \'' . $setSessionUri . '\' + state;
2242
        jQuery.get(uri);
2243
      });
2244
  });',
2245
  array('type' => "inline", 'scope' => JS_DEFAULT));
2246

    
2247
  drupal_set_title(t('Search results'), PASS_THROUGH);
2248

    
2249
  return theme('cdm_search_taxa_results', array(
2250
    'pager' => $taxonPager,
2251
    'path' => 'cdm_dataportal/search/results/taxon',
2252
    ));
2253
}
2254

    
2255
/**
2256
 * Executes the blast search and generates the result list of specimen.
2257
 */
2258
function cdm_dataportal_view_search_results_specimen() {
2259

    
2260
    $specimenPager = cdm_dataportal_search_blast_execute();
2261

    
2262
    return theme('cdm_search_specimen_results', array(
2263
        'pager' => $specimenPager,
2264
        'path' => 'cdm_dataportal/search/results/specimen',
2265
    ));
2266
}
2267

    
2268

    
2269
/**
2270
 * Executes the search for registrations and generates the result list..
2271
 */
2272
function cdm_dataportal_view_search_registrations_results($mode = 'filter') {
2273

    
2274
  switch($mode ){
2275
    case 'taxongraph':
2276
      $block = block_load('cdm_dataportal', 'registrations_search_taxongraph');
2277
      $registration_pager = cdm_dataportal_search_registrations_taxongraph_execute();
2278
      break;
2279
    case 'filter':
2280
    default:
2281
      $block = block_load('cdm_dataportal', 'registrations_search_filter');
2282
      $registration_pager = cdm_dataportal_search_registrations_filter_execute();
2283
  }
2284
  $block->title = null;
2285

    
2286
  drupal_set_title(t('Search registrations'), PASS_THROUGH);
2287

    
2288
  $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
2289
  $registrations_pager_array = compose_search_results($registration_pager, new RegistrationDTOComposeHandler());
2290
  $render_array = array_merge($render_array, $registrations_pager_array);
2291

    
2292
  return $render_array;
2293
}
2294

    
2295
/**
2296
 * Executes the search for registrations and generates the result list..
2297
 */
2298
function cdm_dataportal_view_search_agent() {
2299

    
2300
  $render_array = [];
2301
  $title = isset($_REQUEST['class']) && $_REQUEST['class'] ? $_REQUEST['class'] : 'Persons & Teams';
2302
  drupal_set_title(t($title), PASS_THROUGH);
2303
  // TODO $block = block_load('cdm_dataportal', 'search_agent_filter');
2304
  // $block->title = null;
2305
  // $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
2306
  $pager = cdm_dataportal_search_agent_execute();
2307
  $pager_render_array = compose_search_results($pager, new AgentComposeHandler());
2308
  $render_array = array_merge($render_array, $pager_render_array);
2309
  return $render_array;
2310
}
2311

    
2312

    
2313
/**
2314
 * Provides the standard image which indicated a loading process
2315
 *
2316
 * @return string
2317
 *  The img html tag
2318
 */
2319
function loading_image_html() {
2320
  return '<img class="loading" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal')
2321
    . '/images/loading_circle_grey_16.gif" style="display:none;">';
2322
}
2323

    
2324
/**
2325
 * Returns the state of the the showThumbnails flag set in the
2326
 * users session ($_SESSION['pageoption']['searchtaxa']['showThumbnails']).
2327
 *
2328
 * @return boolean
2329
 *    returns 1 if the flag is set
2330
 */
2331
function do_showThumbnails() {
2332
  static $showThumbnails = null;
2333

    
2334
  if($showThumbnails == null) {
2335
    $showThumbnails = 0;
2336
    if (!isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2337
      $showThumbnails = 0;
2338
      $search_gallery_settings = variable_get(CDM_DATAPORTAL_SEARCH_GALLERY_NAME, null);
2339
      $showThumbnails = is_array($search_gallery_settings)
2340
        && isset($search_gallery_settings['cdm_dataportal_show_taxon_thumbnails'])
2341
        && (
2342
            $search_gallery_settings['cdm_dataportal_show_taxon_thumbnails'] +
2343
            $search_gallery_settings['cdm_dataportal_show_synonym_thumbnails'] +
2344
            $search_gallery_settings['cdm_dataportal_show_thumbnail_captions'] > 0
2345
            )
2346
         ? 1 : 0;
2347

    
2348
       drupal_array_set_nested_value($_SESSION, array('pageoption', 'searchtaxa', 'showThumbnails'), $showThumbnails);
2349
    }
2350
    $showThumbnails = $_SESSION['pageoption']['searchtaxa']['showThumbnails'];
2351
    if (!is_numeric($showThumbnails)) {
2352
      $showThumbnails = 1;
2353
    }
2354
  }
2355

    
2356
  return $showThumbnails;
2357
}
2358

    
2359

    
2360

    
2361
/* ====================== other functions ====================== */
2362
/**
2363
 * Creates a URL to the taxon page specified by the $uuid parameter.
2364
 *
2365
 * The URL will be prepended with a path element to a specific taxon page tab.
2366
 *
2367
 * This tab is either taken from the CDM_DATAPORTAL_DEFAULT_TAXON_TAB which can
2368
 * be set globally in the administrative settings or individually in the user
2369
 * profile. If the CDM_DATAPORTAL_DEFAULT_TAXON_TAB value is set to LAST_VISITED_TAB
2370
 * the last portal will stay on this last tab.
2371
 *
2372
 * A third option is offerered by the $page_tab parameter which allows overwriting this
2373
 * internal mechanism by a specific value.
2374
 *
2375
 * @param string $uuid
2376
 *   The UUID of the taxon.
2377
 * @param string $page_tab
2378
 *   Overwriting the preset mechanism by defining specific value for the
2379
 *   taxon page tab.
2380
 * @return string
2381
 *   The created URL.
2382
 */
2383
function path_to_taxon($uuid, $page_tab = FALSE) {
2384

    
2385
  $tab = get_default_taxon_tab();
2386
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
2387

    
2388
  if (!$uuid) {
2389
    return FALSE;
2390
  }
2391

    
2392
  if ($page_tab) {
2393
    $url = 'cdm_dataportal/taxon/' . $uuid . '/' . $page_tab;
2394
  }
2395
  elseif (!$tab || strtolower($tab) == 'general') {
2396
    $url = 'cdm_dataportal/taxon/' . $uuid;
2397
  }
2398
  elseif (get_last_taxon_page_tab() &&   $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]) {
2399
    $url = 'cdm_dataportal/taxon/' . $uuid . '/' . get_last_taxon_page_tab();
2400
  }
2401
  else {
2402
    $url = 'cdm_dataportal/taxon/' . $uuid . '/' . strtolower($tab);
2403
  }
2404
  return $url;
2405
}
2406

    
2407
function path_to_description($uuid, $descriptive_dataset_uuid = NULL) {
2408

    
2409
    if (!$uuid) {
2410
        return FALSE;
2411
    }
2412
    else {
2413
      return 'cdm_dataportal/description/' . $uuid
2414
        . (is_uuid($descriptive_dataset_uuid) ? '/' . $descriptive_dataset_uuid : '');
2415
    }
2416
}
2417

    
2418
function path_to_specimen($uuid) {
2419

    
2420
    if (!$uuid) {
2421
        return FALSE;
2422
    }
2423
    else {
2424
        return 'cdm_dataportal/occurrence/' . $uuid;
2425
    }
2426
}
2427

    
2428
function path_to_specimen_by_accession_number($accession_number) {
2429

    
2430
    if (!$accession_number) {
2431
        return FALSE;
2432
    }
2433
    else {
2434
        return 'cdm_dataportal/specimen/accession_number/' . $accession_number;
2435
    }
2436
}
2437

    
2438
function path_to_named_area($uuid) {
2439

    
2440
  if (!$uuid) {
2441
    return FALSE;
2442
  }
2443
  else {
2444
    return 'cdm_dataportal/named_area/' . $uuid;
2445
  }
2446
}
2447

    
2448
/**
2449
 * @param $uuid
2450
 *
2451
 * @return string
2452
 */
2453
function path_to_collection($uuid) {
2454
  if (!$uuid) {
2455
    return '';
2456
  }
2457
  else {
2458
    return 'cdm_dataportal/collection/' . $uuid;
2459
  }
2460
}
2461

    
2462
/**
2463
 * Creates a URL to show a synonmy in the according taxon page.
2464
 *
2465
 * The URL will point to the synonymy tab of the taxon page of the accepted taxon given as parameter $acceptedUuid.
2466
 * The resulting URI will include query parameters to highlight the synonym, and to optionally display
2467
 * the accepted taxons name in aform like "Foo bar is accepted taxon for Ree doo". The URI will also
2468
 * include the sysnonym uuid as fragment in order to let the browser scroll to the according location
2469
 * in the page
2470
 *
2471
 * @param string $synonymUuid
2472
 *    The uuid of the synonym
2473
 * @param string $acceptedUuid
2474
 *    The uuid of the according accepted taxon
2475
 * @return string
2476
 *    The URL to show a synonmy in the according taxon page
2477
 */
2478
function uri_to_synonym($synonymUuid, $acceptedUuid) {
2479
  $acceptedPath = path_to_taxon($acceptedUuid, "synonymy");
2480
  return url($acceptedPath, array(
2481
      'query' => array(
2482
        // highlite the synony in the synonymy
2483
        'highlite' => $synonymUuid,
2484
        // the taxon page is refered from a synonym and the synonym can optionally be named in the page title
2485
        // see theme_taxon_page_title()
2486
        'acceptedFor' => $synonymUuid
2487
      ),
2488
      'fragment' => $synonymUuid
2489
  ));
2490

    
2491
}
2492

    
2493
/**
2494
 * Composes the drupal path to the key identified by the uuid.
2495
 *
2496
 * @param string $keyType
2497
 *    the key typer corresponds to the specific class of the CDM
2498
 *    IdentificationKey. Possible values are
2499
 *      -PolytomousKey
2500
 *      -MultimediaKey
2501
 *      - ...
2502
 * @param string $keyUuid
2503
 *   The UUID of the key
2504
 */
2505
function path_to_key($keyType, $keyUuid) {
2506
  if (!$keyUuid || !$keyType) {
2507
    return FALSE;
2508
  }
2509
  $keyType[0] = strtolower($keyType[0]);
2510
  return "cdm_dataportal/" . $keyType . "/$keyUuid";
2511
}
2512

    
2513
/**
2514
 * Composes the drupal path to the reference identified by the uuid.
2515
 *
2516
 * @param $uuid string String representation of the registration entity uuid.
2517
 *
2518
 * @return string
2519
 *  The drupal path
2520
 *
2521
 */
2522
function path_to_reference($uuid) {
2523
  if (!$uuid) {
2524
    return FALSE;
2525
  }
2526
  return 'cdm_dataportal/reference/' . $uuid;
2527
}
2528

    
2529
/**
2530
 * @param string $registration_identifier
2531
 *  The persistent identifier of the registration entity (Registration.identifier).
2532
 *
2533
 * @return string
2534
 *  the markup for a HTML link
2535
 */
2536
function render_link_to_registration($registration_identifier) {
2537

    
2538
  if(variable_get(CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK)){
2539
    $path = $registration_identifier;
2540
    $query = [];
2541
  } else {
2542
    $path = 'cdm_dataportal/registration';
2543
    $query = ['identifier' => $registration_identifier];
2544
  }
2545
  return l($registration_identifier, $path, array('attributes' => array('class' => array('identifier')), 'query' => $query));
2546
}
2547

    
2548

    
2549
/**
2550
 * Creates the path to a cdm_dataportal taxon name page.
2551
 *
2552
 * @param string $taxon_name_uuid
2553
 *   The uuid as string of the CDM TaxonName to show a name page for
2554
 * @param string $taxon_to_hide_uuid
2555
 *   The uuid as string of a taxon which should not be displayed in the taxon list
2556
 * @param string $highlited_synonym_uuid
2557
 *   Optional parameter which takes another taxon uuid, if given the
2558
 *   target taxon pages will show the synonymy tab where the taxon
2559
 *   referenced by the $highlite_synonym_uuid will be highlighted
2560
 *   in case it is found on this page.
2561
 * @param $redirect_to_taxon
2562
 *   If true, the name page will redirect to the related taxon if there is a single one
2563
 *   for this name only.
2564
 *
2565
 * @return string
2566
 *  URI path element as string
2567
 */
2568
function path_to_name($name_uuid, $taxon_to_hide_uuid = NULL, $highlited_synonym_uuid  = NULL, $redirect_to_taxon = false) {
2569
  $res = FALSE;
2570
  if ($name_uuid) {
2571
    $res = 'cdm_dataportal/name/' . $name_uuid .
2572
    '/' . (is_uuid($taxon_to_hide_uuid) ? $taxon_to_hide_uuid : "null") .
2573
    '/' . (is_uuid($highlited_synonym_uuid) ? $highlited_synonym_uuid : "null") .
2574
    '/' . ($redirect_to_taxon || variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0) ? "redirect_to_taxon" : "");
2575
  }
2576

    
2577
  return $res;
2578
}
2579

    
2580
/**
2581
 * Composes the drupal path to the media entity identified by the uuid.
2582
 *
2583
 * @param string $uuid
2584
 *  The persistent identifier of the entity entity
2585
 * @return string
2586
 *  The drupal path
2587
 */
2588
function path_to_media($uuid, $representaion_uuid = FALSE, $partId = FALSE) {
2589
  if (!$uuid) {
2590
    return FALSE;
2591
  }
2592
  $out = 'cdm_dataportal/media/' . $uuid;
2593
  if ($representaion_uuid) {
2594
    $out .= '/' . $representaion_uuid;
2595
    if (is_numeric($partId)) {
2596
      $out .= '/' . $partId;
2597
    }
2598
  }
2599
  return $out;
2600
}
2601

    
2602
/**
2603
 * Compares thisRank with thatRank.
2604
 *
2605
 * Returns a negative integer, zero, or a positive integer
2606
 * as the of thisRank is higher than, equal to, or lower than thatRank.
2607
 * e.g:
2608
 * <ul>
2609
 * <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
2610
 * <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
2611
 * <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
2612
 * </ul>
2613
 * <p>
2614
 * This compare logic of the underlying webservice is the
2615
 * <b>inverse logic</b> of the the one implemented in
2616
 * java.lang.Comparable#compareTo(java.lang.Object)
2617
 *
2618
 * @param $thisRankUuid
2619
 * @param $thatRankUuid
2620
 *
2621
 * @return int
2622
 *   A negative integer, zero, or a positive integer
2623
 *   as the thisRank is lower than, equal to, or higher than thatRank.
2624
 */
2625
function rank_compare($thisRankUuid, $thatRankUuid) {
2626
  $result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
2627
  return $result->Integer;
2628
}
2629

    
2630
/**
2631
 * Creates a short version of a taxonname.
2632
 *
2633
 * The short name is created by using the taggedTitle field of
2634
 * TaxonNodeDTO instances.
2635
 * If the taggedTitle if empty the fullname will be returned.
2636
 *
2637
 * @param object $taxonNodeDTO
2638
 *   A TaxonNodeDTO object
2639
 *
2640
 * @return string
2641
 */
2642
function cdm_dataportal_shortname_of($taxonNodeDTO) {
2643

    
2644
  $nameStr = '';
2645

    
2646
  normalize_tagged_text($taxonNodeDTO->taggedTitle);
2647

    
2648
  // Get all tagged text tokens of the scientific name.
2649
  foreach ($taxonNodeDTO->taggedTitle as $tagtxt) {
2650
    if ($tagtxt->type == 'name' || $tagtxt->type == 'rank') {
2651
      $nameStr .= ($nameStr ? ' ' : '') . $tagtxt->text;
2652
    }
2653
  }
2654
  $nameStr = trim($nameStr);
2655

    
2656
  if ($nameStr) {
2657
    if(isset($taxonNodeDTO->status->symbol)){
2658
      $nameStr = $taxonNodeDTO->status->symbol . ' ' . $nameStr;
2659
    }
2660
    // Do not return short names for these.
2661
    if ($taxonNodeDTO->unplaced || $taxonNodeDTO->excluded) {
2662
      return $nameStr;
2663
    }
2664

    
2665
    /*
2666
    1st capture group (^[a-zA-Z]): First letter of uninomial.
2667
    Second capture group ([\p{L}]+): remaining letters of uninomial ([\p{L} = an UTF-8 letter).
2668
    Third capture group (\s+[^(\x2E]+\s+.+$|\s+[a-zA-Z]+$): letters of name,
2669
    but only matching if no '(' or '.' in second word of name,        ( \x2E = '.')
2670
    OR only one specific epithet \s+[\p{L}\x22\x2D\xD7]+$             (\x22= '"', \x2D='-', \xD7='×' )
2671
    */
2672
    $pattern = '/(^[a-zA-Z])([\p{L}]+)(\s+[^(\x2E]+\s+.+$|\s+[\p{L}\x22\x2D\xD7]+$)/u';
2673
    if (preg_match($pattern, $nameStr, $matches, PREG_OFFSET_CAPTURE)) {
2674
      return $matches[1][0] . "." . $matches[3][0];
2675
    }
2676
    else {
2677
      return $nameStr;
2678
    }
2679
  }
2680
  else {
2681
    return $taxonNodeDTO->titleCache;
2682
  }
2683
}
2684

    
2685
/**
2686
 * Check if a taxon is accepted by the current taxonomic tree.
2687
 *
2688
 * @param mixed $taxon
2689
 *   The Taxon obkect to check.
2690
 *
2691
 * @return bool
2692
 *   Returns TRUE if $taxon is accepted, FALSE otherwise.
2693
 */
2694
function _cdm_dataportal_acceptedByCurrentView($taxon) {
2695

    
2696
  $default_classification_uuid = get_current_classification_uuid();
2697

    
2698
  if (isset($taxon->taxonNodes)) {
2699
    $taxon_nodes = $taxon->taxonNodes;
2700
  }
2701
  else {
2702
    $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon->uuid);
2703
  }
2704

    
2705
  if ($taxon->class == "Taxon" && isset($taxon_nodes)) {
2706
    foreach ($taxon_nodes as $node) {
2707
      if($node->class == 'TaxonNodeDto' && isset($node->classificationUUID)){
2708
        // case of TaxonNodeDto
2709
        return $node->classificationUUID == $default_classification_uuid;
2710
      } else if($node->class == 'TaxonNode' && isset($node->classification->uuid)) {
2711
         return $node->classification->uuid == $default_classification_uuid;
2712
      }
2713
    }
2714
  }
2715
  return FALSE;
2716
}
2717

    
2718
/**
2719
 * Checks is the source has one of the given types.
2720
 *
2721
 * @param object $source
2722
 *   The original source entity
2723
 * @param array $types
2724
 *   An array of element of the OriginalSourceType enumeration
2725
 *   If not set the default will be used which is:
2726
 *    - Lineage
2727
 *    - PrimaryMediaSource
2728
 *    - PrimaryTaxonomicSource
2729
 *    - Unknown
2730
 *    - Other
2731
 * @return boolean
2732
 */
2733
  function _is_original_source_type($source, $types = null) {
2734
    // this is the default
2735
    // maybe this should also be put into the settings
2736
    static $default = array(
2737
      OriginalSourceType::Lineage,
2738
      OriginalSourceType::PrimaryMediaSource,
2739
      OriginalSourceType::PrimaryTaxonomicSource,
2740
      OriginalSourceType::Unknown,
2741
      OriginalSourceType::Other,
2742
      OriginalSourceType::Aggregation
2743
    );
2744

    
2745
    if(!$types){
2746
      $types = $default;
2747
    }
2748
    return isset($source->type) && in_array($source->type, $types);
2749
  }
2750

    
2751
/**
2752
 * Collects all the media from a list of description elements.
2753
 *
2754
 * @param array $descriptionElements
2755
 *   The description elements from which to collect the media.
2756
 *
2757
 * @return array
2758
 *   The output with all the collected media.
2759
 */
2760
function cdm_dataportal_media_from_descriptionElements($descriptionElements) {
2761

    
2762
  $outArrayOfMedia = array();
2763

    
2764
  // Avoiding a warning box in Drupal for Flora Malesiana.
2765
  if (isset($descriptionElements) && is_array($descriptionElements)) {
2766
    foreach ($descriptionElements as $descriptionElement) {
2767
      if (isset($descriptionElement->media) && is_array($descriptionElement->media)) {
2768
        foreach ($descriptionElement->media as $media) {
2769
          if (is_object($media)) {
2770
            $outArrayOfMedia[] = $media;
2771
          }
2772
        }
2773
      }
2774
    }
2775
  }
2776
  return $outArrayOfMedia;
2777
}
2778

    
2779

    
2780

    
2781

    
2782
/**
2783
 * Creates a CDM Dynabox.
2784
 *
2785
 * @param string $dynabox_id
2786
 *   a uninque name for tha dynabox, using a cdm entity uuid as id is good practice.
2787
 * @param string $label
2788
 *   The clickable text to show.
2789
 * @param string $content_url
2790
 *   The cdm REST service request url wich will deliver the content to be shown
2791
 *   once the dynabox toggles open.
2792
 * @param string $theme
2793
 *   The theme to be used for rendering the cdm REST service response with is
2794
 *   returned from the $content_url.
2795
 * @param string $link_alt_text
2796
 *   The value for the alt attribute of the dynabox link.
2797
 * @param array $enclosingtags
2798
 *   An array with two elements: $enclosingtags[0] will be used for the dynabox
2799
 *   element itself, $enclosingtags[1] is the tag to be used for the
2800
 *   dynabox_content (optional)
2801
 * @param array $attributes
2802
 * @param $content_element_selector
2803
 *   Optional jQuery selector which can be used to reference a dom element which should
2804
 *   be used as container for the content to be shown. The dynabox-<dynabox id>-content
2805
 *  element will be placed in this container.
2806
 *
2807
 * @param string $open_callback
2808
 *   optional javascript call back function to be triggered after toggling the box to
2809
 *   the open state.
2810
 * @param string $close_callback
2811
 *   optional javascript call back function to be triggered after toggling the box to
2812
 *   the closed state.
2813
 * @return string Returns HTML for a dynabox.
2814
 * Returns HTML for a dynabox.
2815
 */
2816
function cdm_dynabox($dynabox_id, $label, $content_url, $theme, $link_alt_text,
2817
                     $enclosingtags = array('li', 'ul'), $attributes = array(),
2818
                     $content_element_selector = null,
2819
                     $open_callback = 'function(){}', $close_callback = 'function(){}' ) {
2820
  $out = '';
2821

    
2822
  // check for plain class attribute string
2823
  $dynabox_id = preg_replace('/[^a-zA-Z0-9\-]/', '', $dynabox_id);
2824

    
2825
  if(!array_key_exists('class', $attributes)) {
2826
    $attributes['class'] = ["dynabox"];
2827
  } else {
2828
    $attributes['class'] = array_merge($attributes['class'], ["dynabox"]);
2829
  }
2830
  $attributes['id'][] = 'dynabox-' . $dynabox_id;
2831
  $dynabox_attributes = drupal_attributes($attributes);
2832

    
2833

    
2834
  _add_js_domEvent(); // requires domEvent.js
2835
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cdm_dynabox.js');
2836
  drupal_add_js("
2837
  jQuery(document).ready(
2838
      function() {
2839
        dynabox('". $dynabox_id ."',
2840
          {
2841
            open_callback: " . $open_callback .",
2842
            close_callback: " . $close_callback .
2843
            ($content_element_selector ? ",\n content_container_selector: '" . $content_element_selector . "'" : "") . "
2844
          }
2845
        );
2846
      }
2847
   );",
2848
   array(
2849
    'type'=>'inline',
2850
    'scope'=>'footer'
2851
    )
2852
  );
2853

    
2854

    
2855
  $cdm_proxy_url = url('cdm_api/proxy/' . urlencode($content_url) . "/$theme");
2856
  $out .= '<!-- dynabox for ' . $content_url . ' -->';
2857
  $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>';
2858
  $out .= '  <' . $enclosingtags[1] . ' id="dynabox-' . $dynabox_id . '-content">';
2859
  $out .= '    <' . $enclosingtags[0] . ' class="dynabox-content-inner">' . loading_image_html() . '</' . $enclosingtags[0] . '>';
2860
  $out .= '    </' . $enclosingtags[1] . '>';
2861
  $out .= '  </' . $enclosingtags[0] . '>';
2862
  $out .= '<!-- dynabox end -->';
2863
  return $out;
2864
}
2865

    
2866
/**
2867
 * Checks whether a feature has any description elements.
2868
 *
2869
 * @param mixed $featureNode
2870
 *   A feature node as produced by the function _mergeFeatureTreeDescriptions().
2871
 *
2872
 * @see _mergeFeatureTreeDescriptions()
2873
 *
2874
 * @return bool
2875
 *   Returns TRUE if the given $featureNode or any of its subordinate nodes
2876
 *   contains at least one non empty TextData or at least one DescriptionElement
2877
 *   of an other type. A TextData element holding a multilanguageText or a
2878
 *   source reference is considered to be not empty.
2879
 *
2880
 * @TODO this function may have become obsolete by the new method of detecting empty blocks,
2881
 *       see $block_content_is_not_empty in make_feature_block_list() and
2882
 *       $feature_block_has_content in compose_feature_block_items_generic
2883
 */
2884
function has_feature_node_description_elements($featureNode) {
2885

    
2886
  if (isset($featureNode->descriptionElements) && is_array($featureNode->descriptionElements) && count($featureNode->descriptionElements) > 0) {
2887
    if(!isset($featureNode->descriptionElements['#type'])){ // #type is used to identify e.g. DTO elements: '#type' => 'DTO'
2888
      foreach ($featureNode->descriptionElements as $descriptionElement) {
2889
        if ($descriptionElement->class != "TextData" || isset($descriptionElement->multilanguageText_L10n->text)
2890
          && $descriptionElement->multilanguageText_L10n->text != ''
2891
          || isset($descriptionElement->sources[0])
2892
          || isset($descriptionElement->media[0]) ) {
2893
          return TRUE;
2894
        }
2895
      }
2896
    }
2897
  }
2898
  else if (isset($featureNode->childNodes) && is_array($featureNode->childNodes)) {
2899
    foreach ($featureNode->childNodes as $child) {
2900
      if (has_feature_node_description_elements($child)) {
2901
        return TRUE;
2902
      }
2903
    }
2904
  }
2905
  return FALSE;
2906
}
2907

    
2908
/**
2909
 * Checks if the current page is a valid taxon portal page and responds with HTTP status 404 (not found) otherwise
2910
 *
2911
 * @param $chapter
2912
 *   The taxon page chapter or part
2913
 */
2914
function cdm_check_valid_taxon_page($chapter){
2915
  static $taxon_tabs = null;
2916

    
2917
  cdm_check_valid_portal_page();
2918

    
2919
  if($taxon_tabs == null){
2920
    $taxon_tabs = array('all', 'description');
2921
    foreach(get_taxon_tabs_list() as $tab){
2922
      $taxon_tabs[] = strtolower($tab);
2923
    }
2924
  }
2925

    
2926
  if(!in_array($chapter, $taxon_tabs)){
2927
    // oops this is not a valid chapter name
2928
    http_response_code(404); // 404 = Not Found
2929
  }
2930

    
2931
}
2932

    
2933
function check_js_devel_mode_disabled() {
2934
  if(variable_get('cdm_js_devel_mode', FALSE)) {
2935
    drupal_set_message(t('The !url1 is enabled.
2936
        WARNING: this is a performance penalty and must be turned off on production websites.', array(
2937
      '!url1' => l('java-script development mode', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-cdm-js-devel-mode'))
2938
    )),
2939
      'warning'
2940
    );
2941
  }
2942
}
2943

    
2944
/**
2945
 * Checks if the current page is a valid portal page and responds with HTTP status 404 (not found) otherwise.
2946
 * The test applied by default it a check for the query parameter 'q' ending with a file suffix like '*.*'
2947
 *
2948
 * @param $preg_pattern
2949
 *   Optional regular expression pattern to be used in preg_match().
2950
 */
2951
function cdm_check_valid_portal_page($preg_pattern = null){
2952
  $ends_with_file_suffix_pattern = '/\/[^\.\/]*[\.][^\.\/]*$/';
2953
  if($preg_pattern === null){
2954
    $preg_pattern = $ends_with_file_suffix_pattern;
2955
  }
2956
  if(preg_match($preg_pattern, $_GET['q'])){
2957
    // oops this urls ends with a file_suffix and thus does not refer to a portal page
2958
    http_response_code(404); // 404 = Not Found
2959
    exit('HTTP 404');
2960
  }
2961
  check_js_devel_mode_disabled();
2962
}
2963

    
2964
/**
2965
 * Generates the diff of the texts and presents it in a HTML diff viewer.
2966
 *
2967
 * @param $text_a
2968
 * @param $text_b
2969
 * @return string
2970
 */
2971
function diff_viewer($text_a, $text_b) {
2972

    
2973
  static $diff_viewer_count = 0;
2974

    
2975
  $element_id = 'part_definitions_diff_' . $diff_viewer_count++;
2976

    
2977
  // http://code.stephenmorley.org/php/diff-implementation/
2978
  module_load_include('php', 'cdm_dataportal', 'lib/class.Diff');
2979
  drupal_add_css(drupal_get_path('module',
2980
      'cdm_dataportal') . '/css/diff.css');
2981
  _add_jquery_ui();
2982
  drupal_add_js(
2983
    'jQuery(document).ready( function(){
2984
        jQuery(\'#' . $element_id . '\').accordion({
2985
        collapsible: true,
2986
        active: false,
2987
        fillSpace: true,
2988
        }).children(\'div\').css({ \'height\': \'auto\' });
2989
        jQuery(\'#' . $element_id . ' table.diff\').prepend(\'<thead><tr><th>Default</th><th>User defined<th></th><tr></thead>\');
2990
     });'
2991
    , array(
2992
    'type' => 'inline',
2993
    'scope' => 'footer'
2994
  ));
2995

    
2996
  $diff = Diff::compare($text_a,
2997
    $text_b);
2998
  $diff_viewer_markup = '<div id="' . $element_id . '"><h3>View Diff</h3><div>'
2999
    . Diff::toTable($diff, '', '')
3000
    . '</div></div>';
3001
  return $diff_viewer_markup;
3002
}
3003

    
3004
/**
3005
 * ====== EXPERIMENTAL only used by Euro+Med ===============
3006
 */
3007

    
3008

    
3009
/**
3010
 * See
3011
 *  - https://dev.e-taxonomy.eu/redmine/issues/9233
3012
 *  - https://www.drupal.org/project/feedback_simple
3013
 *  - https://www.drupal.org/node/1299158
3014
 * Implements hook_preprocess_feedback_simple().
3015
 *
3016
 * TODO: move into separate module
3017
 */
3018
function cdm_dataportal_preprocess_feedback_simple(&$variables) {
3019
  // Add modal_forms classes.
3020
  $variables['class'][] = 'ctools-use-modal';
3021
  // Uncomment either small, medium or large.
3022
  $variables['class'][] = 'ctools-modal-modal-popup-small';
3023
  // $variables['class'][] = 'ctools-modal-modal-popup-medium';
3024
  // $variables['class'][] = 'ctools-modal-modal-popup-large';
3025
}
3026

    
3027

    
(10-10/18)