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