Project

General

Profile

« Previous | Next » 

Revision 0a311d85

Added by Andreas Kohlbecker almost 3 years ago

ref #9659 all ext_links templates with cdm_tokens, glue removed

View differences:

modules/cdm_dataportal/ext_links/ext_links.module
302 302
 * Implements hook_block_view().
303 303
 */
304 304
function ext_links_block_view($delta) {
305
  // TODO Rename block deltas (e.g. '0') to readable strings.
306 305
  switch ($delta) {
307 306
    case '0':
308 307
      $block['subject'] = 'External links';
309

  
310
      $uuid = get_current_taxon_uuid();
311
      if ($uuid) {
312
        $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
313

  
314
        // $taxon->titleCache;
315
        // var_export()
316
        if (!empty($taxon)) {
317
          drupal_add_js(drupal_get_path('module', 'ext_links') . '/ext_links.js');
318
          $speciesName = ext_link_species_name($taxon);
319

  
320
          $genus = $taxon->name->taggedName[0]->text;
321
          $species = null;
322
          if(isset($taxon->name->taggedName[1])){
323
            $species = $taxon->name->taggedName[1]->text;
324
          }
325
          $block_content = '';
326
          $grouped = variable_get('ext_links_appearance_grouped', 1);
327
          if ($grouped) {
328
            $block['content'] = theme('ext_links_list_grouped', array('speciesName' => $speciesName, 'genus' => $genus, 'species' => $species));
329
          }
330
          else {
331
            $block['content'] = theme('ext_links_list_plain', array('speciesName' => $speciesName, 'genus' => $genus, 'species' => $species ));
332
          }
333

  
334
          // if(variable_get('ext_links_gbif_check', TRUE)) {
335
          // $block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_gbif_link', $ext_links_default[gbif][link_default_value]).str_replace('"','%22',$speciesName[genus]).variable_get('ext_links_gbif_concat', ' ').str_replace('"','%22',$speciesName[species]).'\')">'.variable_get('ext_links_gbif_text', $ext_links_default[gbif][text_default_value]).'</a><br />';
336
          /*
337
           $block_content .=
338
           /* TODO
339
           Please manually fix the parameters on the l() or url() function on the next line.
340
           Typically, this was not changed because of a function call inside an array call like
341
           array('title' => t('View user profile.')).
342
           l(variable_get('ext_links_gbif_text', $ext_links_default[gbif][text_default_value]),
343
           'JavaScript:popupExternalLinks('.variable_get('ext_links_gbif_link', $ext_links_default[gbif][link_default_value]).$speciesName[genus].variable_get('ext_links_gbif_concat', ' ').$speciesName[species],
344
           array(), null, null, true);
345
           */
346
          /*}
347
           if(variable_get('ext_links_biocase_check', 1)) {
348
           $block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_biocase_link', $ext_links_default[biocase][link_default_value]).str_replace('"','%22',$speciesName[genus]).variable_get('ext_links_biocase_concat', ' ').str_replace('"','%22',$speciesName[species]).'\')">'.variable_get('ext_links_biocase_text', $ext_links_default[biocase][text_default_value]).'</a><br />';
349
           }
350
           if(variable_get('ext_links_nybg_check', 1)) {
351
           $block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_nybg_link', $ext_links_default[nybg][link_default_value]).str_replace('"','%22',$speciesName[genus]).variable_get('ext_links_nybg_concat', ' ').str_replace('"','%22',$speciesName[species]).'\')">'.variable_get('ext_links_nybg_text', $ext_links_default[nybg][text_default_value]).'</a><br />';
352
           }
353
           if(variable_get('ext_links_tropicos_check', 1)) {
354
           $block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_tropicos_link', $ext_links_default[tropicos][link_default_value]).str_replace('"','%22',$speciesName[genus]).variable_get('ext_links_tropicos_concat', ' ').str_replace('"','%22',$speciesName[species]).'\')">'.variable_get('ext_links_tropicos_text', $ext_links_default[tropicos][text_default_value]).'</a><br />';
355
           }
356
           if(variable_get('ext_links_ncbi_check', 1)) {
357
           $block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_ncbi_link', $ext_links_default[ncbi][link_default_value]).str_replace('"','%22',$speciesName[genus]).variable_get('ext_links_ncbi_concat', ' ').str_replace('"','%22',$speciesName[species]).'\')">'.variable_get('ext_links_ncbi_text', $ext_links_default[ncbi][text_default_value]).'</a><br />';
358
           }
359
           if(variable_get('ext_links_google_check', 1)) {
360
           $block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_google_link', $ext_links_default[google][link_default_value]).str_replace('"','%22',$speciesName[genus]).variable_get('ext_links_google_concat', ' ').str_replace('"','%22',$speciesName[species]).'\')">'.variable_get('ext_links_google_text', $ext_links_default[google][text_default_value]).'</a><br />';
361
           }
362
           if(variable_get('ext_links_flickr_check', 1)) {
363
           $block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_flickr_link', $ext_links_default[flickr][link_default_value]).str_replace('"','%22',$speciesName[genus]).variable_get('ext_links_flickr_concat', ' ').str_replace('"','%22',$speciesName[species]).'\')">'.variable_get('ext_links_flickr_text', $ext_links_default[flickr][text_default_value]).'</a><br />';
364
           }
365
           if(variable_get('ext_links_scholar_check', 1)) {
366
           $block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_scholar_link', $ext_links_default[scholar][link_default_value]).str_replace('"','%22',$speciesName[genus]).variable_get('ext_links_scholar_concat', ' ').str_replace('"','%22',$speciesName[species]).'\')">'.variable_get('ext_links_scholar_text', $ext_links_default[scholar][text_default_value]).'</a><br />';
367
           }
368
           if(variable_get('ext_links_bhl_check', 1)) {
369
           $block_content .= '<a href="JavaScript:popupExternalLinks(\''.variable_get('ext_links_bhl_link', $ext_links_default[bhl][link_default_value]).str_replace('"','%22',$speciesName[genus]).variable_get('ext_links_bhl_concat', ' ').str_replace('"','%22',$speciesName[species]).'\')">'.variable_get('ext_links_bhl_text', $ext_links_default[bhl][text_default_value]).'</a><br />';
370
           }
371

  
372
           $block['content'] = $block_content;
373
           $block['content'] = theme('ext_links_list_plain');
374

  
375
           }
376

  
377
           }*/
378
          // if taxon
379
        }
308
      drupal_add_js(drupal_get_path('module', 'ext_links') . '/ext_links.js');
309
      if (variable_get('ext_links_appearance_grouped', 1)) {
310
        $block['content'] = render_ext_links_list_grouped();
311
      } else {
312
        $block['content'] = render_ext_links_list_plain();
380 313
      }
381
      // If path.
314
    }
382 315
      return $block;
383
  } /* switch */
384

  
385 316
}
386 317

  
387 318
/**
388 319
 * Applies the name tokens to the external link templates.
389 320
 *
390
 * @param $ext_link
391
 * @param $species_name
321
 * @param $ext_link_template
392 322
 *
393 323
 * @return array
394 324
 *  Array with the keys:
395 325
 *     - title: the title of the link
396 326
 *     - url: the url of the link
397 327
 */
398
function make_ext_link($ext_link, $species_name) {
399
  switch ($ext_link->id) {
400
    case 'nybg':
401
      if ($species_name['genus'] != NULL) {
402
        $query = 'DetFiledAsGenusLocal+%3D+\%27' . $species_name['genus'] . '\%27';
403
      }
404
      if ($species_name['species'] != NULL) {
405
        $query .= $ext_link->glue . 'DetFiledAsSpeciesLocal+%3D+\%27' . $species_name['species'] . '\%27';
406
      }
407
      break;
408
    case 'arkive':
409
      $postURL = '&output=xml_no_dtd&client=arkive-images&site=arkive-images&ie=utf8&oe=utf8&num=20&proxystylesheet=tng-search&filter=0&getfields=*';
410
      $query = str_replace('"', '%22', $species_name['genus']) . variable_get('ext_links_arkive_concat', '+') . str_replace('"', '%22', $species_name['species']) . $postURL;
411
      break;
412
    case 'herbcat':
413
      $postURL = '&x=11&y=13&homePageSearchOption=scientific_name&nameOfSearchPage=home_page';
414
      $query = str_replace('"', '%22', $species_name['genus']) . variable_get('ext_links_herbcat_concat', '+') . str_replace('"', '%22', $species_name['species']) . $postURL;
415
      break;
416
    case 'iucn':
417
    case 'wcsp':
418
      // apparently no search api, thus plain link without genus and species
419
      $query = '';
420
      break;
421
    case 'ipni':
422
      $query = 'find_genus=' . $species_name['genus'] . '&find_species=' . $species_name['species'];
423
      break;
424
    default:
425
      $query = rawurlencode($species_name['genus']) . $ext_link->glue . rawurlencode($species_name['species']);
426
  }
427
  $ext_link_array = [
428
    'title' => $ext_link->title,
429
    'url' => token_replace($ext_link->link) /* . $query */
430
  ];
328
function ext_links_apply_template($ext_link_template) {
329
      $ext_link_array = [
330
        'title' => $ext_link_template->title,
331
        'url' => token_replace($ext_link_template->link, [],
332
          [
333
            'callback' => 'ext_links_token_replacement_urlencode',
334
            'clear' => true
335
          ])
336
      ];
431 337
  return $ext_link_array;
432 338
}
433 339

  
434 340
/**
435
 * @todo Please document this function.
436
 * @see http://drupal.org/node/1354
341
 * Callback function to be passed to token_replace() to urlencode the token replacements.
342
 *
343
 * @param array $replacements
344
 *   The replacements for the tokens
345
 * @param array $data
346
 *    Unused, see token_replace()
347
 * @param array $options
348
 *    Unused, see token_replace()
349
 *
350
 * @see token_replace()
437 351
 */
438
function theme_ext_links_list_grouped($variables) {
439

  
440
  $species_name = $variables['speciesName'];
441
  if(!isset($species_name['genus'])) {
442
    $species_name['genus'] = '';
443
  }
444
  if(!isset($species_name['species'])) {
445
    $species_name['species'] = '';
352
function ext_links_token_replacement_urlencode(array &$replacements, array $data = [], array $options = []){
353
  foreach ($replacements as &$repl){
354
    $repl = rawurlencode($repl);
446 355
  }
447 356

  
357
}
358

  
359
/**
360
 * Creates html markup of ext_links grouped by category
361
 */
362
function render_ext_links_list_grouped() {
363

  
448 364
  $ext_links = ext_links_templates(true);
449 365

  
450 366
  $ext_links_by_category = [];
......
453 369
    if(!array_key_exists($ext_link->category, $ext_links_by_category)){
454 370
      $ext_links_by_category[$ext_link->category] = [];
455 371
    }
456
    $ext_link_render_array = make_ext_link($ext_link, $species_name);
372
    $ext_link_render_array = ext_links_apply_template($ext_link);
457 373
    $ext_links_by_category[$ext_link->category][] = $ext_link_render_array;
458 374
  }
459 375

  
......
470 386
}
471 387

  
472 388
/**
473
 * @todo Please document this function.
474
 * @see http://drupal.org/node/1354
389
 * Creates html markup of ext_links as plain list
475 390
 */
476
function theme_ext_links_list_plain($variables) {
477
  $speciesName = $variables['speciesName'];
478
  if (!isset($speciesName['genus'])) {
479
    $speciesName['genus'] = '';
480
  }
481
  if (!isset($speciesName['species'])) {
482
    $speciesName['species'] = '';
483
  }
391
function render_ext_links_list_plain() {
484 392

  
485 393
  $ext_links_templates = ext_links_templates(true);
486 394
  $block_content = '';
487 395
  foreach ($ext_links_templates as $ext_link) {
488
    $ext_link = make_ext_link($ext_link, $speciesName);
396
    $ext_link = ext_links_apply_template($ext_link);
489 397
    $block_content .= l($ext_link['title'], 'JavaScript:popupExternalLinks(\'' . $ext_link['url'] . '\')', ['external' => TRUE]) .'<br />';
490 398
  }
491 399
  return $block_content;
492 400
}
493 401

  
494 402
/**
495
 * @todo Please document this function.
496
 * @see http://drupal.org/node/1354
403
 * Implements hook_theme()
497 404
 */
498 405
function ext_links_theme() {
499 406
  return array(
500
    'ext_links_list_grouped' => array('variables' => array(
501
      'speciesName' => NULL,
502
      'genus' => NULL,
503
      'species' => NULL,
504
      )),
505
    'ext_links_list_plain' => array('variables' => array(
506
      'speciesName' => NULL,
507
      'genus' => NULL,
508
      'species' => NULL,
509
      )),
510 407
    // theme_ext_links_admin_overview
511 408
    'ext_links_admin_overview' => array(
512 409
      'render element' => 'form',
513 410
      'file' => 'ext_links.admin.inc',
514
    ),
515
//    'ext_links_link_template_filter_order' => array(
516
//      'render element' => 'element',
517
//      'file' => 'ext_links.admin.inc',
518
//    ),
411
    )
519 412
  );
520 413
}
521 414

  
......
528 421
function ext_links_template_defaults() {
529 422
  $ext_links_default["gbif"] = array(
530 423
    'id' => "gbif",
531
    'link' => 'http://www.gbif.org/species/search?q=',
424
    'link' => 'http://www.gbif.org/species/search?q=[cdm:taxon_name]',
532 425
    'title' => 'Search GBIF...',
533
    'glue' => ' ',
534 426
    'weight' => 0,
535 427
    'status' => 1,
536 428
    'category' => 'Specimens/Occurrences',
537 429
  );
538 430
  $ext_links_default["biocase"] = array(
539 431
    'id' => "biocase",
540
    'link' => 'http://search.biocase.org/edit/search/units/simpleSearch/query1?unitName=',
432
    'link' => 'http://search.biocase.org/edit/search/units/simpleSearch/query1?unitName=[cdm:taxon_name]',
541 433
    'title' => 'Search BioCASE...',
542
    'glue' => ' ',
543 434
    'weight' => 0,
544 435
    'status' => 1,
545 436
    'category' => 'Specimens/Occurrences',
546 437
  );
547 438
  $ext_links_default["nybg"] = array(
548 439
    'id' => "nybg",
549
    'link' => 'http://sweetgum.nybg.org/science/vh/specimen_list.php?SummaryData=',
440
    'link' => 'http://sweetgum.nybg.org/science/vh/specimen_list.php?SummaryData=[cdm:taxon_name]',
550 441
    'title' => 'Search NYBG...',
551
    'glue' => '+AND+',
552 442
    'weight' => 0,
553 443
    'status' => 1,
554 444
    'category' => 'Specimens/Occurrences',
555 445
  );
556 446
  $ext_links_default["tropicos"] = array(
557 447
    'id' => "tropicos",
558
    'link' => 'http://www.tropicos.org/NameSearch.aspx?name=',
448
    'link' => 'http://www.tropicos.org/NameSearch.aspx?name=[cdm:taxon_name]',
559 449
    'title' => 'Search Tropicos...',
560
    'glue' => '+',
561 450
    'weight' => 0,
562 451
    'status' => 1,
563 452
    'category' => 'Specimens/Occurrences',
564 453
  );
565 454
  $ext_links_default["ncbi"] = array(
566 455
    'id' => "ncbi",
567
    'link' => 'http://www.ncbi.nlm.nih.gov/gquery/gquery.fcgi?term=',
456
    'link' => 'http://www.ncbi.nlm.nih.gov/gquery/gquery.fcgi?term=%22[cdm:taxon_name]%22',
568 457
    'title' => 'Search NCBI...',
569
    'glue' => '+AND+',
570 458
    'weight' => 0,
571 459
    'status' => 1,
572 460
    'category' => 'Molecular Resources',
573 461
  );
574 462
  $ext_links_default["google"] = array(
575 463
    'id' => "google",
576
    'link' => 'http://images.google.com/images?q=',
464
    'link' => 'http://images.google.com/images?q=%22[cdm:taxon_name]%22',
577 465
    'title' => 'Search Google Images...',
578
    'glue' => '+',
579 466
    'weight' => 0,
580 467
    'status' => 1,
581 468
    'category' => 'Images',
582 469
  );
583 470
  $ext_links_default["flickr"] = array(
584 471
    'id' => "flickr",
585
    'link' => 'http://www.flickr.com/search/?w=all&q=',
472
    'link' => 'http://www.flickr.com/search/?w=all&q=%22[cdm:taxon_name]%22',
586 473
    'title' => 'Search flickr...',
587
    'glue' => '+',
588 474
    'weight' => 0,
589 475
    'status' => 1,
590 476
    'category' => 'Images',
591 477
  );
592 478
  $ext_links_default["scholar"] = array(
593 479
    'id' => "scholar",
594
    'link' => 'http://scholar.google.de/scholar?hl=de&btnG=Suche&lr=&as_ylo=&as_vis=0&q=',
480
    'link' => 'http://scholar.google.de/scholar?q=%22[cdm:taxon_name]%22',
595 481
    'title' => 'Search Google scholar...',
596
    'glue' => '+',
597 482
    'weight' => 0,
598 483
    'status' => 1,
599 484
    'category' => 'Literature',
600 485
  );
601 486
  $ext_links_default["bhl"] = array(
602 487
    'id' => "bhl",
603
    'link' => 'http://www.biodiversitylibrary.org/Search.aspx?searchCat=&searchTerm=',
488
    // BHL does not normalize rank terms, ssp., sub., subsp. are not unified, therefore we skip that part:
489
    'link' => 'https://www.biodiversitylibrary.org/search?searchTerm=[cdm:taxon_name:genus_or_uninomial]+[cdm:taxon_name:epithet]+[cdm:taxon_name:infraspecific_epithet]&stype=F#/names',
604 490
    'title' => 'Search BHL...',
605
    'glue' => ' ',
606 491
    'weight' => 0,
607 492
    'status' => 1,
608 493
    'category' => 'Literature',
609 494
  );
610 495
  $ext_links_default["arkive"] = array(
496
    // domain no longer exists! Remove extlink?
611 497
    'id' => "arkive",
612
    'link' => 'http://www.arkive.org/search.html?q=',
498
    'link' => 'http://www.arkive.org/search.html?q=[cdm:taxon_name]&output=xml_no_dtd&client=arkive-images&site=arkive-images&ie=utf8&oe=utf8&num=20&proxystylesheet=tng-search&filter=0&getfields=*',
613 499
    'title' => 'Search ARKive...',
614
    'glue' => '+',
615 500
    'weight' => 0,
616 501
    'status' => 0,
617 502
    'category' => 'Images',
618 503
  );
619 504
  $ext_links_default["herbcat"] = array(
620 505
    'id' => "herbcat",
621
    'link' => 'http://apps.kew.org/herbcat/getHomePageResults.do?homePageSearchText=',
506
    'link' => 'http://apps.kew.org/herbcat/getSearchPageResults.do?typeSpecimen=false&imageSpecimen=false&currentName=false&typeOfCollection=all_collection&&genus=[cdm:taxon_name:genus_or_uninomial]&&species=[cdm:taxon_name:epithet]&infraspecificName=[cdm:taxon_name:infraspecific_epithet]',
622 507
    'title' => 'Search Kew Herbarium Catalogue...',
623
    'glue' => '+',
624 508
    'weight' => 0,
625 509
    'status' => 1,
626 510
    'category' => 'Specimens/Occurrences',
627 511
  );
628 512
  $ext_links_default["iucn"] = array(
629 513
    'id' => "iucn",
630
    'link' => 'http://www.iucnredlist.org/',
631
    'title' => 'Go to IUCN Red List...',
632
    'glue' => ' ',
514
    'link' => 'https://www.iucnredlist.org/search?query=[cdm:taxon_name]',
515
    'title' => 'Search IUCN Red List...',
633 516
    'weight' => 0,
634 517
    'status' => 1,
635 518
    'category' => 'Conservation',
636 519
  );
637 520
  $ext_links_default["ipni"] = array(
638 521
    'id' => "ipni",
639
    'link' => 'http://www.ipni.org/ipni/advPlantNameSearch.do?',
522
    'link' => 'https://www.ipni.org/?q=[cdm:taxon_name]',
640 523
    'title' => 'Search IPNI...',
641
    'glue' => '&',
642 524
    'weight' => 0,
643 525
    'status' => 1,
644 526
    'category' => 'Classification',
645 527
  );
646 528
  $ext_links_default["wcsp"] = array(
647 529
    'id' => "wcsp",
648
    'link' => 'http://wcsp.science.kew.org/qsearch.do?plantName=',
530
    'link' => 'http://wcsp.science.kew.org/qsearch.do?plantName=[cdm:taxon_name]',
649 531
    'title' => 'Search World Checklist Monocots...',
650
    'glue' => ' ',
651 532
    'weight' => 0,
652 533
    'status' => 1,
653 534
    'category' => 'Classification',
654 535
  );
655 536
  $ext_links_default["tpl"] = array(
656 537
    'id' => "tpl",
657
    'link' => 'http://www.theplantlist.org/tpl/search?q=',
538
    'link' => 'http://www.theplantlist.org/tpl/search?q=[cdm:taxon_name]',
658 539
    'title' => 'Search The Plant List...',
659
    'glue' => '+',
660 540
    'weight' => 0,
661 541
    'status' => 1,
662 542
    'category' => 'Classification',
663 543
  );
664 544
  $ext_links_default["eol"] = array(
665 545
    'id' => "eol",
666
    'link' => 'http://eol.org/search/?q=',
546
    'link' => 'http://eol.org/search/?q=[cdm:taxon_name]',
667 547
    'title' => 'Search Encyclopaedia of Life...',
668
    'glue' => '+',
669 548
    'weight' => 0,
670 549
    'status' => 1,
671 550
    'category' => 'General',
672 551
  );
673 552
  $ext_links_default["jstor"] = array(
674 553
    'id' => "jstor",
675
    'link' => 'https://plants.jstor.org/search?filter=name&so=ps_group_by_genus_species+asc&Query=',
554
    'link' => 'https://plants.jstor.org/search?filter=name&so=ps_group_by_genus_species+asc&Query=[cdm:taxon_name]',
676 555
    'title' => 'Search JSTOR Plant Science...',
677
    'glue' => ' ',
678 556
    'weight' => 0,
679 557
    'status' => 1,
680 558
    'category' => 'General',
681 559
  );
682 560
  $ext_links_default["epic"] = array(
683 561
    'id' => "epic",
684
    'link' => 'http://epic.kew.org/searchepic/summaryquery.do?scientificName=',
562
    'link' => 'http://epic.kew.org/searchepic/summaryquery.do?scientificName=[cdm:taxon_name]&searchAll=true&categories=names&categories=bibl&categories=colln&categories=taxon&categories=flora',
685 563
    'title' => 'Search ePIC...',
686
    'glue' => '+',
687 564
    'weight' => 0,
688 565
    'status' => 1,
689 566
    'category' => 'General',
690 567
  );
691 568
  $ext_links_default["fairchild"] = array(
569
    //disabled since Fairchild Guide To Palms seems to be down
692 570
    'id' => "fairchild",
693 571
    'link' => 'http://palmguide.org/palmsearch.php?query=',
694 572
    'title' => 'Search Fairchild Guide To Palms...',
695
    'glue' => '+',
696 573
    'weight' => 0,
697
    'status' => 0, //disabled since Fairchild Guide To Palms seems to be down
574
    'status' => 0,
698 575
    'category' => 'Specimens/Occurrences',
699 576
  );
700 577
  $ext_links_default["ggbn"] = array(
701 578
    'id' => "ggbn",
702
    'link' => 'http://www.ggbn.org/ggbn_portal/search/result?fullScientificName=',
579
    'link' => 'http://www.ggbn.org/ggbn_portal/search/result?fullScientificName=[cdm:taxon_name]',
703 580
    'title' => 'Search GGBN...',
704
    'glue' => '+',
705 581
    'weight' => 0,
706 582
    'status' => 1,
707 583
    'category' => 'Molecular Resources',

Also available in: Unified diff