You are here

discussthis.module in Discuss This! 7.2

Same filename and directory in other branches
  1. 5 discussthis.module
  2. 6 discussthis.module
  3. 7 discussthis.module

Associations discussions in forums with specific nodes

File

discussthis.module
View source
<?php

/**
 * @file
 *
 * Associations discussions in forums with specific nodes
 */
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.fields.inc';
include_once 'discussthis.admin.inc';

// ---------------------------------------------
// HOOK IMPLEMENTATIONS

/**
 * Implements hook_help().
 */
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;
}

/**
 * Implements hook_permission().
 */
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."),
    ),
  );
}

/**
 * Implements hook_menu().
 */
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 not properly checked on callbacks (see function)
    '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 not properly checked on callbacks (see function)
    'access arguments' => array(
      'initiate discuss this topics',
    ),
    'file' => 'discussthis.discussion.inc',
  );
  $items['discussthis/autocomplete'] = array(
    'title' => 'Autocomplete forum topics',
    'page callback' => 'discussthis_autocomplete',
    // access not properly checked on callbacks (see function)
    'access arguments' => array(
      'access content',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'discussthis.autocomplete.inc',
  );
  return $items;
}

/**
 * Implements hook_theme().
 */
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',
    ),
  );
}

/**
 * Implements hook_form_alter().
 *
 * Adds per-node override forum dropdown and topic autocomplete
 * form for node edit forms.
 */
function discussthis_form_alter(&$form, &$form_state, $form_id) {

  //
  if ($form_id == 'forum_node_form' && !empty($form_state['discussthis']['post'])) {

    // we need to tweak forum forms to make sure that captcha do not
    // both us when we're auto-posting a new entry in the forum
    // if the user has a captcha on the forum, we need to add a dummy entry
    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) {

        // the captcha type is set to none so it will be ignored
        $form['buttons']['captcha']['#captcha_type'] = 'none';
      }
    }
  }
}

/**
 * \brief Validate the comment the user just posted.
 *
 * This function validates the entered data. The comment module
 * expects a valid name, email address and URL.
 *
 * \param[in] $form The form
 * \param[in,out] $form_state The current state of the form
 */
function discussthis_create_form_validate($form, &$form_state) {
  comment_form_validate($form, $form_state);
}

Functions

Namesort descending Description
discussthis_create_form_validate \brief Validate the comment the user just posted.
discussthis_form_alter Implements hook_form_alter().
discussthis_help Implements hook_help().
discussthis_menu Implements hook_menu().
discussthis_permission Implements hook_permission().
discussthis_theme Implements hook_theme().

Constants