You are here

function _language_sections_settings in Language Sections 6.2

Same name and namespace in other branches
  1. 5 language_sections.module \_language_sections_settings()
  2. 6 language_sections.module \_language_sections_settings()
  3. 7.2 language_sections.module \_language_sections_settings()
1 call to _language_sections_settings()
language_sections_filter in ./language_sections.module

File

./language_sections.module, line 209

Code

function _language_sections_settings($mod_name, $mod_prefix) {

  //require_once(dirname(__FILE__) . '/help.html');
  global $language;
  $textsize = 30;

  // Get $elements and $specials.
  extract(_language_sections_context());

  // Create collapsible section for this module in the filters configuration form.
  $section =& $form[$mod_name];
  $shared = _language_sections_setting($mod_prefix, 'shared');
  $section = array(
    '#type' => 'fieldset',
    '#title' => $shared ? sprintf('%s (%s)', t($mod_name), t('shared configuration')) : t($mod_name),
    '#collapsible' => TRUE,
  );

  /*
  $section['help'] = array(
    '#type' => 'markup',
    '#value' => '<p>Help goes here.</p>',
  );
  */
  $fieldset =& $section['triggers'];
  $fieldset = array(
    '#type' => 'fieldset',
    '#title' => t('Current language triggers'),
    '#description' => t('Which elements from current language can be used in language-section markers?'),
  );

  // Create a checkbox for each $element.
  $title = '%element';
  $desc = 'Language:%element is currently %value.';
  foreach ($elements as $element) {
    $key = 'trigger_' . $element;
    $tvars = array(
      '%element' => $element,
      '%value' => $language->{$element} ? $language->{$element} : t('<blank>'),
    );
    $fieldset[$mod_prefix . $key] = array(
      '#type' => 'checkbox',
      '#title' => t($title, $tvars),
      '#default_value' => _language_sections_setting($mod_prefix, $key),
      '#description' => t($desc, $tvars),
    );
  }

  // Create an entry field for special codes ("all" and "other").
  $examples = array(
    'all' => 'all|todos|toutes',
    'other' => 'english|other|otro|autre',
  );
  foreach ($specials as $type => $desc) {
    $key = 'trigger_special_' . $type;
    $tvars = array(
      '%desc' => $desc,
      '%ex' => t($examples[$type]),
    );
    $section[$mod_prefix . $key] = array(
      '#type' => 'textfield',
      '#title' => t('Triggers for %desc sections', $tvars),
      '#size' => $textsize,
      '#default_value' => _language_sections_setting($mod_prefix, $key),
      '#description' => t('Text that may mark an %desc section. Leave blank to disable, multiple entries allowed, e.g: %ex', $tvars),
    );
  }
  $fieldset =& $section['advanced'];
  $fieldset = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $key = 'shared';
  $fieldset[$mod_prefix . $key] = array(
    '#type' => 'checkbox',
    '#title' => t('Shared configuration'),
    '#default_value' => $shared,
    '#description' => t('Use the same configuration for all filters. If you change this, save and then check all configuration values.'),
  );
  $key = 'short_help';
  $fieldset[$mod_prefix . $key] = array(
    '#type' => 'textarea',
    '#title' => t('User help'),
    '#rows' => 2,
    '#default_value' => _language_sections_setting($mod_prefix, $key),
    '#description' => t('Filter-help shown to the user. This text is passed through t().'),
  );
  $key = 'alt';
  $use_alt = _language_sections_setting($mod_prefix, $key);
  $fieldset[$mod_prefix . $key] = array(
    '#type' => 'checkbox',
    '#title' => t('Use alternative pattern'),
    '#default_value' => $use_alt,
    '#description' => t('If set, sections can be defined using the pattern given below. Otherwise, the default pattern will be used.'),
  );
  $key = 'pattern';

  // Update stored pattern if we need to.
  if (!$use_alt && variable_get($mod_prefix . $key, FALSE)) {
    variable_del($mod_prefix . $key);
  }
  $pattern = _language_sections_setting($mod_prefix, $key);
  $fieldset[$mod_prefix . $key] = array(
    '#type' => 'textfield',
    '#title' => t('Alternative pattern'),
    '#size' => 40,
    '#default_value' => $pattern,
    '#description' => t('If enabled above, this pattern will be used for finding sections in the text.' . ' Initially, this is set to the module\'s internal default.' . ' You should not change the number of parenthesised groups in the expression.'),
  );

  // Display a message showing whether caching is enabled (patch installed.)
  $msg = array(
    'Patch for $func is not installed - output cannot be cached. See included README.txt',
    'Patch for $func is installed - output can be cached.',
  );
  $fieldset['cache'] = array(
    '#type' => 'fieldset',
    '#title' => t('Output caching'),
    'msg' => array(
      '#value' => t($msg[defined('check_markup_language_patch_1')], array(
        '$func' => 'check_markup()',
      )),
    ),
  );

  // If form is being posted, process new settings.
  if (!empty($_POST)) {

    // Rebuild stored triggers.
    foreach (language_list() as $lang) {
      _language_sections_get_triggers($mod_prefix, $lang, TRUE);
    }
  }
  return $form;
}