function discussthis_admin_settings in Discuss This! 6
Same name and namespace in other branches
- 7.2 discussthis.admin.inc \discussthis_admin_settings()
- 7 discussthis.admin.inc \discussthis_admin_settings()
\brief Generate the administration form.
This function generates the administration form for the Discuss This! module.
The form includes entries of interest:
\li Selection of who should be the author of newly-created forum discussions
The author can be a specific person, the author of the node being discussed or the currently logged in user. All 3 cases make sense, yet each website may want to use one or the other user.
\warning Note that the user assigned to such posts should NOT have more rights in regard to Input formats, otherwise XSS attacks are possible. Although the module attempts to prevent such problems, it is your responsibility to choose who has the right to create posts in your forum and from what data.
\li The set of node types to which Discuss This! links are added
That selection should probably be moved to each Content type instead of being in this settings form. It let the user select the nodes where a link appear based on a node type.
\todo We could also look into adding a table to allow the user to make such a selection on a per node basis.
\li For each selected node type, a default forum in which to create discussion topics
\li Whether to display some of the comments at the bottom of the original node
\li Default content
\li Authorize users to log in right from the Discuss This! link
\return discussthis settings edit form
1 string reference to 'discussthis_admin_settings'
- _discussthis_menu in ./
discussthis.admin.inc - \brief Actual implementation of hook_menu().
File
- ./
discussthis.admin.inc, line 97 - Settings callbacks
Code
function discussthis_admin_settings() {
drupal_add_js(drupal_get_path('module', 'discussthis') . '/discussthis.js');
drupal_add_css(drupal_get_path('module', 'discussthis') . '/discussthis.css');
$node_types = node_get_types('names');
$discussthis_nodetypes = variable_get('discussthis_nodetypes', array());
// prevent Discuss This! in forums
unset($node_types['forum']);
unset($discussthis_nodetypes['forum']);
// adjust the discussthis_nodetypes arrays
foreach ($node_types as $type => $name) {
if (!isset($discussthis_nodetypes[$type])) {
$discussthis_nodetypes[$type] = 0;
}
}
foreach ($discussthis_nodetypes as $type => $enabled) {
if (!isset($node_types[$type])) {
unset($discussthis_nodetypes[$type]);
}
}
// links and comments (node being discussed)
$form['discussthis'] = array(
'#type' => 'fieldset',
'#title' => t('Settings for nodes being discussed'),
'#description' => t('Setup the forum message that is created automatically when a new discussion is started.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['discussthis']['discussthis_autocomplete_contains'] = array(
'#type' => 'checkbox',
'#title' => t('Auto-complete in nodes searches posts that contain the entered string'),
'#description' => t('WARNING: on systems with a large number of nodes in forums, this feature can be very slow. If unsure, leave unchecked.'),
'#default_value' => variable_get('discussthis_autocomplete_contains', 0),
);
$form['discussthis']['discussthis_link'] = array(
'#type' => 'textfield',
'#title' => t('Discuss This! link'),
'#description' => t('Enter the message used as the Discuss This! link when no comments were posted yet. Leave empty to use the default.'),
'#default_value' => variable_get('discussthis_link', ''),
);
$form['discussthis']['discussthis_participate'] = array(
'#type' => 'textfield',
'#title' => t('Participate link'),
'#description' => t('Enter the message shown in the Discuss This! link once comments were already posted. Leave empty to use the default.'),
'#default_value' => variable_get('discussthis_participate', ''),
);
$form['discussthis']['discussthis_new_user'] = array(
'#type' => 'textfield',
'#title' => t('New user message'),
'#description' => t('Enter the message shown in the Discuss This! link in regard to having the user register a new account. In that case, the user will have to come back to the node on his own in order to post his comment...'),
'#default_value' => variable_get('discussthis_new_user', ''),
);
$form['discussthis']['discussthis_showcounts'] = array(
'#type' => 'checkbox',
'#title' => t('Show comment counts'),
'#description' => t('When checked, show the number of comments in the discussion (new/total.)'),
'#default_value' => variable_get('discussthis_showcounts', 1),
);
$form['discussthis']['discussthis_login'] = array(
'#type' => 'checkbox',
'#title' => t('Login/Register link for Anonymous users'),
'#description' => t('Check this box to offer anonymous users to login/register when on a page with the Discuss this feature. Note: this will have no effect if anonymous users do not have the "access discuss this links" permission. If your registration process is complicated, you may want to turn this feature off.'),
'#default_value' => variable_get('discussthis_login', 1),
);
$form['discussthis']['discussthis_comments'] = array(
'#type' => 'textfield',
'#title' => t('Number of comments'),
'#description' => t('Select the number of forum comments to display at the bottom of the node being discussed. This feature is ignored in teaser view. Use 0 to disable this feature.'),
'#default_value' => variable_get('discussthis_comments', 0),
'#size' => 10,
);
// author, template, post being created
$form['discussthis_post'] = array(
'#type' => 'fieldset',
'#title' => t('Post settings for new topics'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['discussthis_post']['discussthis_new_post_title'] = array(
'#type' => 'textfield',
'#title' => t('Discuss This! comment form title'),
'#description' => t('Enter the title of the Discuss This! form used to create a new topic. Leave empty to use the default.'),
'#default_value' => variable_get('discussthis_new_post_title', ''),
);
$form['discussthis_post']['discussthis_author'] = array(
'#type' => 'textfield',
'#title' => t('Author of newly created Forum discussions'),
'#description' => t('You can enter one of the following as the Forum discussion author:' . '<ul>' . '<li>Leave blank if you want the person who clicks the link to be the author of the new topic;</li>' . '<li>Enter an asterisk (*) to use author of the node being commented;</li>' . '<li>Enter the name of the author to use.</li>' . '</ul>' . 'Note that if the author doesn\'t have permissions to edit their own topics,' . ' they won\'t be able to update the topic being posted, and if they don\'t have' . ' permissions to post comments, they will not be able to actually submit a' . ' comment on the newly-created forum topic.'),
'#size' => 30,
'#maxlength' => 60,
'#autocomplete_path' => 'user/autocomplete',
'#default_value' => variable_get('discussthis_author', ''),
);
$form['discussthis_post']['discussthis_newsubject'] = array(
'#type' => 'textfield',
'#title' => t('Title for newly created Forum discussions'),
'#size' => 30,
'#maxlength' => 60,
'#default_value' => variable_get('discussthis_newsubject', '[node-title]'),
);
$default_body = DISCUSSTHIS_DEFAULT_NODE_MESSAGE;
$form['discussthis_post']['discussthis_newtemplate'] = array(
'#type' => 'textarea',
'#title' => t('Template for auto-created Forum discussions'),
'#description' => theme('token_help', array(
'discussthis',
'user',
)),
'#default_value' => variable_get('discussthis_newtemplate', $default_body),
);
// the forum/node type table
$form['discussthis_forums'] = array(
'#type' => 'fieldset',
'#title' => t('Node type & forum selection'),
'#description' => t('Defines the forum attached to each node type. Leave a node type unchecked if you do not want Discuss This! on these nodes.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#prefix' => '<div class="discussthis-admin">',
'#suffix' => '</div>',
);
$form['discussthis_forums']['discussthis_nodetypes'] = array(
'#type' => 'checkboxes',
'#title' => t('Node types using Discuss This'),
'#description' => t('Select:<ul class="discussthis-help"><li>All the node types where you want the Discuss This! link to appear,</li><li>The forum in which to create the new topic (can be overridden in each node),</li><li>The format used for the topic posts.</li></ul>'),
'#default_value' => $discussthis_nodetypes,
'#options' => $node_types,
);
$forums = forum_get_forums();
$discussthis_forums = array(
'0' => '-- select --',
);
foreach ($forums as $tid => $forum) {
if (empty($forum->container)) {
$discussthis_forums[$tid] = str_repeat('-', $forum->depth) . $forum->name;
}
}
$formats = filter_formats();
$discussthis_formats = array(
'0' => 'Default',
);
foreach ($formats as $fid => $format) {
$discussthis_formats[$fid] = $format->name;
}
// This should probably be within the node type config page, or else use some AJAX thingy to update
// these form fields based on the discussthis_nodetypes selection above..
foreach ($discussthis_nodetypes as $type => $name) {
// IMPORTANT NOTE: Those two items are RIGHT aligned and thus appear from right to left
$form['discussthis_forums']['defaults']['discussthis_format_' . $type] = array(
'#type' => 'select',
'#default_value' => variable_get('discussthis_format_' . $type, 0),
'#options' => $discussthis_formats,
'#prefix' => '<span class="conditional discussthis-formats">',
'#suffix' => '</span>',
);
$form['discussthis_forums']['defaults']['discussthis_node_' . $type] = array(
//'#title' => 'Forum for '. $node_types[$type], -- when it works, this appears under the checkbox when the checkbox is checked
'#type' => 'select',
'#default_value' => variable_get('discussthis_node_' . $type, 0),
'#options' => $discussthis_forums,
'#prefix' => '<span class="conditional discussthis-nodes">',
'#suffix' => '</span>',
);
}
$form['discussthis_forums']['#theme'] = 'discussthis_admin_settings_forums';
// Now process the form
return system_settings_form($form);
}