You are here

function drupalchat_settings_form in DrupalChat 6.2

Same name and namespace in other branches
  1. 6 includes/drupalchat.admin.inc \drupalchat_settings_form()
  2. 7.2 drupalchat.admin.inc \drupalchat_settings_form()
  3. 7 drupalchat.admin.inc \drupalchat_settings_form()

Callback for admin/settings/drupalchat.

1 string reference to 'drupalchat_settings_form'
drupalchat_menu in ./drupalchat.module
Implementaiton of hook_menu()

File

./drupalchat.admin.inc, line 34
Administrative functions to configure DrupalChat.

Code

function drupalchat_settings_form() {
  drupal_add_css('misc/farbtastic/farbtastic.css');
  drupal_add_js('misc/farbtastic/farbtastic.js');
  drupal_add_js(drupal_get_path('module', 'drupalchat') . '/js/drupalchat.admin.js', 'module', 'footer');

  /*
  drupalchat_yui_path();
  if ((variable_get('drupalchat_yui_use_cdn', 1) == 2) && (!variable_get('drupalchat_yui_path', NULL))) {
    drupal_set_message(t("You need to download the latest stable release of the !library and extract the entire folder into sites/all/libraries.", array('!library' => l(t('YUI library'), 'http://developer.yahoo.com/yui/3/', array('attributes' => array('target' => '_blank'))))));
  }
  */
  $seconds = array(
    1 => 1,
    2 => 2,
    3 => 3,
    4 => 4,
    5 => 5,
    6 => 6,
    7 => 7,
    8 => 8,
    9 => 9,
    10 => 10,
    11 => 11,
    12 => 12,
    13 => 13,
    14 => 14,
    15 => 15,
    16 => 16,
    17 => 17,
    18 => 18,
    19 => 19,
    20 => 20,
  );
  $themes = _drupalchat_load_themes(drupal_get_path('module', 'drupalchat') . '/themes', 'css');
  $polling_method = variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX);
  if ($polling_method == DRUPALCHAT_LONGPOLL && ini_get('max_execution_time') < 30) {
    drupal_set_message(t('For DrupalChat Long Polling to be effective, please set max_execution_time to above 30 in your server php.ini file.'), 'warning');
  }
  $form = array();

  /*$form['libraries'] = array(
      '#type' => 'fieldset',
      '#title' => t('Library info'),
      '#collapsible' => TRUE,
    );
    $form['libraries']['yui'] = array(
      '#type' => 'fieldset',
      '#title' => t('YUI'),
      '#collapsible' => TRUE,
    );
    $form['libraries']['yui']['drupalchat_yui_use_cdn'] = array(
      '#type' => 'select',
      '#title' => t('Load YUI library from Yahoo CDN'),
      '#collapsible' => TRUE,
  	'#options' => array(1 => 'Yes', 2 => 'No, load from my server'),
      '#default_value' => variable_get('drupalchat_yui_use_cdn', 1),
    );
    $form['libraries']['yui']['drupalchat_yui_path'] = array(
      '#type' => 'textfield',
      '#title' => t('YUI library path on your server'),
      '#description' => t("You need to download the latest stable release of the !library and extract the entire folder into sites/all/libraries. The path will be automatically discovered; you may override the directory path here if you wish to use another version; do not add slashes before or after the path.", array('!library' => l(t('YUI library'), 'http://developer.yahoo.com/yui/3/', array('attributes' => array('target' => '_blank'))))),
      '#default_value' => variable_get('drupalchat_yui_path',NULL),
    );
    */
  $form['drupalchat_general'] = array(
    '#type' => 'fieldset',
    '#title' => t('DrupalChat General Settings'),
    '#collapsible' => TRUE,
  );
  $form['drupalchat_general']['drupalchat_polling_method'] = array(
    '#type' => 'radios',
    '#title' => t('Choose Polling Method'),
    '#default_value' => variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX),
    '#options' => array(
      DRUPALCHAT_COMMERCIAL => t('iFlyChat server'),
      DRUPALCHAT_AJAX => t('Normal AJAX'),
      DRUPALCHAT_LONGPOLL => t('Long Polling'),
      DRUPALCHAT_NODEJS => t('Node.js (currently under development)'),
    ),
    '#description' => t('Decide the server backend for Drupal Chat.'),
  );
  $form['drupalchat_general']['drupalchat_app_id'] = array(
    '#type' => 'textfield',
    '#title' => t('iFlyChat APP ID'),
    '#description' => t("Please enter the APP ID by registering at !elink.", array(
      '!elink' => l(t('iFlyChat.com'), 'https://iflychat.com', array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )),
    )),
    '#default_value' => variable_get('drupalchat_app_id', NULL),
  );
  $form['drupalchat_general']['drupalchat_external_api_key'] = array(
    '#type' => 'textfield',
    '#title' => t('iFlyChat API Key'),
    '#description' => t("Please enter the API key by registering at !elink.", array(
      '!elink' => l(t('iFlyChat.com'), 'https://iflychat.com', array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )),
    )),
    '#default_value' => variable_get('drupalchat_external_api_key', NULL),
  );
  $form['drupalchat_general']['drupalchat_theme'] = array(
    '#type' => 'select',
    '#title' => t('Theme'),
    '#description' => t('All themes from inside the <em>themes</em> folder will be displayed here.'),
    '#options' => $themes,
    '#default_value' => variable_get('drupalchat_theme', 'light'),
  );
  $form['drupalchat_general']['drupalchat_notification_sound'] = array(
    '#type' => 'select',
    '#title' => t('Notification Sound'),
    '#description' => t('Select whether to play notification sound when a new message is received.'),
    '#options' => array(
      1 => 'Yes',
      2 => 'No',
    ),
    '#default_value' => variable_get('drupalchat_notification_sound', 1),
  );
  $form['drupalchat_general']['drupalchat_user_picture'] = array(
    '#type' => 'select',
    '#title' => t('User Pictures'),
    '#description' => t('Select whether to show user pictures in chat.'),
    '#options' => array(
      1 => 'Yes',
      2 => 'No',
    ),
    '#default_value' => variable_get('drupalchat_user_picture', 1),
  );
  $form['drupalchat_general']['drupalchat_enable_smiley'] = array(
    '#type' => 'select',
    '#title' => t('Enable Smileys'),
    '#description' => t('Select whether to show smileys.'),
    '#options' => array(
      1 => 'Yes',
      2 => 'No',
    ),
    '#default_value' => variable_get('drupalchat_enable_smiley', 1),
  );
  $form['drupalchat_general']['drupalchat_log_messages'] = array(
    '#type' => 'select',
    '#title' => t('Log chat messages'),
    '#description' => t('Select whether to log chat messages, which can be later viewed in !inbox_link.', array(
      '!inbox_link' => l(t('message inbox'), 'drupalchat/messages/inbox'),
    )),
    '#options' => array(
      1 => 'Yes',
      2 => 'No',
    ),
    '#default_value' => variable_get('drupalchat_log_messages', 1),
  );
  $form['drupalchat_general']['drupalchat_anon_prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Prefix to be used with anonymous users'),
    '#description' => t("Please specify the prefix to be used with anonymous users. It shouldn't be long. Ideally it should be between 4 to 7 characters."),
    '#default_value' => variable_get('drupalchat_anon_prefix', 'Guest'),
  );
  $form['drupalchat_general']['drupalchat_anon_use_name'] = array(
    '#type' => 'select',
    '#title' => t('Use random name or number for anonymous user'),
    '#description' => t('Select whether to use random generated name or number to assign to a new anonymous user'),
    '#options' => array(
      1 => 'Name',
      2 => 'Number',
    ),
    '#default_value' => variable_get('drupalchat_anon_use_name', 1),
  );
  $form['drupalchat_general']['drupalchat_user_latency'] = array(
    '#type' => 'select',
    '#title' => t('Chat List Latency'),
    '#description' => t('The delay, in seconds, after which the user will be shown offline in the chat list(i.e. removed from the chat list) from the time he/she goes offline. Increase this value if you find the chat list is unstable and keeps on changing a lot (for example - when a user navigates from one page to another he/she goes offline and then comes back online again). Decrease it if you find that the users are shown in the chat list for too long after they have left your website.'),
    '#options' => $seconds,
    '#default_value' => variable_get('drupalchat_user_latency', 20),
  );
  $form['drupalchat_general']['drupalchat_refresh_rate'] = array(
    '#type' => 'select',
    '#title' => t('Normal AJAX Refesh Rate'),
    '#description' => t('The time interval, in seconds, after which DrupalChat checks for new messages.'),
    '#options' => $seconds,
    '#default_value' => variable_get('drupalchat_refresh_rate', 2),
    '#disabled' => variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX) == DRUPALCHAT_LONGPOLL ? TRUE : FALSE,
  );
  $form['drupalchat_general']['drupalchat_send_rate'] = array(
    '#type' => 'select',
    '#title' => t('Normal AJAX Send message delay'),
    '#description' => t('The delay, in seconds, to send a message to the server.'),
    '#options' => $seconds,
    '#default_value' => variable_get('drupalchat_send_rate', 2),
    '#disabled' => variable_get('drupalchat_polling_method', DRUPALCHAT_AJAX) == DRUPALCHAT_LONGPOLL ? TRUE : FALSE,
  );
  $form['drupalchat_pc'] = array(
    '#type' => 'fieldset',
    '#title' => t('Chat Moderation'),
    '#collapsible' => TRUE,
  );
  $form['drupalchat_pc']['drupalchat_enable_chatroom'] = array(
    '#type' => 'radios',
    '#title' => t('Enable Public Chatroom'),
    '#default_value' => variable_get('drupalchat_enable_chatroom', 1),
    '#options' => array(
      1 => 'Yes',
      2 => 'No',
    ),
  );
  $form['drupalchat_path'] = array(
    '#type' => 'fieldset',
    '#title' => t('DrupalChat Visibility'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['drupalchat_path']['drupalchat_show_embed_chat'] = array(
    '#type' => 'item',
    '#title' => t("Show Embed Chat"),
    '#description' => t("Click on the !elink to view the tutorial of embedding the chat onto a page.", array(
      '!elink' => l(t('link'), 'https://iflychat.com/embedded-chatroom-example-public-chatroom', array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )),
    )),
  );
  $access = user_access('use PHP for settings');
  $options = array(
    0 => t('All pages except those listed'),
    1 => t('Only the listed pages'),
  );
  $description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
    '%blog' => 'blog',
    '%blog-wildcard' => 'blog/*',
    '%front' => '<front>',
  ));
  if (module_exists('php') && $access) {
    $options += array(
      2 => t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'),
    );
    $title = t('Pages or PHP code');
    $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array(
      '%php' => '<?php ?>',
    ));
  }
  else {
    $title = t('Pages');
  }
  $form['drupalchat_path']['drupalchat_path_visibility'] = array(
    '#type' => 'radios',
    '#title' => t('Show DrupalChat on specific pages'),
    '#options' => $options,
    '#default_value' => variable_get('drupalchat_path_visibility', 0),
  );
  $form['drupalchat_path']['drupalchat_path_pages'] = array(
    '#type' => 'textarea',
    '#title' => '<span>' . $title . '</span>',
    '#default_value' => variable_get('drupalchat_path_pages', NULL),
    '#description' => $description,
  );
  $form['drupalchat_chatlist_cont'] = array(
    '#type' => 'fieldset',
    '#title' => t('DrupalChat User Online List Control'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['drupalchat_chatlist_cont']['drupalchat_rel'] = array(
    '#type' => 'radios',
    '#title' => t('Relationship method'),
    '#default_value' => variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH),
    '#options' => array(
      DRUPALCHAT_REL_AUTH => t('All users'),
    ),
    '#description' => t('This determines the method for creating the chat buddylist.'),
  );
  if (module_exists('user_relationships_api')) {
    $form['drupalchat_chatlist_cont']['drupalchat_rel']['#options'][DRUPALCHAT_REL_UR] = t('User Relationship module');
  }
  if (module_exists('flag_friend')) {
    $form['drupalchat_chatlist_cont']['drupalchat_rel']['#options'][DRUPALCHAT_REL_FF] = t('Flag Friend module');
  }
  $form['drupalchat_chatlist_cont']['drupalchat_ur_name'] = array(
    '#type' => 'textfield',
    '#title' => t('User Relationships Role Names to integrate with'),
    '#description' => t('The singular form of User Relationships Role Names (e.g. buddy, friend, coworker, spouse) separated by comma.'),
    '#default_value' => variable_get('drupalchat_ur_name', NULL),
    '#autocomplete_path' => 'drupalchat/ur-autocomplete',
  );
  return system_settings_form($form);
}