Project

General

Profile

Download (6.39 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 reference
26
 *      The entity to be rendered
27
 *  @param string $citation_detail
28
 *      The citation detail like page number
29
 *  @param boolean do_text_link
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
 *  @param boolean do_icon_link
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
function cdm_reference_markup($reference, $citation_detail = NULL, $do_text_link = FALSE, $do_icon_link = FALSE) {
40

    
41
  $citation = trim($reference->titleCache);
42
  $icon_link = "";
43
  if((isset($do_icon_link) && $do_icon_link === TRUE)) {
44
    $icon_link = cdm_internal_link(path_to_reference($reference->uuid));
45
  }
46
  if (isset($do_text_link) && $do_text_link === TRUE) {
47
    $out = '<span class="reference">';
48
    $out .= l($citation, path_to_reference($reference->uuid), array(
49
      'attributes' => array(
50
        "class" => "reference",
51
      ),
52
      'absolute' => TRUE,
53
      'html' => TRUE,
54
    ));
55
    $out .= $icon_link . '</span>';
56
  }
57
  else {
58
    $out = '<span class="reference">' . $citation . $icon_link . '</span>';
59
  }
60

    
61
  if (!empty($citation_detail)) {
62
    $out .= ": " . $citation_detail;
63
  }
64

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

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

    
78
  return $out;
79
}
80

    
81
/**
82
 * Creates an internal link displayes as icon.
83
 *
84
 * @param $path
85
 * The drupal path to create the link for
86
 * @param string[] $class_attributes
87
 *   Class attributes for the link element. By default ['superscript'] is being used.
88
 *
89
 * @return string
90
 */
91
function cdm_internal_link($path, $class_attributes = ['superscript']) {
92
  return l(custom_icon_font_markup('icon-interal-link-alt-solid', ['class' => $class_attributes]), $path, ['html' => true]);
93
}
94

    
95
/**
96
 * Creates a HTML representations for a CDM ReferenceDTO object
97
 *
98
 * In terms of rendering the entity and dto are interchangeable,
99
 * therefore this method simply delegates to the according entity method.
100
 *
101
 *  @param $reference_dto
102
 *      The dto to be rendered
103
 *  @param string $microReference
104
 *      The citation detail like page number
105
 *  @param boolean doTextLink
106
 *      Show the citation string as link to the reference page. This option does not affect links to the reference URI or DOI.
107
 *      These links are always created when this data is available
108
 *  @param boolean doIconLink
109
 *      Append an icon to the citation string which links to the reference page, links to the reference URI or DOI are always
110
 *      created when this data is available
111
 *
112
 * @return string
113
 *    the markup for the referenceDTO
114
 *
115
 */
116
function cdm_reference_dto_markup($reference_dto, $microReference = NULL, $doTextLink = FALSE, $doIconLink = FALSE) {
117
  return cdm_reference_markup($reference_dto, $microReference, $doTextLink, $doIconLink);
118
}
119

    
120
/**
121
 * Creates a anchor tag as clickable link to an external resource, either as text link or as icon.
122
 * The resulting link will have no 'target' attribute, so the link will open in the same tab by default.
123
 * So the users can decide.
124
 *
125
 * @param $uri
126
 *    The uri to link to
127
 * @param $iconified
128
 *    The link will be rendered as icon of this is true.
129
 * @return string
130
 *
131
 */
132
function cdm_external_uri($uri, $iconified = true)
133
{
134
  $options = array(
135
    'external' => true,
136
    'html' => false,
137
    );
138
  if (!empty($uri)) {
139
    if($iconified){
140
      $options['html'] = true;
141
      return l(font_awesome_icon_markup('fa-external-link-alt', array('class' => array('superscript'))), $uri, $options);
142
    } else {
143
      return l($uri, $uri, $options);
144
    }
145
  }
146
}
147

    
148
/**
149
 * Creates markup for a CDM Doi entity.
150
 *
151
 * @param $doi
152
 *  The CDM DOI
153
 *
154
 * @return string
155
 *  Markup
156
 */
157
function cdm_doi($doi, $iconified = true) {
158

    
159
  if (!empty($doi)) {
160

    
161
    $doi_resolve_uri = 'http://doi.org/' . $doi->prefix;
162
    if (isset($doi->suffix)) {
163
      $doi_resolve_uri .= '/' . $doi->suffix;
164
    }
165
    if($iconified){
166
      return l(font_awesome_icon_markup('fa-external-link-square-alt', array('class' => array('superscript'))), $doi_resolve_uri, array('html' => TRUE));
167
    } else {
168
      return l($doi_resolve_uri, $doi_resolve_uri);
169
    }
170
  }
171

    
172
}
173

    
174
/**
175
 * Renders a representation for an CDM OriginalSourceBase entity
176
 *
177
 * @param $source
178
 *  The cdm OriginalSourceBase entity
179
 * @param bool $do_link_to_reference
180
 *
181
 * @param bool $do_link_to_name_used_in_source
182
 *
183
 * @return string
184
 */
185
function render_original_source($source, $do_link_to_reference = TRUE, $do_link_to_name_used_in_source = FALSE) {
186
  $out = '';
187

    
188
  if (isset($source->citation)) {
189
    $out .= cdm_reference_markup($source->citation, $source->citationMicroReference, false, $do_link_to_reference);
190
  }
191
  if(isset($source->cdmSource)){
192
    $out .= render_cdm_entity_link($source->cdmSource);
193
  }
194

    
195
  if($out){
196

    
197
    $name_in_source_render_array = compose_name_in_source($source, $do_link_to_name_used_in_source);
198
    if(!empty($name_in_source_render_array)) {
199
      $out .=  ' <span class="nameUsedInSource">(' . t('as') . ' ' . $name_in_source_render_array['#markup'] . ')</span>';
200
    }
201

    
202
    $id_with_namespace = '';
203
    if( isset($source->idNamespace) && $source->idNamespace ) {
204
      $id_with_namespace = $source->idNamespace . ' ';
205
    }
206
    if( isset($source->idInSource) && $source->idInSource ) {
207
      $id_with_namespace .= $source->idInSource;
208
    } else {
209
      $id_with_namespace = NULL;
210
    }
211

    
212
    if($id_with_namespace){
213
      $out .=  ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
214
    }
215
  }
216

    
217
  return $out;
218
}
(6-6/8)