You are here

function _subscriptions_get_setting in Subscriptions 6

Same name and namespace in other branches
  1. 5.2 subscriptions.module \_subscriptions_get_setting()
  2. 7 subscriptions.module \_subscriptions_get_setting()
  3. 2.0.x subscriptions.module.old.php \_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 uses_defaults values; $account can be NULL/0 (for site default), a user object, or a uid.

10 calls to _subscriptions_get_setting()
subscriptions_add_form in ./subscriptions.admin.inc
Provide the form definition for adding subscriptions via subscriptions/add/... link.
subscriptions_autosubscribe in ./subscriptions.module
Subscribe users to content they post, if not already subscribed (context: on_post, on_update, on_comment).
subscriptions_blog_ui_blog_form in ./subscriptions_blog_ui.module
Returns the blog subscription form.
subscriptions_content_type_form in ./subscriptions_content.module
Build the Content Types subscriptions form at user/UID/subscriptions/type.
subscriptions_form_column_filter in ./subscriptions.admin.inc
Helper function for the submodules to hide invisible or empty columns from their page form table(s).

... See full list

File

./subscriptions.module, line 605
Subscriptions module.

Code

function _subscriptions_get_setting($name, $account) {
  global $user;
  if (!isset($account) || is_object($account) && empty($account->uid) || is_numeric($account) && $account <= 0) {
    $uid = -DRUPAL_AUTHENTICATED_RID;
    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_query("SELECT uid, digest, 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 FROM {subscriptions_user} WHERE uid in (%d, %d) ORDER BY uid", -DRUPAL_AUTHENTICATED_RID, $uid);
    while ($s = db_fetch_array($result)) {
      $defaults[$s['uid']] = $s;
    }
    if (empty($defaults[$uid])) {

      // Note: This should not happen -- subscriptions_user() takes 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:
      $account = user_load($uid);
      subscriptions_user('insert', NULL, $account);
      subscriptions_user('load', NULL, $account);
      return _subscriptions_get_setting($name, $account);
    }
    $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];
}