View source
<?php
define('DISCUSSTHIS_DEFAULT_NODE_MESSAGE', '<div>Following is a discussion on the [node:content-type] item titled: <a href="[node:url]">[node:title]</a>.</div>' . '<div>Below is the discussion so far. Feel free to add your own comments!</div>');
include_once 'discussthis.node.inc';
include_once 'discussthis.admin.inc';
function discussthis_help($path) {
$output = '';
switch ($path) {
case "admin/help#module_name":
$output = '<p>' . t('Displays links to discussion forums for a given node. Administrators can select the types of nodes for which this is enabled, and for each of these, which forum new topics should be created in.') . '</p>';
$output .= '<ul><li><a href="admin/config/discussthis">Discuss This configuration settings</a></li>';
$output .= '<li><a href="admin/user/access#module-discussthis">Discuss This permissions configuration</a></li></ul>';
break;
}
return $output;
}
function discussthis_permission() {
return array(
'administer discuss this' => array(
'title' => t('Administer discuss this'),
'description' => t('Access Discuss This! setting page and configure it.'),
),
'override discuss this forums' => array(
'title' => t('Override discuss this forums'),
'description' => t('Users with this settings can override default settings for discussion name for a node.') . ' <i>' . t('NOTE: this dependents on node edit permission.') . '</i>',
),
'access discuss this links' => array(
'title' => t('Access discuss this links'),
'description' => t('Acess the discussion on a node and discuss it.'),
),
'initiate discuss this topics' => array(
'title' => t('Initiate discuss this topics'),
'description' => t("Users with this permission can create a discussion for nodes that haven't."),
),
);
}
function discussthis_menu() {
$items = array();
$items['admin/structure/discussthis'] = array(
'title' => 'Discuss This',
'description' => 'Configure discuss this module defaults, including what node types and what forums to link to.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'discussthis_admin_settings',
),
'access arguments' => array(
'administer discuss this',
),
'file' => 'discussthis.admin.inc',
);
$items['discussthis/new/%'] = array(
'page callback' => 'discussthis_new',
'page arguments' => array(
2,
),
'access arguments' => array(
'initiate discuss this topics',
),
'type' => MENU_CALLBACK,
);
$items['discussthis/create/%'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'discussthis_create_discussion_form',
2,
),
'access arguments' => array(
'initiate discuss this topics',
),
'file' => 'discussthis.discussion.inc',
);
$items['discussthis/autocomplete'] = array(
'title' => 'Autocomplete forum topics',
'page callback' => 'discussthis_autocomplete',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'file' => 'discussthis.autocomplete.inc',
);
return $items;
}
function discussthis_theme($existing, $type, $theme, $path) {
return array(
'discussthis_admin_settings_theming' => array(
'render element' => 'element',
'file' => 'discussthis.admin.inc',
),
'discussion_render_wrapper' => array(
'render element' => 'content',
'template' => 'templates/discussion-wrapper',
'file' => 'discussthis.discussion.inc',
),
'discussion_render_item' => array(
'render element' => 'elements',
'template' => 'templates/discussion-item',
'file' => 'discussthis.discussion.inc',
),
);
}
function discussthis_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'forum_node_form' && !empty($form_state['discussthis']['post'])) {
if (module_exists('captcha') && (arg(0) != 'admin' || variable_get('captcha_allow_on_admin_pages', FALSE)) && !user_access('skip CAPTCHA')) {
module_load_include('inc', 'captcha');
$captcha_point = captcha_get_form_id_setting('forum_node_form');
if ($captcha_point && $captcha_point->type) {
$form['buttons']['captcha']['#captcha_type'] = 'none';
}
}
}
if (!user_access('override discuss this forums')) {
return;
}
if (isset($form['type']['#value'])) {
$type = $form['type']['#value'];
}
elseif (isset($form['orig_type']['#value'])) {
$type = $form['orig_type']['#value'];
}
else {
return;
}
if ($form_id != $type . '_node_form') {
return;
}
$nid = $form['nid']['#value'];
$forum_tid = _discussthis_get_forum($nid, $type);
if (!$forum_tid) {
return;
}
$form['discussthis'] = array(
'#type' => 'fieldset',
'#title' => t('Discuss This'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
'#group' => 'additional_settings',
);
$name = '';
$topic_nid = _discussthis_get_topic($nid);
if ($topic_nid) {
$topic = node_load($topic_nid);
if ($topic) {
$name = '<strong>' . t('Current topic #@nid: @title', array(
'@title' => $topic->title,
'@nid' => $topic_nid,
)) . '</strong><br /><br />';
}
else {
$sql = "DELETE FROM {discussthis} WHERE nid = %d";
db_delete('discussthis')
->condition('nid', $nid)
->execute();
unset($topic_nid);
}
}
if (!$topic_nid) {
$discussthis_forums = _discussthis_build_forums_selection_list();
$discussthis_forums[0] = 'No Discuss This!';
$form['discussthis']['discussthis_forum'] = array(
'#type' => 'select',
'#title' => t('Forum for new discussion'),
'#required' => TRUE,
'#description' => t('Select the forum where the first discussion about this node will be created. Or select "No Discuss This!" to prevent discussions on this node. Note: if a topic is attached to this node, then this parameter will have no effect.'),
'#options' => $discussthis_forums,
'#default_value' => $forum_tid,
);
}
$form['discussthis']['discussthis_topic'] = array(
'#type' => 'textfield',
'#title' => t('Identifier of the forum topic to attach to this node'),
'#description' => $name . t('Override default topic associated with this node. Leave empty for default topic. Enter a topic name and use autocompletion to associate this node with an existing topic.'),
'#default_value' => $topic_nid ? $topic_nid : '',
'#autocomplete_path' => 'discussthis/autocomplete',
'#maxlength' => 255,
);
}
function discussthis_create_form_validate($form, &$form_state) {
comment_form_validate($form, $form_state);
}