Project

General

Profile

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

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

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

    
55

    
56
  /* ============================ java script functions ============================= */
57

    
58

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

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

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

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

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

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

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

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

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

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

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

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

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

    
153
  function _add_js_openlayers() {
154

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

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

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

    
175

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

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

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

    
206
  }
207

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

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

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

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

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

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

    
287
  global $base_url;
288

    
289

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

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

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

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

    
339

    
340
function _add_js_utis_client($jquery_selector){
341

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

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

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

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

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

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

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

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

    
472

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

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

    
483
    return '';
484
  }
485

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

    
496

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

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

    
506
    return '';
507
  }
508

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
859
  return $items;
860
}
861

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

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

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

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

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

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

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

    
902

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

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

    
913
    }
914
    return $requirements;
915
}
916

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

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

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

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

    
1076

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

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

    
1097
  return $taxon_uuid;
1098
}
1099

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

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

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

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

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

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

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

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

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

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

    
1184
  return $form;
1185

    
1186
}
1187

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

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

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

    
1203
  $current_classification_uuid = get_current_classification_uuid();
1204

    
1205

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

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

    
1232
  return $render_array;
1233
}
1234

    
1235

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

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

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

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

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

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

    
1296
  cdm_check_valid_portal_page();
1297

    
1298
  return compose_cdm_reference_page($uuid);
1299
}
1300

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

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

    
1317
  cdm_check_valid_portal_page();
1318

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

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

    
1347
  static $media = NULL;
1348

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

    
1354

    
1355
    $mediaQueryParameters = taxon_media_query_parameters();
1356

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

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

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

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

    
1388
  static $occurences = NULL;
1389

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

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

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

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

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

    
1412

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

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

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

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

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

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

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

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

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

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

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

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

    
1600
  cdm_check_valid_portal_page();
1601

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

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

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

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

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

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

    
1645

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

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

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

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

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

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

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

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

    
1732
  return $taxonpage;
1733
}
1734

    
1735

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

    
1740
  $specimenpage = specimen_by_accession_number_view($accession_number);
1741

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

    
1749

    
1750
}
1751

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

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

    
1769

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

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

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

    
1811

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

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

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

    
1821
  return $specimenpage;
1822
}
1823

    
1824

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

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

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

    
1848
    return $specimenpage;
1849
}
1850

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

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

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

    
1886
    return $description_page;
1887
}
1888

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

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

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

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

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

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

    
1925
  return $named_area_page;
1926
}
1927

    
1928
function cdm_dataportal_named_area_page_view($uuid) {
1929

    
1930
  cdm_check_valid_portal_page();
1931

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

    
1940

    
1941
}
1942

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

    
1967
  cdm_check_valid_portal_page();
1968

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

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

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

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

    
2077

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

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

    
2096

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

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

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

    
2118

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

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

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

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

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

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

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

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

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

    
2177
  return $render_array ;
2178
}
2179

    
2180

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

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

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

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

    
2214
  $taxonPager = cdm_dataportal_search_taxon_execute();
2215

    
2216
  $showThumbnails = do_showThumbnails();
2217

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

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

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

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

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

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

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

    
2261
    $specimenPager = cdm_dataportal_search_blast_execute();
2262

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

    
2269

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

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

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

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

    
2293
  return $render_array;
2294
}
2295

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

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

    
2313

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

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

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

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

    
2357
  return $showThumbnails;
2358
}
2359

    
2360

    
2361

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

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

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

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

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

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

    
2419
function path_to_specimen($uuid) {
2420

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

    
2429
function path_to_specimen_by_accession_number($accession_number) {
2430

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

    
2439
function path_to_named_area($uuid) {
2440

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

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

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

    
2492
}
2493

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

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

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

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

    
2549

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

    
2578
  return $res;
2579
}
2580

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

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

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

    
2645
  $nameStr = '';
2646

    
2647
  normalize_tagged_text($taxonNodeDTO->taggedTitle);
2648

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

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

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

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

    
2697
  $default_classification_uuid = get_current_classification_uuid();
2698

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

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

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

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

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

    
2763
  $outArrayOfMedia = array();
2764

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

    
2780

    
2781

    
2782

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

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

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

    
2834

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

    
2855

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

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

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

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

    
2918
  cdm_check_valid_portal_page();
2919

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

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

    
2932
}
2933

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

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

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

    
2974
  static $diff_viewer_count = 0;
2975

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

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

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

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

    
3009

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

    
3028

    
(10-10/18)