Revision 82e80b81
Added by Andreas Kohlbecker almost 2 years ago
modules/cdm_dataportal/ext_links/ext_links.module | ||
---|---|---|
76 | 76 |
'access arguments' => ['access administration pages'], |
77 | 77 |
'file' => 'ext_links.admin.inc', |
78 | 78 |
]; |
79 |
$items['admin/config/cdm_dataportal/ext_links/%link_template/disable'] = [
|
|
79 |
$items['admin/config/cdm_dataportal/ext_links/%link_template/status/%value'] = [
|
|
80 | 80 |
'title' => 'Disable external link', |
81 | 81 |
'page callback' => 'drupal_get_form', |
82 | 82 |
'page arguments' => ['ext_links_admin_disable', 4], |
... | ... | |
87 | 87 |
} |
88 | 88 |
|
89 | 89 |
|
90 |
/** |
|
91 |
* Returns the genus and the first epithet from the object taxon. |
|
92 |
*/ |
|
93 |
function getSpeciesName($taxon) { |
|
94 |
$speciesName = array(); |
|
95 |
$i = 0; |
|
96 |
while (isset($taxon->name->taggedName[$i]) && !isset($speciesName['species'])) { |
|
97 |
if ($taxon->name->taggedName[$i]->type == "name") { |
|
98 |
if (!isset($speciesName['genus'])) { |
|
99 |
$speciesName['genus'] = $taxon->name->taggedName[$i]->text; |
|
100 |
} |
|
101 |
else { |
|
102 |
$speciesName['species'] = $taxon->name->taggedName[$i]->text; |
|
103 |
} |
|
104 |
} |
|
105 |
$i++; |
|
106 |
} |
|
107 |
return $speciesName; |
|
108 |
} |
|
109 |
|
|
110 | 90 |
/** |
111 | 91 |
* Retrieves a list of External Link templates, ordered by weight. |
112 | 92 |
* |
... | ... | |
134 | 114 |
$link_templates[] = (object)$a; |
135 | 115 |
} |
136 | 116 |
} else { |
137 |
$link_templates = db_select('ext_links_templates', 'ff')
|
|
117 |
$link_templates = db_select('ext_links', 'elt')
|
|
138 | 118 |
->addTag('translatable') |
139 |
->fields('ff')
|
|
140 |
// ->condition('status', 1)
|
|
119 |
->fields('elt')
|
|
120 |
->condition('status', 1) |
|
141 | 121 |
->orderBy('weight') |
142 | 122 |
->execute(); |
143 | 123 |
} |
... | ... | |
147 | 127 |
return $link_templates; |
148 | 128 |
} |
149 | 129 |
|
130 |
/** |
|
131 |
* Resets the text format caches. |
|
132 |
* |
|
133 |
* @see filter_formats() |
|
134 |
*/ |
|
135 |
function ext_links_templates_reset() { |
|
136 |
cache_clear_all('ext_links_templates', 'cache', TRUE); |
|
137 |
drupal_static_reset('ext_links_templates'); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* Loads a text format object from the database. |
|
142 |
* |
|
143 |
* @param $extlink_id |
|
144 |
* The external link ID. ($link->id) |
|
145 |
* |
|
146 |
* @return |
|
147 |
* A fully-populated text format object, if the requested format exists and |
|
148 |
* is enabled. If the format does not exist, or exists in the database but |
|
149 |
* has been marked as disabled, FALSE is returned. |
|
150 |
* |
|
151 |
* @see ext_links_exists() |
|
152 |
*/ |
|
153 |
function ext_links_load($extlink_id) { |
|
154 |
$formats = ext_links_templates(); |
|
155 |
return isset($formats[$extlink_id]) ? $formats[$extlink_id] : FALSE; |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* Saves a text format object to the database. |
|
160 |
* |
|
161 |
* @param $link_template |
|
162 |
* A link template object having the properties: |
|
163 |
* - id: The machine name of the external link. If this corresponds |
|
164 |
* to an existing external link, this one will be updated; |
|
165 |
* otherwise, a new external link will be created. |
|
166 |
* - title: The link title |
|
167 |
* - link: The link url template. |
|
168 |
* - glue: The string to concatenate name parts in the URL query string. |
|
169 |
* - status: (optional) An integer indicating whether the ext link is |
|
170 |
* enabled (1) or not (0). Defaults to 1. |
|
171 |
* - weight: (optional) The weight of the external link, which controls its |
|
172 |
* placement in external link block. If omitted, the weight is set to 0. |
|
173 |
* Defaults to NULL. |
|
174 |
* |
|
175 |
* @return |
|
176 |
* SAVED_NEW or SAVED_UPDATED. |
|
177 |
*/ |
|
178 |
function ext_links_save($link_template) { |
|
179 |
$link_template->title = trim($link_template->title); |
|
180 |
$link_template->cache = true; |
|
181 |
if (!isset($link_template->status)) { |
|
182 |
$link_template->status = 1; |
|
183 |
} |
|
184 |
if (!isset($link_template->weight)) { |
|
185 |
$link_template->weight = 0; |
|
186 |
} |
|
187 |
|
|
188 |
// Insert or update the text format. |
|
189 |
$return = db_merge('ext_links') |
|
190 |
->key(array('format' => $link_template->title)) |
|
191 |
->fields(array( |
|
192 |
'id' => $link_template->id, |
|
193 |
'title' => $link_template->title, |
|
194 |
'link' => $link_template->link, |
|
195 |
'glue' => $link_template->glue, |
|
196 |
'status' => (int) $link_template->status, |
|
197 |
'weight' => (int) $link_template->weight, |
|
198 |
)) |
|
199 |
->execute(); |
|
200 |
|
|
201 |
if ($return != SAVED_NEW) { |
|
202 |
// Clear the filter cache whenever an external link is updated. |
|
203 |
cache_clear_all($link_template->format . ':', 'cache_filter', TRUE); |
|
204 |
} |
|
205 |
ext_links_templates_reset(); |
|
206 |
return $return; |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* Determines if a external link exists. |
|
211 |
* |
|
212 |
* @param $ext_link_name |
|
213 |
* The ID of the external link to check. |
|
214 |
* |
|
215 |
* @return |
|
216 |
* TRUE if the external link exists, FALSE otherwise. |
|
217 |
* |
|
218 |
* @see ext_links_load() |
|
219 |
*/ |
|
220 |
function ext_links_exists($ext_link_name) { |
|
221 |
return (bool) db_query_range('SELECT 1 FROM {ext_links} WHERE name = :name', 0, 1, array(':name' => $ext_link_name))->fetchField(); |
|
222 |
} |
|
223 |
|
|
224 |
|
|
225 |
/** |
|
226 |
* Returns the genus and the first epithet from the object taxon. |
|
227 |
* |
|
228 |
* @param $taxon |
|
229 |
* A CDM Taxon instance object |
|
230 |
* @return array |
|
231 |
* An associate array with two elements: |
|
232 |
* - genus: the uninomial |
|
233 |
* - species: the species epithet |
|
234 |
*/ |
|
235 |
function ext_link_species_name($taxon) { |
|
236 |
$speciesName = array(); |
|
237 |
$i = 0; |
|
238 |
while (isset($taxon->name->taggedName[$i]) && !isset($speciesName['species'])) { |
|
239 |
if ($taxon->name->taggedName[$i]->type == "name") { |
|
240 |
if (!isset($speciesName['genus'])) { |
|
241 |
$speciesName['genus'] = $taxon->name->taggedName[$i]->text; |
|
242 |
} |
|
243 |
else { |
|
244 |
$speciesName['species'] = $taxon->name->taggedName[$i]->text; |
|
245 |
} |
|
246 |
} |
|
247 |
$i++; |
|
248 |
} |
|
249 |
return $speciesName; |
|
250 |
} |
|
251 |
|
|
150 | 252 |
/** |
151 | 253 |
* Implements hook_block_info(). |
152 | 254 |
*/ |
... | ... | |
174 | 276 |
// var_export() |
175 | 277 |
if (!empty($taxon)) { |
176 | 278 |
drupal_add_js(drupal_get_path('module', 'ext_links') . '/ext_links.js'); |
177 |
$speciesName = getSpeciesName($taxon);
|
|
279 |
$speciesName = ext_link_species_name($taxon);
|
|
178 | 280 |
|
179 | 281 |
$genus = $taxon->name->taggedName[0]->text; |
180 | 282 |
$species = null; |
... | ... | |
261 | 363 |
$species = $variables['species']; |
262 | 364 |
$block_content = ''; |
263 | 365 |
$categories = NULL; |
264 |
$ext_links_default = ext_links_get_default();
|
|
366 |
$ext_links_default = ext_links_templates();
|
|
265 | 367 |
|
266 | 368 |
|
267 | 369 |
/* |
... | ... | |
561 | 663 |
*/ |
562 | 664 |
function ext_links_template_defaults() { |
563 | 665 |
$ext_links_default["gbif"] = array( |
666 |
'id' => "gbif", |
|
564 | 667 |
'link' => 'http://www.gbif.org/species/search?q=', |
565 | 668 |
'title' => 'Search GBIF...', |
566 | 669 |
'glue' => ' ', |
... | ... | |
569 | 672 |
'category' => 'Specimens/Occurrences', |
570 | 673 |
); |
571 | 674 |
$ext_links_default["biocase"] = array( |
675 |
'id' => "biocase", |
|
572 | 676 |
'link' => 'http://search.biocase.org/edit/search/units/simpleSearch/query1?unitName=', |
573 | 677 |
'title' => 'Search BioCASE...', |
574 | 678 |
'glue' => ' ', |
... | ... | |
577 | 681 |
'category' => 'Specimens/Occurrences', |
578 | 682 |
); |
579 | 683 |
$ext_links_default["nybg"] = array( |
684 |
'id' => "nybg", |
|
580 | 685 |
'link' => 'http://sweetgum.nybg.org/science/vh/specimen_list.php?SummaryData=', |
581 | 686 |
'title' => 'Search NYBG...', |
582 | 687 |
'glue' => '+AND+', |
... | ... | |
585 | 690 |
'category' => 'Specimens/Occurrences', |
586 | 691 |
); |
587 | 692 |
$ext_links_default["tropicos"] = array( |
693 |
'id' => "tropicos", |
|
588 | 694 |
'link' => 'http://www.tropicos.org/NameSearch.aspx?name=', |
589 | 695 |
'title' => 'Search Tropicos...', |
590 | 696 |
'glue' => '+', |
... | ... | |
593 | 699 |
'category' => 'Specimens/Occurrences', |
594 | 700 |
); |
595 | 701 |
$ext_links_default["ncbi"] = array( |
702 |
'id' => "ncbi", |
|
596 | 703 |
'link' => 'http://www.ncbi.nlm.nih.gov/gquery/gquery.fcgi?term=', |
597 | 704 |
'title' => 'Search NCBI...', |
598 | 705 |
'glue' => '+AND+', |
... | ... | |
601 | 708 |
'category' => 'Molecular Resources', |
602 | 709 |
); |
603 | 710 |
$ext_links_default["google"] = array( |
711 |
'id' => "google", |
|
604 | 712 |
'link' => 'http://images.google.com/images?q=', |
605 | 713 |
'title' => 'Search Google Images...', |
606 | 714 |
'glue' => '+', |
... | ... | |
609 | 717 |
'category' => 'Images', |
610 | 718 |
); |
611 | 719 |
$ext_links_default["flickr"] = array( |
720 |
'id' => "flickr", |
|
612 | 721 |
'link' => 'http://www.flickr.com/search/?w=all&q=', |
613 | 722 |
'title' => 'Search flickr...', |
614 | 723 |
'glue' => '+', |
... | ... | |
617 | 726 |
'category' => 'Images', |
618 | 727 |
); |
619 | 728 |
$ext_links_default["scholar"] = array( |
729 |
'id' => "scholar", |
|
620 | 730 |
'link' => 'http://scholar.google.de/scholar?hl=de&btnG=Suche&lr=&as_ylo=&as_vis=0&q=', |
621 | 731 |
'title' => 'Search Google scholar...', |
622 | 732 |
'glue' => '+', |
... | ... | |
625 | 735 |
'category' => 'Literature', |
626 | 736 |
); |
627 | 737 |
$ext_links_default["bhl"] = array( |
738 |
'id' => "bhl", |
|
628 | 739 |
'link' => 'http://www.biodiversitylibrary.org/Search.aspx?searchCat=&searchTerm=', |
629 | 740 |
'title' => 'Search BHL...', |
630 | 741 |
'glue' => ' ', |
... | ... | |
633 | 744 |
'category' => 'Literature', |
634 | 745 |
); |
635 | 746 |
$ext_links_default["arkive"] = array( |
747 |
'id' => "arkive", |
|
636 | 748 |
'link' => 'http://www.arkive.org/search.html?q=', |
637 | 749 |
'title' => 'Search ARKive...', |
638 | 750 |
'glue' => '+', |
... | ... | |
641 | 753 |
'category' => 'Images', |
642 | 754 |
); |
643 | 755 |
$ext_links_default["herbcat"] = array( |
756 |
'id' => "herbcat", |
|
644 | 757 |
'link' => 'http://apps.kew.org/herbcat/getHomePageResults.do?homePageSearchText=', |
645 | 758 |
'title' => 'Search Kew Herbarium Catalogue...', |
646 | 759 |
'glue' => '+', |
... | ... | |
649 | 762 |
'category' => 'Specimens/Occurrences', |
650 | 763 |
); |
651 | 764 |
$ext_links_default["iucn"] = array( |
765 |
'id' => "iucn", |
|
652 | 766 |
'link' => 'http://www.iucnredlist.org/', |
653 | 767 |
'title' => 'Go to IUCN Red List...', |
654 | 768 |
'glue' => ' ', |
... | ... | |
657 | 771 |
'category' => 'Conservation', |
658 | 772 |
); |
659 | 773 |
$ext_links_default["ipni"] = array( |
774 |
'id' => "ipni", |
|
660 | 775 |
'link' => 'http://www.ipni.org/ipni/advPlantNameSearch.do?', |
661 | 776 |
'title' => 'Search IPNI...', |
662 | 777 |
'glue' => '&', |
... | ... | |
665 | 780 |
'category' => 'Classification', |
666 | 781 |
); |
667 | 782 |
$ext_links_default["wcsp"] = array( |
783 |
'id' => "wcsp", |
|
668 | 784 |
'link' => 'http://wcsp.science.kew.org/qsearch.do?plantName=', |
669 | 785 |
'title' => 'Search World Checklist Monocots...', |
670 | 786 |
'glue' => ' ', |
... | ... | |
673 | 789 |
'category' => 'Classification', |
674 | 790 |
); |
675 | 791 |
$ext_links_default["tpl"] = array( |
792 |
'id' => "tpl", |
|
676 | 793 |
'link' => 'http://www.theplantlist.org/tpl/search?q=', |
677 | 794 |
'title' => 'Search The Plant List...', |
678 | 795 |
'glue' => '+', |
... | ... | |
681 | 798 |
'category' => 'Classification', |
682 | 799 |
); |
683 | 800 |
$ext_links_default["eol"] = array( |
801 |
'nme' => "eol", |
|
684 | 802 |
'link' => 'http://eol.org/search/?q=', |
685 | 803 |
'title' => 'Search Encyclopaedia of Life...', |
686 | 804 |
'glue' => '+', |
... | ... | |
689 | 807 |
'category' => 'General', |
690 | 808 |
); |
691 | 809 |
$ext_links_default["jstor"] = array( |
810 |
'id' => "jstor", |
|
692 | 811 |
'link' => 'https://plants.jstor.org/search?filter=name&so=ps_group_by_genus_species+asc&Query=', |
693 | 812 |
'title' => 'Search JSTOR Plant Science...', |
694 | 813 |
'glue' => ' ', |
... | ... | |
697 | 816 |
'category' => 'General', |
698 | 817 |
); |
699 | 818 |
$ext_links_default["epic"] = array( |
819 |
'id' => "epic", |
|
700 | 820 |
'link' => 'http://epic.kew.org/searchepic/summaryquery.do?scientificName=', |
701 | 821 |
'title' => 'Search ePIC...', |
702 | 822 |
'glue' => '+', |
... | ... | |
704 | 824 |
'status' => 1, |
705 | 825 |
'category' => 'General', |
706 | 826 |
); |
707 |
/* |
|
708 |
* hidden since Fairchild Guide To Palms seems to be down |
|
709 | 827 |
$ext_links_default["fairchild"] = array( |
828 |
'id' => "fairchild", |
|
710 | 829 |
'link' => 'http://palmguide.org/palmsearch.php?query=', |
711 | 830 |
'title' => 'Search Fairchild Guide To Palms...', |
712 | 831 |
'glue' => '+', |
713 | 832 |
'weight' => 0, |
714 |
'status' => 1,
|
|
833 |
'status' => 0, //disabled since Fairchild Guide To Palms seems to be down
|
|
715 | 834 |
'category' => 'Specimens/Occurrences', |
716 | 835 |
); |
717 |
*/ |
|
718 | 836 |
$ext_links_default["ggbn"] = array( |
837 |
'id' => "ggbn", |
|
719 | 838 |
'link' => 'http://www.ggbn.org/ggbn_portal/search/result?fullScientificName=', |
720 | 839 |
'title' => 'Search GGBN...', |
721 | 840 |
'glue' => '+', |
Also available in: Unified diff
ref #9659 admin overview improved and edit form ready