Skip to content

Commit

Permalink
Fixed
Browse files Browse the repository at this point in the history
- The new version of Googlebot (smartphone) emulates Chrome 41, which shouldn't really be flagged as an unsupported browser given it's actually a bot. So there are now user agent exceptions (specifically tailored to Google for now) that will allow trusted bots to access the site regardless of version number or browser name. In a future update this will be manageable via the plugins settings.
  • Loading branch information
Mark Notton committed Mar 20, 2019
1 parent a44dd7b commit 3551715
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.1.5 - 2019-03-20
### Fixed
- The new version of Googlebot (smartphone) emulates Chrome 41, which shouldn't really be flagged as an unsupported browser given it's actually a bot. So there are now user agent exceptions (specifically tailored to Google for now) that will allow trusted bots to access the site regardless of version number or browser name. In a future update this will be manageable via the plugins settings.

## 1.1.4 - 2018-10-18
### Added
- ES5 Babelified agent.es5.js distribution file.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "marknotton/agent",
"description": "Query the server-side information from the users agent data.",
"type": "craft-plugin",
"version": "1.1.4",
"version": "1.1.5",
"keywords": [
"craft",
"cms",
Expand Down Expand Up @@ -33,7 +33,7 @@
"extra": {
"name": "Agent",
"handle": "agent",
"schemaVersion": "1.1.4",
"schemaVersion": "1.1.5",
"hasCpSettings": false,
"hasCpSection": false,
"changelogUrl": "https://github.com/marknotton/craft-plugin-agent/blob/master/CHANGELOG.md",
Expand Down
2 changes: 1 addition & 1 deletion src/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Agent extends Plugin {

public static $plugin;

public $schemaVersion = '1.1.2';
public $schemaVersion = '1.1.5';

public function init() {

Expand Down
12 changes: 12 additions & 0 deletions src/services/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class Services extends Component {
public $name; // Global variable for easy access: {{ browser.name }}
public $version; // Global variable for easy access: {{ browser.version }}

// If a user agent partially matches any of these strings, the 'check' method
// will pass regardless of any other user defined rules.
private $agentExceptions = ['APIs-Google', 'Mediapartners-Google', 'AdsBot-Google-Mobile', 'AdsBot-Google-Mobile',
'AdsBot-Google', 'Googlebot-Image', 'Googlebot', 'Googlebot-News', 'Googlebot', 'Googlebot-Video',
'Mediapartners-Google', 'AdsBot-Google-Mobile-Apps', 'FeedFetcher-Google'];

/**
* Get the full name of the browser or version number
* @return object
Expand Down Expand Up @@ -64,6 +70,12 @@ public function check() {
return false;
}

$regex = '/('.implode("|",$this->agentExceptions).')/i';

if (preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) {
return true;
}

$valid = false;

$arguments = func_get_args();
Expand Down

0 comments on commit 3551715

Please sign in to comment.