You are here

function _typogrify_settings in Typogrify 6

Same name and namespace in other branches
  1. 5 typogrify.module \_typogrify_settings()
  2. 7 typogrify.module \_typogrify_settings()

Typogrify filter settings form.

Parameters

integer $format: ID if the input format to generate a settings form for.

Return value

array Form API array containing our settings form.

1 call to _typogrify_settings()
typogrify_filter in ./typogrify.module
Implementation of hook_filter().

File

./typogrify.module, line 163
typogrify.module Typogrify: Brings typographical refinemnts to drupal

Code

function _typogrify_settings($format) {
  module_load_include('class.php', 'typogrify');
  module_load_include('php', 'typogrify', 'unicode-conversion');
  if (!function_exists('smartypants')) {
    module_load_include('php', 'typogrify', 'smartypants');
  }

  // Load the Typogrify settings through a helper function.
  $settings = _typogrify_get_settings($format);
  $fieldset = array(
    '#type' => 'fieldset',
    '#title' => t('Typogrify'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );
  $fieldset['help'] = array(
    '#type' => 'markup',
    '#value' => '<p>Enable the following typographic refinements:</p>',
  );

  // Smartypants settings.
  $fieldset['smartypants_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use typographers quotation marks and dashes (!smartylink)', array(
      '!smartylink' => l('SmartyPants', 'http://daringfireball.net/projects/smartypants/'),
    )),
    '#default_value' => $settings['smartypants_enabled'],
  );

  // Smartypants hyphenation settings.
  // Uses the same values as the parse attributes in the SmartyPants
  // function (@see SmartyPants in smartypants.php)
  $fieldset['smartypants_hyphens'] = array(
    '#type' => 'select',
    '#title' => t('Hyphenation settings for SmartyPants'),
    '#default_value' => $settings['smartypants_hyphens'],
    '#options' => array(
      1 => t('“--” for em-dashes; no en-dash support'),
      3 => t('“--” for em-dashes; “---” for en-dashes'),
      2 => t('“---” for em-dashes; “--” for en-dashes'),
    ),
  );

  // Wrap ampersand settings.
  $fieldset['wrap_ampersand'] = array(
    '#type' => 'checkbox',
    '#title' => t('Wrap ampersands'),
    '#default_value' => $settings['wrap_ampersand'],
  );

  // Remove widows settings.
  $fieldset['widont_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Remove widows'),
    '#default_value' => $settings['widont_enabled'],
  );

  // Wrap caps settings.
  $fieldset['wrap_caps'] = array(
    '#type' => 'checkbox',
    '#title' => t('Wrap caps'),
    '#default_value' => $settings['wrap_caps'],
  );

  // Wrap initial quotes settings.
  $fieldset['wrap_initial_quotes'] = array(
    '#type' => 'checkbox',
    '#title' => t('Wrap quotation marks'),
    '#default_value' => $settings['wrap_initial_quotes'],
  );

  // Ligature conversion settings.
  $ligature_options = array();
  foreach (unicode_conversion_map('ligature') as $ascii => $unicode) {
    $ligature_options[$ascii] = t('Convert @ascii to !unicode', array(
      '@ascii' => $ascii,
      '!unicode' => $unicode,
    ));
  }
  $fieldset['ligatures'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Ligatures'),
    '#options' => $ligature_options,
    '#default_value' => $settings['ligatures'],
  );

  // Arrow conversion settings.
  $arrow_options = array();
  foreach (unicode_conversion_map('arrow') as $ascii => $unicode) {
    $arrow_options[$ascii] = t('Convert @ascii to !unicode', array(
      '@ascii' => $ascii,
      '!unicode' => $unicode,
    ));
  }
  $fieldset['arrows'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Arrows'),
    '#options' => $arrow_options,
    '#default_value' => $settings['arrows'],
  );

  // Version Information Settings
  $version_strings = array();
  $version_strings[] = t('SmartyPants PHP version: !version', array(
    '!version' => l(SMARTYPANTS_PHP_VERSION, 'http://www.michelf.com/projects/php-smartypants/'),
  ));
  $version_strings[] = t('PHP Typogrify Version: !version', array(
    '!version' => l('1.0', 'http://blog.hamstu.com/'),
  ));
  $fieldset['info']['typogrify_status'] = array(
    '#type' => 'markup',
    '#value' => theme('item_list', $version_strings, t('Version Information')),
  );

  // Name our fieldset based on the format, so the settings will be
  // stored in one array per format.
  $form['typogrify_settings_' . $format] = $fieldset;
  return $form;
}