/** * helper for check with strings * * @since 1.6.3 * @param str $string string that is going to be checked * @return bool true if ad can be displayed */ static function helper_check_string($string = '', $options = array()) { if (!isset($options['operator']) || !isset($options['value']) || '' === $options['value']) { return true; } $operator = $options['operator']; $value = $options['value']; // check length of url if ($operator !== 'regex' && $operator !== 'regex_not') { if (strlen($value) > strlen($string)) { return false; } } // check the condition by mode and bool $condition = true; switch ($operator) { // referrer contains string on any position case 'contain': $condition = stripos($string, $value) !== false; break; // referrer does not contain string on any position // referrer does not contain string on any position case 'contain_not': $condition = stripos($string, $value) === false; break; // referrer starts with the string // referrer starts with the string case 'start': $condition = stripos($string, $value) === 0; break; // referrer does not start with the string // referrer does not start with the string case 'start_not': $condition = stripos($string, $value) !== 0; break; // referrer ends with the string // referrer ends with the string case 'end': // check if string is longer than referrer $strlen = strlen($string); $vallen = strlen($value); $condition = substr_compare($string, $value, $strlen - $vallen, $vallen, true) === 0; break; // referrer does not end with the string // referrer does not end with the string case 'end_not': // check if string is longer than referrer $strlen = strlen($string); $vallen = strlen($value); $condition = substr_compare($string, $value, $strlen - $vallen, $vallen, true) !== 0; break; // referrer is equal to the string // referrer is equal to the string case 'match': // strings do match, but should not or not match but should $condition = strcasecmp($value, $string) === 0; break; // referrer is not equal to the string // referrer is not equal to the string case 'match_not': // strings do match, but should not or not match but should $condition = strcasecmp($value, $string) !== 0; break; // string is a regular expression // string is a regular expression case 'regex': // check regular expression first if (@preg_match($value, null) === false) { Advanced_Ads::log("Advanced Ads: regular expression '{$value}' in visitor condition is broken."); } else { $condition = preg_match($value, $string); } break; // string is not a regular expression // string is not a regular expression case 'regex_not': if (@preg_match($value, null) === false) { Advanced_Ads::log("Advanced Ads: regular expression '{$value}' in visitor condition is broken."); } else { $condition = !preg_match($value, $string); } break; } return $condition; }