https://github.com/james2doyle/pyro-sniffer-plugin
Sniff information from the user agent for use in the frontend. Useful for adding classes or conditional loading.
https://github.com/james2doyle/pyro-sniffer-plugin
Last synced: 12 months ago
JSON representation
Sniff information from the user agent for use in the frontend. Useful for adding classes or conditional loading.
- Host: GitHub
- URL: https://github.com/james2doyle/pyro-sniffer-plugin
- Owner: james2doyle
- Created: 2013-06-18T22:24:12.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2014-07-04T14:44:23.000Z (almost 12 years ago)
- Last Synced: 2025-01-07T08:48:55.833Z (over 1 year ago)
- Language: PHP
- Size: 184 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
pyro-sniffer-plugin
===================
Sniff information from the user agent for use in the frontend. Useful for adding classes or conditional loading.
This plugin is **not** built on the [CodeIgniter User Agent Library](http://ellislab.com/codeigniter/user-guide/libraries/user_agent.html).
The reason I did not use the built in CodeIgniter lib, was because Pyro is only going to have CodeIgniter for a few more months(right?!?!), and I also want to have the information returned in a different way. This plugin is pretty small and only really gets information that is helpful to be used in CSS and Javascript (CSS custom classes and js feature detection/fallbacks).
If you are looking for a plugin that uses the user agent library, check out [this plugin called Agent](https://www.pyrocms.com/store/details/agent_plugin).
### Usage
```html
```
On my Mac running Google Chrome, this would return:
```html
```
On my iPhone, this would return:
```html
```
#### conditional content
This works in 2.2/develop. Not sure about 2.3 or 2.1.
```html
{{ if { sniffer:get key="type" } == 'desktop' }}
{{ else }}
{{ endif }}
```
here is the full dump of the `$results` object for my machine:
```php
$results = array (
['useragent'] => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.44 Safari/537.36' // full ua string
['name'] => 'Google Chrome' // name of the browser
['browser'] => 'google-chrome' // CSS safe browser name
['version'] => '28.0.1500.44' // bowser version
['type'] => 'desktop' // device form factor
['platform'] => 'mac' // OS platform
['pattern'] => '#(?Version|Chrome|other)[/ ]+(?[0-9.|a-zA-Z.]*)#' // match pattern
);
```