Project

General

Profile

Download (28.9 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_fetch_all(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
  $out = '';
84

    
85
  RenderHints::pushToRenderStack('feature_nodes');
86

    
87
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
88

    
89
  // Creating an array to place the description elements in.
90

    
91
  // =============== SPECIAL NUMBER OF TAXA  ================= //
92
  $bibliographyOut = array();
93
  $countFeatures = 0;
94
  $numberOfChildren = count(cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array (get_taxonomictree_uuid_selected(), $taxon->uuid)));
95
  if ($taxon->name->rank->titleCache == "Genus") {
96
    $subRank = "species";
97
  }
98
  if ($taxon->name->rank->titleCache == "Species") {
99
    if($numberOfChildren==1){
100
      $subRank = "infraspecific taxon";
101
    }
102
    else{
103
      $subRank = "infraspecific taxa";
104
    }
105
  }
106
  if ($numberOfChildren != 0) {
107
    $out .= '<a name="number_of_taxa"> </a><H2>Number of Taxa</H2><div class="content"> <ul class="description">';
108
    $out .= '<li class=\"descriptionText DescriptionElement\">' . $numberOfChildren . " " . $subRank . '</li></ul>';
109
  }
110
  // =============== END SPECIAL NUMBER OF TAXA ================= //
111

    
112
  foreach ($mergedFeatureNodes as $node) {
113

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

    
116
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
117
      $block = new stdclass(); // Empty object.
118
      $block->module = 'cdm_dataportal';
119
      $media_list = array();
120

    
121
      // =============== SPECIAL bibliography ================= //
122
      // If the option is enabled the description elements will be added
123
      // to the array.
124
      $show_bibliography = variable_get('cdm_show_bibliography', 1);
125
      if ($show_bibliography) {
126
        $bibliographyOut[] = $node->descriptionElements;
127
      }
128
      // =============== SPECIAL bibliography ================= //
129

    
130

    
131
      if ($node->feature->uuid != UUID_IMAGE && $node->feature->uuid != UUID_USE) {
132
        $countFeatures++;
133
        $countFeatures++;
134
        $block->delta = generalizeString($featureRepresentation);
135
        $block->subject = '<span class="' . html_class_attribute_ref($node->feature) . '">'
136
            . theme('cdm_feature_name',  array('feature_name' => $featureRepresentation)) . '</span>';
137
        $block->module = "cdm_dataportal-feature";
138
        $block->content = '';
139

    
140
        /*
141
         * Content/DISTRIBUTION.
142
         */
143
        if ($node->feature->uuid == UUID_DISTRIBUTION) {
144

    
145
          $distributionElements = null;
146
          $distribution_info_dto = null;
147
          $text_data_out_array = array();
148

    
149
          $distribution_sortOutArray = FALSE;
150
          if (variable_get('distribution_sort', 'NO_SORT') != 'NO_SORT') {
151
            $distribution_glue = '';
152
            $distribution_enclosingTag = 'dl';
153
          }
154
          else {
155
            $distribution_glue = '';
156
            $distribution_enclosingTag = 'ul';
157
          }
158

    
159
          if(!isset($node->descriptionElements['#type']) || !$node->descriptionElements['#type']=='DTO') {
160
            // skip the DISTRIBUTION section if there is no DTO type element
161
            continue;
162
          }
163

    
164
          if(isset($node->descriptionElements['TextData'])){
165
            // --- TextData
166

    
167
            $text_data_glue = '';
168
            $text_data_sort = FALSE;
169
            $text_data_enclosingTag = 'ul';
170

    
171
            foreach ($node->descriptionElements['TextData'] as $text_data_element){
172
              $asListElement = FALSE;
173
              $repr = theme('cdm_descriptionElementTextData', array(
174
                  'element' => $text_data_element,
175
                  'asListElement' => $asListElement,
176
                  'feature_uuid' => $text_data_element->feature->uuid,
177
              ));
178

    
179
              if (!array_search($repr, $text_data_out_array)) {
180
                $text_data_out_array[] = $repr;
181
                // TODO HINT: sorting in theme_cdm_feature_block_elements will
182
                // not work since this array contains html attributes with uuids
183
                // !!!!
184
                $text_data_sort = TRUE;
185
                $text_data_glue = '<br/> ';
186
                $text_data_enclosingTag = 'p';
187
              }
188
            }
189
          }
190

    
191

    
192
          if ($text_data_out_array && variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
193
            $tmp_render_array = compose_cdm_feature_block_elements(
194
              $text_data_out_array,
195
              $node->feature,
196
              $text_data_glue,
197
              $text_data_sort,
198
              $text_data_enclosingTag
199
            );
200

    
201
            $block->content .= $tmp_render_array['#markup'];
202
          }
203

    
204
          // --- Distribution map
205
          $distribution_map_query_parameters = null;
206
          if(isset($node->descriptionElements['DistributionInfoDTO'])) {
207
            $distribution_map_query_parameters = $node->descriptionElements['DistributionInfoDTO']->mapUriParams;
208
          }
209
          $map_render_element = compose_distribution_map($taxon, $distribution_map_query_parameters);
210
          $block->content .= $map_render_element['#markup'];
211

    
212
            // --- tree or list
213
              $dto_out_array = array();
214
          if(isset($node->descriptionElements['DistributionInfoDTO'])) {
215
            $distribution_info_dto = $node->descriptionElements['DistributionInfoDTO'];
216

    
217
            // --- tree
218
            if (is_object($distribution_info_dto->tree)) {
219
              $dto_out_array[] = theme('cdm_description_ordered_distributions', array('distribution_tree' => $distribution_info_dto->tree));
220
            }
221

    
222
            // --- sorted element list
223
            if( is_array($distribution_info_dto->elements) && count($distribution_info_dto->elements) > 0 ) {
224
              foreach ($distribution_info_dto->elements as $descriptionElement){
225
                if (is_object($descriptionElement->area)) {
226
                  $sortKey = $descriptionElement->area->representation_L10n;
227
                  $distributionElements[$sortKey] = $descriptionElement;
228
                }
229
              }
230
              ksort($distributionElements);
231
              $dto_out_array[] = theme('cdm_descriptionElement_Distribution', array(
232
                  'descriptionElements' => $distributionElements,
233
              ));
234

    
235
            }
236
            //
237

    
238
            $tmp_render_array = compose_cdm_feature_block_elements(
239
                $dto_out_array,
240
                $node->feature,
241
                $distribution_glue,
242
                $distribution_sortOutArray,
243
                $distribution_enclosingTag
244
            );
245
            $block->content .= $tmp_render_array['#markup'];
246
          }
247

    
248
          // --- TextData at the bottom
249
          if ($text_data_out_array && !variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
250
            $tmp_render_array = compose_cdm_feature_block_elements(
251
                $text_data_out_array,
252
                $node->feature,
253
                $text_data_glue,
254
                $text_data_sort,
255
                $text_data_enclosingTag
256
            );
257
            $block->content .= $tmp_render_array['#markup'];
258
          }
259

    
260
        }
261

    
262
        /*
263
        Content/COMMON_NAME.
264
        */
265
        elseif ($node->feature->uuid == UUID_COMMON_NAME) {
266
          $block->content .= theme('cdm_common_names', array('elements' => $node->descriptionElements));
267
        }
268

    
269
        /*
270
         * Content/ALL OTHER FEATURES.
271
        */
272
        else if ($node->feature->uuid == UUID_USE_RECORD) {
273
          $block->content .= theme('cdm_block_Uses', array('taxonUuid' => $taxon->uuid));
274
          // $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid),
275
        }
276
        else {
277
          $block->content .= compose_cdm_descriptionElements($node->descriptionElements, $node->feature->uuid, $taxon->uuid);
278

    
279
          /*
280
          Content/ALL OTHER FEATURES/Subordinate Features
281
          subordinate features are printed inline in one floating text,
282
          it is expected that subordinate features only "contain" TextData
283
          elements.
284
          */
285
          // TODO move into own theme.
286
          if (isset($node->childNodes[0])) {
287

    
288
            // TODO support more than one level of children.
289
            // @see http://dev.e-taxonomy.eu/trac/ticket/2393/
290
            $text = '';
291
            foreach ($node->childNodes as $child) {
292

    
293
              if (isset($child->descriptionElements) && is_array($child->descriptionElements)) {
294
               foreach ($child->descriptionElements as $element) {
295

    
296
                 if (is_array($element->media)) {
297
                    // Append media of supordinate elements to list of main
298
                    // feature.
299
                   $media_list = array_merge($media_list, $element->media);
300
                 }
301

    
302
                 $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
303
                // TODO use localized version of feature name, the locale must
304
                // match the locale of the multilanguage text
305
                // (http://dev.e-taxonomy.eu/trac/ticket/2394).
306
                 $description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
307
               }
308
               $text .= " " . $description;
309
               $description = '';
310
             }
311
            }
312
            $block->content .= $text;
313
          }
314
        }
315

    
316
        /*
317
        Media/ALL FEATURES.
318
        */
319
        $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
320

    
321
        $gallery = theme('cdm_media_gallerie', array(
322
           'mediaList' => $media_list,
323
           'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
324
           'maxExtend' => isset($gallery_settings['cdm_dataportal_media_maxextend']) ? $gallery_settings['cdm_dataportal_media_maxextend'] : NULL ,
325
           'cols' => isset($gallery_settings['cdm_dataportal_media_cols']) ? $gallery_settings['cdm_dataportal_media_cols'] : NULL ,
326
           'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? $gallery_settings['cdm_dataportal_media_maxRows'] : NULL ,
327
           'captionElements' => isset($captionElements) ? $captionElements : NULL ,
328
           )
329
        );
330

    
331
        $block->content .= $gallery;
332
        $block->content .= theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid));
333
        $block->content .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid));
334

    
335
        // Add anchor to subject.
336
        $block->subject = '<a name="' . $block->delta . '"></a>' . $block->subject;
337

    
338
        $block->region = FALSE;
339
        $out .= theme('block', array('elements' => array(
340
          '#block' => $block,
341
          '#children' => $block->content,
342
        )));
343
      }
344
    }
345
  }
346

    
347
  // Add the display of the number of taxa in the selected genus.
348
  //
349

    
350

    
351
// !!!!!! no longer needed !!!!
352
  // Calling the theme function for Bibliography to add it to the output.
353
//  $show_bibliography = variable_get('cdm_show_bibliography', 1);
354
//  if ($show_bibliography && $countFeatures != 0) {
355
//    $out .= theme('cdm_descriptionElementBibliography', array('descriptionElementsBibliography' => $bibliographyOut));
356
//  }
357

    
358
  RenderHints::popFromRenderStack();
359
  return $out;
360
}
361

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

    
371
  $showThumbnails = isset($_SESSION['pageoption']['searchtaxa']['showThumbnails']) ? $_SESSION['pageoption']['searchtaxa']['showThumbnails'] : 0;
372
  if (!is_numeric($showThumbnails)) {
373
    // AT RBG KEW - 14/11/2011 - Set the show thumbnails to 0 by default.
374
    $showThumbnails = 0;
375
  }
376
  $setSessionUri = url('cdm_api/setvalue/session', array('query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => '')));
377
  drupal_add_js('jQuery(document).ready(function() {
378

    
379
        // Init.
380
        if(' . $showThumbnails . ' == 1){
381
              jQuery(\'.media_gallery\').show(20);
382
        } else {
383
          jQuery(\'.media_gallery\').hide(20);
384
        }
385
        // Add change hander.
386
        jQuery(\'#showThumbnails\').change(
387
          function(event){
388
            var state = 0;
389
            if(jQuery(this).is(\':checked\')){
390
              jQuery(\'.media_gallery\').show(20);
391
              state = 1;
392
            } else {
393
              jQuery(\'.media_gallery\').hide(20);
394
            }
395
            // Store state in session variable.
396
            var uri = \'' . $setSessionUri . '\' + state;
397
            jQuery.get(uri);
398
          });
399
        });', "inline");
400

    
401
  drupal_set_title(t('Search results'));
402

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

    
426
/*
427
Comment @WA: theme function moved to cdm_dataportal module,
428
theme/cdm_dataportal.bibliography.theme so this can be used by other portals
429
as well.
430
@TODO: should this not be part of the palmweb_2 featuretree and be treated
431
as a normal description feature?
432
function theme_cdm_descriptionElementBibliography
433
function formatReference_for_Bibliography($references) {
434
 */
435

    
436
/**
437
 * @todo Please document this function.
438
 */
439
function palmweb_2_cdm_media_caption($variables){
440
  $media = $variables['media'];
441
  $elements = $variables['elements'];
442

    
443
  $media_metadata = cdm_read_media_metadata($media);
444

    
445
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
446
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
447
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
448
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
449
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
450

    
451
  $descriptionPrefix = "";
452

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

    
533
/**
534
 * Overrive of the original theme_cdm_reference()
535
 * the main difference here seems to be that
536
 * this function is completely omitting the citation title cache
537
 * and only sets the authorTeam as the
538
 * _short_form_of_author_team() as $citation.
539
 *
540
 * If the authorteam is not set citation was empty,
541
 * this has been fixed for http://dev.e-taxonomy.eu/trac/ticket/4261
542
 *
543
 * TODO can this be made configuable via the dataportal
544
 *      settings so that we can remove this function?
545
 */
546
function xxx_palmweb_2_cdm_reference($variables) {
547
  $reference = $variables['reference'];
548
  $microReference = $variables['microReference'];
549
  $doLink = $variables['doLink'];
550
  $referenceStyle = $variables['referenceStyle'];
551

    
552
  if(!isset($reference->authorTeam)){
553
    $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
554
  } else {
555
    $author_team = $reference->authorTeam;
556
  }
557

    
558
  $year = '';
559
  if (isset($reference->datePublished->start)) {
560
    $year = partialToYear($reference->datePublished->start);
561
  }
562
  if(isset($author_team->titleCache)){
563
    $citation = _short_form_of_author_team ($author_team->titleCache) . (!empty($year) ? '. ' . $year : '');
564
    $citation = str_replace('..', '.', $citation);
565
  } else {
566
    $citation = $reference->titleCache;
567
  }
568

    
569
  if ($doLink) {
570
    $out = '<span class="reference">';
571
    $out .= l($citation, path_to_reference($reference->uuid), array(
572
    'attributes' => array('class' => 'reference'),
573
    'absolute' => TRUE,
574
    'html' => TRUE,
575
    ));
576
    $out .= '</span>';
577
  }
578
  else {
579
    $out = '<span class="reference">' . $citation . '</span>';
580
  }
581
  // FIXME use microreference webservice instead.
582
  if (!empty($descriptionElementSource->citationMicroReference)) {
583
    $out .= ': ' . $descriptionElementSource->citationMicroReference;
584
  }
585

    
586
  return $out;
587
}
588

    
589
/**
590
 * Sets the body-tag class attribute.
591
 *
592
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
593
 */
594
function phptemplate_body_class($sidebar_left, $sidebar_right) {
595
  if ($sidebar_left != '' && $sidebar_right != '') {
596
    $class = 'sidebars';
597
  }
598
  else {
599
    if ($sidebar_left != '') {
600
      $class = 'sidebar-left';
601
    }
602
    if ($sidebar_right != '') {
603
      $class = 'sidebar-right';
604
    }
605
  }
606

    
607
  if (isset($class)) {
608
    print ' class="' . $class . '"';
609
  }
610
}
611

    
612
/**
613
 * Allow themeable wrapping of all comments.
614
 */
615
function phptemplate_comment_wrapper($content, $type = NULL) {
616
  static $node_type;
617
  if (isset($type)) {
618
    $node_type = $type;
619
  }
620

    
621
  if (!$content || $node_type == 'forum') {
622
    return '<div id="comments">' . $content . '</div>';
623
  }
624
  else {
625
    return '<div id="comments"><h2 class="comments">' . t('Comments') . '</h2>' . $content . '</div>';
626
  }
627
}
628

    
629
/**
630
 * Override or insert PHPTemplate variables into the templates.
631
 */
632
function _phptemplate_variables($hook, $vars) {
633
  if ($hook == 'page') {
634

    
635
    if ($secondary = menu_secondary_local_tasks()) {
636
      $output = '<span class="clear"></span>';
637
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
638
      $vars['tabs2'] = $output;
639
    }
640

    
641
    // Hook into color.module
642
    if (module_exists('color')) {
643
      _color_page_alter($vars);
644
    }
645
    return $vars;
646
  }
647
  return array();
648
}
649

    
650
/**
651
 * Returns the rendered local tasks. The default implementation renders
652
 * them as tabs.
653
 *
654
 * @ingroup themeable
655
 */
656
function phptemplate_menu_local_tasks() {
657
  $output = '';
658

    
659
  if ($primary = menu_primary_local_tasks()) {
660
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
661
  }
662

    
663
  return $output;
664
}
665

    
666
/**
667
 * @todo Please document this function.
668
 * @see http://drupal.org/node/1354
669
 */
670
function palmweb_2_cdm_feature_name($variables){
671
  $feature_name = $variables['feature_name'];
672
  switch ($feature_name) {
673
    case "Protologue": return t("Original Publication");
674
    default: return t(ucfirst($feature_name));
675
  }
676
}
677

    
678
/**
679
 * Implements hook_preprocess_HOOK() for theme_page().
680
 *
681
 * Assign the css classes primary-links and secondary-links to the menus and
682
 * process the 'Login' menu item, to change into 'My account' after login and
683
 * change the tab title for the IMCE file browser.
684
 *
685
 * @author W.Addink <w.addink@eti.uva.nl>
686
 */
687
function palmweb_2_preprocess_page(&$vars) {
688

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

    
730
  // Change IMCE tab to 'Personal Files'.
731
  if (!empty($vars['tabs']['#primary'])) {
732
    foreach ($vars['tabs']['#primary'] as $key => $value) {
733
      if ($value['#link']['path'] == 'user/%/imce') {
734
        $vars['tabs']['#primary'][$key]['#link']['title'] = t('Personal Files');
735
      }
736
    }
737
  }
738

    
739

    
740
  /* Display node title as page title for the comment form.
741
  * Comment @WA: it would probably be better to select $uuid from node_cdm
742
  * table and link to cdm_dataportal/taxon/%uuid instead.
743
  */
744
  if (arg(0) == 'comment' && arg(1) == 'reply') {
745
      $node = $vars['page']['content']['system_main']['comment_node']['#node'];
746
      $vars['title'] = l(check_plain($node->title),'node/' . $node->nid);
747
  }
748
}
749

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

    
776
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
777
  global $base_url;
778
  if ($base_url == '/') {
779
    drupal_set_message(t('
780
      The $base_url in this portal could not be set, please set the $base_url
781
      manually your Drupal settings.php file.', 'error'
782
    ));
783
  }
784
  $fixed_file_path = $base_url . $file_path;
785

    
786
  $preg_file_path = preg_quote($file_path, '/');
787
  $body = preg_replace ('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path , $body);
788
  $body = preg_replace ('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path , $body);
789
  $body = preg_replace ('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path , $body);
790
  $body = preg_replace ('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path , $body);
791

    
792
  $vars['fixed_body'] = $body;
793
}
794

    
795
/**
796
 * Implements hook_form_FORM_ID_alter() for comment_form().
797
 *
798
 * Alter the comment form to make it look like a D5 style comment form.
799
 *
800
 * @author W.Addink <w.addink@eti.uva.nl>
801
 */
802
function palmweb_2_form_comment_form_alter(&$form, &$form_state) {
803

    
804
  if (!isset($form['comment_preview'])) {
805
    $form['header'] = array(
806
      '#markup' => '<h2>' . t('Reply') . '</h2>',
807
      '#weight' => -2,
808
    );
809
  }
810
  $form['subject']['#title'] = $form['subject']['#title'] . ':';
811
  $form['comment_body']['und'][0]['#title'] = $form['comment_body']['und'][0]['#title'] . ':';
812
  if (isset($form['author']['_author']['#title'])) {
813
    $form['author']['_author']['#title'] = $form['author']['_author']['#title'] . ':';
814
  }
815
  $form['actions']['submit']['#value'] = t('Post comment');
816
  $form['actions']['submit']['#weight'] = 1000;
817
  $form['actions']['preview']['#value'] = t('Preview comment');
818
}
819

    
820
/**
821
 * Implements hook_preprocess_HOOK() for theme_comment().
822
 *
823
 * Alter the comment display to make it look like a D5 style comment.
824
 *
825
 * @author W.Addink <w.addink@eti.uva.nl>
826
 */
827
function palmweb_2_preprocess_comment(&$variables) {
828
  $comment = $variables['elements']['#comment'];
829
  if (isset($comment->subject)) {
830
    // Print title without link.
831
    $variables['title'] = $comment->subject;
832
    if ($variables['status'] == 'comment-preview') {
833
      // Add 'new' to preview.
834
      $variables['new'] = t('new');
835
    }
836
  }
837
}
(11-11/11)