Project

General

Profile

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

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

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

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

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

    
54

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

    
57

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

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

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

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

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

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

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

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

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

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

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

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

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

    
152
  function _add_js_openlayers() {
153

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

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

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

    
174

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

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

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

    
205
  }
206

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

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

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

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

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

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

    
286
  global $base_url;
287

    
288

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

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

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

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

    
338

    
339
function _add_js_utis_client($jquery_selector){
340

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

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

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

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

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

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

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

    
451
function _add_js_derivation_tree_focus_unit($unit_uuid){
452
  drupal_add_js('jQuery(document).ready(function() {
453
      jQuery( ".derived-unit-tree > .uuid\\\\:' . $unit_uuid . ' > .unit-header, .derived-unit-sub-tree > .uuid\\\\:' . $unit_uuid . ' > .unit-header" )
454
         .css(\'font-weight\', \'bold\')
455
        .find(".page-link").hide();
456
    });',
457
    array('type' => 'inline')
458
  );
459
}
460

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

    
481

    
482
    if($icon_name){
483
      if(!isset($attributes['class'])){
484
        $attributes['class'] = array();
485
      }
486
      $attributes['class'][] = 'fa';
487
      $attributes['class'][] = $icon_name;
488

    
489
      return '<i ' . drupal_attributes($attributes) . '></i>';
490
    }
491

    
492
    return '';
493
  }
494

    
495
/**
496
 * @param string $glyph_name
497
 *   The name of the gloyph (e.g. 'icon-interal-link-alt-solid') for the foll list please
498
 *   refer to modules/cdm_dataportal/fonts/custom-icon-font
499
 * @param array $attributes
500
 * @return string
501
 */
502
  function custom_icon_font_markup($glyph_name = NULL, $attributes = array()){
503
    _add_font_custom_icon_font();
504

    
505

    
506
    if($glyph_name){
507
      if(!isset($attributes['class'])){
508
        $attributes['class'] = array();
509
      }
510
      $attributes['class'][] = $glyph_name;
511

    
512
      return '<i ' . drupal_attributes($attributes) . '></i>';
513
    }
514

    
515
    return '';
516
  }
517

    
518
/**
519
 * Adds the css  containing the font awesome icons to the html header.
520
 */
521
function _add_font_awesome_font()
522
{
523
  // $fa_font_version = 'font-awesome-4.6.3/css/font-awesome.min.css';
524
  $fa_font_version = 'fontawesome-free-5.9.0-web/css/all.css';
525
  $font_awesome_css_uri = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/fonts/' . $fa_font_version;
526

    
527
  drupal_add_html_head_link(
528
    array(
529
      'href' => $font_awesome_css_uri,
530
      'rel' => 'stylesheet'
531
    )
532
  );
533
}
534

    
535
/**
536
 * Adds the css  containing the font awesome icons to the html header.
537
 */
538
function _add_font_custom_icon_font()
539
{
540

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

    
543
  drupal_add_html_head_link(
544
    array(
545
      'href' => $custom_icon_font_css_uri,
546
      'rel' => 'stylesheet'
547
    )
548
  );
549
}
550

    
551
/* ====================== hook implementations ====================== */
552
  /**
553
   * Implements hook_permission().
554
   *
555
   * Valid permissions for this module.
556
   *
557
   * @return array
558
   *   An array of valid permissions for the cdm_dataportal module.
559
   */
560
  function cdm_dataportal_permission() {
561
    return array(
562
      'administer cdm_dataportal' => array(
563
        'title' => t('Administer CDM DataPortal settings'),
564
        'description' => t("Access the settings pages specific for the cdm_dataportal module"),
565
      ),
566
      'access cdm content' => array(
567
        'title' => t('Access CDM content'),
568
        'description' => t("Access content (taxa, names, specimens, etc.) served by the CDM web service."),
569
      ),
570
    );
571
  }
572

    
573
/**
574
 * Implements hook_menu().
575
 */
576
function cdm_dataportal_menu() {
577
  $items = array();
578

    
579
  // @see settings.php.
580
  cdm_dataportal_menu_admin($items);
581
  cdm_dataportal_menu_help($items);
582

    
583
  $items['cdm_dataportal/names'] = array(
584
    'page callback' => 'cdm_dataportal_view_names',
585
    'access arguments' => array('access cdm content'),
586
    'type' => MENU_CALLBACK,
587
  );
588

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

    
597
  $items['cdm_dataportal/occurrence'] = array(
598
        'page callback' => 'cdm_dataportal_specimen_page_view',
599
        'access arguments' => array('access cdm content'),
600
        'type' => MENU_CALLBACK,
601
        // Expected callback arguments: uuid.
602
    );
603

    
604
  $items['cdm_dataportal/description'] = array(
605
        'page callback' => 'cdm_dataportal_description_page_view',
606
        'access arguments' => array('access cdm content'),
607
        'type' => MENU_CALLBACK,
608
        // Expected callback arguments: uuid.
609
    );
610

    
611
   $items['cdm_dataportal/specimen/accession_number'] = array(
612
        'page callback' => 'cdm_dataportal_specimen_by_accession_number_page_view',
613
        'access arguments' => array('access cdm content'),
614
        'type' => MENU_CALLBACK,
615
        // Expected callback arguments: accession number.
616
    );
617
  $items['cdm_dataportal/named_area'] = array(
618
    'page callback' => 'cdm_dataportal_named_area_page_view',
619
    'access arguments' => array('access cdm content'),
620
    'type' => MENU_CALLBACK,
621
    // Expected callback arguments: uuid.
622
  );
623

    
624
  $items['cdm_dataportal/name'] = array(
625
    'page callback' => 'cdm_dataportal_name_page_view',
626
      /*
627
    'page arguments' => array(
628
       'taxon_name_uuid',
629
       'taxon_to_hide_uuid',
630
       'synonym_uuid' => NULL
631
      ),
632
      */
633
    'access arguments' => array('access cdm content'),
634
    'type' => MENU_CALLBACK,
635
    // Expected callback arguments: uuid.
636
  );
637

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

    
645
  $items['cdm_dataportal/reference/list'] = array(
646
    'page callback' => 'cdm_dataportal_view_reference_list',
647
    'access arguments' => array('access cdm content'),
648
    'type' => MENU_CALLBACK,
649
    // Expected callback arguments: uuid.
650
  );
651

    
652
  $items['cdm_dataportal/media'] = array(
653
    'page callback' => 'cdm_dataportal_view_media',
654
    'access arguments' => array('access cdm content'),
655
    'type' => MENU_CALLBACK,
656
    // Expected callback arguments:
657
    // uuid, mediarepresentation_uuid, part_uuid or part#.
658
  );
659

    
660
  $items['cdm_dataportal/polytomousKey'] = array(
661
    'page callback' => 'cdm_dataportal_view_polytomousKey',
662
    'access arguments' => array('access cdm content'),
663
    'type' => MENU_CALLBACK,
664
    // Expected callback arguments: polytomousKey->uuid.
665
  );
666

    
667
  $items['cdm_dataportal/search'] = array(
668
    'page callback' => 'cdm_dataportal_view_search_advanced',
669
    'access arguments' => array('access cdm content'),
670
    'type' => MENU_CALLBACK,
671
  );
672

    
673
  // Optional callback arguments: page.
674
  $items['cdm_dataportal/registration'] = array(
675
    'page callback' => 'cdm_dataportal_registration_page_view',
676
    'access arguments' => array('access cdm content'),
677
    'type' => MENU_CALLBACK,
678
    // Expected callback arguments: uuid.
679
  );
680

    
681
  // ------------ SEARCH -----------
682
  $items['cdm_dataportal/search/advanced'] = array(
683
    'title' => 'Advanced', // will be passed through t()
684
    'page callback' => 'cdm_dataportal_view_search_advanced',
685
    'access arguments' => array('access cdm content'),
686
    'type' => MENU_DEFAULT_LOCAL_TASK,
687
  );
688
  $items['cdm_dataportal/search/blast'] = array(
689
    'title' => 'Blast', // will be passed through t()
690
    'page callback' => 'cdm_dataportal_view_search_blast',
691
    'access arguments' => array('access cdm content'),
692
    'type' => MENU_LOCAL_TASK,
693
  );
694

    
695
  $items['cdm_dataportal/search/taxon_by_description'] = array(
696
    'title' => 'By content category', // will be passed through t()
697
    'page callback' => 'cdm_dataportal_view_search_taxon_by_description',
698
    'access arguments' => array('access cdm content'),
699
    'type' => MENU_LOCAL_TASK,
700
  );
701
  $items['cdm_dataportal/search/results/taxon'] = array(
702
    'page callback' => 'cdm_dataportal_view_search_results_taxon',
703
    'access arguments' => array('access cdm content'),
704
    'type' => MENU_CALLBACK,
705
  );
706

    
707
  $items['cdm_dataportal/search/results/specimen'] = array(
708
      'page callback' => 'cdm_dataportal_view_search_results_specimen',
709
      'access arguments' => array('access cdm content'),
710
      'type' => MENU_CALLBACK,
711
  );
712

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

    
747
  // Optional callback arguments: page.
748
  $items['cdm_dataportal/search/agent'] = array(
749
    'page callback' => 'cdm_dataportal_view_search_agent',
750
    'access arguments' => array('access cdm content'),
751
    'type' => MENU_CALLBACK,
752
    // Expected callback arguments: uuid.
753
  );
754

    
755
  // ------------ menu items with variable path elements -----------
756

    
757
  // 'May not cache' in D5.
758
  $items['cdm_dataportal/name/%'] = array(
759
    // 'page callback' => 'cdm_dataportal_view_name',
760
    'page callback' => 'cdm_dataportal_name_page_view',
761
    'page arguments' => array(2, 3, 4, 5),
762
    'access arguments' => array('access cdm content'),
763
    'type' => MENU_CALLBACK,
764
  );
765

    
766
  // --- Local tasks for Taxon.
767
  // --- tabbed taxon page
768
  if (variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
769
    $items['cdm_dataportal/taxon/%'] = array(
770
      'title' => cdm_taxonpage_tab_label('General'),
771
      'page callback' => 'cdm_dataportal_taxon_page_view',
772
      'access arguments' => array('access cdm content'),
773
      'type' => MENU_CALLBACK,
774
      'weight' => 1,
775
      'page arguments' => array(2, "description")
776
      , // Expected callback arguments: taxon_uuid.
777
    );
778

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

    
789
    $items['cdm_dataportal/taxon/%/description'] = array(
790
      'title' => cdm_taxonpage_tab_label('General'),
791
      'page callback' => 'cdm_dataportal_taxon_page_view',
792
      'access arguments' => array('access cdm content'),
793
      'type' => MENU_DEFAULT_LOCAL_TASK,
794
      'weight' => 2,
795
      'page arguments' => array(2, "description")
796
      , // Expected callback arguments: taxon_uuid.
797
    );
798

    
799
    $items['cdm_dataportal/taxon/%/synonymy'] = array(
800
      'title' => cdm_taxonpage_tab_label('Synonymy'),
801
      'page callback' => 'cdm_dataportal_taxon_page_view',
802
      'access arguments' => array('access cdm content'),
803
      'type' => MENU_LOCAL_TASK,
804
      'weight' => 4,
805
      'page arguments' => array(2, "synonymy", 4)
806
      , // Expected callback arguments: taxon_uuid and ...
807
    );
808
    $items['cdm_dataportal/taxon/%/images'] = array( // Images
809
      'title' => cdm_taxonpage_tab_label('Images'),
810
      'page callback' => 'cdm_dataportal_taxon_page_view',
811
      'access arguments' => array('access cdm content'),
812
      'type' => MENU_LOCAL_TASK,
813
      'weight' => 5,
814
      'page arguments' => array(2, "images")
815
      , // Expected callback arguments: taxon_uuid.
816
    );
817

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

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

    
838
    $items['cdm_dataportal/taxon/%/experts'] = array( // Experts
839
      'title' => cdm_taxonpage_tab_label('Experts'),
840
        'page callback' => 'cdm_dataportal_taxon_page_view',
841
        'access arguments' => array('access cdm content'),
842
        'type' => MENU_LOCAL_TASK,
843
        'weight' => 6,
844
        'page arguments' => array(2, "experts")
845
    , // Expected callback arguments: taxon_uuid.
846
    );
847

    
848
    $items['cdm_dataportal/taxon/autosuggest/%/%/%/'] = array(
849
        'page callback' => 'cdm_dataportal_taxon_autosuggest',
850
        'access arguments' => array('access cdm content'),
851
        'page arguments' => array(3,4,5),
852
        'type' => MENU_CALLBACK
853
    );
854
  }
855

    
856
  // --- refresh link for all cdmnode types
857
  foreach (cdm_get_nodetypes() as $type=>$name) {
858
    $items['cdm_dataportal/' . $name . '/%/refresh'] = array(
859
        'title' => 'Refresh',
860
        'page callback' => 'cdm_dataportal_refresh_node',
861
        'access arguments' => array('administer cdm_dataportal'),
862
        'type' => MENU_LOCAL_TASK,
863
        'weight' => 100,
864
        'page arguments' => array($name, 2)
865
    );
866
  }
867

    
868
  return $items;
869
}
870

    
871
/**
872
 * Implements hook_init().
873
 *
874
 */
875
function cdm_dataportal_init() {
876
  if (!path_is_admin(current_path())) {
877
    //FIXME To add CSS or JS that should be present on all pages, modules
878
    //      should not implement this hook, but declare these files in their .info file.
879
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal.css');
880
    // drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
881
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_screen.css', array('type' => 'screen'));
882
  } else {
883
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_settings.css');
884
  }
885

    
886
  if(variable_get('cdm_debug_mode', FALSE)){
887
    $file = 'temporary://drupal_debug.txt';
888
    file_put_contents($file, 'CDM DEBUG LOG for ' . $_GET['q']. "\n"); // will overwrite the file
889
  }
890

    
891
  $bibliography_settings = get_bibliography_settings();
892
  $enclosing_tag = $bibliography_settings['enabled'] == 1 ? 'div' : 'span';
893
  FootnoteManager::registerFootnoteSet('BIBLIOGRAPHY', $enclosing_tag, $bibliography_settings['key_format']);
894
}
895

    
896
function cdm_dataportal_refresh_node($cdm_node_name, $uuid, $parameters = array()){
897

    
898
  $base_path = 'cdm_dataportal/' . $cdm_node_name . '/' . $uuid;
899

    
900
  if($cdm_node_name == 'taxon' && variable_get('cdm_dataportal_taxonpage_tabs', 1)){
901
    // force reloading of all and notify user about this special loading
902
    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: ')
903
        . l('Back to tabbed taxon page', $base_path));
904
    $base_path .= '/all';
905
  } else {
906
    drupal_set_message(t('The level 2 cache has been cleared for this page'));
907
  }
908

    
909
  $parameters['cacheL2_refresh'] ='1';
910

    
911

    
912
  drupal_goto($base_path, array('query' => $parameters));
913
}
914

    
915
/**
916
 * Implements hook_requirements($phase)
917
 */
918
function cdm_dataportal_requirements($phase) {
919
    $requirements = array();
920
    if($phase == 'runtime'){
921

    
922
    }
923
    return $requirements;
924
}
925

    
926
/**
927
 * Implements hook_block_info().
928
 */
929
function cdm_dataportal_block_info() {
930

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

    
986
/**
987
 * Implements hook_block_view().
988
 */
989
function cdm_dataportal_block_view($delta) {
990
  // TODO Rename block deltas (e.g. '2') to readable strings.
991
  switch ($delta) {
992
    // case 'delta-1':
993
    // $block['subject'] = t('Credits');
994
    // $block['content'] = theme('cdm_credits');
995
    // return $block;
996
    case '2':
997
      $block['subject'] = t('Search taxa');
998
      $form = drupal_get_form('cdm_dataportal_search_taxon_form');
999
      $block['content'] = drupal_render($form);
1000

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

    
1085

    
1086
/**
1087
 * Provides the uuid of the taxon for pages with the path ./taxon/{taxon_uuid}
1088
 *
1089
 * @return string
1090
 *   the taxon uuid or NULL
1091
 */
1092
function get_current_taxon_uuid()
1093
{
1094
  static $taxon_uuid;
1095

    
1096
  if(!isset($taxon_uuid)){
1097
    if(isset($_REQUEST['currentTaxon']) && is_uuid($_REQUEST['currentTaxon'])) {
1098
      $taxon_uuid = $_REQUEST['currentTaxon'];
1099
    } else if (arg(1) == 'taxon' && is_uuid(arg(2))) {
1100
      $taxon_uuid = arg(2);
1101
    } else {
1102
      $taxon_uuid = null;
1103
    }
1104
  }
1105

    
1106
  return $taxon_uuid;
1107
}
1108

    
1109
/**
1110
 * Returns the currently classification tree in use.
1111
 *
1112
 * @return string
1113
 *   The uuid of the currently focused classification
1114
 */
1115
function get_current_classification_uuid() {
1116
  if (isset($_SESSION['cdm']['taxonomictree_uuid']) && is_uuid($_SESSION['cdm']['taxonomictree_uuid'])) {
1117
    return $_SESSION['cdm']['taxonomictree_uuid'];
1118
  }
1119
  else {
1120
    return variable_get(CDM_TAXONOMICTREE_UUID, FALSE);
1121
  }
1122
}
1123

    
1124
/*
1125
 function cdm_dataportal_session_clear($cdm_ws_uri_update = FALSE){
1126
 $_SESSION['cdm'] = NULL;
1127
 if(is_string($cdm_ws_uri_update)){
1128
 $_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
1129
 }
1130
 }
1131

    
1132
 function cdm_dataportal_session_validate(){
1133
 if(!isset($_SESSION['cdm']['ws_uri'])){
1134
 $_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', FALSE));
1135
 } else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', FALSE)){
1136
 cdm_dataportal_session_clear(variable_get('cdm_webservice_url', FALSE));
1137
 }
1138
 }
1139
 */
1140

    
1141
/**
1142
 * creates a  selector form for taxonomic trees.
1143
 *
1144
 * @return array
1145
 *  a drupal form array
1146
 */
1147
function cdm_taxonomictree_selector() {
1148
  _add_js_treeselector();
1149

    
1150
  $form = drupal_get_form('cdm_taxonomictree_selector_form');
1151
  return $form;
1152
}
1153

    
1154
/**
1155
 * @todo Please document this function.
1156
 * @see http://drupal.org/node/1354
1157
 *
1158
 * used by cdm_taxonomictree_selector()
1159
 *
1160
 * @deprecated use compose_classification_selector instead
1161
 */
1162
function cdm_taxonomictree_selector_form($form, &$form_state) {
1163

    
1164
  $url = url('cdm_api/setvalue/session', array('query' => NULL));
1165
  $form['#action'] = $url;
1166

    
1167
  $form['var'] = array(
1168
    '#weight' => -3,
1169
    '#type' => 'hidden',
1170
    '#value' => '[cdm][taxonomictree_uuid]',
1171
  );
1172

    
1173
  $destination_array = drupal_get_destination();
1174
  $destination = $destination_array['destination'];
1175

    
1176
  $form['destination'] = array(
1177
    '#weight' => -3,
1178
    '#type' => 'hidden',
1179
    '#value' =>  $destination,
1180
  );
1181
  $options = cdm_get_taxontrees_as_options(
1182
    FALSE,
1183
    variable_get(CDM_TAXONTREE_INCLUDES, [])
1184
  );
1185
  $form['val'] = array(
1186
    '#type' => 'select',
1187
    '#title' => t('Available classifications'),
1188
    '#default_value' => get_current_classification_uuid(),
1189
    '#options' => $options,
1190
    '#attributes' => array('class' => array('highlite-first-child')),
1191
  );
1192

    
1193
  return $form;
1194

    
1195
}
1196

    
1197
/**
1198
 *
1199
 * @ingroup compose
1200
 */
1201
function compose_classification_selector() {
1202

    
1203
  $destination_array = drupal_get_destination();
1204
  $destination = $destination_array['destination'];
1205

    
1206
  $options = cdm_get_taxontrees_as_options(
1207
    FALSE,
1208
    variable_get(CDM_TAXONTREE_INCLUDES, [])
1209
  );
1210
  $items = array();
1211

    
1212
  $current_classification_uuid = get_current_classification_uuid();
1213

    
1214

    
1215
  foreach($options as $uuid=>$label){
1216
    $class_attributes = '';
1217
    if($current_classification_uuid == $uuid){
1218
      $class_attributes  = array('focused');
1219
    }
1220
    $items[] = array(
1221
      'data' => l($label,
1222
        'cdm_api/setvalue/session',
1223
        array(
1224
          'query' => array(
1225
            'destination' => $destination,
1226
            'val' => $uuid,
1227
            'var' => '[cdm][taxonomictree_uuid]'
1228
          ),
1229
        )
1230
      ),
1231
      'class' => $class_attributes
1232
    );
1233
  }
1234

    
1235
  $render_array = array(
1236
    '#theme' => 'item_list',
1237
    '#type' => 'ul',
1238
    '#items' => $items
1239
  );
1240

    
1241
  return $render_array;
1242
}
1243

    
1244

    
1245
/* ====================== menu callback functions ====================== */
1246
/**
1247
 * @todo Please document this function.
1248
 * @see http://drupal.org/node/1354
1249
 */
1250
/*
1251
function cdm_dataportal_form_alter(&$form, &$form_state, $form_id) {
1252
  static $comment_node_disabled =  0;
1253
  static $comment_node_read_only =  1;
1254
  static $comment_node_read_write =  2;
1255

    
1256
  if ($form_id == 'node_type_form'
1257
   && isset($form['identity']['type'])
1258
   && array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
1259
  ) {
1260
    $form['workflow']['comment'] = array(
1261
      '#type' => 'radios',
1262
      '#title' => t('Default comment setting'),
1263
      '#default_value' => variable_get('comment__' . $node->type . $form['#node_type']->type, $comment_node_disabled),
1264
      '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
1265
      '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
1266
    );
1267
  }
1268
}
1269
*/
1270

    
1271
/**
1272
 * Displays a list of the known taxonomic names.
1273
 *
1274
 * When the list of taxonomic names is displayed, long lists are split up into
1275
 * multiple pages.
1276
 *
1277
 * TODO: Parameters are still preliminary.
1278
 *
1279
 * @param string $beginsWith
1280
 * @param string $page
1281
 *   Page number to diplay defaults to page 1.
1282
 * @param bool $onlyAccepted
1283
 */
1284
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = FALSE) {
1285

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

    
1288
  /*
1289
  // FIXME the filter for accepted names will be a form element, thus this
1290
  // widget should be generated via form api preferably as block.
1291
  $out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
1292
  $out .= theme('cdm_dataportal_widget_names_list', $names, $page);
1293
  $out .= theme('cdm_listof_taxa', $taxonPager);
1294
  return $out;
1295
  */
1296
}
1297

    
1298
/**
1299
 * @todo Please document this function.
1300
 * @see http://drupal.org/node/1354
1301
 * @throws Exception
1302
 */
1303
function cdm_dataportal_view_reference($uuid, $arg2 = NULL) {
1304

    
1305
  cdm_check_valid_portal_page();
1306

    
1307
  return compose_cdm_reference_page($uuid);
1308
}
1309

    
1310
/**
1311
 * Creates a view on a all references contained in the portal.
1312
 *
1313
 * This function is used at the path cdm_dataportal/reference/list
1314
 */
1315
function cdm_dataportal_view_reference_list($pageNumber) {
1316
  $referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get(CDM_SEARCH_RESULT_PAGE_SIZE, CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT), $pageNumber);
1317
  cdm_reference_pager($referencePager, 'cdm_dataportal/reference/list/');
1318
}
1319

    
1320
/**
1321
 * @todo Please document this function.
1322
 * @see http://drupal.org/node/1354
1323
 */
1324
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = FALSE, $part = 0) {
1325

    
1326
  cdm_check_valid_portal_page();
1327

    
1328
  $media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
1329
  if (!$media) {
1330
    drupal_set_title(t('Media does not exist'), PASS_THROUGH);
1331
    return "";
1332
  }
1333
  return theme('cdm_media_page', array(
1334
    'media' => $media,
1335
    'mediarepresentation_uuid' => $mediarepresentation_uuid,
1336
    'partId' => $part,
1337
    ));
1338
}
1339

    
1340
/**
1341
 * Loads the media associated to the given taxon from the cdm server.
1342
 * The aggregation settings regarding taxon relathionships and
1343
 * taxonnomic childen are taken into account.
1344
 *
1345
 * The media lists are cached in a static variable.
1346
 *
1347
 * @param Taxon $taxon
1348
 *   A CDM Taxon entity
1349
 *
1350
 * @return array
1351
 *   An array of CDM Media entities
1352
 *
1353
 */
1354
  function _load_media_for_taxon($taxon) {
1355

    
1356
  static $media = NULL;
1357

    
1358
  if(!isset($media)) {
1359
    $media = array();
1360
  }
1361
  if (!isset($media[$taxon->uuid])) {
1362

    
1363

    
1364
    $mediaQueryParameters = taxon_media_query_parameters();
1365

    
1366
    $ws_endpoint = NULL;
1367
    if ( $mediaQueryParameters['includeTaxonomicChildren']) {
1368
      $ws_endpoint = CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA;
1369
    } else {
1370
      $ws_endpoint = CDM_WS_PORTAL_TAXON_MEDIA;
1371
    }
1372
    // this parameter is not yet used by the CDM_WS_PORTAL_TAXON_*MEDIA
1373
    // services
1374
    unset($mediaQueryParameters['includeTaxonomicChildren']);
1375

    
1376
    $media[$taxon->uuid] = cdm_ws_get($ws_endpoint,
1377
        array(
1378
            $taxon->uuid,
1379
        ),
1380
        queryString($mediaQueryParameters)
1381
       );
1382
  }
1383

    
1384
  return $media[$taxon->uuid];
1385
}
1386

    
1387
/**
1388
 *
1389
 * @param Taxon $taxon
1390
 *   A CDM Taxon entitiy
1391
 *
1392
 * @return array
1393
 *   An array of CDM SpecimenOrObservation entities
1394
 *
1395
function _load_occurences_for_taxon($taxon){
1396

    
1397
  static $occurences = NULL;
1398

    
1399
  if(!isset($occurences)) {
1400
    $occurences = array();
1401
  }
1402

    
1403
  if (!isset($occurences[$taxon->uuid])){
1404

    
1405
    $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1406
    $relationship_choice['direct'] = get_selection($relationship_choice['direct']);
1407
    $relationship_choice['invers'] = get_selection($relationship_choice['invers']);
1408

    
1409
    $by_associatedtaxon_query = http_build_query(array(
1410
        'relationshipsInvers' => implode(',', $relationship_choice['invers']),
1411
        'relationships' => implode(',', $relationship_choice['direct']),
1412
        'pageSize' => null // all hits in one page
1413
    )
1414
    );
1415

    
1416
    $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
1417
        null,
1418
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
1419
    );
1420

    
1421

    
1422
    if(isset($pager->records[0])){
1423
      $occurences[$taxon->uuid] =  $pager->records;
1424
    }
1425
  }
1426
  return $occurences[$taxon->uuid];
1427
}
1428
 */
1429

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

    
1462
/**
1463
 * Recursive function to convert an object into an array.
1464
 * also subordinate objects will be converted.
1465
 *
1466
 * @param object $object
1467
 *  the object to be converted
1468
 * @return array
1469
 *  The array
1470
 */
1471
function object_to_array($object) {
1472
  if(is_object($object) || is_array($object)) {
1473
    $array = (array)$object;
1474
    foreach ($array as $key=>$value){
1475
      $array[$key] = object_to_array($value);
1476
    }
1477
    return $array;
1478
  } else {
1479
    return $object;
1480
  }
1481
}
1482

    
1483
/**
1484
 * Searches the $collection for the cdm entitiy given as $element.
1485
 *
1486
 * The elements are compared by their UUID.
1487
 *
1488
 * @param $element
1489
 *  the CDM entitiy to search for
1490
 * @param $collection
1491
 *  the list of CDM entities to search in
1492
 *
1493
 * @return boolean TRUE if the $collection contains the $element, otheriwse FALSE
1494
 *
1495
 */
1496
function contains_cdm_entitiy($element, $collection) {
1497
  $result = FALSE;
1498
  foreach ($collection as $a) {
1499
    if ($a->uuid == $element->uuid) {
1500
      $result = TRUE;
1501
    }
1502
  }
1503
  return $result;
1504
}
1505

    
1506
/**
1507
 * Filters the array $entity_list of CDM entities by the list
1508
 * of $excludes. Any element contained in the $excludes will be removed
1509
 * from included int the returned list.
1510
 *
1511
 * If the $entity_list is not an array the $excludes will be returned.
1512
 */
1513
function filter_cdm_entity_list($entity_list, $excludes) {
1514
  if (is_array($entity_list)) {
1515
    $result = $entity_list;
1516
    if ($excludes) {
1517
      foreach ($excludes as $exclude) {
1518
        if (!contains_cdm_entitiy($exclude, $entity_list)) {
1519
          $result[] = $exclude;
1520
        }
1521
      }
1522
    }
1523
  }
1524
  else {
1525
    $result = $excludes;
1526
  }
1527
  return $result;
1528
}
1529

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

    
1564
/**
1565
 * Loads the subgraph of a given PolytomousKeyNode.
1566
 *
1567
 * Loads the subgraph of the given PolytomousKeyNode recursively from
1568
 * the CDM REST service.
1569
 *
1570
 * @param mixed $polytomousKeyNode
1571
 *   PolytomousKeyNode passed by reference.
1572
 *
1573
 * @return void
1574
 */
1575
function _load_polytomousKeySubGraph(&$polytomousKeyNode) {
1576

    
1577
  if (!$polytomousKeyNode) {
1578
    return;
1579
  }
1580
  if ($polytomousKeyNode->class != "PolytomousKeyNode") {
1581
    drupal_set_message('_load_polytomousKeySubGraph(): ' . t('invalid type given.'), 'error');
1582
    return;
1583
  }
1584
  if (!is_uuid($polytomousKeyNode->uuid)) {
1585
    drupal_set_message('_load_polytomousKeySubGraph(): ' . t('invalid type given.'), 'error');
1586
    return;
1587
  }
1588

    
1589
  $polytomousKeyNode = cdm_ws_get(CDM_WS_PORTAL_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid);
1590

    
1591
  if (!$polytomousKeyNode) {
1592
    // drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error");
1593
    return;
1594
  }
1595

    
1596
  // Load children.
1597
  foreach ($polytomousKeyNode->children as &$childNode) {
1598
    _load_polytomousKeySubGraph($childNode);
1599
  }
1600
  return;
1601
}
1602

    
1603
/**
1604
 * @todo Please document this function.
1605
 * @see http://drupal.org/node/1354
1606
 */
1607
function cdm_dataportal_view_polytomousKey($polytomousKeyUuid) {
1608

    
1609
  cdm_check_valid_portal_page();
1610

    
1611
  $polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid);
1612
  if (!$polytomousKey) {
1613
    drupal_set_title(t('Polytomous key does not exist'), PASS_THROUGH);
1614
    return "";
1615
  }
1616

    
1617
  $sourcePager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources'));
1618
  if (is_array($sourcePager->records)) {
1619
    $polytomousKey->sources = $sourcePager->records;
1620
    // $polytomousKey->sources->citation = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources'));
1621
  }
1622

    
1623
  $annotationPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'annotations'));
1624
  if (is_array($annotationPager->records)) {
1625
    $polytomousKey->annotations = $annotationPager->records;
1626
  }
1627

    
1628
  _load_polytomousKeySubGraph($polytomousKey->root);
1629
  return theme('cdm_polytomousKey_page', array('polytomousKey' => $polytomousKey));
1630
}
1631

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

    
1651
  cdm_check_valid_taxon_page($chapter);
1652
  cdm_dd("START OF TAXON PAGE [" . $chapter . "] " . $uuid . ' for ' . $_GET['q']);
1653

    
1654

    
1655
  // Display the page for the taxon defined by $uuid.
1656
  // set_last_taxon_page_tab(arg(3));
1657
  $taxonpage = cdm_dataportal_taxon_view($uuid, $chapter);
1658
  if (!empty($taxonpage)) {
1659
    cdm_dd("END OF TAXON PAGE [" . $chapter . "] " . $uuid);
1660
    return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title, $taxonpage->content);
1661
  }
1662
  else {
1663
    cdm_dd("END OF TAXON PAGE [" . $chapter . "] " . $uuid . ' !!! PAGE IS EMPTY !!!');
1664
    return '';
1665
  }
1666
}
1667

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

    
1696
  $taxonpage->title = theme('cdm_taxon_page_title', array(
1697
    'taxon' => $taxon
1698
  ));
1699

    
1700
  // Check if the taxon id contained in the currently selected tree.
1701
  $taxon_in_current_classification = taxon_in_current_classification($uuid);
1702

    
1703
  if (!$taxon_in_current_classification) {
1704
    $classifications = get_classifications_for_taxon($taxon);
1705
    RenderHints::pushToRenderStack('not_in_current_classification');
1706
    RenderHints::setFootnoteListKey('not_in_current_classification');
1707
    FootnoteManager::blockFootnotesFor('not_in_current_classification');
1708
    $taxon_name_markup = render_taxon_or_name($taxon);
1709
    FootnoteManager::unblockFootnotesFor('not_in_current_classification');
1710
    RenderHints::clearFootnoteListKey();
1711

    
1712
    if (count($classifications) == 0) {
1713
      drupal_set_message(t('This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification.',
1714
        array(
1715
        '!taxonname' => $taxon_name_markup,
1716
        )
1717
      ), 'warning');
1718
    }
1719
    else {
1720
      $trees = '';
1721
      foreach ($classifications as $classification) {
1722
        if (isset($classification->titleCache)) {
1723
          $trees .= ($trees ? ', ' : '') . '<strong>' . $classification->titleCache . '</strong>';
1724
        }
1725
      }
1726

    
1727
      drupal_set_message(format_plural(count($trees),
1728
          'This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification, but in this one: !trees',
1729
          'This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification, but in one of these: !trees',
1730
          array('!taxonname' => $taxon_name_markup, '!trees' => $trees)
1731
        ) ,
1732
        'warning');
1733
    }
1734
    RenderHints::popFromRenderStack();
1735
  }
1736

    
1737
  // Render the taxon page.
1738
  $render_array = compose_cdm_taxon_page($taxon, $chapter);
1739
  $taxonpage->content = drupal_render($render_array);
1740

    
1741
  return $taxonpage;
1742
}
1743

    
1744

    
1745
function cdm_dataportal_specimen_by_accession_number_page_view($accession_number)
1746
{
1747
  cdm_check_valid_portal_page();
1748

    
1749
  $specimenpage = specimen_by_accession_number_view($accession_number);
1750

    
1751
  if (!empty($specimenpage)) {
1752
    return cdm_node_show_simulate($specimenpage->content);
1753
  }
1754
  else {
1755
    return '';
1756
  }
1757

    
1758

    
1759
}
1760

    
1761
/**
1762
 * Creates a specimen page view.
1763
 * @param string $uuid the UUID of the specimen
1764
 * @return array|string
1765
 */
1766
function cdm_dataportal_specimen_page_view($uuid) {
1767

    
1768
    cdm_check_valid_portal_page();
1769
    $specimenpage = cdm_dataportal_specimen_view($uuid);
1770
    if (!empty($specimenpage)) {
1771
        return cdm_node_show_simulate($specimenpage->content);
1772
    }
1773
    else {
1774
        return '';
1775
    }
1776
}
1777

    
1778

    
1779
/**
1780
 * Creates a specimen page view.
1781
 * @param string $uuid the UUID of the specimen
1782
 * @return object
1783
 *  The page object with the following fields:
1784
 *   - 'title': the page title
1785
 *   - 'content' : the page content rendered as markup
1786
 */
1787
function specimen_by_accession_number_view($accession_number = null) {
1788

    
1789
  $field_unit_dto = cdm_ws_get(CDM_WS_OCCURRENCE_ACCESSION_NUMBER, null, 'accessionNumber=' . $accession_number);
1790

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

    
1820

    
1821
    }
1822
    $specimenpage = new stdClass();
1823

    
1824
    $specimenpage->title = render_cdm_specimen_dto_page_title($field_unit_dto);
1825

    
1826
     $render_array['markup'] = $specimen_table;
1827
     $specimenpage->content = drupal_render($render_array);
1828
  }
1829

    
1830
  return $specimenpage;
1831
}
1832

    
1833

    
1834
/**
1835
 *
1836
 * Creates a specimen view.
1837
 * @param string $uuid the UUID of the specimen
1838
 * @return object
1839
 *    Page object with the fields
1840
 *    - title
1841
 *    - content
1842
 */
1843
function cdm_dataportal_specimen_view($uuid) {
1844

    
1845
    $sob_dto = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE_AS_DTO, $uuid);
1846
    if (empty($sob_dto)) {
1847
        drupal_set_title(t('Specimen does not exist'), PASS_THROUGH);
1848
        return FALSE;
1849
    }
1850
    $specimenpage = new stdClass();
1851
    $specimenpage->title = render_specimen_page_title($sob_dto);
1852

    
1853
    // Render the specimen page.
1854
    $render_array = compose_cdm_specimen_page($sob_dto);
1855
    $specimenpage->content = drupal_render($render_array);
1856

    
1857
    return $specimenpage;
1858
}
1859

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

    
1881
    } else {
1882
      $description_page->title = $description->titleCache;
1883
      drupal_set_title($description_page->title); // not necessary if correctly implemented as drupal node
1884

    
1885
      // Render the description page.
1886
      $render_array = compose_description_table($description->uuid, $descriptive_dataset_uuid);
1887
      if($render_array['title']){
1888
        $page_title = strip_tags($render_array['title']['#markup']);
1889
        drupal_set_title($page_title);
1890
        unset($render_array['title']);
1891
      }
1892
      $description_page->content = drupal_render($render_array);
1893
    }
1894

    
1895
    return $description_page;
1896
}
1897

    
1898
function cdm_dataportal_description_page_view($uuid, $descriptive_dataset_uuid = NULL) {
1899

    
1900
  cdm_check_valid_portal_page();
1901
  $descriptionpage = cdm_dataportal_description_view($uuid, $descriptive_dataset_uuid);
1902
  if (!empty($descriptionpage)) {
1903
    return cdm_node_show_simulate($descriptionpage->content);
1904
  }
1905
  else {
1906
    return NULL;
1907
  }
1908
}
1909

    
1910
/**
1911
 *
1912
 * Creates a named area view.
1913
 * @param string $uuid the UUID of the specimen
1914
 *  * @return object
1915
 *   An object with two fields:
1916
 *     - title: the page title
1917
 *     - content: the page content
1918
 */
1919

    
1920
function cdm_dataportal_named_area_view($uuid) {
1921
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, $uuid);
1922
  if (empty($named_area) || $named_area->class !== 'NamedArea') {
1923
    drupal_set_title(t('Named area does not exist'), PASS_THROUGH);
1924
    return null;
1925
  }
1926
  $named_area_page = new stdClass();
1927

    
1928
  $named_area_page->title = $named_area->representation_L10n;
1929

    
1930
  // Render the specimen page.
1931
  $render_array = compose_cdm_named_area_page($uuid);
1932
  $named_area_page->content = drupal_render($render_array);
1933

    
1934
  return $named_area_page;
1935
}
1936

    
1937
function cdm_dataportal_named_area_page_view($uuid) {
1938

    
1939
  cdm_check_valid_portal_page();
1940

    
1941
  $named_area_page = cdm_dataportal_named_area_view($uuid);
1942
  if (!empty($named_area_page)) {
1943
    return cdm_node_show(NODETYPE_NAME, $uuid, $named_area_page->title, $named_area_page->content);
1944
  }
1945
  else {
1946
    return '';
1947
  }
1948

    
1949

    
1950
}
1951

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

    
1976
  cdm_check_valid_portal_page();
1977

    
1978
  $taxonname_page = cdm_dataportal_name_view(
1979
    is_uuid($taxon_name_uuid) ? $taxon_name_uuid : null,
1980
    is_uuid($taxon_to_hide_uuid) ? $taxon_to_hide_uuid : null,
1981
    $redirect_to_taxon == 'redirect_to_taxon',
1982
    is_uuid($synonym_uuid) ? $synonym_uuid : null);
1983
  if (!empty($taxonname_page)) {
1984
    return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title, $taxonname_page->content);
1985
  }
1986
  else {
1987
    return '';
1988
  }
1989
}
1990

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

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

    
2082
    RenderHints::pushToRenderStack('name_page');
2083
    RenderHints::setFootnoteListKey('name_page');
2084
    $content['taxon_name'] = markup_to_render_array(render_taxon_or_name($taxon_name), null, '<div class="name-page-name">', '</div>');
2085

    
2086

    
2087
    // name relationships
2088
    $name_relations = cdm_ws_fetch_all(str_replace("$0", $taxon_name->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
2089
    if(count($name_relations) > 0){
2090
      $content['name_relationships'] = compose_name_relationships_list($name_relations, $taxon_name->uuid, null);
2091
    }
2092

    
2093
    // type designations
2094
    $type_designations_render_array = compose_type_designations($taxon_name->uuid);
2095
    $content = array_merge($content, $type_designations_render_array);
2096
    // registrations
2097
    $registrationDTOs= cdm_ws_fetch_all(CDM_WS_REGISTRATION_DTO,  array('nameUuid' => $taxon_name_uuid));
2098
    if(isset($registrationDTOs) && count($registrationDTOs ) > 0 ){
2099
      $content['registrations'][] = markup_to_render_array('<h2>' . t("Registrations") . '</h2>') ;
2100
      foreach ($registrationDTOs as $regDTO){
2101
        $content['registrations'][] = compose_registration_dto_compact($regDTO);
2102
      }
2103
    }
2104

    
2105

    
2106
    // related taxa
2107
    $show_taxa_section = variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT);
2108
    if($show_taxa_section){
2109
      if ($taxa) {
2110
        $content['related_taxa_header'] = markup_to_render_array("<h2>" . count($taxa) > 1 ? t("Taxa for this name") :  t("Taxon for this name") . "</h2>");
2111
        $content['related_taxa'] = compose_list_of_taxa($taxa);
2112
      }
2113
      else {
2114
        $content['related_taxa'] = markup_to_render_array('This name is not assigned to any taxon.', null, '<div class="no-taxon-message">', '</div>');
2115
      }
2116
    }
2117

    
2118
    $content['footnotes'] = markup_to_render_array(render_footnotes());
2119

    
2120
    $taxon_name_page->content = $content;
2121
    RenderHints::popFromRenderStack();
2122
    RenderHints::clearFootnoteListKey();
2123
    return $taxon_name_page;
2124
  }
2125
}
2126

    
2127

    
2128
/**
2129
 * Returns a registration page as a Drupal node to be rendered by Drupal.
2130
 *
2131
 * @param string  $registration_identifie
2132
 *   The persistent identifier of the registration urlencoded.
2133
 * @return mixed
2134
 *   The formatted registration page as node.
2135
 */
2136
function cdm_dataportal_registration_page_view() {
2137

    
2138
  cdm_check_valid_portal_page("/\/cdm_dataportal\/registration/");
2139
  $registration_identifier = $_REQUEST['identifier'];
2140
  $registration_page = cdm_dataportal_registration_view($registration_identifier);
2141
  return cdm_node_show_simulate($registration_page);
2142
}
2143

    
2144
/**
2145
 * @param $registration_identifier
2146
 * @return array
2147
 *   The drupal render array for the registration view.
2148
 */
2149
function cdm_dataportal_registration_view($registration_identifier) {
2150

    
2151
  RenderHints::pushToRenderStack('registration_page');
2152
  RenderHints::setFootnoteListKey('registration_page');
2153

    
2154
  $render_array = array();
2155
  $registration_dto = cdm_ws_get(CDM_WS_REGISTRATION_DTO, null, 'identifier=' . $registration_identifier);
2156
  if($registration_dto){
2157

    
2158
    drupal_set_title(t('Registration Id:') . ' ' . $registration_identifier, PASS_THROUGH);
2159
    $render_array = compose_registration_dto_full($registration_dto, true);
2160

    
2161
  } else {
2162
    $status_text = cdm_ws_get(CDM_WS_REGISTRATION_STATUS, null, 'identifier=' . $registration_identifier);
2163
    if(isset($status_text->String)) {
2164
      $status_text = strtolower($status_text->String);
2165
      if($status_text == 'preparation' || $status_text == 'curation'){
2166
        $status_text = 'in ' . $status_text;
2167
      }
2168
      drupal_set_title(t('Registration ' . $status_text), PASS_THROUGH);
2169
      //$status_message;
2170
      drupal_set_message("A registration with the identifier  " . $registration_identifier . " is " . $status_text, "status");
2171
    } else {
2172
      drupal_set_title(t('Registration not found'), PASS_THROUGH);
2173
      drupal_set_message("A registration with the identifier  " . $registration_identifier . " does not exist", "warning");
2174
    }
2175
  }
2176

    
2177
  $render_array = array(
2178
    '#prefix' => '<div id="registration">',
2179
    'registration' => $render_array,
2180
    '#suffix' => '</div>',
2181
  );
2182

    
2183
  RenderHints::popFromRenderStack();
2184
  RenderHints::clearFootnoteListKey();
2185

    
2186
  return $render_array ;
2187
}
2188

    
2189

    
2190
/**
2191
 * Creates a page with the advance search form.
2192
 *
2193
 * NOTE: The advance search form allows searching for taxa.
2194
 */
2195
function cdm_dataportal_view_search_advanced() {
2196
  drupal_set_title(t('Advanced search'), PASS_THROUGH);
2197
  return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
2198
}
2199

    
2200
/**
2201
 * Creates a page with the blast search form.
2202
 *
2203
 * NOTE: The advance search form allows searching for specimen in blast DB.
2204
 */
2205
function cdm_dataportal_view_search_blast() {
2206
    drupal_set_title(t('Blast search'), PASS_THROUGH);
2207
    return drupal_get_form('cdm_dataportal_search_blast_form');
2208
}
2209

    
2210
/**
2211
 * Creates a page with the search form for searching by taxon descriptions.
2212
 */
2213
function cdm_dataportal_view_search_taxon_by_description() {
2214
  drupal_set_title(t('Search by factual data'), PASS_THROUGH);
2215
  return drupal_get_form('cdm_dataportal_search_taxon_by_description_form');
2216
}
2217

    
2218
/**
2219
 * Executes the search and generates the result list of taxa.
2220
 */
2221
function cdm_dataportal_view_search_results_taxon() {
2222

    
2223
  $taxonPager = cdm_dataportal_search_taxon_execute();
2224

    
2225
  $showThumbnails = do_showThumbnails();
2226

    
2227
  $setSessionUri = url('cdm_api/setvalue/session', array(
2228
      'query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => ''),
2229
  ));
2230

    
2231
  drupal_add_js('jQuery(document).ready(function() {
2232

    
2233
      // init
2234
      if(' . $showThumbnails . ' == 1){
2235
          jQuery(\'.media_gallery\').show(20);
2236
      } else {
2237
          jQuery(\'.media_gallery\').hide(20);
2238
      }
2239

    
2240
      // add change handler
2241
      jQuery(\'#showThumbnails input.showThumbnails\').change(
2242
      function(event){
2243
        var state = 0;
2244
        if(jQuery(this).is(\':checked\')){
2245
          jQuery(\'.media_gallery\').show(20);
2246
          state = 1;
2247
        } else {
2248
          jQuery(\'.media_gallery\').hide(20);
2249
        }
2250
        // store state in session variable
2251
        var uri = \'' . $setSessionUri . '\' + state;
2252
        jQuery.get(uri);
2253
      });
2254
  });',
2255
  array('type' => "inline", 'scope' => JS_DEFAULT));
2256

    
2257
  drupal_set_title(t('Search results'), PASS_THROUGH);
2258

    
2259
  return theme('cdm_search_taxa_results', array(
2260
    'pager' => $taxonPager,
2261
    'path' => 'cdm_dataportal/search/results/taxon',
2262
    ));
2263
}
2264

    
2265
/**
2266
 * Executes the blast search and generates the result list of specimen.
2267
 */
2268
function cdm_dataportal_view_search_results_specimen() {
2269

    
2270
    $specimenPager = cdm_dataportal_search_blast_execute();
2271

    
2272
    return theme('cdm_search_specimen_results', array(
2273
        'pager' => $specimenPager,
2274
        'path' => 'cdm_dataportal/search/results/specimen',
2275
    ));
2276
}
2277

    
2278

    
2279
/**
2280
 * Executes the search for registrations and generates the result list..
2281
 */
2282
function cdm_dataportal_view_search_registrations_results($mode = 'filter') {
2283

    
2284
  switch($mode ){
2285
    case 'taxongraph':
2286
      $block = block_load('cdm_dataportal', 'registrations_search_taxongraph');
2287
      $registration_pager = cdm_dataportal_search_registrations_taxongraph_execute();
2288
      break;
2289
    case 'filter':
2290
    default:
2291
      $block = block_load('cdm_dataportal', 'registrations_search_filter');
2292
      $registration_pager = cdm_dataportal_search_registrations_filter_execute();
2293
  }
2294
  $block->title = null;
2295

    
2296
  drupal_set_title(t('Search registrations'), PASS_THROUGH);
2297

    
2298
  $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
2299
  $registrations_pager_array = compose_search_results($registration_pager, new RegistrationDTOComposeHandler());
2300
  $render_array = array_merge($render_array, $registrations_pager_array);
2301

    
2302
  return $render_array;
2303
}
2304

    
2305
/**
2306
 * Executes the search for registrations and generates the result list..
2307
 */
2308
function cdm_dataportal_view_search_agent() {
2309

    
2310
  $render_array = [];
2311
  $title = isset($_REQUEST['class']) && $_REQUEST['class'] ? $_REQUEST['class'] : 'Persons & Teams';
2312
  drupal_set_title(t($title), PASS_THROUGH);
2313
  // TODO $block = block_load('cdm_dataportal', 'search_agent_filter');
2314
  // $block->title = null;
2315
  // $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
2316
  $pager = cdm_dataportal_search_agent_execute();
2317
  $pager_render_array = compose_search_results($pager, new AgentComposeHandler());
2318
  $render_array = array_merge($render_array, $pager_render_array);
2319
  return $render_array;
2320
}
2321

    
2322

    
2323
/**
2324
 * Provides the standard image which indicated a loading process
2325
 *
2326
 * @return string
2327
 *  The img html tag
2328
 */
2329
function loading_image_html() {
2330
  return '<img class="loading" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal')
2331
    . '/images/loading_circle_grey_16.gif" style="display:none;">';
2332
}
2333

    
2334
/**
2335
 * Returns the state of the the showThumbnails flag set in the
2336
 * users session ($_SESSION['pageoption']['searchtaxa']['showThumbnails']).
2337
 *
2338
 * @return boolean
2339
 *    returns 1 if the flag is set
2340
 */
2341
function do_showThumbnails() {
2342
  static $showThumbnails = null;
2343

    
2344
  if($showThumbnails == null) {
2345
    $showThumbnails = 0;
2346
    if (!isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2347
      $showThumbnails = 0;
2348
      $search_gallery_settings = variable_get(CDM_DATAPORTAL_SEARCH_GALLERY_NAME, null);
2349
      $showThumbnails = is_array($search_gallery_settings)
2350
        && isset($search_gallery_settings['cdm_dataportal_show_taxon_thumbnails'])
2351
        && (
2352
            $search_gallery_settings['cdm_dataportal_show_taxon_thumbnails'] +
2353
            $search_gallery_settings['cdm_dataportal_show_synonym_thumbnails'] +
2354
            $search_gallery_settings['cdm_dataportal_show_thumbnail_captions'] > 0
2355
            )
2356
         ? 1 : 0;
2357

    
2358
       drupal_array_set_nested_value($_SESSION, array('pageoption', 'searchtaxa', 'showThumbnails'), $showThumbnails);
2359
    }
2360
    $showThumbnails = $_SESSION['pageoption']['searchtaxa']['showThumbnails'];
2361
    if (!is_numeric($showThumbnails)) {
2362
      $showThumbnails = 1;
2363
    }
2364
  }
2365

    
2366
  return $showThumbnails;
2367
}
2368

    
2369

    
2370

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

    
2395
  $tab = get_default_taxon_tab();
2396
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
2397

    
2398
  if (!$uuid) {
2399
    return FALSE;
2400
  }
2401

    
2402
  if ($page_tab) {
2403
    $url = 'cdm_dataportal/taxon/' . $uuid . '/' . $page_tab;
2404
  }
2405
  elseif (!$tab || strtolower($tab) == 'general') {
2406
    $url = 'cdm_dataportal/taxon/' . $uuid;
2407
  }
2408
  elseif (get_last_taxon_page_tab() &&   $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]) {
2409
    $url = 'cdm_dataportal/taxon/' . $uuid . '/' . get_last_taxon_page_tab();
2410
  }
2411
  else {
2412
    $url = 'cdm_dataportal/taxon/' . $uuid . '/' . strtolower($tab);
2413
  }
2414
  return $url;
2415
}
2416

    
2417
function path_to_description($uuid, $descriptive_dataset_uuid = NULL) {
2418

    
2419
    if (!$uuid) {
2420
        return FALSE;
2421
    }
2422
    else {
2423
      return 'cdm_dataportal/description/' . $uuid
2424
        . (is_uuid($descriptive_dataset_uuid) ? '/' . $descriptive_dataset_uuid : '');
2425
    }
2426
}
2427

    
2428
function path_to_specimen($uuid) {
2429

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

    
2438
function path_to_specimen_by_accession_number($accession_number) {
2439

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

    
2448
function path_to_named_area($uuid) {
2449

    
2450
  if (!$uuid) {
2451
    return FALSE;
2452
  }
2453
  else {
2454
    return 'cdm_dataportal/named_area/' . $uuid;
2455
  }
2456
}
2457

    
2458
/**
2459
 * @param $uuid
2460
 *
2461
 * @return string
2462
 */
2463
function path_to_collection($uuid) {
2464
  if (!$uuid) {
2465
    return '';
2466
  }
2467
  else {
2468
    return 'cdm_dataportal/collection/' . $uuid;
2469
  }
2470
}
2471

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

    
2501
}
2502

    
2503
/**
2504
 * Composes the drupal path to the key identified by the uuid.
2505
 *
2506
 * @param string $keyType
2507
 *    the key typer corresponds to the specific class of the CDM
2508
 *    IdentificationKey. Possible values are
2509
 *      -PolytomousKey
2510
 *      -MultimediaKey
2511
 *      - ...
2512
 * @param string $keyUuid
2513
 *   The UUID of the key
2514
 */
2515
function path_to_key($keyType, $keyUuid) {
2516
  if (!$keyUuid || !$keyType) {
2517
    return FALSE;
2518
  }
2519
  $keyType[0] = strtolower($keyType[0]);
2520
  return "cdm_dataportal/" . $keyType . "/$keyUuid";
2521
}
2522

    
2523
/**
2524
 * Composes the drupal path to the reference identified by the uuid.
2525
 *
2526
 * @param $uuid string String representation of the registration entity uuid.
2527
 *
2528
 * @return string
2529
 *  The drupal path
2530
 *
2531
 */
2532
function path_to_reference($uuid) {
2533
  if (!$uuid) {
2534
    return FALSE;
2535
  }
2536
  return 'cdm_dataportal/reference/' . $uuid;
2537
}
2538

    
2539
/**
2540
 * @param string $registration_identifier
2541
 *  The persistent identifier of the registration entity (Registration.identifier).
2542
 *
2543
 * @return string
2544
 *  the markup for a HTML link
2545
 */
2546
function render_link_to_registration($registration_identifier) {
2547

    
2548
  if(variable_get(CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK)){
2549
    $path = $registration_identifier;
2550
    $query = [];
2551
  } else {
2552
    $path = 'cdm_dataportal/registration';
2553
    $query = ['identifier' => $registration_identifier];
2554
  }
2555
  return l($registration_identifier, $path, array('attributes' => array('class' => array('identifier')), 'query' => $query));
2556
}
2557

    
2558

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

    
2587
  return $res;
2588
}
2589

    
2590
/**
2591
 * Composes the drupal path to the media entity identified by the uuid.
2592
 *
2593
 * @param string $uuid
2594
 *  The persistent identifier of the entity entity
2595
 * @return string
2596
 *  The drupal path
2597
 */
2598
function path_to_media($uuid, $representaion_uuid = FALSE, $partId = FALSE) {
2599
  if (!$uuid) {
2600
    return FALSE;
2601
  }
2602
  $out = 'cdm_dataportal/media/' . $uuid;
2603
  if ($representaion_uuid) {
2604
    $out .= '/' . $representaion_uuid;
2605
    if (is_numeric($partId)) {
2606
      $out .= '/' . $partId;
2607
    }
2608
  }
2609
  return $out;
2610
}
2611

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

    
2640
/**
2641
 * Creates a short version of a taxonname.
2642
 *
2643
 * The short name is created by using the taggedTitle field of
2644
 * TaxonNodeDTO instances.
2645
 * If the taggedTitle if empty the fullname will be returned.
2646
 *
2647
 * @param object $taxonNodeDTO
2648
 *   A TaxonNodeDTO object
2649
 *
2650
 * @return string
2651
 */
2652
function cdm_dataportal_shortname_of($taxonNodeDTO) {
2653

    
2654
  $nameStr = '';
2655

    
2656
  normalize_tagged_text($taxonNodeDTO->taggedTitle);
2657

    
2658
  // Get all tagged text tokens of the scientific name.
2659
  foreach ($taxonNodeDTO->taggedTitle as $tagtxt) {
2660
    if ($tagtxt->type == 'name' || $tagtxt->type == 'rank') {
2661
      $nameStr .= ($nameStr ? ' ' : '') . $tagtxt->text;
2662
    }
2663
  }
2664
  $nameStr = trim($nameStr);
2665

    
2666
  if ($nameStr) {
2667
    if(isset($taxonNodeDTO->status->symbol)){
2668
      $nameStr = $taxonNodeDTO->status->symbol . ' ' . $nameStr;
2669
    }
2670
    // Do not return short names for these.
2671
    if ($taxonNodeDTO->unplaced || $taxonNodeDTO->excluded) {
2672
      return $nameStr;
2673
    }
2674

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

    
2695
/**
2696
 * Check if a taxon is accepted by the current taxonomic tree.
2697
 *
2698
 * @param mixed $taxon
2699
 *   The Taxon obkect to check.
2700
 *
2701
 * @return bool
2702
 *   Returns TRUE if $taxon is accepted, FALSE otherwise.
2703
 */
2704
function _cdm_dataportal_acceptedByCurrentView($taxon) {
2705

    
2706
  $default_classification_uuid = get_current_classification_uuid();
2707

    
2708
  if (isset($taxon->taxonNodes)) {
2709
    $taxon_nodes = $taxon->taxonNodes;
2710
  }
2711
  else {
2712
    $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon->uuid);
2713
  }
2714

    
2715
  if ($taxon->class == "Taxon" && isset($taxon_nodes)) {
2716
    foreach ($taxon_nodes as $node) {
2717
      if($node->class == 'TaxonNodeDto' && isset($node->classificationUUID)){
2718
        // case of TaxonNodeDto
2719
        return $node->classificationUUID == $default_classification_uuid;
2720
      } else if($node->class == 'TaxonNode' && isset($node->classification->uuid)) {
2721
         return $node->classification->uuid == $default_classification_uuid;
2722
      }
2723
    }
2724
  }
2725
  return FALSE;
2726
}
2727

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

    
2755
    if(!$types){
2756
      $types = $default;
2757
    }
2758
    return isset($source->type) && in_array($source->type, $types);
2759
  }
2760

    
2761
/**
2762
 * Collects all the media from a list of description elements.
2763
 *
2764
 * @param array $descriptionElements
2765
 *   The description elements from which to collect the media.
2766
 *
2767
 * @return array
2768
 *   The output with all the collected media.
2769
 */
2770
function cdm_dataportal_media_from_descriptionElements($descriptionElements) {
2771

    
2772
  $outArrayOfMedia = array();
2773

    
2774
  // Avoiding a warning box in Drupal for Flora Malesiana.
2775
  if (isset($descriptionElements) && is_array($descriptionElements)) {
2776
    foreach ($descriptionElements as $descriptionElement) {
2777
      if (isset($descriptionElement->media) && is_array($descriptionElement->media)) {
2778
        foreach ($descriptionElement->media as $media) {
2779
          if (is_object($media)) {
2780
            $outArrayOfMedia[] = $media;
2781
          }
2782
        }
2783
      }
2784
    }
2785
  }
2786
  return $outArrayOfMedia;
2787
}
2788

    
2789

    
2790

    
2791

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

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

    
2835
  if(!array_key_exists('class', $attributes)) {
2836
    $attributes['class'] = ["dynabox"];
2837
  } else {
2838
    $attributes['class'] = array_merge($attributes['class'], ["dynabox"]);
2839
  }
2840
  $attributes['id'][] = 'dynabox-' . $dynabox_id;
2841
  $dynabox_attributes = drupal_attributes($attributes);
2842

    
2843

    
2844
  _add_js_domEvent(); // requires domEvent.js
2845
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cdm_dynabox.js');
2846
  drupal_add_js("
2847
  jQuery(document).ready(
2848
      function() {
2849
        dynabox('". $dynabox_id ."',
2850
          {
2851
            open_callback: " . $open_callback .",
2852
            close_callback: " . $close_callback .
2853
            ($content_element_selector ? ",\n content_container_selector: '" . $content_element_selector . "'" : "") . "
2854
          }
2855
        );
2856
      }
2857
   );",
2858
   array(
2859
    'type'=>'inline',
2860
    'scope'=>'footer'
2861
    )
2862
  );
2863

    
2864

    
2865
  $cdm_proxy_url = url('cdm_api/proxy/' . urlencode($content_url) . "/$theme");
2866
  $out .= '<!-- dynabox for ' . $content_url . ' -->';
2867
  $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>';
2868
  $out .= '  <' . $enclosingtags[1] . ' id="dynabox-' . $dynabox_id . '-content">';
2869
  $out .= '    <' . $enclosingtags[0] . ' class="dynabox-content-inner">' . loading_image_html() . '</' . $enclosingtags[0] . '>';
2870
  $out .= '    </' . $enclosingtags[1] . '>';
2871
  $out .= '  </' . $enclosingtags[0] . '>';
2872
  $out .= '<!-- dynabox end -->';
2873
  return $out;
2874
}
2875

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

    
2896
  if (isset($featureNode->descriptionElements) && is_array($featureNode->descriptionElements) && count($featureNode->descriptionElements) > 0) {
2897
    if(!isset($featureNode->descriptionElements['#type'])){ // #type is used to identify e.g. DTO elements: '#type' => 'DTO'
2898
      foreach ($featureNode->descriptionElements as $descriptionElement) {
2899
        if ($descriptionElement->class != "TextData" || isset($descriptionElement->multilanguageText_L10n->text)
2900
          && $descriptionElement->multilanguageText_L10n->text != ''
2901
          || isset($descriptionElement->sources[0])
2902
          || isset($descriptionElement->media[0]) ) {
2903
          return TRUE;
2904
        }
2905
      }
2906
    }
2907
  }
2908
  else if (isset($featureNode->childNodes) && is_array($featureNode->childNodes)) {
2909
    foreach ($featureNode->childNodes as $child) {
2910
      if (has_feature_node_description_elements($child)) {
2911
        return TRUE;
2912
      }
2913
    }
2914
  }
2915
  return FALSE;
2916
}
2917

    
2918
/**
2919
 * Checks if the current page is a valid taxon portal page and responds with HTTP status 404 (not found) otherwise
2920
 *
2921
 * @param $chapter
2922
 *   The taxon page chapter or part
2923
 */
2924
function cdm_check_valid_taxon_page($chapter){
2925
  static $taxon_tabs = null;
2926

    
2927
  cdm_check_valid_portal_page();
2928

    
2929
  if($taxon_tabs == null){
2930
    $taxon_tabs = array('all', 'description');
2931
    foreach(get_taxon_tabs_list() as $tab){
2932
      $taxon_tabs[] = strtolower($tab);
2933
    }
2934
  }
2935

    
2936
  if(!in_array($chapter, $taxon_tabs)){
2937
    // oops this is not a valid chapter name
2938
    http_response_code(404); // 404 = Not Found
2939
  }
2940

    
2941
}
2942

    
2943
function check_js_devel_mode_disabled() {
2944
  if(variable_get('cdm_js_devel_mode', FALSE)) {
2945
    drupal_set_message(t('The !url1 is enabled.
2946
        WARNING: this is a performance penalty and must be turned off on production websites.', array(
2947
      '!url1' => l('java-script development mode', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-cdm-js-devel-mode'))
2948
    )),
2949
      'warning'
2950
    );
2951
  }
2952
}
2953

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

    
2974
/**
2975
 * Generates the diff of the texts and presents it in a HTML diff viewer.
2976
 *
2977
 * @param $text_a
2978
 * @param $text_b
2979
 * @return string
2980
 */
2981
function diff_viewer($text_a, $text_b) {
2982

    
2983
  static $diff_viewer_count = 0;
2984

    
2985
  $element_id = 'part_definitions_diff_' . $diff_viewer_count++;
2986

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

    
3006
  $diff = Diff::compare($text_a,
3007
    $text_b);
3008
  $diff_viewer_markup = '<div id="' . $element_id . '"><h3>View Diff</h3><div>'
3009
    . Diff::toTable($diff, '', '')
3010
    . '</div></div>';
3011
  return $diff_viewer_markup;
3012
}
3013

    
3014
/**
3015
 * ====== EXPERIMENTAL only used by Euro+Med ===============
3016
 */
3017

    
3018

    
3019
/**
3020
 * See
3021
 *  - https://dev.e-taxonomy.eu/redmine/issues/9233
3022
 *  - https://www.drupal.org/project/feedback_simple
3023
 *  - https://www.drupal.org/node/1299158
3024
 * Implements hook_preprocess_feedback_simple().
3025
 *
3026
 * TODO: move into separate module
3027
 */
3028
function cdm_dataportal_preprocess_feedback_simple(&$variables) {
3029
  // Add modal_forms classes.
3030
  $variables['class'][] = 'ctools-use-modal';
3031
  // Uncomment either small, medium or large.
3032
  $variables['class'][] = 'ctools-modal-modal-popup-small';
3033
  // $variables['class'][] = 'ctools-modal-modal-popup-medium';
3034
  // $variables['class'][] = 'ctools-modal-modal-popup-large';
3035
}
3036

    
3037

    
(10-10/18)