User-Agent

FIXME Better translate

Since the release of R429 in the template can be made distinctions with IF statements, due to the values ​​of the user agent.

A small test script which reads out the values ​​of the user agent. The results thereof are illustrated in the various <!--if:XXXX-->Do that<!--/if--> queries.

Please install the php file in the directory /frontend_render/..

The control takes the TAG {IF-UAG} or {IF-UAG:X:Y}. Where X is the distance from the left -and Y specify the distance from the upper edge of the browser for the output.

E.g.:

  • {IF-UAG} (X/Y -Values ​​for the position in the script) .
  • {IF-UAG:200:25} (200px in X -and 25px in Y-direction).


The TAG should be placed near the beginning or end outside of the outer div container.

In the php-file, you can edit the IF statements to your own ideas. In this first overview all possible IF statements are included with simple values​​. The negative statements are not entered.


Condition:

conf.inc.php:

$phpwcms['render_device']     = 1; // allow user agent specific rendering templates <!--if:mobile-->DoMobile<!--/if--><!--!if:mobile-->DoNotMobile<!--/!if--><!--!if:default-->Default<!--/!if-->


Application:

<!--if:XXXX-->....<!--/if--> oder die Nagation: <!--!if:XXXX-->....<!--/!if-->

mobile

<!--if:mobile-->  - All Mobile<br> <!--/if-->

desktop

<!--if:desktop--> - All Desktop<br><!--/if-->

platform: WinPhone, WinCE, Win, iOS, Mac, GoogleTV, Android, BlackBerry, WebOS, Linux, Unix, Symbian, Other

<!--if:platform:win-->    - Platform Win PC<br>         <!--/if-->
<!--if:platform:mac-->    - Platform Mac PC<br>         <!--/if-->
<!--if:platform:win,mac-->- Platform Win und Mac PC<br> <!--/if-->

device: Default, Other, Smartphone, Tablet, Desktop, TV

<!--if:device:Default-->    - Device Default<br>    <!--/if-->
<!--if:device:Smartphonet-->- Device Smartphone<br> <!--/if-->
<!--if:device:Tablet-->     - Device Tablet<br>     <!--/if-->
<!--if:device:Desktop-->    - Device Desktop<br>    <!--/if-->
<!--if:device:TV-->         - Device TV<br>         <!--/if-->

browser: Other, Firefox, Chrome, Safari, IE, IEMobile, Opera, Mozilla

<!--if:browser:Other-->    - Browser Other<br>   <!--/if-->
<!--if:browser:Firefox-->  - Browser Firefox<br> <!--/if-->
<!--if:browser:Chrome-->   - Browser Chrome<br>  <!--/if-->
<!--if:browser: Safari-->  - Browser Safari<br>  <!--/if-->
<!--if:browser: IE-->      - Browser IE<br>      <!--/if-->
<!--if:browser: IEMobile-->- Browser IEMobile<br><!--/if-->
<!--if:browser: Opera-->   - Browser Opera<br>   <!--/if-->
<!--if:browser: Mozilla--> - Browser Safari<br>  <!--/if-->

engine: Gecko, Other, WebKit, Opera, KHTML, IE

<!--if:engine:Gecko-->  - Engine Gecko<br> <!--/if-->
<!--if:engine:Other-->  - Engine Other<br> <!--/if-->
<!--if:engine:WebKit--> - Engine WebKit<br><!--/if-->
<!--if:engine:Opera-->  - Engine Opera<br> <!--/if-->
<!--if:engine:KHTML-->  - Engine KHTML<br> <!--/if-->
<!--if:engine:IE-->     - Engine IE<br>    <!--/if-->

version

<!--if:version:531-->  - Version No 531<br><!--/if-->

default

<!--!if:default-->     - Not Default<br><!--/!if-->


Output Examples:

Desktop:

Tablets:

Since version 1.5 (r452) there is no “mobile” output when using tablets.

Smartphones:


PHP Script:

Very simple method:
The values ​​of the user agent read directly:

dumpVar(phpwcms_getUserAgent());


Comfortable Script:

File: template/inc_script/frontend_render/rt_test_if_user_agent.php

rt_test_if_user_agent.php

<?php
/*
*******************************************************************
* Test User-Agent with if statement since r429
* 23.02.2012 KH
*
* TAG: {IF-UAG} or {IF-UAG:X:Y} with absolute X/Y output position
*
********************************************************************/
 
// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day."); }
// ----------------------------------------------------------------
 
if (strpos($content['all'], '{IF-UAG') !== false) {
 
    $_if = '<b>IF-Statement</b><br>'.LF;
 
 
    // *************************************************************************
    // Geasmmelte IF Abfragen: Editierbarer Bereich
    // *************************************************************************
    // *************************************************************************
 
    // mobile
    $_if .= '
        <!--if:mobile-->  - All Mobile<br> <!--/if-->
    ';
 
    // desktop
    $_if .= '
        <!--if:desktop--> - All Desktop<br><!--/if-->
    ';
 
    // platform: WinPhone, WinCE, Win, iOS, Mac, GoogleTV, Android, BlackBerry, WebOS, Linux, Unix, Symbian, Other
    $_if .= '
        <!--if:platform:win-->    - Platform Win PC<br>         <!--/if-->
        <!--if:platform:mac-->    - Platform Mac PC<br>         <!--/if-->
        <!--if:platform:win,mac-->- Platform Win und Mac PC<br> <!--/if-->
    ';
 
    // device: Default, Other, Smartphone, Tablet, Desktop, TV
    $_if .= '
        <!--if:device:Default-->    - Device Default<br>    <!--/if-->
        <!--if:device:Smartphonet-->- Device Smartphone<br> <!--/if-->
        <!--if:device:Tablet-->     - Device Tablet<br>     <!--/if-->
        <!--if:device:Desktop-->    - Device Desktop<br>    <!--/if-->
        <!--if:device:TV-->         - Device TV<br>         <!--/if-->
    ';
 
    // browser: Other, Firefox, Chrome, Safari, IE, IEMobile, Opera, Mozilla
    $_if .= '
        <!--if:browser:Other-->    - Browser Other<br>   <!--/if-->
        <!--if:browser:Firefox-->  - Browser Firefox<br> <!--/if-->
        <!--if:browser:Chrome-->   - Browser Chrome<br>  <!--/if-->
        <!--if:browser: Safari-->  - Browser Safari<br>  <!--/if-->
        <!--if:browser: IE-->      - Browser IE<br>      <!--/if-->
        <!--if:browser: IEMobile-->- Browser IEMobile<br><!--/if-->
        <!--if:browser: Opera-->   - Browser Opera<br>   <!--/if-->
        <!--if:browser: Mozilla--> - Browser Safari<br>  <!--/if-->
    ';
 
    // engine: Gecko, Other, WebKit, Opera, KHTML, IE
    $_if .= '
        <!--if:engine:Gecko-->  - Engine Gecko<br> <!--/if-->
        <!--if:engine:Other-->  - Engine Other<br> <!--/if-->
        <!--if:engine:WebKit--> - Engine WebKit<br><!--/if-->
        <!--if:engine:Opera-->  - Engine Opera<br> <!--/if-->
        <!--if:engine:KHTML-->  - Engine KHTML<br> <!--/if-->
        <!--if:engine:IE-->     - Engine IE<br>    <!--/if-->
    ';
 
    // version
    $_if .= '
        <!--if:version:531-->  - Version No 531<br><!--/if-->
    ';
 
    // default
    $_if .= '
        <!--!if:default-->     - Not Default<br><!--/!if-->
    ';
 
    // *************************************************************************
    // *************************************************************************
 
 
 
    // -----------------------------------------------------
    // Fenster-Ausgabeposition festlegen: {IF-UAG:X:Y}
    // -----------------------------------------------------
 
    $_left    = '200px';  // X px
    $_top     = '10px';   // Y px
 
 
    preg_match('/\{IF-UAG:(.*?):(.*?)\}/', $content['all'], $_matches);
 
 
    if (isset($_matches[1])) $_left = $_matches[1].'px';  // x Position
    if (isset($_matches[2])) $_top  = $_matches[2].'px';  // y Position
 
 
 
    // -----------------------------------------------------
    // User Agent abholen
    // -----------------------------------------------------
    //dumpVar(phpwcms_getUserAgent());
 
    $_userAgent = phpwcms_getUserAgent();
 
 
    // -----------------------------------------------------
    // Ausgabeformat festlegen
    // -----------------------------------------------------
    $_pos_all = '<div style="
                    display:        block;
                    position:        absolute;
                    top:            '.$_top.';
                    left:            '.$_left.';
                    overflow:        auto;
                    z-index:        8000;
                    background-color:#c4f2e2;
                    border:         1px solid blue;
                    text-align:     left;">
    ';
 
    $_pos_uAg = '<div style="
                    display:        block;
                    width:             160px;
                    float:             left;
                    background-color:#c4f2c8;
                    text-align:     left;
                    border-right:    1px solid #aaa;
                    padding:        4px;">
    ';
 
    $_pos_if = '<div style="
                    display:        block;
                    width:             200px;
                    float:             left;
                    background-color:#c4f2e2;
                    text-align:     left;
                    padding:        4px;">
    ';
 
 
    // -----------------------------------------------------
    // Output User-Agent
    // -----------------------------------------------------
    $_uAg_Outp = '<b>User-Agent</b><br>'.LF;
 
    foreach ($_userAgent as $_key=>$_value) {
        $_uAg_Outp .= '<div style="float: left; width:65px;">['.$_key.'] </div><div> => '.$_value.'</div>'.LF;
    }
 
    $_uAg_Outp .= '<div style="clear: both;"></div>'.LF;
 
 
    $content['all'] = preg_replace('/\{IF-UAG\}/', $_pos_all.$_pos_uAg.$_uAg_Outp.'</div>'.$_pos_if.$_if.'</div></div>', $content['all'] );
 
    $content['all'] = preg_replace('/\{IF-UAG:.*?:.*?\}/', $_pos_all.$_pos_uAg.$_uAg_Outp.'</div>'.$_pos_if.$_if.'</div></div>', $content['all'] );
 
}
 
?>



Extracting the OS version from iOS

Version 1.0

Use within the CMS e.g.:

<!--if:platform:iOS_V3-->iOS Version3<!--/if-->
<!--if:platform:iOS_V4-->iOS Version4<!--/if-->


Simple script: derived from → Detect iOS version with PHP

File: template/inc_script/frontend_init/rt_iOS_OS_user_agent.php

rt_iOS_OS_user_agent.php

<?php
/*
*******************************************************************
* 08.11.2012 KH: Extract the OS from the User-Agent for iOS devices
*
* This solution can be queried with the built in if statements. -> iOS_V4, iOS_V5, iOS_V6
*
* In CMS e.g.:
* <!--if:platform:iOS_V3-->iOS Version3<!--/if-->
* <!--if:platform:iOS_V4-->iOS Version4<!--/if-->
*
* File: template/inc_script/frontend_init/rt_iOS_OS_user_agent.php
*
********************************************************************/
 
// -------------------------------------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
// -------------------------------------------------------------------------------------------
 
// Example USER-AGENT iOS
// --------------------------------------------------------
// Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5
// Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5
// --------------------------------------------------------
 
if ($GLOBALS['phpwcms']['USER_AGENT']['platform'] == 'iOS') {
 
    $os_vers = preg_replace("/(.*) OS ([0-9]*)_(.*)/","$2", $_SERVER['HTTP_USER_AGENT']);
    $GLOBALS['phpwcms']['USER_AGENT']['platform'] = $GLOBALS['phpwcms']['USER_AGENT']['platform'].'_V'.$os_vers;
}
 
?>


At the output of the platform just the iOS version is appended. With a smartphone or tablet running iOS 5 the output changes from e.g. iOS to iOS_V5.

Please check with the iPod and older iOS versions.


Version 1.1

It is tested against iOS versions greater than 5.

Use within the CMS e.g.:

<!--if:platform:iOS-->iOS Version x - 5<!--/if-->
<!--if:platform:iOS_V6-->iOS Version6<!--/if-->


Simple script: derived from → Detect iOS version with PHP

File: template/inc_script/frontend_init/rt_iOS_OS_user_agent.php

rt_iOS_OS_user_agent.php

<?php
/*
*******************************************************************
* 08.11.2012 KH: Extract the OS from the User-Agent for iOS devices
* V1.1
* This solution can be queried with the built in if statements. -> iOS, iOS_V6
*Enhanced V1.1: Only if iOS V6 is used, the if statement is extended.
*
*
* In CMS e.g.:
* <!--if:platform:iOS-->iOS Version x - 5<!--/if-->
* <!--if:platform:iOS_V6-->iOS Version6<!--/if-->
*
* File: template/inc_script/frontend_init/rt_iOS_OS_user_agent.php
*
********************************************************************/
 
// -------------------------------------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
// -------------------------------------------------------------------------------------------
 
// Example USER-AGENT iOS
// --------------------------------------------------------
// Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5
// Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5
// --------------------------------------------------------
 
if ($GLOBALS['phpwcms']['USER_AGENT']['platform'] == 'iOS') {
 
    $os_vers = preg_replace("/(.*) OS ([0-9]*)_(.*)/","$2", $_SERVER['HTTP_USER_AGENT']);
 
    if (((int) $os_vers) == $os_vers) // Integer ?
        if ($os_vers > 5)
            $GLOBALS['phpwcms']['USER_AGENT']['platform'] .= '_V6';
}
 
?>


If iOS6 is in use we simply appended _V6. (iOSiOS_V6) to the output. All of the lower iOS versions have no control.

Please check with the iPod and older iOS versions.


english/other-enhancements/tools/user-agent.txt · Last modified: 2018/06/03 18:09 (external edit)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0