Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / themes / palmweb_2 / template.php @ 384ff2ba

History | View | Annotate | Download (17.4 KB)

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_taxa_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('Display image thumbnails') . '</form></div>';
124
  if (!empty($pager) && count($pager->records) > 0) {
125
      $out .= '<div id="search_results">';
126
    $list_of_taxa = compose_list_of_taxa($pager->records);
127
    $out .= drupal_render($list_of_taxa);
128
    $out .= '</div>';
129
    $out .= theme('cdm_pager', array(
130
      'pager' => $pager,
131
      'path' => $path,
132
      'parameters' => $_REQUEST,
133
    ));
134
  }
135
  else {
136
    $out = '<h4 class="error">Sorry, no matching entries found.</h4>';
137
  }
138
  return $out;
139
}
140

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

    
148
  $media_metadata = read_media_metadata($media);
149

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

    
156
  $descriptionPrefix = "";
157

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

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

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

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

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

    
292
  return $out;
293
}
294

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

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

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

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

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

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

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

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

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

    
369
  return $output;
370
}
371

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

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

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

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

    
445

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

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

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

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

    
498
  $vars['fixed_body'] = $body;
499
}
500

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

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

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