https://github.com/philecms/phileuseragent
a useragent sniffing plugin for Phile that exposes data to the template
https://github.com/philecms/phileuseragent
philecms-plugin
Last synced: 7 months ago
JSON representation
a useragent sniffing plugin for Phile that exposes data to the template
- Host: GitHub
- URL: https://github.com/philecms/phileuseragent
- Owner: PhileCMS
- License: mit
- Created: 2013-11-13T18:42:55.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-06-19T13:25:41.000Z (about 12 years ago)
- Last Synced: 2024-12-28T02:48:48.056Z (over 1 year ago)
- Topics: philecms-plugin
- Language: PHP
- Size: 240 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
phileUserAgent
==============
A plugin for [Phile](https://github.com/PhileCMS/Phile) to expose browser user-agent data to the template.
### 1.1 Installation (composer)
```
php composer.phar require phile/user-agent:*
```
### 1.2 Installation (Download)
* Install the latest version of [Phile](https://github.com/PhileCMS/Phile)
* Clone this repo into `plugins/phile/userAgent`
### 2. Activation
After you have installed the plugin. You need to add the following line to your `config.php` file:
```
$config['plugins']['phile\\userAgent'] = array('active' => true);
```
### Usage
This plugin will create a new variable in your template called `{{ useragent }}`.
You can use this varaible to load conditional content, add special classes, or even modify your javascript.
#### Exposed Infomation
Here is an example (from my laptop) of the full useragent array:
```php
array(
'useragent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.6 Safari/537.36', // full useragent string
'name' => 'Google Chrome', // name of the browser
'browser' => 'google-chrome', // css safe browser name
'version' => '32.0.1700.6', // browser version number
'type' => 'desktop', // form factor browser || mobile
'platform' => 'mac', // Operating System
'pattern' => '#(?Version|Chrome|other)[/ ]+(?[0-9.|a-zA-Z.]*)#' // regex pattern that matched
);
```
#### Conditional Content
```html
{% if useragent.type == 'desktop' %}
{% else %}
{% endif %}
```
#### Special Classes
```html
{{ content }}
```
#### Javascript Additions
If we put this code in the *head of our document*, we can encode the `{{ useragent }}` array as json and use it in our javascript:
```javascript
window.Phile.useragent = {{ useragent|json_encode() }};
```
Now `Phile.useragent.browser` would return the CSS safe browser name in our javascript.