Project

General

Profile

Download (5.05 KB) Statistics
| Branch: | Tag: | Revision:
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 b2ebf0d3 Andreas Kohlbecker
 * Creates a pager widget for the given CDM Pager containing CDM Reference entities.
18
 *
19
 * @param $referencePager object
20
 *    A CDM Pager  containing CDM Reference entities
21
 * @param $path
22
 *    The base path to be used when generating the pager item links
23
 * @$parameters
24
 *
25
 * @return string
26
 *   Markup
27 6657531f Andreas Kohlbecker
 */
28 b2ebf0d3 Andreas Kohlbecker
function cdm_reference_pager($referencePager, $path, $parameters) {
29
30 6657531f Andreas Kohlbecker
  drupal_set_title(t('Bibliographic index'), PASS_THROUGH);
31
  $out = '';
32
  if (count($referencePager->records) > 0) {
33
    $out .= '<ul>';
34
    foreach ($referencePager->records as $reference) {
35
      // FIXME remove hack.
36
      $reference->fullCitation = $reference->titleCache;
37
      // For matching cdm entity to STO.
38
      $out .= '<li>' . theme('cdm_reference', array(
39
        'reference' => $reference,
40
        'microReference' => NULL,
41
        'doLink' => TRUE,
42
        )) . '</li>';
43
    }
44
    $out .= '</ul>';
45
    $out .= theme('cdm_pager', array(
46
      'pager' => $referencePager,
47
      'path' => $path,
48
      'parameters' => $parameters,
49
    ));
50
  }
51
  else {
52
    $out = '<h4 class="error">Sorry, this page contains not entries.</h4>';
53
  }
54
  return $out;
55
}
56
57
/**
58 43998144 Andreas Kohlbecker
 * Creates a HTML representations for a CDM Reference instance..
59 6657531f Andreas Kohlbecker
 *
60
 * Used by:
61
 * - theme_cdm_typedesignations
62 b2ebf0d3 Andreas Kohlbecker
 * - cdm_reference_pager
63 b7a20282 Andreas Kohlbecker
 * - cdm_taxonRelationships
64 6657531f Andreas Kohlbecker
 *
65
 * @param array $variables
66
 *   An associative array containing:
67
 *   - reference
68
 *   - microReference
69 0639ca2a Andreas Kohlbecker
 *   - doLink:
70
 *      Whether to create a link to the reference page, links to the reference URI or DOI are always
71
 *      created when this data is available
72 43998144 Andreas Kohlbecker
 *   - referenceStyle: the value "zoology" will cause a specific rendeting of the
73
 *      reference suitable for zoological publications.
74
 *
75
 * @return string
76
 *    the markup for the reference
77 6657531f Andreas Kohlbecker
 *
78
 * @ingroup themeable
79
 */
80
function theme_cdm_reference($variables) {
81
  $reference = $variables['reference'];
82
  $microReference = $variables['microReference'];
83
  $doLink = $variables['doLink'];
84
  $referenceStyle = $variables['referenceStyle'];
85 1b57b3c1 Andreas Kohlbecker
86 0639ca2a Andreas Kohlbecker
  if (!isset($reference->authorship)) {
87 f0bf24e7 Andreas Kohlbecker
    $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
88 0639ca2a Andreas Kohlbecker
  }
89
  else {
90 1ce9afb7 Patric Plitzner
    $author_team = $reference->authorship;
91 f0bf24e7 Andreas Kohlbecker
  }
92 6657531f Andreas Kohlbecker
93
  if ($referenceStyle == "zoology") {
94
    $year = '';
95
    if (isset($reference->datePublished->start)) {
96
      $year = partialToYear($reference->datePublished->start);
97
    }
98
    $citation = $author_team->titleCache . (!empty($year) ? '. ' . $year : '');
99
  }
100
  else {
101
    $citation = $reference->titleCache;
102
  }
103
104
  if (isset($doLink) && $doLink === TRUE) {
105
    $out = '<span class="reference">';
106
    $out .= l($citation, path_to_reference($reference->uuid), array(
107
      'attributes' => array(
108
        "class" => "reference",
109
      ),
110
      'absolute' => TRUE,
111
      'html' => TRUE,
112
    ));
113
    $out .= '</span>';
114
  }
115
  else {
116
    $out = '<span class="reference">' . $citation . '</span>';
117
  }
118
119
  if (!empty($microReference)) {
120
    $out .= ": " . $microReference;
121
  }
122
123 0639ca2a Andreas Kohlbecker
  if (isset($reference->doi) && !empty($reference->doi)) {
124 9091d35a Andreas Kohlbecker
125
    $doi_resolve_uri = 'http://doi.org/' . $reference->doi->prefix;
126
    if(isset($reference->doi->suffix)){
127
      $doi_resolve_uri .= '/' . $reference->doi->suffix;
128
    }
129 0639ca2a Andreas Kohlbecker
    $out .= l(font_awesome_icon_markup('fa-external-link-square', array('class' => array('superscript'))), $doi_resolve_uri, array('html' => TRUE));
130
  }
131
  if (isset($reference->uri) && !empty($reference->uri)) {
132
    $out .= l(font_awesome_icon_markup('fa-external-link', array('class' => array('superscript'))), $reference->uri, array('html' => TRUE));
133
  }
134
135 6657531f Andreas Kohlbecker
  return $out;
136
}
137
138 f3a04cfa Andreas Kohlbecker
/**
139
 * @todo Please document this function.
140
 * @see http://drupal.org/node/1354
141
 */
142
function theme_cdm_OriginalSource($variables) {
143
  $out = '';
144
  $source = $variables['source'];
145 bb3188cb Andreas Kohlbecker
  $do_link_to_reference = $variables['doLink'];
146
  $do_link_to_name_used_in_source = $variables['do_link_to_name_used_in_source'];
147 f3a04cfa Andreas Kohlbecker
148 1b04a204 Andreas Kohlbecker
  if (isset($source->citation)) {
149 f3a04cfa Andreas Kohlbecker
    $out = theme('cdm_reference', array(
150
        'reference' => $source->citation,
151
        'microReference' => $source->citationMicroReference,
152 bb3188cb Andreas Kohlbecker
        'doLink' => $do_link_to_reference,
153 f3a04cfa Andreas Kohlbecker
    ));
154 dcf17487 Andreas Kohlbecker
155 bb3188cb Andreas Kohlbecker
    $name_in_source_render_array = compose_name_in_source($source, $do_link_to_name_used_in_source);
156
    if(!empty($name_in_source_render_array)) {
157
      $out .=  ' <span class="nameUsedInSource">(' . t('as') . ' ' . $name_in_source_render_array['#markup'] . ')</span>';
158 046b235b Andreas Kohlbecker
    }
159 8ca88c4e Andreas Kohlbecker
160
    $id_with_namespace = '';
161
    if( isset($source->idNamespace) && $source->idNamespace ) {
162
      $id_with_namespace = $source->idNamespace . '/';
163
    }
164 8af64a68 Andreas Kohlbecker
    if( isset($source->idInSource) && $source->idInSource ) {
165 8ca88c4e Andreas Kohlbecker
      $id_with_namespace .= $source->idInSource;
166
    } else {
167
      $id_with_namespace = NULL;
168
    }
169 44d445c0 Andreas Kohlbecker
170 8ca88c4e Andreas Kohlbecker
    if($id_with_namespace){
171
      $out .=  ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
172 f3a04cfa Andreas Kohlbecker
    }
173
  }
174
  return $out;
175 1b04a204 Andreas Kohlbecker
}