Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / theme / cdm_dataportal.references.theme @ e7f3789b

History | View | Annotate | Download (4.99 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
 * - 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
 *
36
 * @return string
37
 *    the markup for the reference
38
 *
39
 * @ingroup themeable
40
 */
41
function cdm_reference_markup($reference, $microReference = NULL, $doTextLink = FALSE, $doIconLink = FALSE) {
42

    
43
  $citation = trim($reference->titleCache);
44
  $iconlink = "";
45
  if((isset($doIconLink) && $doIconLink === TRUE)) {
46
    $iconlink = l(custom_icon_font_markup('icon-interal-link-alt-solid', array('class' => array('superscript'))), path_to_reference($reference->uuid), array('html' => true));
47
  }
48
  if (isset($doTextLink) && $doTextLink === TRUE) {
49
    $out = '<span class="reference">';
50
    $out .= l($citation, path_to_reference($reference->uuid), array(
51
      'attributes' => array(
52
        "class" => "reference",
53
      ),
54
      'absolute' => TRUE,
55
      'html' => TRUE,
56
    ));
57
    $out .= $iconlink . '</span>';
58
  }
59
  else {
60
    $out = '<span class="reference">' . $citation . $iconlink . '</span>';
61
  }
62

    
63
  if (!empty($microReference)) {
64
    $out .= ": " . $microReference;
65
  }
66

    
67
  if(isset($reference->doi)){
68
    $out .= cdm_doi($reference->doi);
69
  }
70

    
71
  if (isset($reference->uri)){
72
    if($reference->type == 'WebPage'){
73
      // the cdm cache strategy adds the uri to the titleCache which is unwanted in this case,
74
      // so is is removed from there
75
      $out = str_replace('- ' . $reference->uri, '',  $out);
76
    }
77
    $out .= cdm_external_uri($reference->uri);
78
  }
79

    
80
  return $out;
81
}
82

    
83
/**
84
 * Creates a anchor tag as clickable link to an external resource, either as text link or as icon.
85
 * The resulting link will have no 'target' attribute, so the link will open in the same tab by default.
86
 * So the users can decide.
87
 *
88
 * @param $uri
89
 *    The uri to link to
90
 * @param $iconified
91
 *    The link will be rendered as icon of this is true.
92
 * @return string
93
 *
94
 */
95
function cdm_external_uri($uri, $iconified = true)
96
{
97
  $options = array(
98
    'external' => true,
99
    'html' => false,
100
    );
101
  if (!empty($uri)) {
102
    if($iconified){
103
      $options['html'] = true;
104
      return l(font_awesome_icon_markup('fa-external-link-alt', array('class' => array('superscript'))), $uri, $options);
105
    } else {
106
      return l($uri, $uri, $options);
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-alt', 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
 * Renders a representation for an CDM OriginalSourceBase entity
139
 *
140
 * @param $source
141
 *  The cdm OriginalSourceBase entity
142
 * @param bool $do_link_to_reference
143
 *
144
 * @param bool $do_link_to_name_used_in_source
145
 *
146
 * @return string
147
 * @throws \Exception
148
 */
149
function render_original_source($source, $do_link_to_reference = TRUE, $do_link_to_name_used_in_source = FALSE) {
150
  $out = '';
151

    
152
  if (isset($source->citation)) {
153
    $out .= cdm_reference_markup($source->citation, $source->citationMicroReference, false, $do_link_to_reference);
154
  }
155
  if(isset($source->cdmSource)){
156
    $out .= render_cdm_entity_link($source->cdmSource);
157
  }
158

    
159
  if($out){
160

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

    
166
    $id_with_namespace = '';
167
    if( isset($source->idNamespace) && $source->idNamespace ) {
168
      $id_with_namespace = $source->idNamespace . ' ';
169
    }
170
    if( isset($source->idInSource) && $source->idInSource ) {
171
      $id_with_namespace .= $source->idInSource;
172
    } else {
173
      $id_with_namespace = NULL;
174
    }
175

    
176
    if($id_with_namespace){
177
      $out .=  ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
178
    }
179
  }
180

    
181
  return $out;
182
}
Add picture from clipboard (Maximum size: 40 MB)