Retrieve the expected CAPTCHA code

@return mixed|null
331228
protected function getExpectedCode()
    {
        $options = $this->session->get($this->key, array());

        if (is_array($options) && isset($options['phrase'])) {
            return $options['phrase'];
        }

        return null;
    }
232142
public function getKeyPress()
    {
        $this->disableShowInput();
        $this->disableRequireReturn();

        $input = null;
        while (1) {
            $input = fread(STDIN, 10000);
            break;
        }

        $this->enableShowInput();
        $this->enableRequireReturn();

        $specialKey = $this->detectSpecialKey($input);

        return $specialKey ? $specialKey : (string)$input;
    }
647331
protected function _getCaptcha(array $data) {
		$id = !empty($data['captcha_id']) ? (int)$data['captcha_id'] : null;

		if (array_key_exists($id, $this->_captchas)) {
			return $this->_captchas[$id];
		}

		$request = Router::getRequest();
		if (!$request->getSession()->started()) {
			$request->getSession()->start();
		}
		$sessionId = $request->getSession()->id();
		if (!$sessionId && PHP_SAPI === 'cli') {
			$sessionId = 'test';
		}

		$ip = $request->clientIp();

		if (!$id) {
			$this->_captchas[$id] = null;
			return null;
		}

		$conditions = [
			'id' => $id,
			'ip' => $ip,
			'session_id' => $sessionId
		];
		$this->_captchas[$id] = $this->_captchasTable->find()->where($conditions)->first();
		return $this->_captchas[$id];
	}
811025
private function getImage($code)
    {
        if (!is_dir(DIR_CACHE . 'captcha/')) {
            FileSystem::mkDir(DIR_CACHE . 'captcha/');
        }

        $filename_url = DIR_CACHE_URL . 'captcha/' . VISITOR_HASH . md5($code) . '.png';
        $filename = DIR_BASE . $filename_url;

        // Already generated
        if (file_exists($filename)) {
            return $filename_url;
        }

        // Placeholders
        $linenum = rand($this->min_length, $this->max_length);
        $img_arr = array(
            'captcha_empty.png',
            'captcha_empty_black.png'
        );

        // Fonts, can set multiple
        $font_arr = [];
        $font_arr[0]['fname'] = 'droidsans.ttf'; // TODO place fonts in folder
        $font_arr[0]['size'] = rand(15, 20); // Size in pt

        // Random font
        $n = rand(0, count($font_arr) - 1);
        $img_fn = $img_arr[rand(0, count($img_arr) - 1)];
        $image_handler = imagecreatefrompng(DIR_CMS_IMAGES . $img_fn);

        // Fill
        for ($i = 0; $i < $linenum; $i++) {
            $color = imagecolorallocate($image_handler, rand(0, 150), rand(0, 100), rand(0, 150));
            imageline($image_handler, rand(0, 15), rand(1, 15), rand(100, 160), rand(1, 50), $color);
        }
        $color = imagecolorallocate($image_handler, rand(0, 200), 0, rand(0, 200));

        $x = rand(0, 5);
        for ($i = 0; $i < strlen($code); $i++) {
            $x += 15;
            $letter = substr($code, $i, 1);
            imagettftext($image_handler, $font_arr[$n]['size'], rand(2, 4), $x, rand(20, 25), $color, DIR_ASSETS . 'fonts/' . $font_arr[$n]['fname'], $letter);
        }

        for ($i = 0; $i < $linenum; $i++) {
            $color = imagecolorallocate($image_handler, rand(0, 255), rand(0, 200), rand(0, 255));
            imageline($image_handler, rand(0, 20), rand(1, 50), rand(150, 180), rand(1, 50), $color);
        }

        // Save file
        ImagePNG($image_handler, $filename);
        ImageDestroy($image_handler);
        return $filename_url;
    }
922227
public function displayCaptchaPicture()
    {
        $app = Application::getFacadeApplication();
        $responseFactory = $app->make(ResponseFactoryInterface::class);

        return $responseFactory->notFound('Captcha without image');
    }
729996
public function get($code)
    {
        foreach ($this->getDbConnection()->fetchAll(
            'SELECT * from oauth_auth_code
            WHERE auth_code = :authCode AND expire_time > :ts',
            [
                'authCode' => $code,
                'ts' => time()
            ]
        ) as $row) {
            if ($row) {
                return (new AuthCodeEntity($this->server))
                    ->setRedirectUri($row['client_redirect_uri'])
                    ->setExpireTime($row['expire_time'])
                    ->setId($row['auth_code']);
            }
        }
        return null;
    }
382367
public function generateCode()
    {
        $this->digits[0] = rand(0, 9);
        $this->digits[1] = rand(0, 9);
        $this->digits[2] = rand(0, 9);
        $this->digits[3] = rand(0, 9);
        $this->digits[4] = rand(0, 9);
        $this->value = $this->digits[0] * 10000 + $this->digits[1] * 1000;
        $this->value += $this->digits[2] * 100 + $this->digits[3] * 10 + $this->digits[4];
        $this->xorValue = $this->value ^ $this->config->codeKey;
        $_SESSION['captcha'] = $this->xorValue;

        return $this;
    }
365873
public function getCodeAsString()
    {
        switch ($this->getCode()) {
            case self::BURIED:
                return 'Buried';
                break;

            case self::NOT_FOUND:
                return 'Not Found';
                break;

            case self::EXPECTED_CRLF:
                return 'Expected CRLF';
                break;

            case self::JOB_TOO_BIG:
                return 'Job Too Big';
                break;

            case self::DEADLINE_SOON:
                return 'Deadline Soon';
                break;

            case self::TIMED_OUT:
                return 'Timed Out';
                break;

            case self::TUBE_NAME_TOO_LONG:
                return 'Tube Name Too Long';
                break;

            case self::NOT_IGNORED:
                return 'Not Ignored';
                break;

            case self::OUT_OF_MEMORY:
                return 'Out of Memory';
                break;

            case self::INTERNAL_ERROR:
                return 'Internal Error';
                break;

            case self::BAD_FORMAT:
                return 'Bad Format';
                break;

            case self::UNKNOWN_COMMAND:
                return 'Unknown Command';
                break;

            case self::SERVER_OFFLINE:
                return 'Server Offline';
                break;

            case self::SERVER_READ:
                return 'Server Read Error';
                break;

            case self::SERVER_WRITE:
                return 'Server Write Error';
                break;

            default:
                return 'Unknown';
                break;
        }
    }
660137
public function getAuthorizationCode($code)
    {
        if (isset($this->authorizationCodes[$code])) {
            return $this->authorizationCodes[$code];
        }

        return null;
    }
480714
protected function getFigcaption()
    {
        $figcaption = '';

        if ($this->hasAttribute('title')) {
            $figcaption = '<figcaption class="code-highlight-caption">';
            $figcaption .= '<span class="code-highlight-caption-title">';
            $figcaption .= $this->getAttribute('title');
            $figcaption .= '</span>';
            $figcaption .= $this->getFigcaptionLink();
            $figcaption .= '</figcaption>';
        }

        return $figcaption;
    }
122443
public function getResponseCode()
    {
        $code = 0;

        $dom = $this->getDOMDocument();
        $xpath = new DOMXPath($dom);
        if (($codeAttribute = $xpath->query('/response/@code')->item(0)) instanceof DOMAttr) {
            $code = intval($codeAttribute->nodeValue);
        }

        return $code;
    }
1271457
public function getInput()
    {
        $this->htmlOptions['class'] = (isset($this->htmlOptions['class']) ? $this->htmlOptions['class'] . ' ' : '') . 'input markdown-input';
        $this->htmlOptions['ajax-url'] = $this->previewURL ?: WebApp::get()->request()->getCurrentURL();
        $this->htmlOptions['csrf-key'] = WebApp::get()->request()->getCsrfKey();
        $this->htmlOptions['csrf-value'] = WebApp::get()->request()->getCsrfValue();
        return Form::get()->textarea($this->getName(), $this->getValue(), $this->htmlOptions);
    }
1041533
public function html()
    {
        if (!$this->getPublicKey()) {
            throw new Exception('You must set public key provided by reCaptcha');
        }

        $error = ($this->getError() ? '&amp;error=' . $this->getError() : null);

        $theme = null;

        // If user specified a reCaptcha theme, output it as one of the options
        if ($this->theme) {
            $theme = '<script> var RecaptchaOptions = {theme: "' . $this->theme . '"};</script>';
        }

        return $theme . '<script type="text/javascript" src="' . self::SERVER . '/challenge?k=' . $this->getPublicKey() . $error . '"></script>

        <noscript>
            <iframe src="' . self::SERVER . '/noscript?k=' . $this->getPublicKey() . $error . '" height="300" width="500" frameborder="0"></iframe><br/>
            <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
            <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
        </noscript>';
    }
764191
public function get_response_code()
    {
        switch ($this->conn->resultcode) {
            case 'NOPERM':
                return self::NOPERM;
            case 'READ-ONLY':
                return self::READONLY;
            case 'TRYCREATE':
                return self::TRYCREATE;
            case 'INUSE':
                return self::INUSE;
            case 'OVERQUOTA':
                return self::OVERQUOTA;
            case 'ALREADYEXISTS':
                return self::ALREADYEXISTS;
            case 'NONEXISTENT':
                return self::NONEXISTENT;
            case 'CONTACTADMIN':
                return self::CONTACTADMIN;
            default:
                return self::UNKNOWN;
        }
    }
806892
protected function getTokenInstance()
    {
        if (!$this->tokenInstance) {
            $this->tokenInstance = Token::instance('captcha')->setOptions(['title' => '图形码']);
        }
        
        return $this->tokenInstance;
    }
172183
public function getRoundCode()
    {
        $roundCode = null;
        $roundId = $this->getRoundId();
        if ($roundId > 0) {
            $roundCode = $this->getRespondentTrack()->getRoundCode($roundId);
        }

        return $roundCode;
    }
597487
public function getCode()
    {
        if (!$this->isSuccessful() && isset($this->data['error']) && isset($this->data['error']['code'])) {
            return $this->data['error']['code'];
        }

        return null;
    }