You are here

function _subscriptions_get_setting in Subscriptions 2.0.x

Same name and namespace in other branches
  1. 5.2 subscriptions.module \_subscriptions_get_setting()
  2. 6 subscriptions.module \_subscriptions_get_setting()
  3. 7 subscriptions.module \_subscriptions_get_setting()

Helper function to retrieve send_self/autosub_on_post/autosub_on_update/autosub_on_comment/ | 1, 0, digest/send_interval/send_updates/send_comments/ | -1 = use default send_interval_visible/send_updates_visible/send_comments_visible/ | 1, 0, -1 = only preference, -2 = always use site default secure_links | 1, 0 for $uid>0; 1, 0, -1, -2 for -DRUPAL_AUTHENTICATED_RID uses_defaults values;

Parameters

string $name:

object|int|null $account: NULL/0 (for site default), a user object, a uid (if >0) or a -rid (if <0).

13 calls to _subscriptions_get_setting()
subscriptions_add_form in ./subscriptions.admin.old.php
Provide the form definition for adding subscriptions via subscriptions/add/... link.
subscriptions_autosubscribe in ./subscriptions.module.old.php
Subscribes users to content they post, if not already subscribed (context: on_post, on_update, on_comment).
subscriptions_form_column_filter in ./subscriptions.admin.old.php
Helper function for the submodules to hide invisible or empty columns from their page form table(s).
subscriptions_og_og_membership_insert in subscriptions_og/subscriptions_og.module
Implements hook_og_membership_insert().
subscriptions_og_page in subscriptions_og/subscriptions_og.module
Defines a user's overview of which groups she is subscribed to.

... See full list

File

./subscriptions.module.old.php, line 881
Subscriptions module.

Code

function _subscriptions_get_setting($name, $account) {
  global $user;
  $uid = -DRUPAL_AUTHENTICATED_RID;
  if (empty($account) || is_object($account) && empty($account->uid) || is_numeric($account) && $account <= 0) {
    unset($account);
  }
  elseif (is_numeric($account)) {
    if ($account == $user->uid) {
      $account = $user;
      $uid = $user->uid;
    }
    else {
      $uid = $account;
      unset($account);
    }
  }
  if (isset($account)) {
    $uid = $account->uid;
  }
  static $defaults = array();
  if (!isset($defaults[$uid][$name])) {
    $result = db_select('subscriptions_user', 'su', array(
      'fetch' => PDO::FETCH_ASSOC,
    ))
      ->fields('su', array(
      'uid',
      'digest',
      'secure_links',
      'send_interval',
      'send_updates',
      'send_comments',
      'send_interval_visible',
      'send_updates_visible',
      'send_comments_visible',
      'autosub_on_post',
      'autosub_on_update',
      'autosub_on_comment',
      'send_self',
    ))
      ->condition('su.uid', array(
      -DRUPAL_AUTHENTICATED_RID,
      $uid,
    ), 'IN')
      ->orderBy('su.uid')
      ->execute();
    foreach ($result as $s) {
      $defaults[$s['uid']] = $s;
    }
    if (empty($defaults[$uid])) {

      // Note: This should not happen -- subscriptions_user_insert() and
      // subscriptions_user_delete() take care of inserting/removing records
      // as users are created/deleted.
      // If it does happen, then users were created without calling the proper
      // hooks, or they may have been created on another multi-site (#351753).
      // Let's add the missing records, as if the user were being created just
      // now, with the expected hook_user() invocations:
      if ($uid > 0) {
        $account = user_load($uid);
        subscriptions_user_insert(array(), $account, NULL);
      }
      else {
        db_insert('subscriptions_user')
          ->fields(array(
          'uid' => $uid,
        ))
          ->execute();
      }
      return _subscriptions_get_setting($name, $uid);
    }
    $secure_links_site = _subscriptions_get_setting('secure_links', NULL);
    if ($uid > 0) {
      if ($secure_links_site >= 0 || $defaults[$uid]['secure_links'] == -1) {
        $defaults[$uid]['secure_links'] = abs($secure_links_site) >= 2;
      }
    }
    $defaults[$uid]['uses_defaults'] = FALSE;
    foreach ($defaults[$uid] as $key => $value) {
      if ($value < 0) {

        // not set, use site dft
        $defaults[$uid][$key] = $defaults[-DRUPAL_AUTHENTICATED_RID][$key];
        $defaults[$uid]['uses_defaults'] = TRUE;
      }
    }
    foreach (array(
      'interval',
      'updates',
      'comments',
    ) as $parm) {

      // Site overrides user values.
      if ($defaults[-DRUPAL_AUTHENTICATED_RID]['send_' . $parm . '_visible'] == -2) {
        $defaults[$uid]['send_' . $parm] = $defaults[-DRUPAL_AUTHENTICATED_RID]['send_' . $parm];
      }
    }
  }
  return $defaults[$uid][$name];
}