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('Comments and comment form.'),
|
11
|
'icon' => 'icon_node.png',
|
12
|
'description' => t('The comments and comment form for 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
|
/**
|
23
|
* Render the node comments.
|
24
|
*/
|
25
|
function ctools_node_comment_wrapper_content_type_render($subtype, $conf, $panel_args, $context) {
|
26
|
$node = isset($context->data) ? clone($context->data) : NULL;
|
27
|
$block = new stdClass();
|
28
|
$block->module = 'comments';
|
29
|
$block->delta = $node->nid;
|
30
|
|
31
|
$renderable = array(
|
32
|
'#theme' => 'comment_wrapper__node_' . $node->type,
|
33
|
'#node' => $node,
|
34
|
'comments' => array(),
|
35
|
'comment_form' => array(),
|
36
|
);
|
37
|
|
38
|
// Add in the comments.
|
39
|
if (($node->comment_count && user_access('access comments')) || user_access('administer comments')) {
|
40
|
$mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED);
|
41
|
$comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50);
|
42
|
if ($cids = comment_get_thread($node, $mode, $comments_per_page)) {
|
43
|
$comments = comment_load_multiple($cids);
|
44
|
comment_prepare_thread($comments);
|
45
|
$build = comment_view_multiple($comments, $node);
|
46
|
$build['pager']['#theme'] = 'pager';
|
47
|
$renderable['comments'] = $build;
|
48
|
}
|
49
|
}
|
50
|
|
51
|
// Stuff in the comment form.
|
52
|
if ($node->comment == COMMENT_NODE_OPEN) {
|
53
|
if (user_access('post comments')) {
|
54
|
$comment = new stdClass();
|
55
|
$comment->nid = $node->nid;
|
56
|
$comment->pid = NULL;
|
57
|
$form_state = array(
|
58
|
'ctools comment alter' => TRUE,
|
59
|
'node' => $node,
|
60
|
'build_info' => array(
|
61
|
'args' => array(
|
62
|
$comment,
|
63
|
),
|
64
|
),
|
65
|
);
|
66
|
$renderable['comment_form'] = drupal_build_form('comment_node_' . $node->type . '_form', $form_state);
|
67
|
}
|
68
|
else if (!empty($conf['anon_links'])) {
|
69
|
$renderable['comment_form'] = theme('comment_post_forbidden', array('node' => $node));
|
70
|
}
|
71
|
}
|
72
|
|
73
|
$block->content = drupal_render($renderable);
|
74
|
|
75
|
return $block;
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* Returns an edit form for the comment wrapper.
|
80
|
*/
|
81
|
function ctools_node_comment_wrapper_content_type_edit_form($form, &$form_state) {
|
82
|
$conf = $form_state['conf'];
|
83
|
$form['mode'] = array(
|
84
|
'#type' => 'select',
|
85
|
'#title' => t('Mode'),
|
86
|
'#default_value' => $conf['mode'],
|
87
|
'#options' => _comment_get_modes(),
|
88
|
'#weight' => 1,
|
89
|
);
|
90
|
foreach (_comment_per_page() as $i) {
|
91
|
$options[$i] = t('!a comments per page', array('!a' => $i));
|
92
|
}
|
93
|
$form['comments_per_page'] = array('#type' => 'select',
|
94
|
'#title' => t('Pager'),
|
95
|
'#default_value' => $conf['comments_per_page'],
|
96
|
'#options' => $options,
|
97
|
'#weight' => 3,
|
98
|
);
|
99
|
return $form;
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* Submit handler for the comment wrapper settings form.
|
104
|
*/
|
105
|
function ctools_node_comment_wrapper_content_type_edit_form_submit($form, &$form_state) {
|
106
|
// Copy everything from our defaults.
|
107
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
108
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
109
|
}
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* Returns the administrative title.
|
114
|
*/
|
115
|
function ctools_node_comment_wrapper_content_type_admin_title($subtype, $conf, $context) {
|
116
|
return t('Comments and comment form');
|
117
|
}
|