Project

General

Profile

« Previous | Next » 

Revision dd0767b6

Added by Andreas Kohlbecker over 3 years ago

ref #8543 moving footnote functions to separate inc file

View differences:

modules/cdm_dataportal/cdm_dataportal.module
23 23
  module_load_include('php', 'cdm_dataportal', 'cdm_dataportal.search');
24 24

  
25 25
  module_load_include('inc', 'cdm_dataportal', 'includes/common');
26
  module_load_include('inc', 'cdm_dataportal', 'includes/footnotes');
26 27
  module_load_include('inc', 'cdm_dataportal', 'includes/agent');
27 28
  module_load_include('inc', 'cdm_dataportal', 'includes/name');
28 29
  module_load_include('inc', 'cdm_dataportal', 'includes/taxon');
......
2786 2787
  return $outArrayOfMedia;
2787 2788
}
2788 2789

  
2789
/**
2790
 * Fetches the list of visible annotations for each of the cdm entities and returns the footnote keys for them.
2791
 *
2792
 * The footnotes are passed to the FootnoteManager in order to store the annotations and to create the footnote keys.
2793
 *
2794
 * @see cdm_fetch_visible_annotations()
2795
 *
2796
 * @param array $cdm_entities
2797
 *   An array of CdmBase instances.
2798
 * @param $footnote_list_key_suggestion string
2799
 *    optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined be set to
2800
 *    RenderHints::getFootnoteListKey().'-annotations' otherwise the supplied key will be used.
2801
 *
2802
 * @return array of footnote keys
2803
 */
2804
function cdm_entities_annotations_footnotekeys(array $cdm_entities, $footnote_list_key_suggestion = NULL) {
2805

  
2806
  $foot_note_keys = [];
2807
  foreach ($cdm_entities as $cdm_entity) {
2808
        $foot_note_keys = array_merge($foot_note_keys, cdm_entity_annotations_as_footnotekeys($cdm_entity,$footnote_list_key_suggestion));
2809
  }
2810

  
2811
  return $foot_note_keys;
2812
}
2813

  
2814
/**
2815
 * Fetches the list of visible annotations for the cdm entity or for the comparable
2816
 * object and returns the footnote keys.
2817
 *
2818
 * The footnotes are passed to the FootnoteManager in order to store the
2819
 * annotations and to create the footnote keys.
2820

  
2821
 * @param stdClass $cdm_entity
2822
 *   A single CdmBase instance ore comparable object.
2823
 * @param $footnote_list_key_suggestion string
2824
 *    optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined be set to
2825
 *    RenderHints::getFootnoteListKey().'-annotations' otherwise the supplied key will be used.
2826
 * @return array of footnote keys
2827
 *
2828
 * @see cdm_fetch_visible_annotations()
2829
 */
2830
function cdm_entity_annotations_as_footnotekeys(stdClass $cdm_entity, $footnote_list_key_suggestion = NULL) {
2831

  
2832
  $foot_note_keys = [];
2833

  
2834
  // Getting the key for the footnotemanager.
2835
  if (isset($footnote_list_key_suggestion)) {
2836
    $footnote_list_key = $footnote_list_key_suggestion;
2837
  } else {
2838
    $footnote_list_key = RenderHints::getFootnoteListKey() . '-annotations';
2839
  }
2840

  
2841
  // Adding the footnotes keys.
2842
  $annotations = cdm_fetch_visible_annotations($cdm_entity);
2843
  if (is_array($annotations)) {
2844
    foreach ($annotations as $annotation) {
2845
      $foot_note_keys[] = FootnoteManager::addNewFootnote($footnote_list_key, $annotation->text);
2846
    }
2847
  }
2848 2790

  
2849
  return $foot_note_keys;
2850
}
2851 2791

  
2852 2792

  
2853 2793
/**
modules/cdm_dataportal/includes/descriptions.inc
333 333
  return $item;
334 334
}
335 335

  
336
/**
337
 * Creates the footnotes for the given CDM instance.
338
 *
339
 * Footnotes are created for annotations and original sources whereas the resulting footnote keys depend on the
340
 * parameters $footnote_list_key_suggestion and $is_bibliography_aware, see parameter $footnote_list_key_suggestion
341
 * for more details.
342
 *
343
 * possible keys for
344
 *     - annotation footnotes:
345
 *       - $footnote_list_key_suggestion
346
 *       - RenderHints::getFootnoteListKey().'-annotations'
347
 *     - original source footnotes
348
 *       - "BIBLIOGRAPHY" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 1 )
349
 *       - "BIBLIOGRAPHY-$footnote_list_key_suggestion" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 0 )
350
 *       - $footnote_list_key_suggestion (when $is_bibliography_aware)
351
 *
352
 * @param $description_element
353
 *   A CDM DescriptionElement instance
354
 * @param string $separator
355
 *   Optional parameter. The separator string to concatenate the footnote ids, default is ','
356
 * @param $footnote_list_key_suggestion string
357
 *    Optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined by the nested
358
 *    method calls by calling RenderHints::getFootnoteListKey(). NOTE: the footnote key for annotations will be set to
359
 *    RenderHints::getFootnoteListKey().'-annotations'.
360
 * @param bool $do_link_to_reference
361
 *    Create a link to the reference pages for sources when TRUE.
362
 * @param bool $do_link_to_name_used_in_source
363
 *    Create a link to the name pages for name in source when TRUE.
364
 * @param bool $is_bibliography_aware
365
 *    Put source references into the bibliography when this param is TRUE.
366
 *
367
 * @return String
368
 *   The foot note keys
369
 *
370
 * @throws \Exception re-throw exception from theme()
371
 * @see cdm_entities_annotations_footnotekeys()
372
 *    For original sources the $footnote_list_key_suggestion will be overwritten by bibliography_footnote_list_key() when
373
 *    $is_bibliography_aware is set TRUE.
374
 * @$original_source_footnote_tag
375
 *    null will cause bibliography_footnote_list_key to use the default
376
 */
377
function cdm_create_footnotes(
378
    $description_element,
379
    $separator = ',',
380
    $footnote_list_key_suggestion = null,
381
    $do_link_to_reference = FALSE,
382
    $do_link_to_name_used_in_source = FALSE,
383
    $is_bibliography_aware = FALSE
384
  ){
385

  
386
  $sources = cdm_entity_sources_sorted($description_element);
387

  
388
  // Annotations as footnotes.
389
  $footnote_keys = cdm_entity_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
390

  
391
  // Source references as footnotes.
392
  if($is_bibliography_aware){
393
    $bibliography_settings = get_bibliography_settings();
394
    $sources_footnote_list_key = bibliography_footnote_list_key($footnote_list_key_suggestion);
395
    $original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // null will cause bibliography_footnote_list_key to use the default
396
  } else {
397
    $sources_footnote_list_key = $footnote_list_key_suggestion;
398
    if(!$sources_footnote_list_key) {
399
      RenderHints::getFootnoteListKey();
400
    }
401
    $original_source_footnote_tag = NULL;
402
  }
403

  
404
  foreach ($sources as $source) {
405
    if (_is_original_source_type($source)) {
406
      $fn_key = FootnoteManager::addNewFootnote(
407
        $sources_footnote_list_key,
408
        render_original_source(
409
          $source,
410
          $do_link_to_reference,
411
          $do_link_to_name_used_in_source
412
        ),
413
        $original_source_footnote_tag
414
      );
415
      // Ensure uniqueness of the footnote keys.
416
      cdm_add_footnote_to_array($footnote_keys, $fn_key);
417
    }
418
  }
419
  // Sort and render footnote keys.
420
  asort($footnote_keys);
421
  return footnote_keys_to_markup($footnote_keys, $separator);
422
}
423

  
424
/**
425
 * Creates markup for an array of foot note keys
426
 *
427
 * @param array $footnote_keys
428
 * @param string $separator
429
 *
430
 * @return string
431
 */
432
function footnote_keys_to_markup(array $footnote_keys, $separator) {
433

  
434
  $footnotes_markup = '';
435
  foreach ($footnote_keys as $foot_note_key) {
436
    try {
437
      $footnotes_markup .= cdm_footnote_key($foot_note_key, ($footnotes_markup ? $separator : ''));
438
    } catch (Exception $e) {
439
      drupal_set_message("Exception: " . $e->getMessage(), 'error');
440
    }
441
  }
442
  return $footnotes_markup;
443
}
444

  
445

  
446 336
/**
447 337
 * Compare callback to be used in usort() to sort render arrays produced by
448 338
 * compose_description_element().
modules/cdm_dataportal/includes/footnotes.inc
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

  
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
 * possible keys for
27
 *     - annotation footnotes:
28
 *       - $footnote_list_key_suggestion
29
 *       - RenderHints::getFootnoteListKey().'-annotations'
30
 *     - original source footnotes
31
 *       - "BIBLIOGRAPHY" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 1 )
32
 *       - "BIBLIOGRAPHY-$footnote_list_key_suggestion" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 0 )
33
 *       - $footnote_list_key_suggestion (when $is_bibliography_aware)
34
 *
35
 * @param $description_element
36
 *   A CDM DescriptionElement instance
37
 * @param string $separator
38
 *   Optional parameter. The separator string to concatenate the footnote ids, default is ','
39
 * @param $footnote_list_key_suggestion string
40
 *    Optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined by the nested
41
 *    method calls by calling RenderHints::getFootnoteListKey(). NOTE: the footnote key for annotations will be set to
42
 *    RenderHints::getFootnoteListKey().'-annotations'.
43
 * @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
 *
50
 * @return String
51
 *   The foot note keys
52
 *
53
 * @throws \Exception re-throw exception from theme()
54
 * @see cdm_entities_annotations_footnotekeys()
55
 *    For original sources the $footnote_list_key_suggestion will be overwritten by bibliography_footnote_list_key() when
56
 *    $is_bibliography_aware is set TRUE.
57
 * @$original_source_footnote_tag
58
 *    null will cause bibliography_footnote_list_key to use the default
59
 */
60
function cdm_create_footnotes(
61
  $description_element,
62
  $separator = ',',
63
  $footnote_list_key_suggestion = null,
64
  $do_link_to_reference = FALSE,
65
  $do_link_to_name_used_in_source = FALSE,
66
  $is_bibliography_aware = FALSE
67
){
68

  
69
  $sources = cdm_entity_sources_sorted($description_element);
70

  
71
  // Annotations as footnotes.
72
  $footnote_keys = cdm_entity_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
73

  
74
  // Source references as footnotes.
75
  if($is_bibliography_aware){
76
    $bibliography_settings = get_bibliography_settings();
77
    $sources_footnote_list_key = bibliography_footnote_list_key($footnote_list_key_suggestion);
78
    $original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // null will cause bibliography_footnote_list_key to use the default
79
  } else {
80
    $sources_footnote_list_key = $footnote_list_key_suggestion;
81
    if(!$sources_footnote_list_key) {
82
      RenderHints::getFootnoteListKey();
83
    }
84
    $original_source_footnote_tag = NULL;
85
  }
86

  
87
  foreach ($sources as $source) {
88
    if (_is_original_source_type($source)) {
89
      $fn_key = FootnoteManager::addNewFootnote(
90
        $sources_footnote_list_key,
91
        render_original_source(
92
          $source,
93
          $do_link_to_reference,
94
          $do_link_to_name_used_in_source
95
        ),
96
        $original_source_footnote_tag
97
      );
98
      // Ensure uniqueness of the footnote keys.
99
      cdm_add_footnote_to_array($footnote_keys, $fn_key);
100
    }
101
  }
102
  // Sort and render footnote keys.
103
  asort($footnote_keys);
104
  return footnote_keys_to_markup($footnote_keys, $separator);
105
}
106

  
107
/**
108
 * Fetches the list of visible annotations for each of the cdm entities and returns the footnote keys for them.
109
 *
110
 * The footnotes are passed to the FootnoteManager in order to store the annotations and to create the footnote keys.
111
 *
112
 * @see cdm_fetch_visible_annotations()
113
 *
114
 * @param array $cdm_entities
115
 *   An array of CdmBase instances.
116
 * @param $footnote_list_key_suggestion string
117
 *    optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined be set to
118
 *    RenderHints::getFootnoteListKey().'-annotations' otherwise the supplied key will be used.
119
 *
120
 * @return array of footnote keys
121
 */
122
function cdm_entities_annotations_footnotekeys(array $cdm_entities, $footnote_list_key_suggestion = NULL) {
123

  
124
  $foot_note_keys = [];
125
  foreach ($cdm_entities as $cdm_entity) {
126
    $foot_note_keys = array_merge($foot_note_keys, cdm_entity_annotations_as_footnotekeys($cdm_entity,$footnote_list_key_suggestion));
127
  }
128

  
129
  return $foot_note_keys;
130
}
131

  
132
/**
133
 * Fetches the list of visible annotations for the cdm entity or for the comparable
134
 * object and returns the footnote keys.
135
 *
136
 * The footnotes are passed to the FootnoteManager in order to store the
137
 * annotations and to create the footnote keys.
138

  
139
 * @param stdClass $cdm_entity
140
 *   A single CdmBase instance ore comparable object.
141
 * @param $footnote_list_key_suggestion string
142
 *    optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined be set to
143
 *    RenderHints::getFootnoteListKey().'-annotations' otherwise the supplied key will be used.
144
 * @return array of footnote keys
145
 *
146
 * @see cdm_fetch_visible_annotations()
147
 */
148
function cdm_entity_annotations_as_footnotekeys(stdClass $cdm_entity, $footnote_list_key_suggestion = NULL) {
149

  
150
  $foot_note_keys = [];
151

  
152
  // Getting the key for the footnotemanager.
153
  if (isset($footnote_list_key_suggestion)) {
154
    $footnote_list_key = $footnote_list_key_suggestion;
155
  } else {
156
    $footnote_list_key = RenderHints::getFootnoteListKey() . '-annotations';
157
  }
158

  
159
  // Adding the footnotes keys.
160
  $annotations = cdm_fetch_visible_annotations($cdm_entity);
161
  if (is_array($annotations)) {
162
    foreach ($annotations as $annotation) {
163
      $foot_note_keys[] = FootnoteManager::addNewFootnote($footnote_list_key, $annotation->text);
164
    }
165
  }
166

  
167
  return $foot_note_keys;
168
}
169

  
170
/**
171
 * Creates markup for an array of foot note keys
172
 *
173
 * @param array $footnote_keys
174
 * @param string $separator
175
 *
176
 * @return string
177
 */
178
function footnote_keys_to_markup(array $footnote_keys, $separator) {
179

  
180
  $footnotes_markup = '';
181
  foreach ($footnote_keys as $foot_note_key) {
182
    try {
183
      $footnotes_markup .= cdm_footnote_key($foot_note_key, ($footnotes_markup ? $separator : ''));
184
    } catch (Exception $e) {
185
      drupal_set_message("Exception: " . $e->getMessage(), 'error');
186
    }
187
  }
188
  return $footnotes_markup;
189
}
190

  
191
/**
192
 * @todo Please document this function.
193
 * @see http://drupal.org/node/1354
194
 */
195
function cdm_add_footnote_to_array(&$footnote_list, $footnote) {
196
  if (!cdm_exist_footnote($footnote_list, $footnote)) {
197
    $footnote_list[] = $footnote;
198
  }
199
}
200

  
201

  
202
/**
203
 * Create markup for the footnotes mapped to the $footnoteListKey.
204
 *
205
 * @param null $footnote_list_key
206
 *  The footnote list key, see RenderHints::getFootnoteListKey()
207
 * @param $element_tag
208
 *  The tag for the footnote element
209
 *
210
 * @return string
211
 * @throws \Exception
212
 */
213
function cdm_annotation_footnotes($footnote_list_key = null, $element_tag = 'span') {
214
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
215
    return '';
216
  }
217
  return cdm_footnotes($footnote_list_key . '-annotations', $element_tag);
218
}
219

  
220
/**
221
 * Creates markup for a foot note key
222
 *
223
 * @param null $footnoteKey
224
 * @param string $separator
225
 * @param bool $separator_off
226
 *
227
 * @return string
228
 *   The footnote key markup
229
 */
230
function cdm_footnote_key($footnoteKey = null, $separator = '', $separator_off = false) {
231

  
232
  if (!is_object($footnoteKey) or !isset($footnoteKey->footnoteListKey)) {
233
    return '';
234
  }
235
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
236
    return '';
237
  }
238

  
239
  if ($separator_off) {
240
    $separator = '';
241
  }
242
  $out = '<span class="footnote-key footnote-key-' . $footnoteKey->keyStr . ' member-of-footnotes-' . $footnoteKey->footnoteListKey . '">'
243
    . $separator . '<a href="#footnote-' . $footnoteKey->keyStr . '">' . $footnoteKey->keyStr . '</a>' . '</span>';
244
  return $out;
245
}
246

  
247
/**
248
 * @param null $footnoteKey
249
 * @param null $footnoteText
250
 * @param string $enclosing_tag
251
 *   default is 'span'
252
 *
253
 * @return string
254
 */
255
function footnote_markup($footnoteKey = null, $footnoteText = null, $enclosing_tag = 'span') {
256
  _add_js_footnotes();
257
  if($enclosing_tag == null){
258
    $enclosing_tag = 'span';
259
  }
260
  return '<' . $enclosing_tag . ' class="footnote footnote-' . $footnoteKey . '">'
261
    . '<a name="footnote-' . $footnoteKey . '"></a>'
262
    . '<span class="footnote-anchor">' . $footnoteKey . '.</span>&nbsp;' . $footnoteText
263
    . '</' . $enclosing_tag . '>';
264
}
265

  
266

  
267

  
268
/**
269
 * Create markup for the footnotes mapped to the $footnoteListKey.
270
 *
271
 * @param null $footnote_list_key
272
 *  The footnote list key, see RenderHints::getFootnoteListKey()
273
 * @param $element_tag
274
 *  The tag for the footnote element
275
 *
276
 * @return string
277
 */
278
function cdm_footnotes($footnote_list_key = null, $element_tag = 'span') {
279

  
280
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
281
    return '';
282
  }
283

  
284
  $out = '<' . $element_tag . ' class="footnotes footnotes-' . $footnote_list_key . ' ">'
285
    . FootnoteManager::renderFootnoteList($footnote_list_key)
286
    . '</' . $element_tag . '>';
287

  
288
  FootnoteManager::removeFootnoteList($footnote_list_key);
289
  return $out;
290
}
291

  
292
/**
293
 * Renders the footnotes for annotations and sources, etc.
294
 *
295
 * @param string $footnote_list_key
296
 *    RenderHints::getFootnoteListKey() will be used if this parameter is undefined.
297
 * @param string $enclosingTag
298
 *    Default tag is 'span'
299
 *
300
 * @return string
301
 *    The markup string
302
 *
303
 */
304
function render_cdm_footnotes($footnote_list_key = NULL, $enclosingTag = 'span'){
305

  
306
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
307
    return '';
308
  }
309
  if(!$footnote_list_key){
310
    $footnote_list_key = RenderHints::getFootnoteListKey();
311
  }
312

  
313
  $out = '<' . $enclosingTag . ' class="footnotes footnotes-' . $footnote_list_key . ' ">'
314
    . FootnoteManager::renderFootnoteList($footnote_list_key . '-annotations') . ' ' . FootnoteManager::renderFootnoteList($footnote_list_key)
315
    . '</' . $enclosingTag . '>';
316
  FootnoteManager::removeFootnoteList($footnote_list_key . '-annotations');
317
  FootnoteManager::removeFootnoteList($footnote_list_key);
318
  return $out;
319
}
320

  
321
/**
322
 * @todo Please document this function.
323
 * @see http://drupal.org/node/1354
324
 */
325
function cdm_exist_footnote($footnote_list, $footnote) {
326
  $result = FALSE;
327
  if (is_array($footnote_list)) {
328
    foreach ($footnote_list as $element) {
329
      if ($element == $footnote) {
330
        $result = TRUE;
331
      }
332
    }
333
  }
334
  return $result;
335
}
modules/cdm_dataportal/theme/cdm_dataportal.common.theme
178 178
  return $out;
179 179
}
180 180

  
181
/**
182
 * Create markup for the footnotes mapped to the $footnoteListKey.
183
 *
184
 * @param null $footnote_list_key
185
 *  The footnote list key, see RenderHints::getFootnoteListKey()
186
 * @param $element_tag
187
 *  The tag for the footnote element
188
 *
189
 * @return string
190
 * @throws \Exception
191
 */
192
function cdm_annotation_footnotes($footnote_list_key = null, $element_tag = 'span') {
193
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
194
    return '';
195
  }
196
  return cdm_footnotes($footnote_list_key . '-annotations', $element_tag);
197
}
198

  
199
/* ============================ footnotes ============================= */
200
/**
201
 * Creates markup for a foot note key
202
 *
203
 * @param null $footnoteKey
204
 * @param string $separator
205
 * @param bool $separator_off
206
 *
207
 * @return string
208
 *   The footnote key markup
209
 */
210
function cdm_footnote_key($footnoteKey = null, $separator = '', $separator_off = false) {
211

  
212
  if (!is_object($footnoteKey) or !isset($footnoteKey->footnoteListKey)) {
213
    return '';
214
  }
215
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
216
    return '';
217
  }
218

  
219
  if ($separator_off) {
220
    $separator = '';
221
  }
222
  $out = '<span class="footnote-key footnote-key-' . $footnoteKey->keyStr . ' member-of-footnotes-' . $footnoteKey->footnoteListKey . '">'
223
    . $separator . '<a href="#footnote-' . $footnoteKey->keyStr . '">' . $footnoteKey->keyStr . '</a>' . '</span>';
224
  return $out;
225
}
226

  
227
/**
228
 * @param null $footnoteKey
229
 * @param null $footnoteText
230
 * @param string $enclosing_tag
231
 *   default is 'span'
232
 *
233
 * @return string
234
 */
235
function footnote_markup($footnoteKey = null, $footnoteText = null, $enclosing_tag = 'span') {
236
  _add_js_footnotes();
237
  if($enclosing_tag == null){
238
    $enclosing_tag = 'span';
239
  }
240
  return '<' . $enclosing_tag . ' class="footnote footnote-' . $footnoteKey . '">'
241
    . '<a name="footnote-' . $footnoteKey . '"></a>'
242
    . '<span class="footnote-anchor">' . $footnoteKey . '.</span>&nbsp;' . $footnoteText
243
    . '</' . $enclosing_tag . '>';
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
 */
256
function cdm_footnotes($footnote_list_key = null, $element_tag = 'span') {
257

  
258
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
259
    return '';
260
  }
261

  
262
  $out = '<' . $element_tag . ' class="footnotes footnotes-' . $footnote_list_key . ' ">'
263
    . FootnoteManager::renderFootnoteList($footnote_list_key)
264
    . '</' . $element_tag . '>';
265

  
266
  FootnoteManager::removeFootnoteList($footnote_list_key);
267
  return $out;
268
}
269

  
270
/**
271
 * Renders the footnotes for annotations and sources, etc.
272
 *
273
 * @param string $footnote_list_key
274
 *    RenderHints::getFootnoteListKey() will be used if this parameter is undefined.
275
 * @param string $enclosingTag
276
 *    Default tag is 'span'
277
 *
278
 * @return string
279
 *    The markup string
280
 *
281
 */
282
function render_cdm_footnotes($footnote_list_key = NULL, $enclosingTag = 'span'){
283

  
284
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
285
    return '';
286
  }
287
  if(!$footnote_list_key){
288
    $footnote_list_key = RenderHints::getFootnoteListKey();
289
  }
290

  
291
  $out = '<' . $enclosingTag . ' class="footnotes footnotes-' . $footnote_list_key . ' ">'
292
    . FootnoteManager::renderFootnoteList($footnote_list_key . '-annotations') . ' ' . FootnoteManager::renderFootnoteList($footnote_list_key)
293
    . '</' . $enclosingTag . '>';
294
  FootnoteManager::removeFootnoteList($footnote_list_key . '-annotations');
295
  FootnoteManager::removeFootnoteList($footnote_list_key);
296
  return $out;
297
}
298

  
299 181
/**
300 182
 * Created markup for the annotations
301 183
 * @param null $annotations
......
318 200
  return $out;
319 201
}
320 202

  
321
/**
322
 * @todo Please document this function.
323
 * @see http://drupal.org/node/1354
324
 */
325
function cdm_exist_footnote($footnote_list, $footnote) {
326
  $result = FALSE;
327
  if (is_array($footnote_list)) {
328
    foreach ($footnote_list as $element) {
329
      if ($element == $footnote) {
330
        $result = TRUE;
331
      }
332
    }
333
  }
334
  return $result;
335
}
336 203

  
337
/**
338
 * @todo Please document this function.
339
 * @see http://drupal.org/node/1354
340
 */
341
function cdm_add_footnote_to_array(&$footnote_list, $footnote) {
342
  if (!cdm_exist_footnote($footnote_list, $footnote)) {
343
    $footnote_list[] = $footnote;
344
  }
345
}
346 204

  
347 205
/**
348 206
 * Theme function for CDM marker instances

Also available in: Unified diff