<?php
 class vB_HumanVerify_Question extends vB_HumanVerify { protected bool $usestoken = true; protected function fetch_answer() { $question = vB::getDbAssertor()->getRow('hv_question_fetch_answer'); return $question['questionid']; } public function verify_token($input, $action) { if (!is_array($input) OR empty($input['input'])) { if (!$this->fetch_answer()) { return true; } else { $this->error = 'humanverify_missing'; return false; } } $input['input'] = trim($input['input']); vB::getDbAssertor()->assertQuery('humanverify', [ vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'viewed' => 1, vB_dB_Query::CONDITIONS_KEY => [ 'hash' => $input['hash'], 'viewed' => 0 ] ]); if (vB::getDbAssertor()->affected_rows()) { $question = vB::getDbAssertor()->getRow('hv_question_fetch', [ 'hash' => $input['hash'], ]); $this->delete_token($input['hash']); if (!$question) { $this->error = 'humanverify_question_wronganswer'; return false; } else if (!$question['questionid']) { return true; } else { if ($question['regex'] AND preg_match('#' . str_replace('#', '\#', $question['regex']) . '#siU', $input['input'])) { return true; } else if ( vB::getDbAssertor()->getRow('hvanswer', [ 'questionid' => intval($question['questionid']), 'answer' => $input['input'] ]) ) { return true; } else { $this->error = 'humanverify_question_wronganswer'; return false; } } } else { $this->delete_token($input['hash'], null, 0); $this->error = 'humanverify_question_wronganswer'; return false; } } } 