You are here

function sbp_attach_sbp_settings in Search by Page 6

Same name and namespace in other branches
  1. 7 sbp_attach.module \sbp_attach_sbp_settings()

Implementation of Search by Page hook_sbp_settings().

Adds a node type selection form to the Search by Page settings page, and some options related to presentation.

File

./sbp_attach.module, line 438
Module file for Search by Page Attachments, a sub-module for Search by Page.

Code

function sbp_attach_sbp_settings($environment) {
  $form = array();
  $form['sbp_attach'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#weight' => -70,
    '#title' => t('Attachments'),
  );

  // Explanation
  $form['sbp_attach']['explain'] = array(
    '#type' => 'markup',
    '#value' => '<p>' . t('Search by Page Attachments indexes file attachments on your content types for searching. The attachments can be uploaded using the optional core Upload module, the CCK FileField module, or CCK fields derived from FileField. Choose the content types you want to index attachments of below, and if you want to index attachments from CCK fields, also choose which CCK fields you would like to index.') . '</p>',
    '#weight' => -10,
  );
  $form['sbp_attach']['explain2'] = array(
    '#type' => 'markup',
    '#value' => '<p>' . t('You must choose at least one content type to index, or no attachments will be indexed. Clear all content types or disable the Search by Page Attachments module to stop indexing file attachments.') . '</p>',
    '#weight' => -9,
  );

  // Option 1: Which node types to index attachments for
  $form['sbp_attach']['sbp_attach_node_types'] = array(
    '#type' => 'select',
    '#multiple' => TRUE,
    '#title' => t('Content types to index attachments of'),
    '#default_value' => search_by_page_setting_get('sbp_attach_node_types', $environment, array()),
    '#options' => node_get_types('names'),
    '#description' => t('Choose which content types whose Upload or CCK FileField files you would like to have indexed by Search by Page. Use the Control or Command key to select multiple types or undo your selections.'),
    '#weight' => 0,
  );

  // Option 2: Which CCK FileField types to index, if we have CCK installed
  // Note: Don't check for FileField itself - leave it open to other
  // field modules that use 'fid', and let the user decide
  $opts = array();
  if (function_exists('content_fields')) {

    // Go through all existing CCK fields
    $types = content_fields();
    foreach ($types as $field) {

      // See if this field has an 'fid' column. Cannot find file if not.
      $dbinfo = content_database_info($field);
      if (!$dbinfo['columns']['fid']) {
        continue;
      }

      // It does have a file ID column -- add it to the selection list.
      $name = check_plain($field['field_name']);
      $opts[$name] = check_plain($name);
    }
  }
  if (count($opts)) {
    $form['sbp_attach']['sbp_attach_field_types'] = array(
      '#type' => 'select',
      '#multiple' => TRUE,
      '#title' => t('CCK fields to index'),
      '#default_value' => search_by_page_setting_get('sbp_attach_field_types', $environment, array()),
      '#options' => $opts,
      '#description' => t('Choose which CCK field types contain attachments you would like to have indexed by Search by Page. Use the Control or Command key to select multiple types or undo your selections.'),
      '#weight' => 1,
    );
  }
  else {
    $form['sbp_attach']['no_field_info'] = array(
      '#type' => 'markup',
      '#value' => '<p>' . t('No CCK field types supporting file attachments were found. Only attachments from the core Uploads module will be indexed.') . '</p>',
      '#weight' => 1,
    );
  }

  // Other options
  $form['sbp_attach']['sbp_options_section_markup'] = array(
    '#type' => 'markup',
    '#value' => '<p><strong>' . t('Options:') . '</strong></p>',
    '#weight' => 2,
  );
  $form['sbp_attach']['sbp_attach_only_listed'] = array(
    '#type' => 'checkbox',
    '#title' => t('Limit to listed files'),
    '#default_value' => search_by_page_setting_get('sbp_attach_only_listed', $environment, 0),
    '#description' => t('The core Uploads module and the CCK FileField module allow you to specify whether a particular attached file should be listed on the site. If you check this option, Search by Page Attachments will only index files that have been marked as Listed. Otherwise, all attached files will be indexed.'),
    '#weight' => 3,
  );
  $form['sbp_attach']['sbp_attach_prepend_node_title'] = array(
    '#type' => 'checkbox',
    '#title' => t('Prepend content item title to file name'),
    '#default_value' => search_by_page_setting_get('sbp_attach_prepend_node_title', $environment, 0),
    '#description' => t('When an attached file is presented to the user in search results, the results will display a title, which defaults to the file name. If you check this box, the content item title will be prepended to the file name.'),
    '#weight' => 4,
  );
  $form['sbp_attach']['sbp_attach_title_sep'] = array(
    '#type' => 'textfield',
    '#title' => t('Content item title separator'),
    '#default_value' => search_by_page_setting_get('sbp_attach_title_sep', $environment, '/'),
    '#description' => t('If you have chosen to prepend the content item title to the file name, this separator will be put between the item title and the file name.'),
    '#weight' => 5,
  );
  $form['sbp_attach']['sbp_attach_use_description'] = array(
    '#type' => 'checkbox',
    '#title' => t('Substitute description for file name'),
    '#default_value' => search_by_page_setting_get('sbp_attach_use_description', $environment, 0),
    '#description' => t('When an attached file is presented to the user in search results, the results will display a title, which is the file name by default. If you check this box, and the file has a Description defined, the description will be substituted for the file name in the search result title.'),
    '#weight' => 6,
  );
  $form['sbp_attach']['sbp_attach_role'] = array(
    '#type' => 'radios',
    '#title' => t('Role for indexing'),
    '#options' => user_roles(),
    '#default_value' => search_by_page_setting_get('sbp_attach_role', $environment, DRUPAL_ANONYMOUS_RID),
    '#weight' => 7,
    '#description' => t("When Search by Page indexes attached files for searching, the files will be viewed from the perspective and permissions of a user with this role."),
  );
  $times = array(
    '1' => t('1 second'),
    '3600' => t('1 hour'),
    '86400' => t('1 day'),
    '604800' => t('1 week'),
    '31449600' => t('1 year'),
    '0' => t('Never'),
  );
  $form['sbp_attach']['sbp_attach_min_time'] = array(
    '#type' => 'select',
    '#title' => t('Minimum reindexing time'),
    '#options' => $times,
    '#default_value' => search_by_page_setting_get('sbp_attach_min_time', $environment, 0),
    '#weight' => 8,
    '#description' => t("Search by Page automatically indexes attachments on new content items, and reindexes attachments if the content item they are attached to is updated. After indexing these updated attachments, Search by Page can also cycle through previously-indexed attachments, in case the file may have been updated without the content item it is attached to being updated. This would be necessary if files on the site are maintained and updated by a separate process (e.g., log files, replacement files added by FTP, etc.). By default, Search by Page will not reindex an attachment until the content item it is attached to is updated, but if you need attachments to be reindexed, you can set the minimum indexing cycle time here. In this case, attachments will be reindexed periodically, along with other Search by Page content, after waiting at least the minimum time set here before reindexing."),
  );
  $form['sbp_attach']['sbp_attach_max_time'] = array(
    '#type' => 'select',
    '#title' => t('Maximum reindexing time'),
    '#options' => $times,
    '#default_value' => search_by_page_setting_get('sbp_attach_max_time', $environment, 0),
    '#weight' => 9,
    '#description' => t("Conversely to the minimum reindexing time (see above), Search by Page can be set to prioritize reindexing each attachment (by marking it as needing immediate reindexing) after this amount of time has passed. This has higher priority than the cycle-through reindexing of the setting above.") . ' ' . t('But be careful with this setting! If you set it too small, it can interfere with new content being indexed, because the reindexed content will have equal priority to content that has never been indexed. So make sure your settings allow for enough time for new content to be indexed before forcing reindexing.'),
  );

  // Add a link to helper function config page
  $form['sbp_attach']['helpers'] = array(
    '#type' => 'markup',
    '#value' => '<p>' . l(t('Configure helper functions for extracting text from attachment files'), 'admin/settings/search_files/helpers') . '</p>',
    '#weight' => 10,
  );
  return $form;
}