You are here

function glossify_admin_settings in Glossify 6.3

Same name and namespace in other branches
  1. 5 glossify.module \glossify_admin_settings()
  2. 6 glossify.admin.inc \glossify_admin_settings()

Form builder for administrative settings.

1 string reference to 'glossify_admin_settings'
glossify_menu in ./glossify.module
Implementation of hook_menu().

File

./glossify.admin.inc, line 14
Glossify Administration

Code

function glossify_admin_settings() {
  $conf_key = arg(3);
  if (empty($conf_key)) {
    $conf_key = 'global';
  }
  $configurations = variable_get('glossify_configurations', NULL);
  $configuration = $configurations[$conf_key];
  $form['config_id'] = array(
    '#type' => 'hidden',
    '#value' => $conf_key,
  );
  if ($conf_key !== 'global') {
    $form['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Configuration name'),
      '#description' => t('The name that will be displayed on the tab.'),
      '#default_value' => $conf_key !== 'add' ? $conf_key : '',
    );
  }
  else {
    $form['glossify_mode'] = array(
      '#type' => 'radios',
      '#title' => 'Filter mode',
      '#default_value' => variable_get('glossify_process_mode', GLOSSIFY_USE_FILTER),
      '#options' => array(
        t('Use input format filtering'),
        t('Glossify without filters'),
        t('Glossify without filters - omit comments'),
      ),
      '#description' => t('Using a filter may be faster due to caching but will always process comments.'),
      '#weight' => -40,
    );
  }
  $form['from'] = array(
    '#type' => 'select',
    '#title' => t('Content types to be filtered'),
    '#multiple' => TRUE,
    '#options' => node_get_types('names'),
    '#default_value' => $configuration['from'],
    '#description' => t('Glossify looks into their text for keywords and replaces them with links.'),
  );
  $form['to'] = array(
    '#type' => 'select',
    '#title' => t('Target content types.'),
    '#multiple' => TRUE,
    '#options' => node_get_types('names'),
    '#default_value' => $configuration['to'],
    '#description' => t('The source(s) for the keywords.'),
  );
  $form['style'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Style of glossary terms.'),
    '#options' => array(
      'hovertip' => t('Hovertips'),
      'links' => t('Links'),
      'reference' => t('Reference section under content'),
    ),
    '#default_value' => isset($configuration['style']) ? $configuration['style'] : array(),
    '#description' => t('How the glossary should be styled. Note: "hovertip" style requires hovertip.module. If you choose anything other than links - it should work but for now it is untested territory - feedback welcome.'),
  );
  $form['switches'] = array(
    '#type' => 'fieldset',
    '#title' => t('Switches'),
    '#collapsible' => TRUE,
  );
  $form['switches']['only_first'] = array(
    '#type' => 'checkbox',
    '#title' => t('Only link first occurance of term. On by default. If unchecked all occurences are replaced.'),
    '#default_value' => $configuration['only_first'],
  );
  $form['switches']['unicode'] = array(
    '#type' => 'checkbox',
    '#title' => t('Unicode compatibility.'),
    '#default_value' => $configuration['unicode'],
    '#description' => t('If you get php warnings from this setting, try updating your PCRE PHP-library.'),
  );
  $form['switches']['break'] = array(
    '#type' => 'checkbox',
    '#title' => t('Check this to NOT break words.'),
    '#default_value' => $configuration['break'],
    '#description' => t('Example: "ship" will not linkify "shipyard", "starship", ...'),
  );
  $form['switches']['case_insensitivity'] = array(
    '#type' => 'checkbox',
    '#title' => t('Case insensitivity.'),
    '#default_value' => isset($configuration['case_insensitivity']) ? $configuration['case_insensitivity'] : FALSE,
    '#description' => t('Example: "drupal" will also linkify "Drupal".'),
  );
  $form['switches']['link_self'] = array(
    '#type' => 'checkbox',
    '#title' => t('Link to self.'),
    '#default_value' => isset($configuration['link_self']) ? $configuration['link_self'] : FALSE,
  );
  $form['switches']['language'] = array(
    '#type' => 'checkbox',
    '#title' => t('Link only to same language.'),
    '#default_value' => $configuration['language'],
  );
  $form['switches']['teaser'] = array(
    '#type' => 'checkbox',
    '#title' => t('Link content in teaser'),
    '#default_value' => $configuration['teaser'],
    '#description' => t('Currently disfunctional.'),
  );
  $form['methods'] = array(
    '#type' => 'fieldset',
    '#title' => t('Methods'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['methods']['use_title'] = array(
    '#type' => 'checkbox',
    '#title' => t('Make use of the title field of a node.'),
    '#default_value' => $configuration['methods']['use_title'],
  );
  $form['methods']['internal'] = array(
    '#type' => 'fieldset',
    '#title' => t('Internal'),
    '#collapsible' => TRUE,
    '#collapsed' => $configuration['methods']['use_internal'] ? FALSE : TRUE,
  );
  $form['methods']['internal']['use_internal'] = array(
    '#type' => 'checkbox',
    '#title' => t('Attach 2 additional fields to the selected Node types.'),
    '#default_value' => $configuration['methods']['use_internal'],
  );
  if (!module_exists('content')) {
    $form['methods']['cck'] = array(
      '#value' => t('If you wish to use CCK Fields for your Keywords get the <a href="http://drupal.org/project/cck">CCK module</a>.'),
    );
  }
  else {
    foreach (array_keys(content_fields()) as $key) {
      $all_cck_field_names[$key] = $key;
    }
    $all_cck_field_names['none'] = 'none';
    $form['methods']['cck'] = array(
      '#type' => 'fieldset',
      '#title' => t('CCK'),
      '#collapsible' => TRUE,
      '#collapsed' => $configuration['methods']['use_cck'] ? FALSE : TRUE,
    );
    $form['methods']['cck']['use_cck'] = array(
      '#type' => 'checkbox',
      '#title' => t('Make use of CCK.'),
      '#description' => t('This is mostly here to provide compatibility with older versions, but it can also be used in conjunction with the module-internal fields.'),
      '#default_value' => $configuration['methods']['use_cck'],
    );
    $form['methods']['cck']['keyword_field'] = array(
      '#type' => 'select',
      '#title' => t("CCK field to look into for synonyms of the node's title. For more than 1 content type - use the same cck field please."),
      '#options' => $all_cck_field_names,
      '#default_value' => isset($configuration['methods']['keyword_field']) || !empty($configuration['methods']['keyword_field']) ? $configuration['methods']['keyword_field'] : NULL,
      '#description' => t('Select a CCK field for synonyms.'),
    );
    $form['methods']['cck']['override_field'] = array(
      '#type' => 'select',
      '#title' => t("CCK field to look into for a 'target url override'. For more than 1 content type - use the same cck field please."),
      '#options' => $all_cck_field_names,
      '#default_value' => isset($configuration['methods']['override_field']) || !empty($configuration['methods']['override_field']) ? $configuration['methods']['override_field'] : NULL,
      '#description' => t("Select a CCK field for target override.  After you create the cck field and then put something into it\n        Example: 'node/34', 'url_alias', 'http://example.com/path' this will make the target url point to your override path."),
    );
  }
  if (!module_exists('taxonomy')) {
    $form['methods']['taxonomy'] = array(
      '#value' => t('In order to use a Vocabulary for your Keywords you need to enable the Taxonomy module.'),
    );
  }
  else {
    $vocabularies = array();
    foreach (taxonomy_get_vocabularies() as $vid => $voc) {
      $vocabularies[$vid] = $voc->name;
    }
    $form['methods']['taxonomy'] = array(
      '#type' => 'fieldset',
      '#title' => t('Taxonomy'),
      '#collapsible' => TRUE,
      '#collapsed' => $configuration['methods']['use_taxonomy'] ? FALSE : TRUE,
    );
    $form['methods']['taxonomy']['use_taxonomy'] = array(
      '#type' => 'checkbox',
      '#title' => t('Make use of Taxonomy.'),
      '#description' => t('Note that you also have to attach the selected Vocabulary to the selected content types.'),
      '#default_value' => $configuration['methods']['use_taxonomy'],
    );
    $form['methods']['taxonomy']['vocabulary'] = array(
      '#type' => 'select',
      '#title' => t("Vocabulary to look into for synonyms of the node's title."),
      '#multiple' => TRUE,
      '#options' => $vocabularies,
      '#default_value' => $configuration['methods']['vocabulary'],
      '#description' => t('Select a Vocabulary for synonyms.'),
    );
    $form['methods']['taxonomy']['link_term'] = array(
      '#type' => 'checkbox',
      '#title' => t('Link to term instead of node.'),
      '#default_value' => isset($configuration['methods']['link_term']) ? $configuration['methods']['link_term'] : FALSE,
    );
  }
  $form['excl'] = array(
    '#type' => 'fieldset',
    '#title' => t('Exclude/Include'),
    '#collapsible' => TRUE,
    '#collapsed' => empty($configuration['excl_tags']) ? TRUE : FALSE,
  );
  $form['excl']['excl_mode'] = array(
    '#type' => 'select',
    '#title' => t('Use Exclude- or Include-Method'),
    '#options' => array(
      t('Exclude'),
      t('Include'),
    ),
    '#default_value' => isset($configuration['excl_mode']) ? $configuration['excl_mode'] : '',
  );
  $form['excl']['excl_tags'] = array(
    '#type' => 'textarea',
    '#title' => t('Tags to exclude/include.'),
    '#default_value' => isset($configuration['excl_tags']) ? $configuration['excl_tags'] : '',
    '#description' => t('One tag per line, or comma seperated.'),
  );
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  if (in_array($conf_key, array(
    'add',
    'global',
  ))) {
    $form['buttons']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset to defaults'),
    );
  }
  if ($conf_key !== 'add' && $conf_key !== 'global') {
    $form['buttons']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete configuration'),
    );
  }
  if (!empty($_POST) && form_get_errors()) {
    drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
  }
  $form['#validate'][] = 'glossify_admin_settings_validate';
  $form['#submit'][] = 'glossify_admin_settings_submit';
  $form['#theme'] = 'system_settings_form';
  return $form;
}