1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Reference theming functions.
|
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
|
|
16
|
|
17
|
/**
|
18
|
* Creates a HTML representations for a CDM Reference instance..
|
19
|
*
|
20
|
* Used by:
|
21
|
* - theme_cdm_typedesignations
|
22
|
* - cdm_reference_pager
|
23
|
* - cdm_taxonRelationships
|
24
|
*
|
25
|
* @param array $variables
|
26
|
* An associative array containing:
|
27
|
* - reference
|
28
|
* - microReference
|
29
|
* - doLink:
|
30
|
* Whether to create a link to the reference page, links to the reference URI or DOI are always
|
31
|
* created when this data is available
|
32
|
* - referenceStyle: the value "zoology" will cause a specific rendeting of the
|
33
|
* reference suitable for zoological publications.
|
34
|
*
|
35
|
* @return string
|
36
|
* the markup for the reference
|
37
|
*
|
38
|
* @ingroup themeable
|
39
|
*/
|
40
|
function theme_cdm_reference($variables) {
|
41
|
$reference = $variables['reference'];
|
42
|
$microReference = $variables['microReference'];
|
43
|
$doLink = $variables['doLink'];
|
44
|
$referenceStyle = $variables['referenceStyle'];
|
45
|
|
46
|
if (!isset($reference->authorship)) {
|
47
|
$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
|
48
|
}
|
49
|
else {
|
50
|
$author_team = $reference->authorship;
|
51
|
}
|
52
|
|
53
|
if ($referenceStyle == "zoology") {
|
54
|
$year = '';
|
55
|
if (isset($reference->datePublished->start)) {
|
56
|
$year = partialToYear($reference->datePublished->start);
|
57
|
}
|
58
|
$citation = $author_team->titleCache . (!empty($year) ? '. ' . $year : '');
|
59
|
}
|
60
|
else {
|
61
|
$citation = $reference->titleCache;
|
62
|
}
|
63
|
|
64
|
if (isset($doLink) && $doLink === TRUE) {
|
65
|
$out = '<span class="reference">';
|
66
|
$out .= l($citation, path_to_reference($reference->uuid), array(
|
67
|
'attributes' => array(
|
68
|
"class" => "reference",
|
69
|
),
|
70
|
'absolute' => TRUE,
|
71
|
'html' => TRUE,
|
72
|
));
|
73
|
$out .= '</span>';
|
74
|
}
|
75
|
else {
|
76
|
$out = '<span class="reference">' . $citation . '</span>';
|
77
|
}
|
78
|
|
79
|
if (!empty($microReference)) {
|
80
|
$out .= ": " . $microReference;
|
81
|
}
|
82
|
|
83
|
if(isset($reference->doi)){
|
84
|
$out .= cdm_doi($reference->doi);
|
85
|
$doi_resolve_uri = 'http://doi.org/' . $reference->doi->prefix;
|
86
|
if(isset($reference->doi->suffix)){
|
87
|
$doi_resolve_uri .= '/' . $reference->doi->suffix;
|
88
|
}
|
89
|
}
|
90
|
|
91
|
if (isset($reference->uri)){
|
92
|
$out .= cdm_external_uri($reference->uri);
|
93
|
}
|
94
|
|
95
|
return $out;
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* @param $reference
|
100
|
* @param $out
|
101
|
* @return string
|
102
|
*/
|
103
|
function cdm_external_uri($uri, $iconified = true)
|
104
|
{
|
105
|
if (!empty($uri)) {
|
106
|
if($iconified){
|
107
|
return l(font_awesome_icon_markup('fa-external-link', array('class' => array('superscript'))), $uri, array('html' => TRUE));
|
108
|
} else {
|
109
|
return l($uri, $uri);
|
110
|
}
|
111
|
}
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* Creates markup for a CDM Doi entity.
|
116
|
*
|
117
|
* @param $doi
|
118
|
* The CDM DOI
|
119
|
*
|
120
|
* @return string
|
121
|
* Markup
|
122
|
*/
|
123
|
function cdm_doi($doi, $iconified = true) {
|
124
|
|
125
|
if (!empty($doi)) {
|
126
|
|
127
|
$doi_resolve_uri = 'http://doi.org/' . $doi->prefix;
|
128
|
if (isset($doi->suffix)) {
|
129
|
$doi_resolve_uri .= '/' . $doi->suffix;
|
130
|
}
|
131
|
if($iconified){
|
132
|
return l(font_awesome_icon_markup('fa-external-link-square', array('class' => array('superscript'))), $doi_resolve_uri, array('html' => TRUE));
|
133
|
} else {
|
134
|
return l($doi_resolve_uri, $doi_resolve_uri);
|
135
|
}
|
136
|
}
|
137
|
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* @todo Please document this function.
|
142
|
* @see http://drupal.org/node/1354
|
143
|
*/
|
144
|
function theme_cdm_OriginalSource($variables) {
|
145
|
$out = '';
|
146
|
$source = $variables['source'];
|
147
|
$do_link_to_reference = $variables['doLink'];
|
148
|
$do_link_to_name_used_in_source = $variables['do_link_to_name_used_in_source'];
|
149
|
|
150
|
if (isset($source->citation)) {
|
151
|
$out = theme('cdm_reference', array(
|
152
|
'reference' => $source->citation,
|
153
|
'microReference' => $source->citationMicroReference,
|
154
|
'doLink' => $do_link_to_reference,
|
155
|
));
|
156
|
|
157
|
$name_in_source_render_array = compose_name_in_source($source, $do_link_to_name_used_in_source);
|
158
|
if(!empty($name_in_source_render_array)) {
|
159
|
$out .= ' <span class="nameUsedInSource">(' . t('as') . ' ' . $name_in_source_render_array['#markup'] . ')</span>';
|
160
|
}
|
161
|
|
162
|
$id_with_namespace = '';
|
163
|
if( isset($source->idNamespace) && $source->idNamespace ) {
|
164
|
$id_with_namespace = $source->idNamespace . '/';
|
165
|
}
|
166
|
if( isset($source->idInSource) && $source->idInSource ) {
|
167
|
$id_with_namespace .= $source->idInSource;
|
168
|
} else {
|
169
|
$id_with_namespace = NULL;
|
170
|
}
|
171
|
|
172
|
if($id_with_namespace){
|
173
|
$out .= ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
|
174
|
}
|
175
|
}
|
176
|
return $out;
|
177
|
}
|