Project

General

Profile

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

    
7
/**
8
 * 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_feature_block_elements 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_feature_block_elements', 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_feature_block_elements', 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_feature_block_elements', 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
          $block->content .= theme('cdm_common_names', array('elements' => $node->descriptionElements));
248
        }
249

    
250
        /*
251
        Content/ALL OTHER FEATURES.
252
        */
253
        elseif ($node->feature->uuid == UUID_USE_RECORD) {
254
          $block->content .= theme('cdm_block_Uses', array('taxonUuid' => $taxon->uuid));
255
          // $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid),
256
        }
257
        else {
258
          $block->content .= theme('cdm_descriptionElements', array(
259
            'descriptionElements' => $node->descriptionElements,
260
            'featureUuid' => $node->feature->uuid,
261
            'taxon_uuid' => $taxon->uuid,
262
          ));
263

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

    
273
            // TODO support more than one level of children.
274
            // @see http://dev.e-taxonomy.eu/trac/ticket/2393/
275
            $text = '';
276
            foreach ($node->childNodes as $child) {
277

    
278
              if (isset($child->descriptionElements) && is_array($child->descriptionElements)) {
279
               foreach ($child->descriptionElements as $element) {
280

    
281
                 if (is_array($element->media)) {
282
                    // Append media of supordinate elements to list of main
283
                    // feature.
284
                   $media_list = array_merge($media_list, $element->media);
285
                 }
286

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

    
301
        /*
302
        Media/ALL FEATURES.
303
        */
304
        $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
305

    
306
        $gallery = theme('cdm_media_gallerie', array(
307
           'mediaList' => $media_list,
308
           'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
309
           'maxExtend' => isset($gallery_settings['cdm_dataportal_media_maxextend']) ? $gallery_settings['cdm_dataportal_media_maxextend'] : NULL ,
310
           'cols' => isset($gallery_settings['cdm_dataportal_media_cols']) ? $gallery_settings['cdm_dataportal_media_cols'] : NULL ,
311
           'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? $gallery_settings['cdm_dataportal_media_maxRows'] : NULL ,
312
           'captionElements' => isset($captionElements) ? $captionElements : NULL ,
313
           )
314
        );
315

    
316
        $block->content .= $gallery;
317
        $block->content .= theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid));
318
        $block->content .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid));
319

    
320
        // Add anchor to subject.
321
        $block->subject = '<a name="' . $block->delta . '"></a>' . $block->subject;
322

    
323
        $block->region = FALSE;
324
        $out .= theme('block', array('elements' => array(
325
          '#block' => $block,
326
          '#children' => $block->content,
327
        )));
328
      }
329
    }
330
  }
331

    
332
  // Add the display of the number of taxa in the selected genus.
333
  //
334

    
335

    
336
  // Calling the theme function for Bibliography to add it to the output.
337
  $show_bibliography = variable_get('cdm_show_bibliography', 1);
338
  if ($show_bibliography && $countFeatures != 0) {
339
    $out .= theme('cdm_descriptionElementBibliography', array('descriptionElementsBibliography' => $bibliographyOut));
340
  }
341

    
342
  RenderHints::popFromRenderStack();
343
  return $out;
344
}
345

    
346
/**
347
 * @todo Please document this function.
348
 * @see http://drupal.org/node/1354
349
 */
350
function palmweb_2_cdm_search_results($variables){
351
  $pager = $variables['pager'];
352
  $path = $variables['path'];
353
  $out = '';
354

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

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

    
385
  drupal_set_title(t('Search results'));
386

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

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

    
420
/**
421
 * @todo Please document this function.
422
 */
423
function palmweb_2_cdm_media_caption($variables){
424
  $media = $variables['media'];
425
  $elements = $variables['elements'];
426

    
427
  $media_metadata = cdm_read_media_metadata($media);
428

    
429
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
430
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
431
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
432
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
433
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
434

    
435
  $descriptionPrefix = "";
436

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

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

    
535
  if(!isset($reference->authorTeam)){
536
    $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
537
  } else {
538
    $author_team = $reference->authorTeam;
539
  }
540

    
541
  $year = '';
542
  if (isset($reference->datePublished->start)) {
543
    $year = partialToYear($reference->datePublished->start);
544
  }
545
  if(isset($author_team->titleCache)){
546
    $citation = _short_form_of_author_team ($author_team->titleCache) . (!empty($year) ? '. ' . $year : '');
547
    $citation = str_replace('..', '.', $citation);
548
  } else {
549
    $citation = $reference->titleCache;
550
  }
551

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

    
569
  return $out;
570
}
571

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

    
590
  if (isset($class)) {
591
    print ' class="' . $class . '"';
592
  }
593
}
594

    
595
/**
596
 * Allow themeable wrapping of all comments.
597
 */
598
function phptemplate_comment_wrapper($content, $type = NULL) {
599
  static $node_type;
600
  if (isset($type)) {
601
    $node_type = $type;
602
  }
603

    
604
  if (!$content || $node_type == 'forum') {
605
    return '<div id="comments">' . $content . '</div>';
606
  }
607
  else {
608
    return '<div id="comments"><h2 class="comments">' . t('Comments') . '</h2>' . $content . '</div>';
609
  }
610
}
611

    
612
/**
613
 * Override or insert PHPTemplate variables into the templates.
614
 */
615
function _phptemplate_variables($hook, $vars) {
616
  if ($hook == 'page') {
617

    
618
    if ($secondary = menu_secondary_local_tasks()) {
619
      $output = '<span class="clear"></span>';
620
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
621
      $vars['tabs2'] = $output;
622
    }
623

    
624
    // Hook into color.module
625
    if (module_exists('color')) {
626
      _color_page_alter($vars);
627
    }
628
    return $vars;
629
  }
630
  return array();
631
}
632

    
633
/**
634
 * Returns the rendered local tasks. The default implementation renders
635
 * them as tabs.
636
 *
637
 * @ingroup themeable
638
 */
639
function phptemplate_menu_local_tasks() {
640
  $output = '';
641

    
642
  if ($primary = menu_primary_local_tasks()) {
643
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
644
  }
645

    
646
  return $output;
647
}
648

    
649
/**
650
 * @todo Please document this function.
651
 * @see http://drupal.org/node/1354
652
 */
653
function palmweb_2_cdm_feature_name($variables){
654
  $feature_name = $variables['feature_name'];
655
  switch ($feature_name) {
656
    case "Protologue": return t("Original Publication");
657
    default: return t(ucfirst($feature_name));
658
  }
659
}
660

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

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

    
713
  // Change IMCE tab to 'Personal Files'.
714
  if (!empty($vars['tabs']['#primary'])) {
715
    foreach ($vars['tabs']['#primary'] as $key => $value) {
716
      if ($value['#link']['path'] == 'user/%/imce') {
717
        $vars['tabs']['#primary'][$key]['#link']['title'] = t('Personal Files');
718
      }
719
    }
720
  }
721

    
722

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

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

    
759
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
760
  global $base_url;
761
  if ($base_url == '/') {
762
    drupal_set_message(t('
763
      The $base_url in this portal could not be set, please set the $base_url
764
      manually your Drupal settings.php file.', 'error'
765
    ));
766
  }
767
  $fixed_file_path = $base_url . $file_path;
768

    
769
  $preg_file_path = preg_quote($file_path, '/');
770
  $body = preg_replace ('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path , $body);
771
  $body = preg_replace ('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path , $body);
772
  $body = preg_replace ('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path , $body);
773
  $body = preg_replace ('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path , $body);
774

    
775
  $vars['fixed_body'] = $body;
776
}
777

    
778
/**
779
 * Implements hook_form_FORM_ID_alter() for comment_form().
780
 *
781
 * Alter the comment form to make it look like a D5 style comment form.
782
 *
783
 * @author W.Addink <w.addink@eti.uva.nl>
784
 */
785
function palmweb_2_form_comment_form_alter(&$form, &$form_state) {
786

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

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