Project

General

Profile

Download (32.2 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
 * Returns HTML for a cdm_taxon_page_profile.
9
 *
10
 * The description page is supposed to be the front page for a taxon.
11
 *
12
 * @param array $variables
13
 *   An associative array containing:
14
 *   - taxon: The taxon object displayed on the taxon page.
15
 *   - mergedTrees
16
 *   - media:
17
 *   - hideImages: boolean, FALSE if images should be hided.
18
 *
19
 * @ingroup themeable
20
 */
21
function palmweb_2_cdm_taxon_page_profile($variables){
22

    
23
  $taxon = $variables['taxon'];
24
  $mergedTrees = $variables['mergedTrees'];
25
  $media = $variables['media'];
26
  $hideImages = $variables['hideImages'];
27

    
28
  $out = '';
29

    
30
  if (!$hideImages) {
31
    // Preferred image.
32
    // Hardcoded for testing.
33
    $defaultRepresentationPart = new stdClass();
34
    $defaultRepresentationPart->width = 184;
35
    $defaultRepresentationPart->height = 144;
36
    $defaultRepresentationPart->uri = drupal_get_path('theme', 'palmweb_2') . '/images/no_picture.png';
37

    
38
    // Preferred image size 184px × 144.
39
    $imageMaxExtend = 184;
40
    $out .= '<div id="taxonProfileImage">';
41
    $out .= theme('cdm_preferredImage', array(
42
      'media' => $media,
43
      'defaultRepresentationPart' => $defaultRepresentationPart,
44
      'imageMaxExtend' => $imageMaxExtend,
45
    ));
46
    $out .= '</div>';
47
  }
48

    
49
  // Description TOC.
50
  $out .= theme('cdm_featureTreeTOCs', array('mergedTrees' => $mergedTrees));
51

    
52
  // Description.
53
  $out .= theme('cdm_featureTrees', array('mergedTrees' => $mergedTrees, 'taxon' => $taxon));
54

    
55
  return $out;
56
}
57

    
58
/**
59
 * @todo Please document this function.
60
 * @see http://drupal.org/node/1354
61
 */
62
function palmweb_2_cdm_descriptionElementDistribution($variables) {
63
  $descriptionElements = $variables['descriptionElements'];
64
  $enclosingTag = $variables['enclosingTag'];
65

    
66
  $out = '';
67
  $separator = ', ';
68

    
69
  RenderHints::pushToRenderStack('descriptionElementDistribution');
70
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
71

    
72
  $itemCnt = 0;
73
  foreach ($descriptionElements as $descriptionElement) {
74
    /*
75
    $out .= ($descriptionElement->class);
76
    // Annotations as footnotes.
77
    $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
78
    // Source references as footnotes.
79
    $sourcesFootnoteKeyList = '';
80
    foreach($descriptionElement->sources as $source){
81
      $_fkey = FootnoteManager::addNewFootnote(UUID_DISTRIBUTION, theme('cdm_DescriptionElementSource', $source, FALSE));
82
      $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, ($sourcesFootnoteKeyList ? $separator : ''));
83
    }
84
    if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
85
      $annotationFootnoteKeys .= $separator;
86
    }
87
    */
88
        $out .= '<' . $enclosingTag . ' class="DescriptionElement DescriptionElement-' . $descriptionElement->class . '">';
89
        // $out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList;
90
        $out .= $descriptionElement->area->representation_L10n;
91
        if (++$itemCnt < count($descriptionElements)) {
92
          $out .= $separator;
93
        }
94
        $out .= "</" . $enclosingTag . ">";
95
  }
96
  $taxonTrees = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
97
  $reference = new stdClass();
98
  foreach ($taxonTrees as $taxonTree) {
99
    if ($taxonTree->uuid == variable_get('cdm_taxonomictree_uuid')) {
100
      if (isset($taxonTree->reference)) {
101
        $reference = $taxonTree->reference;
102
      }
103
      break;
104
    }
105
  }
106
  $referenceCitation = '';
107
  if (isset($reference->uuid)) {
108
    $referenceCitation .= '(<span class="reference">';
109
    $referenceCitation .= l(t('World Checklist of Monocotyledons'), path_to_reference($reference->uuid), array('attributes' => array('class' => array('reference'))));
110
    $referenceCitation .= '</span>)';
111
  }
112
  else {
113
    // Comment @WA Added for compatibility with D5, but I think it is better to
114
    // remove this to not show a link rather than the wrong one.
115
    $referenceCitation .= '(<span class="reference">';
116
    $referenceCitation .= l(t('World Checklist of Monocotyledons'), '', array('attributes' => array('class' => array('reference'))));
117
    $referenceCitation .= '</span>)';
118
  }
119

    
120
  $sourceRefs = '';
121
  if ($out && strlen($out) > 0) {
122
    $sourceRefs = ' ' . $referenceCitation;
123
  }
124

    
125
  if (strlen($sourceRefs) > 0) {
126
    $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
127
  }
128

    
129
  RenderHints::popFromRenderStack();
130
  return $out . $sourceRefs;
131

    
132
}
133

    
134
/**
135
 * @todo Please document this function.
136
 * @see http://drupal.org/node/1354
137
 */
138
function palmweb_2_cdm_feature_nodesTOC($variables){
139
  $featureNodes = $variables['featureNodes'];
140
  $out = '';
141

    
142
  global $theme;
143

    
144
  $out .= '<ul>';
145
  $countFeatures = 0;
146
  $numberOfChildren = count(cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array (
147
    get_taxonomictree_uuid_selected(),
148
    substr(strrchr($_GET["q"],'/'), 1),
149
  )));
150
  if ($numberOfChildren != 0) {
151
    $out .= '<li>';
152
    $out .= l(t(theme('cdm_feature_name', array('feature_name' => 'Number of Taxa'))), $_GET['q'], array(
153
      'attributes' => array('class' => array('toc')),
154
      'fragment' => generalizeString('Number Of Taxa'),
155
    ));
156
    $out .= '</li>';
157
  }
158
  foreach ($featureNodes as $node) {
159
    if (hasFeatureNodeDescriptionElements($node)) {
160
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
161

    
162
      // HACK to implement images for taxa, should be removed.
163
      if ($node->feature->uuid != UUID_IMAGE && $node->feature->uuid != UUID_USE) {
164
        $countFeatures++;
165
        $countFeatures++;
166
        $out .= '<li>' . l(t(theme('cdm_feature_name', array('feature_name' => $featureRepresentation))), $_GET['q'],
167
            array('attributes' => array('class' => array('toc')),'fragment' => generalizeString($featureRepresentation))) . '</li>';
168
      }
169
    }
170
  }
171
  // Setting the Anchor to the Bibliography section if the option is enabled.
172
  $show_bibliography = variable_get('cdm_show_bibliography', 1);
173

    
174
  $markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
175
  $useDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, substr(strrchr($_GET["q"], '/'), 1), queryString($markerTypes));
176
  if (!empty($useDescriptions)) {
177
    $out .= '<li>';
178
    $out .= l(t(theme('cdm_feature_name', array('feature_name' => 'Uses'))), $_GET['q'], array(
179
      'attributes' => array('class' => array('toc')),
180
      'fragment' => 'userecords',
181
    ));
182
    $out .= '</li>';
183
  }
184

    
185
  if ($show_bibliography && $countFeatures != 0) {
186
    $out .= '<li>' . l(t(theme('cdm_feature_name', array('feature_name' => 'Bibliography'))), $_GET['q'], array('attributes' => array('class' => array('toc')), 'fragment' => 'bibliography')) . '</li>';
187
  }
188
  $out .= '</ul>';
189
  return $out;
190
}
191

    
192
/**
193
 * @todo Please document this function.
194
 * @see http://drupal.org/node/1354
195
 */
196
function palmweb_2_cdm_feature_nodes($variables){
197
  $mergedFeatureNodes = $variables['mergedFeatureNodes'];
198
  $taxon = $variables['taxon'];
199

    
200
  $out = '';
201
  RenderHints::pushToRenderStack('feature_nodes');
202

    
203
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
204
  // Creating an array to place the description elements in.
205
  $bibliographyOut = array();
206
  $countFeatures = 0;
207
  $numberOfChildren = count(cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array (get_taxonomictree_uuid_selected(), $taxon->uuid)));
208
  if ($taxon->name->rank->titleCache == "Genus") {
209
    $subRank = "species";
210
  }
211
  if ($taxon->name->rank->titleCache == "Species") {
212
    $subRank = "infraspecific taxa";
213
  }
214
  if ($numberOfChildren != 0) {
215
    $out .= '<a name="number_of_taxa"> </a><H2>Number of Taxa</H2><div class="content"> <ul class="description">';
216
    $out .= '<li class=\"descriptionText DescriptionElement\">' . $numberOfChildren . " " . $subRank . '</li></ul>';
217
  }
218

    
219
  foreach ($mergedFeatureNodes as $node) {
220

    
221
    if (hasFeatureNodeDescriptionElements($node)) {
222

    
223
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
224
      $block = new stdClass();
225
      $block->module = 'cdm_dataportal';
226
      // If the option is enabled the description elements will be added
227
      // to the array.
228
      $show_bibliography = variable_get('cdm_show_bibliography', 1);
229
      if ($show_bibliography) {
230
        $bibliographyOut[] = $node->descriptionElements;
231
      }
232
      $media_list = array();
233
      if ($node->feature->uuid != UUID_IMAGE && $node->feature->uuid != UUID_USE) {
234
        $countFeatures++;
235
        $countFeatures++;
236
        $block->delta = generalizeString($featureRepresentation);
237
        $block->subject = '<span class="' . html_class_atttibute_ref($node->feature) . '">' . theme('cdm_feature_name',  array('feature_name' => $featureRepresentation)) . '</span>';
238
        $block->module = "cdm_dataportal-feature";
239
        $block->content = '';
240

    
241
        /*
242
        Content/DISTRIBUTION.
243
        */
244
        if ($node->feature->uuid == UUID_DISTRIBUTION) {
245

    
246
          if (variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
247
            $distributionTextDataList = array();
248
            $distributionElementsList = array();
249

    
250
            foreach ($node->descriptionElements as $descriptionElement) {
251
              if ($descriptionElement->class == "TextData") {
252
                $distributionTextDataList[] = $descriptionElement;
253
              }
254
              else {
255
                $distributionElementsList[] = $descriptionElement;
256
              }
257
            }
258
            if (count($distributionTextDataList) > 0) {
259
              $node->descriptionElements = $distributionElementsList;
260
              $block->content .= theme('cdm_descriptionElements', array(
261
                'descriptionElements' => $distributionTextDataList,
262
                'featureUuid' => $node->feature->uuid,
263
                'taxon_uuid' => $taxon->uuid,
264
              ));
265
            }
266
          }
267

    
268
          // Display cdm distribution map.
269
          // TODO this is a HACK to a proper generic implementation?
270
          $block->content .= theme('cdm_distribution_map', array('taxon' => $taxon));
271
          $block->content .= theme('cdm_descriptionElements', array(
272
            'descriptionElements' => $node->descriptionElements,
273
            'featureUuid' => $node->feature->uuid,
274
            'taxon_uuid' => $taxon->uuid,
275
          ));
276
        }
277

    
278
        /*
279
        Content/COMMON_NAME.
280
        */
281
        elseif ($node->feature->uuid == UUID_COMMON_NAME) {
282
          // TODO why is theme_cdm_descriptionElement_CommonTaxonName
283
          // not beeing used???
284
          $block->content .= theme('cdm_common_names', array('elements' => $node->descriptionElements));
285
        /*
286
        }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
287
          $block->content .= theme('cdm_image_sources', $node->descriptionElements);
288
        */
289
        }
290

    
291
        /*
292
        Content/ALL OTHER FEATURES.
293
        */
294
        elseif ($node->feature->uuid == UUID_USE_RECORD) {
295
          $block->content .= theme('cdm_block_Uses', $taxon->uuid);
296
          // $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid),
297
        }
298
        else {
299
          $block->content .= theme('cdm_descriptionElements', array(
300
            'descriptionElements' => $node->descriptionElements,
301
            'featureUuid' => $node->feature->uuid,
302
            'taxon_uuid' => $taxon->uuid,
303
          ));
304

    
305
          /*
306
          Content/ALL OTHER FEATURES/Subordinate Features
307
          subordinate features are printed inline in one floating text,
308
          it is expected that subordinate features only "contain" TextData
309
          elements.
310
          */
311
          // TODO move into own theme.
312
          if (count($node->children) > 0) {
313

    
314
            // TODO support more than one level of children.
315
            // @see http://dev.e-taxonomy.eu/trac/ticket/2393/
316
            $text = '';
317
            foreach ($node->children as $child) {
318
             if (is_array($child->descriptionElements)) {
319
               foreach ($child->descriptionElements as $element) {
320

    
321
                 if (is_array($element->media)) {
322
                   // Append media of subordinate elements to the list of
323
                   // main features.
324
                   $media_list = array_merge($media_list, $element->media);
325
                 }
326

    
327
                 $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
328
                // TODO use localized version of feature name, the locale must
329
                // match the locale of the multilanguage text
330
                // (http://dev.e-taxonomy.eu/trac/ticket/2394).
331
                 $description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
332
               }
333
               $text .= " " . $description;
334
               $description = '';
335
             }
336
            }
337
            $block->content .= $text;
338
          }
339
        }
340

    
341
        /*
342
        Media/ALL FEATURES.
343
        */
344
        $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
345

    
346
        $gallery = theme('cdm_media_gallerie', array(
347
           'mediaList' => $media_list,
348
           'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
349
           'maxExtend' => isset($gallery_settings['cdm_dataportal_media_maxextend']) ? $gallery_settings['cdm_dataportal_media_maxextend'] : NULL ,
350
           'cols' => isset($gallery_settings['cdm_dataportal_media_cols']) ? $gallery_settings['cdm_dataportal_media_cols'] : NULL ,
351
           'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? $gallery_settings['cdm_dataportal_media_maxRows'] : NULL ,
352
           'captionElements' => isset($captionElements) ? $captionElements : NULL ,
353
           )
354
        );
355

    
356
        $block->content .= $gallery;
357
        $block->content .= theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid));
358
        $block->content .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid));
359

    
360
        // Add anchor to subject.
361
        $block->subject = '<a name="' . $block->delta . '"></a>' . $block->subject;
362

    
363
        $block->region = FALSE;
364
        $out .= theme('block', array('elements' => array(
365
          '#block' => $block,
366
          '#children' => $block->content,
367
        )));
368
      }
369
    }
370
  }
371
  // Calling the theme function for Bibliography to add it to the output.
372
  // Add the display of the number of taxa in the selected genus.
373
  $out .= theme('cdm_block_Uses', array('taxonUuid' => $taxon->uuid));
374

    
375
  $show_bibliography = variable_get('cdm_show_bibliography', 1);
376
  if ($show_bibliography && $countFeatures != 0) {
377
    $out .= theme('cdm_descriptionElementBibliography', array('descriptionElementsBibliography' => $bibliographyOut));
378
  }
379

    
380
  RenderHints::popFromRenderStack();
381
  return $out;
382
}
383

    
384
/**
385
 * @todo Please document this function.
386
 * @see http://drupal.org/node/1354
387
 */
388
function palmweb_2_cdm_search_results($variables){
389
  $pager = $variables['pager'];
390
  $path = $variables['path'];
391
  $query_parameters = $variables['query_parameters'];
392
  $out = '';
393

    
394
  $showThumbnails = isset($_SESSION['pageoption']['searchtaxa']['showThumbnails']) ? $_SESSION['pageoption']['searchtaxa']['showThumbnails'] : 0;
395
  if (!is_numeric($showThumbnails)) {
396
    // AT RBG KEW - 14/11/2011 - Set the show thumbnails to 0 by default.
397
    $showThumbnails = 0;
398
  }
399
  $setSessionUri = url('cdm_api/setvalue/session', array('query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => '')));
400
  drupal_add_js('jQuery(document).ready(function() {
401

    
402
        // Init.
403
        if(' . $showThumbnails . ' == 1){
404
              jQuery(\'.media_gallery\').show(20);
405
        } else {
406
          jQuery(\'.media_gallery\').hide(20);
407
        }
408
        // Add change hander.
409
        jQuery(\'#showThumbnails\').change(
410
          function(event){
411
            var state = 0;
412
            if(jQuery(this).is(\':checked\')){
413
              jQuery(\'.media_gallery\').show(20);
414
              state = 1;
415
            } else {
416
              jQuery(\'.media_gallery\').hide(20);
417
            }
418
            // Store state in session variable.
419
            var uri = \'' . $setSessionUri . '\' + state;
420
            jQuery.get(uri);
421
          });
422
        });', "inline");
423

    
424
  drupal_set_title(t('Search results'));
425

    
426
  // AT RBG KEW - 14/11/2011 - Changed the wording of the Show Thumbnails
427
  // tickbox text.
428
  $out .= '<div class="page_options">';
429
  $out .= '<form name="pageoptions">';
430
  $out .= '<input id="showThumbnails" type="checkbox" name="showThumbnails" ';
431
  $out .= $showThumbnails == 1 ? 'checked="checked"' : '';
432
  $out .= '> ' . t('Show Image Thumbnails') . '</form></div>';
433
  if (!empty($pager) && count($pager->records) > 0) {
434
      $out .= '<div id="search_results">';
435
    $out .= theme('cdm_list_of_taxa', array('records' => $pager->records));
436
    $out .= '</div>';
437
    $out .= theme('cdm_pager', array(
438
      'pager' => $pager,
439
      'path' => $path,
440
      'parameters' => $query_parameters,
441
    ));
442
  }
443
  else {
444
    $out = '<h4 class="error">Sorry, no matching entries found.</h4>';
445
  }
446
  return $out;
447
}
448

    
449
/*
450
Comment @WA: theme function moved to cdm_dataportal module,
451
theme/cdm_dataportal.bibliography.theme so this can be used by other portals
452
as well.
453
@TODO: should this not be part of the palmweb_2 featuretree and be treated
454
as a normal description feature?
455
function theme_cdm_descriptionElementBibliography
456
function formatReference_for_Bibliography($references) {
457
 */
458

    
459
/**
460
 * @todo Please document this function.
461
 */
462
function palmweb_2_cdm_media_caption($variables){
463
  $media = $variables['media'];
464
  $elements = $variables['elements'];
465
  $fileUri = $variables['fileUri'];
466

    
467
  $media_metadata = cdm_read_media_metadata($media);
468

    
469
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
470
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
471
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
472
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
473
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
474

    
475
  $descriptionPrefix = "";
476

    
477
  $out = '<dl class="media-caption">';
478
  // Title.
479
  if ($doTitle) {
480
    if ($media_metadata['title']) {
481
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
482
      $descriptionPrefix = "- ";
483
    }
484
    elseif (!($doDescription && $media_metadata['description'])) {
485
      // Use filename as fallbackoption if no description will be shown.
486
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
487
      $descriptionPrefix = "- ";
488
    }
489
  }
490
  // Description.
491
  if ($media_metadata['description'] && $doDescription) {
492
    $out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
493
  }
494
  // Artist.
495
  if ($media_metadata['artist'] && $doArtist) {
496
    $out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . str_replace("'","", $media_metadata['artist']) . '</dd>';
497
  }
498
  // Location.
499
  if ($doLocation) {
500
    $location = '';
501
    $location .= $media_metadata['location']['sublocation'];
502
    if ($location && $media_metadata['location']['city']) {
503
      $location .= ', ';
504
    }
505
    $location .= $media_metadata['location']['city'];
506
    if ($location && $media_metadata['location']['province']) {
507
      $location .= ', ';
508
    }
509
    $location .= $media_metadata['location']['province'];
510
    if ($location && $media_metadata['location']['country']) {
511
      $location .= ' (' . $media_metadata['location']['country'] . ')';
512
    }
513
    else {
514
      $location .= $media_metadata['location']['country'];
515
    }
516
    if ($location) {
517
      $out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location  . '</dd>';
518
    }
519
  }
520
  // Rights.
521
  if ($doRights) {
522
    $rights = '';
523
    // Copyrights.
524
    $cnt = count($media_metadata['rights']['copyright']['agentNames']);
525
    if ($cnt > 0) {
526
      $rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
527
      for ($i = 0; $i < $cnt; $i++) {
528
        $rights .= str_replace("'","", $media_metadata['rights']['copyright']['agentNames'][$i]);
529
        if ($i + 1 < $cnt) {
530
          $rights .= ' / ';
531
        }
532
      }
533
      $rights .= '</dd>';
534
    }
535
    // License.
536
    $cnt = count($media_metadata['rights']['license']['agentNames']);
537
    if ($cnt > 0) {
538
      $rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
539
      for ($i = 0; $i < $cnt; $i++) {
540
        $rights .= $media_metadata['rights']['license']['agentNames'][$i];
541
        if ($i + 1 < $cnt) {
542
          $rights .= ' / ';
543
        }
544
      }
545
      $rights .= '</dd>';
546
    }
547
    if ($rights) {
548
      $out .= $rights . '</dt>';
549
    }
550
  }
551
  // TODO add all other metadata elemenst generically.
552
  $out .= '</dl>';
553
  // Return value.
554
  return $out;
555
}
556

    
557
/**
558
 * @todo document this function.
559
 */
560
function palmweb_2_cdm_reference($variables) {
561
  $reference = $variables['reference'];
562
  $microReference = $variables['microReference'];
563
  $doLink = $variables['doLink'];
564
  $referenceStyle = $variables['referenceStyle'];
565

    
566
  $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
567

    
568
  $year = '';
569
  if (isset($reference->datePublished->start)) {
570
    $year = partialToYear($reference->datePublished->start);
571
  }
572
  $citation = _short_form_of_author_team ($author_team->titleCache) . (!empty($year) ? '. ' . $year : '');
573
  $citation = str_replace('..', '.', $citation);
574

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

    
592
  return $out;
593
}
594

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

    
613
  if (isset($class)) {
614
    print ' class="' . $class . '"';
615
  }
616
}
617

    
618
/**
619
 * Allow themeable wrapping of all comments.
620
 */
621
function phptemplate_comment_wrapper($content, $type = NULL) {
622
  static $node_type;
623
  if (isset($type)) {
624
    $node_type = $type;
625
  }
626

    
627
  if (!$content || $node_type == 'forum') {
628
    return '<div id="comments">' . $content . '</div>';
629
  }
630
  else {
631
    return '<div id="comments"><h2 class="comments">' . t('Comments') . '</h2>' . $content . '</div>';
632
  }
633
}
634

    
635
/**
636
 * Override or insert PHPTemplate variables into the templates.
637
 */
638
function _phptemplate_variables($hook, $vars) {
639
  if ($hook == 'page') {
640

    
641
    if ($secondary = menu_secondary_local_tasks()) {
642
      $output = '<span class="clear"></span>';
643
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
644
      $vars['tabs2'] = $output;
645
    }
646

    
647
    // Hook into color.module
648
    if (module_exists('color')) {
649
      _color_page_alter($vars);
650
    }
651
    return $vars;
652
  }
653
  return array();
654
}
655

    
656
/**
657
 * Returns the rendered local tasks. The default implementation renders
658
 * them as tabs.
659
 *
660
 * @ingroup themeable
661
 */
662
function phptemplate_menu_local_tasks() {
663
  $output = '';
664

    
665
  if ($primary = menu_primary_local_tasks()) {
666
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
667
  }
668

    
669
  return $output;
670
}
671

    
672
/**
673
 * @todo Please document this function.
674
 * @see http://drupal.org/node/1354
675
 */
676
function palmweb_2_get_partDefinition($variables) {
677

    
678
  if ($variables['nameType'] == 'BotanicalName') {
679
    return array(
680
      'namePart' => array('name' => TRUE, 'authors' => TRUE),
681
      'authorshipPart' => array(),
682
      'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
683
      'statusPart' => array('status' => TRUE),
684
      'descriptionPart' => array('description' => TRUE),
685
    );
686
  }
687
  return FALSE;
688
}
689

    
690
/**
691
 * @todo Please document this function.
692
 * @see http://drupal.org/node/1354
693
 */
694
function palmweb_2_get_nameRenderTemplate($variables){
695
$template = '';
696

    
697
  switch ($variables['renderPath']) {
698
      case 'acceptedFor':
699
        $template = array(
700
          'namePart' => array('#uri'=>TRUE),
701
        );
702
        break;
703
      case 'typedesignations':
704
        $template = array(
705
          'namePart' => array('#uri'=>TRUE),
706
          'referencePart' => TRUE,
707
        );
708
      case 'taxon_page_title':
709
      case 'list_of_taxa':
710
      case 'taxon_page_synonymy':
711
      case 'related_taxon':
712
      case 'polytomousKey':
713
      case '#DEFAULT':
714
        $template = array(
715
          'namePart' => array('#uri'=>TRUE),
716
          'referencePart' => TRUE,
717
          'descriptionPart' => TRUE,
718
          'statusPart' => TRUE,
719
        );
720
  }
721
  return $template;
722
}
723

    
724
/**
725
 * @todo Please document this function.
726
 * @see http://drupal.org/node/1354
727
 */
728
function palmweb_2_cdm_feature_name($variables){
729
  $feature_name = $variables['feature_name'];
730
  switch ($feature_name) {
731
    case "Protologue": return t("Original Publication");
732
    default: return t(ucfirst($feature_name));
733
  }
734
}
735

    
736
/**
737
 * @todo Please document this function.
738
 * @see http://drupal.org/node/1354
739
 */
740
function palmweb_2_cdm_taxon_page_title($variables){
741
  $taxon = $variables['taxon'];
742
  $uuid = $variables['uuid'];
743
  $synonym_uuid = $variables['synonym_uuid'];
744

    
745
  RenderHints::pushToRenderStack('taxon_page_title');
746
  $synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $synonym_uuid);
747
  $referenceUri = '';
748
  if (isset($taxon->name->nomenclaturalReference)) {
749
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
750
  }
751

    
752
  $out = theme('cdm_taxonName', array(
753
    'taxonName' => $taxon->name,
754
    'nameLink' => NULL,
755
    'refenceLink' => $referenceUri,
756
    'show_annotations' => FALSE,
757
  ));
758

    
759
  RenderHints::popFromRenderStack();
760
  if (isset($synonym->name->titleCache)) {
761
  $result = '<span class = "synonym_title">' . $synonym->name->titleCache . ' is synonym of ' . '</span>' .
762
       '<span class="' . $taxon->class . '">' . $out . '</span>';
763
  }
764
  else {
765
    $result = '<span class="' . $taxon->class . '">' . $out . '</span>';
766
  }
767
  return $result;
768

    
769
}
770

    
771
// Comment @WA this theme function does not exist..
772
/*
773
function palmweb_2_cdm_uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = NULL) {
774
  $acceptedPath = path_to_taxon($acceptedUuid, TRUE);
775
  return url($acceptedPath . ($pagePart ? '/'.$pagePart : '') . '/'.$synonymUuid, 'highlite='.$synonymUuid);
776
  //return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid, $synonymUuid."/$synonymUuid");
777
  //return url("$acceptedPath/$synonymUuid".($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid);
778
}
779
*/
780

    
781
/**
782
 * Implements hook_preprocess_HOOK() for theme_page().
783
 *
784
 * Assign the css classes primary-links and secondary-links to the menus and
785
 * process the 'Login' menu item, to change into 'My account' after login and
786
 * change the tab title for the IMCE file browser.
787
 *
788
 * @author W.Addink <w.addink@eti.uva.nl>
789
 */
790
function palmweb_2_preprocess_page(&$vars) {
791

    
792
  if (isset($vars['main_menu'])) {
793
    // For the Palmae theme we want to change the menu item 'Login' into
794
    // 'My account' if a user is logged in.
795
    global $user;
796
    foreach ($vars['main_menu'] as $key => $value) {
797
        if ($value['href'] == 'user' && !empty($user->name)) {
798
            $vars['main_menu'][$key]['title'] = t('My account');
799
            $vars['main_menu'][$key]['href'] = 'user/' . $user->uid;
800
        }
801
    }
802
    // Theme the main menu with the desired css classes.
803
    $vars['primary_nav'] = theme('links__system_main_menu', array(
804
      'links' => $vars['main_menu'],
805
      'attributes' => array(
806
        'class' => array('links', 'inline', 'main-menu', 'primary-links'),
807
      ),
808
      'heading' => array(
809
        'text' => t('Main menu'),
810
        'level' => 'h2',
811
        'class' => array('element-invisible'),
812
      )));
813
  }
814
  else {
815
    $vars['primary_nav'] = FALSE;
816
  }
817
  if (isset($vars['secondary_menu'])) {
818
    $vars['secondary_nav'] = theme('links__system_secondary_menu', array(
819
      'links' => $vars['secondary_menu'],
820
      'attributes' => array(
821
        'class' => array('links', 'inline', 'secondary-menu', 'secondary-links'),
822
      ),
823
      'heading' => array(
824
        'text' => t('Secondary menu'),
825
        'level' => 'h2',
826
        'class' => array('element-invisible'),
827
      )));
828
  }
829
  else {
830
    $vars['secondary_nav'] = FALSE;
831
  }
832

    
833
  // Change IMCE tab to 'Personal Files'.
834
  if (!empty($vars['tabs']['#primary'])) {
835
    foreach ($vars['tabs']['#primary'] as $key => $value) {
836
      if ($value['#link']['path'] == 'user/%/imce') {
837
        $vars['tabs']['#primary'][$key]['#link']['title'] = t('Personal Files');
838
      }
839
    }
840
  }
841

    
842

    
843
  /* Display node title as page title for the comment form.
844
  * Comment @WA: it would probably be better to select $uuid from node_cdm
845
  * table and link to cdm_dataportal/taxon/%uuid instead.
846
  */
847
  if (arg(0) == 'comment' && arg(1) == 'reply') {
848
      $node = $vars['page']['content']['system_main']['comment_node']['#node'];
849
      $vars['title'] = l(check_plain($node->title),'node/' . $node->nid);
850
  }
851
}
852

    
853
/**
854
 * Implements hook_preprocess_HOOK() for theme_node().
855
 *
856
 * Fixes file urls in nodes. In nodes, relative urls are used to include files
857
 * like <img src="/files/..
858
 *
859
 * Portals can be installed in configurations with
860
 * sub-directories however, in which case these urls need to be adjusted.
861
 * Examples: mysite.org, mysite.org/myportal, mysite.org/portals/myportal.
862
 *
863
 * Therefore preprocess nodes and replace these urls with a the appropriate url
864
 * for the current setup.
865
 *
866
 * @author W.Addink <w.addink@eti.uva.nl>
867
 */
868
function palmweb_2_preprocess_node(&$vars) {
869
  $body = '';
870
// Warning: use #markup value, for which filters like php, html etc are applied!
871
  if (isset($vars['content']['body'][0]['#markup'])) {
872
    $body = $vars['content']['body'][0]['#markup'];
873
  }
874
  else {
875
    $vars['fixed_body'] = '';
876
    return;
877
  }
878

    
879
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
880
  global $base_url;
881
  if ($base_url == '/') {
882
    drupal_set_message(t('
883
      The $base_url in this portal could not be set, please set the $base_url
884
      manually your Drupal settings.php file.', 'error'
885
    ));
886
  }
887
  $fixed_file_path = $base_url . $file_path;
888

    
889
  $preg_file_path = preg_quote($file_path, '/');
890
  $body = preg_replace ('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path , $body);
891
  $body = preg_replace ('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path , $body);
892
  $body = preg_replace ('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path , $body);
893
  $body = preg_replace ('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path , $body);
894

    
895
  $vars['fixed_body'] = $body;
896
}
897

    
898
/**
899
 * Implements hook_form_FORM_ID_alter() for comment_form().
900
 *
901
 * Alter the comment form to make it look like a D5 style comment form.
902
 *
903
 * @author W.Addink <w.addink@eti.uva.nl>
904
 */
905
function palmweb_2_form_comment_form_alter(&$form, &$form_state) {
906

    
907
  if (!isset($form['comment_preview'])) {
908
    $form['header'] = array(
909
      '#markup' => '<h2>' . t('Reply') . '</h2>',
910
      '#weight' => -2,
911
    );
912
  }
913
  $form['subject']['#title'] = $form['subject']['#title'] . ':';
914
  $form['comment_body']['und'][0]['#title'] = $form['comment_body']['und'][0]['#title'] . ':';
915
  if (isset($form['author']['_author']['#title'])) {
916
    $form['author']['_author']['#title'] = $form['author']['_author']['#title'] . ':';
917
  }
918
  $form['actions']['submit']['#value'] = t('Post comment');
919
  $form['actions']['submit']['#weight'] = 1000;
920
  $form['actions']['preview']['#value'] = t('Preview comment');
921
}
922

    
923
/**
924
 * Implements hook_preprocess_HOOK() for theme_comment().
925
 *
926
 * Alter the comment display to make it look like a D5 style comment.
927
 *
928
 * @author W.Addink <w.addink@eti.uva.nl>
929
 */
930
function palmweb_2_preprocess_comment(&$variables) {
931
  $comment = $variables['elements']['#comment'];
932
  if (isset($comment->subject)) {
933
    // Print title without link.
934
    $variables['title'] = $comment->subject;
935
    if ($variables['status'] == 'comment-preview') {
936
      // Add 'new' to preview.
937
      $variables['new'] = t('new');
938
    }
939
  }
940
}
(11-11/11)