'Metacarta Vmap0', 'PREFERRED' => 'metacarta_vmap0'); } $layerNames = ''; foreach($baseLayers as $layerName => $layerLabel){ if($layerName == 'PREFERRED'){ $preferredLayer = $baseLayers['PREFERRED']; } else { $layerNames .= ($layerNames ? ', ': '') . "'$layerName'"; } } if( isset($baseLayers['gmap']) || isset($baseLayers['gsat']) || isset($baseLayers['ghyb']) ){ drupal_set_html_head(''); drupal_set_html_head(''); } drupal_add_js(" if (Drupal.jsEnabled) { $(document).ready(function() { $('#openlayers_map').cdm_openlayers_map('" .getEDITMapServiceURI()."', { legendPosition: 3, displayWidth: '" . variable_get('cdm_dataportal_geoservice_display_width', false) . "', boundingBox: '" . variable_get('cdm_dataportal_geoservice_bounding_box', false) . "', distributionOpacity: '" . variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5') . "', legendOpacity: '" . variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5') . "', showLayerSwitcher: " . (variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE) ? 'true':'false') . ", baseLayerNames: [".$layerNames."], defaultBaseLayerName: '".$preferredLayer."', }); }); }", 'inline'); } function get_openlayers_map($width, $occurrenceQuery = false, $distributionQuery = false, $legendFormatQuery = false, $map_caption = false ){ _add_js_openlayers_map(); $out = '
Select the default tab to display when visiting a taxon page. Only available if Tabbed Taxon Page is enable.
Note: After performing a search and clicking in any synonym, the taxon tab to be renderized will be the synonymy of the accepted taxon and not the above selected tab.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') ); return $form; } /** * The function submit the user cdm dataportal configurations * @param unknown_type $form * @param unknown_type $form_values */ function cdm_dataportal_user_form_submit($form, $form_values) { global $user; $msg_type = 'status'; $username = $user->name; $variable_to_use = 'cdm_dataportal_' .$user->uid . '_default_tab'; //if is the right user the variables are setted if (arg(0)=='user' && ($uid=arg(1)) && is_numeric($uid) && $user->uid==$uid){ $variable = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB); variable_set($variable_to_use . '_active', $form_values['check']); variable_set($variable_to_use, $form_values['cdm_dataportal_user_form']); if ($form_values['check']){ drupal_set_message('The user default tab will be used for the next taxon site visit.'); drupal_set_message('The user default tab have been changed to: ' . $variable[variable_get($variable_to_use, 0)] . ' for the user ' . $username, $msg_type); }else{ drupal_set_message('The user default tab wont be used for the next taxon site, check the box if you want to use the user default configuration.'); } //problem with the user id => variables wont be saved }else{ $msg_type = 'warning'; drupal_set_message('Default tab have not been saved due to user id problems', $msg_type); } } /** * Implementation of hook_block() * * Provides the following blocks: * 0: list of links useful during development * * @param String $op * @param int $delta */ function cdm_dataportal_block($op='list', $delta=0) { // listing of blocks, such as on the admin/block page if ($op == "list") { //$block[0]["info"] = t("CDM DataPortal DevLinks"); // $block[1]["info"] = t("CDM DataPortal Credits"); $block[2]["info"] = t("CDM Search Taxa"); //$block[3]["info"] = t("CDM Filters"); $block[4]["info"] = t("CDM Dataportal Print"); $block["keys"]["info"] = t("CDM identification keys"); return $block; } else if ($op == 'view') { switch($delta){ // case 1: // $block['subject'] = t('Credits'); // $block['content'] = theme('cdm_credits'); // return $block; case 2: $block['subject'] = t('Search taxa'); $block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form'); if (variable_get('cdm_dataportal_show_advanced_search', 1)){ $block['content'] .= '
* Removes Drupal internal form elements from query
* @param $form
* @return unknown_type
*/
function cdm_dataportal_search_process($form) {
unset($form['form_id']);
unset($form['form_token']);
return $form;
}
/**
* Filters $_REQUEST by a list of valid request parameters and also sets defaults if required.
* returns the processed request parameters submitted by the search form.
*/
function cdm_dataportal_search_form_request(){
$form_params = array();
array_deep_copy($_REQUEST['search'], $form_params);
$form_params['query'] = trim($_REQUEST['query']);
// split of geographic range
if(isset($_REQUEST['search']['geographic_range'])){
$geographicRange = $_REQUEST['search']['geographic_range'];
// remove
unset($form_params['geographic_range']);
}
// add geographic range
if($geographicRange){
$form_params['tdwg_level_select'] = $geographicRange['tdwg_level_select'];
for($i = 1; $i < 5; $i++){
if(isset($geographicRange['tdwg_level_'.$i])){
$form_params['area'] = $geographicRange['tdwg_level_'.$i];
}
}
}
// store in session
$_SESSION['cdm']['search'] = $form_params;
return $form_params;
}
/* UNREACHABLE since action of form directly links to view
function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
$_SESSION['cdm']['search'] = $form_values;
//return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
//$paramstr = compose_url_prameterstr($form_values);
//return url('/cdm_dataportal/search/taxon/', $paramstr);
}
*/
/* ====================== menu callback functions ====================== */
function cdm_dataportal_form_alter($form_id, &$form) {
static $comment_node_disabled = 0;
static $comment_node_read_only = 1;
static $comment_node_read_write = 2;
if ($form_id == 'node_type_form'
&& isset($form['identity']['type'])
&& array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
) {
$form['workflow']['comment'] = array(
'#type' => 'radios',
'#title' => t('Default comment setting'),
'#default_value' => variable_get('comment_'. $form['#node_type']->type, $comment_node_disabled),
'#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
'#description' => t('Users with the administer comments permission will be able to override this setting.'),
);
}
}
function cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed, $form_description = ''){
//TODO move into settings.php
$form[$form_name] = array(
'#type' => 'fieldset',
'#title' => t($form_tittle),
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
'#tree' => true,
'#description' => t($form_description),
);
$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
$gallery_settings = variable_get($form_name, $default_values);
//$test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
/* TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
$form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
'#type' => 'textfield',
'#title' => t('Search Page Size'),
'#default_value' => $test,
'#description' => t('Number of Names to display per page in search results.')
);
*/
$form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
'#type' => 'checkbox',
'#title' => t('Show media thumbnails for accepted taxa'),
'#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
);
$form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
'#type' => 'checkbox',
'#title' => t('Show media thumbnails for synonyms'),
'#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
'#description' => t('')
);
}
//$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
$form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
'#type' => 'checkbox',
'#title' => t('Show captions under thumbnails'),
'#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
'#description' => t('')
);
$form[$form_name]['cdm_dataportal_media_maxextend'] = array(
'#type' => 'textfield',
'#title' => t('Thumbnail size'),
'#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
'#description' => t('Select the size of each individual thumbnail.')
);
if($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME){
$form[$form_name]['cdm_dataportal_media_cols'] = array(
'#type' => 'textfield',
'#title' => t('Number of columns'),
'#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
'#description' => t('Group the thumbnails in columns: select how many columns should the gallery display.')
);
}
if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
$form[$form_name]['cdm_dataportal_media_maxRows'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of rows'),
'#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
'#description' => t('You can group the thumbnails in rows, select in how many rows should be the thumbnails grouped.
Note: If you want an unlimited number of rows please set to 0')
);
}
return $form;
}
/**
* Displays a list of the known taxonomic names. Long lists are split up into multiple pages
*
* TODO: parameters are still preliminar
* @param String $page page number to diplay defaults to page 1
* @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
*/
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
$request_params = array(
'q' => $beginsWith,
//'sec' = '',
//'higherTaxa' => getFiters(),
// 'matchAnywhere' => false, // default is false
'page' => $page,
'onlyAccepted' => $onlyAccepted,
'pagesize' => 20 /*$_SESSION['cdm']['namelist_pagesize'] */);
$taxonPager = cdm_ws_find(CDM_WS_PORTAL_TAXON_FIND, $request_params);
/*
* FIXME the filter for accepted names will be a form element, thus this widget
* should be generated via form api preferably as block
*/
//$out = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
//$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
$out .= theme('cdm_listof_taxa', $taxonPager);
return $out;
}
function cdm_dataportal_view_reference($uuid, $arg2 = null){
$reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
return theme('cdm_reference_page', $reference);
}
function cdm_dataportal_view_reference_list($pageNumber){
$referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
}
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = false, $part = 0){
$media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
}
function _load_taxonBase(&$taxonBase){
if(isset($taxonBase->uuid)){
$taxonBase->name = cdm_ws_get(CDM_WS_TAXON, array($taxonBase->uuid, "name"));
$taxonBase->name->taggedName = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "taggedName"));
$taxonBase->name->nomenclaturalReference = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "nomenclaturalReference"));
}
}
/**
* similar to the variable_get() function of Drupal, except of thst this function
* is able to handle arrays correctly. This function is especially useful
* when dealing with collections of setting form elemens (#tree = true)
*
* @param String $variableKey
* @param String $defaultValueString a sting as for example derived from a CONSTANT
* @return mixed, usually an array
*/
function mixed_variable_get($variableKey, $defaultValueString){
$systemDefaults = unserialize($defaultValueString);
$storedSettings = variable_get($variableKey, array());
if(is_array($storedSettings)){
$settings = array_merge($systemDefaults, $storedSettings);
} else {
$settings = $systemDefaults;
}
return $settings;
}
/**
* Loads the subgraph of the given PolytomousKeyNode recursively from the cdm REST service.
* @param PolytomousKeyNode $polytomousKeyNode passed by reference
* @return nothing
*/
function _load_polytomousKeySubGraph(&$polytomousKeyNode){
if(!$polytomousKeyNode){
return;
}
if($polytomousKeyNode->class != "PolytomousKeyNode"){
drupal_set_message("_load_polytomousKeySubGraph() invalid type given.", "error");
return;
}
if(!is_uuid($polytomousKeyNode->uuid)){
drupal_set_message("_load_polytomousKeySubGraph() invalid type given.", "error");
return;
}
$polytomousKeyNode = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid);
if(!$polytomousKeyNode){
//drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error");
return;
}
// load children
foreach($polytomousKeyNode->children as &$childNode){
_load_polytomousKeySubGraph($childNode);
}
// load subkey
$polytomousKeyNode->subkey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "subkey"));
// load taxon
$polytomousKeyNode->taxon = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "taxon"));
_load_taxonBase($polytomousKeyNode->taxon);
return;
}
function cdm_dataportal_view_polytomousKey($polytomousKeyUuid){
$polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid);
$sourcePager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, "sources"));
if(is_array($sourcePager->records)){
$polytomousKey->sources = $sourcePager->records;
//$polytomousKey->sources->citation = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, "sources"));
}
$annotationPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, "annotations"));
if(is_array($annotationPager->records)){
$polytomousKey->annotations = $annotationPager->records;
}
_load_polytomousKeySubGraph($polytomousKey->root);
return theme('cdm_polytomousKey_page', $polytomousKey);
}
/**
* The taxon page gives detailed information on a taxon, it shows:
* - Taxon name
* - Full list of synonyms homotypic synonyms on top, followed by the
* heterotypic and finally followed by misapplied names.
* The list is ordered historically.
* - All description associated with the taxon.
*
* @param $uuid
* @param $chapter name of the part to display,
* valid values are: 'description', 'images', 'synonymy', 'specimens', 'all'
* @return unknown_type
*/
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all', $synonym_uuid = null){
// display the page for the taxon defined by $uuid
set_last_taxon_page_tab(arg(3));
$taxonpage = cdm_dataportal_taxon_view($uuid, $chapter, $synonym_uuid);
return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
}
/**
* @param $uuid
* @param $chapter name of the part to display,
* valid values are: 'description', 'images', 'synonymy', 'all'
* @return unknown_type
*/
function cdm_dataportal_taxon_view($uuid, $chapter = 'all', $synonym_uuid = null){
$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
if(!$taxon){
drupal_set_title(t('Taxon does not exist'));
return false;
}
$taxonpage->title = theme('cdm_taxon_page_title', $taxon, $uuid, $synonym_uuid);
// check if the taxon id contained in the currently selected tree
$taxon_in_current_tree = taxon_in_current_tree($uuid);
$taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $uuid);
if(!$taxon_in_current_tree){
if(count($taxon_nodes) == 0){
drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained any classification.'
,'warning');
} else {
$trees = '';
foreach($taxon_nodes as $node){
$trees .= ($trees?', ':'').''.$node->classification->titleCache.'';
}
drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained in the currently chosen classification, but in '
.(count($taxon_nodes) > 1? ' one of these: ' : ' this one: ') . $trees
, 'warning');
}
}
// render the taxon page
$taxonpage->content = theme('cdm_taxon_page', $taxon, $chapter);
return $taxonpage;
}
/**
* The function returns a name page as a drupal node ready to be renderized by drupal.
* The node page show the taxon name title and the list of taxon related with such taxon
* name on the tree already in used.
* @param $taxon_name_uuid A taxon name uuid
* @return The formatted name page as node
*/
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
$taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid);
return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title , $taxonname_page->content);
}
/**
* The function genates a object ready to be transformated to a node
* in order to show as a drupal node
* @param $taxon_name_uuid
* @return the object with the page content and title
*/
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
//getting the full taxonname object from the server
$taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
if(!$taxon_name){
drupal_set_title(t('Taxon name does not exist'));
return false;
}
//searching for all the taxa connected with the taxon name on the tree in used
$name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
$request_params = array();
$request_params['query'] = $name_cache;
$request_params['tree'] = get_taxonomictree_uuid_selected();
$request_params['doTaxa'] = 1;
$request_params['doSynonyms'] = 1;
$request_params['doTaxaByCommonNames'] = 0;
$request_params['matchMode'] = "EXACT";
$taxon_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
//removing the name where we come from and
foreach($taxon_pager->records as $k=>&$taxon){
if($taxon->uuid == $taxon_to_hide_uuid){
unset($taxon_pager->records[$k]);
}
}
//show the taxa list or go to the singular taxon
if (sizeof($taxon_pager->records) == 1){ //sigle taxon case
reset($taxon_pager->records);
$singleTaxon = $taxon_pager->records[0];
if($singleTaxon->class != "Taxon"){
// it is a Synonym -> look for the accepted
$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($singleTaxon->uuid, get_taxonomictree_uuid_selected()));
if($synonym_uuid){
drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', 'highlite=' . $synonym_uuid);
}else {
drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', 'highlite=' . $singleTaxon->uuid);
}
}else{
// it is an accepted taxon
if($synonym_uuid){
drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid . '/synonymy', 'highlite=' . $synonym_uuid);
}else{
drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid);
}
}
}else{ //more than one taxa case
$taxon_name_page->title = theme('cdm_name_page_title', $taxon_name);
if($taxon_pager->records){
$taxon_name_page->content = theme_cdm_list_of_taxa($taxon_pager->records, false);
}else{
$taxon_name_page->content = 'This name has no taxa';
}
return $taxon_name_page;
}
}
function cdm_dataportal_view_search_advanced(){
drupal_set_title(t('Advanced search'));
$searchForm = cdm_dataportal_search_taxon_form(true);
return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
}
/**
*
* future extensions to meet palmweb mockup requirements:
* - habitat
* - uses
* - conservation status
* - locality / tdwg region
*/
function cdm_dataportal_view_search_taxon(){
$_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
$request_params = cdm_dataportal_search_form_request();
$taxonPager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
$search_params = $_REQUEST;
unset($search_params['q']);
return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
}
function cdm_view_xml2json(){
$file = arg(2);
$datastr = get_content(variable_get('cdm_webservice_url', '').$file);
return xml2json::transformXmlStringToJson($datastr);
}
/* ====================== other functions ====================== */
/**
* Enter description here...
*
* @param String $uuid the UUID of the taxon
* @return the URL
*/
function path_to_taxon($uuid, $no_tab = false){
$tab = get_default_taxon_tab();
$values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
if(!$uuid) return false;
if (!$tab){
return 'cdm_dataportal/taxon/'.$uuid;
}else if(get_last_taxon_page_tab() && $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]){
return 'cdm_dataportal/taxon/'.$uuid . '/' . get_last_taxon_page_tab();
} else {
return 'cdm_dataportal/taxon/'.$uuid . '/' . strtolower($tab);
}
}
function path_to_key($keyType, $keyUuid){
if(!$keyUuid || !$keyType) return false;
$keyType{0} = strtolower($keyType{0});
return "cdm_dataportal/".$keyType."/$keyUuid";
}
function path_to_reference($uuid){
if(!$uuid) return false;
return 'cdm_dataportal/reference/'.$uuid;
}
function path_to_name($name_uuid){
$res = false;
if($name_uuid){
$res = 'cdm_dataportal/name/'.$name_uuid;
}
return $res;
}
function path_to_media($uuid, $representaion_uuid = false, $partId = false){
if(!$uuid) return false;
$out = 'cdm_dataportal/media/'.$uuid;
if($representaion_uuid){
$out .= '/'.$representaion_uuid;
if($partId !== false){
$out .= '/'.$partId;
}
}
return $out;
}
/**
* Compares thisRank with thatRank.
* Returns a negative integer, zero, or a positive integer
* as the of thisRank is higher than, equal to, or lower than thatRank.
* e.g:
*
* This compare logic of the underlying webservice is the * inverse logic of the the one implemented in * java.lang.Comparable#compareTo(java.lang.Object) * @param $thisRankUuid * @param $thatRankUuid * @return a negative integer, zero, or a positive integer * as the thisRank is lower than, equal to, or higher than thatRank */ function rank_compare($thisRankUuid, $thatRankUuid){ $result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid)); return $result->Integer; } /** * Composes an HTML element class attribute value composed of * the shortname of the cdm class and the uuid of the entity. * This class attribute should be used whereever an cdm-entity is rendered. * * These according class selectors in css must be escaped, eg: * .cdm\:TextData * * @param $cdmEntity */ function html_class_atttibute_ref($cdmEntity){ if(is_cdm_entity($cdmEntity)) { return "cdm:".$cdmEntity->class." uuid:".$cdmEntity->uuid; } } function theme_cdm_uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null){ $acceptedPath = path_to_taxon($acceptedUuid, true); return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid.'&acceptedFor='.$synonymUuid, $synonymUuid); } /** * Preprocess the taggedName to normalize newly introduced tagtypes like hybridSign, separator, .. more? * * @param unknown_type $taggedTextList */ function normalize_TaggedName(&$taggedTextList){ if(is_array($taggedTextList)) { // first pass: rename for($i = 0; $i < count($taggedTextList); $i++){ if($taggedTextList[$i]->type == "hybridSign"){ $taggedTextList[$i]->type = "name"; } } // second pass: resolve separators $taggedNameListNew = array(); for($i = 0; $i < count($taggedTextList); $i++){ if($i + 1 < count($taggedTextList) && $taggedTextList[$i + 1]->type == "separator" ) { if($taggedTextList[$i]->type == $taggedTextList[$i + 2]->type){ $taggedName = $taggedTextList[$i]; $taggedName->text = $taggedName->text . $taggedTextList[$i + 1]->text . $taggedTextList[$i + 2]->text; $taggedNameListNew[] = $taggedName; ++$i; ++$i; } } else { $taggedNameListNew[] = $taggedTextList[$i]; } } $taggedTextList = $taggedNameListNew; } } /** * Creates a short taxonname by using the taggename field of NameSTO or NameTO instances. * If the taggename if empty the fullname will be returned. * * @param unknown_type $Name or TreeNode * @return string */ function cdm_dataportal_shortname_of($name){ $nameStr = ''; normalize_TaggedName($name->taggedTitle); // get all tagged text tokens of the scientific name foreach($name->taggedTitle as $tagtxt){ if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){ $nameStr .= ($nameStr ? ' ' : '').$tagtxt->text; } } $nameStr = trim($nameStr); if($nameStr){ // do not return short names for these //if (stristr(strtolower($nameStr), 'incertae sedis') !== FALSE || // stristr(strtolower($nameStr), 'nomina excludenda') !== FALSE) { if ($name->unplaced || $name->excluded){ return $nameStr; } if($pos = stripos($nameStr, ' ')){ return substr($nameStr, 0, 1).'. '.substr($nameStr, $pos); } else { return $nameStr; } } else { return $name->titleCache; } } /** * Check if a taxon is accepted by the current taxonomic tree * * @param Taxon $taxon * @return true if $taxon is accepted, false otherwise */ function _cdm_dataportal_acceptedByCurrentView($taxon){ $defaultTreeUuid = get_taxonomictree_uuid_selected(); if($taxon->class == "Taxon" && isset($taxon->taxonNodes)){ foreach($taxon->taxonNodes as $node){ if($node->classification == $defaultTreeUuid) { return true; } } } return false; } /**@Deprecated * */ function compose_url_prameterstr($parameters = array(), $parentPropertyName = false){ $pstr = ''; foreach($parameters as $key=>$value){ if(is_array($value)){ } else { $pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value); } } return $pstr; } /** * workaround for missing original source type, idNamespace is always set in these cases * @param unknown_type $source * @return unknown_type */ function _is_original_source_type($source){ return !$source->idNamespace && strlen($source->idNamespace) == 0; } /** * The function read the metadata info such title or artist of a media file. The * function tries at first to get all the info from the file metadata and if it is * not avaible look at the media file info stored at the database. * @param $media The media file * @return array The array with the avilable specified metadata info. * TODO rename to read_media_metadata() and move to *.module */ function cdm_read_media_metadata($media){ $metadata_caption = array('title' => '', //media_metadata and media 'artist' => '', //media_metadata and media 'rights', //media_metadata and media 'location', //media_metadata 'filename' => '', //media 'mediacreated' => '', //media 'description' => ''); //media //getting the media metadata $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid)); $media_metadata_aux = (array) $media_metadata; //filename if(isset($media->representations[0]->parts[0]->uri)){ $fileUri = $media->representations[0]->parts[0]->uri; $filename = substr($fileUri, strrpos($fileUri, "/")+1); $metadata_caption['filename'] = $filename; } else{ $metadata_caption['filename'] = ''; } //title if ($media_metadata->ObjectName) { $metadata_caption['title'] = $media_metadata->ObjectName; } else if ($media_metadata_aux['Object Name']){ $metadata_caption['title'] = $media_metadata_aux['Object Name']; } else if ($media->title_L10n){ $metadata_caption['title'] = $media->title_L10n; } else if ($media->titleCache){ $metadata_caption['title'] = $media->titleCache; } // append description to title if ($media->description_L10n) { $metadata_caption['title'] .= '' . $media->description_L10n . ''; } //artist if ($media_metadata->Artist){ $metadata_caption['artist'] = ($media_metadata->Artist ? ''.$media_metadata->Artist : ''); } elseif ($media->artist->titleCache){ $metadata_caption['artist'] = $media->artist->titleCache; } //copyright $metadata_caption['rights'] = array('copyright' => array('agentNames' => array()), 'license' => array('agentNames' => array(), 'types' => array(), 'abbreviatedTexts' => array(), 'uris' => array())); if ($media_metadata->Copyright) $metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright; elseif ($media->rights){ foreach($media->rights as $right){ switch($right->term->uuid){ case UUID_RIGHTS_LICENCE: $metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? ''.$right->agent->firstname.' '.$right->agent->lastname : ''); $metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? ''.$right->representation_L10n : ''); $metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? ''.$right->abbreviatedText : ''); $metadata_caption['rights']['license']['uris'][] = ($right->uri ? ''.$right->uri : ''); break; case UUID_RIGHTS_COPYRIGHT: $metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname; break; } } } else { $metadata_caption['rights']['agentNames'][] = ''; } //filling the description (though there is no description in the db???) //$metadata_caption['description'] = $media->description_L10n; //location $metadata_caption['location'] = array(); $metadata_caption['location']['sublocation'] = $media_metadata->Sublocation; $metadata_caption['location']['city'] = $media_metadata->City; $metadata_caption['location']['province'] = $media_metadata->Province; $metadata_caption['location']['country'] = $media_metadata->Country; /* //creation date if($media_metadata["Modify Date"]) $metadata_caption['mediacreated'] = $media_metadata["Modify Date"]; else $metadata_caption['mediacreated'] = $media->created; */ //returned value return $metadata_caption; } /** * This function collects all the media from a list of description elements * and return them as an Array. * * @param $descriptionElementes The description elements * @return Array The output with all the media */ function cdm_dataportal_media_from_descriptionElements($descriptionElements){ //variables $outArrayOfMedia = array(); //return value //implementation if(is_array($descriptionElements)){//avoiding warning box in drupal for flora malesiana foreach($descriptionElements as $descriptionElement){ if(is_array($descriptionElement->media)){ foreach($descriptionElement->media as $media){ if(is_object($media)){ $outArrayOfMedia[] = $media; } } } } } return $outArrayOfMedia; } function cdm_annotations_as_footnotekeys($cdmBase, $footnote_list_key = null){ $footNoteKeys = array(); //is argument cdmBase an array? if (!is_array($cdmBase)){ $cdmBase_array = array(); $cdmBase_array[] = $cdmBase; }else{ $cdmBase_array = $cdmBase; } //getting the key for the footnotemanager if( $footnote_list_key ){ $footnoteListKey = $footnote_list_key; }else{ $footnoteListKey = RenderHints::getFootnoteListKey() . '-annotations'; } //adding the footnotes keys foreach($cdmBase_array as $cdmBase_element){ $annotations = cdm_ws_getAnnotationsFor($cdmBase_element, variable_get('annotations_types_as_footnotes', unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT))); if(is_array($annotations)){ foreach($annotations as $annotation){ $footNoteKeys[] = FootnoteManager::addNewFootnote($footnoteListKey, $annotation->text); } } } return $footNoteKeys; } function cdm_dynabox($label, $content_url, $theme, $link_alt_text, $enclosingtags = array('li', 'ul')){ drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_dynabox.js'); $cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/$theme"); $out .= '<'. $enclosingtags[0]. ' class="dynabox">'.$label.''; $out .= '<'. $enclosingtags[1]. ' class="dynabox_content" title="'.$cdm_proxy_url.'"><'. $enclosingtags[0]. '>'. $enclosingtags[0]. '>'. $enclosingtags[1]. '>'; $out .= ''. $enclosingtags[0]. '>'; return $out; } /** * returns true if the given $featureNode or any of its subordinate nodes contains * at least one non empty TextData or at leas one DescriptionElement of an other type. * * @param unknown_type $featureNode A heature node as produced by the function _mergeFeatureTreeDescriptions() */ function hasFeatureNodeDescriptionElements($featureNode) { if(is_array($featureNode->descriptionElements) && count($featureNode->descriptionElements) > 0) { foreach ($featureNode->descriptionElements as $descriptionElement) { if($descriptionElement->class != "TextData" || $descriptionElement->multilanguageText_L10n->text){ return true; } } } else if(is_array($featureNode->children)) { foreach ($featureNode->children as $child) { if(hasFeatureNodeDescriptionElements($child)){ return true; } } } return false; }