1 |
dd0767b6
|
Andreas Kohlbecker
|
<?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 |
|
|
|
19 |
|
|
/**
|
20 |
|
|
* Creates the footnotes for the given CDM instance.
|
21 |
|
|
*
|
22 |
|
|
* Footnotes are created for annotations and original sources whereas the resulting footnote keys depend on the
|
23 |
|
|
* parameters $footnote_list_key_suggestion and $is_bibliography_aware, see parameter $footnote_list_key_suggestion
|
24 |
|
|
* for more details.
|
25 |
|
|
*
|
26 |
d0d0a092
|
Andreas Kohlbecker
|
* possible keys for annotation and source footnotes:
|
27 |
dd0767b6
|
Andreas Kohlbecker
|
* - $footnote_list_key_suggestion
|
28 |
d0d0a092
|
Andreas Kohlbecker
|
* - RenderHints::getFootnoteListKey()
|
29 |
dd0767b6
|
Andreas Kohlbecker
|
* - original source footnotes
|
30 |
|
|
* - "BIBLIOGRAPHY" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 1 )
|
31 |
|
|
* - "BIBLIOGRAPHY-$footnote_list_key_suggestion" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 0 )
|
32 |
|
|
* - $footnote_list_key_suggestion (when $is_bibliography_aware)
|
33 |
|
|
*
|
34 |
fe064e2d
|
Andreas Kohlbecker
|
* @param $cdm_entity
|
35 |
|
|
* A CDM entity
|
36 |
dd0767b6
|
Andreas Kohlbecker
|
* @param string $separator
|
37 |
|
|
* Optional parameter. The separator string to concatenate the footnote ids, default is ','
|
38 |
|
|
* @param $footnote_list_key_suggestion string
|
39 |
|
|
* Optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined by the nested
|
40 |
d0d0a092
|
Andreas Kohlbecker
|
* method calls by calling RenderHints::getFootnoteListKey().
|
41 |
51ace96f
|
Andreas Kohlbecker
|
* For original sources the $footnote_list_key_suggestion will be overwritten by bibliography_footnote_list_key() when
|
42 |
|
|
* $is_bibliography_aware is set TRUE.
|
43 |
dd0767b6
|
Andreas Kohlbecker
|
* @param bool $do_link_to_reference
|
44 |
|
|
* Create a link to the reference pages for sources when TRUE.
|
45 |
|
|
* @param bool $do_link_to_name_used_in_source
|
46 |
|
|
* Create a link to the name pages for name in source when TRUE.
|
47 |
|
|
* @param bool $is_bibliography_aware
|
48 |
|
|
* Put source references into the bibliography when this param is TRUE.
|
49 |
51ace96f
|
Andreas Kohlbecker
|
* For original sources the $footnote_list_key_suggestion will be overwritten
|
50 |
|
|
* by bibliography_footnote_list_key() when
|
51 |
|
|
* $is_bibliography_aware is set TRUE.
|
52 |
dd0767b6
|
Andreas Kohlbecker
|
* @return String
|
53 |
d8069342
|
Andreas Kohlbecker
|
* The foot note keys as markup
|
54 |
dd0767b6
|
Andreas Kohlbecker
|
*
|
55 |
51ace96f
|
Andreas Kohlbecker
|
* NOTE: Only used in @see handle_annotations_and_sources()
|
56 |
dd0767b6
|
Andreas Kohlbecker
|
*/
|
57 |
d8069342
|
Andreas Kohlbecker
|
function render_entity_footnotes(
|
58 |
fe064e2d
|
Andreas Kohlbecker
|
$cdm_entity,
|
59 |
dd0767b6
|
Andreas Kohlbecker
|
$separator = ',',
|
60 |
|
|
$footnote_list_key_suggestion = null,
|
61 |
|
|
$do_link_to_reference = FALSE,
|
62 |
|
|
$do_link_to_name_used_in_source = FALSE,
|
63 |
|
|
$is_bibliography_aware = FALSE
|
64 |
|
|
){
|
65 |
|
|
|
66 |
fe064e2d
|
Andreas Kohlbecker
|
$sources = cdm_entity_sources_sorted($cdm_entity);
|
67 |
dd0767b6
|
Andreas Kohlbecker
|
|
68 |
1c30a02b
|
Andreas Kohlbecker
|
if (!isset($footnote_list_key_suggestion) || !$footnote_list_key_suggestion) {
|
69 |
|
|
$footnote_list_key_suggestion = RenderHints::getFootnoteListKey();
|
70 |
|
|
}
|
71 |
|
|
|
72 |
dd0767b6
|
Andreas Kohlbecker
|
// Annotations as footnotes.
|
73 |
fe064e2d
|
Andreas Kohlbecker
|
$footnote_keys = cdm_entity_annotations_as_footnote_keys($cdm_entity, $footnote_list_key_suggestion);
|
74 |
dd0767b6
|
Andreas Kohlbecker
|
|
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 |
|
|
$original_source_footnote_tag = NULL;
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
foreach ($sources as $source) {
|
86 |
|
|
if (_is_original_source_type($source)) {
|
87 |
|
|
$fn_key = FootnoteManager::addNewFootnote(
|
88 |
|
|
$sources_footnote_list_key,
|
89 |
|
|
render_original_source(
|
90 |
|
|
$source,
|
91 |
|
|
$do_link_to_reference,
|
92 |
|
|
$do_link_to_name_used_in_source
|
93 |
|
|
),
|
94 |
|
|
$original_source_footnote_tag
|
95 |
|
|
);
|
96 |
|
|
// Ensure uniqueness of the footnote keys.
|
97 |
fe064e2d
|
Andreas Kohlbecker
|
if(array_search($fn_key, $footnote_keys)=== false) {
|
98 |
|
|
$footnote_keys[] = $fn_key;
|
99 |
|
|
}
|
100 |
dd0767b6
|
Andreas Kohlbecker
|
}
|
101 |
|
|
}
|
102 |
|
|
// Sort and render footnote keys.
|
103 |
|
|
asort($footnote_keys);
|
104 |
d8069342
|
Andreas Kohlbecker
|
return render_footnote_keys($footnote_keys, $separator);
|
105 |
dd0767b6
|
Andreas Kohlbecker
|
}
|
106 |
|
|
|
107 |
|
|
/**
|
108 |
|
|
* Fetches the list of visible annotations for the cdm entity or for the comparable
|
109 |
|
|
* object and returns the footnote keys.
|
110 |
|
|
*
|
111 |
|
|
* The footnotes are passed to the FootnoteManager in order to store the
|
112 |
|
|
* annotations and to create the footnote keys.
|
113 |
|
|
|
114 |
|
|
* @param stdClass $cdm_entity
|
115 |
|
|
* A single CdmBase instance ore comparable object.
|
116 |
d0d0a092
|
Andreas Kohlbecker
|
* @param $footnote_list_key string
|
117 |
|
|
* optional parameter. If this parameter is left empty (null, 0, "") the
|
118 |
|
|
* footnote key will be set to RenderHints::getFootnoteListKey()
|
119 |
|
|
* otherwise the supplied $footnote_list_key will be used.
|
120 |
dd0767b6
|
Andreas Kohlbecker
|
* @return array of footnote keys
|
121 |
|
|
*
|
122 |
|
|
* @see cdm_fetch_visible_annotations()
|
123 |
|
|
*/
|
124 |
d0d0a092
|
Andreas Kohlbecker
|
function cdm_entity_annotations_as_footnote_keys(stdClass $cdm_entity, $footnote_list_key = NULL) {
|
125 |
dd0767b6
|
Andreas Kohlbecker
|
|
126 |
|
|
$foot_note_keys = [];
|
127 |
|
|
|
128 |
d0d0a092
|
Andreas Kohlbecker
|
if (!isset($footnote_list_key) || !$footnote_list_key) {
|
129 |
|
|
$footnote_list_key = RenderHints::getFootnoteListKey();
|
130 |
dd0767b6
|
Andreas Kohlbecker
|
}
|
131 |
|
|
|
132 |
|
|
// Adding the footnotes keys.
|
133 |
|
|
$annotations = cdm_fetch_visible_annotations($cdm_entity);
|
134 |
|
|
if (is_array($annotations)) {
|
135 |
|
|
foreach ($annotations as $annotation) {
|
136 |
|
|
$foot_note_keys[] = FootnoteManager::addNewFootnote($footnote_list_key, $annotation->text);
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
return $foot_note_keys;
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
/**
|
144 |
|
|
* Creates markup for an array of foot note keys
|
145 |
|
|
*
|
146 |
|
|
* @param array $footnote_keys
|
147 |
|
|
* @param string $separator
|
148 |
|
|
*
|
149 |
|
|
* @return string
|
150 |
|
|
*/
|
151 |
d8069342
|
Andreas Kohlbecker
|
function render_footnote_keys(array $footnote_keys, $separator) {
|
152 |
dd0767b6
|
Andreas Kohlbecker
|
|
153 |
|
|
$footnotes_markup = '';
|
154 |
|
|
foreach ($footnote_keys as $foot_note_key) {
|
155 |
|
|
try {
|
156 |
d8069342
|
Andreas Kohlbecker
|
$footnotes_markup .= render_footnote_key($foot_note_key, ($footnotes_markup ? $separator : ''));
|
157 |
dd0767b6
|
Andreas Kohlbecker
|
} catch (Exception $e) {
|
158 |
|
|
drupal_set_message("Exception: " . $e->getMessage(), 'error');
|
159 |
|
|
}
|
160 |
|
|
}
|
161 |
|
|
return $footnotes_markup;
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
/**
|
165 |
|
|
* Creates markup for a foot note key
|
166 |
|
|
*
|
167 |
|
|
* @param null $footnoteKey
|
168 |
|
|
* @param string $separator
|
169 |
|
|
* @param bool $separator_off
|
170 |
|
|
*
|
171 |
|
|
* @return string
|
172 |
|
|
* The footnote key markup
|
173 |
|
|
*/
|
174 |
d8069342
|
Andreas Kohlbecker
|
function render_footnote_key($footnoteKey = null, $separator = '', $separator_off = false) {
|
175 |
dd0767b6
|
Andreas Kohlbecker
|
|
176 |
|
|
if (!is_object($footnoteKey) or !isset($footnoteKey->footnoteListKey)) {
|
177 |
|
|
return '';
|
178 |
|
|
}
|
179 |
|
|
if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
180 |
|
|
return '';
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
if ($separator_off) {
|
184 |
|
|
$separator = '';
|
185 |
|
|
}
|
186 |
|
|
$out = '<span class="footnote-key footnote-key-' . $footnoteKey->keyStr . ' member-of-footnotes-' . $footnoteKey->footnoteListKey . '">'
|
187 |
|
|
. $separator . '<a href="#footnote-' . $footnoteKey->keyStr . '">' . $footnoteKey->keyStr . '</a>' . '</span>';
|
188 |
|
|
return $out;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
/**
|
192 |
|
|
* @param null $footnoteKey
|
193 |
|
|
* @param null $footnoteText
|
194 |
|
|
* @param string $enclosing_tag
|
195 |
|
|
* default is 'span'
|
196 |
|
|
*
|
197 |
|
|
* @return string
|
198 |
|
|
*/
|
199 |
d8069342
|
Andreas Kohlbecker
|
function render_footnote($footnoteKey = null, $footnoteText = null, $enclosing_tag = 'span') {
|
200 |
dd0767b6
|
Andreas Kohlbecker
|
_add_js_footnotes();
|
201 |
|
|
if($enclosing_tag == null){
|
202 |
|
|
$enclosing_tag = 'span';
|
203 |
|
|
}
|
204 |
|
|
return '<' . $enclosing_tag . ' class="footnote footnote-' . $footnoteKey . '">'
|
205 |
|
|
. '<a name="footnote-' . $footnoteKey . '"></a>'
|
206 |
|
|
. '<span class="footnote-anchor">' . $footnoteKey . '.</span> ' . $footnoteText
|
207 |
|
|
. '</' . $enclosing_tag . '>';
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
/**
|
213 |
|
|
* Create markup for the footnotes mapped to the $footnoteListKey.
|
214 |
|
|
*
|
215 |
|
|
* @param null $footnote_list_key
|
216 |
|
|
* The footnote list key, see RenderHints::getFootnoteListKey()
|
217 |
|
|
* @param $element_tag
|
218 |
|
|
* The tag for the footnote element
|
219 |
|
|
*
|
220 |
|
|
* @return string
|
221 |
3c4a5472
|
Andreas Kohlbecker
|
* The markup
|
222 |
dd0767b6
|
Andreas Kohlbecker
|
*/
|
223 |
d8069342
|
Andreas Kohlbecker
|
function render_footnotes($footnote_list_key = null, $element_tag = 'span') {
|
224 |
dd0767b6
|
Andreas Kohlbecker
|
|
225 |
|
|
if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
226 |
|
|
return '';
|
227 |
|
|
}
|
228 |
|
|
|
229 |
1c30a02b
|
Andreas Kohlbecker
|
if (!isset($footnote_list_key) || !$footnote_list_key) {
|
230 |
|
|
$footnote_list_key = RenderHints::getFootnoteListKey();
|
231 |
|
|
}
|
232 |
|
|
|
233 |
dd0767b6
|
Andreas Kohlbecker
|
$out = '<' . $element_tag . ' class="footnotes footnotes-' . $footnote_list_key . ' ">'
|
234 |
|
|
. FootnoteManager::renderFootnoteList($footnote_list_key)
|
235 |
|
|
. '</' . $element_tag . '>';
|
236 |
|
|
|
237 |
|
|
FootnoteManager::removeFootnoteList($footnote_list_key);
|
238 |
|
|
return $out;
|
239 |
|
|
}
|