Project

General

Profile

Download (4.84 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
 * Creates a HTML representations for a CDM Reference instance..
19
 *
20
 * Used by:
21
 * - theme_cdm_typedesignations
22
 * - cdm_reference_pager
23
 * - cdm_taxonRelationships
24
 *
25
 * @param array $variables
26
 *   An associative array containing:
27
 *   - reference
28
 *   - microReference
29
 *   - 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
 *   - 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
 *
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

    
46
  if (!isset($reference->authorship)) {
47
    $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
48
  }
49
  else {
50
    $author_team = $reference->authorship;
51
  }
52
  if ($referenceStyle == "zoology") {
53
    $year = '';
54
    if (isset($reference->datePublished)) {
55
      $year = timePeriodToString($reference->datePublished, true, 'YYYY');
56
    }
57
    $citation = $author_team->titleCache . (!empty($year) ? '. ' . $year : '');
58
  }
59
  else {
60
    $citation = $reference->titleCache;
61
  }
62

    
63
  $citation = trim($citation);
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
  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

    
94
/**
95
 * Creates a anchor tag as clickable link to an external resource, either as text link or as icon.
96
 * The resulting link will have no 'target' attribute, so the link will open in the same tab by default.
97
 * So the users can decide.
98
 *
99
 * @param $uri
100
 *    The uri to link to
101
 * @param $iconified
102
 *    The link will be rendered as icon of this is true.
103
 * @return string
104
 *
105
 */
106
function cdm_external_uri($uri, $iconified = true)
107
{
108
  $options = array(
109
    'external' => true,
110
    'html' => false,
111
    );
112
  if (!empty($uri)) {
113
    if($iconified){
114
      $options['html'] = true;
115
      return l(font_awesome_icon_markup('fa-external-link', array('class' => array('superscript'))), $uri, $options);
116
    } else {
117
      return l($uri, $uri, $options);
118
    }
119
  }
120
}
121

    
122
/**
123
 * Creates markup for a CDM Doi entity.
124
 *
125
 * @param $doi
126
 *  The CDM DOI
127
 *
128
 * @return string
129
 *  Markup
130
 */
131
function cdm_doi($doi, $iconified = true) {
132

    
133
  if (!empty($doi)) {
134

    
135
    $doi_resolve_uri = 'http://doi.org/' . $doi->prefix;
136
    if (isset($doi->suffix)) {
137
      $doi_resolve_uri .= '/' . $doi->suffix;
138
    }
139
    if($iconified){
140
      return l(font_awesome_icon_markup('fa-external-link-square', array('class' => array('superscript'))), $doi_resolve_uri, array('html' => TRUE));
141
    } else {
142
      return l($doi_resolve_uri, $doi_resolve_uri);
143
    }
144
  }
145

    
146
}
147

    
148
/**
149
 * @todo Please document this function.
150
 * @see http://drupal.org/node/1354
151
 */
152
function theme_cdm_OriginalSource($variables) {
153
  $out = '';
154
  $source = $variables['source'];
155
  $do_link_to_reference = $variables['doLink'];
156
  $do_link_to_name_used_in_source = $variables['do_link_to_name_used_in_source'];
157

    
158
  if (isset($source->citation)) {
159
    $out = theme('cdm_reference', array(
160
        'reference' => $source->citation,
161
        'microReference' => $source->citationMicroReference,
162
        'doLink' => $do_link_to_reference,
163
    ));
164

    
165
    $name_in_source_render_array = compose_name_in_source($source, $do_link_to_name_used_in_source);
166
    if(!empty($name_in_source_render_array)) {
167
      $out .=  ' <span class="nameUsedInSource">(' . t('as') . ' ' . $name_in_source_render_array['#markup'] . ')</span>';
168
    }
169

    
170
    $id_with_namespace = '';
171
    if( isset($source->idNamespace) && $source->idNamespace ) {
172
      $id_with_namespace = $source->idNamespace . ' ';
173
    }
174
    if( isset($source->idInSource) && $source->idInSource ) {
175
      $id_with_namespace .= $source->idInSource;
176
    } else {
177
      $id_with_namespace = NULL;
178
    }
179

    
180
    if($id_with_namespace){
181
      $out .=  ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
182
    }
183
  }
184
  return $out;
185
}
(7-7/9)