You are here

function ctools_term_ctools_access_check in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 plugins/access/term.inc \ctools_term_ctools_access_check()

Check for access.

1 string reference to 'ctools_term_ctools_access_check'
term.inc in plugins/access/term.inc
Plugin to provide access control based upon specific terms.

File

plugins/access/term.inc, line 92
Plugin to provide access control based upon specific terms.

Code

function ctools_term_ctools_access_check($conf, $context) {

  // As far as I know there should always be a context at this point, but this
  // is safe.
  if (empty($context) || empty($context->data) || empty($context->data->vid) || empty($context->data->tid)) {
    return FALSE;
  }

  // Get the $vid.
  if (!isset($conf['vid'])) {
    return FALSE;
  }
  $vid = $conf['vid'];

  // Get the terms.
  if (!isset($conf[$vid])) {
    return FALSE;
  }
  $return = FALSE;

  // Tags get saved as an imploded array of strings.
  if (!is_array($conf[$vid])) {
    $terms = explode(', ', $conf[$vid]);

    // For multi-term with names, we'll only accept the first term because
    // that is the name we have.
    return in_array($context->data->name, $terms);
  }
  else {
    $terms = array_filter($conf[$vid]);

    // For multi-term if any terms coincide, let's call that good enough:
    if (isset($context->tids)) {
      return (bool) array_intersect($terms, $context->tids);
    }
    else {
      return in_array($context->data->tid, $terms);
    }
  }
}