Project

General

Profile

Download (9.72 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Common 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
define('FOOTNOTE_ANNOTATIONS', 'annotations');
17

    
18
/**
19
 * Get the true path to the root of the Drupal site.
20
 *
21
 * Better than using DOCUMENT_ROOT and base_path().
22
 */
23
function absolute_path_to_drupal() {
24
  static $absolute_path_to_drupal = NULL;
25

    
26
  if ($absolute_path_to_drupal === NULL) {
27
    // Get the absolute path to this file:
28
    $dir = rtrim(str_replace('\\', '/', dirname(__FILE__)), '/');
29
    $parts = explode('/', $dir);
30
    // Iterate up the directory hierarchy until we find the website root:
31
    $done = FALSE;
32
    do {
33
      // Check a couple of obvious things:
34
      $done = is_dir("$dir/sites") && is_dir("$dir/includes") && is_file("$dir/index.php");
35
      if (!$done) {
36
        // If there's no more path to examine, we didn't find the site root:
37
        if (empty($parts)) {
38
          $absolute_path_to_drupal = FALSE;
39
          break;
40
        }
41
        // Go up one level and look again:
42
        array_pop($parts);
43
        $dir = implode('/', $parts);
44
      }
45
    } while (!$done);
46

    
47
    $absolute_path_to_drupal = $dir;
48
  }
49
  return $absolute_path_to_drupal;
50
}
51

    
52
/**
53
 * Checks if the taxon specified by the uuid is contained in the currently focused classification.
54
 *
55
 * @param $taxon_uuid
56
 * @return bool
57
 */
58
function taxon_in_current_classification($taxon_uuid) {
59
  $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon_uuid);
60
  $taxon_in_current_tree = FALSE;
61
  if (is_array($taxon_nodes)) {
62
    foreach ($taxon_nodes as $node) {
63
      if (get_current_classification_uuid() == $node->classificationUUID) {
64
        $taxon_in_current_tree = TRUE;
65
        break;
66
      }
67
    }
68
  }
69
  return $taxon_in_current_tree;
70
}
71

    
72
/**
73
 * TODO if getting fragment from request is possible remove
74
 * $_REQUEST['highlite'] HACK
75
 * NOT WORKING since fragments are not available to the server
76
 *
77
 * function fragment(){
78
 *    global $fragment;
79
 *    if(!$fragment){
80
 *       $fragment = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '#'));
81
 *    }
82
 *   return $fragment;
83
 * }
84
 */
85
function uuid_anchor($uuid, $innerHTML) {
86
  $highlite = FALSE;
87
  $params = drupal_get_query_parameters();
88
  if (isset($params['highlite']) && $params['highlite'] == $uuid) {
89
    $highlite = TRUE;
90
  }
91

    
92
  return '<a name="' . $uuid . '" ></a><span class="' . ($highlite ? 'highlite' : '') . '">' . $innerHTML . '</span>';
93
}
94

    
95
/**
96
 * @todo Enter description here...
97
 * @deprecated looks like this is not used anymore
98
 */
99
/*
100
function tagNameParts($name, $numOfNameTokens) {
101
  $out = '<span class="name">';
102

    
103
  $token = strtok($name, " \n\t");
104
  $i = 0;
105
  $noSpace = TRUE;
106
  while ($token != FALSE) {
107
    if ($i == $numOfNameTokens) {
108
      $out .= '</span> <span class="authors">';
109
      $noSpace = TRUE;
110
    }
111
    $out .= ($noSpace ? '' : ' ') . $token;
112
    $noSpace = FALSE;
113
    $token = strtok(" \n\t");
114
    $i++;
115
  }
116
  return $out . '</span>';
117
}
118
*/
119

    
120
/* ============================ annotations ============================= */
121

    
122
/**
123
 * Returns HTML for annotations to cdm objects.
124
 *
125
 * Almost any cdmObject may be annotated. Therefore we provide a generic way to
126
 * display as well as create or update annotations. The following cdm classes
127
 * are annotatable:
128
 *
129
 * - DescriptionElementBase
130
 * - EventBase
131
 * - HomotypicalGroup
132
 * - IdentifiableEntity
133
 * - DescriptionBase
134
 * - IdentifiableMediaEntity
135
 * - Media
136
 * - Sequence
137
 * - TaxonBase
138
 * - TaxonName
139
 * - TaxonomicTree
140
 * - TermBase
141
 * - LanguageStringBase
142
 * - ReferencedEntityBase
143
 * - NomenclaturalStatus
144
 * - OriginalSourceBase
145
 * - RelationshipBase
146
 * - TypeDesignationBase
147
 * - TaxonNode
148
 * - WorkingSet
149
 *
150
 * @param array $cdm_entities
151
 *   An array of CdmBase instances.
152
 * @param $footnote_list_key_suggestion string
153
 *    optional parameter. If this parameter is left empty (null, 0, "") the
154
 *   footnote key will be determined be set to
155
 *   RenderHints::getFootnoteListKey().'-annotations' otherwise the supplied
156
 *   key will be used.
157
 *
158
 * @return string
159
 *   The markup.
160
 */
161
function cdm_entities_annotations_as_footnotekeys($cdm_entities, $footnote_list_key =null){
162

    
163
  // check if footnotes for annotations are disabled completely
164
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
165
    return '';
166
  }
167
  $out = '';
168
  if(is_array($cdm_entities)){
169
    // array of entities
170
    $footNoteKeys = cdm_entities_annotations_footnotekeys($cdm_entities, $footnote_list_key);
171
  } else {
172
    // single entity
173
    $footNoteKeys = cdm_entity_annotations_as_footnotekeys($cdm_entities, $footnote_list_key);
174
  }
175
  foreach ($footNoteKeys as $a) {
176
    $out .= cdm_footnote_key($a, ($out ? ',' : ''));
177
  }
178
  return $out;
179
}
180

    
181
/**
182
 * Created markup for the annotations
183
 * @param null $annotations
184
 * @param $enclosingTag
185
 *  Tag name of the DOM element to enclose the annotations.
186
 *
187
 * @return string
188
 */
189
function cdm_annotations($annotations = null, $enclosingTag = span) {
190

    
191
  if (!is_array($annotations)) {
192
    return '';
193
  }
194
  $out = '<' . $enclosingTag . ' class="annotations">';
195
  $i = 0;
196
  foreach ($annotations as $annotation) {
197
    $out .= ($i++ > 0 ? ', ' : '') . $annotation->text;
198
  }
199
  $out .= '</' . $enclosingTag . '>';
200
  return $out;
201
}
202

    
203

    
204

    
205
/**
206
 * Theme function for CDM marker instances
207
 *
208
 * @see compose_cdm_marker();
209
 * @param array $variables
210
 *   - markerType_representation_l10n: the localized representation of the marker.markerType field
211
 */
212
function theme_cdm_marker($variables) {
213
  $class_attribute = null;
214
  //TODO class attribute hacked?, use generic drupal way?
215
  if(isset($variables['attributes']['class'])){
216
    $class_attribute = $variables['attributes']['class'];
217
  }
218
  return '<span class="' . $class_attribute . '">' . $variables['label'] . '</span>';
219
}
220

    
221
/* ============================ pager ============================= */
222

    
223
/**
224
 * @todo Please document this function.
225
 * @see http://drupal.org/node/1354
226
 */
227
function theme_cdm_pager($variables) {
228
  $pager = $variables['pager'];
229
  $path = $variables['path'];
230
  $parameters = $variables['parameters'];
231
  $out = '';
232

    
233
  if ($pager->pagesAvailable > 1) {
234

    
235
    $out .= '<div class="pager">';
236
    if ($pager->currentIndex > 0) {
237
      $out .= theme('cdm_pager_link', array(
238
        'text' => '« ' . t('First'),
239
        'linkIndex' => 0,
240
        'pager' => $pager,
241
        'path' => $path,
242
        'parameters' => $parameters,
243
        'attributes' => array('class' => array('pager-first')),
244
        ));
245
      $out .= theme('cdm_pager_link', array(
246
        'text' => '‹ ' . t('Previous'),
247
        'linkIndex' => $pager->currentIndex - 1,
248
        'pager' => $pager,
249
        'path' => $path,
250
        'parameters' => $parameters,
251
        'attributes' => array('class' => array('pager-previous')),
252
        ));
253
    }
254

    
255
    if ($pager->indices[0] > 0) {
256
      $out .= '<div class="pager-list-dots-left">...</div>';
257
    }
258

    
259
    foreach ($pager->indices as $index) {
260
      $label = $index + 1;
261
      $out .= theme('cdm_pager_link', array('text' => $label, 'linkIndex' => $index, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
262
  'class' => array('pager-first'),
263
)));
264
    }
265
    if ($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1) {
266
      $out .= '<div class="pager-list-dots-right">...</div>';
267
    }
268

    
269
    if ($pager->nextIndex) {
270
      $out .= theme(
271
        'cdm_pager_link',
272
        array(
273
          'text' => t('Next') . ' ›',
274
          'linkIndex' => $pager->nextIndex,
275
          'pager' => $pager,
276
          'path' => $path,
277
          'parameters' => $parameters,
278
          'attributes' => array(
279
            'class' => array('pager-next'),
280
          )
281
        )
282
      );
283
      $out .= theme(
284
        'cdm_pager_link',
285
        array(
286
          'text' => t('Last') . ' »',
287
          'linkIndex' => $pager->pagesAvailable - 1,
288
          'pager' => $pager,
289
          'path' => $path,
290
          'parameters' => $parameters,
291
          'attributes' => array(
292
            'class' => array('pager-last'),
293
          )
294
        )
295
      );
296
    }
297
    $out .= '</div>';
298

    
299
    return $out;
300
  }
301
}
302

    
303
/**
304
 * @todo Please document this function.
305
 * @see http://drupal.org/node/1354
306
 */
307
function theme_cdm_pager_link($variables) {
308
  $text = $variables['text'];
309
  $linkIndex = $variables['linkIndex'];
310
  $pager = $variables['pager'];
311
  $path = $variables['path'];
312
  $parameters = $variables['parameters'];
313
  $attributes = $variables['attributes'];
314

    
315
  // the parameters may still contain the q param,
316
  // but this is already in the path variable
317
  unset($parameters['q']);
318

    
319
  $parameters['pager']['pageNumber'] = $linkIndex;
320
  if ($linkIndex == $pager->currentIndex) {
321
    $out = '<strong>' . $text . '</strong>';
322
  }
323
  else {
324
    // $queryString = drupal_query_string_encode($parameters);
325
    $queryString = $parameters;
326
    $out = l($text, $path, array(
327
      'attributes' => $attributes,
328
      'query' => $queryString,
329
    ));
330
  }
331
  return $out;
332
}
333

    
334
/* ============================ special buttons ============================= */
335

    
336
/**
337
 * @todo Please document this function.
338
 * @see http://drupal.org/node/1354
339
 */
340
function theme_cdm_print_button() {
341

    
342
  drupal_add_js('jQuery(document).ready(function() {
343
         jQuery(\'#print_button\').click(function () {
344
         window.print();
345
     });
346
  });', array('type' => 'inline'));
347

    
348
  $output = '<div id="print_button"><img src="' . base_path()  .  drupal_get_path('module', 'cdm_dataportal') . '/images/print_icon.gif"' . ' alt="' . t('Print this page') . '" title="' . t('Print this page') . '" />';
349
  // .t('Print this page');
350
  // $output .= l('Print this page', '');
351
  $output .= '<span>Print this page</span>';
352
  $output .= '</div>';
353

    
354
  return $output;
355
}
356

    
(1-1/9)