check for spam

@param array $fields names of fields to check against spam
@param int $threshold number of suspicious content which when exceeded will indicate spam
@return boolean $spam_detected
559934
public function detectSpam(array $fields = [], $threshold = 3) {

		$verify	= $this->requestValues->get('verify');
		$timer	= Session::getSessionDataBag()->get('antiSpamTimer');

		if(
			!$verify ||
			!isset($timer[$verify]) ||
			(microtime(true) - $timer[$verify] < 1)
		) {
			return true;
		}

		$label = md5($verify);

		if(is_null($this->requestValues->get('confirm_entry_' . $label)) || $this->requestValues->get('confirm_entry_' . $label) !== '') {
			return true;
		}

		foreach($fields as $f) {
			if(preg_match_all('~<\s*a\s+href\s*\=\s*(\\\\*"|\\\\*\'){0,1}http://~i', $this->requestValues->get($f), $tmp) > $threshold) {
				return true;
			}
			if(preg_match('~\[\s*url.*?\]~i', $this->requestValues->get($f))) {
				return true;
			}
		}
		return false;

	}
290551
public function isDirty($fields = [])
    {
        if (!is_array($fields)) {
            $fields = [$fields];
        }

        foreach ($fields as $field) {
            $field = $this->normalizeFieldName($field);

            if (array_key_exists($field, $this->dirty)) {
                return true;
            }
        }

        return false;
    }
1298004
protected function checkRequiredFields()
    {
        if (empty($this->toAddresses)) {
            return false;
        }
        if (empty($this->subject)) {
            return false;
        }

        if (empty($this->plainMessage) && empty($this->htmlMessage) && empty($this->attachments)) {
            return false;
        }

        return true;
    }
994110
public function fields(array $fields)
    {
        $fields = self::filter($fields);
        $diff   = array_diff($fields, Config::table($this->name)->fields());

        if (empty($diff))
        {
            return TRUE;
        }
        throw new LazerException('Field(s) "' . implode(', ', $diff) . '" does not exists in table "' . $this->name . '"');
    }
1210470
public function selectExcept($fields)
    {
        $fields = array_diff($this->getFields(), is_array($fields) ? $fields : [$fields]);

        return $this->select($fields);
    }
514637
public function select($fields)
    {
        if (!$fields) {
            return $this;
        }

        if (is_string($fields)) {
            $fields = (array)preg_split('#[\s,]+#', $fields, -1, PREG_SPLIT_NO_EMPTY);
        }

        $r = '';
        /** @noinspection ForeachSourceInspection */
        foreach ($fields as $k => $v) {
            if (strpos($v, '[') === false && strpos($v, '(') === false) {
                /** @noinspection NotOptimalIfConditionsInspection */
                if (is_int($k)) {
                    $r .= preg_replace('#\w+#', '[\\0]', $v) . ', ';
                } else {
                    $r .= preg_replace('#\w+#', '[\\0]', $v) . ' AS [' . $k . '], ';
                }
            } elseif (is_int($k)) {
                $r .= $v . ', ';
            } else {
                $r .= $v . ' AS [' . $k . '], ';
            }
        }
        $this->_fields = substr($r, 0, -2);

        return $this;
    }
573484
private static function handleSelectandi($fields) {
        $i = 0;
        $res = '';
        foreach($fields as $what) {
            $res .= ($i > 0 ? ', ' : '') . self::$_ops->selectandi($what);
            $i++;
        }
        return $res;
    }
451257
public function iShouldNotSeeTheField($field) {
    $element = $this->getSession()->getPage();
    $this->assertElementNotVisible($field, $element->findField($field));
  }
733837
public function isSpam(Request $request)
    {
        $spammers = $this->getSpammerListFromCache();

        $referrerUrl = $request->getParam('urlref');

        foreach ($spammers as $spammerHost) {
            if (stripos($referrerUrl, $spammerHost) !== false) {
                Common::printDebug('Referrer URL is a known spam: ' . $spammerHost);
                return true;
            }
        }

        return false;
    }
510786
public static function checkNumberField($field, $msg)
    {
        if ((StringUtils::isEmpty($field) === false) && !is_numeric($field)) {
            throw new MsgException($msg);
        }
    }
393499
public function getAllEmailAddresses($fields = ['to', 'from', 'cc', 'bcc'])
    {
        $addresses = [];
        foreach ($fields as $field) {
            if(isset($this->allEmailAddressesByField[$field])) {
                foreach ($this->allEmailAddressesByField[$field] as $emailAddress) {
                    $addresses[] = $emailAddress;
                }
            }
        }

        return array_unique($addresses);
    }
1190863
public function mremove(array $fields)
    {
        $removed = 0;

        foreach ($fields as $field) {
            $removed += $this->remove($field);
        }

        return $removed;
    }
232439
public function checkPost($source, $items = array())
    {
        $this->passed = false;
        foreach ($items as $item => $rules) {

            foreach ($rules as $rule => $rule_value) {

                $value = $source[$item];
                $item  = $item;

                if ($rule === 'required' && empty($value)) {

                    $this->addError(ucfirst($item) . $this->feedback['req']);

                } else if (!empty($value)) {

                    switch ($rule) {
                        case 'min':
                            if (strlen($value) < $rule_value)  {
                                $this->addError(
                                    ucfirst($item) 
                                    . $this->feedback['min'] 
                                    . $rule_value 
                                    . $this->feedback['chars']
                                );
                            }
                            break;

                        case 'max':
                            if (strlen($value) > $rule_value) {
                                $this->addError(
                                    ucfirst($item) 
                                    . $this->feedback['max'] 
                                    . $rule_value 
                                    . $this->feedback['chars']
                                );
                            }
                            break;

                        case 'matches':
                            if ($value != $source[$rule_value])  {
                                $this->addError(
                                    ucfirst($rule_value) 
                                    . $this->feedback['match'] 
                                    . $item
                                );
                            }
                            break;

                        case 'notTaken':
                            $check = $this->db->select(
                                array($item), 
                                $rule_value,
                                null, 
                                array(array($item, '=', $value))
                            );

                            if ($check->count()) {
                                $this->addError("'$value'" . $this->feedback['exists']);
                            }
                            break;

                        case 'validEmail':
                            if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
                                $this->addError(ucfirst($item) . $this->feedback['invalid']);
                            }
                            break;

                        case 'validInput':
                            if (!preg_match('/^[0-9A-Za-z\æ\ø\å\s]{3,}$/', $value))  {
                                $this->addError(
                                    ucfirst($item) 
                                    . $this->feedback['invalid'] 
                                    . $this->feedback['input']
                                );
                            }
                            break;

                        case 'noSpaces':
                            if (strpos($value, ' ')) {
                                $this->addError(
                                    ucfirst($item) 
                                    . $this->feedback['spaces']
                                );
                            }
                            break;

                        case 'validNumber':
                            if (!is_numeric($value)) {
                                $this->addError(ucfirst($item) . $this->feedback['number']);
                            }
                            break;
                    }
                }
            }
        }

        $this->passed = (empty($this->errors)) ? true : false;

        return $this;
    }
1097451
public function exclude($field)
    {
        $fields = (is_array($field) ? $field : func_get_args());

        foreach ($fields as $field) {
            $this->fields[$field] = -1;
        }
    }
847412
private function belowErrorCountThreshold(array $messages)
    {
        if (is_int($this->configuration[self::ERROR_COUNT_THRESHOLD_KEY]) === false) {
            throw new Exception(sprintf('Invalid «%s» config key.', self::ERROR_COUNT_THRESHOLD_KEY));
        }

        $threshold = $this->configuration[self::ERROR_COUNT_THRESHOLD_KEY];
        $belowThreshold = count($messages) <= $threshold;

        return $belowThreshold;
    }
151048
public function validate($fields = [])
    {
        if (empty($this->rules())) return true;
        foreach ($this->rules() as $rules) {
            if (is_array($rules[0])) {
                foreach ($rules[0] as $v){
                    if(!empty($fields) && !in_array($v,$fields)) continue;
                    $this->_validate($rules,$v);
                }
            } else {
                if(!empty($fields) && !in_array($rules[0],$fields)) continue;
                $this->_validate($rules,$rules[0]);
            }
        }
        $attributes = $this->attributes();
        if(!empty($this->_validateError) && !empty($attributes)){
            foreach ($this->_validateError as $k=> &$v){
                if(strpos($v,':attribute')!==false){
                    $v = isset($attributes[$k])? str_replace(':attribute',$attributes[$k],$v) : $v;
                }
            }
        }
        return empty($this->_validateError);
    }
97483
public function isValid($sendHeaders = true)
    {
        if (Application::getInstance()->runningInConsole()) {
            return !$this->validator->with($this->inputs)->fails();
        }

        return $this->formBuilder->isValid($sendHeaders);
    }