You are here

function shoutbox_admin_settings in Shoutbox 7.2

Same name and namespace in other branches
  1. 5 shoutbox.module \shoutbox_admin_settings()
  2. 6.2 shoutbox.pages.inc \shoutbox_admin_settings()
  3. 6 shoutbox.module \shoutbox_admin_settings()
  4. 7 shoutbox.pages.inc \shoutbox_admin_settings()

Admin settings form.

1 string reference to 'shoutbox_admin_settings'
shoutbox_menu in ./shoutbox.module
Implements hook_menu().

File

./shoutbox.pages.inc, line 11
Page callbacks for the shoutbox module.

Code

function shoutbox_admin_settings($form, &$form_state) {

  //add css to admin section
  drupal_add_css(drupal_get_path('module', 'shoutbox') . '/shoutbox.css');
  $form['display_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Display settings'),
    '#collapsible' => TRUE,
  );
  $form['display_settings']['shoutbox_max_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum amount of characters in a shout'),
    '#default_value' => variable_get('shoutbox_max_length', 255),
    '#size' => 5,
    '#required' => TRUE,
    '#description' => t('Set the amount of allowed characters per shout. Enter 0 for no limit. This will not affect existing shouts.'),
  );
  $form['display_settings']['shoutbox_showamount_block'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of posts to show in the block'),
    '#default_value' => variable_get('shoutbox_showamount_block', 10),
    '#size' => 4,
    '#maxlength' => 4,
    '#required' => TRUE,
    '#description' => t('Set the number of shoutbox posts to show in the block.'),
  );
  $form['display_settings']['shoutbox_showamount_page'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of posts to show on the page'),
    '#default_value' => variable_get('shoutbox_showamount_page', 30),
    '#size' => 4,
    '#maxlength' => 4,
    '#required' => TRUE,
    '#description' => t('Set the number of shoutbox posts to show on the page.'),
  );
  $form['display_settings']['shoutbox_ascending'] = array(
    '#type' => 'checkbox',
    '#title' => t('Post newest shouts on top'),
    '#default_value' => variable_get('shoutbox_ascending', 1),
    '#description' => t('When checked, new shouts will appear on the top instead of the bottom.'),
  );
  $form['display_settings']['shoutbox_defaultname'] = array(
    '#type' => 'checkbox',
    '#title' => t('Default the name field to the logged in user name'),
    '#default_value' => variable_get('shoutbox_defaultname', 1),
    '#description' => t('When checked, "Your name/nick" will be replaced by the logged in user name'),
  );
  $form['display_settings']['shoutbox_widget_type'] = array(
    '#type' => 'radios',
    '#title' => t('Input form type'),
    '#default_value' => variable_get('shoutbox_widget_type', 'textfield'),
    '#description' => t('Choose the type of form widget used for entering a shout.'),
    '#options' => array(
      'textfield' => t('Textfield'),
      'textarea' => t('Textarea'),
    ),
  );
  $form['display_settings']['shoutbox_submit_type'] = array(
    '#type' => 'radios',
    '#title' => t('Sumbission type'),
    '#default_value' => variable_get('shoutbox_submit_type', 'post'),
    '#description' => t('Choose the type of submission used for a shout. <br/><small>Please note that "Ajax" submission does not cooperate(yet) with captcha module</small>'),
    '#options' => array(
      'ajax' => t('Ajax'),
      'post' => t('Post'),
    ),
  );

  // set the default message of the shoutfield
  $form['display_settings']['shoutbox_default_message'] = array(
    '#type' => 'textfield',
    '#title' => t('The default message of the shoutfield'),
    '#default_value' => variable_get('shoutbox_default_message', DEFAULTMSGTEXT),
    '#size' => 60,
    '#maxlength' => 255,
    '#required' => FALSE,
    '#description' => t("Set the default message in the inputfield of the shoutbox. If you don't want to show a message, leave this input field empty."),
    '#attributes' => array(
      'class' => array(
        'shoutbox_default_message',
      ),
    ),
  );
  $form['display_settings']['shoutbox_time_format'] = array(
    '#type' => 'select',
    '#title' => t('Time format'),
    '#default_value' => variable_get('shoutbox_time_format', 'ago'),
    '#description' => t('Choose the format which shout times will be rendered in.'),
    '#options' => array(
      'ago' => t('Time ago (1 hour 15 minutes ago)'),
      'small' => t('Small !time', array(
        '!time' => '(' . format_date(REQUEST_TIME, 'short') . ')',
      )),
      'medium' => t('Medium !time', array(
        '!time' => '(' . format_date(REQUEST_TIME, 'medium') . ')',
      )),
      'large' => t('Large !time', array(
        '!time' => '(' . format_date(REQUEST_TIME, 'long') . ')',
      )),
    ),
  );
  $form['display_settings']['shoutbox_restrict_general_shouts'] = array(
    '#type' => 'checkbox',
    '#title' => t('Restrict general shouts'),
    '#default_value' => variable_get('shoutbox_restrict_general_shouts', 1),
    '#description' => t('When checked, shoutboxes outside of specific contexts will be restricted to general shouts. There are modules that utilize the Shoutbox API, such as Shoutbox group, that will enter shouts meant to only be displayed in certain locations. Checking this will insure that those shouts are only displayed by the modules responsible for creating them.'),
  );
  $choices = array();

  // Generate choices for profile fields or custom fields for user
  if (module_exists('profile') && db_table_exists('profile_field')) {
    $fields = db_query("SELECT name FROM {profile_field} ORDER BY name ASC");
    foreach ($fields as $field) {
      $choices['profile!' . $field->name] = $field->name;
    }
    $form['display_settings']['shoutbox_profile_name'] = array(
      '#type' => 'select',
      '#title' => t('Use profile field for user name'),
      '#options' => array(
        0 => '- None -',
      ) + $choices,
      '#default_value' => variable_get('shoutbox_profile_name', 0),
      '#description' => t('Select an existing custom profile field to use as the user name.'),
    );
  }
  elseif (db_table_exists('field_config') && db_table_exists('field_config_instance')) {
    $fields = db_query("SELECT fi.field_name,fi.id FROM {field_config} as f,{field_config_instance} as fi\n                          WHERE f.id=fi.field_id AND f.type='text'\n                          AND fi.entity_type='user' AND fi.bundle='user' ORDER BY field_name ASC");
    foreach ($fields as $field) {
      $field_name = str_replace("field_", "", $field->field_name);
      $choices['custom<split>' . $field_name] = $field_name;
    }
  }

  //if custom fields found add select box
  if (count($choices) > 0) {
    $form['display_settings']['shoutbox_profile_name'] = array(
      '#type' => 'select',
      '#title' => t('Use profile field for user name'),
      '#options' => array(
        0 => '- None -',
      ) + $choices,
      '#default_value' => variable_get('shoutbox_profile_name', 0),
      '#description' => t('Select an existing custom profile field to use as the user name or select - None - for the regular username.'),
    );
  }
  else {
    $form['display_settings']['shoutbox_profile_name'] = array(
      '#type' => 'item',
      '#title' => t('Use custom field for user name'),
      '#description' => t('Add custom field in <a href="@page_url">Account Setting</a> or enable the profile module to allow
                            Shoutbox to use different field instead of the username.', array(
        '@page_url' => '../people/accounts/fields',
      )),
    );
  }
  $form['display_settings']['shoutbox_replace_shout'] = array(
    '#type' => 'item',
    '#title' => t('Change "shout" globally'),
    '#description' => t('Set replacement for "shout". Does not apply to admin section. (Please use lowercase letters e.g. shout,shouts)'),
  );
  $form['display_settings']['shoutbox_replace_shout']['shoutbox_replace_singular'] = array(
    '#type' => 'textfield',
    '#title' => t('Singular'),
    '#default_value' => variable_get('shoutbox_replace_singular', 'shout'),
    '#size' => 15,
    '#required' => FALSE,
    '#attributes' => array(
      'class' => array(
        'shoutbox_replace',
      ),
    ),
  );
  $form['display_settings']['shoutbox_replace_shout']['shoutbox_replace_plural'] = array(
    '#type' => 'textfield',
    '#title' => t('Plural'),
    '#default_value' => variable_get('shoutbox_replace_plural', 'Shout'),
    '#size' => 15,
    '#required' => FALSE,
    '#attributes' => array(
      'class' => array(
        'shoutbox_replace',
      ),
    ),
  );

  // TODO: Figure out how to create a form for filter

  /* $form['shoutbox_filter_format'] = _shoutbox_filter_form(); */

  /* $form['shoutbox_filter_format']['#collapsed'] = FALSE; */

  /* $form['shoutbox_filter_format']['shoutbox_escape_html'] = array( */

  /*   '#type' => 'checkbox', */

  /*   '#title' => t('Escape all HTML & formatting'), */

  /*   '#default_value' => variable_get('shoutbox_escape_html', 1), */

  /*   '#description' => '<strong>' . t('Checking this will ignore the input format selected below, and escape all HTML from the shouts.') . '</strong>', */

  /*   '#weight' => -10, */

  /* ); */
  $form['time_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Time settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['time_settings']['shoutbox_refresh'] = array(
    '#type' => 'textfield',
    '#title' => t('Auto refresh (in seconds)'),
    '#default_value' => shoutbox_get_refresh_rate(),
    '#size' => 4,
    '#maxlength' => 4,
    '#description' => t('Shoutbox can be set to automatically refresh every x number of seconds.  Set to 0 to turn off the auto refresh.'),
  );
  $form['time_settings']['shoutbox_anonymous_timeout'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of minutes for which anonymous users may edit or delete their own posts'),
    '#default_value' => variable_get('shoutbox_anonymous_timeout', 20),
    '#size' => 4,
    '#maxlength' => 4,
    '#description' => t('Anonymous users can edit or delete their post within this amount of time from it being posted, as long as they have the same IP address as when they posted it.  If you don\'t want shout editing and/or deleting, remove these permissions from Drupal\'s anonymous users role. Set 0 for no limit.'),
  );
  $form['time_settings']['shoutbox_registered_timeout'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of minutes for which registered users may edit or delete their own posts'),
    '#default_value' => variable_get('shoutbox_registered_timeout', 0),
    '#size' => 4,
    '#maxlength' => 4,
    '#description' => t('Registered users can edit or delete their post within this amount of time from it being posted.  If you don\'t want editing and/or deleting, remove these permissions from Drupal\'s authenticated users role. Set 0 for no limit.'),
  );
  $form['time_settings']['shoutbox_expire'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of days after which shouts will be purged from the database'),
    '#default_value' => variable_get('shoutbox_expire', 0),
    '#size' => 4,
    '#maxlength' => 4,
    '#description' => t('Shouts will be permanently deleted after the number of days specified.  Shouts will never expire when this is set to 0.'),
  );
  return system_settings_form($form);
}