You are here

function swftools_admin_handling_form in SWF Tools 6.3

Same name and namespace in other branches
  1. 5 swftools.module \swftools_admin_handling_form()
  2. 6 swftools.admin.inc \swftools_admin_handling_form()
  3. 6.2 swftools.admin.inc \swftools_admin_handling_form()
1 string reference to 'swftools_admin_handling_form'
swftools_menu in ./swftools.module
Implementation of hook_menu().

File

includes/swftools.admin.inc, line 282
Configuration settings for SWF Tools.

Code

function swftools_admin_handling_form() {
  $form = array();
  $form['swftools_files'] = array(
    '#type' => 'fieldset',
    '#title' => t('File locations'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $current_path = variable_get('swftools_media_url', $GLOBALS['base_url'] . '/' . file_create_path(''));

  // Misname the variable with '_dummy' so that it is not saved!
  $form['swftools_files']['swftools_media_url_dummy'] = array(
    '#type' => 'textfield',
    '#title' => t('Media directory url'),
    '#default_value' => $current_path,
    '#disabled' => TRUE,
    '#description' => t("This helps swftools identify the server where your media files are located.\n                         You cannot change it here, as changing it has the potential to break existing\n                         content. You can set this on the &#36;conf array in your settings.php file.\n                         For example: <pre>\n  &#36;conf = array(\n    'swftools_media_url' => 'http://anothersite.com/media', // No trailing slashes!\n  );</pre>               Leaving this value unset in your settings.php file will\n                         persuade SWF Tools to check for the existence of your\n                         media files, as they are automatically assumed to be\n                         on the local server."),
  );
  $form['swftools_files']['swftools_check_media'] = array(
    '#type' => 'radios',
    '#title' => t('File checking'),
    '#options' => array(
      1 => t('Enabled - check that local files exist.'),
      0 => t('Disabled - do not check that local files exist.'),
    ),
    '#default_value' => variable_get('swftools_check_media', TRUE),
    '#description' => t('This option will cause SWF Tools to check that requested local
                         media files exist, and issue a warning if they do not. If this
                         option is set to do not check then the mark up will be placed on
                         the page irrespective of whether the file is actually present.'),
  );

  // Get handling form by calling the profile form with no profile setting
  $form += swftools_handling_profile_form();

  // Make handlers collapsible
  $form['swftools_handlers'] += array(
    '#type' => 'fieldset',
    '#title' => t('File handling'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Choose how different file types are handled.'),
  );
  $form['swftools_private'] = array(
    '#type' => 'fieldset',
    '#title' => t('Private file system'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Allow SWF Tools to grant access to non-uploaded files
  $form['swftools_private']['swftools_grant_access_to_private_files'] = array(
    '#type' => 'radios',
    '#title' => t('Access to supported private files'),
    '#options' => array(
      1 => t('Enabled'),
      0 => t('Disabled'),
    ),
    '#default_value' => variable_get('swftools_grant_access_to_private_files', SWFTOOLS_PRIVATE_ACCESS_DENIED),
    '#description' => t('If using a private file system then SWF Tools is unable to
                         access files that are not uploaded via a file module that
                         supports a private file system. For example, SWF Tools will
                         be unable to access files that were manually uploaded via FTP.
                         Enabling this setting will allow SWF Tools to grant access
                         to files with extensions defined by the next setting.
                         Note - if another module <em>denies</em> access then access
                         to the file will not be granted. SWF Tools itself does not
                         deny access to any file.
                         '),
  );

  // Should SWF Tools allow access to private files?
  $form['swftools_private']['swftools_grant_access_extensions'] = array(
    '#type' => 'textfield',
    '#title' => t('Extensions that SWF Tools will allow access to'),
    '#default_value' => variable_get('swftools_grant_access_extensions', SWFTOOLS_PRIVATE_ACCESS_ALLOWED_EXTENSIONS),
    '#maxlength' => 255,
    '#description' => t('Under a private file system SWF Tools will grant access to files
                         with extensions in this list. Separate extensions with a space
                         and do not include the leading dot. Although any extension can be
                         added to this list, only <em>swf flv xml mp3 jpg jpeg</em> and
                         <em>png</em> will return the correct headers.'),
  );

  // Get current mime type array
  $mime_types = _swftools_mime_types();

  // $mime_types are stored as an array where key is the extension, and value is the mime type
  $defaults = array();

  // Turn each key/value pair in to a string
  foreach ($mime_types as $extension => $type) {
    $defaults[] = $extension . ' ' . $type;
  }

  // Implode the resulting array to create a single string for presenation
  $defaults = implode("\n", $defaults);

  // Put text area on the page
  $form['swftools_private']['swftools_mime_types_input'] = array(
    '#type' => 'textarea',
    '#title' => t('Mime types'),
    '#default_value' => $defaults,
    '#description' => t('Enter a list of additional extensions that SWF Tools should recognise. Put each extension on a separate line, with the
                         extension first, followed by a space, and then the mime type for that type of file.'),
  );
  $form['swftools_advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Enable SWF Tools cache?
  $form['swftools_advanced']['swftools_cache'] = array(
    '#type' => 'radios',
    '#title' => t('SWF Tools cache'),
    '#options' => array(
      CACHE_DISABLED => t('Disabled'),
      CACHE_NORMAL => t('Enabled (recommended)'),
    ),
    '#default_value' => variable_get('swftools_cache', CACHE_NORMAL),
    '#description' => t('During site development it can be helpful to disable the cache and
                         force content to be regenerated on every page call. Note that content
                         being generated via an input filter is always cached by the input filter
                         itself and disabling the SWF Tools cache will not stop the filter cache.
                         Even when the SWF Tools cache is disabled it will continue to store content
                         to allow features such as serving content from %path to function.', array(
      '%path' => base_path() . 'swftools/html/nn',
    )),
  );

  // Allow SWF Tools to grant access to content from the cache?
  $form['swftools_advanced']['swftools_grant_access_to_cache'] = array(
    '#type' => 'radios',
    '#title' => t('Allow cached content to be served'),
    '#options' => array(
      0 => t('Disabled'),
      1 => t('Enabled'),
    ),
    '#default_value' => variable_get('swftools_grant_access_to_cache', 0),
    '#description' => t('SWF Tools stores generated content in its own cache. You can simplify
                         the use of features like LightBox by allowing access to content directly
                         from the cache via the path %path, where %cid is the 32 character cid of
                         the content. SWF Tools will serve a basic page with nothing but the flash
                         content. The only access control is that the user has the %access permission.
                         ', array(
      '%path' => base_path() . 'swftools/html/nn',
      '%cid' => 'nn',
      '%access' => 'access content',
    )),
  );

  // Where should error messages be written?
  $form['swftools_advanced']['swftools_error_output'] = array(
    '#type' => 'radios',
    '#title' => t('Error messages'),
    '#options' => array(
      SWFTOOLS_ERROR_NONE => t('None'),
      SWFTOOLS_ERROR_WATCHDOG => t('Watchdog'),
      SWFTOOLS_ERROR_SCREEN => t('Screen'),
      SWFTOOLS_ERROR_WATCHDOG_AND_SCREEN => t('Watchdog and screen'),
    ),
    '#default_value' => variable_get('swftools_error_output', SWFTOOLS_ERROR_WATCHDOG_AND_SCREEN),
    '#description' => t('If SWF Tools encounters an error when trying to determine how to embed a piece of content it will generate an error message to help diagnose the problem. These messages can be written to the screen, which is useful when setting a site up, but in a production environment you might prefer to just log them in the watchdog.'),
  );

  // Get available actions - this is just a list of available actions and descriptions about them
  $actions = swftools_get_actions();

  // Get the array of actions, keyed on extension
  $_extensions = _swftools_actions();

  // Turn it around to we are organised by action
  foreach ($_extensions as $extension => $action) {
    $extensions[$action][] = $extension;
  }

  // Make extensions an array
  $form['swftools_advanced']['swftools_extensions'] = array(
    '#tree' => TRUE,
  );

  // Put each option on the form to let the user assign extensions to each available action
  foreach ($actions as $action => $info) {

    // Only output single file handlers (list handlers handle collections of single files of the same type)
    if (substr($action, -5) != '_list') {

      // Place an option on the page
      $form['swftools_advanced']['swftools_extensions'][$action] = array(
        '#type' => 'textfield',
        '#title' => t('Extensions to associate with ' . $info['#type']),
        '#default_value' => isset($extensions[$action]) ? implode(' ', $extensions[$action]) : '',
        '#description' => t('Enter a list of extensions, separated by spaces, that SWF Tools should associate with ' . $info['#type'] . '.'),
        '#weight' => 1 + $info['#weight'] / 10,
      );
    }
  }

  // Add custom form handler to flush cache upon submit
  $form['#submit'][] = 'swftools_admin_settings_submit';

  // Add custom handler to process extension handling
  $form['#submit'][] = 'swftools_admin_extensions_submit';

  // Add custom handler to process extension handling
  $form['#submit'][] = 'swftools_admin_mime_type_submit';

  // Return finished form
  return system_settings_form($form);
}