Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / content_types / node_context / node_comments.inc @ 7e72b748

1
<?php
2

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

    
22
function ctools_node_comments_content_type_render($subtype, $conf, $panel_args, $context) {
23
  if (empty($context->data->nid)) {
24
    return;
25
  }
26
  $node = clone $context->data;
27
  $block = new stdClass();
28
  $block->module = 'comments';
29
  $block->delta  = $node->nid;
30
  $block->title = t('Comments');
31

    
32
  if ($node->comment) {
33
    $block->content = ctools_comment_render($node, $conf);
34
  }
35

    
36
  return $block;
37
}
38

    
39
function ctools_node_comments_content_type_edit_form($form, &$form_state) {
40
  $conf = $form_state['conf'];
41
  $form['mode'] = array(
42
    '#type' => 'select',
43
    '#title' => t('Mode'),
44
    '#default_value' => $conf['mode'],
45
    '#options' => _comment_get_modes(),
46
    '#weight' => 1,
47
  );
48
  foreach (_comment_per_page() as $i) {
49
    $options[$i] = t('!a comments per page', array('!a' => $i));
50
  }
51
  $form['comments_per_page'] = array('#type' => 'select',
52
    '#title' => t('Pager'),
53
    '#default_value' => $conf['comments_per_page'],
54
    '#options' => $options,
55
    '#weight' => 3,
56
  );
57
  return $form;
58
}
59

    
60
function ctools_node_comments_content_type_edit_form_submit($form, &$form_state) {
61
  // Copy everything from our defaults.
62
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
63
    $form_state['conf'][$key] = $form_state['values'][$key];
64
  }
65
}
66

    
67
function ctools_node_comments_content_type_admin_title($subtype, $conf, $context) {
68
  return t('"@s" comments', array('@s' => $context->identifier));
69
}
70

    
71
/**
72
 * This function is a somewhat stripped down version of comment_render
73
 * that removes a bunch of cruft that we both don't need, and makes it
74
 * difficult to modify this.
75
 */
76
function ctools_comment_render($node, $conf) {
77
  $output = '';
78
  if (!user_access('access comments') || !$node->comment) {
79
    return;
80
  }
81

    
82
  $mode = $conf['mode'];
83
  $comments_per_page = $conf['comments_per_page'];
84

    
85
  $cids = comment_get_thread($node, $mode, $comments_per_page);
86
  $comments = comment_load_multiple($cids);
87

    
88
  if ($comments) {
89
    drupal_add_css(drupal_get_path('module', 'comment') . '/comment.css');
90
    comment_prepare_thread($comments);
91
    $build = comment_view_multiple($comments, $node);
92
    $build['pager']['#theme'] = 'pager';
93
    return drupal_render($build);
94
  }
95
  return;
96
}