You are here

function subscriptions_user_settings_form in Subscriptions 7

Same name and namespace in other branches
  1. 5.2 subscriptions.admin.inc \subscriptions_user_settings_form()
  2. 6 subscriptions.admin.inc \subscriptions_user_settings_form()
  3. 2.0.x subscriptions.admin.old.php \subscriptions_user_settings_form()

Returns the form definition for the settings part of the overview page.

This subform is also used for admin/settings/subscriptions/userdefaults.

_state

Parameters

array $form:

object|null $account: Must be a valid user account from user_load() or NULL (for the admin form).

Return value

array

1 call to subscriptions_user_settings_form()
subscriptions_page_user_overview in ./subscriptions.admin.inc
Construct the overview page, which displays a summary of subscriptions per type as well as the user settings at user/UID/subscriptions. This form is also used for admin/settings/subscriptions/userdefaults.

File

./subscriptions.admin.inc, line 580
Subscriptions module (load-on-demand admin functions).

Code

function subscriptions_user_settings_form(array $form, array &$form_state, $account) {
  global $user;
  $uid = !empty($account) ? $account->uid : -DRUPAL_AUTHENTICATED_RID;
  $tr = 't';
  $form['settings'] = array(
    '#type' => 'fieldset',
    '#title' => check_plain($tr('Settings')),
    '#weight' => 10,
    '#collapsible' => !empty($account),
    '#collapsed' => !empty($account),
  );
  if ($uid < 0) {
    $form['settings']['info'] = array(
      '#type' => 'fieldset',
      '#title' => t('Admin Information'),
      '#attributes' => array(
        'class' => array(
          'error',
        ),
      ),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['settings']['info'][] = array(
      '#markup' => '<div>' . t("The subtabs here under %User_defaults mirror those found at !My_account_Subscriptions, except that the fieldsets here come up already expanded. Please go there now and familiarize yourself with what's there!", array(
        '%User_defaults' => $tr('User defaults'),
        '!My_account_Subscriptions' => l($tr('My account') . '|' . $tr('Subscriptions'), 'user/' . $user->uid . '/subscriptions'),
        '%Settings' => $tr('Settings'),
      )) . '</div>',
    );
    $form['settings']['info'][] = array(
      '#markup' => '<div>' . t("The default settings that you define here are used for those users that haven't (yet) saved their own settings.", array(
        '%User_defaults' => $tr('User defaults'),
        '!My_account_Subscriptions' => l($tr('My account') . '|' . $tr('Subscriptions'), 'user/' . $user->uid . '/subscriptions'),
        '%Settings' => $tr('Settings'),
      )) . '</div>',
    );
    $description = '<span class="error">' . t("If you hide this page, your users won't be able to change any of these settings. The default is OFF.") . '<br />' . t('Also, you must give your users the %subscribe_to_content permission, so that they have access to the %Pages_Threads page!', array(
      '%subscribe_to_content' => $tr('Subscribe to content'),
      '%Pages_Threads' => $tr('Pages/Threads'),
    )) . '</span>';
    $form['settings']['info']['hide_overview_page'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide the %Overview page from your users', array(
        '%Overview' => t('Overview'),
      )),
      '#default_value' => variable_get('subscriptions_hide_overview_page', 0),
      '#description' => filter_xss($description, array(
        'span',
        'br',
        'em',
      )),
      '#prefix' => '<div style="height: 1ex;">&nbsp;</div>',
    );
  }
  $form['settings']['autosub'] = array(
    '#type' => 'fieldset',
    '#title' => t('Auto-subscribe'),
    '#access' => empty($account) || user_access('subscribe to content', $account),
  );
  $form['settings']['autosub']['autosub_post'] = array(
    '#type' => 'checkbox',
    '#title' => t('Auto-subscribe to new content'),
    '#default_value' => _subscriptions_get_setting('autosub_on_post', $account),
    '#description' => t('Automatically subscribes you to items that you create.'),
  );
  $form['settings']['autosub']['autosub_update'] = array(
    '#type' => 'checkbox',
    '#title' => t('Auto-subscribe to updated content'),
    '#default_value' => _subscriptions_get_setting('autosub_on_update', $account),
    '#description' => t('Automatically subscribes you to items that you update (if you have that permission).'),
  );
  $form['settings']['autosub']['autosub_comment'] = array(
    '#type' => 'checkbox',
    '#title' => t('Auto-subscribe to comments'),
    '#default_value' => _subscriptions_get_setting('autosub_on_comment', $account),
    '#description' => t('Automatically subscribes you to items that you comment on (or where you update a comment, if you have that permission).'),
    '#access' => module_exists('comment') && (empty($account) || user_access('post comments', $account) || user_access('post comments without approval', $account)),
  );
  $form['settings']['sendself'] = array(
    '#type' => 'checkbox',
    '#title' => t('Notify poster of own posts'),
    '#default_value' => _subscriptions_get_setting('send_self', $account),
    '#description' => t("Sends you notifications about your own posts (if you're subscribed)."),
  );
  $form['settings']['digest'] = array(
    '#type' => 'checkbox',
    '#title' => t('Digest mode'),
    '#default_value' => _subscriptions_get_setting('digest', $account),
    '#description' => t("Merges your notifications into a single email, sent at the interval you specify."),
  );
  $secure_links_site = _subscriptions_get_setting('secure_links', 0);
  $variables = array(
    '!http' => 'http',
    '!https' => 'https',
  );
  if (empty($account)) {
    $form['settings']['secure_links'] = array(
      '#title' => t('Type of links to send'),
      '#type' => 'select',
      '#options' => array(
        0 => t('Always !http', $variables),
        -1 => t('Let the user choose, default to !http', $variables),
        -2 => t('Let the user choose, default to !https', $variables),
        2 => t('Always !https', $variables),
      ),
      '#default_value' => $secure_links_site,
      '#description' => t('Set the type of the links in the notifications, depending on what protocol(s) your site support. Default is %always_http.', array(
        '%always_http' => t('Always !http', $variables),
      )),
    );
  }
  else {
    if ($secure_links_site < 0) {
      $form['settings']['secure_links'] = array(
        '#title' => t('Type of links to send'),
        '#type' => 'select',
        '#options' => array(
          -1 => t('Site default'),
          0 => 'http',
          1 => 'https',
        ),
        '#default_value' => _subscriptions_get_setting('secure_links', $account),
        '#description' => t('Set the type of the links in the notifications. %Site_default is %default.', array(
          '%Site_default' => t('Site default'),
          '%default' => abs($secure_links_site) >= 2 ? 'https' : 'http',
        )),
      );
    }
  }
  if (_subscriptions_get_setting('send_interval_visible', $account) == -2) {
    $intervals = _subscriptions_send_intervals();
    $interval = $intervals[_subscriptions_get_setting('send_interval', $account)];
    $form['settings']['digest']['#description'] = t('Merges your notifications into a single email, sent at regular intervals (%interval).', array(
      '%interval' => $interval,
    ));
  }
  $form['settings']['preferences'] = array(
    '#type' => 'fieldset',
    '#title' => t('Preferences'),
    '#access' => FALSE,
  );
  $form['settings']['preferences']['send_interval'] = array(
    '#title' => t('Send interval'),
    '#type' => 'select',
    '#options' => _subscriptions_send_intervals(),
    '#default_value' => _subscriptions_get_setting('send_interval', $account),
    '#description' => t('The frequency of notifications; it may take longer, but notifications will not be sent more frequently than indicated.'),
  );
  $form['settings']['preferences']['send_updates'] = array(
    '#title' => t('On updates'),
    '#type' => 'checkbox',
    '#default_value' => _subscriptions_get_setting('send_updates', $account),
    '#description' => t('Sends a notification when an item is updated.'),
  );
  $form['settings']['preferences']['send_comments'] = array(
    '#title' => t('On comments'),
    '#type' => 'checkbox',
    '#default_value' => _subscriptions_get_setting('send_comments', $account),
    '#description' => t('Sends a notification when an item receives a comment or reply.'),
  );
  $form['settings']['preferences']['description'] = array(
    '#markup' => t('Any changes you make here will only apply to newly created subscriptions.'),
  );
  $form['settings']['visibility'] = array(
    '#type' => 'fieldset',
    '#title' => t('Visibility of controls'),
    '#collapsible' => !empty($account),
    '#collapsed' => !empty($account),
    '#access' => FALSE,
  );
  $form['settings']['visibility'][] = array(
    '#type' => 'item',
    '#description' => t('The control(s) mentioned below appear(s) as one or more columns<br /> a) in the %Subscribe subform of node pages and<br /> b) on the sibling subtabs of this %Overview page.<br /> After you have set your %Preferences right above, you may want to hide the corresponding column(s), if you never change those values anyway.', array(
      '%Subscribe' => $tr('Subscribe'),
      '%Overview' => $tr('Overview'),
      '%Preferences' => $tr('Preferences'),
    )),
  );
  $visibility_options = array(
    t('Visible'),
    t('Hidden'),
  );
  if (empty($account)) {
    $visibility_options[] = t('Permanently hidden, except for the %preferences', array(
      '%preferences' => 'Preferences',
    ));
    $visibility_options[] = t('Completely inaccessible to the user');
    $form['settings']['visibility']['info'] = array(
      '#type' => 'fieldset',
      '#title' => t('Admin Information'),
      '#attributes' => array(
        'class' => array(
          'error',
        ),
      ),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['settings']['visibility']['info'][] = array(
      '#markup' => t("Beyond defining the %Visible/%Hidden defaults for your users, you can", array(
        '%Visible' => $tr('Visible'),
        '%Hidden' => $tr('Hidden'),
      )) . '<ul><li>' . t("permanently hide the columns (and the corresponding visibility controls), so that the users cannot make them visible anymore (they can still change their %Preferences though), or", array(
        '%Preferences' => $tr('Preferences'),
      )) . '</li>' . '<li>' . t("you can even hide the %Preferences, so that what you've set right above is cast in stone.", array(
        '%Preferences' => $tr('Preferences'),
      )) . '</li></ul>',
    );
  }
  foreach (array(
    'interval',
    'updates',
    'comments',
  ) as $parm) {
    $site_setting = _subscriptions_get_setting('send_' . $parm . '_visible', 0);
    $suppress_comment_controls = $parm == 'comments' && !module_exists('comment');
    $pref_access = (empty($account) || $site_setting >= -1) && !$suppress_comment_controls;
    $control_access = (empty($account) || $site_setting >= 0) && !$suppress_comment_controls;
    $form['settings']['visibility']['send_' . $parm . '_visible'] = array(
      '#title' => filter_xss($parm == 'interval' ? t('Send interval') : ($parm == 'updates' ? t('On updates') : t('On comments'))),
      '#type' => 'radios',
      '#options' => $visibility_options,
      '#default_value' => 1 - _subscriptions_get_setting('send_' . $parm . '_visible', $account),
      '#access' => $control_access,
    );
    if ($control_access) {
      $form['settings']['visibility']['#access'] = TRUE;
    }
    $form['settings']['preferences']['send_' . $parm]['#access'] = $pref_access;
    if ($pref_access) {
      $form['settings']['preferences']['#access'] = TRUE;
    }
  }
  $form['settings']['save_settings'] = array(
    '#type' => 'submit',
    '#value' => t('Save settings'),
  );
  if ($uid > 0 && !_subscriptions_get_setting('uses_defaults', $account)) {
    $form['settings']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset to site defaults'),
    );
  }
  $form['#submit'][] = '_subscriptions_user_settings_form_submit';
  return $form;
}