Revision 275b2642
Added by Andreas Kohlbecker over 7 years ago
modules/cdm_dataportal/cdm_api/cdm_api.module | ||
---|---|---|
469 | 469 |
} |
470 | 470 |
|
471 | 471 |
/** |
472 |
* @todo Improve the documentation of this function. |
|
473 |
* |
|
474 |
* media Array [4] |
|
475 |
* representations Array [3] |
|
476 |
* mimeType image/jpeg |
|
477 |
* representationParts Array [1] |
|
478 |
* duration 0 |
|
479 |
* heigth 0 |
|
480 |
* size 0 |
|
481 |
* uri |
|
482 |
* http://wp5.e-taxonomy.eu/dataportal/cichorieae/media/protolog/jpeg/Acanthocephalus_p1.jpg |
|
483 |
* uuid 15c687f1-f79d-4b79-992f-7ba0f55e610b |
|
484 |
* width 0 |
|
485 |
* suffix jpg |
|
486 |
* uuid 930b7d51-e7b6-4350-b21e-8124b14fe29b |
|
487 |
* title |
|
488 |
* uuid 17e514f1-7a8e-4daa-87ea-8f13f8742cf9 |
|
489 | 472 |
* |
490 | 473 |
* @param object $media |
491 | 474 |
* @param array $mimeTypes |
... | ... | |
519 | 502 |
$mimeTypes = array(); |
520 | 503 |
$dwa = 0; |
521 | 504 |
$dw = 0; |
505 |
$valid_parts_cnt = 0; |
|
522 | 506 |
// Look for part with the best matching size. |
523 | 507 |
foreach ($representation->parts as $part) { |
508 |
if(empty($part->uri)){ |
|
509 |
// skip part if URI is missing |
|
510 |
continue; |
|
511 |
} |
|
512 |
$valid_parts_cnt++; |
|
524 | 513 |
if (isset($part->width) && isset($part->height)) { |
525 | 514 |
$dw = $part->width * $part->height - $height * $width; |
526 | 515 |
} |
... | ... | |
529 | 518 |
} |
530 | 519 |
$dwa += $dw; |
531 | 520 |
} |
532 |
$dwa = (count($representation->parts) > 0) ? $dwa / count($representation->parts) : 0; |
|
533 |
$prefRepr[$dwa . '_'] = $representation; |
|
521 |
if($valid_parts_cnt > 0){ |
|
522 |
$dwa = $dwa / $valid_parts_cnt; |
|
523 |
$prefRepr[$dwa . '_'] = $representation; |
|
524 |
} |
|
534 | 525 |
} |
535 | 526 |
} |
536 | 527 |
} |
modules/cdm_dataportal/includes/name.inc | ||
---|---|---|
474 | 474 |
$second_citation = '[& ' . $description_element->multilanguageText_L10n->text . '].'; |
475 | 475 |
} |
476 | 476 |
$descriptionHtml .= $second_citation; |
477 |
$descriptionHtml .= theme("cdm_media", array(
|
|
478 |
'descriptionElement' => $description_element,
|
|
479 |
'mimeTypePreference' => array(
|
|
477 |
$descriptionHtml .= cdm_description_element_media(
|
|
478 |
$description_element, |
|
479 |
array( |
|
480 | 480 |
'application/pdf', |
481 | 481 |
'image/png', |
482 | 482 |
'image/jpeg', |
483 | 483 |
'image/gif', |
484 | 484 |
'text/html', |
485 | 485 |
) |
486 |
) |
|
487 | 486 |
); |
488 | 487 |
|
489 | 488 |
} |
modules/cdm_dataportal/theme/cdm_dataportal.media.theme | ||
---|---|---|
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
/** |
55 |
* @todo Please document this function. |
|
56 |
* @see http://drupal.org/node/1354 |
|
55 |
* Creates the markup for the media associated a DescriptionElement instance. |
|
56 |
* |
|
57 |
* @param $descriptionElement |
|
58 |
* the DescriptionElement instance |
|
59 |
* @param $mimeTypePreference array |
|
60 |
* An array of mime type strings. the order of the mimetpes is the oerder of preference. |
|
61 |
* E.g.: array('application/pdf','image/jpeg') |
|
62 |
* |
|
63 |
* @return string |
|
64 |
* The markup |
|
57 | 65 |
*/ |
58 |
function theme_cdm_media($variables) { |
|
59 |
$descriptionElement = $variables['descriptionElement']; |
|
60 |
$mimeTypePreference = $variables['mimeTypePreference']; |
|
66 |
function cdm_description_element_media($descriptionElement, $mimeTypePreference) { |
|
67 |
|
|
61 | 68 |
$out = ''; |
62 | 69 |
|
63 | 70 |
_add_js_thickbox(); |
64 | 71 |
|
65 |
$uuid = $descriptionElement->uuid; |
|
66 | 72 |
$feature = $descriptionElement->feature; |
67 | 73 |
$medias = $descriptionElement->media; |
68 | 74 |
|
... | ... | |
76 | 82 |
$out .= theme('cdm_media_mime_' . $contentTypeDirectory, array('mediaRepresentation' => $mediaRepresentation, 'feature' => $feature)); |
77 | 83 |
} |
78 | 84 |
else { |
79 |
// No media available, so display just the type term. |
|
80 |
$out .= $feature->representation_L10n; |
|
85 |
// Media has empty or corrupt representation |
|
86 |
if(user_is_logged_in()){ |
|
87 |
drupal_set_message('The media entity (' . l($media->uuid, path_to_media($media->uuid)) .') has empty or corrupt representation parts. Maybe the URI is empty.' , 'warning'); |
|
88 |
} |
|
81 | 89 |
} |
82 | 90 |
} |
83 | 91 |
return $out; |
modules/cdm_dataportal/theme/theme_registry.inc | ||
---|---|---|
85 | 85 |
'cdm_block_Uses' => array('variables' => array('taxonUuid' => NULL)), |
86 | 86 |
|
87 | 87 |
// Themes in cdm_dataportal.media.theme. |
88 |
'cdm_media' => array('variables' => array('descriptionElement' => NULL, 'mimeTypePreference' => NULL)), |
|
89 | 88 |
'cdm_media_mime_application' => array('variables' => array('mediaRepresentation' => NULL, 'feature' => NULL)), |
90 | 89 |
'cdm_media_mime_image' => array('variables' => array('mediaRepresentation' => NULL, 'feature' => NULL)), |
91 | 90 |
'cdm_media_mime_text' => array('variables' => array('mediaRepresentation' => NULL, 'feature' => NULL)), |
Also available in: Unified diff
fix #5948 supressing media when uri is missing, also turning theme function into plain markup function