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('Node comments'),
|
15
|
'icon' => 'icon_node.png',
|
16
|
'description' => t('The comments of 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
|
function ctools_node_comments_content_type_render($subtype, $conf, $panel_args, $context) {
|
27
|
if (empty($context->data->nid)) {
|
28
|
return;
|
29
|
}
|
30
|
$node = clone $context->data;
|
31
|
$block = new stdClass();
|
32
|
$block->module = 'comments';
|
33
|
$block->delta = $node->nid;
|
34
|
$block->title = t('Comments');
|
35
|
|
36
|
if ($node->comment) {
|
37
|
$block->content = ctools_comment_render($node, $conf);
|
38
|
}
|
39
|
|
40
|
return $block;
|
41
|
}
|
42
|
|
43
|
function ctools_node_comments_content_type_edit_form($form, &$form_state) {
|
44
|
$conf = $form_state['conf'];
|
45
|
$form['mode'] = array(
|
46
|
'#type' => 'select',
|
47
|
'#title' => t('Mode'),
|
48
|
'#default_value' => $conf['mode'],
|
49
|
'#options' => _comment_get_modes(),
|
50
|
'#weight' => 1,
|
51
|
);
|
52
|
foreach (_comment_per_page() as $i) {
|
53
|
$options[$i] = t('!a comments per page', array('!a' => $i));
|
54
|
}
|
55
|
$form['comments_per_page'] = array(
|
56
|
'#type' => 'select',
|
57
|
'#title' => t('Pager'),
|
58
|
'#default_value' => $conf['comments_per_page'],
|
59
|
'#options' => $options,
|
60
|
'#weight' => 3,
|
61
|
);
|
62
|
return $form;
|
63
|
}
|
64
|
|
65
|
function ctools_node_comments_content_type_edit_form_submit($form, &$form_state) {
|
66
|
// Copy everything from our defaults.
|
67
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
68
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
69
|
}
|
70
|
}
|
71
|
|
72
|
function ctools_node_comments_content_type_admin_title($subtype, $conf, $context) {
|
73
|
return t('"@s" comments', array('@s' => $context->identifier));
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* This function is a somewhat stripped down version of comment_render
|
78
|
* that removes a bunch of cruft that we both don't need, and makes it
|
79
|
* difficult to modify this.
|
80
|
*/
|
81
|
function ctools_comment_render($node, $conf) {
|
82
|
$output = '';
|
83
|
if (!user_access('access comments') || !$node->comment) {
|
84
|
return;
|
85
|
}
|
86
|
|
87
|
$mode = $conf['mode'];
|
88
|
$comments_per_page = $conf['comments_per_page'];
|
89
|
|
90
|
$cids = comment_get_thread($node, $mode, $comments_per_page);
|
91
|
$comments = comment_load_multiple($cids);
|
92
|
|
93
|
if ($comments) {
|
94
|
drupal_add_css(drupal_get_path('module', 'comment') . '/comment.css');
|
95
|
comment_prepare_thread($comments);
|
96
|
$build = comment_view_multiple($comments, $node);
|
97
|
$build['pager']['#theme'] = 'pager';
|
98
|
return drupal_render($build);
|
99
|
}
|
100
|
return;
|
101
|
}
|