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 . '"><a name="footnote-' . $footnoteKey . '"></a><span class="footnote-anchor">' . $footnoteKey . '.</span>&nbsp;' . $footnoteText . '</span>';
304
  return $out;
305
}
306

    
307
/**
308
 * @todo Please document this function.
309
 * @see http://drupal.org/node/1354
310
 */
311
function theme_cdm_footnotes($variables) {
312
  $footnoteListKey = $variables['footnoteListKey'];
313
  $enclosingTag = $variables['enclosingTag'];
314
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
315
    return '';
316
  }
317
  $out = '<' . $enclosingTag . ' class="footnotes footnotes-' . $footnoteListKey . ' ">' . FootnoteManager::renderFootnoteList($footnoteListKey) . '</' . $enclosingTag . '>';
318
  FootnoteManager::removeFootnoteList($footnoteListKey);
319
  return $out;
320
}
321

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

    
341
/**
342
 * @todo Please document this function.
343
 * @see http://drupal.org/node/1354
344
 */
345
function cdm_exist_footnote($footnote_list, $footnote) {
346
  $result = FALSE;
347
  if (is_array($footnote_list)) {
348
    foreach ($footnote_list as $element) {
349
      if ($element == $footnote) {
350
        $result = TRUE;
351
      }
352
    }
353
  }
354
  return $result;
355
}
356

    
357
/**
358
 * @todo Please document this function.
359
 * @see http://drupal.org/node/1354
360
 */
361
function cdm_add_footnote_to_array(&$footnote_list, $footnote) {
362
  if (!cdm_exist_footnote($footnote_list, $footnote)) {
363
    $footnote_list[] = $footnote;
364
  }
365
}
366

    
367
/* ============================ pager ============================= */
368
/**
369
 * @todo Please document this function.
370
 * @see http://drupal.org/node/1354
371
 */
372
function theme_cdm_pager($variables) {
373
  $pager = $variables['pager'];
374
  $path = $variables['path'];
375
  $parameters = $variables['parameters'];
376
  $out = '';
377

    
378
  if ($pager->pagesAvailable > 1) {
379

    
380
    $out .= '<div class="pager">';
381
    if ($pager->currentIndex > 0) {
382
      $out .= theme('cdm_pager_link', array(
383
        'text' => t('« first'),
384
        'linkIndex' => 0,
385
        'pager' => $pager,
386
        'path' => $path,
387
        'parameters' => $parameters,
388
        'attributes' => array('class' => array('pager-first')),
389
        ));
390
      $out .= theme('cdm_pager_link', array(
391
        'text' => t('‹ previous'),
392
        'linkIndex' => $pager->currentIndex - 1,
393
        'pager' => $pager,
394
        'path' => $path,
395
        'parameters' => $parameters,
396
        'attributes' => array('class' => array('pager-previous')),
397
        ));
398
    }
399

    
400
    if ($pager->indices[0] > 0) {
401
      $out .= '<div class="pager-list-dots-left">...</div>';
402
    }
403

    
404
    foreach ($pager->indices as $index) {
405
      $label = $index + 1;
406
      $out .= theme('cdm_pager_link', array('text' => $label, 'linkIndex' => $index, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
407
  'class' => array('pager-first'),
408
)));
409
    }
410
    if ($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1) {
411
      $out .= '<div class="pager-list-dots-right">...</div>';
412
    }
413

    
414
    if ($pager->nextIndex) {
415
      $out .= theme('cdm_pager_link', array('text' => t('next ›'), 'linkIndex' => $pager->nextIndex, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
416
  'class' => array('pager-next'),
417
)));
418
      $out .= theme('cdm_pager_link', array('text' => t('last »'), 'linkIndex' => $pager->pagesAvailable - 1, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
419
  'class' => array('pager-last'),
420
)));
421
    }
422
    $out .= '</div>';
423

    
424
    return $out;
425
  }
426
}
427

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

    
455
/* ============================ special buttons ============================= */
456
/**
457
 * @todo Please document this function.
458
 * @see http://drupal.org/node/1354
459
 */
460
function theme_cdm_back_to_search_result_button() {
461
  $out = '';
462

    
463
  $show_button = variable_get('cdm_dataportal_show_back_to_search_results');
464
  if (isset($_SESSION['cdm']['search']) && isset($show_button)) {
465
    /* ['cdm']['last_search'] */
466
    // $out .= '<div id="backButton">'.l(t('Back to search result'), $_SESSION
467
    // ).'</div>';
468
    $out .= '<div id="backButton">' . l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search']) . '</div>';
469
  }
470
  return $out;
471
}
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
  global $base_url;
488

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

    
495
  $output = '<div id="print_button"><img src="' . $base_url . '/' . drupal_get_path('module', 'cdm_dataportal') . '/images/print_icon.gif' . ' "alt="' . t('Print this page') . ' "title="' . t('Print this page') . '" />';
496
  // .t('Print this page');
497
  // $output .= l('Print this page', '');
498
  $output .= '<span>Print this page</span>';
499
  $output .= '</div>';
500

    
501
  return $output;
502
}
503

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

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

    
554
/**
555
 * @todo Please document this function.
556
 * @see http://drupal.org/node/1354
557
 */
558
function _add_js_footnotes() {
559
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/footnotes.js');
560
}
561

    
562
/**
563
 * @todo Please document this function.
564
 * @see http://drupal.org/node/1354
565
 */
566
function _add_js_cluetip() {
567

    
568
  // TODO replace by
569
  // @see http://www.socialembedded.com/labs/jQuery-Tooltip-Plugin/jQuery-Tooltip-Plugin.html
570
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cluetip/jquery.cluetip.js');
571
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/jquery.dimensions.js');
572
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cluetip/jquery.hoverIntent.js');
573
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/js/cluetip/jquery.cluetip.css');
574
  drupal_add_js("jQuery(document).ready(function(){
575
      jQuery('.cluetip').css({color: '#0062C2'}).cluetip({
576
        splitTitle: '|',
577
        showTitle: true,
578
        activation: 'hover',
579
        sicky: true,
580
        arrows: true,
581
        dropShadow: false,
582
        cluetipClass: 'rounded'
583
      });
584
    });", array('type' => 'inline'));
585
}
586

    
587
/**
588
 * @todo Please document this function.
589
 * @see http://drupal.org/node/1354
590
 */
591
function _add_js_ahah() {
592
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/ahah-content.js');
593
}
(2-2/9)