1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* footnote functions.
|
5
|
*
|
6
|
* @copyright
|
7
|
* (C) 2007-2020 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
|
* @author
|
16
|
* - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
|
17
|
*/
|
18
|
const FOOTNOTE_KEY_SUFFIX_ANNOTATIONS = '-annotations';
|
19
|
|
20
|
/**
|
21
|
* Creates the footnotes for the given CDM instance.
|
22
|
*
|
23
|
* Footnotes are created for annotations and original sources whereas the resulting footnote keys depend on the
|
24
|
* parameters $footnote_list_key_suggestion and $is_bibliography_aware, see parameter $footnote_list_key_suggestion
|
25
|
* for more details.
|
26
|
*
|
27
|
* possible keys for
|
28
|
* - annotation footnotes:
|
29
|
* - $footnote_list_key_suggestion
|
30
|
* - RenderHints::getFootnoteListKey().FOOTNOTE_KEY_SUFFIX_ANNOTATIONS
|
31
|
* - original source footnotes
|
32
|
* - "BIBLIOGRAPHY" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 1 )
|
33
|
* - "BIBLIOGRAPHY-$footnote_list_key_suggestion" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 0 )
|
34
|
* - $footnote_list_key_suggestion (when $is_bibliography_aware)
|
35
|
*
|
36
|
* @param $cdm_entity
|
37
|
* A CDM entity
|
38
|
* @param string $separator
|
39
|
* Optional parameter. The separator string to concatenate the footnote ids, default is ','
|
40
|
* @param $footnote_list_key_suggestion string
|
41
|
* Optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined by the nested
|
42
|
* method calls by calling RenderHints::getFootnoteListKey(). NOTE: the footnote key for annotations will be set to
|
43
|
* RenderHints::getFootnoteListKey().'-annotations'.
|
44
|
* @param bool $do_link_to_reference
|
45
|
* Create a link to the reference pages for sources when TRUE.
|
46
|
* @param bool $do_link_to_name_used_in_source
|
47
|
* Create a link to the name pages for name in source when TRUE.
|
48
|
* @param bool $is_bibliography_aware
|
49
|
* Put source references into the bibliography when this param is TRUE.
|
50
|
*
|
51
|
* @return String
|
52
|
* The foot note keys as markup
|
53
|
*
|
54
|
* @throws \Exception re-throw exception from theme()
|
55
|
* @see cdm_entities_annotations_footnote_keys()
|
56
|
* For original sources the $footnote_list_key_suggestion will be overwritten by bibliography_footnote_list_key() when
|
57
|
* $is_bibliography_aware is set TRUE.
|
58
|
* @$original_source_footnote_tag
|
59
|
* null will cause bibliography_footnote_list_key to use the default
|
60
|
*/
|
61
|
function render_entity_footnotes(
|
62
|
$cdm_entity,
|
63
|
$separator = ',',
|
64
|
$footnote_list_key_suggestion = null,
|
65
|
$do_link_to_reference = FALSE,
|
66
|
$do_link_to_name_used_in_source = FALSE,
|
67
|
$is_bibliography_aware = FALSE
|
68
|
){
|
69
|
|
70
|
$sources = cdm_entity_sources_sorted($cdm_entity);
|
71
|
|
72
|
// Annotations as footnotes.
|
73
|
$footnote_keys = cdm_entity_annotations_as_footnote_keys($cdm_entity, $footnote_list_key_suggestion);
|
74
|
|
75
|
// Source references as footnotes.
|
76
|
if($is_bibliography_aware){
|
77
|
$bibliography_settings = get_bibliography_settings();
|
78
|
$sources_footnote_list_key = bibliography_footnote_list_key($footnote_list_key_suggestion);
|
79
|
$original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // null will cause bibliography_footnote_list_key to use the default
|
80
|
} else {
|
81
|
$sources_footnote_list_key = $footnote_list_key_suggestion;
|
82
|
if(!$sources_footnote_list_key) {
|
83
|
RenderHints::getFootnoteListKey();
|
84
|
}
|
85
|
$original_source_footnote_tag = NULL;
|
86
|
}
|
87
|
|
88
|
foreach ($sources as $source) {
|
89
|
if (_is_original_source_type($source)) {
|
90
|
$fn_key = FootnoteManager::addNewFootnote(
|
91
|
$sources_footnote_list_key,
|
92
|
render_original_source(
|
93
|
$source,
|
94
|
$do_link_to_reference,
|
95
|
$do_link_to_name_used_in_source
|
96
|
),
|
97
|
$original_source_footnote_tag
|
98
|
);
|
99
|
// Ensure uniqueness of the footnote keys.
|
100
|
if(array_search($fn_key, $footnote_keys)=== false) {
|
101
|
$footnote_keys[] = $fn_key;
|
102
|
}
|
103
|
}
|
104
|
}
|
105
|
// Sort and render footnote keys.
|
106
|
asort($footnote_keys);
|
107
|
return render_footnote_keys($footnote_keys, $separator);
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Fetches the list of visible annotations for each of the cdm entities and returns the footnote keys for them.
|
112
|
*
|
113
|
* The footnotes are passed to the FootnoteManager in order to store the annotations and to create the footnote keys.
|
114
|
*
|
115
|
* @see cdm_fetch_visible_annotations()
|
116
|
*
|
117
|
* @param array $cdm_entities
|
118
|
* An array of CdmBase instances.
|
119
|
* @param $footnote_list_key_suggestion string
|
120
|
* optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined be set to
|
121
|
* RenderHints::getFootnoteListKey().FOOTNOTE_KEY_SUFFIX_ANNOTATIONS otherwise the supplied key will be used.
|
122
|
*
|
123
|
* @return array of footnote keys
|
124
|
*/
|
125
|
function cdm_entities_annotations_footnote_keys(array $cdm_entities, $footnote_list_key_suggestion = NULL) {
|
126
|
|
127
|
$foot_note_keys = [];
|
128
|
foreach ($cdm_entities as $cdm_entity) {
|
129
|
$foot_note_keys = array_merge($foot_note_keys, cdm_entity_annotations_as_footnote_keys($cdm_entity,$footnote_list_key_suggestion));
|
130
|
}
|
131
|
|
132
|
return $foot_note_keys;
|
133
|
}
|
134
|
|
135
|
/**
|
136
|
* Fetches the list of visible annotations for the cdm entity or for the comparable
|
137
|
* object and returns the footnote keys.
|
138
|
*
|
139
|
* The footnotes are passed to the FootnoteManager in order to store the
|
140
|
* annotations and to create the footnote keys.
|
141
|
|
142
|
* @param stdClass $cdm_entity
|
143
|
* A single CdmBase instance ore comparable object.
|
144
|
* @param $footnote_list_key_suggestion string
|
145
|
* optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined be set to
|
146
|
* RenderHints::getFootnoteListKey().'-annotations' otherwise the supplied key will be used.
|
147
|
* @return array of footnote keys
|
148
|
*
|
149
|
* @see cdm_fetch_visible_annotations()
|
150
|
*/
|
151
|
function cdm_entity_annotations_as_footnote_keys(stdClass $cdm_entity, $footnote_list_key_suggestion = NULL) {
|
152
|
|
153
|
$foot_note_keys = [];
|
154
|
|
155
|
// Getting the key for the FootnoteManager.
|
156
|
if (isset($footnote_list_key_suggestion)) {
|
157
|
$footnote_list_key = $footnote_list_key_suggestion;
|
158
|
} else {
|
159
|
$footnote_list_key = RenderHints::getFootnoteListKey() . FOOTNOTE_KEY_SUFFIX_ANNOTATIONS;
|
160
|
}
|
161
|
|
162
|
// Adding the footnotes keys.
|
163
|
$annotations = cdm_fetch_visible_annotations($cdm_entity);
|
164
|
if (is_array($annotations)) {
|
165
|
foreach ($annotations as $annotation) {
|
166
|
$foot_note_keys[] = FootnoteManager::addNewFootnote($footnote_list_key, $annotation->text);
|
167
|
}
|
168
|
}
|
169
|
|
170
|
return $foot_note_keys;
|
171
|
}
|
172
|
|
173
|
/**
|
174
|
* Created and registers footnotes in the FootnoteManager and returns the
|
175
|
* footnote keys as markup.
|
176
|
*
|
177
|
* The following cdm cdm classes are annotatable:
|
178
|
*
|
179
|
* - DescriptionElementBase
|
180
|
* - EventBase
|
181
|
* - HomotypicalGroup
|
182
|
* - IdentifiableEntity
|
183
|
* - DescriptionBase
|
184
|
* - IdentifiableMediaEntity
|
185
|
* - Media
|
186
|
* - Sequence
|
187
|
* - TaxonBase
|
188
|
* - TaxonName
|
189
|
* - TaxonomicTree
|
190
|
* - TermBase
|
191
|
* - LanguageStringBase
|
192
|
* - ReferencedEntityBase
|
193
|
* - NomenclaturalStatus
|
194
|
* - OriginalSourceBase
|
195
|
* - RelationshipBase
|
196
|
* - TypeDesignationBase
|
197
|
* - TaxonNode
|
198
|
* - WorkingSet
|
199
|
*
|
200
|
* @param array $cdm_entities
|
201
|
* An array of CdmBase instances.
|
202
|
* @param $footnote_list_key_suggestion string
|
203
|
* optional parameter. If this parameter is left empty (null, 0, "") the
|
204
|
* footnote key will be determined be set to
|
205
|
* RenderHints::getFootnoteListKey().FOOTNOTE_KEY_SUFFIX_ANNOTATIONS otherwise the supplied
|
206
|
* key will be used.
|
207
|
*
|
208
|
* @return string
|
209
|
* The markup.
|
210
|
*/
|
211
|
function render_entities_annotations_as_footnote_keys(array $cdm_entities, $footnote_list_key =null){
|
212
|
|
213
|
// check if footnotes for annotations are disabled completely
|
214
|
if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
215
|
return '';
|
216
|
}
|
217
|
$markup = '';
|
218
|
$footNoteKeys = cdm_entities_annotations_footnote_keys($cdm_entities, $footnote_list_key);
|
219
|
foreach ($footNoteKeys as $a) {
|
220
|
$markup .= render_footnote_key($a, ($markup ? ',' : ''));
|
221
|
}
|
222
|
return $markup;
|
223
|
}
|
224
|
|
225
|
/**
|
226
|
* Creates markup for an array of foot note keys
|
227
|
*
|
228
|
* @param array $footnote_keys
|
229
|
* @param string $separator
|
230
|
*
|
231
|
* @return string
|
232
|
*/
|
233
|
function render_footnote_keys(array $footnote_keys, $separator) {
|
234
|
|
235
|
$footnotes_markup = '';
|
236
|
foreach ($footnote_keys as $foot_note_key) {
|
237
|
try {
|
238
|
$footnotes_markup .= render_footnote_key($foot_note_key, ($footnotes_markup ? $separator : ''));
|
239
|
} catch (Exception $e) {
|
240
|
drupal_set_message("Exception: " . $e->getMessage(), 'error');
|
241
|
}
|
242
|
}
|
243
|
return $footnotes_markup;
|
244
|
}
|
245
|
|
246
|
/**
|
247
|
* Create markup for the footnotes mapped to the $footnoteListKey.
|
248
|
*
|
249
|
* @param null $footnote_list_key
|
250
|
* The footnote list key, see RenderHints::getFootnoteListKey()
|
251
|
* @param $element_tag
|
252
|
* The tag for the footnote element
|
253
|
*
|
254
|
* @return string
|
255
|
* @throws \Exception
|
256
|
*/
|
257
|
function render_annotation_footnotes($footnote_list_key = null, $element_tag = 'span') {
|
258
|
if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
259
|
return '';
|
260
|
}
|
261
|
return render_footnotes($footnote_list_key . FOOTNOTE_KEY_SUFFIX_ANNOTATIONS, $element_tag);
|
262
|
}
|
263
|
|
264
|
/**
|
265
|
* Creates markup for a foot note key
|
266
|
*
|
267
|
* @param null $footnoteKey
|
268
|
* @param string $separator
|
269
|
* @param bool $separator_off
|
270
|
*
|
271
|
* @return string
|
272
|
* The footnote key markup
|
273
|
*/
|
274
|
function render_footnote_key($footnoteKey = null, $separator = '', $separator_off = false) {
|
275
|
|
276
|
if (!is_object($footnoteKey) or !isset($footnoteKey->footnoteListKey)) {
|
277
|
return '';
|
278
|
}
|
279
|
if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
280
|
return '';
|
281
|
}
|
282
|
|
283
|
if ($separator_off) {
|
284
|
$separator = '';
|
285
|
}
|
286
|
$out = '<span class="footnote-key footnote-key-' . $footnoteKey->keyStr . ' member-of-footnotes-' . $footnoteKey->footnoteListKey . '">'
|
287
|
. $separator . '<a href="#footnote-' . $footnoteKey->keyStr . '">' . $footnoteKey->keyStr . '</a>' . '</span>';
|
288
|
return $out;
|
289
|
}
|
290
|
|
291
|
/**
|
292
|
* @param null $footnoteKey
|
293
|
* @param null $footnoteText
|
294
|
* @param string $enclosing_tag
|
295
|
* default is 'span'
|
296
|
*
|
297
|
* @return string
|
298
|
*/
|
299
|
function render_footnote($footnoteKey = null, $footnoteText = null, $enclosing_tag = 'span') {
|
300
|
_add_js_footnotes();
|
301
|
if($enclosing_tag == null){
|
302
|
$enclosing_tag = 'span';
|
303
|
}
|
304
|
return '<' . $enclosing_tag . ' class="footnote footnote-' . $footnoteKey . '">'
|
305
|
. '<a name="footnote-' . $footnoteKey . '"></a>'
|
306
|
. '<span class="footnote-anchor">' . $footnoteKey . '.</span> ' . $footnoteText
|
307
|
. '</' . $enclosing_tag . '>';
|
308
|
}
|
309
|
|
310
|
|
311
|
|
312
|
/**
|
313
|
* Create markup for the footnotes mapped to the $footnoteListKey.
|
314
|
*
|
315
|
* @param null $footnote_list_key
|
316
|
* The footnote list key, see RenderHints::getFootnoteListKey()
|
317
|
* @param $element_tag
|
318
|
* The tag for the footnote element
|
319
|
*
|
320
|
* @return string
|
321
|
*/
|
322
|
function render_footnotes($footnote_list_key = null, $element_tag = 'span') {
|
323
|
|
324
|
if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
325
|
return '';
|
326
|
}
|
327
|
|
328
|
$out = '<' . $element_tag . ' class="footnotes footnotes-' . $footnote_list_key . ' ">'
|
329
|
. FootnoteManager::renderFootnoteList($footnote_list_key)
|
330
|
. '</' . $element_tag . '>';
|
331
|
|
332
|
FootnoteManager::removeFootnoteList($footnote_list_key);
|
333
|
return $out;
|
334
|
}
|
335
|
|
336
|
/**
|
337
|
* Renders the footnotes for annotations and sources, etc.
|
338
|
*
|
339
|
* @param string $footnote_list_key
|
340
|
* RenderHints::getFootnoteListKey() will be used if this parameter is undefined.
|
341
|
* @param string $enclosingTag
|
342
|
* Default tag is 'span'
|
343
|
*
|
344
|
* @return string
|
345
|
* The markup string
|
346
|
*
|
347
|
*/
|
348
|
function render_cdm_footnotes($footnote_list_key = NULL, $enclosingTag = 'span'){
|
349
|
|
350
|
if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
351
|
return '';
|
352
|
}
|
353
|
if(!$footnote_list_key){
|
354
|
$footnote_list_key = RenderHints::getFootnoteListKey();
|
355
|
}
|
356
|
|
357
|
$out = '<' . $enclosingTag . ' class="footnotes footnotes-' . $footnote_list_key . ' ">'
|
358
|
. FootnoteManager::renderFootnoteList($footnote_list_key . FOOTNOTE_KEY_SUFFIX_ANNOTATIONS) . ' ' . FootnoteManager::renderFootnoteList($footnote_list_key)
|
359
|
. '</' . $enclosingTag . '>';
|
360
|
FootnoteManager::removeFootnoteList($footnote_list_key . FOOTNOTE_KEY_SUFFIX_ANNOTATIONS);
|
361
|
FootnoteManager::removeFootnoteList($footnote_list_key);
|
362
|
return $out;
|
363
|
}
|