log); return NULL; } elseif ($nb_ac_conditions > 1) { log_error('Several condition attributes with ac W2ML attribute', $econf->log); return NULL; } if ($group !== NULL) { return process_ac_group($econf, $in_elm, $group); } elseif ($user !== NULL) { return process_ac_user($econf, $in_elm, $user); } else { return process_ac_req_or_internal($econf, $in_elm, $req, $internal); } } function process_ac_group($econf, $in_elm, $ac_group) { $user = $econf->user(); return $user->is_in_group($ac_group); } function process_ac_user($econf, $in_elm, $ac_user) { $user = $econf->user(); return $user->name === $ac_user; } function process_ac_req_or_internal($econf, $in_elm, $req, $internal) { $match = get_w2ml_attribute_value($in_elm, 'match'); $nmatch = get_w2ml_attribute_value($in_elm, 'nmatch'); if ($match !== NULL && $nmatch !== NULL) { log_error('W2ML match and nmatch attributes on same element', $econf->log); return NULL; } if ($req !== NULL) { $var_val = get_http_parameter($req, TRUE); } else { $var_val = get_internal_var($econf, $internal); } if ($match === NULL && $nmatch === NULL) { return $var_val !== NULL; } elseif ($match !== NULL) { if (is_string($var_val)) { return @preg_match('/'.$match.'/u', $var_val) === 1; } elseif (is_array($var_val)) { foreach ($var_val as $one_val) { if (@preg_match('/'.$match.'/u', $one_val) === 1) { return TRUE; } } return FALSE; } return FALSE; # for undefined variable } else { if (is_string($var_val)) { # Note: preg_match returns FALSE on error, 0 for no match. return !@preg_match('/'.$nmatch.'/u', $var_val); } elseif (is_array($var_val)) { foreach ($var_val as $one_val) { # Note: preg_match returns FALSE on error, 0 for no match. if (!@preg_match('/'.$nmatch.'/u', $one_val)) { return FALSE; } } return TRUE; } return TRUE; # for undefined variable } } define('AC_SET', 1); define('AC_PLUS', 2); define('AC_MINUS', 3); function process_ac_attribute($econf, $ac, $condition) { if (preg_match('/^([+-]?[xdne])*$/', $ac) !== 1) { log_error('Bad format in ac="'.$ac.'"', $econf->log); return; } $ac_len = strlen($ac); $set_plus_minus = AC_SET; for ($i = 0; $i < $ac_len; ++$i) { switch ($ac{$i}) { case '+': $set_plus_minus = AC_PLUS; break; case '-': $set_plus_minus = AC_MINUS; break; case 'x': $econf->x_access = eval_ac($econf->x_access, $condition, $set_plus_minus); $set_plus_minus = AC_SET; break; case 'd': $econf->d_access = eval_ac($econf->d_access, $condition, $set_plus_minus); $set_plus_minus = AC_SET; break; case 'n': $econf->n_access = eval_ac($econf->n_access, $condition, $set_plus_minus); $set_plus_minus = AC_SET; break; case 'e': $econf->e_access = eval_ac($econf->e_access, $condition, $set_plus_minus); $set_plus_minus = AC_SET; break; } } } function eval_ac($current_access, $condition, $set_plus_minus) { switch ($set_plus_minus) { case AC_SET: return $condition; case AC_PLUS: return $current_access || $condition; case AC_MINUS: return $condition ? FALSE : $current_access; } } ?>