An open API service indexing awesome lists of open source software.

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

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' %}


desktop screenshot

{% else %}

mobile screenshot

{% 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.