コード例 #1
0
ファイル: CrawlerDetector.php プロジェクト: dinajpuri/tracker
 /**
  * Check if current request is from a bot.
  *
  * @return bool
  */
 public function isRobot()
 {
     return $this->detector->isCrawler();
 }
コード例 #2
0
 /** @test */
 public function http_from_header()
 {
     $headers = (array) json_decode('{"DOCUMENT_ROOT":"\\/home\\/test\\/public_html","GATEWAY_INTERFACE":"CGI\\/1.1","HTTP_ACCEPT":"*\\/*","HTTP_ACCEPT_ENCODING":"gzip, deflate","HTTP_CACHE_CONTROL":"no-cache","HTTP_CONNECTION":"Keep-Alive","HTTP_FROM":"googlebot(at)googlebot.com","HTTP_HOST":"www.test.com","HTTP_PRAGMA":"no-cache","HTTP_USER_AGENT":"Mozilla\\/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/28.0.1500.71 Safari\\/537.36","PATH":"\\/bin:\\/usr\\/bin","QUERY_STRING":"order=closingDate","REDIRECT_STATUS":"200","REMOTE_ADDR":"127.0.0.1","REMOTE_PORT":"3360","REQUEST_METHOD":"GET","REQUEST_URI":"\\/?test=testing","SCRIPT_FILENAME":"\\/home\\/test\\/public_html\\/index.php","SCRIPT_NAME":"\\/index.php","SERVER_ADDR":"127.0.0.1","SERVER_ADMIN":"*****@*****.**","SERVER_NAME":"www.test.com","SERVER_PORT":"80","SERVER_PROTOCOL":"HTTP\\/1.1","SERVER_SIGNATURE":"","SERVER_SOFTWARE":"Apache","UNIQUE_ID":"Vx6MENRxerBUSDEQgFLAAAAAS","PHP_SELF":"\\/index.php","REQUEST_TIME_FLOAT":1461619728.0705,"REQUEST_TIME":1461619728}');
     $cd = new CrawlerDetect($headers);
     $this->assertEquals($cd->isCrawler(), true);
 }
コード例 #3
0
 /**
  * _shouldSendAnalytics determines whether we should be sending Google Analytics data
  * @return bool
  */
 public function shouldSendAnalytics()
 {
     $result = true;
     if (!craft()->config->get("sendAnalyticsData", "instantanalytics")) {
         return false;
     }
     if (!craft()->config->get("sendAnalyticsInDevMode", "instantanalytics") && craft()->config->get('devMode')) {
         return false;
     }
     if (craft()->isConsole()) {
         return false;
     }
     if (craft()->request->isCpRequest()) {
         return false;
     }
     if (craft()->request->isLivePreview()) {
         return false;
     }
     /* -- Check the $_SERVER[] super-global exclusions */
     $exclusions = craft()->config->get("serverExcludes", "instantanalytics");
     if (isset($exclusions) && is_array($exclusions)) {
         foreach ($exclusions as $match => $matchArray) {
             if (isset($_SERVER[$match])) {
                 foreach ($matchArray as $matchItem) {
                     if (preg_match($matchItem, $_SERVER[$match])) {
                         return false;
                     }
                 }
             }
         }
     }
     /* -- Filter out bot/spam requests via UserAgent */
     if (craft()->config->get("filterBotUserAgents", "instantanalytics")) {
         $CrawlerDetect = new CrawlerDetect();
         // Check the user agent of the current 'visitor'
         if ($CrawlerDetect->isCrawler()) {
             return false;
         }
     }
     /* -- Filter by user group */
     $session = craft()->userSession;
     if ($session) {
         $user = $session->getUser();
         $exclusions = craft()->config->get("groupExcludes", "instantanalytics");
         if (craft()->config->get("adminExclude", "instantanalytics") && $session->isAdmin()) {
             return false;
         }
         if ($user && isset($exclusions) && is_array($exclusions)) {
             if ($session->isLoggedIn()) {
                 foreach ($exclusions as $matchItem) {
                     if ($user->isInGroup($matchItem)) {
                         return false;
                     }
                 }
             }
         }
     }
     return $result;
 }
コード例 #4
0
ファイル: CrawlController.php プロジェクト: Kaelcao/colormev2
 public function isCrawler()
 {
     $CrawlerDetect = new CrawlerDetect();
     return $CrawlerDetect->isCrawler();
 }
コード例 #5
0
ファイル: Agent.php プロジェクト: jorisvanw/agent
 /**
  * Check if device is a robot.
  *
  * @param  string  $userAgent
  * @return bool
  */
 public function isRobot($userAgent = null)
 {
     // Get bot rules
     $rules = $this->mergeRules(array(static::$utilities['Bot']), array(static::$utilities['MobileBot']), static::$robots, $this->getConfigRules(['robots']));
     foreach ($rules as $regex) {
         // Check for match
         if ($this->match($regex, $userAgent)) {
             return true;
         }
     }
     // Added CrawlerDetect for a more complete detection.
     $CrawlerDetect = new CrawlerDetect();
     return $CrawlerDetect->isCrawler($userAgent);
 }
コード例 #6
0
ファイル: RedirectManager.php プロジェクト: adrenth/redirect
 /**
  * Update database statistics
  *
  * @param int $redirectId
  */
 private function updateStatistics($redirectId)
 {
     $now = Carbon::now();
     /** @var Redirect $redirect */
     $redirect = Redirect::find($redirectId);
     if ($redirect === null) {
         return;
     }
     $redirect->update(['hits' => DB::raw('hits + 1'), 'last_used_at' => $now]);
     $crawlerDetect = new CrawlerDetect();
     Client::create(['redirect_id' => $redirectId, 'timestamp' => $now, 'day' => $now->day, 'month' => $now->month, 'year' => $now->year, 'crawler' => $crawlerDetect->isCrawler() ? $crawlerDetect->getMatches() : null]);
 }