protected function _check($ip, $userAgent)
 {
     if (Http::getQuery($this->_trapName) && !Validate::isGoogleBot()) {
         $isBadCrawler = false;
         $isGoodCrawler = false;
         if ($this->_badCrawlerFile) {
             $badCrawlerXml = simplexml_load_file($this->_badCrawlerFile);
             if (is_null($badCrawlerXml) || !$badCrawlerXml) {
                 throw new \Exception('Invalid xml file : "' . $this->_badCrawlerFile . '"');
             }
         }
         if ($this->_goodCrawlerFile) {
             $goodCrawlerXml = simplexml_load_file($this->_goodCrawlerFile);
             if (is_null($goodCrawlerXml) || !$goodCrawlerXml) {
                 throw new \Exception('Invalid xml file : "' . $this->_goodCrawlerFile . '"');
             }
         }
         if ($badCrawlerXml) {
             $badCrawlerList = $badCrawlerXml->crawler;
             foreach ($badCrawlerList as $crawler) {
                 if (isset($crawler->ip) && (string) $crawler->ip == $ip) {
                     $isBadCrawler = true;
                 }
                 if (isset($crawler->userAgent) && strripos((string) $crawler->userAgent, $userAgent) !== false) {
                     $isBadCrawler = true;
                 }
                 if ($isBadCrawler) {
                     $this->_catch($ip, $userAgent, self::CRAWLER_BAD);
                     Session::getInstance()->add(md5($ip . 'badcrawler'), true, true, true);
                     Router::getInstance()->show403(true);
                     break;
                 }
             }
             unset($crawler);
         }
         if ($goodCrawlerXml) {
             $goodCrawlerList = $goodCrawlerXml->crawler;
             foreach ($goodCrawlerList as $crawler) {
                 if (isset($crawler->ip) && (string) $crawler->ip == $ip) {
                     $isGoodCrawler = true;
                 }
                 if (isset($crawler->userAgent) && strripos((string) $crawler->userAgent, $userAgent) !== false) {
                     $isGoodCrawler = true;
                 }
                 if ($isGoodCrawler) {
                     $this->_catch($ip, $userAgent, self::CRAWLER_BAD);
                     break;
                 }
             }
             unset($crawler);
         }
         // unknown
         if (!$isBadCrawler && !$isGoodCrawler) {
             $this->_catch($ip, $userAgent, self::CRAWLER_BAD);
         }
     }
 }
 public function run()
 {
     if (empty(self::$_routes)) {
         throw new \Exception('No routes defined');
     }
     //get http request URI (delete hostname)
     if (!$this->_urlParameterKey) {
         $request = str_replace(self::getHost(), '', Http::getServer('HTTP_HOST') . Http::getServer('REQUEST_URI'));
     } else {
         //Or get url key parameter
         $request = Http::getQuery($this->urlParameterKey, '');
     }
     Logger::getInstance()->debug('Run router for request : "' . $request . '"', 'router');
     $routeMatch = false;
     $routeIndex = self::getRoute('index');
     if ($request === '' && $routeIndex) {
         $routeMatch = true;
         $this->runRoute('index');
     } else {
         // each routes
         foreach (self::$_routes as $route) {
             $vars = array();
             // Check if have rules
             if (!$route->getRules()) {
                 continue;
             }
             // each route rules
             $rules = $route->getRules();
             foreach ($rules as &$rule) {
                 Logger::getInstance()->debug('Try rule: "' . $rule . '"', 'router');
                 if ($route->getRegex()) {
                     $routeMatch = (bool) preg_match('`^' . $rule . '$`iu', $request, $vars);
                 } else {
                     $routeMatch = $request == $rule;
                 }
                 if ($routeMatch) {
                     $this->_setCurrentRule($rule);
                     Logger::getInstance()->debug('Match route : "' . $route->getName() . '" with rule : "' . $rule . '"', 'router');
                     break;
                 }
             }
             // If don't match, pass to next route
             if (!$routeMatch) {
                 continue;
             }
             // run route, and break
             if ($routeMatch) {
                 $this->runRoute($route->getName(), $vars);
                 break;
             }
         }
     }
     if (!$routeMatch) {
         Logger::getInstance()->debug('No route find', 'router');
         $this->show404();
     }
 }
 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);
 }