Ejemplo n.º 1
0
 function log_hit($hit)
 {
     if ($hit['status_code'] == 404) {
         if ($this->get_setting('restrict_logging', true)) {
             if (!($this->get_setting('log_spiders', true) && suweb::is_search_engine_ua($hit['user_agent'])) && !($this->get_setting('log_errors_with_referers', true) && strlen($hit['referer']))) {
                 return $hit;
             }
         }
         $exceptions = suarr::explode_lines($this->get_setting('exceptions', ''));
         foreach ($exceptions as $exception) {
             if (preg_match(sustr::wildcards_to_regex($exception), $hit['url'])) {
                 return $hit;
             }
         }
         $l = $this->get_setting('log', array());
         $max_log_size = absint(sustr::preg_filter('0-9', strval($this->get_setting('max_log_size', 100))));
         while (count($l) > $max_log_size) {
             array_pop($l);
         }
         $u = $hit['url'];
         if (!isset($l[$u])) {
             $l[$u] = array();
             $l[$u]['hit_count'] = 0;
             $l[$u]['is_new'] = isset($hit['is_new']) ? $hit['is_new'] : true;
             $l[$u]['referers'] = array();
             $l[$u]['user_agents'] = array();
             $l[$u]['last_hit_time'] = 0;
         }
         $l[$u]['hit_count']++;
         if (!$l[$u]['is_new'] && $hit['is_new']) {
             $l[$u]['is_new'] = true;
         }
         if ($hit['time'] > $l[$u]['last_hit_time']) {
             $l[$u]['last_hit_time'] = $hit['time'];
         }
         if (strlen($hit['referer']) && !in_array($hit['referer'], $l[$u]['referers'])) {
             $l[$u]['referers'][] = $hit['referer'];
         }
         if (strlen($hit['user_agent']) && !in_array($hit['user_agent'], $l[$u]['user_agents'])) {
             $l[$u]['user_agents'][] = $hit['user_agent'];
         }
         $this->update_setting('log', $l);
     }
     return $hit;
 }