Project

General

Profile

Download (4.43 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

    
53
  if ($referenceStyle == "zoology") {
54
    $year = '';
55
    if (isset($reference->datePublished)) {
56
      $year = timePeriodToString($reference->datePublished, true, 'YYYY');
57
    }
58
    $citation = $author_team->titleCache . (!empty($year) ? '. ' . $year : '');
59
  }
60
  else {
61
    $citation = $reference->titleCache;
62
  }
63

    
64
  $citation = trim($citation);
65
  if (isset($doLink) && $doLink === TRUE) {
66
    $out = '<span class="reference">';
67
    $out .= l($citation, path_to_reference($reference->uuid), array(
68
      'attributes' => array(
69
        "class" => "reference",
70
      ),
71
      'absolute' => TRUE,
72
      'html' => TRUE,
73
    ));
74
    $out .= '</span>';
75
  }
76
  else {
77
    $out = '<span class="reference">' . $citation . '</span>';
78
  }
79

    
80
  if (!empty($microReference)) {
81
    $out .= ": " . $microReference;
82
  }
83

    
84
  if(isset($reference->doi)){
85
    $out .= cdm_doi($reference->doi);
86
  }
87

    
88
  if (isset($reference->uri)){
89
    $out .= cdm_external_uri($reference->uri);
90
  }
91

    
92
  return $out;
93
}
94

    
95
/**
96
 * @param $reference
97
 * @param $out
98
 * @return string
99
 */
100
function cdm_external_uri($uri, $iconified = true)
101
{
102
  if (!empty($uri)) {
103
    if($iconified){
104
      return l(font_awesome_icon_markup('fa-external-link', array('class' => array('superscript'))), $uri, array('html' => TRUE));
105
    } else {
106
      return l($uri, $uri);
107
    }
108
  }
109
}
110

    
111
/**
112
 * Creates markup for a CDM Doi entity.
113
 *
114
 * @param $doi
115
 *  The CDM DOI
116
 *
117
 * @return string
118
 *  Markup
119
 */
120
function cdm_doi($doi, $iconified = true) {
121

    
122
  if (!empty($doi)) {
123

    
124
    $doi_resolve_uri = 'http://doi.org/' . $doi->prefix;
125
    if (isset($doi->suffix)) {
126
      $doi_resolve_uri .= '/' . $doi->suffix;
127
    }
128
    if($iconified){
129
      return l(font_awesome_icon_markup('fa-external-link-square', array('class' => array('superscript'))), $doi_resolve_uri, array('html' => TRUE));
130
    } else {
131
      return l($doi_resolve_uri, $doi_resolve_uri);
132
    }
133
  }
134

    
135
}
136

    
137
/**
138
 * @todo Please document this function.
139
 * @see http://drupal.org/node/1354
140
 */
141
function theme_cdm_OriginalSource($variables) {
142
  $out = '';
143
  $source = $variables['source'];
144
  $do_link_to_reference = $variables['doLink'];
145
  $do_link_to_name_used_in_source = $variables['do_link_to_name_used_in_source'];
146

    
147
  if (isset($source->citation)) {
148
    $out = theme('cdm_reference', array(
149
        'reference' => $source->citation,
150
        'microReference' => $source->citationMicroReference,
151
        'doLink' => $do_link_to_reference,
152
    ));
153

    
154
    $name_in_source_render_array = compose_name_in_source($source, $do_link_to_name_used_in_source);
155
    if(!empty($name_in_source_render_array)) {
156
      $out .=  ' <span class="nameUsedInSource">(' . t('as') . ' ' . $name_in_source_render_array['#markup'] . ')</span>';
157
    }
158

    
159
    $id_with_namespace = '';
160
    if( isset($source->idNamespace) && $source->idNamespace ) {
161
      $id_with_namespace = $source->idNamespace . '/';
162
    }
163
    if( isset($source->idInSource) && $source->idInSource ) {
164
      $id_with_namespace .= $source->idInSource;
165
    } else {
166
      $id_with_namespace = NULL;
167
    }
168

    
169
    if($id_with_namespace){
170
      $out .=  ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
171
    }
172
  }
173
  return $out;
174
}
(7-7/9)