Project

General

Profile

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

    
7
/**
8
 * @todo Please document this function.
9
 * @see http://drupal.org/node/1354
10
 */
11
function garland_cichorieae_cdm_descriptionElementTextData($variables) {
12
  $element = $variables['element'];
13
  $asListElement = $variables['asListElement'];
14
  $feature_uuid = $variables['feature_uuid'];
15

    
16
  $description = '';
17
  if (isset($element->multilanguageText_L10n->text)) {
18
    $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
19
  }
20
  $sourceRefs = '';
21
  $do_links = TRUE;
22
  $default_theme = variable_get('theme_default', 'garland_cichorieae');
23

    
24
  if (($default_theme == 'flora_malesiana' || $default_theme == 'flore_afrique_centrale' || $default_theme == 'flore_gabon') && $element->feature->titleCache == 'Citation') {
25
    $asListElement = TRUE;
26
  }
27
  elseif ($element->feature->uuid == UUID_CHROMOSOMES_NUMBERS) {
28
    $asListElement = TRUE;
29
  }
30
  else {
31
    $asListElement = FALSE;
32
  }
33

    
34
  // Printing annotations footnotes.
35
  $annotation_fkeys = theme('cdm_annotations_as_footnotekeys', array(
36
    'cdmBase_list' => $element,
37
    'footnote_list_key' => $feature_uuid,
38
  ));
39

    
40
  if ($feature_uuid == UUID_NAME_USAGE || $feature_uuid == UUID_CHROMOSOMES) {
41
    $do_links = FALSE;
42
  }
43

    
44
  if (is_array($element->sources)) {
45
    foreach ($element->sources as $source) {
46
      // Initialize some variables.
47
      if ($feature_uuid == UUID_NAME_USAGE) {
48
        $referenceCitation = cdm_ws_get(
49
          CDM_WS_NOMENCLATURAL_REFERENCE_CITATION,
50
          array($source->citation->uuid),
51
          "microReference=" . urlencode($source->citationMicroReference
52
        ));
53
        $referenceCitation = $referenceCitation->String;
54
      }
55
      else {
56
        $referenceCitation = theme('cdm_OriginalSource', array(
57
          'source' => $source,
58
          'doLink' => $do_links,
59
        ));
60
      }
61
      if ($description && strlen($description) > 0 && $referenceCitation) {
62
        $sourceRefs .= ' (' . $referenceCitation . ')';
63
      }
64
      elseif ($referenceCitation) {
65
        $sourceRefs = $referenceCitation;
66
      }
67
      // Generate the output.
68
      if (strlen($sourceRefs) > 0) {
69
        $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
70
      }
71
      $name_used_in_source_link_to_show = '';
72
      if (isset($source->nameUsedInSource->uuid) && ($feature_uuid != UUID_NAME_USAGE)) {
73
        // Do a link to name page.
74
        $name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache, path_to_name($source->nameUsedInSource->uuid), array(), NULL, NULL, FALSE, TRUE);
75
      }
76
      elseif (isset($source->nameUsedInSource->uuid) && ($feature_uuid == UUID_NAME_USAGE)) {
77
        // Do not do link for NAME USAGE feature.
78
        $name_used_in_source_link_to_show = $source->nameUsedInSource->titleCache;
79
      }
80
      elseif (isset($source->nameUsedInSource->originalNameString) && strlen($source->nameUsedInSource->originalNameString) > 0) {
81
        // Show a text without link.
82
        $name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
83
      }
84

    
85
      if ($asListElement && ($feature_uuid == UUID_NAME_USAGE)) {
86
        $out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
87
        // Adding ":" if necesary.
88
        if (!empty($name_used_in_source_link_to_show) && (!empty($description) || !empty($sourceRefs))) {
89
          $out .= ': ';
90
        }
91

    
92
        $out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', array(
93
          'cdmBase_list' => $element,
94
          'footnote_list_key' => $feature_uuid,
95
        )) . $annotation_fkeys . '</li>';
96
      }
97
      elseif ($asListElement) {
98

    
99
        $out = '<li class="descriptionText DescriptionElement">';
100
        // Adding ":" if necessary.
101
        if (!empty($name_used_in_source_link_to_show)) {
102
          if ( (!empty($description)|| !empty($sourceRefs)) && $feature_uuid != UUID_CHROMOSOMES_NUMBERS) {
103
            $out .= $name_used_in_source_link_to_show . ': ';
104
          } else {
105
            $out .= $name_used_in_source_link_to_show . ' ';
106
          }
107
        }
108

    
109
        $out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', array(
110
          'cdmBase_list' => $element,
111
          'footnote_list_key' => $feature_uuid,
112
        )) . $annotation_fkeys . '</li>';
113
        // Special handling for flora malesiana.
114
        // TODO: possible better way to implement this case?
115
      }
116
      else {
117
        if (isset($name_used_in_source_link_to_show)) {
118
          $name_used_in_source_link_to_show = ' (name in source: ' . $name_used_in_source_link_to_show . ')';
119
        }
120
        if (!isset($description)) {
121
          $description = '';
122
        }
123
        if (!isset($sourceRefs)) {
124
            $sourceRefs = '';
125
        }
126
        if (!isset($name_used_in_source_link_to_show)) {
127
            $name_used_in_source_link_to_show = '';
128
        }
129
        if (!isset($annotation_fkeys)) {
130
            $annotation_fkeys = '';
131
        }
132
        $out = '<span class="' . html_class_attribute_ref($element) . '"> ' . $description . $sourceRefs . $name_used_in_source_link_to_show . $annotation_fkeys . '</span>';
133
      }
134
    }
135
  }
136

    
137
  // If no sources, print the description.
138
  if (!isset($out)) {
139
    $out = '<span class="' . html_class_attribute_ref($element) . '"> ' . $description . $annotation_fkeys . '</span>';
140
  }
141

    
142
  /* Dead code:
143
   *
144
   * Disabled code; can this be removed?
145
  if ($feature_uuid == UUID_NAME_USAGE){ foreach($element->sources as
146
  $source){ $referenceCitation =
147
  cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION,
148
  array($source->citation->uuid),
149
  "microReference=".urlencode($source->citationMicroReference));
150
  $referenceCitation = $referenceCitation->String; if($description &&
151
  strlen($description) > 0 && $referenceCitation ){ $sourceRefs .= '
152
  ('.$referenceCitation.')' ; }else if ($referenceCitation){ $sourceRefs =
153
  $referenceCitation; } } }else{ foreach($element->sources as $source){
154
  $referenceCitation = theme('cdm_OriginalSource', $source,
155
  ($feature_uuid == UUID_NAME_USAGE) ? FALSE : TRUE); if($description &&
156
  strlen($description) > 0 && $referenceCitation ){ $sourceRefs .= '
157
  ('.$referenceCitation.')' ; }else if ($referenceCitation){ $sourceRefs =
158
  $referenceCitation; } } } if(strlen($sourceRefs) > 0){ $sourceRefs = '<span
159
  class="sources">' . $sourceRefs . '</span>'; } if
160
  ($source->nameUsedInSource->uuid && ($feature_uuid != UUID_NAME_USAGE)){
161
  //do a link to name page $name_used_in_source_link_to_show =
162
  l($source->nameUsedInSource->titleCache,
163
  path_to_name($source->nameUsedInSource->uuid), array(), NULL, NULL, FALSE
164
  ,TRUE); }else if ($source->nameUsedInSource->uuid && ($feature_uuid ==
165
  UUID_NAME_USAGE)){ //do not do link for NAME USAGE feature
166
  $name_used_in_source_link_to_show = $source->nameUsedInSource->titleCache;
167
  }else if (strlen($source->nameUsedInSource->originalNameString) > 0){
168
  //show a text without link $name_used_in_source_link_to_show =
169
  $source->nameUsedInSource->originalNameString; } if($asListElement &&
170
  ($feature_uuid == UUID_NAME_USAGE)){ $out = '<li class="descriptionText">'
171
  . $name_used_in_source_link_to_show; //adding ":" if necesary if
172
  ($name_used_in_source_link_to_show && ($description || $sourceRefs)){ $out
173
  .= ': '; } $out .= $description . $sourceRefs .
174
  theme('cdm_annotations_as_footnotekeys', $element) . '</li>'; }else if
175
  ($asListElement){ $out = '<li class="descriptionText">' .
176
  $name_used_in_source_link_to_show; //adding ":" if necesary if
177
  ($name_used_in_source_link_to_show && ($description || $sourceRefs)){ $out
178
  .= ': '; } $out .= $description . $sourceRefs .
179
  theme('cdm_annotations_as_footnotekeys', $element) . '</li>'; //special
180
  handling for flora malesiana TODO: possible better way to implement this
181
  case? }else{ if ($name_used_in_source_link_to_show){
182
  $name_used_in_source_link_to_show = ' (name in source: '.
183
  $name_used_in_source_link_to_show . ')'; } $out = $description .
184
  $sourceRefs . $name_used_in_source_link_to_show; $out .=
185
  theme('cdm_annotations_as_footnotekeys', $element); }
186
  */
187
  // Add annotations as footnote key.
188
  // $out .= theme('cdm_annotations_as_footnotekeys', $element); move above.
189
  return $out;
190
}
191

    
192
// NO LONGER NEEDED - since term representation is changed now in the cdm for
193
// the cichorieae
194
// ====> delete
195
// /**
196
// * @overrides theme_cdm_taggedtext2html in order to replace t.infr and
197
// t.infgen. with '[unranked]'
198
// */
199
// function garland_cichorieae_cdm_taggedtext2html(array &$taggedtxt, $tag =
200
// 'span', $glue = ' ', $skiptags = array()){
201
// $out = '';
202
// $i = 0;
203
// foreach($taggedtxt as $tt){
204
// if(!in_array($tt->type, $skiptags) && strlen($tt->text) > 0){
205
// $out .= (strlen($out) > 0 && ++$i < count($taggedtxt)? $glue : '').'<'.$tag.'
206
// class="'.$tt->type.'">';
207
// if($tt->type == "rank" && ($tt->text == "t.infr." || $tt->text ==
208
// "t.infgen.")){
209
// $out .= t('[unranked]');
210
// }else{
211
// $out .= t($tt->text);
212
// }
213
// $out .= '</'.$tag.'>';
214
// }
215
// }
216
// return $out;
217
// }
218
/**
219
 * Returns HTML for a cdm_feature_block_elements.
220
 *
221
 * @param array $variables
222
 *   An associative array containing:
223
 *   - elementArray: The array with CDM description elements being formatted.
224
 *   - feature: The description feature container object for the
225
 *     description element array.
226
 *   - glue: String for joining the description elements together.
227
 *   - sortArray: Boolean, TRUE if the array should be sorted before themeing.
228
 *   - enclosingHTML: HTML tag, e.g. 'div', in which to wrap the description.
229
 *
230
 * @ingroup themeable
231
 */
232
function garland_cichorieae_cdm_feature_block_elements($variables) {
233
  $elementArray = $variables['elementArray'];
234
  $feature = $variables['feature'];
235
  $glue = $variables['glue'];
236
  $sortArray = $variables['sortArray'];
237
  $enclosingHtml = $variables['enclosingHtml'];
238

    
239
  $enclosingHtml = 'div';
240
  $out = '<' . $enclosingHtml . ' class="feature-block-elements" id="' . $feature->representation_L10n . '">';
241

    
242
  if ($sortArray) {
243
    sort($elementArray);
244
  }
245

    
246
  $out .= '<span class="feature-block-element">' . join($elementArray, '<span class="feature-block-element">' . $glue . '</span>') . '</span>';
247

    
248
  $out .= '</' . $enclosingHtml . '>';
249
  return $out;
250
}
251

    
252
/*
253
  ***** GARLAND OVERRIDES *****
254
*/
255

    
256
/**
257
 * Sets the body-tag class attribute.
258
 *
259
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
260
 */
261
function phptemplate_body_class($sidebar_left, $sidebar_right) {
262
  if ($sidebar_left != '' && $sidebar_right != '') {
263
    $class = 'sidebars';
264
  }
265
  else {
266
    if ($sidebar_left != '') {
267
      $class = 'sidebar-left';
268
    }
269
    if ($sidebar_right != '') {
270
      $class = 'sidebar-right';
271
    }
272
  }
273

    
274
  if (isset($class)) {
275
    print ' class="' . $class . '"';
276
  }
277
}
278

    
279
/**
280
 * Allow themable wrapping of all comments.
281
 */
282
/*
283
function phptemplate_comment_wrapper($content, $type = NULL) {
284
  static $node_type;
285
  if (isset($type)) $node_type = $type;
286

    
287
  if (! $content || $node_type == 'forum') {
288
    return '<div id="comments">' . $content . '</div>';
289
  }
290
  else {
291
    return '<div id="comments"><h2 class="comments">' . t('Comments') . '</h2>' . $content . '</div>';
292
  }
293
}
294
*/
295

    
296
/**
297
 * Override or insert PHPTemplate variables into the templates.
298
 */
299
function _phptemplate_variables($hook, $vars) {
300
  if ($hook == 'page') {
301

    
302
    if ($secondary = menu_secondary_local_tasks()) {
303
      $output = '<span class="clear"></span>';
304
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
305
      $vars['tabs2'] = $output;
306
    }
307

    
308
    // Hook into color.module
309
    if (module_exists('color')) {
310
      _color_page_alter($vars);
311
    }
312
    return $vars;
313
  }
314
  return array();
315
}
316

    
317
/**
318
 * Returns HTML for the rendered local tasks.
319
 *
320
 * The default implementation renders them as tabs.
321
 *
322
 * @ingroup themeable
323
 */
324
function phptemplate_menu_local_tasks() {
325
  $output = '';
326

    
327
  if ($primary = menu_primary_local_tasks()) {
328
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
329
  }
330

    
331
  return $output;
332
}
333

    
334
/**
335
 * Returns HTML for taxon list thumbnails.
336
 *
337
 * Theme specific mods:
338
 * $captionElements = array('title', '#uri'=>t('open Image'));
339
 * $mediaLinkType:
340
 * "NORMAL": link to the image page or to the $alternativeMediaUri if it is
341
 * defined instead of
342
 * "LIGHTBOX": open the link in a light box,
343
 * TODO expose those in admin section, by adding 'em to gallery_settings see
344
 * http://dev.e-taxonomy.eu/trac/ticket/2494.
345
 *
346
 * @param array $variables
347
 *   An associative array containing:
348
 *   - taxon: The taxon object for which to theme the thumbnails.
349
 *
350
 * @ingroup themeable
351
 */
352
function garland_cichorieae_cdm_taxon_list_thumbnails($variables) {
353
  $out = '';
354
  $taxon = $variables['taxon'];
355

    
356
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
357

    
358
  $mediaLinkType = 'NORMAL';
359
  $showCaption = $gallery_settings['cdm_dataportal_show_thumbnail_captions'];
360
  $captionElements = array();
361
  if ($showCaption) {
362
    $captionElements = array('title', '#uri' => t('open Image'));
363
  }
364

    
365
  $gallery_name = $taxon->uuid;
366

    
367
  $galleryLinkUri = path_to_taxon($taxon->uuid, 'images');
368

    
369
  $mediaList = $mediaList = _load_media_for_taxon($taxon);
370

    
371
  $out .= theme('cdm_media_gallerie', array(
372
    'mediaList' => $mediaList,
373
    'galleryName' => $gallery_name,
374
    'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
375
    'cols' => $gallery_settings['cdm_dataportal_media_cols'],
376
    'maxRows' => $gallery_settings['cdm_dataportal_media_maxRows'],
377
    'captionElements' => $captionElements,
378
    'mediaLinkType' => $mediaLinkType,
379
    'alternativeMediaUri' => $galleryLinkUri,
380
    'showCaption' => NULL,
381
  ));
382

    
383
  return $out;
384
}
385

    
386
/**
387
 * @todo Please document this function.
388
 * @see http://drupal.org/node/1354
389
 */
390
function garland_cichorieae_cdm_feature_name($variables) {
391
  $feature_name = $variables['feature_name'];
392
  switch ($feature_name) {
393
    case "Protologue":
394
      return t("Original Publication");
395
    default:
396
      return ucfirst($feature_name);
397
  }
398
}
399

    
400
/*
401
======== Special functions for subtheme handling=============
402
*/
403

    
404
/**
405
 * @todo Please document this function.
406
 * @see http://drupal.org/node/1354
407
 */
408
function sub_theme() {
409
  global $user, $custom_theme;
410

    
411
  // Only select the user selected theme if it is available in the
412
  // list of enabled themes.
413
  $themes = list_themes();
414
  $theme = $user->theme && $themes[$user->theme]->status ? $user->theme : variable_get('theme_default', 'garland');
415

    
416
  // Allow modules to override the present theme... only select custom theme
417
  // if it is available in the list of installed themes.
418
  $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
419

    
420
  return $theme;
421
}
422

    
423
/**
424
 * Return the path to the currently selected sub theme.
425
 */
426
function path_to_sub_theme() {
427
  $themes = list_themes();
428
  $theme = sub_theme();
429
  return dirname($themes[$theme]->filename);
430
}
431

    
432
/**
433
 * Implements hook_preprocess_HOOK() for theme_page().
434
 *
435
 * Assign the css classes primary-links and secondary-links to the menus.
436
 * Modify primary-links if cdm_api module exists.
437
 */
438
function garland_cichorieae_preprocess_page(&$vars) {
439
  if (isset($vars['main_menu'])) {
440
    /*
441
    obsolete, see http://dev.e-taxonomy.eu/trac/ticket/2191
442
    if(module_exists('cdm_api')){ foreach($vars['main_menu'] as $key =>
443
    $menu_item){ // nb this makes each menu item you click opening a new
444
    browser window..
445
    $menu_item['attributes']['target']=generalizeString($menu_item['title']);
446
    $main_menu[] = $menu_item; }; }else{ $main_menu = $vars['main_menu'] ; };
447
    */
448
    $vars['primary_nav'] = theme('links__system_main_menu', array(
449
      'links' => $vars['main_menu'], 'attributes' => array(
450
        'class' => array(
451
          'links', 'inline', 'main-menu', 'primary-links',
452
        )),
453
        'heading' => array(
454
          'text' => t('Main menu'), 'level' => 'h2', 'class' => array(
455
            'element-invisible',
456
          ))));
457
  }
458
  else {
459
    $vars['primary_nav'] = FALSE;
460
  }
461
  if (isset($vars['secondary_menu'])) {
462
    $vars['secondary_nav'] = theme('links__system_secondary_menu', array(
463
      'links' => $vars['secondary_menu'], 'attributes' => array(
464
        'class' => array(
465
          'links',
466
          'inline',
467
          'secondary-menu',
468
          'secondary-links',
469
        )),
470
        'heading' => array(
471
          'text' => t('Secondary menu'),
472
          'level' => 'h2',
473
          'class' => array('element-invisible'),
474
        )));
475
  }
476
  else {
477
    $vars['secondary_nav'] = FALSE;
478
  }
479

    
480
  /*
481
  Display node title as page title for the comment form.
482
  Comment @WA: it would probably be better to select $uuid from node_cdm
483
  table and link to cdm_dataportal/taxon/%uuid instead.
484
  */
485
  if (arg(0) == 'comment' && arg(1) == 'reply') {
486
    $node = $vars['page']['content']['system_main']['comment_node']['#node'];
487
    $vars['title'] = l(check_plain($node->title), 'node/' . $node->nid);
488
  }
489
}
490

    
491
/**
492
 * Implements hook_preprocess_HOOK() for theme_node().
493
 *
494
 * Fixes file urls in nodes. In nodes, relative urls are used to include files
495
 * like <img src="/files/..
496
 *
497
 * Portals can be installed in configurations with
498
 * sub-directories however, in which case these urls need to be adjusted.
499
 * Examples: mysite.org, mysite.org/myportal, mysite.org/portals/myportal.
500
 *
501
 * Therefore preprocess nodes and replace these urls with a the appropriate url
502
 * for the current setup.
503
 *
504
 * @author W.Addink <w.addink@eti.uva.nl>
505
 */
506
function garland_cichorieae_preprocess_node(&$vars) {
507
  $body = '';
508
  // Warning: use #markup value, for which filters like php, html etc are applied!
509
  if (isset($vars['content']['body'][0]['#markup'])) {
510
    $body = $vars['content']['body'][0]['#markup'];
511
  }
512
  else {
513
    $vars['fixed_body'] = '';
514
    return;
515
  }
516

    
517
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
518
  global $base_url;
519
  if ($base_url == '/') {
520
    drupal_set_message(t('
521
      The $base_url in this portal could not be set, please set the $base_url
522
      manually your Drupal settings.php file.', 'error'
523
    ));
524
  }
525
  $fixed_file_path = $base_url . $file_path;
526
  $preg_file_path = preg_quote($file_path, '/');
527
  $body = preg_replace('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path, $body);
528
  $body = preg_replace('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path, $body);
529
  $body = preg_replace('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path, $body);
530
  $body = preg_replace('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path, $body);
531

    
532
  $vars['fixed_body'] = $body;
533
}
534

    
535
/**
536
 * Implements hook_form_FORM_ID_alter() for comment_form().
537
 *
538
 * Alter the comment form to make it look like a D5 style comment form.
539
 *
540
 * @author W.Addink <w.addink@eti.uva.nl>
541
 */
542
function garland_cichorieae_form_comment_form_alter(&$form, &$form_state) {
543

    
544
  if (!isset($form['comment_preview'])) {
545
    $form['header'] = array(
546
      '#markup' => '<h2>' . t('Reply') . '</h2>',
547
      '#weight' => -2,
548
    );
549
  }
550
  $form['subject']['#title'] = $form['subject']['#title'] . ':';
551
  $form['comment_body']['und'][0]['#title'] = $form['comment_body']['und'][0]['#title'] . ':';
552
  if (isset($form['author']['_author']['#title'])) {
553
    $form['author']['_author']['#title'] = $form['author']['_author']['#title'] . ':';
554
  }
555
  $form['actions']['submit']['#value'] = t('Post comment');
556
  $form['actions']['submit']['#weight'] = 1000;
557
  $form['actions']['preview']['#value'] = t('Preview comment');
558
}
559

    
560
/**
561
 * Implements hook_preprocess_HOOK() for theme_comment().
562
 *
563
 * Alter the comment display to make it look like a D5 style comment.
564
 *
565
 * @author W.Addink <w.addink@eti.uva.nl>
566
 */
567
function garland_cichorieae_preprocess_comment(&$variables) {
568
  $comment = $variables['elements']['#comment'];
569
  if (isset($comment->subject)) {
570
    // Print title without link.
571
    $variables['title'] = $comment->subject;
572
    if ($variables['status'] == 'comment-preview') {
573
      // Add 'new' to preview.
574
      $variables['new'] = t('new');
575
    }
576
  }
577
}
(12-12/13)