Projet

Général

Profil

Paste
Télécharger (2,17 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ds / modules / ds_extras / includes / ds_extras.pages.inc @ 6e9292aa

1
<?php
2

    
3
/**
4
 * @file
5
 * Display Suite Extras page functions.
6
 */
7

    
8
/**
9
 * Menu callback: show an individual node with the Switch field.
10
 */
11
function ds_extras_node_page_view($node) {
12

    
13
  // If there is a menu link to this node, the link becomes the last part
14
  // of the active trail, and the link name becomes the page title.
15
  // Thus, we must explicitly set the page title to be the node title.
16
  drupal_set_title($node->title);
17
  $uri = entity_uri('node', $node);
18
  // Set the node path as the canonical URL to prevent duplicate content.
19
  drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url($uri['path'], $uri['options'])), TRUE);
20
  // Set the non-aliased path as a default shortlink.
21
  drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE)))), TRUE);
22

    
23
  // Update the history table, stating that this user viewed this node.
24
  node_tag_new($node);
25

    
26
  // For markup consistency with other pages, use node_view_multiple() rather than node_view().
27
  $view_mode = (!empty($node->ds_switch)) ? $node->ds_switch : 'full';
28

    
29
  // It's also possible to use $_GET['v'] to switch view modes.
30
  if (isset($_GET['v']) && !empty($_GET['v'])) {
31
    $view_mode = $_GET['v'];
32
  }
33
  drupal_static('ds_extras_view_mode', $view_mode);
34
  return node_view_multiple(array($node->nid => $node), $view_mode);
35
}
36

    
37
/**
38
 * Menu callback: switches to another view mode inline.
39
 */
40
function ds_switch_view_mode_inline() {
41

    
42
  $content = '';
43
  $status = TRUE;
44
  $error = FALSE;
45

    
46
  $id = $_REQUEST['id'];
47
  $view_mode = $_REQUEST['view_mode'];
48
  $entity_type = $_REQUEST['entity_type'];
49
  $entity = entity_load($entity_type, array($id));
50

    
51
  if (!isset($entity[$id])) {
52
    $status = FALSE;
53
    $error = t('Content was not found.');
54
  }
55
  else {
56
    if (node_access('view', $entity[$id])) {
57
      $element = node_view($entity[$id], $view_mode);
58
      $content = drupal_render($element);
59
    }
60
    else {
61
      $error = t('Access denied');
62
    }
63
  }
64

    
65
  drupal_add_http_header('Content-Type', 'text/javascript; charset=utf-8');
66
  print drupal_json_encode(array(
67
    'status' => $status,
68
    'content' => $content,
69
    'errorMessage' => $error,
70
  ));
71
  exit();
72
}