public static function logHit($link, $ref)
 {
     // create or update log
     $existing = FourOhFourLog::get()->filter(array('Referrer' => $ref, 'Link' => $link))->first();
     if ($existing) {
         $existing->Count = $existing->Count + 1;
         $existing->write();
     } else {
         $log = new FourOhFourLog();
         $log->Referrer = $ref;
         $log->Link = $link;
         $log->Count = 1;
         $log->write();
     }
 }
 /**
  * @throws SS_HTTPResponse_Exception
  */
 public function onBeforeHTTPError404($request)
 {
     $getVars = $request->getVars();
     if (!array_key_exists('url', $getVars)) {
         return;
     }
     // no use logging...
     $link = $getVars['url'];
     // get referrer
     if (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) {
         $ref = $_SERVER['HTTP_REFERER'];
         $ref = htmlentities(trim($ref), ENT_QUOTES, 'UTF-8');
         // only log external referrers, internal links will be reported in another report
         $parts = parse_url($ref);
         if (isset($parts['host']) && mb_strpos($parts['host'], $_SERVER['HTTP_HOST']) !== false) {
             return;
         }
     } else {
         $ref = 'unknown';
     }
     // log or count 404
     FourOhFourLog::logHit($link, $ref);
 }
 public function sourceRecords($params, $sort, $limit)
 {
     return FourOhFourLog::get();
 }