Projet

Général

Profil

Paste
Télécharger (3,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / content_types / node_context / node_comment_wrapper.inc @ c304a780

1
<?php
2

    
3
/**
4
 * @file
5
 */
6

    
7
if (module_exists('comment')) {
8
  /**
9
   * Plugins are described by creating a $plugin array which will be used
10
   * by the system that includes this file.
11
   */
12
  $plugin = array(
13
    'single' => TRUE,
14
    'title' => t('Comments and comment form.'),
15
    'icon' => 'icon_node.png',
16
    'description' => t('The comments and comment form for the referenced node.'),
17
    'required context' => new ctools_context_required(t('Node'), 'node'),
18
    'category' => t('Node'),
19
    'defaults' => array(
20
      'mode' => variable_get('comment_default_mode', COMMENT_MODE_THREADED),
21
      'comments_per_page' => variable_get('comment_default_per_page', '50'),
22
    ),
23
  );
24
}
25

    
26
/**
27
 * Render the node comments.
28
 */
29
function ctools_node_comment_wrapper_content_type_render($subtype, $conf, $panel_args, $context) {
30
  $node = isset($context->data) ? clone $context->data : NULL;
31
  $block = new stdClass();
32
  $block->module = 'comments';
33
  $block->delta = $node->nid;
34

    
35
  $renderable = array(
36
    '#theme' => 'comment_wrapper__node_' . $node->type,
37
    '#node' => $node,
38
    'comments' => array(),
39
    'comment_form' => array(),
40
  );
41

    
42
  // Add in the comments.
43
  if (($node->comment_count && user_access('access comments')) || user_access('administer comments')) {
44
    $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
45
    $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
46
    if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {
47
      $comments = comment_load_multiple($cids);
48
      comment_prepare_thread($comments);
49
      $build = comment_view_multiple($comments, $node);
50
      $build['pager']['#theme'] = 'pager';
51
      $renderable['comments'] = $build;
52
    }
53
  }
54

    
55
  // Stuff in the comment form.
56
  if ($node->comment == COMMENT_NODE_OPEN) {
57
    if (user_access('post comments')) {
58
      $comment = new stdClass();
59
      $comment->nid = $node->nid;
60
      $comment->pid = NULL;
61
      $form_state = array(
62
        'ctools comment alter' => TRUE,
63
        'node' => $node,
64
        'build_info' => array(
65
          'args' => array(
66
            $comment,
67
          ),
68
        ),
69
      );
70
      $renderable['comment_form'] = drupal_build_form('comment_node_' . $node->type . '_form', $form_state);
71
    }
72
    elseif (!empty($conf['anon_links'])) {
73
      $renderable['comment_form'] = theme('comment_post_forbidden', array('node' => $node));
74
    }
75
  }
76

    
77
  $block->content = drupal_render($renderable);
78

    
79
  return $block;
80
}
81

    
82
/**
83
 * Returns an edit form for the comment wrapper.
84
 */
85
function ctools_node_comment_wrapper_content_type_edit_form($form, &$form_state) {
86
  $conf = $form_state['conf'];
87
  $form['mode'] = array(
88
    '#type' => 'select',
89
    '#title' => t('Mode'),
90
    '#default_value' => $conf['mode'],
91
    '#options' => _comment_get_modes(),
92
    '#weight' => 1,
93
  );
94
  foreach (_comment_per_page() as $i) {
95
    $options[$i] = t('!a comments per page', array('!a' => $i));
96
  }
97
  $form['comments_per_page'] = array(
98
    '#type' => 'select',
99
    '#title' => t('Pager'),
100
    '#default_value' => $conf['comments_per_page'],
101
    '#options' => $options,
102
    '#weight' => 3,
103
  );
104
  return $form;
105
}
106

    
107
/**
108
 * Submit handler for the comment wrapper settings form.
109
 */
110
function ctools_node_comment_wrapper_content_type_edit_form_submit($form, &$form_state) {
111
  // Copy everything from our defaults.
112
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
113
    $form_state['conf'][$key] = $form_state['values'][$key];
114
  }
115
}
116

    
117
/**
118
 * Returns the administrative title.
119
 */
120
function ctools_node_comment_wrapper_content_type_admin_title($subtype, $conf, $context) {
121
  return t('Comments and comment form');
122
}