Project

General

Profile

Download (5.05 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
 * Creates a pager widget for the given CDM Pager containing CDM Reference entities.
18
 *
19
 * @param $referencePager object
20
 *    A CDM Pager  containing CDM Reference entities
21
 * @param $path
22
 *    The base path to be used when generating the pager item links
23
 * @$parameters
24
 *
25
 * @return string
26
 *   Markup
27
 */
28
function cdm_reference_pager($referencePager, $path, $parameters) {
29

    
30
  drupal_set_title(t('Bibliographic index'), PASS_THROUGH);
31
  $out = '';
32
  if (count($referencePager->records) > 0) {
33
    $out .= '<ul>';
34
    foreach ($referencePager->records as $reference) {
35
      // FIXME remove hack.
36
      $reference->fullCitation = $reference->titleCache;
37
      // For matching cdm entity to STO.
38
      $out .= '<li>' . theme('cdm_reference', array(
39
        'reference' => $reference,
40
        'microReference' => NULL,
41
        'doLink' => TRUE,
42
        )) . '</li>';
43
    }
44
    $out .= '</ul>';
45
    $out .= theme('cdm_pager', array(
46
      'pager' => $referencePager,
47
      'path' => $path,
48
      'parameters' => $parameters,
49
    ));
50
  }
51
  else {
52
    $out = '<h4 class="error">Sorry, this page contains not entries.</h4>';
53
  }
54
  return $out;
55
}
56

    
57
/**
58
 * Creates a HTML representations for a CDM Reference instance..
59
 *
60
 * Used by:
61
 * - theme_cdm_typedesignations
62
 * - cdm_reference_pager
63
 * - cdm_taxonRelationships
64
 *
65
 * @param array $variables
66
 *   An associative array containing:
67
 *   - reference
68
 *   - microReference
69
 *   - doLink:
70
 *      Whether to create a link to the reference page, links to the reference URI or DOI are always
71
 *      created when this data is available
72
 *   - referenceStyle: the value "zoology" will cause a specific rendeting of the
73
 *      reference suitable for zoological publications.
74
 *
75
 * @return string
76
 *    the markup for the reference
77
 *
78
 * @ingroup themeable
79
 */
80
function theme_cdm_reference($variables) {
81
  $reference = $variables['reference'];
82
  $microReference = $variables['microReference'];
83
  $doLink = $variables['doLink'];
84
  $referenceStyle = $variables['referenceStyle'];
85

    
86
  if (!isset($reference->authorship)) {
87
    $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
88
  }
89
  else {
90
    $author_team = $reference->authorship;
91
  }
92

    
93
  if ($referenceStyle == "zoology") {
94
    $year = '';
95
    if (isset($reference->datePublished->start)) {
96
      $year = partialToYear($reference->datePublished->start);
97
    }
98
    $citation = $author_team->titleCache . (!empty($year) ? '. ' . $year : '');
99
  }
100
  else {
101
    $citation = $reference->titleCache;
102
  }
103

    
104
  if (isset($doLink) && $doLink === TRUE) {
105
    $out = '<span class="reference">';
106
    $out .= l($citation, path_to_reference($reference->uuid), array(
107
      'attributes' => array(
108
        "class" => "reference",
109
      ),
110
      'absolute' => TRUE,
111
      'html' => TRUE,
112
    ));
113
    $out .= '</span>';
114
  }
115
  else {
116
    $out = '<span class="reference">' . $citation . '</span>';
117
  }
118

    
119
  if (!empty($microReference)) {
120
    $out .= ": " . $microReference;
121
  }
122

    
123
  if (isset($reference->doi) && !empty($reference->doi)) {
124

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

    
135
  return $out;
136
}
137

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

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

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

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

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