You are here

function notifications_tags_notifications_subscription in Notifications 6.4

Same name and namespace in other branches
  1. 7 notifications_tags/notifications_tags.module \notifications_tags_notifications_subscription()

Implementation of hook notifications_subscription()

File

notifications_tags/notifications_tags.module, line 84
Subscriptions to taxonomy terms

Code

function notifications_tags_notifications_subscription($op, $subscription = NULL, $account = NULL) {
  switch ($op) {
    case 'access':

      // Check access control for subscription to taxonomy term
      if (($conditions = $subscription
        ->get_conditions()) && !empty($conditions['tid'])) {

        // This may be a singe term or an array of terms
        $tids = is_array($conditions['tid']) ? $conditions['tid'] : array(
          $conditions['tid'],
        );

        // Deny access if the term doesn't exist or the vocabulary is not allowed
        $allowed_vocabs = notifications_tags_vocabularies();
        foreach ($tids as $tid) {
          $term = taxonomy_get_term($tid);
          if (!$term || !array_key_exists($term->vid, $allowed_vocabs)) {
            return FALSE;
          }
        }
      }
      break;
    case 'page objects':

      // Return objects on current page to which we can subscribe
      $allowed_vocabs = notifications_tags_vocabularies();
      if (arg(0) == 'taxonomy') {
        $objects = array();
        if (arg(1) == 'term' && is_numeric(arg(2)) && ($term = taxonomy_get_term(arg(2))) && array_key_exists($term->vid, $allowed_vocabs)) {
          $objects['term'] = $term;
        }
        return $objects;
      }
      break;
  }
}