null); protected $_config = null; public function __construct($options = array()) { $this->setOptions($options); return $this; } public function setOptions($options = array()) { foreach ($options as $key => $value) { $method = 'set' . ucfirst($key); if (method_exists($this, $method)) { $this->$method($value); } else { $this->_options[$key] = $value; } } return $this; } public function setDoc($doc) { $this->_doc = $doc; } public function setTemplate($template) { $this->_template = (string) $template; } protected function getTemplate() { if (null == $this->_template) { $this->_template = Qs_Array::get($this->_options, 'tpl', '404.tpl'); } return $this->_template; } public function getConfig($field = false, $default = null) { if (null === $this->_config) { $configObj = Zend_Registry::get('config')->app; if (isset($configObj->notFound)) { $this->_config = $configObj->notFound->toArray(); } } return Qs_Array::get($this->_config, $field, $default); } protected function _getDataObj() { if (null === $this->_dataObj) { $this->_dataObj = new App_NotFound_Obj(); } return $this->_dataObj; } protected function _execRedirection() { if (Qs_Version::compareVersion('2.1.0') <= 0 && Zend_Registry::get('config')->app->cms->hasRedirection) { $obj = new App_Redirection_Obj(); if (($redirect = $obj->getRedirect(CURRENT_PAGE))) { Qs_Http::redirect(BASE_URL_LANGUAGE . '/' . $redirect['destination'], $redirect['status']); exit; } } return false; } protected function _getRefererMode() { static $mode = null; if (null === $mode) { $referer = Qs_Array::get($_SERVER, 'HTTP_REFERER'); if (empty($referer)) { $mode = self::MODE_EMPTY; } else if (Qs_Request::isOwnUrl($referer)) { $mode = self::MODE_OWN; } else { $mode = self::MODE_ALIEN; } } return $mode; } protected function _logNotFound() { if (Qs_Version::compareVersion('2.1.0') > 0) { return $this; } $data = $this->_collectData(); $refererMode = $this->_getRefererMode(); $logMode = (int) $this->getConfig('logMode'); if ($refererMode === ($refererMode & $logMode)) { $this->_getDataObj()->insert($data); } $notifyMode = (int) $this->getConfig('notifyMode'); if ($refererMode === ($refererMode & $notifyMode)) { $mailData = $this->_getMailData($data); $this->_sendNotifyEmails($mailData); } return $this; } protected function _collectData() { $data = array(); $data['modeId'] = $this->_getRefererMode(); $data['isAjax'] = (Qs_Request::isXmlHttpRequest()) ? 'y' : 'n'; $data['request'] = Qs_Array::get($_SERVER, 'REQUEST_URI', ''); $data['referer'] = Qs_Array::get($_SERVER, 'HTTP_REFERER', ''); $data['userAgent'] = Qs_Array::get($_SERVER, 'HTTP_USER_AGENT', ''); $data['ipAddress'] = Qs_Array::get( $_SERVER, 'REMOTE_ADDR', Qs_Array::get($_SERVER, 'HTTP_X_FORWARDED_FOR', '') ); return $data; } protected function _getMailData($data) { $mailData = $data; $mailData['mode'] = $this->_getDataObj()->getNotFoundModeTitle($data['modeId']); $mailData['isAjax'] = ('y' === $data['isAjax']) ? 'Yes' : 'No'; $mailData['viewLink'] = BASE_URL . '/' . Qs_SiteMap::getAliasByItem('NotFound_Admin'); $mailData = array_map('htmlspecialchars', $mailData); return $mailData; } protected function _sendNotifyEmails($data) { $emails = $this->getConfig('notifyEmails'); if (!empty($emails) && is_array($emails)) { $settingsEmails = App_Settings_Obj::get('notFoundNotifyEmails', 'parseEmails'); if (!empty($settingsEmails) && is_array($settingsEmails)) { $emails = array_merge($emails, $settingsEmails); $emails = array_unique($emails); } } else { return $this; } $template = new Qs_Template(); $template->addConstantDataSource(); $template->addGlobalsDataSource(); $template->addArrayDataSource($data); $subject = $template->render($this->getConfig('email[subject]', '')); $body = $template->render($this->getConfig('email[body]', '')); $mail = new Qs_Mail(); $mail->setFrom(App_Settings_Obj::get('siteFrom')); $mail->setSubject($subject); $mail->setHtml($body, null, WWW_PATH); foreach ($emails as $email) { $mail->addTo($email); } return $mail->send(); } public function exec() { $this->_execRedirection(); $this->_logNotFound(); header('HTTP/1.0 404 Not Found'); if (!Qs_Request::isXmlHttpRequest()) { $this->_doc->assign('item', $this->_options); $this->_doc->setLayoutTemplate($this->getTemplate()); $this->_doc->sendHeaders(); echo $this->_doc->fetch(); } exit; } }