Project

General

Profile

Download (29 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
 * This operride theme function ignores the original sources and annotations
9
 * and renders a hardcoded citation string at the end of the list of distibution
10
 * elements.
11
 * TODO the same output could also be achieved by collection all source citations
12
 * as it is done by the footnodesystem and to print the list of citations at the end
13
 * of the area list. The footnote key must be omitted in this case of course.
14
 *
15
 */
16

    
17
function palmweb_2_cdm_descriptionElement_Distribution($variables) {
18
  $descriptionElements = $variables['descriptionElements'];
19
  $enclosingTag = $variables['enclosingTag'];
20

    
21
  $out = '';
22
  $separator = ', ';
23

    
24
  RenderHints::pushToRenderStack('descriptionElementDistribution');
25
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
26

    
27
  $itemCnt = 0;
28
  foreach ($descriptionElements as $descriptionElement) {
29

    
30
    $out .= '<' . $enclosingTag . ' class="DescriptionElement DescriptionElement-' . $descriptionElement->class . '">';
31
    $out .= $descriptionElement->area->representation_L10n;
32
    if (++$itemCnt < count($descriptionElements)) {
33
      $out .= $separator;
34
    }
35
    $out .= "</" . $enclosingTag . ">";
36
  }
37
  $taxonTrees = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
38
  $reference = new stdClass();
39
  foreach ($taxonTrees as $taxonTree) {
40
    if ($taxonTree->uuid == variable_get('cdm_taxonomictree_uuid')) {
41
      if (isset($taxonTree->reference)) {
42
        $reference = $taxonTree->reference;
43
      }
44
      break;
45
    }
46
  }
47
  $referenceCitation = '';
48
  if (isset($reference->uuid)) {
49
    $referenceCitation .= '(<span class="reference">';
50
    $referenceCitation .= l(t('World Checklist of Monocotyledons'), path_to_reference($reference->uuid), array('attributes' => array('class' => array('reference'))));
51
    $referenceCitation .= '</span>)';
52
  }
53
  else {
54
    // Comment @WA Added for compatibility with D5, but I think it is better to
55
    // remove this to not show a link rather than the wrong one.
56
    $referenceCitation .= '(<span class="reference">';
57
    $referenceCitation .= l(t('World Checklist of Monocotyledons'), '', array('attributes' => array('class' => array('reference'))));
58
    $referenceCitation .= '</span>)';
59
  }
60

    
61
  $sourceRefs = '';
62
  if ($out && strlen($out) > 0) {
63
    $sourceRefs = ' ' . $referenceCitation;
64
  }
65

    
66
  if (strlen($sourceRefs) > 0) {
67
    $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
68
  }
69

    
70
  RenderHints::popFromRenderStack();
71
  return $out . $sourceRefs;
72

    
73
}
74

    
75

    
76
/**
77
 * @todo Please document this function.
78
 * @see http://drupal.org/node/1354
79
 */
80
function palmweb_2_cdm_feature_nodes($variables){
81
  $mergedFeatureNodes = $variables['mergedFeatureNodes'];
82
  $taxon = $variables['taxon'];
83

    
84
  $out = '';
85
  RenderHints::pushToRenderStack('feature_nodes');
86

    
87
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
88
  // Creating an array to place the description elements in.
89
  $bibliographyOut = array();
90
  $countFeatures = 0;
91
  $numberOfChildren = count(cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array (get_taxonomictree_uuid_selected(), $taxon->uuid)));
92
  if ($taxon->name->rank->titleCache == "Genus") {
93
    $subRank = "species";
94
  }
95
  if ($taxon->name->rank->titleCache == "Species") {
96
    if($numberOfChildren==1){
97
      $subRank = "infraspecific taxon";
98
    }
99
    else{
100
      $subRank = "infraspecific taxa";
101
    }
102
  }
103
  if ($numberOfChildren != 0) {
104
    $out .= '<a name="number_of_taxa"> </a><H2>Number of Taxa</H2><div class="content"> <ul class="description">';
105
    $out .= '<li class=\"descriptionText DescriptionElement\">' . $numberOfChildren . " " . $subRank . '</li></ul>';
106
  }
107

    
108
  foreach ($mergedFeatureNodes as $node) {
109

    
110
    if (isset($node->descriptionElements['#type']) || has_feature_node_description_elements($node)) {
111

    
112
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
113
      $block = new stdclass(); // Empty object.
114
      $block->module = 'cdm_dataportal';
115
      // If the option is enabled the description elements will be added
116
      // to the array.
117
      $show_bibliography = variable_get('cdm_show_bibliography', 1);
118
      if ($show_bibliography) {
119
        $bibliographyOut[] = $node->descriptionElements;
120
      }
121
      $media_list = array();
122
      if ($node->feature->uuid != UUID_IMAGE && $node->feature->uuid != UUID_USE) {
123
        $countFeatures++;
124
        $countFeatures++;
125
        $block->delta = generalizeString($featureRepresentation);
126
        $block->subject = '<span class="' . html_class_attribute_ref($node->feature) . '">'
127
            . theme('cdm_feature_name',  array('feature_name' => $featureRepresentation)) . '</span>';
128
        $block->module = "cdm_dataportal-feature";
129
        $block->content = '';
130

    
131
      /*
132
         * Content/DISTRIBUTION.
133
         */
134
        if ($node->feature->uuid == UUID_DISTRIBUTION) {
135

    
136
          $distributionElements = null;
137
          $distribution_info_dto = null;
138
          $text_data_out_array = array();
139

    
140
          $distribution_sortOutArray = FALSE;
141
          if (variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT') {
142
            $distribution_glue = '';
143
            $distribution_enclosingTag = 'dl';
144
          }
145
          else {
146
            $distribution_glue = '';
147
            $distribution_enclosingTag = 'ul';
148
          }
149

    
150
          if(!isset($node->descriptionElements['#type']) || !$node->descriptionElements['#type']=='DTO') {
151
            // skip the DISTRIBUTION section if there is no DTO type element
152
            continue;
153
          }
154

    
155
          if(isset($node->descriptionElements['TextData'])){
156
            // --- TextData
157
            foreach ($node->descriptionElements['TextData'] as $text_data_element){
158
              $asListElement = FALSE;
159
              $repr = theme('cdm_descriptionElementTextData', array(
160
                  'element' => $text_data_element,
161
                  'asListElement' => $asListElement,
162
                  'feature_uuid' => $text_data_element->feature->uuid,
163
              ));
164

    
165
              if (!array_search($repr, $text_data_out_array)) {
166
                $text_data_out_array[] = $repr;
167
                // TODO HINT: sorting in theme_cdm_descriptionElementArray will
168
                // not work since this array contains html attributes with uuids
169
                // !!!!
170
                $text_data_sortOutArray = TRUE;
171
                $text_data_glue = '<br/> ';
172
                $text_data_enclosingTag = 'p';
173
              }
174
            }
175
          }
176

    
177

    
178
          if ($text_data_out_array && variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
179
            $block->content .= theme('cdm_descriptionElementArray', array(
180
              'elementArray' => $text_data_out_array,
181
              'feature' => $node->feature,
182
              'glue' => $text_data_glue,
183
              'sortArray' => $text_data_sortOutArray,
184
              'enclosingHtml' => $text_data_enclosingTag,
185
            ));
186
          }
187

    
188
          // --- Distribution map
189
          $distribution_map_query_parameters = null;
190
          if(isset($node->descriptionElements['DistributionInfoDTO'])) {
191
            $distribution_map_query_parameters = $node->descriptionElements['DistributionInfoDTO']->mapUriParams;
192
          }
193
          $map_render_element = compose_distribution_map($taxon, $distribution_map_query_parameters);
194
          $block->content .= $map_render_element['#markup'];
195

    
196
            // --- tree or list
197
              $dto_out_array = array();
198
          if(isset($node->descriptionElements['DistributionInfoDTO'])) {
199
            $distribution_info_dto = $node->descriptionElements['DistributionInfoDTO'];
200

    
201
            // --- tree
202
            if (is_object($distribution_info_dto->tree)) {
203
              $dto_out_array[] = theme('cdm_description_ordered_distributions', array('distribution_tree' => $distribution_info_dto->tree));
204
            }
205

    
206
            // --- sorted element list
207
            if( is_array($distribution_info_dto->elements) && count($distribution_info_dto->elements) > 0 ) {
208
              foreach ($distribution_info_dto->elements as $descriptionElement){
209
                if (is_object($descriptionElement->area)) {
210
                  $sortKey = $descriptionElement->area->representation_L10n;
211
                  $distributionElements[$sortKey] = $descriptionElement;
212
                }
213
              }
214
              ksort($distributionElements);
215
              $dto_out_array[] = theme('cdm_descriptionElement_Distribution', array(
216
                  'descriptionElements' => $distributionElements,
217
              ));
218

    
219
            }
220
            //
221
            $block->content .= theme('cdm_descriptionElementArray', array(
222
                'elementArray' => $dto_out_array,
223
                'feature' => $node->feature,
224
                'glue' => $distribution_glue,
225
                'sortArray' => $distribution_sortOutArray,
226
                'enclosingHtml' => $distribution_enclosingTag,
227
            ));
228
          }
229

    
230
          // --- TextData at the bottom
231
          if ($text_data_out_array && !variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
232
            $block->content .= theme('cdm_descriptionElementArray', array(
233
                'elementArray' => $text_data_out_array,
234
                'feature' => $node->feature,
235
                'glue' => $text_data_glue,
236
                'sortArray' => $text_data_sortOutArray,
237
                'enclosingHtml' => $text_data_enclosingTag,
238
            ));
239
          }
240

    
241
        }
242

    
243
        /*
244
        Content/COMMON_NAME.
245
        */
246
        elseif ($node->feature->uuid == UUID_COMMON_NAME) {
247
          // TODO why is theme_cdm_descriptionElement_CommonTaxonName
248
          // not beeing used???
249
          $block->content .= theme('cdm_common_names', array('elements' => $node->descriptionElements));
250
        /*
251
        }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
252
          $block->content .= theme('cdm_image_sources', $node->descriptionElements);
253
        */
254
        }
255

    
256
        /*
257
        Content/ALL OTHER FEATURES.
258
        */
259
        elseif ($node->feature->uuid == UUID_USE_RECORD) {
260
          $block->content .= theme('cdm_block_Uses', array('taxonUuid' => $taxon->uuid));
261
          // $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid),
262
        }
263
        else {
264
          $block->content .= theme('cdm_descriptionElements', array(
265
            'descriptionElements' => $node->descriptionElements,
266
            'featureUuid' => $node->feature->uuid,
267
            'taxon_uuid' => $taxon->uuid,
268
          ));
269

    
270
          /*
271
          Content/ALL OTHER FEATURES/Subordinate Features
272
          subordinate features are printed inline in one floating text,
273
          it is expected that subordinate features only "contain" TextData
274
          elements.
275
          */
276
          // TODO move into own theme.
277
          if (isset($node->childNodes[0])) {
278

    
279
            // TODO support more than one level of children.
280
            // @see http://dev.e-taxonomy.eu/trac/ticket/2393/
281
            $text = '';
282
            foreach ($node->childNodes as $child) {
283

    
284
              if (isset($child->descriptionElements) && is_array($child->descriptionElements)) {
285
               foreach ($child->descriptionElements as $element) {
286

    
287
                 if (is_array($element->media)) {
288
                    // Append media of supordinate elements to list of main
289
                    // feature.
290
                   $media_list = array_merge($media_list, $element->media);
291
                 }
292

    
293
                 $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
294
                // TODO use localized version of feature name, the locale must
295
                // match the locale of the multilanguage text
296
                // (http://dev.e-taxonomy.eu/trac/ticket/2394).
297
                 $description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
298
               }
299
               $text .= " " . $description;
300
               $description = '';
301
             }
302
            }
303
            $block->content .= $text;
304
          }
305
        }
306

    
307
        /*
308
        Media/ALL FEATURES.
309
        */
310
        $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
311

    
312
        $gallery = theme('cdm_media_gallerie', array(
313
           'mediaList' => $media_list,
314
           'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
315
           'maxExtend' => isset($gallery_settings['cdm_dataportal_media_maxextend']) ? $gallery_settings['cdm_dataportal_media_maxextend'] : NULL ,
316
           'cols' => isset($gallery_settings['cdm_dataportal_media_cols']) ? $gallery_settings['cdm_dataportal_media_cols'] : NULL ,
317
           'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? $gallery_settings['cdm_dataportal_media_maxRows'] : NULL ,
318
           'captionElements' => isset($captionElements) ? $captionElements : NULL ,
319
           )
320
        );
321

    
322
        $block->content .= $gallery;
323
        $block->content .= theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid));
324
        $block->content .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid));
325

    
326
        // Add anchor to subject.
327
        $block->subject = '<a name="' . $block->delta . '"></a>' . $block->subject;
328

    
329
        $block->region = FALSE;
330
        $out .= theme('block', array('elements' => array(
331
          '#block' => $block,
332
          '#children' => $block->content,
333
        )));
334
      }
335
    }
336
  }
337

    
338
  // Add the display of the number of taxa in the selected genus.
339
  //
340

    
341

    
342
  // Calling the theme function for Bibliography to add it to the output.
343
  $show_bibliography = variable_get('cdm_show_bibliography', 1);
344
  if ($show_bibliography && $countFeatures != 0) {
345
    $out .= theme('cdm_descriptionElementBibliography', array('descriptionElementsBibliography' => $bibliographyOut));
346
  }
347

    
348
  RenderHints::popFromRenderStack();
349
  return $out;
350
}
351

    
352
/**
353
 * @todo Please document this function.
354
 * @see http://drupal.org/node/1354
355
 */
356
function palmweb_2_cdm_search_results($variables){
357
  $pager = $variables['pager'];
358
  $path = $variables['path'];
359
  $out = '';
360

    
361
  $showThumbnails = isset($_SESSION['pageoption']['searchtaxa']['showThumbnails']) ? $_SESSION['pageoption']['searchtaxa']['showThumbnails'] : 0;
362
  if (!is_numeric($showThumbnails)) {
363
    // AT RBG KEW - 14/11/2011 - Set the show thumbnails to 0 by default.
364
    $showThumbnails = 0;
365
  }
366
  $setSessionUri = url('cdm_api/setvalue/session', array('query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => '')));
367
  drupal_add_js('jQuery(document).ready(function() {
368

    
369
        // Init.
370
        if(' . $showThumbnails . ' == 1){
371
              jQuery(\'.media_gallery\').show(20);
372
        } else {
373
          jQuery(\'.media_gallery\').hide(20);
374
        }
375
        // Add change hander.
376
        jQuery(\'#showThumbnails\').change(
377
          function(event){
378
            var state = 0;
379
            if(jQuery(this).is(\':checked\')){
380
              jQuery(\'.media_gallery\').show(20);
381
              state = 1;
382
            } else {
383
              jQuery(\'.media_gallery\').hide(20);
384
            }
385
            // Store state in session variable.
386
            var uri = \'' . $setSessionUri . '\' + state;
387
            jQuery.get(uri);
388
          });
389
        });', "inline");
390

    
391
  drupal_set_title(t('Search results'));
392

    
393
  // AT RBG KEW - 14/11/2011 - Changed the wording of the Show Thumbnails
394
  // tickbox text.
395
  $out .= '<div class="page_options">';
396
  $out .= '<form name="pageoptions">';
397
  $out .= '<input id="showThumbnails" type="checkbox" name="showThumbnails" ';
398
  $out .= $showThumbnails == 1 ? 'checked="checked"' : '';
399
  $out .= '> ' . t('Show Image Thumbnails') . '</form></div>';
400
  if (!empty($pager) && count($pager->records) > 0) {
401
      $out .= '<div id="search_results">';
402
    $out .= theme('cdm_list_of_taxa', array('records' => $pager->records));
403
    $out .= '</div>';
404
    $out .= theme('cdm_pager', array(
405
      'pager' => $pager,
406
      'path' => $path,
407
      'parameters' => $_REQUEST,
408
    ));
409
  }
410
  else {
411
    $out = '<h4 class="error">Sorry, no matching entries found.</h4>';
412
  }
413
  return $out;
414
}
415

    
416
/*
417
Comment @WA: theme function moved to cdm_dataportal module,
418
theme/cdm_dataportal.bibliography.theme so this can be used by other portals
419
as well.
420
@TODO: should this not be part of the palmweb_2 featuretree and be treated
421
as a normal description feature?
422
function theme_cdm_descriptionElementBibliography
423
function formatReference_for_Bibliography($references) {
424
 */
425

    
426
/**
427
 * @todo Please document this function.
428
 */
429
function palmweb_2_cdm_media_caption($variables){
430
  $media = $variables['media'];
431
  $elements = $variables['elements'];
432

    
433
  $media_metadata = cdm_read_media_metadata($media);
434

    
435
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
436
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
437
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
438
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
439
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
440

    
441
  $descriptionPrefix = "";
442

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

    
523
/**
524
 * Overrive of the original theme_cdm_reference()
525
 * the main difference here seems to be that
526
 * this function is completely omitting the citation title cache and only sets the authorTeam as the
527
 * _short_form_of_author_team() as $citation.
528
 *
529
 * If the authorteam is not set citatin was empty,
530
 * this has been fixed for http://dev.e-taxonomy.eu/trac/ticket/4261
531
 *
532
 * TODO can this be made configuable via the dataportal
533
 *      settings so that we can remove this function?
534
 */
535
function palmweb_2_cdm_reference($variables) {
536
  $reference = $variables['reference'];
537
  $microReference = $variables['microReference'];
538
  $doLink = $variables['doLink'];
539
  $referenceStyle = $variables['referenceStyle'];
540

    
541
  if(!isset($reference->authorTeam)){
542
    $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
543
  } else {
544
    $author_team = $reference->authorTeam;
545
  }
546

    
547
  $year = '';
548
  if (isset($reference->datePublished->start)) {
549
    $year = partialToYear($reference->datePublished->start);
550
  }
551
  if(isset($author_team->titleCache)){
552
    $citation = _short_form_of_author_team ($author_team->titleCache) . (!empty($year) ? '. ' . $year : '');
553
    $citation = str_replace('..', '.', $citation);
554
  } else {
555
    $citation = $reference->titleCache;
556
  }
557

    
558
  if ($doLink) {
559
    $out = '<span class="reference">';
560
    $out .= l($citation, path_to_reference($reference->uuid), array(
561
    'attributes' => array('class' => 'reference'),
562
    'absolute' => TRUE,
563
    'html' => TRUE,
564
    ));
565
    $out .= '</span>';
566
  }
567
  else {
568
    $out = '<span class="reference">' . $citation . '</span>';
569
  }
570
  // FIXME use microreference webservice instead.
571
  if (!empty($descriptionElementSource->citationMicroReference)) {
572
    $out .= ': ' . $descriptionElementSource->citationMicroReference;
573
  }
574

    
575
  return $out;
576
}
577

    
578
/**
579
 * Sets the body-tag class attribute.
580
 *
581
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
582
 */
583
function phptemplate_body_class($sidebar_left, $sidebar_right) {
584
  if ($sidebar_left != '' && $sidebar_right != '') {
585
    $class = 'sidebars';
586
  }
587
  else {
588
    if ($sidebar_left != '') {
589
      $class = 'sidebar-left';
590
    }
591
    if ($sidebar_right != '') {
592
      $class = 'sidebar-right';
593
    }
594
  }
595

    
596
  if (isset($class)) {
597
    print ' class="' . $class . '"';
598
  }
599
}
600

    
601
/**
602
 * Allow themeable wrapping of all comments.
603
 */
604
function phptemplate_comment_wrapper($content, $type = NULL) {
605
  static $node_type;
606
  if (isset($type)) {
607
    $node_type = $type;
608
  }
609

    
610
  if (!$content || $node_type == 'forum') {
611
    return '<div id="comments">' . $content . '</div>';
612
  }
613
  else {
614
    return '<div id="comments"><h2 class="comments">' . t('Comments') . '</h2>' . $content . '</div>';
615
  }
616
}
617

    
618
/**
619
 * Override or insert PHPTemplate variables into the templates.
620
 */
621
function _phptemplate_variables($hook, $vars) {
622
  if ($hook == 'page') {
623

    
624
    if ($secondary = menu_secondary_local_tasks()) {
625
      $output = '<span class="clear"></span>';
626
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
627
      $vars['tabs2'] = $output;
628
    }
629

    
630
    // Hook into color.module
631
    if (module_exists('color')) {
632
      _color_page_alter($vars);
633
    }
634
    return $vars;
635
  }
636
  return array();
637
}
638

    
639
/**
640
 * Returns the rendered local tasks. The default implementation renders
641
 * them as tabs.
642
 *
643
 * @ingroup themeable
644
 */
645
function phptemplate_menu_local_tasks() {
646
  $output = '';
647

    
648
  if ($primary = menu_primary_local_tasks()) {
649
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
650
  }
651

    
652
  return $output;
653
}
654

    
655
/**
656
 * @todo Please document this function.
657
 * @see http://drupal.org/node/1354
658
 */
659
function palmweb_2_cdm_feature_name($variables){
660
  $feature_name = $variables['feature_name'];
661
  switch ($feature_name) {
662
    case "Protologue": return t("Original Publication");
663
    default: return t(ucfirst($feature_name));
664
  }
665
}
666

    
667
/**
668
 * Implements hook_preprocess_HOOK() for theme_page().
669
 *
670
 * Assign the css classes primary-links and secondary-links to the menus and
671
 * process the 'Login' menu item, to change into 'My account' after login and
672
 * change the tab title for the IMCE file browser.
673
 *
674
 * @author W.Addink <w.addink@eti.uva.nl>
675
 */
676
function palmweb_2_preprocess_page(&$vars) {
677

    
678
  if (isset($vars['main_menu'])) {
679
    // For the Palmae theme we want to change the menu item 'Login' into
680
    // 'My account' if a user is logged in.
681
    global $user;
682
    foreach ($vars['main_menu'] as $key => $value) {
683
        if ($value['href'] == 'user' && !empty($user->name)) {
684
            $vars['main_menu'][$key]['title'] = t('My account');
685
            $vars['main_menu'][$key]['href'] = 'user/' . $user->uid;
686
        }
687
    }
688
    // Theme the main menu with the desired css classes.
689
    $vars['primary_nav'] = theme('links__system_main_menu', array(
690
      'links' => $vars['main_menu'],
691
      'attributes' => array(
692
        'class' => array('links', 'inline', 'main-menu', 'primary-links'),
693
      ),
694
      'heading' => array(
695
        'text' => t('Main menu'),
696
        'level' => 'h2',
697
        'class' => array('element-invisible'),
698
      )));
699
  }
700
  else {
701
    $vars['primary_nav'] = FALSE;
702
  }
703
  if (isset($vars['secondary_menu'])) {
704
    $vars['secondary_nav'] = theme('links__system_secondary_menu', array(
705
      'links' => $vars['secondary_menu'],
706
      'attributes' => array(
707
        'class' => array('links', 'inline', 'secondary-menu', 'secondary-links'),
708
      ),
709
      'heading' => array(
710
        'text' => t('Secondary menu'),
711
        'level' => 'h2',
712
        'class' => array('element-invisible'),
713
      )));
714
  }
715
  else {
716
    $vars['secondary_nav'] = FALSE;
717
  }
718

    
719
  // Change IMCE tab to 'Personal Files'.
720
  if (!empty($vars['tabs']['#primary'])) {
721
    foreach ($vars['tabs']['#primary'] as $key => $value) {
722
      if ($value['#link']['path'] == 'user/%/imce') {
723
        $vars['tabs']['#primary'][$key]['#link']['title'] = t('Personal Files');
724
      }
725
    }
726
  }
727

    
728

    
729
  /* Display node title as page title for the comment form.
730
  * Comment @WA: it would probably be better to select $uuid from node_cdm
731
  * table and link to cdm_dataportal/taxon/%uuid instead.
732
  */
733
  if (arg(0) == 'comment' && arg(1) == 'reply') {
734
      $node = $vars['page']['content']['system_main']['comment_node']['#node'];
735
      $vars['title'] = l(check_plain($node->title),'node/' . $node->nid);
736
  }
737
}
738

    
739
/**
740
 * Implements hook_preprocess_HOOK() for theme_node().
741
 *
742
 * Fixes file urls in nodes. In nodes, relative urls are used to include files
743
 * like <img src="/files/..
744
 *
745
 * Portals can be installed in configurations with
746
 * sub-directories however, in which case these urls need to be adjusted.
747
 * Examples: mysite.org, mysite.org/myportal, mysite.org/portals/myportal.
748
 *
749
 * Therefore preprocess nodes and replace these urls with a the appropriate url
750
 * for the current setup.
751
 *
752
 * @author W.Addink <w.addink@eti.uva.nl>
753
 */
754
function palmweb_2_preprocess_node(&$vars) {
755
  $body = '';
756
// Warning: use #markup value, for which filters like php, html etc are applied!
757
  if (isset($vars['content']['body'][0]['#markup'])) {
758
    $body = $vars['content']['body'][0]['#markup'];
759
  }
760
  else {
761
    $vars['fixed_body'] = '';
762
    return;
763
  }
764

    
765
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
766
  global $base_url;
767
  if ($base_url == '/') {
768
    drupal_set_message(t('
769
      The $base_url in this portal could not be set, please set the $base_url
770
      manually your Drupal settings.php file.', 'error'
771
    ));
772
  }
773
  $fixed_file_path = $base_url . $file_path;
774

    
775
  $preg_file_path = preg_quote($file_path, '/');
776
  $body = preg_replace ('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path , $body);
777
  $body = preg_replace ('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path , $body);
778
  $body = preg_replace ('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path , $body);
779
  $body = preg_replace ('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path , $body);
780

    
781
  $vars['fixed_body'] = $body;
782
}
783

    
784
/**
785
 * Implements hook_form_FORM_ID_alter() for comment_form().
786
 *
787
 * Alter the comment form to make it look like a D5 style comment form.
788
 *
789
 * @author W.Addink <w.addink@eti.uva.nl>
790
 */
791
function palmweb_2_form_comment_form_alter(&$form, &$form_state) {
792

    
793
  if (!isset($form['comment_preview'])) {
794
    $form['header'] = array(
795
      '#markup' => '<h2>' . t('Reply') . '</h2>',
796
      '#weight' => -2,
797
    );
798
  }
799
  $form['subject']['#title'] = $form['subject']['#title'] . ':';
800
  $form['comment_body']['und'][0]['#title'] = $form['comment_body']['und'][0]['#title'] . ':';
801
  if (isset($form['author']['_author']['#title'])) {
802
    $form['author']['_author']['#title'] = $form['author']['_author']['#title'] . ':';
803
  }
804
  $form['actions']['submit']['#value'] = t('Post comment');
805
  $form['actions']['submit']['#weight'] = 1000;
806
  $form['actions']['preview']['#value'] = t('Preview comment');
807
}
808

    
809
/**
810
 * Implements hook_preprocess_HOOK() for theme_comment().
811
 *
812
 * Alter the comment display to make it look like a D5 style comment.
813
 *
814
 * @author W.Addink <w.addink@eti.uva.nl>
815
 */
816
function palmweb_2_preprocess_comment(&$variables) {
817
  $comment = $variables['elements']['#comment'];
818
  if (isset($comment->subject)) {
819
    // Print title without link.
820
    $variables['title'] = $comment->subject;
821
    if ($variables['status'] == 'comment-preview') {
822
      // Add 'new' to preview.
823
      $variables['new'] = t('new');
824
    }
825
  }
826
}
(11-11/11)