/** * Construct and decide whether to show the captcha or not. * * @note Passing $page by reference to setup smarty vars easily. * @param \Page $page */ public function __construct(&$page) { if (!$page instanceof \Page) { throw new \InvalidArgumentException('Invalid Page variable provided'); } $this->page = $page; if ($this->shouldDisplay()) { $this->page->smarty->assign('showCaptcha', true); $this->page->smarty->assign('sitekey', $this->sitekey); if ($this->page->isPostBack()) { if (!$this->processCaptcha($_POST, $_SERVER['REMOTE_ADDR'])) { $this->page->smarty->assign('error', $this->getError()); } //Delete this key after using so it doesn't interfere with normal $_POST //processing. (i.e. contact-us) unset($_POST[Captcha::RECAPTCHA_POSTKEY]); } } else { $this->page->smarty->assign('showCaptcha', false); } }