Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / theme / cdm_dataportal.common.theme @ c278f2a0

History | View | Annotate | Download (14.3 KB)

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
 * @todo Please document this function.
54
 * @see http://drupal.org/node/1354
55
 */
56
function taxon_in_current_classification($taxon_uuid) {
57
  $taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon_uuid);
58
  $taxon_in_current_tree = FALSE;
59
  if (is_array($taxon_nodes)) {
60
    foreach ($taxon_nodes as $node) {
61
      if (get_current_classification_uuid() == $node->classification->uuid) {
62
        $taxon_in_current_tree = TRUE;
63
        break;
64
      }
65
    }
66
  }
67
  return $taxon_in_current_tree;
68
}
69

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

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

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

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

    
118
/* ============================ annotations ============================= */
119

    
120
/**
121
 * Returns HTML for annotations to cdm objects.
122
 *
123
 * Almost any cdmObject may be annotated. Therefore we provide a generic way to
124
 * display as well as create or update annotations. The following cdm classes
125
 * are annotatable:
126
 *
127
 * - DescriptionElementBase
128
 * - EventBase
129
 * - HomotypicalGroup
130
 * - IdentifiableEntity
131
 * - DescriptionBase
132
 * - IdentifiableMediaEntity
133
 * - Media
134
 * - Sequence
135
 * - TaxonBase
136
 * - TaxonNameBase
137
 * - TaxonomicTree
138
 * - TermBase
139
 * - LanguageStringBase
140
 * - ReferencedEntityBase
141
 * - NomenclaturalStatus
142
 * - OriginalSourceBase
143
 * - RelationshipBase
144
 * - TypeDesignationBase
145
 * - TaxonNode
146
 * - WorkingSet
147
 *
148
 * @param array $variables
149
 *   An associative array containing:
150
 *  - cdmBase_list: An array of CdmBase instances or a single instance.
151
 *  - footnote_list_key
152
 *
153
 * @ingroup themeable
154
 */
155
function theme_cdm_annotations_as_footnotekeys($variables) {
156
  $cdm_entities = $variables['cdmBase_list'];
157
  $footnote_list_key = $variables['footnote_list_key'];
158
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
159
    return '';
160
  }
161
  $out = '';
162
  $footNoteKeys = cdm_annotations_as_footnotekeys($cdm_entities, $footnote_list_key);
163
  foreach ($footNoteKeys as $a) {
164
    // $out .= theme('cdm_footnote_key', $a, $a->footnoteListKey, (isset($out)?
165
    // ',' : ''));
166
    $out .= theme('cdm_footnote_key', array('footnoteKey' => $a, 'separator' => ($out ? ',' : '')));
167
  }
168
  return $out;
169
}
170

    
171
/**
172
 * @todo Please document this function.
173
 * @see http://drupal.org/node/1354
174
 */
175
function theme_cdm_annotation_footnotes($variables) {
176
  $footnoteListKey = $variables['footnoteListKey'];
177
  $enclosingTag = $variables['enclosingTag'];
178
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
179
    return '';
180
  }
181
  return theme('cdm_footnotes', array('footnoteListKey' => $footnoteListKey . '-annotations', 'enclosingTag' => $enclosingTag));
182
}
183

    
184
/**
185
 * @todo Please document this function.
186
 * @see http://drupal.org/node/1354
187
 */
188
function theme_cdm_annotation_content($variables) {
189
  $AnnotationTO = $variables['AnnotationTO'];
190
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cdm_annotations.js');
191
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/jquery.form.js');
192

    
193
  $out = theme('cdm_list_of_annotations', array('annotationElements' => $AnnotationTO->annotationElements));
194

    
195
  $annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array(
196
    $AnnotationTO->uuid,
197
  ));
198
  $annotationProxyUrl = url('cdm_api/proxy/' . urlencode($annotationUrl) . '/cdm_annotation_post');
199

    
200
  // TODO users have to be authenticated to the dataportal to be able to write
201
  // annotations.
202
  $out .= '
203
        <div class="annotation_create">
204
          <form action="' . $annotationProxyUrl . '" method="POST">
205
            <textarea name="annotation"></textarea>
206
            <input type="hidden" name="commentator" value="">
207
            <input type="submit" value="' . t('Save annotation') . '" />
208
          </form>
209
       </div>
210
  ';
211

    
212
  return $out;
213
}
214

    
215
/**
216
 * @todo Please document this function.
217
 * @see http://drupal.org/node/1354
218
 */
219
function theme_cdm_list_of_annotations($variables) {
220
  $annotationElements = $variables['annotationElements'];
221
  $out = '<ul class="annotation_list">';
222

    
223
  foreach ($annotationElements as $key => $row) {
224
    $created[$key] = $row;
225
  }
226
  array_multisort($created, SORT_ASC, $annotationElements);
227

    
228
  foreach ($annotationElements as $annotation) {
229
    $out .= '<li>' . $annotation->text . '</li>';
230
  }
231

    
232
  $out .= '</ul>';
233

    
234
  return $out;
235
}
236

    
237
/* ============================ footnotes ============================= */
238
/**
239
 * @todo Please document this function.
240
 * @see http://drupal.org/node/1354
241
 */
242
function theme_cdm_footnote_key($variables) {
243

    
244
  $footnoteKey = $variables['footnoteKey'];
245
  $separator = $variables['separator'];
246
  $highlightable = $variables['highlightable'];
247
  $separator_off = $variables['separator_off'];
248
  if (!is_object($footnoteKey) or !isset($footnoteKey->footnoteListKey)) {
249
    return '';
250
  }
251
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
252
    return '';
253
  }
254

    
255
  if ($separator_off) {
256
    $separator = '';
257
  }
258
  $out = '<span class="footnote-key footnote-key-' . $footnoteKey->keyStr . ' member-of-footnotes-' . $footnoteKey->footnoteListKey . '">' . $separator . '<a href="#footnote-' . $footnoteKey->keyStr . '">' . $footnoteKey->keyStr . '</a>' . '</span>';
259
  return $out;
260
}
261

    
262
/**
263
 * @todo Please document this function.
264
 * @see http://drupal.org/node/1354
265
 */
266
function theme_cdm_footnote($variables) {
267
  $footnoteKey = $variables['footnoteKey'];
268
  $footnoteText = $variables['footnoteText'];
269
  $enclosing_tag = $variables['enclosing_tag'];
270
  _add_js_footnotes();
271
  $out = '<' . $enclosing_tag . ' class="footnote footnote-' . $footnoteKey . '">'
272
    . '<a name="footnote-' . $footnoteKey . '"></a>'
273
    . '<span class="footnote-anchor">' . $footnoteKey . '.</span>&nbsp;' . $footnoteText
274
    . '</' . $enclosing_tag . '>';
275
  return $out;
276
}
277

    
278
/**
279
 * @todo Please document this function.
280
 * @see http://drupal.org/node/1354
281
 */
282
function theme_cdm_footnotes($variables) {
283
  $footnoteListKey = $variables['footnoteListKey'];
284
  $enclosingTag = $variables['enclosingTag'];
285
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
286
    return '';
287
  }
288

    
289
  $out = '<' . $enclosingTag . ' class="footnotes footnotes-' . $footnoteListKey . ' ">'
290
    . FootnoteManager::renderFootnoteList($footnoteListKey)
291
    . '</' . $enclosingTag . '>';
292

    
293
  FootnoteManager::removeFootnoteList($footnoteListKey);
294
  return $out;
295
}
296

    
297
/**
298
 * @todo Please document this function.
299
 * @see http://drupal.org/node/1354
300
 */
301
function theme_cdm_annotations($variables) {
302
  $annotations = $variables['annotations'];
303
  $enclosingTag = $variables['enclosingTag'];
304
  if (!is_array($annotations)) {
305
    return;
306
  }
307
  $out = '<' . $enclosingTag . ' class="annotations">';
308
  $i = 0;
309
  foreach ($annotations as $annotation) {
310
    $out .= ($i++ > 0 ? ', ' : '') . $annotation->text;
311
  }
312
  $out .= '</' . $enclosingTag . '>';
313
  return $out;
314
}
315

    
316
/**
317
 * @todo Please document this function.
318
 * @see http://drupal.org/node/1354
319
 */
320
function cdm_exist_footnote($footnote_list, $footnote) {
321
  $result = FALSE;
322
  if (is_array($footnote_list)) {
323
    foreach ($footnote_list as $element) {
324
      if ($element == $footnote) {
325
        $result = TRUE;
326
      }
327
    }
328
  }
329
  return $result;
330
}
331

    
332
/**
333
 * @todo Please document this function.
334
 * @see http://drupal.org/node/1354
335
 */
336
function cdm_add_footnote_to_array(&$footnote_list, $footnote) {
337
  if (!cdm_exist_footnote($footnote_list, $footnote)) {
338
    $footnote_list[] = $footnote;
339
  }
340
}
341

    
342
/**
343
 * Theme function for CDM marker instances
344
 *
345
 * @see compose_cdm_marker();
346
 * @param array $variables
347
 *   - markerType_representation_l10n: the localized representation of the marker.markerType field
348
 */
349
function theme_cdm_marker($variables) {
350
  $class_attribute = null;
351
  //TODO class attribute hacked?, use generic drupal way?
352
  if(isset($variables['attributes']['class'])){
353
    $class_attribute = $variables['attributes']['class'];
354
  }
355
  return '<span class="' . $class_attribute . '">' . $variables['label'] . '</span>';
356
}
357

    
358
/* ============================ pager ============================= */
359

    
360
/**
361
 * @todo Please document this function.
362
 * @see http://drupal.org/node/1354
363
 */
364
function theme_cdm_pager($variables) {
365
  $pager = $variables['pager'];
366
  $path = $variables['path'];
367
  $parameters = $variables['parameters'];
368
  $out = '';
369

    
370
  if ($pager->pagesAvailable > 1) {
371

    
372
    $out .= '<div class="pager">';
373
    if ($pager->currentIndex > 0) {
374
      $out .= theme('cdm_pager_link', array(
375
        'text' => '« ' . t('First'),
376
        'linkIndex' => 0,
377
        'pager' => $pager,
378
        'path' => $path,
379
        'parameters' => $parameters,
380
        'attributes' => array('class' => array('pager-first')),
381
        ));
382
      $out .= theme('cdm_pager_link', array(
383
        'text' => '‹ ' . t('Previous'),
384
        'linkIndex' => $pager->currentIndex - 1,
385
        'pager' => $pager,
386
        'path' => $path,
387
        'parameters' => $parameters,
388
        'attributes' => array('class' => array('pager-previous')),
389
        ));
390
    }
391

    
392
    if ($pager->indices[0] > 0) {
393
      $out .= '<div class="pager-list-dots-left">...</div>';
394
    }
395

    
396
    foreach ($pager->indices as $index) {
397
      $label = $index + 1;
398
      $out .= theme('cdm_pager_link', array('text' => $label, 'linkIndex' => $index, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
399
  'class' => array('pager-first'),
400
)));
401
    }
402
    if ($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1) {
403
      $out .= '<div class="pager-list-dots-right">...</div>';
404
    }
405

    
406
    if ($pager->nextIndex) {
407
      $out .= theme(
408
        'cdm_pager_link',
409
        array(
410
          'text' => t('Next') . ' ›',
411
          'linkIndex' => $pager->nextIndex,
412
          'pager' => $pager,
413
          'path' => $path,
414
          'parameters' => $parameters,
415
          'attributes' => array(
416
            'class' => array('pager-next'),
417
          )
418
        )
419
      );
420
      $out .= theme(
421
        'cdm_pager_link',
422
        array(
423
          'text' => t('Last') . ' »',
424
          'linkIndex' => $pager->pagesAvailable - 1,
425
          'pager' => $pager,
426
          'path' => $path,
427
          'parameters' => $parameters,
428
          'attributes' => array(
429
            'class' => array('pager-last'),
430
          )
431
        )
432
      );
433
    }
434
    $out .= '</div>';
435

    
436
    return $out;
437
  }
438
}
439

    
440
/**
441
 * @todo Please document this function.
442
 * @see http://drupal.org/node/1354
443
 */
444
function theme_cdm_pager_link($variables) {
445
  $text = $variables['text'];
446
  $linkIndex = $variables['linkIndex'];
447
  $pager = $variables['pager'];
448
  $path = $variables['path'];
449
  $parameters = $variables['parameters'];
450
  $attributes = $variables['attributes'];
451

    
452
  // the parameters may still contain the q param,
453
  // but this is already in the path variable
454
  unset($parameters['q']);
455

    
456
  $parameters['pager']['pageNumber'] = $linkIndex;
457
  if ($linkIndex == $pager->currentIndex) {
458
    $out = '<strong>' . $text . '</strong>';
459
  }
460
  else {
461
    // $queryString = drupal_query_string_encode($parameters);
462
    $queryString = $parameters;
463
    $out = l($text, $path, array(
464
      'attributes' => $attributes,
465
      'query' => $queryString,
466
    ));
467
  }
468
  return $out;
469
}
470

    
471
/* ============================ special buttons ============================= */
472

    
473
/**
474
 * @todo Please document this function.
475
 * @see http://drupal.org/node/1354
476
 */
477
function theme_cdm_back_to_image_gallery_button() {
478
  $out = '<div id="backToGalleryButton">' . l(t('Back to Images'), $_SESSION['cdm']['last_gallery']) . '</div>';
479
  return $out;
480
}
481

    
482
/**
483
 * @todo Please document this function.
484
 * @see http://drupal.org/node/1354
485
 */
486
function theme_cdm_print_button() {
487

    
488
  drupal_add_js('jQuery(document).ready(function() {
489
         jQuery(\'#print_button\').click(function () {
490
         window.print();
491
     });
492
  });', array('type' => 'inline'));
493

    
494
  $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') . '" />';
495
  // .t('Print this page');
496
  // $output .= l('Print this page', '');
497
  $output .= '<span>Print this page</span>';
498
  $output .= '</div>';
499

    
500
  return $output;
501
}
502

    
Add picture from clipboard (Maximum size: 40 MB)