/** * Check if a value passed into the ad request (through $_REQUEST (so GET/POST/COOKIE) * via a name=value pair matches the limitation configured * * @param string $limitation The variable limitation * @param string $op The operator * @param array $aParams An array of additional parameters to be checked * @return boolean Whether this impression's channel passes this limitation's test. */ function MAX_checkSite_Variable($limitation, $op, $aParams = array()) { if (empty($aParams)) { $aParams = $_REQUEST; } $key = substr($limitation, 0, strpos($limitation, '|')); $value = substr($limitation, strpos($limitation, '|') + 1); if (!isset($limitation) || !isset($aParams[$key])) { // To be safe, unless the paramters passed in, and configured are avaiable, // return depending on if the $op is considered a 'positive' test return !MAX_limitationsIsOperatorPositive($op); } else { if (MAX_limitationsIsOperatorNumeric($op)) { return MAX_limitationMatchNumeric($key, $value, $op, $aParams); } else { return MAX_limitationsMatchString($key, $value, $op, $aParams); } } }
/** * Match a numeric value (greater than or less than) * * @param string $paramName Name of the parameter to look for in an array. * @param string $limitation Value to be matched with. * @param string $op The operator used to compare strings. * @param string $aParams The array in which the value is looked for. * @param string $namespace The namespace in the $GLOBALS['_MAX'] array used * if when $aParams is empty. * @return boolean True if the parameters fulfill the limitations, false * otherwise. * * @author Mohammed El-Hakim * @author Chris Nutting <*****@*****.**> */ function MAX_limitationMatchNumeric($paramName, $limitation, $op, $aParams = array(), $namespace = 'CLIENT') { if ($limitation == '') { return !MAX_limitationsIsOperatorPositive($op); } if (empty($aParams)) { $aParams = $GLOBALS['_MAX'][$namespace]; } if (!isset($aParams[$paramName]) || !is_numeric($aParams[$paramName]) || !is_numeric($limitation)) { return !MAX_limitationsIsOperatorPositive($op); } else { $value = $aParams[$paramName]; } if ($op == 'lt') { return $value < $limitation; } else { if ($op == 'gt') { return $value > $limitation; } else { return !MAX_limitationsIsOperatorPositive($op); } } }
/** * Returns an array with downgraded format of operator and data * for array-based delivery limitations. * The old operator is stored in ['op'] field, * the data in ['data'] field. * * @param string $op A new operator. * @param string $sData A new data specification. * @return array An array which contains an old operator in the ['op'] field * and an old data in ['data'] field. */ function MAX_limitationsGetADowngradeForArray($op, $sData) { $aResult = array('data' => $sData); if (MAX_limitationsIsOperatorPositive($op)) { $aResult['op'] = '=='; } else { $aResult['op'] = '!='; } return $aResult; }
/** * An utility function which checks if the value in $aParams[$paramName] * matches the array limitations specified in $limitation and $op. * If $aParams is empty then $GLOBALS['_MAX'][$namespace] is used instead. * See {@link MAX_limitationsMatchArrayValue} for more details on * how matching is done. * * @param string $paramName * @param string $limitation * @param string $op * @param string $aParams * @param string $namespace * @return boolean True if the value matches the limitations, false otherwise. */ function MAX_limitationsMatchArray($paramName, $limitation, $op, $aParams = array(), $namespace = 'CLIENT') { if (empty($aParams)) { $aParams = $GLOBALS['_MAX'][$namespace]; } if ($limitation == '' || empty($aParams[$paramName])) { return !MAX_limitationsIsOperatorPositive($op); } return MAX_limitationsMatchArrayValue($aParams[$paramName], $limitation, $op); }