public function display() { if ($this->hasErrors()) { $this->tpl->setVar('errors', $this->getErrors()); } if ($this->tpl->post === null) { $this->tpl->setVar('post', Http::getPost(), false, true); } if ($this->tpl->query === null) { $this->tpl->setVar('query', Http::getQuery(), false, true); } if ($this->tpl->cookie === null) { $this->tpl->setVar('cookie', Http::getCookie(), false, true); } $this->tpl->setVar('notifyInformation', $this->session->get('notifyInformation'), false, true); $this->tpl->setVar('notifyError', $this->session->get('notifyError'), false, true); $this->tpl->setVar('notifySuccess', $this->session->get('notifySuccess'), false, true); if ($this->_isAjax) { if ($this->hasErrors()) { $this->addAjaxDatas('errors', $this->getErrors()); } if ($this->_ajaxAutoAddDatas['post'] && !array_key_exists('post', $this->_ajaxDatas)) { $this->addAjaxDatas('post', Http::getPost()); } if ($this->_ajaxAutoAddDatas['query'] && !array_key_exists('query', $this->_ajaxDatas)) { $this->addAjaxDatas('query', Http::getQuery()); } if ($this->_ajaxAutoAddDatas['cookie'] && !array_key_exists('cookie', $this->_ajaxDatas)) { $this->addAjaxDatas('cookie', Http::getCookie()); } if ($this->_ajaxAutoAddDatas['content'] && !array_key_exists('content', $this->_ajaxDatas)) { $this->addAjaxDatas('content', $this->tpl->getContent()); } if (!array_key_exists('notifyInformation', $this->_ajaxDatas)) { $this->addAjaxDatas('notifyInformation', $this->session->get('notifyInformation')); } if (!array_key_exists('notifyError', $this->_ajaxDatas)) { $this->addAjaxDatas('notifyError', $this->session->get('notifyError')); } if (!array_key_exists('notifySuccess', $this->_ajaxDatas)) { $this->addAjaxDatas('notifySuccess', $this->session->get('notifySuccess')); } // No cache if (!$this->_ajaxDatasCache) { Header::sentHeader('Cache-Control', 'no-cache, must-revalidate'); Header::sentHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT'); } switch ($this->_ajaxDatasType) { case self::HTML: Header::sentHeader('Content-type', 'text/html'); foreach ($this->_ajaxDatas as $data) { echo $data; } break; case self::XML: Header::sentHeader('Content-type', 'text/xml'); foreach ($this->_ajaxDatas as $data) { echo $data; } break; case self::JSON: Header::sentHeader('Content-type', 'application/json'); echo json_encode((object) $this->_ajaxDatas, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); break; default: throw new \Exception('Ajax datas type not valid'); } } else { //display $this->tpl->display(); $this->log->debug('Display template file : "' . $this->tpl->getFile() . '"', 'router'); } // Delete stored messages $this->session->delete('notifyInformation', true); $this->session->delete('notifyError', true); $this->session->delete('notifySuccess', true); }
protected function _display($captchaType) { $this->create(Session::getInstance()->get($this->getFormName() . 'Captcha'), $captchaType); Header::sentHeader('Cache-Control', 'no-store, no-cache, must-revalidate'); Header::sentHeader('Cache-Control', 'post-check=0, pre-check=0', false); Header::sentHeader('Pragma', 'no-cache'); Header::sentHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT'); if ($captchaType == 'image') { Header::sentHeader('Content-Type', 'image/' . $this->_imageFormat); // display captcha switch ($this->_imageFormat) { case 'png': imagepng($this->_imageContents); break; case 'jpg': imagejpeg($this->_imageContents); break; case 'gif': imagegif($this->_imageContents); break; } } elseif ($captchaType == 'audio') { Header::sentHeader('Content-Type', 'audio/x-wav'); Header::sentHeader('Content-Length', (string) strlen($this->_audioContents)); // display captcha echo $this->_audioContents; } }