Project

General

Profile

Download (97.1 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?php
2
/**
3
 * @file
4
 * Module to provide a CDM Dataportal.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 *
15
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 *   - Wouter Addink <w.addink@eti.uva.nl> (migration from Drupal 5 to Drupal7)
18
 */
19
20 38b27a36 Andreas Kohlbecker
  module_load_include('php', 'cdm_dataportal', 'node_types');
21
  module_load_include('php', 'cdm_dataportal', 'settings');
22
  module_load_include('php', 'cdm_dataportal', 'help');
23
  module_load_include('php', 'cdm_dataportal', 'cdm_dataportal.search');
24
25
  module_load_include('inc', 'cdm_dataportal', 'includes/common');
26 dd0767b6 Andreas Kohlbecker
  module_load_include('inc', 'cdm_dataportal', 'includes/footnotes');
27 e2617c7e Andreas Kohlbecker
  module_load_include('inc', 'cdm_dataportal', 'includes/agent');
28 2e31ea9e Andreas Kohlbecker
  module_load_include('inc', 'cdm_dataportal', 'includes/name');
29 b7a20282 Andreas Kohlbecker
  module_load_include('inc', 'cdm_dataportal', 'includes/taxon');
30 bd56cbc1 Andreas Kohlbecker
  module_load_include('inc', 'cdm_dataportal', 'includes/taxon-node');
31 b7a20282 Andreas Kohlbecker
  module_load_include('inc', 'cdm_dataportal', 'includes/references');
32 38b27a36 Andreas Kohlbecker
  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/descriptions');
37
  module_load_include('inc', 'cdm_dataportal', 'includes/pre-drupal8');
38
39
  module_load_include('inc', 'cdm_dataportal', 'theme/theme_registry');
40
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.common');
41
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.descriptions');
42
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.media');
43
  module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.occurrence');
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 6657531f Andreas Kohlbecker
  }
78
79 38b27a36 Andreas Kohlbecker
  /**
80
   */
81
  function drupal_add_js_rowToggle($tableId){
82 6657531f Andreas Kohlbecker
83 38b27a36 Andreas Kohlbecker
      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 6657531f Andreas Kohlbecker
      });
87 38b27a36 Andreas Kohlbecker
      ', array('type' => 'inline'));
88
  }
89 d2fd2a4c Andreas Kohlbecker
90 38b27a36 Andreas Kohlbecker
  /**
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 5ea8b301 Andreas Kohlbecker
  }
128
129 6b605d3b Andreas Kohlbecker
  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 38b27a36 Andreas Kohlbecker
  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 4c21ffdb Andreas Kohlbecker
        'group' => JS_LIBRARY,
168
        'weight' => 0,
169 38b27a36 Andreas Kohlbecker
        'cache' => TRUE,
170
        'preprocess' => FALSE
171
      )
172
    );
173 2020828c Andreas Kohlbecker
174 c1fc969a Andreas Kohlbecker
175 38b27a36 Andreas Kohlbecker
    // 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 4c21ffdb Andreas Kohlbecker
        'group' => JS_LIBRARY,
181
        'weight' => -1, // before open layers
182 38b27a36 Andreas Kohlbecker
        '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 4c21ffdb Andreas Kohlbecker
        'group' => JS_LIBRARY,
192
        'weight' => 1, // after openlayers
193 38b27a36 Andreas Kohlbecker
        '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 e3026d72 Andreas Kohlbecker
205 38b27a36 Andreas Kohlbecker
  }
206 e3026d72 Andreas Kohlbecker
207 38b27a36 Andreas Kohlbecker
  /**
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 10f6aa4b Andreas Kohlbecker
    )
226 38b27a36 Andreas Kohlbecker
    ),
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 94550ff9 Andreas Kohlbecker
233 38b27a36 Andreas Kohlbecker
  /**
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 fe19a89b Andreas Kohlbecker
     * allow using the "alt" attribute for captions instead of the "title"
241
     * attribute
242
     */
243 38b27a36 Andreas Kohlbecker
    $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 94550ff9 Andreas Kohlbecker
      });
258 38b27a36 Andreas Kohlbecker
      ', array('type' => 'inline'));
259
  }
260 94550ff9 Andreas Kohlbecker
261 38b27a36 Andreas Kohlbecker
  /**
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 94550ff9 Andreas Kohlbecker
270 38b27a36 Andreas Kohlbecker
  /**
271
   * @todo Please document this function.
272
   * @see http://drupal.org/node/1354
273
   */
274
  function _add_js_ahah() {
275 b386ae48 Andreas Kohlbecker
276 38b27a36 Andreas Kohlbecker
    _add_js_domEvent(); // requires domEvent.js
277
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/ahah-content.js');
278
  }
279 94550ff9 Andreas Kohlbecker
280 d0d23caa Andreas Kohlbecker
/**
281
 * @todo Please document this function.
282
 * @see http://drupal.org/node/1354
283
 */
284
function _add_js_taxonomic_children($jquery_selector) {
285 b0adfd32 Andreas Kohlbecker
286
  global $base_url;
287
288
289
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/jquery.cdm.taxonomic_children.js');
290 faf4f771 Andreas Kohlbecker
  
291 d0d23caa Andreas Kohlbecker
  drupal_add_js('jQuery(document).ready(function() {
292 b0adfd32 Andreas Kohlbecker
        jQuery(\'' . $jquery_selector . '\').taxonomic_children({
293 09edee9a Andreas Kohlbecker
          // hoverClass: "fa-rotate-90",
294
          // activeClass: "fa-rotate-90",
295 b0adfd32 Andreas Kohlbecker
          classificationUuid: "' . get_current_classification_uuid() . '",
296 0af3ce28 Andreas Kohlbecker
          taxonUuid: "' . get_current_taxon_uuid() . '",
297 38da4e54 Andreas Kohlbecker
          cdmWebappBaseUri: "' . variable_get('cdm_webservice_url', '') . '",
298 b0adfd32 Andreas Kohlbecker
          proxyBaseUri: "' . $base_url . '",
299
          
300
        });
301 d0d23caa Andreas Kohlbecker
      });
302
      ', array('type' => 'inline'));
303
}
304
305 38b27a36 Andreas Kohlbecker
  /**
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 b386ae48 Andreas Kohlbecker
314 087bb473 Andreas Kohlbecker
  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 b18d70f6 Andreas Kohlbecker
  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 c05d1cfb Andreas Kohlbecker
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 e27e3ff2 Andreas Kohlbecker
          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 c05d1cfb Andreas Kohlbecker
        });
357
      });',
358
    array('type' => 'inline')
359
  );
360
}
361
362 4a462641 Andreas Kohlbecker
function _add_js_universalviewer($jquery_selector, $manifest_uri){
363 a1f7edc0 Andreas Kohlbecker
364
  $universalviewer_path  = drupal_get_path('module',    'cdm_dataportal') . '/js/universalviewer';
365
366
  drupal_add_css($universalviewer_path . '/uv/uv.css');
367 a6f91032 Andreas Kohlbecker
  drupal_add_css($universalviewer_path . '/uv-fix.css');
368 a1f7edc0 Andreas Kohlbecker
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 b45a8503 Andreas Kohlbecker
  // 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 6c1a6712 Andreas Kohlbecker
  $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 b45a8503 Andreas Kohlbecker
  $config_file = 'uv-config.json';
402 a1f7edc0 Andreas Kohlbecker
  drupal_add_js('
403
      console.log(\'jQuery inline: \' + jQuery.fn.jquery);
404
      jQuery(window).on(\'uvLoaded\', function() {
405
        jQuery( "' . $jquery_selector . '" ).jqUniversalviewer(
406
        {
407 b45a8503 Andreas Kohlbecker
          root: \'' . $folders_up . $universalviewer_path . '/uv\',
408 6c1a6712 Andreas Kohlbecker
          configUri: \'' . $basePath . $universalviewer_path . '/'. $config_file . '\',
409 4a462641 Andreas Kohlbecker
          manifestUri: \'' . $manifest_uri . '\'
410 a1f7edc0 Andreas Kohlbecker
        }
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 38b27a36 Andreas Kohlbecker
  /**
443
   * Provides the markup for an font awesome icon.
444
   *
445
   * The icons is created in default size without any extra features.
446
   *
447
   * The available icons are listed here http://fontawesome.io/cheatsheet/
448 ef12d0c6 Andreas Kohlbecker
   * fontawesome icons have much more features than implemented here in this function,
449
   * for spinning icons, fixed width icons, rotation, etc please checkout the
450 38b27a36 Andreas Kohlbecker
   * examples at http://fontawesome.io/examples/
451
   *
452
   * @parameter $icon_name
453
   *  The name of the icon which starts with 'fa-'
454
   *
455
   * @return String
456
   *    the markup for the icon in an <i> tag
457
   *
458
   */
459 b0aa9a8f Andreas Kohlbecker
  function font_awesome_icon_markup($icon_name = NULL, $attributes = array()){
460 6d9071b7 Andreas Kohlbecker
    _add_font_awesome_font();
461 38b27a36 Andreas Kohlbecker
462
463 b0aa9a8f Andreas Kohlbecker
    if($icon_name){
464
      if(!isset($attributes['class'])){
465
        $attributes['class'] = array();
466
      }
467
      $attributes['class'][] = 'fa';
468
      $attributes['class'][] = $icon_name;
469
470
      return '<i ' . drupal_attributes($attributes) . '></i>';
471 38b27a36 Andreas Kohlbecker
    }
472
473 b0aa9a8f Andreas Kohlbecker
    return '';
474 38b27a36 Andreas Kohlbecker
  }
475 94550ff9 Andreas Kohlbecker
476 2ffe4d59 Andreas Kohlbecker
/**
477
 * @param string $glyph_name
478
 *   The name of the gloyph (e.g. 'icon-interal-link-alt-solid') for the foll list please
479
 *   refer to modules/cdm_dataportal/fonts/custom-icon-font
480
 * @param array $attributes
481
 * @return string
482
 */
483
  function custom_icon_font_markup($glyph_name = NULL, $attributes = array()){
484
    _add_font_custom_icon_font();
485
486
487
    if($glyph_name){
488
      if(!isset($attributes['class'])){
489
        $attributes['class'] = array();
490
      }
491
      $attributes['class'][] = $glyph_name;
492
493
      return '<i ' . drupal_attributes($attributes) . '></i>';
494
    }
495
496
    return '';
497
  }
498
499 6d9071b7 Andreas Kohlbecker
/**
500
 * Adds the css  containing the font awesome icons to the html header.
501
 */
502
function _add_font_awesome_font()
503
{
504 2393d9c5 Andreas Kohlbecker
  // $fa_font_version = 'font-awesome-4.6.3/css/font-awesome.min.css';
505
  $fa_font_version = 'fontawesome-free-5.9.0-web/css/all.css';
506
  $font_awesome_css_uri = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/fonts/' . $fa_font_version;
507 6d9071b7 Andreas Kohlbecker
508
  drupal_add_html_head_link(
509
    array(
510
      'href' => $font_awesome_css_uri,
511
      'rel' => 'stylesheet'
512
    )
513
  );
514
}
515
516 2ffe4d59 Andreas Kohlbecker
/**
517
 * Adds the css  containing the font awesome icons to the html header.
518
 */
519
function _add_font_custom_icon_font()
520
{
521
522
  $custom_icon_font_css_uri = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/fonts/custom-icon-font/style.css';
523
524
  drupal_add_html_head_link(
525
    array(
526
      'href' => $custom_icon_font_css_uri,
527
      'rel' => 'stylesheet'
528
    )
529
  );
530
}
531 38b27a36 Andreas Kohlbecker
532 6d9071b7 Andreas Kohlbecker
/* ====================== hook implementations ====================== */
533 38b27a36 Andreas Kohlbecker
  /**
534
   * Implements hook_permission().
535
   *
536
   * Valid permissions for this module.
537
   *
538
   * @return array
539 8385a9f2 Andreas Kohlbecker
   *   An array of valid permissions for the cdm_dataportal module.
540 38b27a36 Andreas Kohlbecker
   */
541
  function cdm_dataportal_permission() {
542
    return array(
543
      'administer cdm_dataportal' => array(
544 8385a9f2 Andreas Kohlbecker
        'title' => t('Administer CDM DataPortal settings'),
545
        'description' => t("Access the settings pages specific for the cdm_dataportal module"),
546 c6fe437b Andreas Kohlbecker
      ),
547
      'access cdm content' => array(
548
        'title' => t('Access CDM content'),
549
        'description' => t("Access content (taxa, names, specimens, etc.) served by the CDM web service."),
550
      ),
551 38b27a36 Andreas Kohlbecker
    );
552
  }
553 6657531f Andreas Kohlbecker
554
/**
555 f19f47fa Andreas Kohlbecker
 * Implements hook_menu().
556
 */
557 6657531f Andreas Kohlbecker
function cdm_dataportal_menu() {
558
  $items = array();
559
560
  // @see settings.php.
561
  cdm_dataportal_menu_admin($items);
562
  cdm_dataportal_menu_help($items);
563
564
  $items['cdm_dataportal/names'] = array(
565
    'page callback' => 'cdm_dataportal_view_names',
566 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
567 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
568
  );
569
570
  // Optional callback arguments: page.
571
  $items['cdm_dataportal/taxon'] = array(
572
    'page callback' => 'cdm_dataportal_taxon_page_view',
573 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
574 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
575
    // Expected callback arguments: uuid.
576
  );
577
578 a1ce57ce Katja Luther
  $items['cdm_dataportal/occurrence'] = array(
579 6eaec849 Katja Luther
        'page callback' => 'cdm_dataportal_specimen_page_view',
580
        'access arguments' => array('access cdm content'),
581
        'type' => MENU_CALLBACK,
582
        // Expected callback arguments: uuid.
583
    );
584 30845bda Andreas Kohlbecker
585 e170a53e Patrick Plitzner
  $items['cdm_dataportal/description'] = array(
586
        'page callback' => 'cdm_dataportal_description_page_view',
587
        'access arguments' => array('access cdm content'),
588
        'type' => MENU_CALLBACK,
589
        // Expected callback arguments: uuid.
590
    );
591
592 4c812e71 Katja Luther
   $items['cdm_dataportal/specimen/accession_number'] = array(
593 6eaec849 Katja Luther
        'page callback' => 'cdm_dataportal_specimen_by_accession_number_page_view',
594
        'access arguments' => array('access cdm content'),
595
        'type' => MENU_CALLBACK,
596
        // Expected callback arguments: accession number.
597
    );
598 30845bda Andreas Kohlbecker
  $items['cdm_dataportal/named_area'] = array(
599
    'page callback' => 'cdm_dataportal_named_area_page_view',
600
    'access arguments' => array('access cdm content'),
601
    'type' => MENU_CALLBACK,
602
    // Expected callback arguments: uuid.
603
  );
604 9d37c9d9 Patric Plitzner
605 6657531f Andreas Kohlbecker
  $items['cdm_dataportal/name'] = array(
606
    'page callback' => 'cdm_dataportal_name_page_view',
607
      /*
608
    'page arguments' => array(
609
       'taxon_name_uuid',
610
       'taxon_to_hide_uuid',
611
       'synonym_uuid' => NULL
612
      ),
613
      */
614 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
615 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
616
    // Expected callback arguments: uuid.
617
  );
618
619
  $items['cdm_dataportal/reference'] = array(
620
    'page callback' => 'cdm_dataportal_view_reference',
621 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
622 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
623
    // Expected callback arguments: uuid.
624
  );
625
626
  $items['cdm_dataportal/reference/list'] = array(
627
    'page callback' => 'cdm_dataportal_view_reference_list',
628 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
629 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
630
    // Expected callback arguments: uuid.
631
  );
632
633
  $items['cdm_dataportal/media'] = array(
634
    'page callback' => 'cdm_dataportal_view_media',
635 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
636 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
637
    // Expected callback arguments:
638
    // uuid, mediarepresentation_uuid, part_uuid or part#.
639
  );
640
641
  $items['cdm_dataportal/polytomousKey'] = array(
642
    'page callback' => 'cdm_dataportal_view_polytomousKey',
643 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
644 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
645
    // Expected callback arguments: polytomousKey->uuid.
646
  );
647
648
  $items['cdm_dataportal/search'] = array(
649
    'page callback' => 'cdm_dataportal_view_search_advanced',
650 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
651 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
652
  );
653
654 7e219fcc Andreas Kohlbecker
  // Optional callback arguments: page.
655
  $items['cdm_dataportal/registration'] = array(
656
    'page callback' => 'cdm_dataportal_registration_page_view',
657
    'access arguments' => array('access cdm content'),
658
    'type' => MENU_CALLBACK,
659
    // Expected callback arguments: uuid.
660
  );
661
662
  // ------------ SEARCH -----------
663 6657531f Andreas Kohlbecker
  $items['cdm_dataportal/search/advanced'] = array(
664 29077ee5 Andreas Kohlbecker
    'title' => 'Advanced', // will be passed through t()
665 6657531f Andreas Kohlbecker
    'page callback' => 'cdm_dataportal_view_search_advanced',
666 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
667 6657531f Andreas Kohlbecker
    'type' => MENU_DEFAULT_LOCAL_TASK,
668
  );
669 4c812e71 Katja Luther
  $items['cdm_dataportal/search/blast'] = array(
670
    'title' => 'Blast', // will be passed through t()
671
    'page callback' => 'cdm_dataportal_view_search_blast',
672
    'access arguments' => array('access cdm content'),
673
    'type' => MENU_LOCAL_TASK,
674
  );
675
676 6657531f Andreas Kohlbecker
  $items['cdm_dataportal/search/taxon_by_description'] = array(
677 579c485d Andreas Kohlbecker
    'title' => 'By content category', // will be passed through t()
678 6657531f Andreas Kohlbecker
    'page callback' => 'cdm_dataportal_view_search_taxon_by_description',
679 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
680 6657531f Andreas Kohlbecker
    'type' => MENU_LOCAL_TASK,
681
  );
682
  $items['cdm_dataportal/search/results/taxon'] = array(
683
    'page callback' => 'cdm_dataportal_view_search_results_taxon',
684 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
685 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
686
  );
687 a1ce57ce Katja Luther
688 2f30124c Andreas Kohlbecker
  $items['cdm_dataportal/search/results/specimen'] = array(
689
      'page callback' => 'cdm_dataportal_view_search_results_specimen',
690
      'access arguments' => array('access cdm content'),
691
      'type' => MENU_CALLBACK,
692
  );
693
694 efbff4b3 Andreas Kohlbecker
  /*
695
   * MENU_CALLBACK at cdm_dataportal/registration-search is needed to make the
696
   * tabs in the subordinate paths work, accessing this 'page' will cause the
697
   * MENU_DEFAULT_LOCAL_TASK being displayed
698
   */
699
  $items['cdm_dataportal/registration-search'] = array(
700
    'title' => 'Search', // will be passed through t()
701 a6ae799b Andreas Kohlbecker
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
702 efbff4b3 Andreas Kohlbecker
    'page arguments' => array("filter"),
703 a6ae799b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
704
    'type' => MENU_CALLBACK,
705
  );
706 efbff4b3 Andreas Kohlbecker
  /*
707
   * the MENU_DEFAULT_LOCAL_TASK creates a tab for the MENU_CALLBACK
708
   * defined at a higher level of the path (cdm_dataportal/registration-search)
709
   */
710
  $items['cdm_dataportal/registration-search/filter'] = array(
711
    'title' => 'Search', // will be passed through t()
712
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
713
    'page arguments' => array("filter"),
714
    'access arguments' => array('access cdm content'),
715
    'type' => MENU_DEFAULT_LOCAL_TASK,
716
  );
717
  /*
718
   * the MENU_LOCAL_TASK creates another tab
719
   */
720
  $items['cdm_dataportal/registration-search/taxongraph'] = array(
721 5087fadc Andreas Kohlbecker
    'title' => 'Taxon graph search', // will be passed through t()
722 efbff4b3 Andreas Kohlbecker
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
723
    'page arguments' => array("taxongraph"),
724
    'access arguments' => array('access cdm content'),
725
    'type' => MENU_LOCAL_TASK,
726
  );
727
728 e2617c7e Andreas Kohlbecker
  // Optional callback arguments: page.
729
  $items['cdm_dataportal/search/agent'] = array(
730
    'page callback' => 'cdm_dataportal_view_search_agent',
731
    'access arguments' => array('access cdm content'),
732
    'type' => MENU_CALLBACK,
733
    // Expected callback arguments: uuid.
734
  );
735
736 7e219fcc Andreas Kohlbecker
  // ------------ menu items with variable path elements -----------
737 6657531f Andreas Kohlbecker
738
  // 'May not cache' in D5.
739
  $items['cdm_dataportal/name/%'] = array(
740
    // 'page callback' => 'cdm_dataportal_view_name',
741
    'page callback' => 'cdm_dataportal_name_page_view',
742 2f65af04 Andreas Kohlbecker
    'page arguments' => array(2, 3, 4, 5),
743 c6fe437b Andreas Kohlbecker
    'access arguments' => array('access cdm content'),
744 6657531f Andreas Kohlbecker
    'type' => MENU_CALLBACK,
745
  );
746
747 6f1a217c Andreas Kohlbecker
  // --- Local tasks for Taxon.
748
  // --- tabbed taxon page
749 6657531f Andreas Kohlbecker
  if (variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
750
    $items['cdm_dataportal/taxon/%'] = array(
751 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('General'),
752 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
753 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
754 6657531f Andreas Kohlbecker
      'type' => MENU_CALLBACK,
755
      'weight' => 1,
756
      'page arguments' => array(2, "description")
757 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
758 6657531f Andreas Kohlbecker
    );
759
760
    $items['cdm_dataportal/taxon/%/all'] = array(
761 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('General'),
762 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
763 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
764 6657531f Andreas Kohlbecker
      'type' => MENU_CALLBACK,
765
      'weight' => 2,
766
      'page arguments' => array(2, "all")
767 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
768 6657531f Andreas Kohlbecker
    );
769
770
    $items['cdm_dataportal/taxon/%/description'] = array(
771 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('General'),
772 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
773 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
774 6657531f Andreas Kohlbecker
      'type' => MENU_DEFAULT_LOCAL_TASK,
775
      'weight' => 2,
776
      'page arguments' => array(2, "description")
777 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
778 6657531f Andreas Kohlbecker
    );
779
780
    $items['cdm_dataportal/taxon/%/synonymy'] = array(
781 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('Synonymy'),
782 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
783 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
784 6657531f Andreas Kohlbecker
      'type' => MENU_LOCAL_TASK,
785
      'weight' => 4,
786
      'page arguments' => array(2, "synonymy", 4)
787 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid and ...
788 6657531f Andreas Kohlbecker
    );
789 7cc085da Andreas Kohlbecker
    $items['cdm_dataportal/taxon/%/images'] = array( // Images
790 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('Images'),
791 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
792 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
793 6657531f Andreas Kohlbecker
      'type' => MENU_LOCAL_TASK,
794
      'weight' => 5,
795
      'page arguments' => array(2, "images")
796 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
797 6657531f Andreas Kohlbecker
    );
798
799 7cc085da Andreas Kohlbecker
    $items['cdm_dataportal/taxon/%/specimens'] = array( // Specimens
800 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('Specimens'),
801 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
802 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
803 6657531f Andreas Kohlbecker
      'type' => MENU_LOCAL_TASK,
804
      'weight' => 6,
805
      'page arguments' => array(2, "specimens")
806 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
807 6657531f Andreas Kohlbecker
    );
808
809 7cc085da Andreas Kohlbecker
    $items['cdm_dataportal/taxon/%/keys'] = array( // Keys
810 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('Keys'),
811 6657531f Andreas Kohlbecker
      'page callback' => 'cdm_dataportal_taxon_page_view',
812 c6fe437b Andreas Kohlbecker
      'access arguments' => array('access cdm content'),
813 6657531f Andreas Kohlbecker
      'type' => MENU_LOCAL_TASK,
814
      'weight' => 6,
815
      'page arguments' => array(2, "keys")
816 7663cd0b Andreas Kohlbecker
      , // Expected callback arguments: taxon_uuid.
817
    );
818
819 7cc085da Andreas Kohlbecker
    $items['cdm_dataportal/taxon/%/experts'] = array( // Experts
820 4feeabc7 Andreas Kohlbecker
      'title' => cdm_taxonpage_tab_label('Experts'),
821 7663cd0b Andreas Kohlbecker
        'page callback' => 'cdm_dataportal_taxon_page_view',
822 c6fe437b Andreas Kohlbecker
        'access arguments' => array('access cdm content'),
823 7663cd0b Andreas Kohlbecker
        'type' => MENU_LOCAL_TASK,
824
        'weight' => 6,
825
        'page arguments' => array(2, "experts")
826
    , // Expected callback arguments: taxon_uuid.
827 6657531f Andreas Kohlbecker
    );
828 93ae67cc Patrick Plitzner
829 51cc509a Patrick Plitzner
    $items['cdm_dataportal/taxon/autosuggest/%/%/%/'] = array(
830 04a1d647 Patrick Plitzner
        'page callback' => 'cdm_dataportal_taxon_autosuggest',
831 c6fe437b Andreas Kohlbecker
        'access arguments' => array('access cdm content'),
832 51cc509a Patrick Plitzner
        'page arguments' => array(3,4,5),
833 93ae67cc Patrick Plitzner
        'type' => MENU_CALLBACK
834
    );
835 6657531f Andreas Kohlbecker
  }
836
837 6f1a217c Andreas Kohlbecker
  // --- refresh link for all cdmnode types
838
  foreach (cdm_get_nodetypes() as $type=>$name) {
839
    $items['cdm_dataportal/' . $name . '/%/refresh'] = array(
840 7cc085da Andreas Kohlbecker
        'title' => 'Refresh',
841 6f1a217c Andreas Kohlbecker
        'page callback' => 'cdm_dataportal_refresh_node',
842 3113db26 Andreas Kohlbecker
        'access arguments' => array('administer cdm_dataportal'),
843 6f1a217c Andreas Kohlbecker
        'type' => MENU_LOCAL_TASK,
844
        'weight' => 100,
845
        'page arguments' => array($name, 2)
846
    );
847
  }
848
849 6657531f Andreas Kohlbecker
  return $items;
850
}
851
852
/**
853 b85ab055 Andreas Kohlbecker
 * Implements hook_init().
854
 *
855 6657531f Andreas Kohlbecker
 */
856
function cdm_dataportal_init() {
857 8fc089e1 Saskia Gennrich
  if (!path_is_admin(current_path())) {
858
    //FIXME To add CSS or JS that should be present on all pages, modules
859
    //      should not implement this hook, but declare these files in their .info file.
860
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal.css');
861
    // drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
862
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_screen.css', array('type' => 'screen'));
863 63f6d312 Saskia Gennrich
  } else {
864
    drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_settings.css');
865 8fc089e1 Saskia Gennrich
  }
866 2dd59bb5 Andreas Kohlbecker
867
  if(variable_get('cdm_debug_mode', FALSE)){
868
    $file = 'temporary://drupal_debug.txt';
869
    file_put_contents($file, 'CDM DEBUG LOG for ' . $_GET['q']. "\n"); // will overwrite the file
870
  }
871 5611d467 Andreas Kohlbecker
872
  $bibliography_settings = get_bibliography_settings();
873 57d513cb Andreas Kohlbecker
  $enclosing_tag = $bibliography_settings['enabled'] == 1 ? 'div' : 'span';
874
  FootnoteManager::registerFootnoteSet('BIBLIOGRAPHY', $enclosing_tag, $bibliography_settings['key_format']);
875 6657531f Andreas Kohlbecker
}
876
877 6f1a217c Andreas Kohlbecker
function cdm_dataportal_refresh_node($cdm_node_name, $uuid, $parameters = array()){
878
879
  $base_path = 'cdm_dataportal/' . $cdm_node_name . '/' . $uuid;
880
881
  if($cdm_node_name == 'taxon' && variable_get('cdm_dataportal_taxonpage_tabs', 1)){
882
    // force reloading of all and notify user about this special loading
883
    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: ')
884
        . l('Back to tabbed taxon page', $base_path));
885
    $base_path .= '/all';
886
  } else {
887
    drupal_set_message(t('The level 2 cache has been cleared for this page'));
888
  }
889
890
  $parameters['cacheL2_refresh'] ='1';
891
892
893
  drupal_goto($base_path, array('query' => $parameters));
894
}
895
896 102f8c26 Andreas Kohlbecker
/**
897
 * Implements hook_requirements($phase)
898
 */
899
function cdm_dataportal_requirements($phase) {
900
    $requirements = array();
901
    if($phase == 'runtime'){
902
903
    }
904
    return $requirements;
905
}
906
907 6657531f Andreas Kohlbecker
/**
908
 * Implements hook_block_info().
909
 */
910
function cdm_dataportal_block_info() {
911
912
    // $block[0]["info"] = t("CDM DataPortal DevLinks");
913
    // $block[1]["info"] = t("CDM DataPortal Credits");
914 fc13aa30 Andreas Kohlbecker
    $block["2"] = array(
915 beb914ef Andreas Kohlbecker
        "info" => t("CDM - Search Taxa"),
916 fc13aa30 Andreas Kohlbecker
        "cache" => DRUPAL_NO_CACHE
917
      );
918 6657531f Andreas Kohlbecker
    // $block[3]["info"] = t("CDM Filters");
919 beb914ef Andreas Kohlbecker
    $block["4"]["info"] = t("CDM  - Dataportal Print");
920
    $block["keys"]["info"] = t("CDM - Identification keys");
921 46a02272 Andreas Kohlbecker
    $block["fundedByEDIT"]["info"] = t('CDM - Powered by EDIT');
922 f9a3d0f6 Andreas Kohlbecker
    $block["classification_breadcrumbs"] =  array(
923 beb914ef Andreas Kohlbecker
        'info' => t('CDM - Classification breadcrumbs'),
924 f9a3d0f6 Andreas Kohlbecker
        'cache' => DRUPAL_CACHE_PER_PAGE
925
      );
926 bc400a17 Andreas Kohlbecker
    $block["taxonomic_children"] =  array(
927 beb914ef Andreas Kohlbecker
      'info' => t('CDM - Taxonomic children'),
928 bc400a17 Andreas Kohlbecker
      'cache' => DRUPAL_CACHE_PER_PAGE
929
    );
930 beb914ef Andreas Kohlbecker
    $block["back_to_search_results"] =  array(
931
      'title' => '<none>',
932
      'info' => t('CDM - Back to search Results'),
933
      'cache' => DRUPAL_CACHE_PER_PAGE,
934
      'visibility' => BLOCK_VISIBILITY_LISTED,
935
      'pages' => "cdm_dataportal/taxon/*", // multiple page paths separated by "\n"!!!
936
    );
937 a6ae799b Andreas Kohlbecker
  $block['registrations_search_filter'] =  array(
938 b18d70f6 Andreas Kohlbecker
    'title' => 'Filter registrations',
939 a6ae799b Andreas Kohlbecker
    'info' => t('CDM - Registrations search filter'),
940
    'cache' => DRUPAL_CACHE_PER_PAGE,
941 810710a0 Andreas Kohlbecker
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
942 b18d70f6 Andreas Kohlbecker
    'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!!
943 a6ae799b Andreas Kohlbecker
  );
944 efbff4b3 Andreas Kohlbecker
  $block['registrations_search_taxongraph'] =  array(
945
    'title' => 'Taxonomic registration search',
946
    'info' => t('CDM - Registrations search by taxon graph'),
947
    'cache' => DRUPAL_CACHE_PER_PAGE,
948
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
949 b18d70f6 Andreas Kohlbecker
    'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!!
950
  );
951
  $block['registrations_search'] =  array(
952
    'title' => 'Search',
953
    'info' => t('CDM - Registrations search combining filter and taxon graph search' ),
954
    'cache' => DRUPAL_CACHE_PER_PAGE,
955
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
956
    'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!!
957 efbff4b3 Andreas Kohlbecker
  );
958 c05d1cfb Andreas Kohlbecker
  $block['utis_search'] =  array(
959
    'title' => 'UTIS Search',
960
    'info' => t('Query the Unified Taxonomic Information Service (UTIS)' ),
961
    'cache' => DRUPAL_CACHE_PER_PAGE,
962
    'visibility' => BLOCK_VISIBILITY_NOTLISTED
963
  );
964 efbff4b3 Andreas Kohlbecker
  return $block;
965 6657531f Andreas Kohlbecker
}
966
967
/**
968
 * Implements hook_block_view().
969
 */
970
function cdm_dataportal_block_view($delta) {
971
  // TODO Rename block deltas (e.g. '2') to readable strings.
972
  switch ($delta) {
973
    // case 'delta-1':
974
    // $block['subject'] = t('Credits');
975
    // $block['content'] = theme('cdm_credits');
976
    // return $block;
977
    case '2':
978
      $block['subject'] = t('Search taxa');
979 191f88fd Andreas Kohlbecker
      $form = drupal_get_form('cdm_dataportal_search_taxon_form');
980
      $block['content'] = drupal_render($form);
981 6657531f Andreas Kohlbecker
982
      if (variable_get('cdm_dataportal_show_advanced_search', 1)) {
983
        $block['content'] .= '<div>' . l(t('Advanced Search'), 'cdm_dataportal/search') . '</div>';
984 6eaec849 Katja Luther
      }
985 2f30124c Andreas Kohlbecker
      if (variable_get(CDM_SEARCH_BLAST_ENABLED)){
986 6eaec849 Katja Luther
          $block['content'] .= '<div>' . l(t('Blast Search'), 'cdm_dataportal/search/blast') . '</div>';
987 6657531f Andreas Kohlbecker
      }
988
      return $block;
989
    case '4':
990 c8234bdf Andreas Kohlbecker
      $block['subject'] = '';
991 6657531f Andreas Kohlbecker
      $block['content'] = theme('cdm_print_button');
992
      return $block;
993
    case "keys":
994
      $block['subject'] = t('Identification Keys');
995
      $block['content'] = theme('cdm_block_IdentificationKeys', array('taxonUuid' => NULL));
996
      return $block;
997
    case "fundedByEDIT":
998
      // t('Funded by EDIT');
999
      $text = '<none>';
1000
      $block['subject'] = $text;
1001 889c74b7 Andreas Kohlbecker
      $img_tag = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/powered_by_edit.png' . '" alt="' . $text . '"/>';
1002
      $block['content'] = l($img_tag, "http://cybertaxonomy.org/", array(
1003 6657531f Andreas Kohlbecker
        'attributes' => array("target" => "EDIT"),
1004
        'absolute' => TRUE,
1005
        'html' => TRUE,
1006
      ));
1007
      return $block;
1008 f9a3d0f6 Andreas Kohlbecker
    case 'classification_breadcrumbs':
1009 0af3ce28 Andreas Kohlbecker
      $taxon_uuid = get_current_taxon_uuid();
1010 38da4e54 Andreas Kohlbecker
      $block['subject'] = '<none>';
1011
      $block['content'] = compose_classification_breadcrumbs($taxon_uuid);
1012
      return $block;
1013 bc400a17 Andreas Kohlbecker
    case 'taxonomic_children':
1014
      $taxon_uuid = get_current_taxon_uuid();
1015
      $block['subject'] = '<none>';
1016
      $block['content'] = compose_taxonomic_children($taxon_uuid);
1017
      return $block;
1018 beb914ef Andreas Kohlbecker
    case 'back_to_search_results':
1019
      $block['subject'] = '<none>';
1020
      if (isset($_SESSION['cdm']['search'])) {
1021
        $block['content'] = l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search']);
1022
      }
1023
      return $block;
1024 a6ae799b Andreas Kohlbecker
    case 'registrations_search_filter':
1025
      $block['subject'] = '<none>';
1026 efbff4b3 Andreas Kohlbecker
      $block['content'] = drupal_get_form('cdm_dataportal_search_registration_filter_form'); // see cdm_dataportal_search_registration_filter_form($form, &$form_state)
1027
      return $block;
1028
    case 'registrations_search_taxongraph':
1029
      $block['subject'] = '<none>';
1030
      $block['content'] = drupal_get_form('cdm_dataportal_search_registration_taxongraph_form'); // see cdm_dataportal_search_registration_taxongraph_form($form, &$form_state)
1031 a6ae799b Andreas Kohlbecker
      return $block;
1032 b18d70f6 Andreas Kohlbecker
    case 'registrations_search':
1033
      _add_js_ui_accordion();
1034
      _add_font_awesome_font();
1035
      $block['subject'] = '<none>';
1036
      $filter_form = drupal_get_form('cdm_dataportal_search_registration_filter_form');
1037
      $filter_form['#prefix'] = '<div>';
1038
      $filter_form['#suffix'] = '</div>';
1039
      $taxongraph_form = drupal_get_form('cdm_dataportal_search_registration_taxongraph_form');
1040
      $taxongraph_form['#prefix'] = '<div>';
1041
      $taxongraph_form['#suffix'] = '</div>';
1042
      $block['content'] = array(
1043
        'accordion' => array(
1044
          '#markup' => '',
1045
          '#prefix' => '<div id="accordion">',
1046
          '#suffix' => '</div>',
1047
          'content' => array(
1048
            array('#markup' => '<h3>Filter</h3>'),
1049
            $filter_form,
1050
            array('#markup' => '<h3>Taxon graph</h3>'),
1051
            $taxongraph_form,
1052
          )
1053
        )
1054
    );
1055
       return $block;
1056 c05d1cfb Andreas Kohlbecker
    case 'utis_search':
1057
      _add_js_utis_client('.utis_client');
1058
      $block['subject'] = '<none>';
1059 579bc6e3 Andreas Kohlbecker
      $block['content'] = '<div class="utis_client"></div>';
1060 c05d1cfb Andreas Kohlbecker
      return $block;
1061 beb914ef Andreas Kohlbecker
    default:
1062
      return null;
1063 6657531f Andreas Kohlbecker
  }
1064
}
1065
1066 e27e3ff2 Andreas Kohlbecker
1067 0af3ce28 Andreas Kohlbecker
/**
1068
 * Provides the uuid of the taxon for pages with the path ./taxon/{taxon_uuid}
1069
 *
1070
 * @return string
1071
 *   the taxon uuid or NULL
1072
 */
1073
function get_current_taxon_uuid()
1074
{
1075
  static $taxon_uuid;
1076
1077
  if(!isset($taxon_uuid)){
1078
    if(isset($_REQUEST['currentTaxon']) && is_uuid($_REQUEST['currentTaxon'])) {
1079
      $taxon_uuid = $_REQUEST['currentTaxon'];
1080
    } else if (arg(1) == 'taxon' && is_uuid(arg(2))) {
1081
      $taxon_uuid = arg(2);
1082
    } else {
1083
      $taxon_uuid = null;
1084
    }
1085
  }
1086
1087
  return $taxon_uuid;
1088
}
1089
1090
/**
1091
 * Returns the currently classification tree in use.
1092
 *
1093
 * @return string
1094
 *   The uuid of the currently focused classification
1095
 */
1096
function get_current_classification_uuid() {
1097
  if (isset($_SESSION['cdm']['taxonomictree_uuid']) && is_uuid($_SESSION['cdm']['taxonomictree_uuid'])) {
1098
    return $_SESSION['cdm']['taxonomictree_uuid'];
1099
  }
1100
  else {
1101
    return variable_get(CDM_TAXONOMICTREE_UUID, FALSE);
1102
  }
1103
}
1104
1105 6657531f Andreas Kohlbecker
/*
1106
 function cdm_dataportal_session_clear($cdm_ws_uri_update = FALSE){
1107
 $_SESSION['cdm'] = NULL;
1108
 if(is_string($cdm_ws_uri_update)){
1109
 $_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
1110
 }
1111
 }
1112
1113
 function cdm_dataportal_session_validate(){
1114
 if(!isset($_SESSION['cdm']['ws_uri'])){
1115
 $_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', FALSE));
1116
 } else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', FALSE)){
1117
 cdm_dataportal_session_clear(variable_get('cdm_webservice_url', FALSE));
1118
 }
1119
 }
1120
 */
1121
1122
/**
1123 d7588d36 Andreas Kohlbecker
 * creates a  selector form for taxonomic trees.
1124
 *
1125 0af3ce28 Andreas Kohlbecker
 * @return array
1126
 *  a drupal form array
1127 6657531f Andreas Kohlbecker
 */
1128
function cdm_taxonomictree_selector() {
1129
  _add_js_treeselector();
1130
1131 a8a8f23c Andreas Kohlbecker
  $form = drupal_get_form('cdm_taxonomictree_selector_form');
1132 d7588d36 Andreas Kohlbecker
  return $form;
1133 6657531f Andreas Kohlbecker
}
1134
1135
/**
1136
 * @todo Please document this function.
1137
 * @see http://drupal.org/node/1354
1138 0af3ce28 Andreas Kohlbecker
 *
1139
 * @deprecated use compose_classification_selector instead
1140 6657531f Andreas Kohlbecker
 */
1141
function cdm_taxonomictree_selector_form($form, &$form_state) {
1142
1143
  $url = url('cdm_api/setvalue/session', array('query' => NULL));
1144
  $form['#action'] = $url;
1145
1146
  $form['var'] = array(
1147
    '#weight' => -3,
1148
    '#type' => 'hidden',
1149
    '#value' => '[cdm][taxonomictree_uuid]',
1150
  );
1151
1152
  $destination_array = drupal_get_destination();
1153
  $destination = $destination_array['destination'];
1154
1155
  $form['destination'] = array(
1156
    '#weight' => -3,
1157
    '#type' => 'hidden',
1158
    '#value' =>  $destination,
1159
  );
1160
1161 26fb3778 Andreas Kohlbecker
  $options = cdm_get_taxontrees_as_options();
1162
  $taxontree_includes = variable_get(CDM_TAXONTREE_INCLUDES, null);
1163
  if($taxontree_includes){
1164
    $filtered_options = array();
1165
    foreach($options as $uuid=>$label){
1166
      if(!empty($taxontree_includes[$uuid])){
1167
        $filtered_options[$uuid] = $label;
1168
      }
1169
    }
1170
    $options = $filtered_options;
1171
  }
1172
1173 6657531f Andreas Kohlbecker
  $form['val'] = array(
1174
    '#type' => 'select',
1175
    '#title' => t('Available classifications'),
1176 7663cd0b Andreas Kohlbecker
    '#default_value' => get_current_classification_uuid(),
1177 26fb3778 Andreas Kohlbecker
    '#options' => $options,
1178 0af3ce28 Andreas Kohlbecker
    '#attributes' => array('class' => array('highlite-first-child')),
1179 6657531f Andreas Kohlbecker
  );
1180
1181
  return $form;
1182
1183
}
1184
1185 0af3ce28 Andreas Kohlbecker
/**
1186
 *
1187
 * @ingroup compose
1188
 */
1189
function compose_classification_selector() {
1190
1191
  $destination_array = drupal_get_destination();
1192
  $destination = $destination_array['destination'];
1193
1194
  $options = cdm_get_taxontrees_as_options();
1195
  $items = array();
1196
  $taxontree_includes = variable_get(CDM_TAXONTREE_INCLUDES, null);
1197
1198
  $current_classification_uuid = get_current_classification_uuid();
1199
1200
1201
  foreach($options as $uuid=>$label){
1202
    if(!$taxontree_includes || !empty($taxontree_includes[$uuid])){
1203
1204
      $class_attributes = '';
1205
      if($current_classification_uuid == $uuid){
1206
        $class_attributes  = array('focused');
1207
      }
1208
      $items[] = array(
1209
        'data' => l($label,
1210
          'cdm_api/setvalue/session',
1211
          array(
1212
            'query' => array(
1213
              'destination' => $destination,
1214
              'val' => $uuid,
1215
              'var' => '[cdm][taxonomictree_uuid]'
1216
            ),
1217
          )
1218
        ),
1219
        'class' => $class_attributes
1220
      );
1221
    }
1222
  }
1223
1224
  $render_array = array(
1225
    '#theme' => 'item_list',
1226
    '#type' => 'ul',
1227
    '#items' => $items
1228
  );
1229
1230
  return $render_array;
1231
}
1232
1233
1234 6657531f Andreas Kohlbecker
/* UNREACHABLE since action of form directly links to view.
1235
 function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
1236
1237
 $_SESSION['cdm']['search'] = $form_values;
1238
 //return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
1239
 return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
1240
 //$paramstr = compose_url_prameterstr($form_values);
1241
 //return url('/cdm_dataportal/search/taxon/', array('query' => $paramstr));
1242
 }
1243
 */
1244
/* ====================== menu callback functions ====================== */
1245
/**
1246
 * @todo Please document this function.
1247
 * @see http://drupal.org/node/1354
1248
 */
1249
/*
1250
function cdm_dataportal_form_alter(&$form, &$form_state, $form_id) {
1251
  static $comment_node_disabled =  0;
1252
  static $comment_node_read_only =  1;
1253
  static $comment_node_read_write =  2;
1254
1255
  if ($form_id == 'node_type_form'
1256
   && isset($form['identity']['type'])
1257
   && array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
1258
  ) {
1259
    $form['workflow']['comment'] = array(
1260
      '#type' => 'radios',
1261
      '#title' => t('Default comment setting'),
1262
      '#default_value' => variable_get('comment__' . $node->type . $form['#node_type']->type, $comment_node_disabled),
1263
      '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
1264
      '#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
1265
    );
1266
  }
1267
}
1268
*/
1269
1270
/**
1271
 * Displays a list of the known taxonomic names.
1272
 *
1273
 * When the list of taxonomic names is displayed, long lists are split up into
1274
 * multiple pages.
1275
 *
1276
 * TODO: Parameters are still preliminary.
1277
 *
1278
 * @param string $beginsWith
1279
 * @param string $page
1280
 *   Page number to diplay defaults to page 1.
1281
 * @param bool $onlyAccepted
1282
 */
1283
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = FALSE) {
1284
1285
  $out = t('<h3>Sorry, the name list feature is not yet available in this version of the DataPortal software<h3>');
1286
1287
  /*
1288
  // FIXME the filter for accepted names will be a form element, thus this
1289
  // widget should be generated via form api preferably as block.
1290
  $out  = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
1291
  $out .= theme('cdm_dataportal_widget_names_list', $names, $page);
1292
  $out .= theme('cdm_listof_taxa', $taxonPager);
1293
  return $out;
1294
  */
1295
}
1296
1297
/**
1298
 * @todo Please document this function.
1299
 * @see http://drupal.org/node/1354
1300 c0223d83 Andreas Kohlbecker
 * @throws Exception
1301 6657531f Andreas Kohlbecker
 */
1302
function cdm_dataportal_view_reference($uuid, $arg2 = NULL) {
1303 f26245c8 Andreas Kohlbecker
1304
  cdm_check_valid_portal_page();
1305
1306 6cbefddc Andreas Kohlbecker
  return compose_cdm_reference_page($uuid);
1307 6657531f Andreas Kohlbecker
}
1308
1309
/**
1310 b2ebf0d3 Andreas Kohlbecker
 * Creates a view on a all references contained in the portal.
1311 b5dca1e2 Andreas Kohlbecker
 *
1312
 * This function is used at the path cdm_dataportal/reference/list
1313 6657531f Andreas Kohlbecker
 */
1314
function cdm_dataportal_view_reference_list($pageNumber) {
1315 44458b04 Andreas Kohlbecker
  $referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get(CDM_SEARCH_RESULT_PAGE_SIZE, CDM_SEARCH_RESULT_PAGE_SIZE_DEFAULT), $pageNumber);
1316 b2ebf0d3 Andreas Kohlbecker
  cdm_reference_pager($referencePager, 'cdm_dataportal/reference/list/');
1317 6657531f Andreas Kohlbecker
}
1318
1319
/**
1320
 * @todo Please document this function.
1321
 * @see http://drupal.org/node/1354
1322
 */
1323
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = FALSE, $part = 0) {
1324 f26245c8 Andreas Kohlbecker
1325
  cdm_check_valid_portal_page();
1326
1327 6657531f Andreas Kohlbecker
  $media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
1328 4d9660ef Andreas Kohlbecker
  if (!$media) {
1329
    drupal_set_title(t('Media does not exist'), PASS_THROUGH);
1330 de017852 Andreas Kohlbecker
    return "";
1331 4d9660ef Andreas Kohlbecker
  }
1332 6657531f Andreas Kohlbecker
  return theme('cdm_media_page', array(
1333
    'media' => $media,
1334
    'mediarepresentation_uuid' => $mediarepresentation_uuid,
1335
    'partId' => $part,
1336
    ));
1337
}
1338
1339
/**
1340
 * @todo Please document this function.
1341
 * @see http://drupal.org/node/1354
1342
 */
1343
function _load_taxonBase(&$taxonBase) {
1344
  if (isset($taxonBase->uuid)) {
1345 6679207a Andreas Kohlbecker
    $taxonBase->name = cdm_ws_get(CDM_WS_PORTAL_TAXON, array($taxonBase->uuid, "name"));
1346
    $taxonBase->name->nomenclaturalSource = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "nomenclaturalSource"));
1347 6657531f Andreas Kohlbecker
  }
1348
}
1349
1350 9438ad3a Andreas Kohlbecker
/**
1351
 * Loads the media associated to the given taxon from the cdm server.
1352
 * The aggregation settings regarding taxon relathionships and
1353
 * taxonnomic childen are taken into account.
1354
 *
1355
 * The media lists are cached in a static variable.
1356
 *
1357
 * @param Taxon $taxon
1358 4a462641 Andreas Kohlbecker
 *   A CDM Taxon entity
1359 9438ad3a Andreas Kohlbecker
 *
1360
 * @return array
1361
 *   An array of CDM Media entities
1362
 *
1363
 */
1364 4a462641 Andreas Kohlbecker
  function _load_media_for_taxon($taxon) {
1365 9438ad3a Andreas Kohlbecker
1366
  static $media = NULL;
1367
1368
  if(!isset($media)) {
1369
    $media = array();
1370
  }
1371
  if (!isset($media[$taxon->uuid])) {
1372
1373 a950f2f9 Andreas Kohlbecker
1374 4a462641 Andreas Kohlbecker
    $mediaQueryParameters = taxon_media_query_parameters();
1375 9438ad3a Andreas Kohlbecker
1376 f19f47fa Andreas Kohlbecker
    $ws_endpoint = NULL;
1377 4a462641 Andreas Kohlbecker
    if ( $mediaQueryParameters['includeTaxonomicChildren']) {
1378 9438ad3a Andreas Kohlbecker
      $ws_endpoint = CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA;
1379 4a462641 Andreas Kohlbecker
    } else {
1380
      $ws_endpoint = CDM_WS_PORTAL_TAXON_MEDIA;
1381 9438ad3a Andreas Kohlbecker
    }
1382 4a462641 Andreas Kohlbecker
    // this parameter is not yet used by the CDM_WS_PORTAL_TAXON_*MEDIA
1383
    // services
1384
    unset($mediaQueryParameters['includeTaxonomicChildren']);
1385 f19f47fa Andreas Kohlbecker
1386
    $media[$taxon->uuid] = cdm_ws_get($ws_endpoint,
1387
        array(
1388
            $taxon->uuid,
1389
        ),
1390 9438ad3a Andreas Kohlbecker
        queryString($mediaQueryParameters)
1391
       );
1392
  }
1393
1394
  return $media[$taxon->uuid];
1395
}
1396
1397
/**
1398
 *
1399
 * @param Taxon $taxon
1400
 *   A CDM Taxon entitiy
1401
 *
1402
 * @return array
1403
 *   An array of CDM SpecimenOrObservation entities
1404
 *
1405
function _load_occurences_for_taxon($taxon){
1406
1407
  static $occurences = NULL;
1408 f19f47fa Andreas Kohlbecker
1409
  if(!isset($occurences)) {
1410
    $occurences = array();
1411
  }
1412 9438ad3a Andreas Kohlbecker
1413
  if (!isset($occurences[$taxon->uuid])){
1414
1415
    $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
1416
    $relationship_choice['direct'] = get_selection($relationship_choice['direct']);
1417 f19f47fa Andreas Kohlbecker
    $relationship_choice['invers'] = get_selection($relationship_choice['invers']);
1418
1419
    $by_associatedtaxon_query = http_build_query(array(
1420
        'relationshipsInvers' => implode(',', $relationship_choice['invers']),
1421
        'relationships' => implode(',', $relationship_choice['direct']),
1422
        'pageSize' => null // all hits in one page
1423
    )
1424
    );
1425
1426
    $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
1427
        null,
1428
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
1429
    );
1430
1431
1432
    if(isset($pager->records[0])){
1433
      $occurences[$taxon->uuid] =  $pager->records;
1434
    }
1435
  }
1436 9438ad3a Andreas Kohlbecker
  return $occurences[$taxon->uuid];
1437
}
1438
 */
1439
1440 6657531f Andreas Kohlbecker
/**
1441
 * Gets a Drupal variable, string or array and returns it.
1442
 *
1443
 * Similar to the variable_get() function of Drupal, except that this function
1444
 * is able to handle arrays correctly. This function is especially useful
1445 8c962983 Andreas Kohlbecker
 * when dealing with collections of settings form elements (#tree = TRUE).
1446 6657531f Andreas Kohlbecker
 *
1447
 * @param string $variableKey
1448
 *   The Unique key of the Drupal variable in the Drupal variables table.
1449
 * @param string $defaultValueString
1450
 *   A string as for example derived from a CONSTANT.
1451
 *
1452
 * @return mixed
1453 8c962983 Andreas Kohlbecker
 *   usually an array, depending on the nature of the variable.
1454
 *
1455
 * TODO compare with get_array_variable_merged() duplicate functions?
1456 0f7c9d15 Andreas Kohlbecker
 * @deprecated rather use get_array_variable_merged() since this function
1457
 * used an array as second parameter
1458 6657531f Andreas Kohlbecker
 */
1459
function mixed_variable_get($variableKey, $defaultValueString) {
1460
  $systemDefaults = unserialize($defaultValueString);
1461
  $storedSettings = variable_get($variableKey, array());
1462
  if (is_array($storedSettings)) {
1463 8c962983 Andreas Kohlbecker
    // TODO better use drupal_array_merge_deep() ?
1464 6657531f Andreas Kohlbecker
    $settings = array_merge($systemDefaults, $storedSettings);
1465
  }
1466
  else {
1467
    $settings = $systemDefaults;
1468
  }
1469
  return $settings;
1470
}
1471
1472 b5519d3a Andreas Kohlbecker
/**
1473 0f7c9d15 Andreas Kohlbecker
 * Recursive function to convert an object into an array.
1474 b5519d3a Andreas Kohlbecker
 * also subordinate objects will be converted.
1475
 *
1476
 * @param object $object
1477 db725031 Andreas Kohlbecker
 *  the object to be converted
1478
 * @return array
1479
 *  The array
1480 b5519d3a Andreas Kohlbecker
 */
1481 db725031 Andreas Kohlbecker
function object_to_array($object) {
1482 b5519d3a Andreas Kohlbecker
  if(is_object($object) || is_array($object)) {
1483
    $array = (array)$object;
1484
    foreach ($array as $key=>$value){
1485 db725031 Andreas Kohlbecker
      $array[$key] = object_to_array($value);
1486 b5519d3a Andreas Kohlbecker
    }
1487
    return $array;
1488
  } else {
1489
    return $object;
1490
  }
1491
}
1492
1493 2fd6da0b Andreas Kohlbecker
/**
1494
 * Searches the $collection for the cdm entitiy given as $element.
1495
 *
1496
 * The elements are compared by their UUID.
1497
 *
1498
 * @param $element
1499
 *  the CDM entitiy to search for
1500
 * @param $collection
1501
 *  the list of CDM entities to search in
1502
 *
1503
 * @return boolean TRUE if the $collection contains the $element, otheriwse FALSE
1504
 *
1505
 */
1506
function contains_cdm_entitiy($element, $collection) {
1507
  $result = FALSE;
1508
  foreach ($collection as $a) {
1509
    if ($a->uuid == $element->uuid) {
1510
      $result = TRUE;
1511
    }
1512
  }
1513
  return $result;
1514
}
1515
1516
/**
1517 14076b88 Andreas Kohlbecker
 * Filters the array $entity_list of CDM entities by the list
1518 2fd6da0b Andreas Kohlbecker
 * of $excludes. Any element contained in the $excludes will be removed
1519 14076b88 Andreas Kohlbecker
 * from included int the returned list.
1520 2fd6da0b Andreas Kohlbecker
 *
1521
 * If the $entity_list is not an array the $excludes will be returned.
1522
 */
1523
function filter_cdm_entity_list($entity_list, $excludes) {
1524
  if (is_array($entity_list)) {
1525
    $result = $entity_list;
1526
    if ($excludes) {
1527
      foreach ($excludes as $exclude) {
1528
        if (!contains_cdm_entitiy($exclude, $entity_list)) {
1529
          $result[] = $exclude;
1530
        }
1531
      }
1532
    }
1533
  }
1534
  else {
1535
    $result = $excludes;
1536
  }
1537
  return $result;
1538
}
1539
1540 0a1151a4 Andreas Kohlbecker
/**
1541 6f5c7f2a Andreas Kohlbecker
 * Wraps the given $html string into a render array suitable for drupal_render()
1542 0a1151a4 Andreas Kohlbecker
 *
1543 65345976 Andreas Kohlbecker
 * @param $html
1544 0a1151a4 Andreas Kohlbecker
 *   the html string, see
1545
 *   http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#markup
1546 65345976 Andreas Kohlbecker
 * @param $weight
1547 0a1151a4 Andreas Kohlbecker
 *   A positive or negative number (integer or decimal).
1548
 *   see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#weightval
1549 65345976 Andreas Kohlbecker
 * @param $prefix
1550
 *   Optional markup for the '#prefix' element of the render array
1551
 * @param $suffix
1552
 *   Optional markup for the '#suffix' element of the render array
1553 0a1151a4 Andreas Kohlbecker
 *
1554 65345976 Andreas Kohlbecker
 * @return array
1555 0a1151a4 Andreas Kohlbecker
 *   A render array
1556
 *
1557
 */
1558 65345976 Andreas Kohlbecker
function markup_to_render_array($html, $weight = FALSE, $prefix = NULL, $suffix = NULL) {
1559 6f5c7f2a Andreas Kohlbecker
  $render_array = array(
1560
    '#markup' => $html
1561 1ce9afb7 Patric Plitzner
      );
1562 6f5c7f2a Andreas Kohlbecker
  if (is_numeric($weight)) {
1563
    $render_array['#weight'] = $weight;
1564 65345976 Andreas Kohlbecker
  }
1565
  if($prefix){
1566
    $render_array['#prefix'] = $prefix;
1567
  }
1568
  if($suffix) {
1569
    $render_array['#suffix'] = $suffix;
1570
  }
1571 6f5c7f2a Andreas Kohlbecker
  return $render_array;
1572 0a1151a4 Andreas Kohlbecker
}
1573
1574 6657531f Andreas Kohlbecker
/**
1575
 * Loads the subgraph of a given PolytomousKeyNode.
1576
 *
1577
 * Loads the subgraph of the given PolytomousKeyNode recursively from
1578
 * the CDM REST service.
1579
 *
1580
 * @param mixed $polytomousKeyNode
1581
 *   PolytomousKeyNode passed by reference.
1582
 *
1583
 * @return void
1584
 */
1585
function _load_polytomousKeySubGraph(&$polytomousKeyNode) {
1586
1587
  if (!$polytomousKeyNode) {
1588
    return;
1589
  }
1590
  if ($polytomousKeyNode->class != "PolytomousKeyNode") {
1591 f19f47fa Andreas Kohlbecker
    drupal_set_message('_load_polytomousKeySubGraph(): ' . t('invalid type given.'), 'error');
1592 6657531f Andreas Kohlbecker
    return;
1593
  }
1594
  if (!is_uuid($polytomousKeyNode->uuid)) {
1595 f19f47fa Andreas Kohlbecker
    drupal_set_message('_load_polytomousKeySubGraph(): ' . t('invalid type given.'), 'error');
1596 6657531f Andreas Kohlbecker
    return;
1597
  }
1598
1599
  $polytomousKeyNode = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid);
1600
1601
  if (!$polytomousKeyNode) {
1602
    // drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error");
1603
    return;
1604
  }
1605
1606
  // Load children.
1607
  foreach ($polytomousKeyNode->children as &$childNode) {
1608
    _load_polytomousKeySubGraph($childNode);
1609
  }
1610
1611
  // Load subkey.
1612
  $polytomousKeyNode->subkey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "subkey"));
1613
1614
  // Load taxon.
1615
  $polytomousKeyNode->taxon = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "taxon"));
1616
  _load_taxonBase($polytomousKeyNode->taxon);
1617
  return;
1618
}
1619
1620
/**
1621
 * @todo Please document this function.
1622
 * @see http://drupal.org/node/1354
1623
 */
1624
function cdm_dataportal_view_polytomousKey($polytomousKeyUuid) {
1625 f26245c8 Andreas Kohlbecker
1626
  cdm_check_valid_portal_page();
1627
1628 6657531f Andreas Kohlbecker
  $polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid);
1629 4d9660ef Andreas Kohlbecker
  if (!$polytomousKey) {
1630
    drupal_set_title(t('Polytomous key does not exist'), PASS_THROUGH);
1631 de017852 Andreas Kohlbecker
    return "";
1632 4d9660ef Andreas Kohlbecker
  }
1633 6657531f Andreas Kohlbecker
1634
  $sourcePager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources'));
1635
  if (is_array($sourcePager->records)) {
1636
    $polytomousKey->sources = $sourcePager->records;
1637
    // $polytomousKey->sources->citation = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources'));
1638
  }
1639
1640
  $annotationPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'annotations'));
1641
  if (is_array($annotationPager->records)) {
1642
    $polytomousKey->annotations = $annotationPager->records;
1643
  }
1644
1645
  _load_polytomousKeySubGraph($polytomousKey->root);
1646
  return theme('cdm_polytomousKey_page', array('polytomousKey' => $polytomousKey));
1647
}
1648
1649
/**
1650
 * Creates a taxon page view or a chapter of it.
1651
 *
1652
 * The taxon page gives detailed information on a taxon, it shows:
1653
 *  - Taxon name.
1654
 *  - Full list of synonyms homotypic synonyms on top, followed by the
1655
 *    heterotypic and finally followed by misapplied names.
1656
 *    The list is ordered historically.
1657
 *  - All description associated with the taxon.
1658
 *
1659
 * @param string $uuid
1660
 * @param string $chapter
1661
 *   Name of the part to display, valid values are:
1662
 *   'description', 'images', 'synonymy', 'specimens', 'all'.
1663
 *
1664 793dae0a Andreas Kohlbecker
 * @return string
1665 6657531f Andreas Kohlbecker
 */
1666 0c5a23b6 Andreas Kohlbecker
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all') {
1667 5ea8b301 Andreas Kohlbecker
1668 f26245c8 Andreas Kohlbecker
  cdm_check_valid_taxon_page($chapter);
1669 2dd59bb5 Andreas Kohlbecker
  cdm_dd("START OF TAXON PAGE [" . $chapter . "] " . $uuid . ' for ' . $_GET['q']);
1670 b654a866 Andreas Kohlbecker
1671 5ea8b301 Andreas Kohlbecker
1672 6657531f Andreas Kohlbecker
  // Display the page for the taxon defined by $uuid.
1673
  // set_last_taxon_page_tab(arg(3));
1674 0c5a23b6 Andreas Kohlbecker
  $taxonpage = cdm_dataportal_taxon_view($uuid, $chapter);
1675 6657531f Andreas Kohlbecker
  if (!empty($taxonpage)) {
1676 2dd59bb5 Andreas Kohlbecker
    cdm_dd("END OF TAXON PAGE [" . $chapter . "] " . $uuid);
1677 6657531f Andreas Kohlbecker
    return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title, $taxonpage->content);
1678
  }
1679
  else {
1680 2dd59bb5 Andreas Kohlbecker
    cdm_dd("END OF TAXON PAGE [" . $chapter . "] " . $uuid . ' !!! PAGE IS EMPTY !!!');
1681 6657531f Andreas Kohlbecker
    return '';
1682
  }
1683
}
1684
1685
/**
1686 43d01429 Andreas Kohlbecker
 * This function will generate the taxon page part ($chapter) and returns a taxonpage object
1687 59f6da42 Andreas Kohlbecker
 * which has two fields, one for the page title and one for the content. Later on in the
1688
 * process chain the value contained in these fields will be passed to the cdm_node_show()
1689
 * function as the function parameters $title and $content.
1690 6657531f Andreas Kohlbecker
 *
1691
 * @param string $uuid
1692 59f6da42 Andreas Kohlbecker
 *   the uuid of the taxon to show
1693 6657531f Andreas Kohlbecker
 * @param string $chapter
1694
 *   Name of the part to display, valid values are:
1695
 *   'description', 'images', 'synonymy', 'all'.
1696
 *
1697 0c5a23b6 Andreas Kohlbecker
 * @return object with the following fields:
1698 59f6da42 Andreas Kohlbecker
 *   - title : the title of the page
1699
 *   - content: the content of the page
1700
 *
1701 8a1b451e Andreas Kohlbecker
 * @throws Exception
1702
 *
1703 6657531f Andreas Kohlbecker
 */
1704 8cf9238f Andreas Kohlbecker
function cdm_dataportal_taxon_view($uuid, $chapter = 'all') {
1705 6657531f Andreas Kohlbecker
  // Taxon object.
1706
  $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
1707
  if (empty($taxon)) {
1708
    drupal_set_title(t('Taxon does not exist'), PASS_THROUGH);
1709 8a1b451e Andreas Kohlbecker
    return null;
1710 6657531f Andreas Kohlbecker
  }
1711
  $taxonpage = new stdClass();
1712
1713
  $taxonpage->title = theme('cdm_taxon_page_title', array(
1714 8cf9238f Andreas Kohlbecker
    'taxon' => $taxon
1715 6657531f Andreas Kohlbecker
  ));
1716
1717
  // Check if the taxon id contained in the currently selected tree.
1718 7663cd0b Andreas Kohlbecker
  $taxon_in_current_classification = taxon_in_current_classification($uuid);
1719 61b6ee11 Andreas Kohlbecker
1720 7663cd0b Andreas Kohlbecker
  if (!$taxon_in_current_classification) {
1721 61b6ee11 Andreas Kohlbecker
    $classifications = get_classifications_for_taxon($taxon);
1722 e24d373b Andreas Kohlbecker
    RenderHints::pushToRenderStack('not_in_current_classification');
1723 8202a2c0 Andreas Kohlbecker
    RenderHints::setFootnoteListKey('not_in_current_classification');
1724
    FootnoteManager::blockFootnotesFor('not_in_current_classification');
1725 e24d373b Andreas Kohlbecker
    $taxon_name_markup = render_taxon_or_name($taxon);
1726 8202a2c0 Andreas Kohlbecker
    FootnoteManager::unblockFootnotesFor('not_in_current_classification');
1727
    RenderHints::clearFootnoteListKey();
1728 e24d373b Andreas Kohlbecker
1729 61b6ee11 Andreas Kohlbecker
    if (count($classifications) == 0) {
1730 e24d373b Andreas Kohlbecker
      drupal_set_message(t('This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification.',
1731 fba00a4f Andreas Kohlbecker
        array(
1732 e24d373b Andreas Kohlbecker
        '!taxonname' => $taxon_name_markup,
1733 fba00a4f Andreas Kohlbecker
        )
1734
      ), 'warning');
1735 6657531f Andreas Kohlbecker
    }
1736
    else {
1737
      $trees = '';
1738 61b6ee11 Andreas Kohlbecker
      foreach ($classifications as $classification) {
1739
        if (isset($classification->titleCache)) {
1740
          $trees .= ($trees ? ', ' : '') . '<strong>' . $classification->titleCache . '</strong>';
1741 6657531f Andreas Kohlbecker
        }
1742
      }
1743
1744 15b7c460 Andreas Kohlbecker
      drupal_set_message(format_plural(count($trees),
1745 e24d373b Andreas Kohlbecker
          'This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification, but in this one: !trees',
1746
          'This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification, but in one of these: !trees',
1747
          array('!taxonname' => $taxon_name_markup, '!trees' => $trees)
1748 fba00a4f Andreas Kohlbecker
        ) ,
1749
        'warning');
1750 6657531f Andreas Kohlbecker
    }
1751 e24d373b Andreas Kohlbecker
    RenderHints::popFromRenderStack();
1752 6657531f Andreas Kohlbecker
  }
1753
1754
  // Render the taxon page.
1755 9a607f17 Andreas Kohlbecker
  $render_array = compose_cdm_taxon_page($taxon, $chapter);
1756
  $taxonpage->content = drupal_render($render_array);
1757 6657531f Andreas Kohlbecker
1758
  return $taxonpage;
1759
}
1760 961319fe Andreas Kohlbecker
1761
1762 6eaec849 Katja Luther
function cdm_dataportal_specimen_by_accession_number_page_view($accession_number)
1763
{
1764 961319fe Andreas Kohlbecker
  cdm_check_valid_portal_page();
1765 6eaec849 Katja Luther
1766 961319fe Andreas Kohlbecker
  $specimenpage = specimen_by_accession_number_view($accession_number);
1767
1768
  if (!empty($specimenpage)) {
1769
    return cdm_node_show_simulate($specimenpage->content);
1770
  }
1771
  else {
1772
    return '';
1773
  }
1774 4c812e71 Katja Luther
1775 6657531f Andreas Kohlbecker
1776 6eaec849 Katja Luther
}
1777 961319fe Andreas Kohlbecker
1778 9d37c9d9 Patric Plitzner
/**
1779
 * Creates a specimen page view.
1780
 * @param string $uuid the UUID of the specimen
1781
 * @return array|string
1782
 */
1783 961319fe Andreas Kohlbecker
function cdm_dataportal_specimen_page_view($uuid) {
1784 9d37c9d9 Patric Plitzner
1785 b654a866 Andreas Kohlbecker
    cdm_check_valid_portal_page();
1786 961319fe Andreas Kohlbecker
    $specimenpage = cdm_dataportal_specimen_view($uuid);
1787
    if (!empty($specimenpage)) {
1788
        return cdm_node_show_simulate($specimenpage->content);
1789
    }
1790
    else {
1791
        return '';
1792
    }
1793
}
1794 4c812e71 Katja Luther
1795
1796 961319fe Andreas Kohlbecker
/**
1797
 * Creates a specimen page view.
1798
 * @param string $uuid the UUID of the specimen
1799
 * @return object
1800
 *  The page object with the following fields:
1801
 *   - 'title': the page title
1802
 *   - 'content' : the page content rendered as markup
1803
 */
1804 ff51c1cd Katja Luther
function specimen_by_accession_number_view($accession_number = null) {
1805 961319fe Andreas Kohlbecker
1806
  $field_unit_dto = cdm_ws_get(CDM_WS_OCCURRENCE_ACCESSION_NUMBER, null, 'accessionNumber=' . $accession_number);
1807
1808
  // Display the page for the specimen defined by $uuid.
1809
  if (isset($field_unit_dto)){
1810
    $dto_array = array($field_unit_dto);
1811
    $specimen_array = specimen_render_array_items($dto_array);
1812
    $specimen_table = array(
1813
      '#theme' => 'table',
1814
      '#weight' => 2,
1815
      // prefix attributes and rows with '#' to let it pass toF the theme function,
1816
      // otherwise it is handled as child render array
1817
      '#attributes' => array('class' => 'specimens'),
1818
      '#rows' => array(),
1819
      '#prefix' => '<div id="specimens">',
1820
      '#suffix' => '</div>',
1821
    );
1822
    foreach($specimen_array as $value){
1823
      $renderArray = array(
1824
        '#theme' => 'item_list',
1825
        '#items' => array($value),
1826
        '#type' => 'ul');
1827
      $output = drupal_render($renderArray);
1828
      $specimen_table['#rows'][] = array(
1829
        // An array of table rows. Every row is an array of cells, or an associative array
1830
        'data' => array($output),
1831
        'class' =>  array(
1832
          'descriptionElement',
1833
          'descriptionElement_IndividualsAssociation'
1834
        ),
1835
      );
1836 4c812e71 Katja Luther
1837
1838 961319fe Andreas Kohlbecker
    }
1839
    $specimenpage = new stdClass();
1840 4c812e71 Katja Luther
1841 961319fe Andreas Kohlbecker
    $specimenpage->title = theme('theme_cdm_specimen_dto_page_title', array(
1842
      'specimen' => $field_unit_dto
1843
    ));
1844 4c812e71 Katja Luther
1845 ff51c1cd Katja Luther
     $render_array['markup'] = $specimen_table;
1846
     $specimenpage->content = drupal_render($render_array);
1847 961319fe Andreas Kohlbecker
  }
1848 4c812e71 Katja Luther
1849 961319fe Andreas Kohlbecker
  return $specimenpage;
1850 9d37c9d9 Patric Plitzner
}
1851
1852 961319fe Andreas Kohlbecker
1853 9d37c9d9 Patric Plitzner
/**
1854
 *
1855
 * Creates a specimen view.
1856
 * @param string $uuid the UUID of the specimen
1857 961319fe Andreas Kohlbecker
 * @return object
1858
 *    Page object with the fields
1859
 *    - title
1860
 *    - content
1861 9d37c9d9 Patric Plitzner
 */
1862
function cdm_dataportal_specimen_view($uuid) {
1863 a2acff0a Katja Luther
    //TODO: get the derivateDTO and don't call the webservice a second time in compose_cdm_specimen_page
1864 907cc9b4 Patrick Plitzner
    $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, $uuid);
1865 9d37c9d9 Patric Plitzner
    if (empty($specimen)) {
1866
        drupal_set_title(t('Specimen does not exist'), PASS_THROUGH);
1867
        return FALSE;
1868
    }
1869
    $specimenpage = new stdClass();
1870
1871 961319fe Andreas Kohlbecker
    $specimenpage->title = specimen_page_title($specimen);
1872 9d37c9d9 Patric Plitzner
1873 b810158e Patric Plitzner
    // Render the specimen page.
1874 a2acff0a Katja Luther
    $render_array = compose_cdm_specimen_page($specimen);
1875 9d37c9d9 Patric Plitzner
    $specimenpage->content = drupal_render($render_array);
1876
1877
    return $specimenpage;
1878
}
1879
1880 e170a53e Patrick Plitzner
/**
1881
 *
1882
 * Creates a description view.
1883 ea0ae3c7 Patrick Plitzner
 *
1884 e170a53e Patrick Plitzner
 * @param string $uuid the UUID of the description
1885 ea0ae3c7 Patrick Plitzner
 * @param null $descriptive_dataset_uuid the uuid of the data set which defines
1886
 * the display of the description detail page
1887
 *
1888
 * @return object Page object with the fields
1889
 * Page object with the fields
1890
 * - title
1891
 * - content
1892 e170a53e Patrick Plitzner
 */
1893 ea0ae3c7 Patrick Plitzner
function cdm_dataportal_description_view($uuid, $descriptive_dataset_uuid = NULL) {
1894 e170a53e Patrick Plitzner
    $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $uuid);
1895 de017852 Andreas Kohlbecker
    $description_page = new stdClass();
1896 e170a53e Patrick Plitzner
    if (empty($description)) {
1897 de017852 Andreas Kohlbecker
      $description_page->title = t('Description does not exist');
1898
      drupal_set_title($description_page->title, PASS_THROUGH); // not necessary if correctly implemented as drupal node
1899
      $description_page->content = "";
1900 e170a53e Patrick Plitzner
1901 de017852 Andreas Kohlbecker
    } else {
1902
      $description_page->title = $description->titleCache;
1903
      drupal_set_title($description_page->title); // not necessary if correctly implemented as drupal node
1904 e170a53e Patrick Plitzner
1905 de017852 Andreas Kohlbecker
      // Render the description page.
1906 fec3fd41 Andreas Kohlbecker
      $render_array = compose_description_table($description->uuid, $descriptive_dataset_uuid);
1907 20bfe15b Andreas Kohlbecker
      if($render_array['title']){
1908
        $page_title = strip_tags($render_array['title']['#markup']);
1909
        drupal_set_title($page_title);
1910
        unset($render_array['title']);
1911
      }
1912 de017852 Andreas Kohlbecker
      $description_page->content = drupal_render($render_array);
1913
    }
1914 e170a53e Patrick Plitzner
1915 de017852 Andreas Kohlbecker
    return $description_page;
1916 e170a53e Patrick Plitzner
}
1917
1918 ea0ae3c7 Patrick Plitzner
function cdm_dataportal_description_page_view($uuid, $descriptive_dataset_uuid = NULL) {
1919 e170a53e Patrick Plitzner
1920
  cdm_check_valid_portal_page();
1921 ea0ae3c7 Patrick Plitzner
  $descriptionpage = cdm_dataportal_description_view($uuid, $descriptive_dataset_uuid);
1922 e170a53e Patrick Plitzner
  if (!empty($descriptionpage)) {
1923
    return cdm_node_show_simulate($descriptionpage->content);
1924
  }
1925
  else {
1926 de017852 Andreas Kohlbecker
    return NULL;
1927 e170a53e Patrick Plitzner
  }
1928
}
1929
1930 30845bda Andreas Kohlbecker
/**
1931
 *
1932
 * Creates a named area view.
1933
 * @param string $uuid the UUID of the specimen
1934
 *  * @return object
1935
 *   An object with two fields:
1936
 *     - title: the page title
1937
 *     - content: the page content
1938
 */
1939
1940
function cdm_dataportal_named_area_view($uuid) {
1941
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, $uuid);
1942
  if (empty($named_area) || $named_area->class !== 'NamedArea') {
1943
    drupal_set_title(t('Named area does not exist'), PASS_THROUGH);
1944 4d9660ef Andreas Kohlbecker
    return null;
1945 30845bda Andreas Kohlbecker
  }
1946
  $named_area_page = new stdClass();
1947
1948
  $named_area_page->title = $named_area->representation_L10n;
1949
1950
  // Render the specimen page.
1951
  $render_array = compose_cdm_named_area_page($uuid);
1952
  $named_area_page->content = drupal_render($render_array);
1953
1954
  return $named_area_page;
1955
}
1956
1957
function cdm_dataportal_named_area_page_view($uuid) {
1958
1959
  cdm_check_valid_portal_page();
1960
1961
  $named_area_page = cdm_dataportal_named_area_view($uuid);
1962
  if (!empty($named_area_page)) {
1963
    return cdm_node_show(NODETYPE_NAME, $uuid, $named_area_page->title, $named_area_page->content);
1964
  }
1965
  else {
1966
    return '';
1967
  }
1968
1969
1970
}
1971
1972 6657531f Andreas Kohlbecker
/**
1973
 * Returns a name page as a Drupal node ready to be renderized by Drupal.
1974
 *
1975
 * The node page shows the taxon name title and the list of taxon related
1976
 * with such taxon. Name on the tree already in use.
1977
 *
1978 d4ea0dd9 Andreas Kohlbecker
 * @param string $taxon_name_uuid
1979 102f8c26 Andreas Kohlbecker
 *   The uuid of the CDM TaxonName to show a name page for
1980 d4ea0dd9 Andreas Kohlbecker
 * @param string $taxon_to_hide_uuid
1981 51b04faf Andreas Kohlbecker
 *   A taxon which should not be displayed in the taxon list
1982 2f65af04 Andreas Kohlbecker
 * @param $redirect_to_taxon
1983
 *   Automatically redirect to the related taxon if there is only one
1984
 *   accepted taxon for this name.
1985 d4ea0dd9 Andreas Kohlbecker
 * @param string $highlite_synonym_uuid
1986 51b04faf Andreas Kohlbecker
 *   Optinal parameter wich takes another taxon uuid, if given the
1987
 *   target taxon pages will show the syonymy tab where the taxon
1988
 *   refenrenced by the $highlite_synonym_uuid will be highlighted
1989
 *   in case it is found on this page.
1990 6657531f Andreas Kohlbecker
 *
1991
 * @return mixed
1992
 *   The formatted name page as node.
1993
 */
1994 b648739e Andreas Kohlbecker
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = NULL, $redirect_to_taxon = false) {
1995 6657531f Andreas Kohlbecker
1996 f26245c8 Andreas Kohlbecker
  cdm_check_valid_portal_page();
1997
1998 b648739e Andreas Kohlbecker
  $taxonname_page = cdm_dataportal_name_view(
1999
    is_uuid($taxon_name_uuid) ? $taxon_name_uuid : null,
2000
    is_uuid($taxon_to_hide_uuid) ? $taxon_to_hide_uuid : null,
2001
    $redirect_to_taxon == 'redirect_to_taxon',
2002
    is_uuid($synonym_uuid) ? $synonym_uuid : null);
2003 6657531f Andreas Kohlbecker
  if (!empty($taxonname_page)) {
2004
    return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title, $taxonname_page->content);
2005
  }
2006
  else {
2007
    return '';
2008
  }
2009
}
2010
2011
/**
2012 102f8c26 Andreas Kohlbecker
 * View function for a TaxonName page.
2013 6657531f Andreas Kohlbecker
 *
2014 e3001c8d Andreas Kohlbecker
 * The name page lists all taxa for which the name specified by the
2015
 * $taxon_name_uuid is being used. I case there is only one name the
2016
 * page automatically redirects ti the according taxon page. Otherwise
2017
 * the list of names is displayed.
2018 6657531f Andreas Kohlbecker
 *
2019 e3001c8d Andreas Kohlbecker
 * The parameter $taxon_to_hide_uuid allows to exclude a taxon from the
2020
 * list of taxa. This is useful for example when referencing from a taxon
2021
 * to the name page and the referring taxon should not be repeaded in the
2022
 * name page.
2023 6657531f Andreas Kohlbecker
 *
2024 e3001c8d Andreas Kohlbecker
 *
2025 d4ea0dd9 Andreas Kohlbecker
 * @param string $taxon_name_uuid
2026 102f8c26 Andreas Kohlbecker
 *   The uuid of the CDM TaxonName to show a name page for
2027 d4ea0dd9 Andreas Kohlbecker
 * @param string $taxon_to_hide_uuid
2028 e3001c8d Andreas Kohlbecker
 *   A taxon which should not be displayed in the taxon list
2029 2f65af04 Andreas Kohlbecker
 * @param $redirect_to_taxon
2030
 *   Automatically redirect to the related taxon if there is only one
2031
 *   accepted taxon for this name.
2032 d4ea0dd9 Andreas Kohlbecker
 * @param string $highlite_synonym_uuid
2033 2f65af04 Andreas Kohlbecker
 *   Optional parameter which takes another taxon uuid, if given the
2034
 *   target taxon pages will show the synonymy tab where the taxon
2035
 *   referenced by the $highlite_synonym_uuid will be highlighted
2036 e3001c8d Andreas Kohlbecker
 *   in case it is found on this page.
2037
 *
2038 2f65af04 Andreas Kohlbecker
 * @return object|boolean
2039 e3001c8d Andreas Kohlbecker
 *   An object with two fields:
2040
 *     - title: the page title
2041
 *     - content: the page content
2042 2f65af04 Andreas Kohlbecker
 *   or FALSE
2043
 *
2044 6657531f Andreas Kohlbecker
 */
2045 2f65af04 Andreas Kohlbecker
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $redirect_to_taxon, $highlite_synonym_uuid = NULL) {
2046 6657531f Andreas Kohlbecker
  // Getting the full taxonname object from the server.
2047 d0d068e9 Andreas Kohlbecker
  $taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, array($taxon_name_uuid));
2048 6657531f Andreas Kohlbecker
  if (!$taxon_name) {
2049
    drupal_set_title(t('Taxon name does not exist'), PASS_THROUGH);
2050
    return FALSE;
2051
  }
2052 a7560a18 Andreas Kohlbecker
  cdm_load_tagged_full_title($taxon_name);
2053 6657531f Andreas Kohlbecker
  // Searching for all the taxa connected with the taxon name on the tree
2054
  // in use.
2055 fb308159 Andreas Kohlbecker
  $name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
2056
  $restrictions = array(new Restriction("name.titleCache","EXACT", array($name->titleCache), 'AND'));
2057
  $init_strategy = array(
2058
    "name.titleCache",
2059
    "name.nomenclaturalReference.authorship",
2060
    "name.nomenclaturalReference.inReference.authorship",
2061
    "name.nomenclaturalReference.inReference.inReference.authorship",
2062
    "name.nomenclaturalReference.inReference.inReference.inReference.authorship"
2063
  );
2064 e2617c7e Andreas Kohlbecker
  $taxa = cdm_ws_fetch_all_by_restriction("Taxon", NULL, $restrictions, $init_strategy);
2065 6657531f Andreas Kohlbecker
2066 d0d068e9 Andreas Kohlbecker
  // Removing the name where we came from.
2067 fb308159 Andreas Kohlbecker
  foreach ($taxa as $k => &$taxon) {
2068 6657531f Andreas Kohlbecker
    if ($taxon->uuid == $taxon_to_hide_uuid) {
2069 fb308159 Andreas Kohlbecker
      unset($taxa[$k]);
2070 6657531f Andreas Kohlbecker
    }
2071
  }
2072
  // Show the taxa list or go to the singular taxon.
2073 fb308159 Andreas Kohlbecker
  if (sizeof($taxa) == 1 && $redirect_to_taxon) {
2074 2f65af04 Andreas Kohlbecker
    // redirect to the taxon if there is only one.
2075 fb308159 Andreas Kohlbecker
    $singleTaxon = array_pop($taxa);
2076 6657531f Andreas Kohlbecker
    if ($singleTaxon->class != "Taxon") {
2077
      // It is a Synonym -> look for the accepted.
2078 7635cc7d Andreas Kohlbecker
      $accepted_taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($singleTaxon->uuid), 'classificationFilter=' . get_current_classification_uuid());
2079 e3001c8d Andreas Kohlbecker
      if (!empty($highlite_synonym_uuid)) {
2080 7635cc7d Andreas Kohlbecker
        drupal_goto('cdm_dataportal/taxon/' . $accepted_taxon->uuid . '/synonymy', array('query' => array('highlite' => $highlite_synonym_uuid)));
2081 6657531f Andreas Kohlbecker
      }
2082
      else {
2083 7635cc7d Andreas Kohlbecker
        drupal_goto('cdm_dataportal/taxon/' . $accepted_taxon->uuid . '/synonymy', array('query' => array('highlite' => $singleTaxon->uuid)));
2084 6657531f Andreas Kohlbecker
      }
2085
    }
2086
    else {
2087
      // It is an accepted taxon.
2088 e3001c8d Andreas Kohlbecker
      if (!empty($highlite_synonym_uuid)) {
2089
        drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid . '/synonymy', array('query' => array('highlite' => $highlite_synonym_uuid)));
2090 6657531f Andreas Kohlbecker
      }
2091
      else {
2092
        drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid);
2093
      }
2094
    }
2095
  }
2096 2f65af04 Andreas Kohlbecker
  else {
2097
    // display the name page content
2098 6657531f Andreas Kohlbecker
    $taxon_name_page = new stdClass();
2099 4f225a0f Andreas Kohlbecker
    $taxon_name_page->title = theme('cdm_name_page_title', array('taxon_name' => $taxon_name));
2100 2f65af04 Andreas Kohlbecker
    $content = array();
2101
2102 a7560a18 Andreas Kohlbecker
    RenderHints::pushToRenderStack('name_page');
2103 222784c5 Andreas Kohlbecker
    RenderHints::setFootnoteListKey('name_page');
2104 c040bba0 Andreas Kohlbecker
    $content['taxon_name'] = markup_to_render_array(render_taxon_or_name($taxon_name), null, '<div class="name-page-name">', '</div>');
2105 d64f1d61 Andreas Kohlbecker
2106 a7560a18 Andreas Kohlbecker
2107 2f65af04 Andreas Kohlbecker
    // name relationships
2108 d64f1d61 Andreas Kohlbecker
    $name_relations = cdm_ws_fetch_all(str_replace("$0", $taxon_name->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS));
2109
    if(count($name_relations) > 0){
2110
      $content['name_relationships'] = compose_name_relationships_list($name_relations, $taxon_name->uuid, null);
2111
    }
2112 14076b88 Andreas Kohlbecker
2113 a9a04561 Andreas Kohlbecker
    // type designations
2114 a44d210c Andreas Kohlbecker
    $type_designations_render_array = compose_type_designations($taxon_name->uuid);
2115 ae177dac Andreas Kohlbecker
    $content = array_merge($content, $type_designations_render_array);
2116 efff6ee1 Andreas Kohlbecker
    // registrations
2117
    $registrationDTOs= cdm_ws_fetch_all(CDM_WS_REGISTRATION_DTO,  array('nameUuid' => $taxon_name_uuid));
2118
    if(isset($registrationDTOs) && count($registrationDTOs ) > 0 ){
2119
      $content['registrations'][] = markup_to_render_array('<h2>' . t("Registrations") . '</h2>') ;
2120
      foreach ($registrationDTOs as $regDTO){
2121
        $content['registrations'][] = compose_registration_dto_compact($regDTO);
2122
      }
2123
    }
2124
2125
2126 2f65af04 Andreas Kohlbecker
    // related taxa
2127 c05ac190 Andreas Kohlbecker
    $show_taxa_section = variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT);
2128
    if($show_taxa_section){
2129
      if ($taxa) {
2130
        $content['related_taxa_header'] = markup_to_render_array("<h2>Taxa for this name</h2>");
2131
        $content['related_taxa'] = compose_list_of_taxa($taxa);
2132
      }
2133
      else {
2134
        $content['related_taxa'] = markup_to_render_array('This name is not assigned to a taxon.', null, '<div class="no-taxon-message">', '</div>');
2135
      }
2136 6657531f Andreas Kohlbecker
    }
2137 a7560a18 Andreas Kohlbecker
2138 d0d0a092 Andreas Kohlbecker
    $content['footnotes'] = markup_to_render_array(render_footnotes());
2139 deb2fc24 Andreas Kohlbecker
2140 2f65af04 Andreas Kohlbecker
    $taxon_name_page->content = $content;
2141 a7560a18 Andreas Kohlbecker
    RenderHints::popFromRenderStack();
2142 222784c5 Andreas Kohlbecker
    RenderHints::clearFootnoteListKey();
2143 6657531f Andreas Kohlbecker
    return $taxon_name_page;
2144
  }
2145
}
2146
2147 a9a04561 Andreas Kohlbecker
2148 e0d3e148 Andreas Kohlbecker
/**
2149
 * Returns a registration page as a Drupal node to be rendered by Drupal.
2150
 *
2151 aea2f0ea Andreas Kohlbecker
 * @param string  $registration_identifie
2152 e0d3e148 Andreas Kohlbecker
 *   The persistent identifier of the registration urlencoded.
2153
 * @return mixed
2154
 *   The formatted registration page as node.
2155
 */
2156 aea2f0ea Andreas Kohlbecker
function cdm_dataportal_registration_page_view() {
2157 e0d3e148 Andreas Kohlbecker
2158 aea2f0ea Andreas Kohlbecker
  cdm_check_valid_portal_page("/\/cdm_dataportal\/registration/");
2159
  $registration_identifier = $_REQUEST['identifier'];
2160
  $registration_page = cdm_dataportal_registration_view($registration_identifier);
2161 e0d3e148 Andreas Kohlbecker
  return cdm_node_show_simulate($registration_page);
2162
}
2163
2164 961319fe Andreas Kohlbecker
/**
2165 aea2f0ea Andreas Kohlbecker
 * @param $registration_identifier
2166 961319fe Andreas Kohlbecker
 * @return array
2167
 *   The drupal render array for the registration view.
2168
 */
2169 aea2f0ea Andreas Kohlbecker
function cdm_dataportal_registration_view($registration_identifier) {
2170 e0d3e148 Andreas Kohlbecker
2171 a7560a18 Andreas Kohlbecker
  RenderHints::pushToRenderStack('registration_page');
2172 222784c5 Andreas Kohlbecker
  RenderHints::setFootnoteListKey('registration_page');
2173 a7560a18 Andreas Kohlbecker
2174 6cbefddc Andreas Kohlbecker
  $render_array = array();
2175 bd15166b Andreas Kohlbecker
  $registration_dto = cdm_ws_get(CDM_WS_REGISTRATION_DTO, null, 'identifier=' . $registration_identifier);
2176 e0d3e148 Andreas Kohlbecker
  if($registration_dto){
2177
2178 a7560a18 Andreas Kohlbecker
    drupal_set_title(t('Registration Id:') . ' ' . $registration_identifier, PASS_THROUGH);
2179 26b8a1bc Andreas Kohlbecker
    $render_array = compose_registration_dto_full($registration_dto, true);
2180 e0d3e148 Andreas Kohlbecker
2181
  } else {
2182 bd15166b Andreas Kohlbecker
    $status_text = cdm_ws_get(CDM_WS_REGISTRATION_STATUS, null, 'identifier=' . $registration_identifier);
2183 6c9d417d Andreas Kohlbecker
    if(isset($status_text->String)) {
2184 1e7459da Andreas Kohlbecker
      $status_text = strtolower($status_text->String);
2185
      if($status_text == 'preparation' || $status_text == 'curation'){
2186
        $status_text = 'in ' . $status_text;
2187
      }
2188
      drupal_set_title(t('Registration ' . $status_text), PASS_THROUGH);
2189
      //$status_message;
2190 5fdcad30 Andreas Kohlbecker
      drupal_set_message("A registration with the identifier  " . $registration_identifier . " is " . $status_text, "status");
2191 1e7459da Andreas Kohlbecker
    } else {
2192
      drupal_set_title(t('Registration not found'), PASS_THROUGH);
2193 e42db5b0 Andreas Kohlbecker
      drupal_set_message("A registration with the identifier  " . $registration_identifier . " does not exist", "warning");
2194 1e7459da Andreas Kohlbecker
    }
2195 e0d3e148 Andreas Kohlbecker
  }
2196
2197 5446f047 Andreas Kohlbecker
  $render_array = array(
2198 5fdcad30 Andreas Kohlbecker
    '#prefix' => '<div id="registration">',
2199 5446f047 Andreas Kohlbecker
    'registration' => $render_array,
2200
    '#suffix' => '</div>',
2201
  );
2202
2203 a7560a18 Andreas Kohlbecker
  RenderHints::popFromRenderStack();
2204 222784c5 Andreas Kohlbecker
  RenderHints::clearFootnoteListKey();
2205 a7560a18 Andreas Kohlbecker
2206 e0d3e148 Andreas Kohlbecker
  return $render_array ;
2207
}
2208
2209
2210 6657531f Andreas Kohlbecker
/**
2211 84b13813 Andreas Kohlbecker
 * Creates a page with the advance search form.
2212
 *
2213
 * NOTE: The advance search form allows searching for taxa.
2214 6657531f Andreas Kohlbecker
 */
2215 2f30124c Andreas Kohlbecker
function cdm_dataportal_view_search_advanced() {
2216 6657531f Andreas Kohlbecker
  drupal_set_title(t('Advanced search'), PASS_THROUGH);
2217
  return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
2218
}
2219
2220 a1ce57ce Katja Luther
/**
2221
 * Creates a page with the blast search form.
2222
 *
2223
 * NOTE: The advance search form allows searching for specimen in blast DB.
2224
 */
2225
function cdm_dataportal_view_search_blast() {
2226
    drupal_set_title(t('Blast search'), PASS_THROUGH);
2227
    return drupal_get_form('cdm_dataportal_search_blast_form');
2228
}
2229
2230 6657531f Andreas Kohlbecker
/**
2231 84b13813 Andreas Kohlbecker
 * Creates a page with the search form for searching by taxon descriptions.
2232 6657531f Andreas Kohlbecker
 */
2233
function cdm_dataportal_view_search_taxon_by_description() {
2234 6441ddfb Andreas Kohlbecker
  drupal_set_title(t('Search by factual data'), PASS_THROUGH);
2235 6657531f Andreas Kohlbecker
  return drupal_get_form('cdm_dataportal_search_taxon_by_description_form');
2236
}
2237
2238
/**
2239
 * Executes the search and generates the result list of taxa.
2240
 */
2241
function cdm_dataportal_view_search_results_taxon() {
2242
2243 24797d7f Andreas Kohlbecker
  $taxonPager = cdm_dataportal_search_taxon_execute();
2244 6657531f Andreas Kohlbecker
2245 f19f47fa Andreas Kohlbecker
  $showThumbnails = do_showThumbnails();
2246
2247
  $setSessionUri = url('cdm_api/setvalue/session', array(
2248
      'query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => ''),
2249
  ));
2250
2251
  drupal_add_js('jQuery(document).ready(function() {
2252
2253
      // init
2254
      if(' . $showThumbnails . ' == 1){
2255 1d69a96c Andreas Kohlbecker
          jQuery(\'.media_gallery\').show(20);
2256
      } else {
2257
          jQuery(\'.media_gallery\').hide(20);
2258
      }
2259
2260
      // add change handler
2261
      jQuery(\'#showThumbnails input.showThumbnails\').change(
2262 f19f47fa Andreas Kohlbecker
      function(event){
2263 1d69a96c Andreas Kohlbecker
        var state = 0;
2264
        if(jQuery(this).is(\':checked\')){
2265
          jQuery(\'.media_gallery\').show(20);
2266
          state = 1;
2267
        } else {
2268
          jQuery(\'.media_gallery\').hide(20);
2269
        }
2270
        // store state in session variable
2271
        var uri = \'' . $setSessionUri . '\' + state;
2272
        jQuery.get(uri);
2273
      });
2274 78e178e2 Andreas Kohlbecker
  });',
2275 f19f47fa Andreas Kohlbecker
  array('type' => "inline", 'scope' => JS_DEFAULT));
2276
2277 78e178e2 Andreas Kohlbecker
  drupal_set_title(t('Search results'), PASS_THROUGH);
2278
2279 0a1dc066 Andreas Kohlbecker
  return theme('cdm_search_taxa_results', array(
2280 6657531f Andreas Kohlbecker
    'pager' => $taxonPager,
2281
    'path' => 'cdm_dataportal/search/results/taxon',
2282
    ));
2283
}
2284
2285 a1ce57ce Katja Luther
/**
2286
 * Executes the blast search and generates the result list of specimen.
2287
 */
2288
function cdm_dataportal_view_search_results_specimen() {
2289
2290
    $specimenPager = cdm_dataportal_search_blast_execute();
2291
2292
    return theme('cdm_search_specimen_results', array(
2293
        'pager' => $specimenPager,
2294
        'path' => 'cdm_dataportal/search/results/specimen',
2295
    ));
2296
}
2297
2298
2299 a6ae799b Andreas Kohlbecker
/**
2300
 * Executes the search for registrations and generates the result list..
2301
 */
2302 efbff4b3 Andreas Kohlbecker
function cdm_dataportal_view_search_registrations_results($mode = 'filter') {
2303
2304
  switch($mode ){
2305
    case 'taxongraph':
2306
      $block = block_load('cdm_dataportal', 'registrations_search_taxongraph');
2307
      $registration_pager = cdm_dataportal_search_registrations_taxongraph_execute();
2308
      break;
2309
    case 'filter':
2310
    default:
2311
      $block = block_load('cdm_dataportal', 'registrations_search_filter');
2312
      $registration_pager = cdm_dataportal_search_registrations_filter_execute();
2313
  }
2314
  $block->title = null;
2315 a6ae799b Andreas Kohlbecker
2316
  drupal_set_title(t('Search registrations'), PASS_THROUGH);
2317
2318 efbff4b3 Andreas Kohlbecker
  $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
2319 e2617c7e Andreas Kohlbecker
  $registrations_pager_array = compose_search_results($registration_pager, new RegistrationDTOComposeHandler());
2320 a6ae799b Andreas Kohlbecker
  $render_array = array_merge($render_array, $registrations_pager_array);
2321
2322
  return $render_array;
2323
}
2324
2325 e2617c7e Andreas Kohlbecker
/**
2326
 * Executes the search for registrations and generates the result list..
2327
 */
2328
function cdm_dataportal_view_search_agent() {
2329
2330
  $render_array = [];
2331
  $title = isset($_REQUEST['class']) && $_REQUEST['class'] ? $_REQUEST['class'] : 'Persons & Teams';
2332
  drupal_set_title(t($title), PASS_THROUGH);
2333
  // TODO $block = block_load('cdm_dataportal', 'search_agent_filter');
2334
  // $block->title = null;
2335
  // $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
2336
  $pager = cdm_dataportal_search_agent_execute();
2337
  $pager_render_array = compose_search_results($pager, new AgentComposeHandler());
2338
  $render_array = array_merge($render_array, $pager_render_array);
2339
  return $render_array;
2340
}
2341
2342 a6ae799b Andreas Kohlbecker
2343 94550ff9 Andreas Kohlbecker
/**
2344 bb5a542c Andreas Kohlbecker
 * Provides the standard image which indicated a loading process
2345 94550ff9 Andreas Kohlbecker
 *
2346
 * @return string
2347
 *  The img html tag
2348
 */
2349
function loading_image_html() {
2350
  return '<img class="loading" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal')
2351
    . '/images/loading_circle_grey_16.gif" style="display:none;">';
2352
}
2353
2354 78e178e2 Andreas Kohlbecker
/**
2355
 * Returns the state of the the showThumbnails flag set in the
2356
 * users session ($_SESSION['pageoption']['searchtaxa']['showThumbnails']).
2357
 *
2358 c5ed6357 Andreas Kohlbecker
 * @return boolean
2359 78e178e2 Andreas Kohlbecker
 *    returns 1 if the flag is set
2360
 */
2361
function do_showThumbnails() {
2362
  static $showThumbnails = null;
2363
2364
  if($showThumbnails == null) {
2365 c5ed6357 Andreas Kohlbecker
    $showThumbnails = 0;
2366
    if (!isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) {
2367
      $showThumbnails = 0;
2368
      $search_gallery_settings = variable_get(CDM_DATAPORTAL_SEARCH_GALLERY_NAME, null);
2369
      $showThumbnails = is_array($search_gallery_settings)
2370
        && isset($search_gallery_settings['cdm_dataportal_show_taxon_thumbnails'])
2371
        && (
2372
            $search_gallery_settings['cdm_dataportal_show_taxon_thumbnails'] +
2373
            $search_gallery_settings['cdm_dataportal_show_synonym_thumbnails'] +
2374
            $search_gallery_settings['cdm_dataportal_show_thumbnail_captions'] > 0
2375
            )
2376
         ? 1 : 0;
2377 f19f47fa Andreas Kohlbecker
2378 c5ed6357 Andreas Kohlbecker
       drupal_array_set_nested_value($_SESSION, array('pageoption', 'searchtaxa', 'showThumbnails'), $showThumbnails);
2379
    }
2380 f19f47fa Andreas Kohlbecker
    $showThumbnails = $_SESSION['pageoption']['searchtaxa']['showThumbnails'];
2381
    if (!is_numeric($showThumbnails)) {
2382
      $showThumbnails = 1;
2383
    }
2384 78e178e2 Andreas Kohlbecker
  }
2385
2386
  return $showThumbnails;
2387
}
2388
2389 6657531f Andreas Kohlbecker
2390 a6ae799b Andreas Kohlbecker
2391 6657531f Andreas Kohlbecker
/* ====================== other functions ====================== */
2392
/**
2393
 * Creates a URL to the taxon page specified by the $uuid parameter.
2394
 *
2395
 * The URL will be prepended with a path element to a specific taxon page tab.
2396
 *
2397
 * This tab is either taken from the CDM_DATAPORTAL_DEFAULT_TAXON_TAB which can
2398
 * be set globally in the administrative settings or individually in the user
2399
 * profile. If the CDM_DATAPORTAL_DEFAULT_TAXON_TAB value is set to LAST_VISITED_TAB
2400
 * the last portal will stay on this last tab.
2401
 *
2402
 * A third option is offerered by the $page_tab parameter which allows overwriting this
2403
 * internal mechanism by a specific value.
2404
 *
2405
 * @param string $uuid
2406
 *   The UUID of the taxon.
2407
 * @param string $page_tab
2408
 *   Overwriting the preset mechanism by defining specific value for the
2409
 *   taxon page tab.
2410
 * @return string
2411
 *   The created URL.
2412
 */
2413
function path_to_taxon($uuid, $page_tab = FALSE) {
2414
2415
  $tab = get_default_taxon_tab();
2416
  $values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
2417
2418
  if (!$uuid) {
2419
    return FALSE;
2420
  }
2421
2422
  if ($page_tab) {
2423 fec3fd41 Andreas Kohlbecker
    $url = 'cdm_dataportal/taxon/' . $uuid . '/' . $page_tab;
2424 6657531f Andreas Kohlbecker
  }
2425
  elseif (!$tab || strtolower($tab) == 'general') {
2426 fec3fd41 Andreas Kohlbecker
    $url = 'cdm_dataportal/taxon/' . $uuid;
2427 6657531f Andreas Kohlbecker
  }
2428
  elseif (get_last_taxon_page_tab() &&   $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]) {
2429 fec3fd41 Andreas Kohlbecker
    $url = 'cdm_dataportal/taxon/' . $uuid . '/' . get_last_taxon_page_tab();
2430 6657531f Andreas Kohlbecker
  }
2431
  else {
2432 fec3fd41 Andreas Kohlbecker
    $url = 'cdm_dataportal/taxon/' . $uuid . '/' . strtolower($tab);
2433 6657531f Andreas Kohlbecker
  }
2434 fec3fd41 Andreas Kohlbecker
  return $url;
2435 6657531f Andreas Kohlbecker
}
2436
2437 ea0ae3c7 Patrick Plitzner
function path_to_description($uuid, $descriptive_dataset_uuid = NULL) {
2438 e170a53e Patrick Plitzner
2439
    if (!$uuid) {
2440
        return FALSE;
2441
    }
2442
    else {
2443 9705e44e Patrick Plitzner
      return 'cdm_dataportal/description/' . $uuid
2444
        . (is_uuid($descriptive_dataset_uuid) ? '/' . $descriptive_dataset_uuid : '');
2445 e170a53e Patrick Plitzner
    }
2446
}
2447
2448 9d37c9d9 Patric Plitzner
function path_to_specimen($uuid) {
2449
2450
    if (!$uuid) {
2451
        return FALSE;
2452
    }
2453
    else {
2454 a1ce57ce Katja Luther
        return 'cdm_dataportal/occurrence/' . $uuid;
2455 9d37c9d9 Patric Plitzner
    }
2456
}
2457
2458 6eaec849 Katja Luther
function path_to_specimen_by_accession_number($accession_number) {
2459
2460
    if (!$accession_number) {
2461
        return FALSE;
2462
    }
2463
    else {
2464
        return 'cdm_dataportal/specimen/accession_number/' . $accession_number;
2465
    }
2466
}
2467
2468 30845bda Andreas Kohlbecker
function path_to_named_area($uuid) {
2469
2470
  if (!$uuid) {
2471
    return FALSE;
2472
  }
2473
  else {
2474
    return 'cdm_dataportal/named_area/' . $uuid;
2475
  }
2476
}
2477
2478 6657531f Andreas Kohlbecker
/**
2479 630c7044 Andreas Kohlbecker
 * Creates a URL to show a synonmy in the according taxon page.
2480
 *
2481
 * The URL will point to the synonymy tab of the taxon page of the accepted taxon given as parameter $acceptedUuid.
2482
 * The resulting URI will include query parameters to highlight the synonym, and to optionally display
2483
 * the accepted taxons name in aform like "Foo bar is accepted taxon for Ree doo". The URI will also
2484
 * include the sysnonym uuid as fragment in order to let the browser scroll to the according location
2485
 * in the page
2486
 *
2487
 * @param string $synonymUuid
2488
 *    The uuid of the synonym
2489
 * @param string $acceptedUuid
2490
 *    The uuid of the according accepted taxon
2491
 * @return string
2492
 *    The URL to show a synonmy in the according taxon page
2493 6657531f Andreas Kohlbecker
 */
2494
function uri_to_synonym($synonymUuid, $acceptedUuid) {
2495
  $acceptedPath = path_to_taxon($acceptedUuid, "synonymy");
2496 d071bed7 Andreas Kohlbecker
  return url($acceptedPath, array(
2497
      'query' => array(
2498
        // highlite the synony in the synonymy
2499
        'highlite' => $synonymUuid,
2500
        // the taxon page is refered from a synonym and the synonym can optionally be named in the page title
2501
        // see theme_taxon_page_title()
2502
        'acceptedFor' => $synonymUuid
2503 630c7044 Andreas Kohlbecker
      ),
2504
      'fragment' => $synonymUuid
2505 d071bed7 Andreas Kohlbecker
  ));
2506
2507 6657531f Andreas Kohlbecker
}
2508
2509
/**
2510 e0d3e148 Andreas Kohlbecker
 * Composes the drupal path to the key identified by the uuid.
2511 b8bfa4bd Andreas Kohlbecker
 *
2512
 * @param string $keyType
2513
 *    the key typer corresponds to the specific class of the CDM
2514
 *    IdentificationKey. Possible values are
2515
 *      -PolytomousKey
2516
 *      -MultimediaKey
2517
 *      - ...
2518 e0d3e148 Andreas Kohlbecker
 * @param string $keyUuid
2519 b8bfa4bd Andreas Kohlbecker
 *   The UUID of the key
2520 6657531f Andreas Kohlbecker
 */
2521
function path_to_key($keyType, $keyUuid) {
2522
  if (!$keyUuid || !$keyType) {
2523
    return FALSE;
2524
  }
2525
  $keyType{0} = strtolower($keyType{0});
2526
  return "cdm_dataportal/" . $keyType . "/$keyUuid";
2527
}
2528
2529
/**
2530 e0d3e148 Andreas Kohlbecker
 * Composes the drupal path to the reference identified by the uuid.
2531
 *
2532
 * @param $uuid string String representation of the registration entity uuid.
2533
 *
2534
 * @return string
2535
 *  The drupal path
2536
 *
2537 6657531f Andreas Kohlbecker
 */
2538
function path_to_reference($uuid) {
2539
  if (!$uuid) {
2540
    return FALSE;
2541
  }
2542
  return 'cdm_dataportal/reference/' . $uuid;
2543
}
2544
2545 e0d3e148 Andreas Kohlbecker
/**
2546
 * Composes the drupal path to the reference identified by the uuid.
2547
 *
2548
 * @param string $identifier
2549
 *  The persistent identifier of the registration entity (Registration.identifier).
2550
 * @return string
2551
 *  The drupal path
2552
 */
2553
function path_to_registration($identifier) {
2554
2555 977bba78 Andreas Kohlbecker
  if(variable_get(CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK)){
2556
    return $identifier;
2557
  } else {
2558
    return 'cdm_dataportal/registration/' . urlencode($identifier);
2559
  }
2560 e0d3e148 Andreas Kohlbecker
}
2561
2562 6657531f Andreas Kohlbecker
/**
2563 51b04faf Andreas Kohlbecker
 * Creates the path to a cdm_dataportal taxon name page.
2564
 *
2565 e0d3e148 Andreas Kohlbecker
 * @param string $taxon_name_uuid
2566
 *   The uuid as string of the CDM TaxonName to show a name page for
2567
 * @param string $taxon_to_hide_uuid
2568
 *   The uuid as string of a taxon which should not be displayed in the taxon list
2569 d4ea0dd9 Andreas Kohlbecker
 * @param string $highlited_synonym_uuid
2570 e0d3e148 Andreas Kohlbecker
 *   Optional parameter which takes another taxon uuid, if given the
2571
 *   target taxon pages will show the synonymy tab where the taxon
2572
 *   referenced by the $highlite_synonym_uuid will be highlighted
2573 51b04faf Andreas Kohlbecker
 *   in case it is found on this page.
2574 2f65af04 Andreas Kohlbecker
 * @param $redirect_to_taxon
2575
 *   If true, the name page will redirect to the related taxon if there is a single one
2576
 *   for this name only.
2577 51b04faf Andreas Kohlbecker
 *
2578 e0d3e148 Andreas Kohlbecker
 * @return string
2579
 *  URI path element as string
2580 6657531f Andreas Kohlbecker
 */
2581 2f65af04 Andreas Kohlbecker
function path_to_name($name_uuid, $taxon_to_hide_uuid = NULL, $highlited_synonym_uuid  = NULL, $redirect_to_taxon = false) {
2582 6657531f Andreas Kohlbecker
  $res = FALSE;
2583
  if ($name_uuid) {
2584 2f65af04 Andreas Kohlbecker
    $res = 'cdm_dataportal/name/' . $name_uuid .
2585
    '/' . (is_uuid($taxon_to_hide_uuid) ? $taxon_to_hide_uuid : "null") .
2586
    '/' . (is_uuid($highlited_synonym_uuid) ? $highlited_synonym_uuid : "null") .
2587 14832ae9 Andreas Kohlbecker
    '/' . ($redirect_to_taxon || variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0) ? "redirect_to_taxon" : "");
2588 51b04faf Andreas Kohlbecker
  }
2589 2f65af04 Andreas Kohlbecker
2590 6657531f Andreas Kohlbecker
  return $res;
2591
}
2592
2593
/**
2594 e0d3e148 Andreas Kohlbecker
 * Composes the drupal path to the media entity identified by the uuid.
2595
 *
2596
 * @param string $uuid
2597
 *  The persistent identifier of the entity entity
2598
 * @return string
2599
 *  The drupal path
2600 6657531f Andreas Kohlbecker
 */
2601
function path_to_media($uuid, $representaion_uuid = FALSE, $partId = FALSE) {
2602
  if (!$uuid) {
2603
    return FALSE;
2604
  }
2605
  $out = 'cdm_dataportal/media/' . $uuid;
2606
  if ($representaion_uuid) {
2607
    $out .= '/' . $representaion_uuid;
2608 a867b774 Andreas Kohlbecker
    if (is_numeric($partId)) {
2609 6657531f Andreas Kohlbecker
      $out .= '/' . $partId;
2610
    }
2611
  }
2612
  return $out;
2613
}
2614
2615
/**
2616
 * Compares thisRank with thatRank.
2617
 *
2618
 * Returns a negative integer, zero, or a positive integer
2619
 * as the of thisRank is higher than, equal to, or lower than thatRank.
2620
 * e.g:
2621
 * <ul>
2622
 * <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
2623
 * <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
2624
 * <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
2625
 * </ul>
2626
 * <p>
2627
 * This compare logic of the underlying webservice is the
2628
 * <b>inverse logic</b> of the the one implemented in
2629
 * java.lang.Comparable#compareTo(java.lang.Object)
2630
 *
2631
 * @param $thisRankUuid
2632
 * @param $thatRankUuid
2633
 *
2634
 * @return int
2635
 *   A negative integer, zero, or a positive integer
2636
 *   as the thisRank is lower than, equal to, or higher than thatRank.
2637
 */
2638
function rank_compare($thisRankUuid, $thatRankUuid) {
2639
  $result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
2640
  return $result->Integer;
2641
}
2642
2643
/**
2644 a0e3ae5c Andreas Kohlbecker
 * Creates a short version of a taxonname.
2645 6657531f Andreas Kohlbecker
 *
2646 e90899ac Andreas Kohlbecker
 * The short name is created by using the taggedTitle field of
2647 a0e3ae5c Andreas Kohlbecker
 * TaxonNodeDTO instances.
2648 e90899ac Andreas Kohlbecker
 * If the taggedTitle if empty the fullname will be returned.
2649 6657531f Andreas Kohlbecker
 *
2650 a0e3ae5c Andreas Kohlbecker
 * @param object $taxonNodeDTO
2651
 *   A TaxonNodeDTO object
2652 6657531f Andreas Kohlbecker
 *
2653
 * @return string
2654
 */
2655 a0e3ae5c Andreas Kohlbecker
function cdm_dataportal_shortname_of($taxonNodeDTO) {
2656
2657 6657531f Andreas Kohlbecker
  $nameStr = '';
2658
2659 a0e3ae5c Andreas Kohlbecker
  normalize_tagged_text($taxonNodeDTO->taggedTitle);
2660 6657531f Andreas Kohlbecker
2661
  // Get all tagged text tokens of the scientific name.
2662 a0e3ae5c Andreas Kohlbecker
  foreach ($taxonNodeDTO->taggedTitle as $tagtxt) {
2663 6657531f Andreas Kohlbecker
    if ($tagtxt->type == 'name' || $tagtxt->type == 'rank') {
2664
      $nameStr .= ($nameStr ? ' ' : '') . $tagtxt->text;
2665
    }
2666
  }
2667
  $nameStr = trim($nameStr);
2668
2669
  if ($nameStr) {
2670 54164245 Andreas Kohlbecker
    if(isset($taxonNodeDTO->status->symbol)){
2671
      $nameStr = $taxonNodeDTO->status->symbol . ' ' . $nameStr;
2672 9282ac6e Andreas Kohlbecker
    }
2673 6657531f Andreas Kohlbecker
    // Do not return short names for these.
2674 a0e3ae5c Andreas Kohlbecker
    if ($taxonNodeDTO->unplaced || $taxonNodeDTO->excluded) {
2675 6657531f Andreas Kohlbecker
      return $nameStr;
2676
    }
2677
2678
    /*
2679
    1st capture group (^[a-zA-Z]): First letter of uninomial.
2680
    Second capture group ([\p{L}]+): remaining letters of uninomial ([\p{L} = an UTF-8 letter).
2681
    Third capture group (\s+[^(\x2E]+\s+.+$|\s+[a-zA-Z]+$): letters of name,
2682
    but only matching if no '(' or '.' in second word of name,        ( \x2E = '.')
2683
    OR only one specific epithet \s+[\p{L}\x22\x2D\xD7]+$             (\x22= '"', \x2D='-', \xD7='×' )
2684
    */
2685
    $pattern = '/(^[a-zA-Z])([\p{L}]+)(\s+[^(\x2E]+\s+.+$|\s+[\p{L}\x22\x2D\xD7]+$)/u';
2686
    if (preg_match($pattern, $nameStr, $matches, PREG_OFFSET_CAPTURE)) {
2687
      return $matches[1][0] . "." . $matches[3][0];
2688
    }
2689
    else {
2690
      return $nameStr;
2691
    }
2692
  }
2693
  else {
2694 a0e3ae5c Andreas Kohlbecker
    return $taxonNodeDTO->titleCache;
2695 6657531f Andreas Kohlbecker
  }
2696
}
2697
2698
/**
2699
 * Check if a taxon is accepted by the current taxonomic tree.
2700
 *
2701
 * @param mixed $taxon
2702
 *   The Taxon obkect to check.
2703
 *
2704
 * @return bool
2705
 *   Returns TRUE if $taxon is accepted, FALSE otherwise.
2706
 */
2707
function _cdm_dataportal_acceptedByCurrentView($taxon) {
2708
2709 3049fdcd Andreas Kohlbecker
  $default_classification_uuid = get_current_classification_uuid();
2710 6657531f Andreas Kohlbecker
2711
  if (isset($taxon->taxonNodes)) {
2712 3049fdcd Andreas Kohlbecker
    $taxon_nodes = $taxon->taxonNodes;
2713 6657531f Andreas Kohlbecker
  }
2714
  else {
2715 3049fdcd Andreas Kohlbecker
    $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon->uuid);
2716 6657531f Andreas Kohlbecker
  }
2717
2718 3049fdcd Andreas Kohlbecker
  if ($taxon->class == "Taxon" && isset($taxon_nodes)) {
2719
    foreach ($taxon_nodes as $node) {
2720
      if($node->class == 'TaxonNodeDto' && isset($node->classificationUUID)){
2721
        // case of TaxonNodeDto
2722
        return $node->classificationUUID == $default_classification_uuid;
2723
      } else if($node->class == 'TaxonNode' && isset($node->classification->uuid)) {
2724
         return $node->classification->uuid == $default_classification_uuid;
2725 6657531f Andreas Kohlbecker
      }
2726
    }
2727
  }
2728
  return FALSE;
2729
}
2730
2731
/**
2732 54cfa718 Andreas Kohlbecker
 * Checks is the source has one of the given types.
2733
 *
2734
 * @param object $source
2735
 *   The original source entity
2736
 * @param array $types
2737 b08a856c Andreas Kohlbecker
 *   An array of element of the OriginalSourceType enumeration
2738 54cfa718 Andreas Kohlbecker
 *   If not set the default will be used which is:
2739
 *    - Lineage
2740
 *    - PrimaryMediaSource
2741
 *    - PrimaryTaxonomicSource
2742
 *    - Unknown
2743
 *    - Other
2744
 * @return boolean
2745 6657531f Andreas Kohlbecker
 */
2746 54cfa718 Andreas Kohlbecker
  function _is_original_source_type($source, $types = null) {
2747
    // this is the default
2748
    // maybe this should also be put into the settings
2749
    static $default = array(
2750
      OriginalSourceType::Lineage,
2751
      OriginalSourceType::PrimaryMediaSource,
2752
      OriginalSourceType::PrimaryTaxonomicSource,
2753
      OriginalSourceType::Unknown,
2754
      OriginalSourceType::Other,
2755 fe3a5674 Andreas Kohlbecker
      OriginalSourceType::Aggregation
2756 54cfa718 Andreas Kohlbecker
    );
2757
2758
    if(!$types){
2759
      $types = $default;
2760
    }
2761
    return isset($source->type) && in_array($source->type, $types);
2762
  }
2763 6657531f Andreas Kohlbecker
2764
/**
2765
 * Collects all the media from a list of description elements.
2766
 *
2767
 * @param array $descriptionElements
2768
 *   The description elements from which to collect the media.
2769
 *
2770
 * @return array
2771
 *   The output with all the collected media.
2772
 */
2773
function cdm_dataportal_media_from_descriptionElements($descriptionElements) {
2774
2775
  $outArrayOfMedia = array();
2776
2777
  // Avoiding a warning box in Drupal for Flora Malesiana.
2778
  if (isset($descriptionElements) && is_array($descriptionElements)) {
2779
    foreach ($descriptionElements as $descriptionElement) {
2780
      if (isset($descriptionElement->media) && is_array($descriptionElement->media)) {
2781
        foreach ($descriptionElement->media as $media) {
2782
          if (is_object($media)) {
2783
            $outArrayOfMedia[] = $media;
2784
          }
2785
        }
2786
      }
2787
    }
2788
  }
2789
  return $outArrayOfMedia;
2790
}
2791
2792 178d1ae6 Andreas Kohlbecker
2793
2794 d9763fd3 Andreas Kohlbecker
2795 6657531f Andreas Kohlbecker
/**
2796 d9763fd3 Andreas Kohlbecker
 * Creates a CDM Dynabox.
2797
 *
2798 c1f5d897 Andreas Kohlbecker
 * @param string $dynabox_id
2799 d9763fd3 Andreas Kohlbecker
 *   a uninque name for tha dynabox, using a cdm entity uuid as id is good practice.
2800 6657531f Andreas Kohlbecker
 * @param string $label
2801
 *   The clickable text to show.
2802
 * @param string $content_url
2803
 *   The cdm REST service request url wich will deliver the content to be shown
2804
 *   once the dynabox toggles open.
2805
 * @param string $theme
2806 1ce9afb7 Patric Plitzner
 *   The theme to be used for rendering the cdm REST service response with is
2807 6657531f Andreas Kohlbecker
 *   returned from the $content_url.
2808
 * @param string $link_alt_text
2809
 *   The value for the alt attribute of the dynabox link.
2810
 * @param array $enclosingtags
2811
 *   An array with two elements: $enclosingtags[0] will be used for the dynabox
2812
 *   element itself, $enclosingtags[1] is the tag to be used for the
2813 c1f5d897 Andreas Kohlbecker
 *   dynabox_content (optional)
2814 d9763fd3 Andreas Kohlbecker
 * @param array $attributes
2815
 * @param $content_element_selector
2816
 *   Optional jQuery selector which can be used to reference a dom element which should
2817
 *   be used as container for the content to be shown. The dynabox-<dynabox id>-content
2818
 *  element will be placed in this container.
2819
 *
2820 c1f5d897 Andreas Kohlbecker
 * @param string $open_callback
2821 1ce9afb7 Patric Plitzner
 *   optional javascript call back function to be triggered after toggling the box to
2822 c1f5d897 Andreas Kohlbecker
 *   the open state.
2823
 * @param string $close_callback
2824 1ce9afb7 Patric Plitzner
 *   optional javascript call back function to be triggered after toggling the box to
2825 c1f5d897 Andreas Kohlbecker
 *   the closed state.
2826 d9763fd3 Andreas Kohlbecker
 * @return string Returns HTML for a dynabox.
2827
 * Returns HTML for a dynabox.
2828 6657531f Andreas Kohlbecker
 */
2829 d9763fd3 Andreas Kohlbecker
function cdm_dynabox($dynabox_id, $label, $content_url, $theme, $link_alt_text,
2830
                     $enclosingtags = array('li', 'ul'), $attributes = array(),
2831
                     $content_element_selector = null,
2832
                     $open_callback = 'function(){}', $close_callback = 'function(){}' ) {
2833 6657531f Andreas Kohlbecker
  $out = '';
2834 c1f5d897 Andreas Kohlbecker
2835
  // check for plain class attribute string
2836
  $dynabox_id = preg_replace('/[^a-zA-Z0-9\-]/', '', $dynabox_id);
2837
2838 9c9d11f7 Andreas Kohlbecker
  if(!array_key_exists('class', $attributes)) {
2839 bcc70074 Andreas Kohlbecker
    $attributes['class'] = ["dynabox"];
2840
  } else {
2841
    $attributes['class'] = array_merge($attributes['class'], ["dynabox"]);
2842 9c9d11f7 Andreas Kohlbecker
  }
2843 d9763fd3 Andreas Kohlbecker
  $attributes['id'][] = 'dynabox-' . $dynabox_id;
2844 9c9d11f7 Andreas Kohlbecker
  $dynabox_attributes = drupal_attributes($attributes);
2845
2846
2847 b386ae48 Andreas Kohlbecker
  _add_js_domEvent(); // requires domEvent.js
2848 6657531f Andreas Kohlbecker
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cdm_dynabox.js');
2849 c1f5d897 Andreas Kohlbecker
  drupal_add_js("
2850 94bb8db6 Andreas Kohlbecker
  jQuery(document).ready(
2851
      function() {
2852
        dynabox('". $dynabox_id ."',
2853
          {
2854
            open_callback: " . $open_callback .",
2855 d9763fd3 Andreas Kohlbecker
            close_callback: " . $close_callback .
2856
            ($content_element_selector ? ",\n content_container_selector: '" . $content_element_selector . "'" : "") . "
2857 94bb8db6 Andreas Kohlbecker
          }
2858
        );
2859
      }
2860
   );",
2861
   array(
2862
    'type'=>'inline',
2863
    'scope'=>'footer'
2864
    )
2865
  );
2866 6657531f Andreas Kohlbecker
2867 9c9d11f7 Andreas Kohlbecker
2868 6657531f Andreas Kohlbecker
  $cdm_proxy_url = url('cdm_api/proxy/' . urlencode($content_url) . "/$theme");
2869 9c9d11f7 Andreas Kohlbecker
  $out .= '<!-- dynabox for ' . $content_url . ' -->';
2870 7cc085da Andreas Kohlbecker
  $out .= '<' . $enclosingtags[0] . ' ' .  $dynabox_attributes. '><a href="' . $cdm_proxy_url . '" class="label" alt="' . t('@link-alt-text', array('@link-alt-text' => $link_alt_text)) . '">' . $label . '</a>';
2871 d9763fd3 Andreas Kohlbecker
  $out .= '  <' . $enclosingtags[1] . ' id="dynabox-' . $dynabox_id . '-content">';
2872
  $out .= '    <' . $enclosingtags[0] . ' class="dynabox-content-inner">' . loading_image_html() . '</' . $enclosingtags[0] . '>';
2873
  $out .= '    </' . $enclosingtags[1] . '>';
2874
  $out .= '  </' . $enclosingtags[0] . '>';
2875 9c9d11f7 Andreas Kohlbecker
  $out .= '<!-- dynabox end -->';
2876 6657531f Andreas Kohlbecker
  return $out;
2877
}
2878
2879
/**
2880
 * Checks whether a feature has any description elements.
2881
 *
2882
 * @param mixed $featureNode
2883
 *   A feature node as produced by the function _mergeFeatureTreeDescriptions().
2884
 *
2885
 * @see _mergeFeatureTreeDescriptions()
2886
 *
2887
 * @return bool
2888
 *   Returns TRUE if the given $featureNode or any of its subordinate nodes
2889
 *   contains at least one non empty TextData or at least one DescriptionElement
2890
 *   of an other type. A TextData element holding a multilanguageText or a
2891
 *   source reference is considered to be not empty.
2892 159cd9bb Andreas Kohlbecker
 *
2893
 * @TODO this function may have become obsolete by the new method of detecting empty blocks,
2894 1b756c5f Andreas Kohlbecker
 *       see $block_content_is_not_empty in make_feature_block_list() and
2895 0ebb6efc Andreas Kohlbecker
 *       $feature_block_has_content in compose_feature_block_items_generic
2896 6657531f Andreas Kohlbecker
 */
2897 f19f47fa Andreas Kohlbecker
function has_feature_node_description_elements($featureNode) {
2898 6657531f Andreas Kohlbecker
2899
  if (isset($featureNode->descriptionElements) && is_array($featureNode->descriptionElements) && count($featureNode->descriptionElements) > 0) {
2900 092744e1 Andreas Kohlbecker
    if(!isset($featureNode->descriptionElements['#type'])){ // #type is used to identify e.g. DTO elements: '#type' => 'DTO'
2901
      foreach ($featureNode->descriptionElements as $descriptionElement) {
2902 159cd9bb Andreas Kohlbecker
        if ($descriptionElement->class != "TextData" || isset($descriptionElement->multilanguageText_L10n->text)
2903
          && $descriptionElement->multilanguageText_L10n->text != ''
2904
          || isset($descriptionElement->sources[0])
2905
          || isset($descriptionElement->media[0]) ) {
2906 092744e1 Andreas Kohlbecker
          return TRUE;
2907
        }
2908 6657531f Andreas Kohlbecker
      }
2909
    }
2910
  }
2911 092744e1 Andreas Kohlbecker
  else if (isset($featureNode->childNodes) && is_array($featureNode->childNodes)) {
2912 fae36a2a Andreas Kohlbecker
    foreach ($featureNode->childNodes as $child) {
2913 f19f47fa Andreas Kohlbecker
      if (has_feature_node_description_elements($child)) {
2914 6657531f Andreas Kohlbecker
        return TRUE;
2915
      }
2916
    }
2917
  }
2918
  return FALSE;
2919
}
2920 f26245c8 Andreas Kohlbecker
2921
/**
2922
 * Checks if the current page is a valid taxon portal page and responds with HTTP status 404 (not found) otherwise
2923
 *
2924
 * @param $chapter
2925
 *   The taxon page chapter or part
2926
 */
2927
function cdm_check_valid_taxon_page($chapter){
2928
  static $taxon_tabs = null;
2929
2930
  cdm_check_valid_portal_page();
2931
2932
  if($taxon_tabs == null){
2933
    $taxon_tabs = array('all', 'description');
2934
    foreach(get_taxon_tabs_list() as $tab){
2935
      $taxon_tabs[] = strtolower($tab);
2936
    }
2937
  }
2938
2939
  if(!in_array($chapter, $taxon_tabs)){
2940
    // oops this is not a valid chapter name
2941 b4a5c2be Andreas Kohlbecker
    http_response_code(404); // 404 = Not Found
2942 f26245c8 Andreas Kohlbecker
  }
2943
2944
}
2945
2946 b654a866 Andreas Kohlbecker
function check_js_devel_mode_disabled() {
2947
  if(variable_get('cdm_js_devel_mode', FALSE)) {
2948
    drupal_set_message(t('The !url1 is enabled.
2949
        WARNING: this is a performance penalty and must be turned off on production websites.', array(
2950
      '!url1' => l('java-script development mode', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-cdm-js-devel-mode'))
2951
    )),
2952
      'warning'
2953
    );
2954
  }
2955
}
2956
2957 f26245c8 Andreas Kohlbecker
/**
2958 e0d3e148 Andreas Kohlbecker
 * Checks if the current page is a valid portal page and responds with HTTP status 404 (not found) otherwise.
2959
 * The test applied by default it a check for the query parameter 'q' ending with a file suffix like '*.*'
2960 f26245c8 Andreas Kohlbecker
 *
2961 e0d3e148 Andreas Kohlbecker
 * @param $preg_pattern
2962
 *   Optional regular expression pattern to be used in preg_match().
2963 f26245c8 Andreas Kohlbecker
 */
2964 e0d3e148 Andreas Kohlbecker
function cdm_check_valid_portal_page($preg_pattern = null){
2965 595de9f0 Andreas Kohlbecker
  $ends_with_file_suffix_pattern = '/\/[^\.\/]*[\.][^\.\/]*$/';
2966 e0d3e148 Andreas Kohlbecker
  if($preg_pattern === null){
2967
    $preg_pattern = $ends_with_file_suffix_pattern;
2968
  }
2969
  if(preg_match($preg_pattern, $_GET['q'])){
2970 f26245c8 Andreas Kohlbecker
    // oops this urls ends with a file_suffix and thus does not refer to a portal page
2971 b4a5c2be Andreas Kohlbecker
    http_response_code(404); // 404 = Not Found
2972 595de9f0 Andreas Kohlbecker
    exit('HTTP 404');
2973 f26245c8 Andreas Kohlbecker
  }
2974 b654a866 Andreas Kohlbecker
  check_js_devel_mode_disabled();
2975 f26245c8 Andreas Kohlbecker
}
2976 b2b9e057 Andreas Kohlbecker
2977
/**
2978
 * Generates the diff of the texts and presents it in a HTML diff viewer.
2979
 *
2980
 * @param $text_a
2981
 * @param $text_b
2982
 * @return string
2983
 */
2984
function diff_viewer($text_a, $text_b) {
2985
2986
  static $diff_viewer_count = 0;
2987
2988
  $element_id = 'part_definitions_diff_' . $diff_viewer_count++;
2989
2990
  // http://code.stephenmorley.org/php/diff-implementation/
2991
  module_load_include('php', 'cdm_dataportal', 'lib/class.Diff');
2992
  drupal_add_css(drupal_get_path('module',
2993
      'cdm_dataportal') . '/css/diff.css');
2994 087bb473 Andreas Kohlbecker
  _add_jquery_ui();
2995 b2b9e057 Andreas Kohlbecker
  drupal_add_js(
2996
    'jQuery(document).ready( function(){
2997
        jQuery(\'#' . $element_id . '\').accordion({
2998
        collapsible: true,
2999
        active: false,
3000
        fillSpace: true,
3001
        }).children(\'div\').css({ \'height\': \'auto\' });
3002
        jQuery(\'#' . $element_id . ' table.diff\').prepend(\'<thead><tr><th>Default</th><th>User defined<th></th><tr></thead>\');
3003
     });'
3004
    , array(
3005
    'type' => 'inline',
3006
    'scope' => 'footer'
3007
  ));
3008
3009
  $diff = Diff::compare($text_a,
3010
    $text_b);
3011
  $diff_viewer_markup = '<div id="' . $element_id . '"><h3>View Diff</h3><div>'
3012
    . Diff::toTable($diff, '', '')
3013
    . '</div></div>';
3014
  return $diff_viewer_markup;
3015
}
3016