Project

General

Profile

Download (18.4 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
 * @todo Please document this function.
54
 * @see http://drupal.org/node/1354
55
 */
56
function taxon_in_current_tree($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_taxonomictree_uuid_selected() == $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
/**
119
 * Returns HTML for an array of TaggedText items.
120
 *
121
 * Converts an array of TaggedText items into a sequence of corresponding html
122
 * tags whereas each item will provided with a class attribute which set to
123
 * the key of the TaggedText item.
124
 *
125
 * @param array $variables
126
 *   An associative array containing:
127
 *   - taggedtxt: The array to format into html.
128
 *   - tag: The html tag to use.
129
 *   - glue: The string by which the chained text tokens are
130
 *     concatenated together. Default is a blank character.
131
 *   - skiptags: tags to skip.
132
 *
133
 * @ingroup themeable
134
 */
135
function theme_cdm_taggedtext2html($variables) {
136

    
137
  $taggedtxt = $variables['taggedtxt'];
138
  $tag = $variables['tag'];
139
  $glue = $variables['glue'];
140
  $skiptags = $variables['skiptags'];
141
  $out = '';
142
  $i = 0;
143
  foreach ($taggedtxt as $tt) {
144
    if (!in_array($tt->type, $skiptags) && strlen($tt->text) > 0) {
145
      $out .= (strlen($out) > 0 && ++$i < count($taggedtxt) ? $glue : '') . '<' . $tag . ' class="' . $tt->type . '">' . t($tt->text) . '</' . $tag . '>';
146
    }
147
  }
148
  return $out;
149
}
150

    
151
/* ============================ annotations ============================= */
152

    
153
/**
154
 * Returns HTML for annotations to cdm objects.
155
 *
156
 * Almost any cdmObject may be annotated. Therefore we provide a generic way to
157
 * display as well as create or update annotations. The following cdm classes
158
 * are annotatable:
159
 *
160
 * - DescriptionElementBase
161
 * - EventBase
162
 * - HomotypicalGroup
163
 * - IdentifiableEntity
164
 * - DescriptionBase
165
 * - IdentifiableMediaEntity
166
 * - Media
167
 * - Sequence
168
 * - TaxonBase
169
 * - TaxonNameBase
170
 * - TaxonomicTree
171
 * - TermBase
172
 * - LanguageStringBase
173
 * - ReferencedEntityBase
174
 * - NomenclaturalStatus
175
 * - OriginalSourceBase
176
 * - RelationshipBase
177
 * - TypeDesignationBase
178
 * - TaxonNode
179
 * - WorkingSet
180
 *
181
 * @param array $variables
182
 *   An associative array containing:
183
 *  - cdmBase_list: An array of CdmBase instances or a single instance.
184
 *  - footnote_list_key
185
 *
186
 * @ingroup themeable
187
 */
188
function theme_cdm_annotations_as_footnotekeys($variables) {
189
  $cdmBase_list = $variables['cdmBase_list'];
190
  $footnote_list_key = $variables['footnote_list_key'];
191
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
192
    return '';
193
  }
194
  $out = '';
195
  $footNoteKeys = cdm_annotations_as_footnotekeys($cdmBase_list, $footnote_list_key);
196
  foreach ($footNoteKeys as $a) {
197
    // $out .= theme('cdm_footnote_key', $a, $a->footnoteListKey, (isset($out)?
198
    // ',' : ''));
199
    $out .= theme('cdm_footnote_key', array('footnoteKey' => $a, 'separator' => ($out ? ',' : '')));
200
  }
201
  return $out;
202
}
203

    
204
/**
205
 * @todo Please document this function.
206
 * @see http://drupal.org/node/1354
207
 */
208
function theme_cdm_annotation_footnotes($variables) {
209
  $footnoteListKey = $variables['footnoteListKey'];
210
  $enclosingTag = $variables['enclosingTag'];
211
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
212
    return '';
213
  }
214
  return theme('cdm_footnotes', array('footnoteListKey' => $footnoteListKey . '-annotations', 'enclosingTag' => $enclosingTag));
215
}
216

    
217
/**
218
 * @todo Please document this function.
219
 * @see http://drupal.org/node/1354
220
 */
221
function theme_cdm_annotation_content($variables) {
222
  $AnnotationTO = $variables['AnnotationTO'];
223
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cdm_annotations.js');
224
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/jquery.form.js');
225

    
226
  $out .= theme('cdm_list_of_annotations', array('annotationElements' => $AnnotationTO->annotationElements));
227

    
228
  $annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array(
229
    $AnnotationTO->uuid,
230
  ));
231
  $annotationProxyUrl = url('cdm_api/proxy/' . urlencode($annotationUrl) . '/cdm_annotation_post');
232

    
233
  // TODO users have to be authenticated to the dataportal to be able to write
234
  // annotations.
235
  $out .= '
236
        <div class="annotation_create">
237
          <form action="' . $annotationProxyUrl . '" method="POST">
238
            <textarea name="annotation"></textarea>
239
            <input type="hidden" name="commentator" value="">
240
            <input type="submit" value="' . t('Save annotation') . '" />
241
          </form>
242
       </div>
243
  ';
244

    
245
  return $out;
246
}
247

    
248
/**
249
 * @todo Please document this function.
250
 * @see http://drupal.org/node/1354
251
 */
252
function theme_cdm_list_of_annotations($variables) {
253
  $annotationElements = $variables['annotationElements'];
254
  $out = '<ul class="annotation_list">';
255

    
256
  foreach ($annotationElements as $key => $row) {
257
    $created[$key] = $row;
258
  }
259
  array_multisort($created, SORT_ASC, $annotationElements);
260

    
261
  foreach ($annotationElements as $annotation) {
262
    $out .= '<li>' . $annotation->text . '</li>';
263
  }
264

    
265
  $out .= '</ul>';
266

    
267
  return $out;
268
}
269

    
270
/* ============================ footnotes ============================= */
271
/**
272
 * @todo Please document this function.
273
 * @see http://drupal.org/node/1354
274
 */
275
function theme_cdm_footnote_key($variables) {
276

    
277
  $footnoteKey = $variables['footnoteKey'];
278
  $separator = $variables['separator'];
279
  $highlightable = $variables['highlightable'];
280
  $separator_off = $variables['separator_off'];
281
  if (!is_object($footnoteKey) or !isset($footnoteKey->footnoteListKey)) {
282
    return '';
283
  }
284
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
285
    return '';
286
  }
287

    
288
  if ($separator_off) {
289
    $separator = '';
290
  }
291
  $out = '<span class="footnote-key footnote-key-' . $footnoteKey->keyStr . ' member-of-footnotes-' . $footnoteKey->footnoteListKey . '">' . $separator . '<a href="#footnote-' . $footnoteKey->keyStr . '">' . $footnoteKey->keyStr . '</a>' . '</span>';
292
  return $out;
293
}
294

    
295
/**
296
 * @todo Please document this function.
297
 * @see http://drupal.org/node/1354
298
 */
299
function theme_cdm_footnote($variables) {
300
  $footnoteKey = $variables['footnoteKey'];
301
  $footnoteText = $variables['footnoteText'];
302
  _add_js_footnotes();
303
  $out = '<span class="footnote footnote-' . $footnoteKey . '">'
304
    . '<a name="footnote-' . $footnoteKey . '"></a>'
305
    . '<span class="footnote-anchor">' . $footnoteKey . '.</span>&nbsp;' . $footnoteText
306
    . '</span>';
307
  return $out;
308
}
309

    
310
/**
311
 * @todo Please document this function.
312
 * @see http://drupal.org/node/1354
313
 */
314
function theme_cdm_footnotes($variables) {
315
  $footnoteListKey = $variables['footnoteListKey'];
316
  $enclosingTag = $variables['enclosingTag'];
317
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
318
    return '';
319
  }
320

    
321
  $out = '<' . $enclosingTag . ' class="footnotes footnotes-' . $footnoteListKey . ' ">'
322
    . FootnoteManager::renderFootnoteList($footnoteListKey)
323
    . '</' . $enclosingTag . '>';
324

    
325
  FootnoteManager::removeFootnoteList($footnoteListKey);
326
  return $out;
327
}
328

    
329
/**
330
 * @todo Please document this function.
331
 * @see http://drupal.org/node/1354
332
 */
333
function theme_cdm_annotations($variables) {
334
  $annotations = $variables['annotations'];
335
  $enclosingTag = $variables['enclosingTag'];
336
  if (!is_array($annotations)) {
337
    return;
338
  }
339
  $out = '<' . $enclosingTag . ' class="annotations">';
340
  $i = 0;
341
  foreach ($annotations as $annotation) {
342
    $out .= ($i++ > 0 ? ', ' : '') . $annotation->text;
343
  }
344
  $out .= '</' . $enclosingTag . '>';
345
  return $out;
346
}
347

    
348
/**
349
 * @todo Please document this function.
350
 * @see http://drupal.org/node/1354
351
 */
352
function cdm_exist_footnote($footnote_list, $footnote) {
353
  $result = FALSE;
354
  if (is_array($footnote_list)) {
355
    foreach ($footnote_list as $element) {
356
      if ($element == $footnote) {
357
        $result = TRUE;
358
      }
359
    }
360
  }
361
  return $result;
362
}
363

    
364
/**
365
 * @todo Please document this function.
366
 * @see http://drupal.org/node/1354
367
 */
368
function cdm_add_footnote_to_array(&$footnote_list, $footnote) {
369
  if (!cdm_exist_footnote($footnote_list, $footnote)) {
370
    $footnote_list[] = $footnote;
371
  }
372
}
373

    
374
/* ============================ pager ============================= */
375
/**
376
 * @todo Please document this function.
377
 * @see http://drupal.org/node/1354
378
 */
379
function theme_cdm_pager($variables) {
380
  $pager = $variables['pager'];
381
  $path = $variables['path'];
382
  $parameters = $variables['parameters'];
383
  $out = '';
384

    
385
  if ($pager->pagesAvailable > 1) {
386

    
387
    $out .= '<div class="pager">';
388
    if ($pager->currentIndex > 0) {
389
      $out .= theme('cdm_pager_link', array(
390
        'text' => t('« first'),
391
        'linkIndex' => 0,
392
        'pager' => $pager,
393
        'path' => $path,
394
        'parameters' => $parameters,
395
        'attributes' => array('class' => array('pager-first')),
396
        ));
397
      $out .= theme('cdm_pager_link', array(
398
        'text' => t('‹ previous'),
399
        'linkIndex' => $pager->currentIndex - 1,
400
        'pager' => $pager,
401
        'path' => $path,
402
        'parameters' => $parameters,
403
        'attributes' => array('class' => array('pager-previous')),
404
        ));
405
    }
406

    
407
    if ($pager->indices[0] > 0) {
408
      $out .= '<div class="pager-list-dots-left">...</div>';
409
    }
410

    
411
    foreach ($pager->indices as $index) {
412
      $label = $index + 1;
413
      $out .= theme('cdm_pager_link', array('text' => $label, 'linkIndex' => $index, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
414
  'class' => array('pager-first'),
415
)));
416
    }
417
    if ($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1) {
418
      $out .= '<div class="pager-list-dots-right">...</div>';
419
    }
420

    
421
    if ($pager->nextIndex) {
422
      $out .= theme('cdm_pager_link', array('text' => t('next ›'), 'linkIndex' => $pager->nextIndex, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
423
  'class' => array('pager-next'),
424
)));
425
      $out .= theme('cdm_pager_link', array('text' => t('last »'), 'linkIndex' => $pager->pagesAvailable - 1, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
426
  'class' => array('pager-last'),
427
)));
428
    }
429
    $out .= '</div>';
430

    
431
    return $out;
432
  }
433
}
434

    
435
/**
436
 * @todo Please document this function.
437
 * @see http://drupal.org/node/1354
438
 */
439
function theme_cdm_pager_link($variables) {
440
  $text = $variables['text'];
441
  $linkIndex = $variables['linkIndex'];
442
  $pager = $variables['pager'];
443
  $path = $variables['path'];
444
  $parameters = $variables['parameters'];
445
  $attributes = $variables['attributes'];
446
  $out = '';
447
  $parameters['search']['pageNumber'] = $linkIndex;
448
  if ($linkIndex == $pager->currentIndex) {
449
    $out = '<strong>' . $text . '</strong>';
450
  }
451
  else {
452
    // $queryString = drupal_query_string_encode($parameters);
453
    $queryString = $parameters;
454
    $out = l($text, $path, array(
455
      'attributes' => $attributes,
456
      'query' => $queryString,
457
    ));
458
  }
459
  return $out;
460
}
461

    
462
/* ============================ special buttons ============================= */
463
/**
464
 * @todo Please document this function.
465
 * @see http://drupal.org/node/1354
466
 */
467
function theme_cdm_back_to_search_result_button() {
468
  $out = '';
469

    
470
  $show_button = variable_get('cdm_dataportal_show_back_to_search_results');
471
  if (isset($_SESSION['cdm']['search']) && isset($show_button)) {
472
    /* ['cdm']['last_search'] */
473
    // $out .= '<div id="backButton">'.l(t('Back to search result'), $_SESSION
474
    // ).'</div>';
475
    $out .= '<div id="backButton">' . l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search']) . '</div>';
476
  }
477
  return $out;
478
}
479

    
480
/**
481
 * @todo Please document this function.
482
 * @see http://drupal.org/node/1354
483
 */
484
function theme_cdm_back_to_image_gallery_button() {
485
  $out = '<div id="backToGalleryButton">' . l(t('Back to Images'), $_SESSION['cdm']['last_gallery']) . '</div>';
486
  return $out;
487
}
488

    
489
/**
490
 * @todo Please document this function.
491
 * @see http://drupal.org/node/1354
492
 */
493
function theme_cdm_print_button() {
494

    
495
  drupal_add_js('jQuery(document).ready(function() {
496
         jQuery(\'#print_button\').click(function () {
497
         window.print();
498
     });
499
  });', array('type' => 'inline'));
500

    
501
  $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') . '" />';
502
  // .t('Print this page');
503
  // $output .= l('Print this page', '');
504
  $output .= '<span>Print this page</span>';
505
  $output .= '</div>';
506

    
507
  return $output;
508
}
509

    
510
/* ============================ java script functions ============================= */
511
/**
512
 * @todo Please document this function.
513
 * @see http://drupal.org/node/1354
514
 */
515
function _add_js_thickbox() {
516
  // ---- jQuery thickbox:
517
  /*
518
   * bug: compat-1.0.js && thickbox.js line 237 .trigger("unload") -> event is
519
   * not triggered because of problems with compat-1.0.js' see INSTALL.txt
520
   */
521
  // drupal_add_js(drupal_get_path('module',
522
  // 'cdm_dataportal').'/js/jquery.imagetool.min.js');
523
  //
524
  // Add a setting for the path to cdm_dataportal module, used to find the path
525
  // for the loading animation image in thickbox.
526
  drupal_add_js(array(
527
  			'cdm_dataportal' => array(
528
  				'cdm_dataportal_path' => base_path() . drupal_get_path('module', 'cdm_dataportal'),
529
  			)
530
  		),
531
  		'setting'
532
  	);
533
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/thickbox/thickbox.js');
534
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/js/thickbox/cdm_thickbox.css');
535
}
536

    
537
/**
538
 * @todo Please document this function.
539
 * @see http://drupal.org/node/1354
540
 */
541
function _add_js_lightbox($galleryID) {
542
  /*
543
   * Important Notice: The jquery.lightbox-0.5.js has been modified in order to
544
   * allow using the "alt" attribute for captions instead of the "title"
545
   * attribute
546
   */
547
  $lightBoxBasePath = drupal_get_path('module', 'cdm_dataportal') . '/js/jquery-lightbox-0.5';
548
  drupal_add_js($lightBoxBasePath . '/js/jquery.lightbox-0.5.js');
549
  drupal_add_css($lightBoxBasePath . '/css/jquery.lightbox-0.5.css');
550
  drupal_add_js('jQuery(document).ready(function() {
551
      jQuery(\'#' . $galleryID . ' a.lightbox\').lightBox({
552
        fixedNavigation:  true,
553
        imageLoading:     \'' . $lightBoxBasePath . '/images/lightbox-ico-loading.gif\',
554
        imageBtnPrev:     \'' . $lightBoxBasePath . '/images/lightbox-btn-prev.gif\',
555
        imageBtnNext:     \'' . $lightBoxBasePath . '/images/lightbox-btn-next.gif\',
556
        imageBtnClose:    \'' . $lightBoxBasePath . '/images/lightbox-btn-close.gif\',
557
        imageBlank:       \'' . $lightBoxBasePath . '/images/lightbox-blank.gif\',
558
        adjustToWindow: true
559
      });
560
    });
561
    ', array('type' => 'inline'));
562
}
563

    
564
/**
565
 * @todo Please document this function.
566
 * @see http://drupal.org/node/1354
567
 */
568
function _add_js_footnotes() {
569
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/footnotes.js');
570
}
571

    
572
/**
573
 * @todo Please document this function.
574
 * @see http://drupal.org/node/1354
575
 */
576
function _add_js_cluetip() {
577

    
578
  // TODO replace by
579
  // @see http://www.socialembedded.com/labs/jQuery-Tooltip-Plugin/jQuery-Tooltip-Plugin.html
580
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cluetip/jquery.cluetip.js');
581
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/jquery.dimensions.js');
582
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cluetip/jquery.hoverIntent.js');
583
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/js/cluetip/jquery.cluetip.css');
584
  drupal_add_js("jQuery(document).ready(function(){
585
      jQuery('.cluetip').css({color: '#0062C2'}).cluetip({
586
        splitTitle: '|',
587
        showTitle: true,
588
        activation: 'hover',
589
        sicky: true,
590
        arrows: true,
591
        dropShadow: false,
592
        cluetipClass: 'rounded'
593
      });
594
    });", array('type' => 'inline'));
595
}
596

    
597
/**
598
 * @todo Please document this function.
599
 * @see http://drupal.org/node/1354
600
 */
601
function _add_js_ahah() {
602
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/ahah-content.js');
603
}
(2-2/10)