Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / theme / cdm_dataportal.references.theme @ 384ff2ba

History | View | Annotate | Download (5.51 KB)

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
 *   - 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
  if (isset($doTextLink) && $doTextLink === TRUE) {
69
    $out = '<span class="reference">';
70
    $out .= l($citation, path_to_reference($reference->uuid), array(
71
      'attributes' => array(
72
        "class" => "reference",
73
      ),
74
      'absolute' => TRUE,
75
      'html' => TRUE,
76
    ));
77
    $out .= '</span>';
78
  }
79
  else {
80
    $out = '<span class="reference">' . $citation . '</span>';
81
  }
82
  if((isset($doIconLink) && $doIconLink === TRUE)) {
83
    $out .= custom_icon_font_markup('e903');
84
  }
85

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

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

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

    
103
  return $out;
104
}
105

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

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

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

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

    
158
}
159

    
160
/**
161
 * Renders a representation for an CDM OriginalSourceBase entity
162
 *
163
 * @param $source
164
 *  The cdm OriginalSourceBase entity
165
 * @param $do_link_to_reference
166
 * @param $do_link_to_name_used_in_source
167
 * @return string
168
 */
169
function render_original_source($source, $do_link_to_reference = true, $do_link_to_name_used_in_source = false) {
170
  $out = '';
171

    
172
  if (isset($source->citation)) {
173
    $out = theme('cdm_reference', array(
174
        'reference' => $source->citation,
175
        'microReference' => $source->citationMicroReference,
176
        'doIconLink' => $do_link_to_reference,
177
    ));
178

    
179
    $name_in_source_render_array = compose_name_in_source($source, $do_link_to_name_used_in_source);
180
    if(!empty($name_in_source_render_array)) {
181
      $out .=  ' <span class="nameUsedInSource">(' . t('as') . ' ' . $name_in_source_render_array['#markup'] . ')</span>';
182
    }
183

    
184
    $id_with_namespace = '';
185
    if( isset($source->idNamespace) && $source->idNamespace ) {
186
      $id_with_namespace = $source->idNamespace . ' ';
187
    }
188
    if( isset($source->idInSource) && $source->idInSource ) {
189
      $id_with_namespace .= $source->idInSource;
190
    } else {
191
      $id_with_namespace = NULL;
192
    }
193

    
194
    if($id_with_namespace){
195
      $out .=  ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
196
    }
197
  }
198
  return $out;
199
}
Add picture from clipboard (Maximum size: 40 MB)