NAVIGATION
This shows you the differences between two versions of the page.
|
english:other-enhancements:tools:user-agent [2012/02/24 00:20] Knut Heermann (flip-flop) created |
english:other-enhancements:tools:user-agent [2018/06/03 18:09] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== User-Agent ====== | ====== User-Agent ====== | ||
| + | FIXME Better translate | ||
| - | Seit der Release r429 können im Template mit IF Statements entsprechend der Ausgabe des User-Agenten Unterscheidungen getroffen werden. | + | Since the release of R429 in the template can be made distinctions with IF statements, due to the values of the user agent. |
| - | Hier stelle ich eine kleines Testscript vor mit dem es möglich ist, die Werte des User-Agenten und die daraus resultierenden Ergebnisse aus den verschiedenen ##%%<!--if:XXXX-->Do that<!--/if-->%%## Abfragen darzustellen. | + | 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. |
| - | Hierzu wird die unten gezeigte php-Datei im Verzeichnis /frontend_render/.. installiert. | + | Please install the php file in the directory /frontend_render/.. |
| - | Die Ansteuerung übernimmt der TAG **{IF-UAG}** oder **{IF-UAG:X:Y}** wobei X den Abstand vom linken -und Y den Abstand vom oberen Browserrand für die Ausgabe angeben. \\ | + | 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//. |
| - | Z.B.: | + | |
| - | * **{IF-UAG}** //(X/Y -Positionswerte im Script)// . | + | E.g.: |
| - | * **{IF-UAG:200:25}** //(200px in X -und 25px in Y-Richtung)//. | + | * **{IF-UAG}** //(X/Y -Values for the position in the script)// . |
| + | * **{IF-UAG:200:25}** //(200px in X -and 25px in Y-direction)//. | ||
| \\ | \\ | ||
| - | Der TAG sollte möglichst am Anfang oder am Ende außerhalb des äußeren div-Containers platziert werden. | + | 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. | ||
| - | Die php-Datei kann im Bereich der IF-Abfragen nach eigenen Vorstellungen angepasst werden. In dieser ersten Übersicht sind alle möglichen IF Abfragen mit einfachen Werten enthalten. Die Negierungen sind nicht eingepflegt. | ||
| \\ | \\ | ||
| - | ===== Voraussetzung: ===== | + | ===== Condition: ===== |
| Line 31: | Line 34: | ||
| \\ | \\ | ||
| - | ===== Anwendung: ===== | + | ===== Application: ===== |
| Line 97: | Line 100: | ||
| \\ | \\ | ||
| - | ===== Ausgabebeispiele: ===== | + | ===== Output Examples: ===== |
| === Desktop: === | === Desktop: === | ||
| Line 105: | Line 108: | ||
| === Tablets: === | === Tablets: === | ||
| + | **Since version 1.5 (r452) there is no "mobile" output when using tablets.** | ||
| + | |||
| {{ :deutsch:andere-erweiterungen:tools:uag_android-tablet_1.gif|}} | {{ :deutsch:andere-erweiterungen:tools:uag_android-tablet_1.gif|}} | ||
| {{:deutsch:andere-erweiterungen:tools:uag_ios-tablet_1.gif|}} | {{:deutsch:andere-erweiterungen:tools:uag_ios-tablet_1.gif|}} | ||
| Line 118: | Line 123: | ||
| ===== PHP Script: ===== | ===== PHP Script: ===== | ||
| - | **Sehr einfache Methode:** \\ | + | **Very simple method:** \\ |
| - | Die Werte des User-Agenten direkt auslesen: | + | The values of the user agent read directly: |
| <code php>dumpVar(phpwcms_getUserAgent());</code> | <code php>dumpVar(phpwcms_getUserAgent());</code> | ||
| \\ | \\ | ||
| - | **Komfortables Script:** | + | **Comfortable Script:** |
| - | **Datei:** template/inc_script/frontend_render/rt_test_if_user_agent.php | + | **File:** template/inc_script/frontend_render/rt_test_if_user_agent.php |
| <code php |h rt_test_if_user_agent.php |h> | <code php |h rt_test_if_user_agent.php |h> | ||
| Line 131: | Line 137: | ||
| /* | /* | ||
| ******************************************************************* | ******************************************************************* | ||
| - | * Test User-Agent with if statement sinc r429 | + | * Test User-Agent with if statement since r429 |
| * 23.02.2012 KH | * 23.02.2012 KH | ||
| * | * | ||
| Line 298: | Line 304: | ||
| \\ | \\ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ====== 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 -> [[http://stackoverflow.com/questions/7768324/detect-ios-version-with-php|Detect iOS version with PHP]] | ||
| + | |||
| + | **File:** template/inc_script/**frontend_init**/rt_iOS_OS_user_agent.php | ||
| + | |||
| + | <code php |h rt_iOS_OS_user_agent.php |h> | ||
| + | <?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; | ||
| + | } | ||
| + | |||
| + | ?> | ||
| + | |||
| + | </code> | ||
| + | \\ | ||
| + | |||
| + | 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 -> [[http://stackoverflow.com/questions/7768324/detect-ios-version-with-php|Detect iOS version with PHP]] | ||
| + | |||
| + | **File:** template/inc_script/**frontend_init**/rt_iOS_OS_user_agent.php | ||
| + | |||
| + | <code php |h rt_iOS_OS_user_agent.php |h> | ||
| + | <?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'; | ||
| + | } | ||
| + | |||
| + | ?> | ||
| + | |||
| + | </code> | ||
| + | \\ | ||
| + | |||
| + | |||
| + | If iOS6 is in use we simply appended _V6. (**iOS** -> **iOS_V6**) to the output. All of the lower iOS versions have no control. | ||
| + | |||
| + | Please check with the iPod and older iOS versions. | ||
| + | |||
| + | \\ | ||
| + | |||