diff -r 5b37998e522e -r 162c1de6545a web/lib/Zend/Service/ReCaptcha/Response.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Service/ReCaptcha/Response.php Fri Mar 11 15:05:35 2011 +0100 @@ -0,0 +1,159 @@ +setStatus($status); + } + + if ($errorCode !== null) { + $this->setErrorCode($errorCode); + } + + if ($httpResponse !== null) { + $this->setFromHttpResponse($httpResponse); + } + } + + /** + * Set the status + * + * @param string $status + * @return Zend_Service_ReCaptcha_Response + */ + public function setStatus($status) + { + if ($status === 'true') { + $this->_status = true; + } else { + $this->_status = false; + } + + return $this; + } + + /** + * Get the status + * + * @return boolean + */ + public function getStatus() + { + return $this->_status; + } + + /** + * Alias for getStatus() + * + * @return boolean + */ + public function isValid() + { + return $this->getStatus(); + } + + /** + * Set the error code + * + * @param string $errorCode + * @return Zend_Service_ReCaptcha_Response + */ + public function setErrorCode($errorCode) + { + $this->_errorCode = $errorCode; + + return $this; + } + + /** + * Get the error code + * + * @return string + */ + public function getErrorCode() + { + return $this->_errorCode; + } + + /** + * Populate this instance based on a Zend_Http_Response object + * + * @param Zend_Http_Response $response + * @return Zend_Service_ReCaptcha_Response + */ + public function setFromHttpResponse(Zend_Http_Response $response) + { + $body = $response->getBody(); + + $parts = explode("\n", $body, 2); + + if (count($parts) !== 2) { + $status = 'false'; + $errorCode = ''; + } else { + list($status, $errorCode) = $parts; + } + + $this->setStatus($status); + $this->setErrorCode($errorCode); + + return $this; + } +} \ No newline at end of file