Project

General

Profile

Download (29.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Overrides of generic themeing functions in cdm_dataportal.theme.php.
5
 */
6

    
7
/**
8
 * @todo Please document this function.
9
 * @see http://drupal.org/node/1354
10
 */
11
function palmweb_2_cdm_descriptionElementDistribution($variables) {
12
  $descriptionElements = $variables['descriptionElements'];
13
  $enclosingTag = $variables['enclosingTag'];
14

    
15
  $out = '';
16
  $separator = ', ';
17

    
18
  RenderHints::pushToRenderStack('descriptionElementDistribution');
19
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
20

    
21
  $itemCnt = 0;
22
  foreach ($descriptionElements as $descriptionElement) {
23
    /*
24
    $out .= ($descriptionElement->class);
25
    // Annotations as footnotes.
26
    $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
27
    // Source references as footnotes.
28
    $sourcesFootnoteKeyList = '';
29
    foreach($descriptionElement->sources as $source){
30
      $_fkey = FootnoteManager::addNewFootnote(UUID_DISTRIBUTION, theme('cdm_OriginalSource', $source, FALSE));
31
      $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, ($sourcesFootnoteKeyList ? $separator : ''));
32
    }
33
    if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
34
      $annotationFootnoteKeys .= $separator;
35
    }
36
    */
37
        $out .= '<' . $enclosingTag . ' class="DescriptionElement DescriptionElement-' . $descriptionElement->class . '">';
38
        // $out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList;
39
        $out .= $descriptionElement->area->representation_L10n;
40
        if (++$itemCnt < count($descriptionElements)) {
41
          $out .= $separator;
42
        }
43
        $out .= "</" . $enclosingTag . ">";
44
  }
45
  $taxonTrees = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
46
  $reference = new stdClass();
47
  foreach ($taxonTrees as $taxonTree) {
48
    if ($taxonTree->uuid == variable_get('cdm_taxonomictree_uuid')) {
49
      if (isset($taxonTree->reference)) {
50
        $reference = $taxonTree->reference;
51
      }
52
      break;
53
    }
54
  }
55
  $referenceCitation = '';
56
  if (isset($reference->uuid)) {
57
    $referenceCitation .= '(<span class="reference">';
58
    $referenceCitation .= l(t('World Checklist of Monocotyledons'), path_to_reference($reference->uuid), array('attributes' => array('class' => array('reference'))));
59
    $referenceCitation .= '</span>)';
60
  }
61
  else {
62
    // Comment @WA Added for compatibility with D5, but I think it is better to
63
    // remove this to not show a link rather than the wrong one.
64
    $referenceCitation .= '(<span class="reference">';
65
    $referenceCitation .= l(t('World Checklist of Monocotyledons'), '', array('attributes' => array('class' => array('reference'))));
66
    $referenceCitation .= '</span>)';
67
  }
68

    
69
  $sourceRefs = '';
70
  if ($out && strlen($out) > 0) {
71
    $sourceRefs = ' ' . $referenceCitation;
72
  }
73

    
74
  if (strlen($sourceRefs) > 0) {
75
    $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
76
  }
77

    
78
  RenderHints::popFromRenderStack();
79
  return $out . $sourceRefs;
80

    
81
}
82

    
83
/**
84
 * @todo Please document this function.
85
 * @see http://drupal.org/node/1354
86
 */
87
function palmweb_2_cdm_feature_nodesTOC($variables){
88
  $featureNodes = $variables['featureNodes'];
89
  $out = '';
90

    
91
  global $theme;
92

    
93
  $out .= '<ul>';
94
  $countFeatures = 0;
95
  $numberOfChildren = count(cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array (
96
    get_taxonomictree_uuid_selected(),
97
    substr(strrchr($_GET["q"],'/'), 1),
98
  )));
99
  if ($numberOfChildren != 0) {
100
    $out .= '<li>';
101
    $out .= l(t(theme('cdm_feature_name', array('feature_name' => 'Number of Taxa'))), $_GET['q'], array(
102
      'attributes' => array('class' => array('toc')),
103
      'fragment' => generalizeString('Number Of Taxa'),
104
    ));
105
    $out .= '</li>';
106
  }
107
  foreach ($featureNodes as $node) {
108
    if (hasFeatureNodeDescriptionElements($node)) {
109
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
110

    
111
      // HACK to implement images for taxa, should be removed.
112
      if ($node->feature->uuid != UUID_IMAGE && $node->feature->uuid != UUID_USE) {
113
        $countFeatures++;
114
        $countFeatures++;
115
        $out .= '<li>' . l(t(theme('cdm_feature_name', array('feature_name' => $featureRepresentation))), $_GET['q'],
116
            array('attributes' => array('class' => array('toc')),'fragment' => generalizeString($featureRepresentation))) . '</li>';
117
      }
118
    }
119
  }
120
  // Setting the Anchor to the Bibliography section if the option is enabled.
121
  $show_bibliography = variable_get('cdm_show_bibliography', 1);
122

    
123
  $markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
124
  $useDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, substr(strrchr($_GET["q"], '/'), 1), queryString($markerTypes));
125
  if (!empty($useDescriptions)) {
126
    $out .= '<li>';
127
    $out .= l(t(theme('cdm_feature_name', array('feature_name' => 'Uses'))), $_GET['q'], array(
128
      'attributes' => array('class' => array('toc')),
129
      'fragment' => 'userecords',
130
    ));
131
    $out .= '</li>';
132
  }
133

    
134
  if ($show_bibliography && $countFeatures != 0) {
135
    $out .= '<li>' . l(t(theme('cdm_feature_name', array('feature_name' => 'Bibliography'))), $_GET['q'], array('attributes' => array('class' => array('toc')), 'fragment' => 'bibliography')) . '</li>';
136
  }
137
  $out .= '</ul>';
138
  return $out;
139
}
140

    
141
/**
142
 * @todo Please document this function.
143
 * @see http://drupal.org/node/1354
144
 */
145
function palmweb_2_cdm_feature_nodes($variables){
146
  $mergedFeatureNodes = $variables['mergedFeatureNodes'];
147
  $taxon = $variables['taxon'];
148

    
149
  $out = '';
150
  RenderHints::pushToRenderStack('feature_nodes');
151

    
152
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
153
  // Creating an array to place the description elements in.
154
  $bibliographyOut = array();
155
  $countFeatures = 0;
156
  $numberOfChildren = count(cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array (get_taxonomictree_uuid_selected(), $taxon->uuid)));
157
  if ($taxon->name->rank->titleCache == "Genus") {
158
    $subRank = "species";
159
  }
160
  if ($taxon->name->rank->titleCache == "Species") {
161
    $subRank = "infraspecific taxa";
162
  }
163
  if ($numberOfChildren != 0) {
164
    $out .= '<a name="number_of_taxa"> </a><H2>Number of Taxa</H2><div class="content"> <ul class="description">';
165
    $out .= '<li class=\"descriptionText DescriptionElement\">' . $numberOfChildren . " " . $subRank . '</li></ul>';
166
  }
167

    
168
  foreach ($mergedFeatureNodes as $node) {
169

    
170
    if (hasFeatureNodeDescriptionElements($node)) {
171

    
172
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
173
      $block = new stdClass();
174
      $block->module = 'cdm_dataportal';
175
      // If the option is enabled the description elements will be added
176
      // to the array.
177
      $show_bibliography = variable_get('cdm_show_bibliography', 1);
178
      if ($show_bibliography) {
179
        $bibliographyOut[] = $node->descriptionElements;
180
      }
181
      $media_list = array();
182
      if ($node->feature->uuid != UUID_IMAGE && $node->feature->uuid != UUID_USE) {
183
        $countFeatures++;
184
        $countFeatures++;
185
        $block->delta = generalizeString($featureRepresentation);
186
        $block->subject = '<span class="' . html_class_atttibute_ref($node->feature) . '">' . theme('cdm_feature_name',  array('feature_name' => $featureRepresentation)) . '</span>';
187
        $block->module = "cdm_dataportal-feature";
188
        $block->content = '';
189

    
190
        /*
191
        Content/DISTRIBUTION.
192
        */
193
        if ($node->feature->uuid == UUID_DISTRIBUTION) {
194

    
195
          if (variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
196
            $distributionTextDataList = array();
197
            $distributionElementsList = array();
198

    
199
            foreach ($node->descriptionElements as $descriptionElement) {
200
              if ($descriptionElement->class == "TextData") {
201
                $distributionTextDataList[] = $descriptionElement;
202
              }
203
              else {
204
                $distributionElementsList[] = $descriptionElement;
205
              }
206
            }
207
            if (count($distributionTextDataList) > 0) {
208
              $node->descriptionElements = $distributionElementsList;
209
              $block->content .= theme('cdm_descriptionElements', array(
210
                'descriptionElements' => $distributionTextDataList,
211
                'featureUuid' => $node->feature->uuid,
212
                'taxon_uuid' => $taxon->uuid,
213
              ));
214
            }
215
          }
216

    
217
          // Display cdm distribution map.
218
          // TODO this is a HACK to a proper generic implementation?
219
          $block->content .= theme('cdm_distribution_map', array('taxon' => $taxon));
220
          $block->content .= theme('cdm_descriptionElements', array(
221
            'descriptionElements' => $node->descriptionElements,
222
            'featureUuid' => $node->feature->uuid,
223
            'taxon_uuid' => $taxon->uuid,
224
          ));
225
        }
226

    
227
        /*
228
        Content/COMMON_NAME.
229
        */
230
        elseif ($node->feature->uuid == UUID_COMMON_NAME) {
231
          // TODO why is theme_cdm_descriptionElement_CommonTaxonName
232
          // not beeing used???
233
          $block->content .= theme('cdm_common_names', array('elements' => $node->descriptionElements));
234
        /*
235
        }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
236
          $block->content .= theme('cdm_image_sources', $node->descriptionElements);
237
        */
238
        }
239

    
240
        /*
241
        Content/ALL OTHER FEATURES.
242
        */
243
        elseif ($node->feature->uuid == UUID_USE_RECORD) {
244
          $block->content .= theme('cdm_block_Uses', $taxon->uuid);
245
          // $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid),
246
        }
247
        else {
248
          $block->content .= theme('cdm_descriptionElements', array(
249
            'descriptionElements' => $node->descriptionElements,
250
            'featureUuid' => $node->feature->uuid,
251
            'taxon_uuid' => $taxon->uuid,
252
          ));
253

    
254
          /*
255
          Content/ALL OTHER FEATURES/Subordinate Features
256
          subordinate features are printed inline in one floating text,
257
          it is expected that subordinate features only "contain" TextData
258
          elements.
259
          */
260
          // TODO move into own theme.
261
          if (count($node->children) > 0) {
262

    
263
            // TODO support more than one level of children.
264
            // @see http://dev.e-taxonomy.eu/trac/ticket/2393/
265
            $text = '';
266
            foreach ($node->children as $child) {
267
             if (is_array($child->descriptionElements)) {
268
               foreach ($child->descriptionElements as $element) {
269

    
270
                 if (is_array($element->media)) {
271
                   // Append media of subordinate elements to the list of
272
                   // main features.
273
                   $media_list = array_merge($media_list, $element->media);
274
                 }
275

    
276
                 $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
277
                // TODO use localized version of feature name, the locale must
278
                // match the locale of the multilanguage text
279
                // (http://dev.e-taxonomy.eu/trac/ticket/2394).
280
                 $description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
281
               }
282
               $text .= " " . $description;
283
               $description = '';
284
             }
285
            }
286
            $block->content .= $text;
287
          }
288
        }
289

    
290
        /*
291
        Media/ALL FEATURES.
292
        */
293
        $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
294

    
295
        $gallery = theme('cdm_media_gallerie', array(
296
           'mediaList' => $media_list,
297
           'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
298
           'maxExtend' => isset($gallery_settings['cdm_dataportal_media_maxextend']) ? $gallery_settings['cdm_dataportal_media_maxextend'] : NULL ,
299
           'cols' => isset($gallery_settings['cdm_dataportal_media_cols']) ? $gallery_settings['cdm_dataportal_media_cols'] : NULL ,
300
           'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? $gallery_settings['cdm_dataportal_media_maxRows'] : NULL ,
301
           'captionElements' => isset($captionElements) ? $captionElements : NULL ,
302
           )
303
        );
304

    
305
        $block->content .= $gallery;
306
        $block->content .= theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid));
307
        $block->content .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid));
308

    
309
        // Add anchor to subject.
310
        $block->subject = '<a name="' . $block->delta . '"></a>' . $block->subject;
311

    
312
        $block->region = FALSE;
313
        $out .= theme('block', array('elements' => array(
314
          '#block' => $block,
315
          '#children' => $block->content,
316
        )));
317
      }
318
    }
319
  }
320
  // Calling the theme function for Bibliography to add it to the output.
321
  // Add the display of the number of taxa in the selected genus.
322
  $out .= theme('cdm_block_Uses', array('taxonUuid' => $taxon->uuid));
323

    
324
  $show_bibliography = variable_get('cdm_show_bibliography', 1);
325
  if ($show_bibliography && $countFeatures != 0) {
326
    $out .= theme('cdm_descriptionElementBibliography', array('descriptionElementsBibliography' => $bibliographyOut));
327
  }
328

    
329
  RenderHints::popFromRenderStack();
330
  return $out;
331
}
332

    
333
/**
334
 * @todo Please document this function.
335
 * @see http://drupal.org/node/1354
336
 */
337
function palmweb_2_cdm_search_results($variables){
338
  $pager = $variables['pager'];
339
  $path = $variables['path'];
340
  $out = '';
341

    
342
  $showThumbnails = isset($_SESSION['pageoption']['searchtaxa']['showThumbnails']) ? $_SESSION['pageoption']['searchtaxa']['showThumbnails'] : 0;
343
  if (!is_numeric($showThumbnails)) {
344
    // AT RBG KEW - 14/11/2011 - Set the show thumbnails to 0 by default.
345
    $showThumbnails = 0;
346
  }
347
  $setSessionUri = url('cdm_api/setvalue/session', array('query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => '')));
348
  drupal_add_js('jQuery(document).ready(function() {
349

    
350
        // Init.
351
        if(' . $showThumbnails . ' == 1){
352
              jQuery(\'.media_gallery\').show(20);
353
        } else {
354
          jQuery(\'.media_gallery\').hide(20);
355
        }
356
        // Add change hander.
357
        jQuery(\'#showThumbnails\').change(
358
          function(event){
359
            var state = 0;
360
            if(jQuery(this).is(\':checked\')){
361
              jQuery(\'.media_gallery\').show(20);
362
              state = 1;
363
            } else {
364
              jQuery(\'.media_gallery\').hide(20);
365
            }
366
            // Store state in session variable.
367
            var uri = \'' . $setSessionUri . '\' + state;
368
            jQuery.get(uri);
369
          });
370
        });', "inline");
371

    
372
  drupal_set_title(t('Search results'));
373

    
374
  // AT RBG KEW - 14/11/2011 - Changed the wording of the Show Thumbnails
375
  // tickbox text.
376
  $out .= '<div class="page_options">';
377
  $out .= '<form name="pageoptions">';
378
  $out .= '<input id="showThumbnails" type="checkbox" name="showThumbnails" ';
379
  $out .= $showThumbnails == 1 ? 'checked="checked"' : '';
380
  $out .= '> ' . t('Show Image Thumbnails') . '</form></div>';
381
  if (!empty($pager) && count($pager->records) > 0) {
382
      $out .= '<div id="search_results">';
383
    $out .= theme('cdm_list_of_taxa', array('records' => $pager->records));
384
    $out .= '</div>';
385
    $out .= theme('cdm_pager', array(
386
      'pager' => $pager,
387
      'path' => $path,
388
      'parameters' => $_REQUEST,
389
    ));
390
  }
391
  else {
392
    $out = '<h4 class="error">Sorry, no matching entries found.</h4>';
393
  }
394
  return $out;
395
}
396

    
397
/*
398
Comment @WA: theme function moved to cdm_dataportal module,
399
theme/cdm_dataportal.bibliography.theme so this can be used by other portals
400
as well.
401
@TODO: should this not be part of the palmweb_2 featuretree and be treated
402
as a normal description feature?
403
function theme_cdm_descriptionElementBibliography
404
function formatReference_for_Bibliography($references) {
405
 */
406

    
407
/**
408
 * @todo Please document this function.
409
 */
410
function palmweb_2_cdm_media_caption($variables){
411
  $media = $variables['media'];
412
  $elements = $variables['elements'];
413
  $fileUri = $variables['fileUri'];
414

    
415
  $media_metadata = cdm_read_media_metadata($media);
416

    
417
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
418
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
419
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
420
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
421
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
422

    
423
  $descriptionPrefix = "";
424

    
425
  $out = '<dl class="media-caption">';
426
  // Title.
427
  if ($doTitle) {
428
    if ($media_metadata['title']) {
429
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
430
      $descriptionPrefix = "- ";
431
    }
432
    elseif (!($doDescription && $media_metadata['description'])) {
433
      // Use filename as fallbackoption if no description will be shown.
434
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
435
      $descriptionPrefix = "- ";
436
    }
437
  }
438
  // Description.
439
  if ($media_metadata['description'] && $doDescription) {
440
    $out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
441
  }
442
  // Artist.
443
  if ($media_metadata['artist'] && $doArtist) {
444
    $out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . str_replace("'","", $media_metadata['artist']) . '</dd>';
445
  }
446
  // Location.
447
  if ($doLocation) {
448
    $location = '';
449
    $location .= $media_metadata['location']['sublocation'];
450
    if ($location && $media_metadata['location']['city']) {
451
      $location .= ', ';
452
    }
453
    $location .= $media_metadata['location']['city'];
454
    if ($location && $media_metadata['location']['province']) {
455
      $location .= ', ';
456
    }
457
    $location .= $media_metadata['location']['province'];
458
    if ($location && $media_metadata['location']['country']) {
459
      $location .= ' (' . $media_metadata['location']['country'] . ')';
460
    }
461
    else {
462
      $location .= $media_metadata['location']['country'];
463
    }
464
    if ($location) {
465
      $out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location  . '</dd>';
466
    }
467
  }
468
  // Rights.
469
  if ($doRights) {
470
    $rights = '';
471
    // Copyrights.
472
    $cnt = count($media_metadata['rights']['copyright']['agentNames']);
473
    if ($cnt > 0) {
474
      $rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
475
      for ($i = 0; $i < $cnt; $i++) {
476
        $rights .= str_replace("'","", $media_metadata['rights']['copyright']['agentNames'][$i]);
477
        if ($i + 1 < $cnt) {
478
          $rights .= ' / ';
479
        }
480
      }
481
      $rights .= '</dd>';
482
    }
483
    // License.
484
    $cnt = count($media_metadata['rights']['license']['agentNames']);
485
    if ($cnt > 0) {
486
      $rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
487
      for ($i = 0; $i < $cnt; $i++) {
488
        $rights .= $media_metadata['rights']['license']['agentNames'][$i];
489
        if ($i + 1 < $cnt) {
490
          $rights .= ' / ';
491
        }
492
      }
493
      $rights .= '</dd>';
494
    }
495
    if ($rights) {
496
      $out .= $rights . '</dt>';
497
    }
498
  }
499
  // TODO add all other metadata elemenst generically.
500
  $out .= '</dl>';
501
  // Return value.
502
  return $out;
503
}
504

    
505
/**
506
 * @todo document this function.
507
 */
508
function palmweb_2_cdm_reference($variables) {
509
  $reference = $variables['reference'];
510
  $microReference = $variables['microReference'];
511
  $doLink = $variables['doLink'];
512
  $referenceStyle = $variables['referenceStyle'];
513

    
514
  $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
515

    
516
  $year = '';
517
  if (isset($reference->datePublished->start)) {
518
    $year = partialToYear($reference->datePublished->start);
519
  }
520
  $citation = _short_form_of_author_team ($author_team->titleCache) . (!empty($year) ? '. ' . $year : '');
521
  $citation = str_replace('..', '.', $citation);
522

    
523
  if ($doLink) {
524
    $out = '<span class="reference">';
525
    $out .= l($citation, path_to_reference($reference->uuid), array(
526
    'attributes' => array('class' => 'reference'),
527
    'absolute' => TRUE,
528
    'html' => TRUE,
529
    ));
530
    $out .= '</span>';
531
  }
532
  else {
533
    $out = '<span class="reference">' . $citation . '</span>';
534
  }
535
  // FIXME use microreference webservice instead.
536
  if (!empty($descriptionElementSource->citationMicroReference)) {
537
    $out .= ': ' . $descriptionElementSource->citationMicroReference;
538
  }
539

    
540
  return $out;
541
}
542

    
543
/**
544
 * Sets the body-tag class attribute.
545
 *
546
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
547
 */
548
function phptemplate_body_class($sidebar_left, $sidebar_right) {
549
  if ($sidebar_left != '' && $sidebar_right != '') {
550
    $class = 'sidebars';
551
  }
552
  else {
553
    if ($sidebar_left != '') {
554
      $class = 'sidebar-left';
555
    }
556
    if ($sidebar_right != '') {
557
      $class = 'sidebar-right';
558
    }
559
  }
560

    
561
  if (isset($class)) {
562
    print ' class="' . $class . '"';
563
  }
564
}
565

    
566
/**
567
 * Allow themeable wrapping of all comments.
568
 */
569
function phptemplate_comment_wrapper($content, $type = NULL) {
570
  static $node_type;
571
  if (isset($type)) {
572
    $node_type = $type;
573
  }
574

    
575
  if (!$content || $node_type == 'forum') {
576
    return '<div id="comments">' . $content . '</div>';
577
  }
578
  else {
579
    return '<div id="comments"><h2 class="comments">' . t('Comments') . '</h2>' . $content . '</div>';
580
  }
581
}
582

    
583
/**
584
 * Override or insert PHPTemplate variables into the templates.
585
 */
586
function _phptemplate_variables($hook, $vars) {
587
  if ($hook == 'page') {
588

    
589
    if ($secondary = menu_secondary_local_tasks()) {
590
      $output = '<span class="clear"></span>';
591
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
592
      $vars['tabs2'] = $output;
593
    }
594

    
595
    // Hook into color.module
596
    if (module_exists('color')) {
597
      _color_page_alter($vars);
598
    }
599
    return $vars;
600
  }
601
  return array();
602
}
603

    
604
/**
605
 * Returns the rendered local tasks. The default implementation renders
606
 * them as tabs.
607
 *
608
 * @ingroup themeable
609
 */
610
function phptemplate_menu_local_tasks() {
611
  $output = '';
612

    
613
  if ($primary = menu_primary_local_tasks()) {
614
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
615
  }
616

    
617
  return $output;
618
}
619

    
620
/**
621
 *  @deprecated define name render templates via the layout settings
622
 */
623
function palmweb_2_get_partDefinition($variables) {
624

    
625
  return array(
626
    'BotanicalName'=> array(
627
        'namePart' => array('name' => TRUE, 'authors' => TRUE),
628
        'authorshipPart' => array(),
629
        'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
630
        'statusPart' => array('status' => TRUE),
631
        'descriptionPart' => array('description' => TRUE),
632
    ),
633
    'ZoologicalName' => array(
634
          'namePart' => array('name' => TRUE),
635
          'referencePart' => array('authors' => TRUE),
636
          'microreferencePart' => array('microreference' => TRUE),
637
          'statusPart' => array('status' => TRUE),
638
          'descriptionPart' => array('description' => TRUE),
639
      ),
640
    '#DEFAULT' => array(
641
        'namePart' => array(
642
            'name' => TRUE,
643
            'authors' => TRUE
644
        ),
645
        'referencePart' => array(
646
            'reference' => TRUE
647
        ),
648
        'microreferencePart' => array(
649
            'microreference' => TRUE,
650
        ),
651
        'statusPart' => array(
652
            'status' => TRUE,
653
        ),
654
        'descriptionPart' => array(
655
            'description' => TRUE,
656
        ),
657
      )
658
  );
659
}
660

    
661
/**
662
 *  @deprecated define name render templates via the layout settings
663
 */
664
function palmweb_2_get_nameRenderTemplate($variables){
665
  return array(
666
    'acceptedFor' =>
667
      $template = array(
668
        'namePart' => array('#uri'=>TRUE),
669
      ),
670
    'typedesignations' => array(
671
        'namePart' => array('#uri'=>TRUE),
672
        'referencePart' => TRUE,
673
      ),
674
    'taxon_page_title,list_of_taxa,taxon_page_synonymy,related_taxon,polytomousKey' => array(
675
        'namePart' => array('#uri'=>TRUE),
676
        'referencePart' => TRUE,
677
        'descriptionPart' => TRUE,
678
        'statusPart' => TRUE,
679
      ),
680
    '#DEFAULT' => array(
681
        'namePart' => array('#uri'=>TRUE),
682
        'referencePart' => TRUE,
683
        'descriptionPart' => TRUE,
684
        'statusPart' => TRUE,
685
     )
686
  );
687
}
688

    
689
/**
690
 * @todo Please document this function.
691
 * @see http://drupal.org/node/1354
692
 */
693
function palmweb_2_cdm_feature_name($variables){
694
  $feature_name = $variables['feature_name'];
695
  switch ($feature_name) {
696
    case "Protologue": return t("Original Publication");
697
    default: return t(ucfirst($feature_name));
698
  }
699
}
700

    
701
/**
702
 * Implements hook_preprocess_HOOK() for theme_page().
703
 *
704
 * Assign the css classes primary-links and secondary-links to the menus and
705
 * process the 'Login' menu item, to change into 'My account' after login and
706
 * change the tab title for the IMCE file browser.
707
 *
708
 * @author W.Addink <w.addink@eti.uva.nl>
709
 */
710
function palmweb_2_preprocess_page(&$vars) {
711

    
712
  if (isset($vars['main_menu'])) {
713
    // For the Palmae theme we want to change the menu item 'Login' into
714
    // 'My account' if a user is logged in.
715
    global $user;
716
    foreach ($vars['main_menu'] as $key => $value) {
717
        if ($value['href'] == 'user' && !empty($user->name)) {
718
            $vars['main_menu'][$key]['title'] = t('My account');
719
            $vars['main_menu'][$key]['href'] = 'user/' . $user->uid;
720
        }
721
    }
722
    // Theme the main menu with the desired css classes.
723
    $vars['primary_nav'] = theme('links__system_main_menu', array(
724
      'links' => $vars['main_menu'],
725
      'attributes' => array(
726
        'class' => array('links', 'inline', 'main-menu', 'primary-links'),
727
      ),
728
      'heading' => array(
729
        'text' => t('Main menu'),
730
        'level' => 'h2',
731
        'class' => array('element-invisible'),
732
      )));
733
  }
734
  else {
735
    $vars['primary_nav'] = FALSE;
736
  }
737
  if (isset($vars['secondary_menu'])) {
738
    $vars['secondary_nav'] = theme('links__system_secondary_menu', array(
739
      'links' => $vars['secondary_menu'],
740
      'attributes' => array(
741
        'class' => array('links', 'inline', 'secondary-menu', 'secondary-links'),
742
      ),
743
      'heading' => array(
744
        'text' => t('Secondary menu'),
745
        'level' => 'h2',
746
        'class' => array('element-invisible'),
747
      )));
748
  }
749
  else {
750
    $vars['secondary_nav'] = FALSE;
751
  }
752

    
753
  // Change IMCE tab to 'Personal Files'.
754
  if (!empty($vars['tabs']['#primary'])) {
755
    foreach ($vars['tabs']['#primary'] as $key => $value) {
756
      if ($value['#link']['path'] == 'user/%/imce') {
757
        $vars['tabs']['#primary'][$key]['#link']['title'] = t('Personal Files');
758
      }
759
    }
760
  }
761

    
762

    
763
  /* Display node title as page title for the comment form.
764
  * Comment @WA: it would probably be better to select $uuid from node_cdm
765
  * table and link to cdm_dataportal/taxon/%uuid instead.
766
  */
767
  if (arg(0) == 'comment' && arg(1) == 'reply') {
768
      $node = $vars['page']['content']['system_main']['comment_node']['#node'];
769
      $vars['title'] = l(check_plain($node->title),'node/' . $node->nid);
770
  }
771
}
772

    
773
/**
774
 * Implements hook_preprocess_HOOK() for theme_node().
775
 *
776
 * Fixes file urls in nodes. In nodes, relative urls are used to include files
777
 * like <img src="/files/..
778
 *
779
 * Portals can be installed in configurations with
780
 * sub-directories however, in which case these urls need to be adjusted.
781
 * Examples: mysite.org, mysite.org/myportal, mysite.org/portals/myportal.
782
 *
783
 * Therefore preprocess nodes and replace these urls with a the appropriate url
784
 * for the current setup.
785
 *
786
 * @author W.Addink <w.addink@eti.uva.nl>
787
 */
788
function palmweb_2_preprocess_node(&$vars) {
789
  $body = '';
790
// Warning: use #markup value, for which filters like php, html etc are applied!
791
  if (isset($vars['content']['body'][0]['#markup'])) {
792
    $body = $vars['content']['body'][0]['#markup'];
793
  }
794
  else {
795
    $vars['fixed_body'] = '';
796
    return;
797
  }
798

    
799
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
800
  global $base_url;
801
  if ($base_url == '/') {
802
    drupal_set_message(t('
803
      The $base_url in this portal could not be set, please set the $base_url
804
      manually your Drupal settings.php file.', 'error'
805
    ));
806
  }
807
  $fixed_file_path = $base_url . $file_path;
808

    
809
  $preg_file_path = preg_quote($file_path, '/');
810
  $body = preg_replace ('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path , $body);
811
  $body = preg_replace ('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path , $body);
812
  $body = preg_replace ('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path , $body);
813
  $body = preg_replace ('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path , $body);
814

    
815
  $vars['fixed_body'] = $body;
816
}
817

    
818
/**
819
 * Implements hook_form_FORM_ID_alter() for comment_form().
820
 *
821
 * Alter the comment form to make it look like a D5 style comment form.
822
 *
823
 * @author W.Addink <w.addink@eti.uva.nl>
824
 */
825
function palmweb_2_form_comment_form_alter(&$form, &$form_state) {
826

    
827
  if (!isset($form['comment_preview'])) {
828
    $form['header'] = array(
829
      '#markup' => '<h2>' . t('Reply') . '</h2>',
830
      '#weight' => -2,
831
    );
832
  }
833
  $form['subject']['#title'] = $form['subject']['#title'] . ':';
834
  $form['comment_body']['und'][0]['#title'] = $form['comment_body']['und'][0]['#title'] . ':';
835
  if (isset($form['author']['_author']['#title'])) {
836
    $form['author']['_author']['#title'] = $form['author']['_author']['#title'] . ':';
837
  }
838
  $form['actions']['submit']['#value'] = t('Post comment');
839
  $form['actions']['submit']['#weight'] = 1000;
840
  $form['actions']['preview']['#value'] = t('Preview comment');
841
}
842

    
843
/**
844
 * Implements hook_preprocess_HOOK() for theme_comment().
845
 *
846
 * Alter the comment display to make it look like a D5 style comment.
847
 *
848
 * @author W.Addink <w.addink@eti.uva.nl>
849
 */
850
function palmweb_2_preprocess_comment(&$variables) {
851
  $comment = $variables['elements']['#comment'];
852
  if (isset($comment->subject)) {
853
    // Print title without link.
854
    $variables['title'] = $comment->subject;
855
    if ($variables['status'] == 'comment-preview') {
856
      // Add 'new' to preview.
857
      $variables['new'] = t('new');
858
    }
859
  }
860
}
(11-11/11)