You are here

function classified_admin_settings in Classified Ads 6.3

Same name and namespace in other branches
  1. 7.3 classified.admin.inc \classified_admin_settings()

Implements hook_settings().

Return value

array A form array. Keys will be automagically saved as variables.

1 string reference to 'classified_admin_settings'
classified_menu in ./classified.module
Implements hook_menu().

File

./classified.admin.inc, line 36
Admin page(s) for the classified module.

Code

function classified_admin_settings() {
  module_load_include('inc', 'classified', 'classified_utils');
  $vid = _classified_get('vid');
  $vocabulary = taxonomy_vocabulary_load($vid, TRUE);
  if (!$vocabulary) {
    $form['error'] = array(
      '#value' => t('Module vocabulary has gone missing. Please reinstall the module.'),
    );
    return $form;
  }

  // Ads configuration section.
  $form['ads-wrapper'] = array(
    '#type' => 'fieldset',
    '#title' => t('Ads configuration'),
    '#collapsible' => TRUE,
  );
  $form['ads-wrapper']['classified-max-length'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum ad length'),
    '#size' => 5,
    '#maxlength' => 5,
    '#default_value' => _classified_get('max-length'),
    '#description' => t('The maximum number of characters in your Classified Ad. Set to 0 to disable the max length check.'),
  );
  $form['ads-wrapper']['classified-list-body'] = array(
    '#type' => 'radios',
    '#title' => t('List display'),
    '#options' => array(
      'empty' => t('Empty'),
      'body' => t('Node body'),
      'node' => t('Node view in "Ad list" <a href="!link">build mode</a>', array(
        '!link' => url('admin/content/node-type/classified/display/classified'),
      )),
    ),
    '#description' => t('How should Classified Ads be displayed in lists.'),
    '#default_value' => _classified_get('list-body'),
  );
  $form['ads-wrapper']['classified-edit-modr8'] = array(
    '#type' => 'checkbox',
    '#title' => t('Modr8 edits'),
    '#description' => t('If modr8 is available, editing a node sends it back to moderation for non-privileged users'),
    '#default_value' => _classified_get('edit-modr8'),
  );

  // Lifetimes and grace section.
  $form['lifetimes-wrapper'] = array(
    '#type' => 'fieldset',
    '#title' => t('Ad Lifetimes'),
    '#theme' => 'classified_admin_lifetimes',
    // '#tree'        => TRUE,
    '#collapsible' => TRUE,
    '#description' => t('Lifetime for each classified ad category. Categories themselves are configured <a href="@here">here</a> and the vocabulary containing them is configured <a href="@there">there</a>. All durations are in days.', array(
      '@here' => url('admin/content/taxonomy/' . $vid),
      '@there' => url('admin/content/taxonomy/edit/vocabulary/' . $vid),
    )),
  );
  $categories = taxonomy_get_tree($vid);
  $lifetimes = _classified_get('lifetimes');
  $lifetime_default = reset($lifetimes);

  // Empty placeholder needs to be in form to allow setting in validate handler.
  $form['classified-lifetimes'] = array(
    '#type' => 'value',
    '#value' => NULL,
  );
  $form['lifetimes-wrapper']['classified-lifetime-default'] = array(
    '#type' => 'textfield',
    '#title' => t('Default lifetime'),
    '#default_value' => $lifetime_default,
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t('Will be used for every term not having a specific lifetime below.'),
  );
  foreach ($categories as $term) {
    $form['lifetimes-wrapper']['classified-lifetime-' . $term->tid] = array(
      '#type' => 'textfield',
      '#title' => theme('indentation', $term->depth) . check_plain($term->name),
      '#default_value' => isset($lifetimes[$term->tid]) ? $lifetimes[$term->tid] : NULL,
      '#size' => 3,
      '#maxlength' => 3,
    );
  }
  $form['lifetimes-wrapper']['classified-grace'] = array(
    '#type' => 'textfield',
    '#title' => t('Grace delay for expired ads'),
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t('Once expired, ads are kept unpublished for that delay before being deleted. Set to -1 for infinite. Setting to 0 means immediate deletion upon expiration.'),
    '#default_value' => _classified_get('grace'),
  );
  $form['#validate'][] = 'classified_admin_settings_validate';
  $ret = system_settings_form($form);
  return $ret;
}