Project

General

Profile

Download (4.4 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
/**
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
53
  if ($referenceStyle == "zoology") {
54
    $year = '';
55 c7f92453 Andreas Kohlbecker
    if (isset($reference->datePublished)) {
56
      $year = timePeriodToString($reference->datePublished, true, 'YYYY');
57 6657531f Andreas Kohlbecker
    }
58
    $citation = $author_team->titleCache . (!empty($year) ? '. ' . $year : '');
59
  }
60
  else {
61
    $citation = $reference->titleCache;
62
  }
63
64
  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
    $out .= cdm_external_uri($reference->uri);
89
  }
90
91
  return $out;
92
}
93 9091d35a Andreas Kohlbecker
94 0a288588 Andreas Kohlbecker
/**
95
 * @param $reference
96
 * @param $out
97
 * @return string
98
 */
99
function cdm_external_uri($uri, $iconified = true)
100
{
101
  if (!empty($uri)) {
102
    if($iconified){
103
      return l(font_awesome_icon_markup('fa-external-link', array('class' => array('superscript'))), $uri, array('html' => TRUE));
104
    } else {
105
      return l($uri, $uri);
106 9091d35a Andreas Kohlbecker
    }
107 0639ca2a Andreas Kohlbecker
  }
108 0a288588 Andreas Kohlbecker
}
109
110
/**
111
 * Creates markup for a CDM Doi entity.
112
 *
113
 * @param $doi
114
 *  The CDM DOI
115
 *
116
 * @return string
117
 *  Markup
118
 */
119
function cdm_doi($doi, $iconified = true) {
120
121
  if (!empty($doi)) {
122
123
    $doi_resolve_uri = 'http://doi.org/' . $doi->prefix;
124
    if (isset($doi->suffix)) {
125
      $doi_resolve_uri .= '/' . $doi->suffix;
126
    }
127
    if($iconified){
128
      return l(font_awesome_icon_markup('fa-external-link-square', array('class' => array('superscript'))), $doi_resolve_uri, array('html' => TRUE));
129
    } else {
130
      return l($doi_resolve_uri, $doi_resolve_uri);
131
    }
132 0639ca2a Andreas Kohlbecker
  }
133
134 6657531f Andreas Kohlbecker
}
135
136 f3a04cfa Andreas Kohlbecker
/**
137
 * @todo Please document this function.
138
 * @see http://drupal.org/node/1354
139
 */
140
function theme_cdm_OriginalSource($variables) {
141
  $out = '';
142
  $source = $variables['source'];
143 bb3188cb Andreas Kohlbecker
  $do_link_to_reference = $variables['doLink'];
144
  $do_link_to_name_used_in_source = $variables['do_link_to_name_used_in_source'];
145 f3a04cfa Andreas Kohlbecker
146 1b04a204 Andreas Kohlbecker
  if (isset($source->citation)) {
147 f3a04cfa Andreas Kohlbecker
    $out = theme('cdm_reference', array(
148
        'reference' => $source->citation,
149
        'microReference' => $source->citationMicroReference,
150 bb3188cb Andreas Kohlbecker
        'doLink' => $do_link_to_reference,
151 f3a04cfa Andreas Kohlbecker
    ));
152 dcf17487 Andreas Kohlbecker
153 bb3188cb Andreas Kohlbecker
    $name_in_source_render_array = compose_name_in_source($source, $do_link_to_name_used_in_source);
154
    if(!empty($name_in_source_render_array)) {
155
      $out .=  ' <span class="nameUsedInSource">(' . t('as') . ' ' . $name_in_source_render_array['#markup'] . ')</span>';
156 046b235b Andreas Kohlbecker
    }
157 8ca88c4e Andreas Kohlbecker
158
    $id_with_namespace = '';
159
    if( isset($source->idNamespace) && $source->idNamespace ) {
160
      $id_with_namespace = $source->idNamespace . '/';
161
    }
162 8af64a68 Andreas Kohlbecker
    if( isset($source->idInSource) && $source->idInSource ) {
163 8ca88c4e Andreas Kohlbecker
      $id_with_namespace .= $source->idInSource;
164
    } else {
165
      $id_with_namespace = NULL;
166
    }
167 44d445c0 Andreas Kohlbecker
168 8ca88c4e Andreas Kohlbecker
    if($id_with_namespace){
169
      $out .=  ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
170 f3a04cfa Andreas Kohlbecker
    }
171
  }
172
  return $out;
173 1b04a204 Andreas Kohlbecker
}