Project

General

Profile

Download (5.82 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
 * - render_type_designations
22
 * - cdm_reference_pager
23
 * - cdm_taxonRelationships
24
 *
25
 * @param array $variables
26
 *   An associative array containing:
27
 *   - reference
28
 *   - microReference
29
 *   - doTextLink:
30
 *      Show the citation string as link to the reference page. This option does not affect links to the reference URI or DOI.
31
 *      These links are always created when this data is available
32
 *   - doIconLink:
33
 *      Append an icon to the citation string which links to the reference page, links to the reference URI or DOI are always
34
 *      created when this data is available
35
 *   - referenceStyle: the value "zoology" will cause a specific rendeting of the
36
 *      reference suitable for zoological publications.
37
 *
38
 * @return string
39
 *    the markup for the reference
40
 *
41
 * @ingroup themeable
42
 */
43
function theme_cdm_reference($variables) {
44
  $reference = $variables['reference'];
45
  $microReference = $variables['microReference'];
46
  $doTextLink = $variables['doTextLink'];
47
  $doIconLink = $variables['doIconLink'];
48
  $referenceStyle = $variables['referenceStyle'];
49

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

    
67
  $citation = trim($citation);
68
  $iconlink = "";
69
  if((isset($doIconLink) && $doIconLink === TRUE)) {
70
    $iconlink = l(custom_icon_font_markup('icon-interal-link-alt-solid', array('class' => array('superscript'))), path_to_reference($reference->uuid), array('html' => true));
71
  }
72
  if (isset($doTextLink) && $doTextLink === TRUE) {
73
    $out = '<span class="reference">';
74
    $out .= l($citation, path_to_reference($reference->uuid), array(
75
      'attributes' => array(
76
        "class" => "reference",
77
      ),
78
      'absolute' => TRUE,
79
      'html' => TRUE,
80
    ));
81
    $out .= $iconlink . '</span>';
82
  }
83
  else {
84
    $out = '<span class="reference">' . $citation . $iconlink . '</span>';
85
  }
86

    
87
  if (!empty($microReference)) {
88
    $out .= ": " . $microReference;
89
  }
90

    
91
  if(isset($reference->doi)){
92
    $out .= cdm_doi($reference->doi);
93
  }
94

    
95
  if (isset($reference->uri)){
96
    if($reference->type == 'WebPage'){
97
      // the cdm cache strategy adds the uri to the titleCache which is unwanted in this case,
98
      // so is is removed from there
99
      $out = str_replace('- ' . $reference->uri, '',  $out);
100
    }
101
    $out .= cdm_external_uri($reference->uri);
102
  }
103

    
104
  return $out;
105
}
106

    
107
/**
108
 * Creates a anchor tag as clickable link to an external resource, either as text link or as icon.
109
 * The resulting link will have no 'target' attribute, so the link will open in the same tab by default.
110
 * So the users can decide.
111
 *
112
 * @param $uri
113
 *    The uri to link to
114
 * @param $iconified
115
 *    The link will be rendered as icon of this is true.
116
 * @return string
117
 *
118
 */
119
function cdm_external_uri($uri, $iconified = true)
120
{
121
  $options = array(
122
    'external' => true,
123
    'html' => false,
124
    );
125
  if (!empty($uri)) {
126
    if($iconified){
127
      $options['html'] = true;
128
      return l(font_awesome_icon_markup('fa-external-link-alt', array('class' => array('superscript'))), $uri, $options);
129
    } else {
130
      return l($uri, $uri, $options);
131
    }
132
  }
133
}
134

    
135
/**
136
 * Creates markup for a CDM Doi entity.
137
 *
138
 * @param $doi
139
 *  The CDM DOI
140
 *
141
 * @return string
142
 *  Markup
143
 */
144
function cdm_doi($doi, $iconified = true) {
145

    
146
  if (!empty($doi)) {
147

    
148
    $doi_resolve_uri = 'http://doi.org/' . $doi->prefix;
149
    if (isset($doi->suffix)) {
150
      $doi_resolve_uri .= '/' . $doi->suffix;
151
    }
152
    if($iconified){
153
      return l(font_awesome_icon_markup('fa-external-link-square-alt', array('class' => array('superscript'))), $doi_resolve_uri, array('html' => TRUE));
154
    } else {
155
      return l($doi_resolve_uri, $doi_resolve_uri);
156
    }
157
  }
158

    
159
}
160

    
161
/**
162
 * Renders a representation for an CDM OriginalSourceBase entity
163
 *
164
 * @param $source
165
 *  The cdm OriginalSourceBase entity
166
 * @param bool $do_link_to_reference
167
 *
168
 * @param bool $do_link_to_name_used_in_source
169
 *
170
 * @return string
171
 * @throws \Exception
172
 */
173
function render_original_source($source, $do_link_to_reference = TRUE, $do_link_to_name_used_in_source = FALSE) {
174
  $out = '';
175

    
176
  if (isset($source->citation)) {
177
    $out .= theme('cdm_reference', [
178
      'reference' => $source->citation,
179
      'microReference' => $source->citationMicroReference,
180
      'doIconLink' => $do_link_to_reference,
181
    ]);
182
  }
183
  if(isset($source->cdmSource)){
184
    $out .= render_cdm_entity_link($source->cdmSource);
185
  }
186

    
187
  if($out){
188

    
189
    $name_in_source_render_array = compose_name_in_source($source, $do_link_to_name_used_in_source);
190
    if(!empty($name_in_source_render_array)) {
191
      $out .=  ' <span class="nameUsedInSource">(' . t('as') . ' ' . $name_in_source_render_array['#markup'] . ')</span>';
192
    }
193

    
194
    $id_with_namespace = '';
195
    if( isset($source->idNamespace) && $source->idNamespace ) {
196
      $id_with_namespace = $source->idNamespace . ' ';
197
    }
198
    if( isset($source->idInSource) && $source->idInSource ) {
199
      $id_with_namespace .= $source->idInSource;
200
    } else {
201
      $id_with_namespace = NULL;
202
    }
203

    
204
    if($id_with_namespace){
205
      $out .=  ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
206
    }
207
  }
208

    
209
  return $out;
210
}
(7-7/9)