Project

General

Profile

Download (5.67 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
 * @todo Please document this function.
18
 * @see http://drupal.org/node/1354
19
 */
20
function theme_cdm_reference_pager($variables) {
21
  $referencePager = $variables['referencePager'];
22
  $path = $variables['path'];
23
  $parameters = $variables['parameters'];
24
  drupal_set_title(t('Bibliographic index'), PASS_THROUGH);
25
  $out = '';
26
  if (count($referencePager->records) > 0) {
27
    $out .= '<ul>';
28
    foreach ($referencePager->records as $reference) {
29
      // FIXME remove hack.
30
      $reference->fullCitation = $reference->titleCache;
31
      // For matching cdm entity to STO.
32
      $out .= '<li>' . theme('cdm_reference', array(
33
        'reference' => $reference,
34
        'microReference' => NULL,
35
        'doLink' => TRUE,
36
        )) . '</li>';
37
    }
38
    $out .= '</ul>';
39
    $out .= theme('cdm_pager', array(
40
      'pager' => $referencePager,
41
      'path' => $path,
42
      'parameters' => $parameters,
43
    ));
44
  }
45
  else {
46
    $out = '<h4 class="error">Sorry, this page contains not entries.</h4>';
47
  }
48
  return $out;
49
}
50

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

    
80
  if (!isset($reference->authorship)) {
81
    $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
82
  }
83
  else {
84
    $author_team = $reference->authorship;
85
  }
86

    
87
  if ($referenceStyle == "zoology") {
88
    $year = '';
89
    if (isset($reference->datePublished->start)) {
90
      $year = partialToYear($reference->datePublished->start);
91
    }
92
    $citation = $author_team->titleCache . (!empty($year) ? '. ' . $year : '');
93
  }
94
  else {
95
    $citation = $reference->titleCache;
96
  }
97

    
98
  if (isset($doLink) && $doLink === TRUE) {
99
    $out = '<span class="reference">';
100
    $out .= l($citation, path_to_reference($reference->uuid), array(
101
      'attributes' => array(
102
        "class" => "reference",
103
      ),
104
      'absolute' => TRUE,
105
      'html' => TRUE,
106
    ));
107
    $out .= '</span>';
108
  }
109
  else {
110
    $out = '<span class="reference">' . $citation . '</span>';
111
  }
112

    
113
  if (!empty($microReference)) {
114
    $out .= ": " . $microReference;
115
  }
116

    
117
  if (isset($reference->doi) && !empty($reference->doi)) {
118

    
119
    $doi_resolve_uri = 'http://doi.org/' . $reference->doi->prefix;
120
    if(isset($reference->doi->suffix)){
121
      $doi_resolve_uri .= '/' . $reference->doi->suffix;
122
    }
123
    $out .= l(font_awesome_icon_markup('fa-external-link-square', array('class' => array('superscript'))), $doi_resolve_uri, array('html' => TRUE));
124
  }
125
  if (isset($reference->uri) && !empty($reference->uri)) {
126
    $out .= l(font_awesome_icon_markup('fa-external-link', array('class' => array('superscript'))), $reference->uri, array('html' => TRUE));
127
  }
128

    
129
  return $out;
130
}
131

    
132
/**
133
 * Cleanup of the textual short form of an author team.
134
 *
135
 * The cdm fails to create correct representations of author teams.
136
 * The '&' gluing the authors together need to be cleaned up.
137
 *
138
 * @param $author_team
139
 *  the authorTeam string
140
 *
141
 * @return string
142

    
143
 */
144
function _short_form_of_author_team($author_team) {
145
  $number_of_authors = substr_count($author_team, ' & ') + 1;
146
  // var_dump($author_team);
147
  // var_dump($number_of_authors);
148
  switch ($number_of_authors) {
149
    case 1:
150
      $result = $author_team;
151
      break;
152

    
153
    case 2:
154
      $result = str_replace(' & ', ' and ', $author_team);
155
      break;
156

    
157
    default:
158
      $result_parts = explode(' & ', $author_team);
159
      $result = $result_parts[0] . ' et al.';
160
  }
161
  return $result;
162
}
163

    
164
/**
165
 * @todo Please document this function.
166
 * @see http://drupal.org/node/1354
167
 */
168
function theme_cdm_OriginalSource($variables) {
169
  $out = '';
170
  $source = $variables['source'];
171
  $do_link_to_reference = $variables['doLink'];
172
  $do_link_to_name_used_in_source = $variables['do_link_to_name_used_in_source'];
173

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

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

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

    
196
    if($id_with_namespace){
197
      $out .=  ' <span class="idInSource">[' . $id_with_namespace . ']</span>';
198
    }
199
  }
200
  return $out;
201
}
(7-7/9)