Project

General

Profile

Download (17.3 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 xxx_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_fetch_all(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_search_results($variables){
81
  $pager = $variables['pager'];
82
  $path = $variables['path'];
83
  $out = '';
84

    
85
  $showThumbnails = isset($_SESSION['pageoption']['searchtaxa']['showThumbnails']) ? $_SESSION['pageoption']['searchtaxa']['showThumbnails'] : 0;
86
  if (!is_numeric($showThumbnails)) {
87
    // AT RBG KEW - 14/11/2011 - Set the show thumbnails to 0 by default.
88
    $showThumbnails = 0;
89
  }
90
  $setSessionUri = url('cdm_api/setvalue/session', array('query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => '')));
91
  drupal_add_js('jQuery(document).ready(function() {
92

    
93
        // Init.
94
        if(' . $showThumbnails . ' == 1){
95
              jQuery(\'.media_gallery\').show(20);
96
        } else {
97
          jQuery(\'.media_gallery\').hide(20);
98
        }
99
        // Add change hander.
100
        jQuery(\'#showThumbnails\').change(
101
          function(event){
102
            var state = 0;
103
            if(jQuery(this).is(\':checked\')){
104
              jQuery(\'.media_gallery\').show(20);
105
              state = 1;
106
            } else {
107
              jQuery(\'.media_gallery\').hide(20);
108
            }
109
            // Store state in session variable.
110
            var uri = \'' . $setSessionUri . '\' + state;
111
            jQuery.get(uri);
112
          });
113
        });', "inline");
114

    
115
  drupal_set_title(t('Search results'));
116

    
117
  // AT RBG KEW - 14/11/2011 - Changed the wording of the Show Thumbnails
118
  // tickbox text.
119
  $out .= '<div class="page_options">';
120
  $out .= '<form name="pageoptions">';
121
  $out .= '<input id="showThumbnails" type="checkbox" name="showThumbnails" ';
122
  $out .= $showThumbnails == 1 ? 'checked="checked"' : '';
123
  $out .= '> ' . t('Show Image Thumbnails') . '</form></div>';
124
  if (!empty($pager) && count($pager->records) > 0) {
125
      $out .= '<div id="search_results">';
126
    $out .= theme('cdm_list_of_taxa', array('records' => $pager->records));
127
    $out .= '</div>';
128
    $out .= theme('cdm_pager', array(
129
      'pager' => $pager,
130
      'path' => $path,
131
      'parameters' => $_REQUEST,
132
    ));
133
  }
134
  else {
135
    $out = '<h4 class="error">Sorry, no matching entries found.</h4>';
136
  }
137
  return $out;
138
}
139

    
140
/**
141
 * @todo Please document this function.
142
 */
143
function palmweb_2_cdm_media_caption($variables){
144
  $media = $variables['media'];
145
  $elements = $variables['elements'];
146

    
147
  $media_metadata = read_media_metadata($media);
148

    
149
  $doTitle = !$elements || array_search('title', $elements) !== FALSE;
150
  $doDescription = !$elements || array_search('description', $elements) !== FALSE;
151
  $doArtist = !$elements || array_search('artist', $elements) !== FALSE;
152
  $doLocation = !$elements || array_search('location', $elements) !== FALSE;
153
  $doRights = !$elements || array_search('rights', $elements) !== FALSE;
154

    
155
  $descriptionPrefix = "";
156

    
157
  $out = '<dl class="media-caption">';
158
  // Title.
159
  if ($doTitle) {
160
    if ($media_metadata['title']) {
161
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
162
      $descriptionPrefix = "- ";
163
    }
164
    elseif (!($doDescription && $media_metadata['description'])) {
165
      // Use filename as fallbackoption if no description will be shown.
166
      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
167
      $descriptionPrefix = "- ";
168
    }
169
  }
170
  // Description.
171
  if ($media_metadata['description'] && $doDescription) {
172
    $out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
173
  }
174
  // Artist.
175
  if ($media_metadata['artist'] && $doArtist) {
176
    $out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . str_replace("'","", $media_metadata['artist']) . '</dd>';
177
  }
178
  // Location.
179
  if ($doLocation) {
180
    $location = '';
181
    $location .= $media_metadata['location']['sublocation'];
182
    if ($location && $media_metadata['location']['city']) {
183
      $location .= ', ';
184
    }
185
    $location .= $media_metadata['location']['city'];
186
    if ($location && $media_metadata['location']['province']) {
187
      $location .= ', ';
188
    }
189
    $location .= $media_metadata['location']['province'];
190
    if ($location && $media_metadata['location']['country']) {
191
      $location .= ' (' . $media_metadata['location']['country'] . ')';
192
    }
193
    else {
194
      $location .= $media_metadata['location']['country'];
195
    }
196
    if ($location) {
197
      $out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location  . '</dd>';
198
    }
199
  }
200
  // Rights.
201
  if ($doRights) {
202
    $rights = '';
203
    // Copyrights.
204
    $cnt = count($media_metadata['rights']['copyright']['agentNames']);
205
    if ($cnt > 0) {
206
      $rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
207
      for ($i = 0; $i < $cnt; $i++) {
208
        $rights .= str_replace("'","", $media_metadata['rights']['copyright']['agentNames'][$i]);
209
        if ($i + 1 < $cnt) {
210
          $rights .= ' / ';
211
        }
212
      }
213
      $rights .= '</dd>';
214
    }
215
    // License.
216
    $cnt = count($media_metadata['rights']['license']['agentNames']);
217
    if ($cnt > 0) {
218
      $rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
219
      for ($i = 0; $i < $cnt; $i++) {
220
        $rights .= $media_metadata['rights']['license']['agentNames'][$i];
221
        if ($i + 1 < $cnt) {
222
          $rights .= ' / ';
223
        }
224
      }
225
      $rights .= '</dd>';
226
    }
227
    if ($rights) {
228
      $out .= $rights . '</dt>';
229
    }
230
  }
231
  // TODO add all other metadata elemenst generically.
232
  $out .= '</dl>';
233
  // Return value.
234
  return $out;
235
}
236

    
237
/**
238
 * Overrive of the original theme_cdm_reference()
239
 * the main difference here seems to be that
240
 * this function is completely omitting the citation title cache
241
 * and only sets the authorship as the
242
 * _short_form_of_author_team() as $citation.
243
 *
244
 * If the authorteam is not set citation was empty,
245
 * this has been fixed for http://dev.e-taxonomy.eu/trac/ticket/4261
246
 *
247
 * TODO can this be made configuable via the dataportal
248
 *      settings so that we can remove this function?
249
 */
250
function xxx_palmweb_2_cdm_reference($variables) {
251
  $reference = $variables['reference'];
252
  $microReference = $variables['microReference'];
253
  $doLink = $variables['doLink'];
254
  $referenceStyle = $variables['referenceStyle'];
255

    
256
  if(!isset($reference->authorship)){
257
    $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
258
  } else {
259
    $author_team = $reference->authorship;
260
  }
261

    
262
  $year = '';
263
  if (isset($reference->datePublished->start)) {
264
    $year = partialToYear($reference->datePublished->start);
265
  }
266
  if(isset($author_team->titleCache)){
267
    $citation = _short_form_of_author_team ($author_team->titleCache) . (!empty($year) ? '. ' . $year : '');
268
    $citation = str_replace('..', '.', $citation);
269
  } else {
270
    $citation = $reference->titleCache;
271
  }
272

    
273
  if ($doLink) {
274
    $out = '<span class="reference">';
275
    $out .= l($citation, path_to_reference($reference->uuid), array(
276
    'attributes' => array('class' => 'reference'),
277
    'absolute' => TRUE,
278
    'html' => TRUE,
279
    ));
280
    $out .= '</span>';
281
  }
282
  else {
283
    $out = '<span class="reference">' . $citation . '</span>';
284
  }
285
  // FIXME use microreference webservice instead.
286
  if (!empty($descriptionElementSource->citationMicroReference)) {
287
    $out .= ': ' . $descriptionElementSource->citationMicroReference;
288
  }
289

    
290
  return $out;
291
}
292

    
293
/**
294
 * Sets the body-tag class attribute.
295
 *
296
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
297
 */
298
function phptemplate_body_class($sidebar_left, $sidebar_right) {
299
  if ($sidebar_left != '' && $sidebar_right != '') {
300
    $class = 'sidebars';
301
  }
302
  else {
303
    if ($sidebar_left != '') {
304
      $class = 'sidebar-left';
305
    }
306
    if ($sidebar_right != '') {
307
      $class = 'sidebar-right';
308
    }
309
  }
310

    
311
  if (isset($class)) {
312
    print ' class="' . $class . '"';
313
  }
314
}
315

    
316
/**
317
 * Allow themeable wrapping of all comments.
318
 */
319
function phptemplate_comment_wrapper($content, $type = NULL) {
320
  static $node_type;
321
  if (isset($type)) {
322
    $node_type = $type;
323
  }
324

    
325
  if (!$content || $node_type == 'forum') {
326
    return '<div id="comments">' . $content . '</div>';
327
  }
328
  else {
329
    return '<div id="comments"><h2 class="comments">' . t('Comments') . '</h2>' . $content . '</div>';
330
  }
331
}
332

    
333
/**
334
 * Override or insert PHPTemplate variables into the templates.
335
 */
336
function _phptemplate_variables($hook, $vars) {
337
  if ($hook == 'page') {
338

    
339
    if ($secondary = menu_secondary_local_tasks()) {
340
      $output = '<span class="clear"></span>';
341
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
342
      $vars['tabs2'] = $output;
343
    }
344

    
345
    // Hook into color.module
346
    if (module_exists('color')) {
347
      _color_page_alter($vars);
348
    }
349
    return $vars;
350
  }
351
  return array();
352
}
353

    
354
/**
355
 * Returns the rendered local tasks. The default implementation renders
356
 * them as tabs.
357
 *
358
 * @ingroup themeable
359
 */
360
function phptemplate_menu_local_tasks() {
361
  $output = '';
362

    
363
  if ($primary = menu_primary_local_tasks()) {
364
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
365
  }
366

    
367
  return $output;
368
}
369

    
370
/**
371
 * @todo Please document this function.
372
 * @see http://drupal.org/node/1354
373
 */
374
function palmweb_2_cdm_feature_name($variables){
375
  $feature_name = $variables['feature_name'];
376
  switch ($feature_name) {
377
    case "Protologue": return t("Original Publication");
378
    default: return t(ucfirst($feature_name));
379
  }
380
}
381

    
382
/**
383
 * Implements hook_preprocess_HOOK() for theme_page().
384
 *
385
 * Assign the css classes primary-links and secondary-links to the menus and
386
 * process the 'Login' menu item, to change into 'My account' after login and
387
 * change the tab title for the IMCE file browser.
388
 *
389
 * @author W.Addink <w.addink@eti.uva.nl>
390
 */
391
function palmweb_2_preprocess_page(&$vars) {
392

    
393
  if (isset($vars['main_menu'])) {
394
    // For the Palmae theme we want to change the menu item 'Login' into
395
    // 'My account' if a user is logged in.
396
    global $user;
397
    foreach ($vars['main_menu'] as $key => $value) {
398
        if ($value['href'] == 'user' && !empty($user->name)) {
399
            $vars['main_menu'][$key]['title'] = t('My account');
400
            $vars['main_menu'][$key]['href'] = 'user/' . $user->uid;
401
        }
402
    }
403
    // Theme the main menu with the desired css classes.
404
    $vars['primary_nav'] = theme('links__system_main_menu', array(
405
      'links' => $vars['main_menu'],
406
      'attributes' => array(
407
        'class' => array('links', 'inline', 'main-menu', 'primary-links'),
408
      ),
409
      'heading' => array(
410
        'text' => t('Main menu'),
411
        'level' => 'h2',
412
        'class' => array('element-invisible'),
413
      )));
414
  }
415
  else {
416
    $vars['primary_nav'] = FALSE;
417
  }
418
  if (isset($vars['secondary_menu'])) {
419
    $vars['secondary_nav'] = theme('links__system_secondary_menu', array(
420
      'links' => $vars['secondary_menu'],
421
      'attributes' => array(
422
        'class' => array('links', 'inline', 'secondary-menu', 'secondary-links'),
423
      ),
424
      'heading' => array(
425
        'text' => t('Secondary menu'),
426
        'level' => 'h2',
427
        'class' => array('element-invisible'),
428
      )));
429
  }
430
  else {
431
    $vars['secondary_nav'] = FALSE;
432
  }
433

    
434
  // Change IMCE tab to 'Personal Files'.
435
  if (!empty($vars['tabs']['#primary'])) {
436
    foreach ($vars['tabs']['#primary'] as $key => $value) {
437
      if ($value['#link']['path'] == 'user/%/imce') {
438
        $vars['tabs']['#primary'][$key]['#link']['title'] = t('Personal Files');
439
      }
440
    }
441
  }
442

    
443

    
444
  /* Display node title as page title for the comment form.
445
  * Comment @WA: it would probably be better to select $uuid from node_cdm
446
  * table and link to cdm_dataportal/taxon/%uuid instead.
447
  */
448
  if (arg(0) == 'comment' && arg(1) == 'reply') {
449
      $node = $vars['page']['content']['system_main']['comment_node']['#node'];
450
      $vars['title'] = l(check_plain($node->title),'node/' . $node->nid);
451
  }
452
}
453

    
454
/**
455
 * Implements hook_preprocess_HOOK() for theme_node().
456
 *
457
 * Fixes file urls in nodes. In nodes, relative urls are used to include files
458
 * like <img src="/files/..
459
 *
460
 * Portals can be installed in configurations with
461
 * sub-directories however, in which case these urls need to be adjusted.
462
 * Examples: mysite.org, mysite.org/myportal, mysite.org/portals/myportal.
463
 *
464
 * Therefore preprocess nodes and replace these urls with a the appropriate url
465
 * for the current setup.
466
 *
467
 * @author W.Addink <w.addink@eti.uva.nl>
468
 */
469
function palmweb_2_preprocess_node(&$vars) {
470
  $body = '';
471
// Warning: use #markup value, for which filters like php, html etc are applied!
472
  if (isset($vars['content']['body'][0]['#markup'])) {
473
    $body = $vars['content']['body'][0]['#markup'];
474
  }
475
  else {
476
    $vars['fixed_body'] = '';
477
    return;
478
  }
479

    
480
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
481
  global $base_url;
482
  if ($base_url == '/') {
483
    drupal_set_message(t('
484
      The $base_url in this portal could not be set, please set the $base_url
485
      manually your Drupal settings.php file.', 'error'
486
    ));
487
  }
488
  $fixed_file_path = $base_url . $file_path;
489

    
490
  $preg_file_path = preg_quote($file_path, '/');
491
  $body = preg_replace ('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path , $body);
492
  $body = preg_replace ('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path , $body);
493
  $body = preg_replace ('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path , $body);
494
  $body = preg_replace ('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path , $body);
495

    
496
  $vars['fixed_body'] = $body;
497
}
498

    
499
/**
500
 * Implements hook_form_FORM_ID_alter() for comment_form().
501
 *
502
 * Alter the comment form to make it look like a D5 style comment form.
503
 *
504
 * @author W.Addink <w.addink@eti.uva.nl>
505
 */
506
function palmweb_2_form_comment_form_alter(&$form, &$form_state) {
507

    
508
  if (!isset($form['comment_preview'])) {
509
    $form['header'] = array(
510
      '#markup' => '<h2>' . t('Reply') . '</h2>',
511
      '#weight' => -2,
512
    );
513
  }
514
  $form['subject']['#title'] = $form['subject']['#title'] . ':';
515
  $form['comment_body']['und'][0]['#title'] = $form['comment_body']['und'][0]['#title'] . ':';
516
  if (isset($form['author']['_author']['#title'])) {
517
    $form['author']['_author']['#title'] = $form['author']['_author']['#title'] . ':';
518
  }
519
  $form['actions']['submit']['#value'] = t('Post comment');
520
  $form['actions']['submit']['#weight'] = 1000;
521
  $form['actions']['preview']['#value'] = t('Preview comment');
522
}
523

    
524
/**
525
 * Implements hook_preprocess_HOOK() for theme_comment().
526
 *
527
 * Alter the comment display to make it look like a D5 style comment.
528
 *
529
 * @author W.Addink <w.addink@eti.uva.nl>
530
 */
531
function palmweb_2_preprocess_comment(&$variables) {
532
  $comment = $variables['elements']['#comment'];
533
  if (isset($comment->subject)) {
534
    // Print title without link.
535
    $variables['title'] = $comment->subject;
536
    if ($variables['status'] == 'comment-preview') {
537
      // Add 'new' to preview.
538
      $variables['new'] = t('new');
539
    }
540
  }
541
}
(11-11/11)