| 1 |
<?php
|
| 2 |
// $Id: flatcomments.module,v 1.6 2009/10/20 02:36:43 dragonwize Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Make comments replies to the node, regardless of the reply link used.
|
| 7 |
*/
|
| 8 |
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_form_alter().
|
| 12 |
*/
|
| 13 |
function flatcomments_form_alter(&$form, &$form_state, $form_id) {
|
| 14 |
switch ($form['#id']) {
|
| 15 |
case 'node-type-form':
|
| 16 |
dsm($form);
|
| 17 |
// Add note about flatcomments to comment display description.
|
| 18 |
$form['comment']['comment_default_mode']['#description'] .= t(' <strong>Flatcomments enabled:</strong> Leave this box unchecked to force replies to be to the main post instead of other comments.');
|
| 19 |
/*
|
| 20 |
// Add option to default display mode.
|
| 21 |
$form['comment']['comment_default_mode']['#options'][5] = t('Orderable flat list - expanded');
|
| 22 |
|
| 23 |
// Add submit handler to handle additional display mode.
|
| 24 |
array_unshift($form['#submit'], 'flatcomments_node_type_form_submit');
|
| 25 |
|
| 26 |
// If display mode is 2 and our variable is 5 then set default value to 5.
|
| 27 |
$display_mode = $form['comment']['comment_default_mode']['#default_value'];
|
| 28 |
$node_type = $form['#node_type']->type;
|
| 29 |
$orderable = variable_get('flatcomments_default_mode_' . $node_type, 0);
|
| 30 |
if ($display_mode == 4 && $orderable == 5 && !$form_state['submitted']) {
|
| 31 |
$form['comment']['comment_default_mode']['#default_value'] = 5;
|
| 32 |
}
|
| 33 |
|
| 34 |
// Add option to remove reply link from comments.
|
| 35 |
$form['comment']['flatcomments_remove_reply_link'] = array(
|
| 36 |
'#type' => 'checkboxes',
|
| 37 |
'#title' => t('Links'),
|
| 38 |
'#default_value' => variable_get('flatcomments_remove_reply_link_' . $node_type, array()),
|
| 39 |
'#options' => array(
|
| 40 |
'reply' => t('Do not show a reply link on comments'),
|
| 41 |
),
|
| 42 |
);
|
| 43 |
*/
|
| 44 |
break;
|
| 45 |
}
|
| 46 |
}
|
| 47 |
|
| 48 |
/**
|
| 49 |
* Implementation of hook_comment_presave().
|
| 50 |
*/
|
| 51 |
function flatcomments_comment_presave($comment) {
|
| 52 |
// Only affect new comments and comments set to be displayed flat.
|
| 53 |
$display_mode = (int)variable_get('comment_default_mode_' . str_replace('comment_node_', '', $comment->node_type), 0);
|
| 54 |
if (!$comment->cid && $display_mode === 0) {
|
| 55 |
// Set parent id to NULL to prevent threads.
|
| 56 |
$comment->pid = NULL;
|
| 57 |
}
|
| 58 |
}
|