'. t('The talk module gives you the option to display comments on a seperate tab. The option is per content type and can be set in the workflow options of a content type.') .'
'; return $output; } } /** * Implementation of hook_menu(). */ function talk_menu() { $items = array(); $items['node/%node/talk'] = array( 'title' => talk_title(), 'page callback' => 'talk_handle', 'page arguments' => array(1), 'access callback' => 'user_access', 'access arguments' => array('access comments'), 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/talk'] = array( 'title' => t('Talk page'), 'description' => t('Configure settings for the talk page.'), 'page callback' => 'drupal_get_form', 'page arguments' => array('talk_admin_form'), ); return $items; } /** * Menu call back for admin form. */ function talk_admin_form() { $form = array(); $form['talk_title'] = array( '#type' => 'textfield', '#title' => t('Title of the "talk" page'), '#default_value' => talk_title(), ); return system_settings_form($form); } function talk_title($title = NULL) { if (is_null($title)) { return variable_get('talk_title', t('Talk')); } variable_set('talk_title', $title); } /** * Menu callback for talk page. */ function talk_handle($node) { if ($node->nid && talk_activated($node->type) && _talk_node_comment_value($node)) { drupal_set_title($node->title); $add_comments = _talk_node_comment_value($node) == COMMENT_NODE_READ_WRITE && user_access('post comments'); return theme('talkpage', $node, $add_comments); } else { return drupal_not_found(); } } /** * Implementation of hook_nodeapi(). */ function talk_nodeapi(&$node, $op) { switch ($op) { case 'load': if (talk_activated($node->type) && arg(0) == 'node' && !arg(2)) { // Overwrite setting of comment module and set comments for this node to disabled. // This prevents the comments of being displayed. $output['comment_original_value'] = $node->comment; $output['comment'] = 0; return $output; } break; } } /** * Implementation of hook_link(). */ function talk_link($type, $node = null, $teaser = false) { if ($type == 'node' && talk_activated($node->type) && user_access('access comments')) { $result = array(); if ($node->comment_count) { $result['talk_view'] = array( 'title' => t('!title page (!nr comments)', array('!nr' => $node->comment_count, '!title' => talk_title())), 'href' => 'node/'. $node->nid .'/talk', ); } else if (_talk_node_comment_value($node) == COMMENT_NODE_READ_WRITE) { $result['talk_view'] = array( 'title' => t('Add new comment'), 'href' => "comment/reply/$node->nid", ); } return $result; } } /** * Implementation of hook_form_alter(). */ function talk_form_alter(&$form, $form_state, $form_id) { // Add option to comment options of node types. if ($form_id == 'node_type_form' && isset($form['identity']['type']) && module_exists('comment')) { $form['workflow']['comment_talk'] = array( '#type' => 'checkbox', '#title' => t('Display comments on separate talk page'), '#prefix' => ''. t('Talk pages:') .'', '#weight' => 5, '#default_value' => talk_activated($form['#node_type']->type), ); } } /** * Implementation of hook_link_alter(). */ function talk_link_alter(&$links, $node) { unset($links['comment_add']); } /** * Implementation of hook_form_alter() * Changing the destination to the talk page after posting a comment */ function talk_comment($a1, $op) { if ($op == 'insert' || $op == 'update') { $_REQUEST['destination'] = 'node/'. $a1['nid'] .'/talk'; } } /** * Is talk page option activated for node tpye? */ function talk_activated($node_type, $value = null) { if (is_null($value)) { return variable_get('comment_talk_'. $node_type, FALSE); } variable_set('comment_talk_'. $node_type, $value); } /** * Value of 'comment' of node. */ function _talk_node_comment_value(&$node) { return isset($node->comment_original_value) ? $node->comment_original_value : $node->comment; } /* * Theme functions */ /** * Implementation of hook_theme(). */ function talk_theme() { return array( 'talkpage' => array( 'template' => 'talkpage', 'arguments' => array('node' => NULL, 'add_comments' => NULL), ), ); } /** * Theme talkpage for node * @param $node * node whose talk page is displayed * @param $add_comments * boolean which indicates if the adding of comments is allowed for current user */ function template_preprocess_talkpage(&$variables) { $add_comments = $variables['add_comments']; $node = $variables['node']; $variables['title'] = talk_title(); $comment_link = ''; if ($add_comments) { $comment_link = l(t('Add new comment'), "comment/reply/$node->nid"); } $comments = comment_render($node, 0); $redisplay = FALSE; if ($node->comment_count > 1 && $add_comments) { $redisplay = TRUE; } $variables['redisplay'] = $redisplay; $variables['comment_link'] = $comment_link; $variables['comments'] = $comments; }