Project

General

Profile

Download (25.5 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
 * @todo Please document this function.
9
 * @see http://drupal.org/node/1354
10
 */
11
function palmweb_2_cdm_descriptionElementDistribution($variables) {
12
  $descriptionElements = $variables['descriptionElements'];
13
  $enclosingTag = $variables['enclosingTag'];
14

    
15
  $out = '';
16
  $separator = ', ';
17

    
18
  RenderHints::pushToRenderStack('descriptionElementDistribution');
19
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
20

    
21
  $itemCnt = 0;
22
  foreach ($descriptionElements as $descriptionElement) {
23
    /*
24
    $out .= ($descriptionElement->class);
25
    // Annotations as footnotes.
26
    $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
27
    // Source references as footnotes.
28
    $sourcesFootnoteKeyList = '';
29
    foreach($descriptionElement->sources as $source){
30
      $_fkey = FootnoteManager::addNewFootnote(UUID_DISTRIBUTION, theme('cdm_OriginalSource', $source, FALSE));
31
      $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, ($sourcesFootnoteKeyList ? $separator : ''));
32
    }
33
    if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
34
      $annotationFootnoteKeys .= $separator;
35
    }
36
    */
37
        $out .= '<' . $enclosingTag . ' class="DescriptionElement DescriptionElement-' . $descriptionElement->class . '">';
38
        // $out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList;
39
        $out .= $descriptionElement->area->representation_L10n;
40
        if (++$itemCnt < count($descriptionElements)) {
41
          $out .= $separator;
42
        }
43
        $out .= "</" . $enclosingTag . ">";
44
  }
45
  $taxonTrees = cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
46
  $reference = new stdClass();
47
  foreach ($taxonTrees as $taxonTree) {
48
    if ($taxonTree->uuid == variable_get('cdm_taxonomictree_uuid')) {
49
      if (isset($taxonTree->reference)) {
50
        $reference = $taxonTree->reference;
51
      }
52
      break;
53
    }
54
  }
55
  $referenceCitation = '';
56
  if (isset($reference->uuid)) {
57
    $referenceCitation .= '(<span class="reference">';
58
    $referenceCitation .= l(t('World Checklist of Monocotyledons'), path_to_reference($reference->uuid), array('attributes' => array('class' => array('reference'))));
59
    $referenceCitation .= '</span>)';
60
  }
61
  else {
62
    // Comment @WA Added for compatibility with D5, but I think it is better to
63
    // remove this to not show a link rather than the wrong one.
64
    $referenceCitation .= '(<span class="reference">';
65
    $referenceCitation .= l(t('World Checklist of Monocotyledons'), '', array('attributes' => array('class' => array('reference'))));
66
    $referenceCitation .= '</span>)';
67
  }
68

    
69
  $sourceRefs = '';
70
  if ($out && strlen($out) > 0) {
71
    $sourceRefs = ' ' . $referenceCitation;
72
  }
73

    
74
  if (strlen($sourceRefs) > 0) {
75
    $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
76
  }
77

    
78
  RenderHints::popFromRenderStack();
79
  return $out . $sourceRefs;
80

    
81
}
82

    
83
/**
84
 * @todo Please document this function.
85
 * @see http://drupal.org/node/1354
86
 */
87
function palmweb_2_cdm_feature_nodes($variables){
88
  $mergedFeatureNodes = $variables['mergedFeatureNodes'];
89
  $taxon = $variables['taxon'];
90

    
91
  $out = '';
92
  RenderHints::pushToRenderStack('feature_nodes');
93

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

    
110
  foreach ($mergedFeatureNodes as $node) {
111

    
112
    if (hasFeatureNodeDescriptionElements($node)) {
113

    
114
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
115
      $block = new stdClass();
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_atttibute_ref($node->feature) . '">' . theme('cdm_feature_name',  array('feature_name' => $featureRepresentation)) . '</span>';
129
        $block->module = "cdm_dataportal-feature";
130
        $block->content = '';
131

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

    
137
          if (variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
138
            $distributionTextDataList = array();
139
            $distributionElementsList = array();
140

    
141
            foreach ($node->descriptionElements as $descriptionElement) {
142
              if ($descriptionElement->class == "TextData") {
143
                $distributionTextDataList[] = $descriptionElement;
144
              }
145
              else {
146
                $distributionElementsList[] = $descriptionElement;
147
              }
148
            }
149
            if (count($distributionTextDataList) > 0) {
150
              $node->descriptionElements = $distributionElementsList;
151
              $block->content .= theme('cdm_descriptionElements', array(
152
                'descriptionElements' => $distributionTextDataList,
153
                'featureUuid' => $node->feature->uuid,
154
                'taxon_uuid' => $taxon->uuid,
155
              ));
156
            }
157
          }
158

    
159
          // Display cdm distribution map.
160
          // TODO this is a HACK to a proper generic implementation?
161
          $block->content .= theme('cdm_distribution_map', array('taxon' => $taxon));
162
          $block->content .= theme('cdm_descriptionElements', array(
163
            'descriptionElements' => $node->descriptionElements,
164
            'featureUuid' => $node->feature->uuid,
165
            'taxon_uuid' => $taxon->uuid,
166
          ));
167
        }
168

    
169
        /*
170
        Content/COMMON_NAME.
171
        */
172
        elseif ($node->feature->uuid == UUID_COMMON_NAME) {
173
          // TODO why is theme_cdm_descriptionElement_CommonTaxonName
174
          // not beeing used???
175
          $block->content .= theme('cdm_common_names', array('elements' => $node->descriptionElements));
176
        /*
177
        }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
178
          $block->content .= theme('cdm_image_sources', $node->descriptionElements);
179
        */
180
        }
181

    
182
        /*
183
        Content/ALL OTHER FEATURES.
184
        */
185
        elseif ($node->feature->uuid == UUID_USE_RECORD) {
186
          $block->content .= theme('cdm_block_Uses', $taxon->uuid);
187
          // $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid),
188
        }
189
        else {
190
          $block->content .= theme('cdm_descriptionElements', array(
191
            'descriptionElements' => $node->descriptionElements,
192
            'featureUuid' => $node->feature->uuid,
193
            'taxon_uuid' => $taxon->uuid,
194
          ));
195

    
196
          /*
197
          Content/ALL OTHER FEATURES/Subordinate Features
198
          subordinate features are printed inline in one floating text,
199
          it is expected that subordinate features only "contain" TextData
200
          elements.
201
          */
202
          // TODO move into own theme.
203
          if (count($node->children) > 0) {
204

    
205
            // TODO support more than one level of children.
206
            // @see http://dev.e-taxonomy.eu/trac/ticket/2393/
207
            $text = '';
208
            foreach ($node->children as $child) {
209
             if (is_array($child->descriptionElements)) {
210
               foreach ($child->descriptionElements as $element) {
211

    
212
                 if (is_array($element->media)) {
213
                   // Append media of subordinate elements to the list of
214
                   // main features.
215
                   $media_list = array_merge($media_list, $element->media);
216
                 }
217

    
218
                 $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
219
                // TODO use localized version of feature name, the locale must
220
                // match the locale of the multilanguage text
221
                // (http://dev.e-taxonomy.eu/trac/ticket/2394).
222
                 $description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
223
               }
224
               $text .= " " . $description;
225
               $description = '';
226
             }
227
            }
228
            $block->content .= $text;
229
          }
230
        }
231

    
232
        /*
233
        Media/ALL FEATURES.
234
        */
235
        $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
236

    
237
        $gallery = theme('cdm_media_gallerie', array(
238
           'mediaList' => $media_list,
239
           'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
240
           'maxExtend' => isset($gallery_settings['cdm_dataportal_media_maxextend']) ? $gallery_settings['cdm_dataportal_media_maxextend'] : NULL ,
241
           'cols' => isset($gallery_settings['cdm_dataportal_media_cols']) ? $gallery_settings['cdm_dataportal_media_cols'] : NULL ,
242
           'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? $gallery_settings['cdm_dataportal_media_maxRows'] : NULL ,
243
           'captionElements' => isset($captionElements) ? $captionElements : NULL ,
244
           )
245
        );
246

    
247
        $block->content .= $gallery;
248
        $block->content .= theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid));
249
        $block->content .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid));
250

    
251
        // Add anchor to subject.
252
        $block->subject = '<a name="' . $block->delta . '"></a>' . $block->subject;
253

    
254
        $block->region = FALSE;
255
        $out .= theme('block', array('elements' => array(
256
          '#block' => $block,
257
          '#children' => $block->content,
258
        )));
259
      }
260
    }
261
  }
262
  // Calling the theme function for Bibliography to add it to the output.
263
  // Add the display of the number of taxa in the selected genus.
264
  $out .= theme('cdm_block_Uses', array('taxonUuid' => $taxon->uuid));
265

    
266
  $show_bibliography = variable_get('cdm_show_bibliography', 1);
267
  if ($show_bibliography && $countFeatures != 0) {
268
    $out .= theme('cdm_descriptionElementBibliography', array('descriptionElementsBibliography' => $bibliographyOut));
269
  }
270

    
271
  RenderHints::popFromRenderStack();
272
  return $out;
273
}
274

    
275
/**
276
 * @todo Please document this function.
277
 * @see http://drupal.org/node/1354
278
 */
279
function palmweb_2_cdm_search_results($variables){
280
  $pager = $variables['pager'];
281
  $path = $variables['path'];
282
  $out = '';
283

    
284
  $showThumbnails = isset($_SESSION['pageoption']['searchtaxa']['showThumbnails']) ? $_SESSION['pageoption']['searchtaxa']['showThumbnails'] : 0;
285
  if (!is_numeric($showThumbnails)) {
286
    // AT RBG KEW - 14/11/2011 - Set the show thumbnails to 0 by default.
287
    $showThumbnails = 0;
288
  }
289
  $setSessionUri = url('cdm_api/setvalue/session', array('query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => '')));
290
  drupal_add_js('jQuery(document).ready(function() {
291

    
292
        // Init.
293
        if(' . $showThumbnails . ' == 1){
294
              jQuery(\'.media_gallery\').show(20);
295
        } else {
296
          jQuery(\'.media_gallery\').hide(20);
297
        }
298
        // Add change hander.
299
        jQuery(\'#showThumbnails\').change(
300
          function(event){
301
            var state = 0;
302
            if(jQuery(this).is(\':checked\')){
303
              jQuery(\'.media_gallery\').show(20);
304
              state = 1;
305
            } else {
306
              jQuery(\'.media_gallery\').hide(20);
307
            }
308
            // Store state in session variable.
309
            var uri = \'' . $setSessionUri . '\' + state;
310
            jQuery.get(uri);
311
          });
312
        });', "inline");
313

    
314
  drupal_set_title(t('Search results'));
315

    
316
  // AT RBG KEW - 14/11/2011 - Changed the wording of the Show Thumbnails
317
  // tickbox text.
318
  $out .= '<div class="page_options">';
319
  $out .= '<form name="pageoptions">';
320
  $out .= '<input id="showThumbnails" type="checkbox" name="showThumbnails" ';
321
  $out .= $showThumbnails == 1 ? 'checked="checked"' : '';
322
  $out .= '> ' . t('Show Image Thumbnails') . '</form></div>';
323
  if (!empty($pager) && count($pager->records) > 0) {
324
      $out .= '<div id="search_results">';
325
    $out .= theme('cdm_list_of_taxa', array('records' => $pager->records));
326
    $out .= '</div>';
327
    $out .= theme('cdm_pager', array(
328
      'pager' => $pager,
329
      'path' => $path,
330
      'parameters' => $_REQUEST,
331
    ));
332
  }
333
  else {
334
    $out = '<h4 class="error">Sorry, no matching entries found.</h4>';
335
  }
336
  return $out;
337
}
338

    
339
/*
340
Comment @WA: theme function moved to cdm_dataportal module,
341
theme/cdm_dataportal.bibliography.theme so this can be used by other portals
342
as well.
343
@TODO: should this not be part of the palmweb_2 featuretree and be treated
344
as a normal description feature?
345
function theme_cdm_descriptionElementBibliography
346
function formatReference_for_Bibliography($references) {
347
 */
348

    
349
/**
350
 * @todo Please document this function.
351
 */
352
function palmweb_2_cdm_media_caption($variables){
353
  $media = $variables['media'];
354
  $elements = $variables['elements'];
355
  $fileUri = $variables['fileUri'];
356

    
357
  $media_metadata = cdm_read_media_metadata($media);
358

    
359
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
360
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
361
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
362
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
363
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
364

    
365
  $descriptionPrefix = "";
366

    
367
  $out = '<dl class="media-caption">';
368
  // Title.
369
  if ($doTitle) {
370
    if ($media_metadata['title']) {
371
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
372
      $descriptionPrefix = "- ";
373
    }
374
    elseif (!($doDescription && $media_metadata['description'])) {
375
      // Use filename as fallbackoption if no description will be shown.
376
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
377
      $descriptionPrefix = "- ";
378
    }
379
  }
380
  // Description.
381
  if ($media_metadata['description'] && $doDescription) {
382
    $out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
383
  }
384
  // Artist.
385
  if ($media_metadata['artist'] && $doArtist) {
386
    $out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . str_replace("'","", $media_metadata['artist']) . '</dd>';
387
  }
388
  // Location.
389
  if ($doLocation) {
390
    $location = '';
391
    $location .= $media_metadata['location']['sublocation'];
392
    if ($location && $media_metadata['location']['city']) {
393
      $location .= ', ';
394
    }
395
    $location .= $media_metadata['location']['city'];
396
    if ($location && $media_metadata['location']['province']) {
397
      $location .= ', ';
398
    }
399
    $location .= $media_metadata['location']['province'];
400
    if ($location && $media_metadata['location']['country']) {
401
      $location .= ' (' . $media_metadata['location']['country'] . ')';
402
    }
403
    else {
404
      $location .= $media_metadata['location']['country'];
405
    }
406
    if ($location) {
407
      $out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location  . '</dd>';
408
    }
409
  }
410
  // Rights.
411
  if ($doRights) {
412
    $rights = '';
413
    // Copyrights.
414
    $cnt = count($media_metadata['rights']['copyright']['agentNames']);
415
    if ($cnt > 0) {
416
      $rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
417
      for ($i = 0; $i < $cnt; $i++) {
418
        $rights .= str_replace("'","", $media_metadata['rights']['copyright']['agentNames'][$i]);
419
        if ($i + 1 < $cnt) {
420
          $rights .= ' / ';
421
        }
422
      }
423
      $rights .= '</dd>';
424
    }
425
    // License.
426
    $cnt = count($media_metadata['rights']['license']['agentNames']);
427
    if ($cnt > 0) {
428
      $rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
429
      for ($i = 0; $i < $cnt; $i++) {
430
        $rights .= $media_metadata['rights']['license']['agentNames'][$i];
431
        if ($i + 1 < $cnt) {
432
          $rights .= ' / ';
433
        }
434
      }
435
      $rights .= '</dd>';
436
    }
437
    if ($rights) {
438
      $out .= $rights . '</dt>';
439
    }
440
  }
441
  // TODO add all other metadata elemenst generically.
442
  $out .= '</dl>';
443
  // Return value.
444
  return $out;
445
}
446

    
447
/**
448
 * @todo document this function.
449
 */
450
function palmweb_2_cdm_reference($variables) {
451
  $reference = $variables['reference'];
452
  $microReference = $variables['microReference'];
453
  $doLink = $variables['doLink'];
454
  $referenceStyle = $variables['referenceStyle'];
455

    
456
  $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
457

    
458
  $year = '';
459
  if (isset($reference->datePublished->start)) {
460
    $year = partialToYear($reference->datePublished->start);
461
  }
462
  $citation = _short_form_of_author_team ($author_team->titleCache) . (!empty($year) ? '. ' . $year : '');
463
  $citation = str_replace('..', '.', $citation);
464

    
465
  if ($doLink) {
466
    $out = '<span class="reference">';
467
    $out .= l($citation, path_to_reference($reference->uuid), array(
468
    'attributes' => array('class' => 'reference'),
469
    'absolute' => TRUE,
470
    'html' => TRUE,
471
    ));
472
    $out .= '</span>';
473
  }
474
  else {
475
    $out = '<span class="reference">' . $citation . '</span>';
476
  }
477
  // FIXME use microreference webservice instead.
478
  if (!empty($descriptionElementSource->citationMicroReference)) {
479
    $out .= ': ' . $descriptionElementSource->citationMicroReference;
480
  }
481

    
482
  return $out;
483
}
484

    
485
/**
486
 * Sets the body-tag class attribute.
487
 *
488
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
489
 */
490
function phptemplate_body_class($sidebar_left, $sidebar_right) {
491
  if ($sidebar_left != '' && $sidebar_right != '') {
492
    $class = 'sidebars';
493
  }
494
  else {
495
    if ($sidebar_left != '') {
496
      $class = 'sidebar-left';
497
    }
498
    if ($sidebar_right != '') {
499
      $class = 'sidebar-right';
500
    }
501
  }
502

    
503
  if (isset($class)) {
504
    print ' class="' . $class . '"';
505
  }
506
}
507

    
508
/**
509
 * Allow themeable wrapping of all comments.
510
 */
511
function phptemplate_comment_wrapper($content, $type = NULL) {
512
  static $node_type;
513
  if (isset($type)) {
514
    $node_type = $type;
515
  }
516

    
517
  if (!$content || $node_type == 'forum') {
518
    return '<div id="comments">' . $content . '</div>';
519
  }
520
  else {
521
    return '<div id="comments"><h2 class="comments">' . t('Comments') . '</h2>' . $content . '</div>';
522
  }
523
}
524

    
525
/**
526
 * Override or insert PHPTemplate variables into the templates.
527
 */
528
function _phptemplate_variables($hook, $vars) {
529
  if ($hook == 'page') {
530

    
531
    if ($secondary = menu_secondary_local_tasks()) {
532
      $output = '<span class="clear"></span>';
533
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
534
      $vars['tabs2'] = $output;
535
    }
536

    
537
    // Hook into color.module
538
    if (module_exists('color')) {
539
      _color_page_alter($vars);
540
    }
541
    return $vars;
542
  }
543
  return array();
544
}
545

    
546
/**
547
 * Returns the rendered local tasks. The default implementation renders
548
 * them as tabs.
549
 *
550
 * @ingroup themeable
551
 */
552
function phptemplate_menu_local_tasks() {
553
  $output = '';
554

    
555
  if ($primary = menu_primary_local_tasks()) {
556
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
557
  }
558

    
559
  return $output;
560
}
561

    
562
/**
563
 * @todo Please document this function.
564
 * @see http://drupal.org/node/1354
565
 */
566
function palmweb_2_cdm_feature_name($variables){
567
  $feature_name = $variables['feature_name'];
568
  switch ($feature_name) {
569
    case "Protologue": return t("Original Publication");
570
    default: return t(ucfirst($feature_name));
571
  }
572
}
573

    
574
/**
575
 * Implements hook_preprocess_HOOK() for theme_page().
576
 *
577
 * Assign the css classes primary-links and secondary-links to the menus and
578
 * process the 'Login' menu item, to change into 'My account' after login and
579
 * change the tab title for the IMCE file browser.
580
 *
581
 * @author W.Addink <w.addink@eti.uva.nl>
582
 */
583
function palmweb_2_preprocess_page(&$vars) {
584

    
585
  if (isset($vars['main_menu'])) {
586
    // For the Palmae theme we want to change the menu item 'Login' into
587
    // 'My account' if a user is logged in.
588
    global $user;
589
    foreach ($vars['main_menu'] as $key => $value) {
590
        if ($value['href'] == 'user' && !empty($user->name)) {
591
            $vars['main_menu'][$key]['title'] = t('My account');
592
            $vars['main_menu'][$key]['href'] = 'user/' . $user->uid;
593
        }
594
    }
595
    // Theme the main menu with the desired css classes.
596
    $vars['primary_nav'] = theme('links__system_main_menu', array(
597
      'links' => $vars['main_menu'],
598
      'attributes' => array(
599
        'class' => array('links', 'inline', 'main-menu', 'primary-links'),
600
      ),
601
      'heading' => array(
602
        'text' => t('Main menu'),
603
        'level' => 'h2',
604
        'class' => array('element-invisible'),
605
      )));
606
  }
607
  else {
608
    $vars['primary_nav'] = FALSE;
609
  }
610
  if (isset($vars['secondary_menu'])) {
611
    $vars['secondary_nav'] = theme('links__system_secondary_menu', array(
612
      'links' => $vars['secondary_menu'],
613
      'attributes' => array(
614
        'class' => array('links', 'inline', 'secondary-menu', 'secondary-links'),
615
      ),
616
      'heading' => array(
617
        'text' => t('Secondary menu'),
618
        'level' => 'h2',
619
        'class' => array('element-invisible'),
620
      )));
621
  }
622
  else {
623
    $vars['secondary_nav'] = FALSE;
624
  }
625

    
626
  // Change IMCE tab to 'Personal Files'.
627
  if (!empty($vars['tabs']['#primary'])) {
628
    foreach ($vars['tabs']['#primary'] as $key => $value) {
629
      if ($value['#link']['path'] == 'user/%/imce') {
630
        $vars['tabs']['#primary'][$key]['#link']['title'] = t('Personal Files');
631
      }
632
    }
633
  }
634

    
635

    
636
  /* Display node title as page title for the comment form.
637
  * Comment @WA: it would probably be better to select $uuid from node_cdm
638
  * table and link to cdm_dataportal/taxon/%uuid instead.
639
  */
640
  if (arg(0) == 'comment' && arg(1) == 'reply') {
641
      $node = $vars['page']['content']['system_main']['comment_node']['#node'];
642
      $vars['title'] = l(check_plain($node->title),'node/' . $node->nid);
643
  }
644
}
645

    
646
/**
647
 * Implements hook_preprocess_HOOK() for theme_node().
648
 *
649
 * Fixes file urls in nodes. In nodes, relative urls are used to include files
650
 * like <img src="/files/..
651
 *
652
 * Portals can be installed in configurations with
653
 * sub-directories however, in which case these urls need to be adjusted.
654
 * Examples: mysite.org, mysite.org/myportal, mysite.org/portals/myportal.
655
 *
656
 * Therefore preprocess nodes and replace these urls with a the appropriate url
657
 * for the current setup.
658
 *
659
 * @author W.Addink <w.addink@eti.uva.nl>
660
 */
661
function palmweb_2_preprocess_node(&$vars) {
662
  $body = '';
663
// Warning: use #markup value, for which filters like php, html etc are applied!
664
  if (isset($vars['content']['body'][0]['#markup'])) {
665
    $body = $vars['content']['body'][0]['#markup'];
666
  }
667
  else {
668
    $vars['fixed_body'] = '';
669
    return;
670
  }
671

    
672
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
673
  global $base_url;
674
  if ($base_url == '/') {
675
    drupal_set_message(t('
676
      The $base_url in this portal could not be set, please set the $base_url
677
      manually your Drupal settings.php file.', 'error'
678
    ));
679
  }
680
  $fixed_file_path = $base_url . $file_path;
681

    
682
  $preg_file_path = preg_quote($file_path, '/');
683
  $body = preg_replace ('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path , $body);
684
  $body = preg_replace ('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path , $body);
685
  $body = preg_replace ('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path , $body);
686
  $body = preg_replace ('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path , $body);
687

    
688
  $vars['fixed_body'] = $body;
689
}
690

    
691
/**
692
 * Implements hook_form_FORM_ID_alter() for comment_form().
693
 *
694
 * Alter the comment form to make it look like a D5 style comment form.
695
 *
696
 * @author W.Addink <w.addink@eti.uva.nl>
697
 */
698
function palmweb_2_form_comment_form_alter(&$form, &$form_state) {
699

    
700
  if (!isset($form['comment_preview'])) {
701
    $form['header'] = array(
702
      '#markup' => '<h2>' . t('Reply') . '</h2>',
703
      '#weight' => -2,
704
    );
705
  }
706
  $form['subject']['#title'] = $form['subject']['#title'] . ':';
707
  $form['comment_body']['und'][0]['#title'] = $form['comment_body']['und'][0]['#title'] . ':';
708
  if (isset($form['author']['_author']['#title'])) {
709
    $form['author']['_author']['#title'] = $form['author']['_author']['#title'] . ':';
710
  }
711
  $form['actions']['submit']['#value'] = t('Post comment');
712
  $form['actions']['submit']['#weight'] = 1000;
713
  $form['actions']['preview']['#value'] = t('Preview comment');
714
}
715

    
716
/**
717
 * Implements hook_preprocess_HOOK() for theme_comment().
718
 *
719
 * Alter the comment display to make it look like a D5 style comment.
720
 *
721
 * @author W.Addink <w.addink@eti.uva.nl>
722
 */
723
function palmweb_2_preprocess_comment(&$variables) {
724
  $comment = $variables['elements']['#comment'];
725
  if (isset($comment->subject)) {
726
    // Print title without link.
727
    $variables['title'] = $comment->subject;
728
    if ($variables['status'] == 'comment-preview') {
729
      // Add 'new' to preview.
730
      $variables['new'] = t('new');
731
    }
732
  }
733
}
(11-11/11)