Project

General

Profile

Download (28.6 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

    
111

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

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

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

    
138
          $distributionElements = null;
139
          $distribution_info_dto = null;
140
          $text_data_out_array = array();
141

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

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

    
157
          if(isset($node->descriptionElements['TextData'])){
158
            // --- TextData
159

    
160
            $text_data_glue = '';
161
            $text_data_sort = FALSE;
162
            $text_data_enclosingTag = 'ul';
163

    
164
            foreach ($node->descriptionElements['TextData'] as $text_data_element){
165
              $asListElement = FALSE;
166
              $repr = theme('cdm_descriptionElementTextData', array(
167
                  'element' => $text_data_element,
168
                  'asListElement' => $asListElement,
169
                  'feature_uuid' => $text_data_element->feature->uuid,
170
              ));
171

    
172
              if (!array_search($repr, $text_data_out_array)) {
173
                $text_data_out_array[] = $repr;
174
                // TODO HINT: sorting in theme_cdm_feature_block_elements will
175
                // not work since this array contains html attributes with uuids
176
                // !!!!
177
                $text_data_sort = TRUE;
178
                $text_data_glue = '<br/> ';
179
                $text_data_enclosingTag = 'p';
180
              }
181
            }
182
          }
183

    
184

    
185
          if ($text_data_out_array && variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
186
            $tmp_render_array = compose_cdm_feature_block_elements(
187
              $text_data_out_array,
188
              $node->feature,
189
              $text_data_glue,
190
              $text_data_sort,
191
              $text_data_enclosingTag
192
            );
193

    
194
            $block->content .= $tmp_render_array['#markup'];
195
          }
196

    
197
          // --- Distribution map
198
          $distribution_map_query_parameters = null;
199
          if(isset($node->descriptionElements['DistributionInfoDTO'])) {
200
            $distribution_map_query_parameters = $node->descriptionElements['DistributionInfoDTO']->mapUriParams;
201
          }
202
          $map_render_element = compose_distribution_map($taxon, $distribution_map_query_parameters);
203
          $block->content .= $map_render_element['#markup'];
204

    
205
            // --- tree or list
206
              $dto_out_array = array();
207
          if(isset($node->descriptionElements['DistributionInfoDTO'])) {
208
            $distribution_info_dto = $node->descriptionElements['DistributionInfoDTO'];
209

    
210
            // --- tree
211
            if (is_object($distribution_info_dto->tree)) {
212
              $dto_out_array[] = theme('cdm_description_ordered_distributions', array('distribution_tree' => $distribution_info_dto->tree));
213
            }
214

    
215
            // --- sorted element list
216
            if( is_array($distribution_info_dto->elements) && count($distribution_info_dto->elements) > 0 ) {
217
              foreach ($distribution_info_dto->elements as $descriptionElement){
218
                if (is_object($descriptionElement->area)) {
219
                  $sortKey = $descriptionElement->area->representation_L10n;
220
                  $distributionElements[$sortKey] = $descriptionElement;
221
                }
222
              }
223
              ksort($distributionElements);
224
              $dto_out_array[] = theme('cdm_descriptionElement_Distribution', array(
225
                  'descriptionElements' => $distributionElements,
226
              ));
227

    
228
            }
229
            //
230

    
231
            $tmp_render_array = compose_cdm_feature_block_elements(
232
                $dto_out_array,
233
                $node->feature,
234
                $distribution_glue,
235
                $distribution_sortOutArray,
236
                $distribution_enclosingTag
237
            );
238
            $block->content .= $tmp_render_array['#markup'];
239
          }
240

    
241
          // --- TextData at the bottom
242
          if ($text_data_out_array && !variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
243
            $tmp_render_array = compose_cdm_feature_block_elements(
244
                $text_data_out_array,
245
                $node->feature,
246
                $text_data_glue,
247
                $text_data_sort,
248
                $text_data_enclosingTag
249
            );
250
            $block->content .= $tmp_render_array['#markup'];
251
          }
252

    
253
        }
254

    
255
        /*
256
        Content/COMMON_NAME.
257
        */
258
        elseif ($node->feature->uuid == UUID_COMMON_NAME) {
259
          $block->content .= theme('cdm_common_names', array('elements' => $node->descriptionElements));
260
        }
261

    
262
        /*
263
        Content/ALL OTHER FEATURES.
264
        */
265
        elseif ($node->feature->uuid == UUID_USE_RECORD) {
266
          $block->content .= theme('cdm_block_Uses', array('taxonUuid' => $taxon->uuid));
267
          // $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid),
268
        }
269
        else {
270
          $block->content .= compose_cdm_descriptionElements($node->descriptionElements, $node->feature->uuid, $taxon->uuid);
271

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

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

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

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

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

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

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

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

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

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

    
340
  // Add the display of the number of taxa in the selected genus.
341
  //
342

    
343

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

    
350
  RenderHints::popFromRenderStack();
351
  return $out;
352
}
353

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

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

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

    
393
  drupal_set_title(t('Search results'));
394

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

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

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

    
435
  $media_metadata = cdm_read_media_metadata($media);
436

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

    
443
  $descriptionPrefix = "";
444

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

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

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

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

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

    
577
  return $out;
578
}
579

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

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

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

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

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

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

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

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

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

    
654
  return $output;
655
}
656

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

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

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

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

    
730

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

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

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

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

    
783
  $vars['fixed_body'] = $body;
784
}
785

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

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

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