1 |
6657531f
|
Andreas Kohlbecker
|
<?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 |
43998144
|
Andreas Kohlbecker
|
* Creates a HTML representations for a CDM Reference instance..
|
19 |
6657531f
|
Andreas Kohlbecker
|
*
|
20 |
|
|
* Used by:
|
21 |
|
|
* - theme_cdm_typedesignations
|
22 |
b2ebf0d3
|
Andreas Kohlbecker
|
* - cdm_reference_pager
|
23 |
b7a20282
|
Andreas Kohlbecker
|
* - cdm_taxonRelationships
|
24 |
6657531f
|
Andreas Kohlbecker
|
*
|
25 |
|
|
* @param array $variables
|
26 |
|
|
* An associative array containing:
|
27 |
|
|
* - reference
|
28 |
|
|
* - microReference
|
29 |
0639ca2a
|
Andreas Kohlbecker
|
* - 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 |
43998144
|
Andreas Kohlbecker
|
* - 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 |
6657531f
|
Andreas Kohlbecker
|
*
|
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 |
1b57b3c1
|
Andreas Kohlbecker
|
|
46 |
0639ca2a
|
Andreas Kohlbecker
|
if (!isset($reference->authorship)) {
|
47 |
f0bf24e7
|
Andreas Kohlbecker
|
$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
|
48 |
0639ca2a
|
Andreas Kohlbecker
|
}
|
49 |
|
|
else {
|
50 |
1ce9afb7
|
Patric Plitzner
|
$author_team = $reference->authorship;
|
51 |
f0bf24e7
|
Andreas Kohlbecker
|
}
|
52 |
6657531f
|
Andreas Kohlbecker
|
if ($referenceStyle == "zoology") {
|
53 |
|
|
$year = '';
|
54 |
c7f92453
|
Andreas Kohlbecker
|
if (isset($reference->datePublished)) {
|
55 |
|
|
$year = timePeriodToString($reference->datePublished, true, 'YYYY');
|
56 |
6657531f
|
Andreas Kohlbecker
|
}
|
57 |
|
|
$citation = $author_team->titleCache . (!empty($year) ? '. ' . $year : '');
|
58 |
|
|
}
|
59 |
|
|
else {
|
60 |
|
|
$citation = $reference->titleCache;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
b9a4f351
|
Andreas Kohlbecker
|
$citation = trim($citation);
|
64 |
6657531f
|
Andreas Kohlbecker
|
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 |
0a288588
|
Andreas Kohlbecker
|
if(isset($reference->doi)){
|
84 |
|
|
$out .= cdm_doi($reference->doi);
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
if (isset($reference->uri)){
|
88 |
27bceb70
|
Andreas Kohlbecker
|
if($reference->type == 'WebPage'){
|
89 |
|
|
// the cdm cache strategy adds the uri to the titleCache which is unwanted in this case,
|
90 |
|
|
// so is is removed from there
|
91 |
|
|
$out = str_replace('- ' . $reference->uri, '', $out);
|
92 |
|
|
}
|
93 |
0a288588
|
Andreas Kohlbecker
|
$out .= cdm_external_uri($reference->uri);
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
return $out;
|
97 |
|
|
}
|
98 |
9091d35a
|
Andreas Kohlbecker
|
|
99 |
0a288588
|
Andreas Kohlbecker
|
/**
|
100 |
723aa98c
|
Andreas Kohlbecker
|
* Creates a anchor tag as clickable link to an external resource, either as text link or as icon.
|
101 |
|
|
* The resulting link will have no 'target' attribute, so the link will open in the same tab by default.
|
102 |
|
|
* So the users can decide.
|
103 |
|
|
*
|
104 |
|
|
* @param $uri
|
105 |
|
|
* The uri to link to
|
106 |
|
|
* @param $iconified
|
107 |
|
|
* The link will be rendered as icon of this is true.
|
108 |
0a288588
|
Andreas Kohlbecker
|
* @return string
|
109 |
723aa98c
|
Andreas Kohlbecker
|
*
|
110 |
0a288588
|
Andreas Kohlbecker
|
*/
|
111 |
|
|
function cdm_external_uri($uri, $iconified = true)
|
112 |
|
|
{
|
113 |
723aa98c
|
Andreas Kohlbecker
|
$options = array(
|
114 |
|
|
'external' => true,
|
115 |
|
|
'html' => false,
|
116 |
|
|
);
|
117 |
0a288588
|
Andreas Kohlbecker
|
if (!empty($uri)) {
|
118 |
|
|
if($iconified){
|
119 |
723aa98c
|
Andreas Kohlbecker
|
$options['html'] = true;
|
120 |
|
|
return l(font_awesome_icon_markup('fa-external-link', array('class' => array('superscript'))), $uri, $options);
|
121 |
0a288588
|
Andreas Kohlbecker
|
} else {
|
122 |
723aa98c
|
Andreas Kohlbecker
|
return l($uri, $uri, $options);
|
123 |
9091d35a
|
Andreas Kohlbecker
|
}
|
124 |
0639ca2a
|
Andreas Kohlbecker
|
}
|
125 |
0a288588
|
Andreas Kohlbecker
|
}
|
126 |
|
|
|
127 |
|
|
/**
|
128 |
|
|
* Creates markup for a CDM Doi entity.
|
129 |
|
|
*
|
130 |
|
|
* @param $doi
|
131 |
|
|
* The CDM DOI
|
132 |
|
|
*
|
133 |
|
|
* @return string
|
134 |
|
|
* Markup
|
135 |
|
|
*/
|
136 |
|
|
function cdm_doi($doi, $iconified = true) {
|
137 |
|
|
|
138 |
|
|
if (!empty($doi)) {
|
139 |
|
|
|
140 |
|
|
$doi_resolve_uri = 'http://doi.org/' . $doi->prefix;
|
141 |
|
|
if (isset($doi->suffix)) {
|
142 |
|
|
$doi_resolve_uri .= '/' . $doi->suffix;
|
143 |
|
|
}
|
144 |
|
|
if($iconified){
|
145 |
|
|
return l(font_awesome_icon_markup('fa-external-link-square', array('class' => array('superscript'))), $doi_resolve_uri, array('html' => TRUE));
|
146 |
|
|
} else {
|
147 |
|
|
return l($doi_resolve_uri, $doi_resolve_uri);
|
148 |
|
|
}
|
149 |
0639ca2a
|
Andreas Kohlbecker
|
}
|
150 |
|
|
|
151 |
6657531f
|
Andreas Kohlbecker
|
}
|
152 |
|
|
|
153 |
f3a04cfa
|
Andreas Kohlbecker
|
/**
|
154 |
bb93d5d1
|
Andreas Kohlbecker
|
* Renders a representation for an CDM OriginalSourceBase entity
|
155 |
|
|
*
|
156 |
|
|
* @param $source
|
157 |
|
|
* The cdm OriginalSourceBase entity
|
158 |
|
|
* @param $do_link_to_reference
|
159 |
|
|
* @param $do_link_to_name_used_in_source
|
160 |
|
|
* @return string
|
161 |
f3a04cfa
|
Andreas Kohlbecker
|
*/
|
162 |
44707ee3
|
Andreas Kohlbecker
|
function render_original_source($source, $do_link_to_reference = true, $do_link_to_name_used_in_source = false) {
|
163 |
f3a04cfa
|
Andreas Kohlbecker
|
$out = '';
|
164 |
|
|
|
165 |
1b04a204
|
Andreas Kohlbecker
|
if (isset($source->citation)) {
|
166 |
f3a04cfa
|
Andreas Kohlbecker
|
$out = theme('cdm_reference', array(
|
167 |
|
|
'reference' => $source->citation,
|
168 |
|
|
'microReference' => $source->citationMicroReference,
|
169 |
bb3188cb
|
Andreas Kohlbecker
|
'doLink' => $do_link_to_reference,
|
170 |
f3a04cfa
|
Andreas Kohlbecker
|
));
|
171 |
dcf17487
|
Andreas Kohlbecker
|
|
172 |
bb3188cb
|
Andreas Kohlbecker
|
$name_in_source_render_array = compose_name_in_source($source, $do_link_to_name_used_in_source);
|
173 |
|
|
if(!empty($name_in_source_render_array)) {
|
174 |
|
|
$out .= ' <span class="nameUsedInSource">(' . t('as') . ' ' . $name_in_source_render_array['#markup'] . ')</span>';
|
175 |
046b235b
|
Andreas Kohlbecker
|
}
|
176 |
8ca88c4e
|
Andreas Kohlbecker
|
|
177 |
|
|
$id_with_namespace = '';
|
178 |
|
|
if( isset($source->idNamespace) && $source->idNamespace ) {
|
179 |
05c57463
|
Andreas Kohlbecker
|
$id_with_namespace = $source->idNamespace . ' ';
|
180 |
8ca88c4e
|
Andreas Kohlbecker
|
}
|
181 |
8af64a68
|
Andreas Kohlbecker
|
if( isset($source->idInSource) && $source->idInSource ) {
|
182 |
8ca88c4e
|
Andreas Kohlbecker
|
$id_with_namespace .= $source->idInSource;
|
183 |
|
|
} else {
|
184 |
|
|
$id_with_namespace = NULL;
|
185 |
|
|
}
|
186 |
44d445c0
|
Andreas Kohlbecker
|
|
187 |
8ca88c4e
|
Andreas Kohlbecker
|
if($id_with_namespace){
|
188 |
|
|
$out .= ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
|
189 |
f3a04cfa
|
Andreas Kohlbecker
|
}
|
190 |
|
|
}
|
191 |
|
|
return $out;
|
192 |
1b04a204
|
Andreas Kohlbecker
|
}
|