This is very Cool and Rad!! 8)
I found this page from nokia:
http://wiki.forum.nokia.com/index.php/User-Agent_headers_for_Nokia_devices
about S60 3.0 Web browser.
//So in the snippet:
$browser = strpos($_SERVER['HTTP_USER_AGENT'],"SymbianOS/9.1");
I hope will do it!
A good tip. You should probably modify your code slightly due to the peculiarities of MODx snippets, however. It’s best to use return instead of echo, and to always return something (e.g., a blank string) no matter what. Otherwise you may get the number 1 in your output (the numerical representation of TRUE) when you expect no output, and appending a 1 to your stylesheet name wouldn’t be helpful. Most people start off snippets by setting an $output var to a blank string, append any other values to be outputted in the snippet, and then return $output at the end. Whatever you return will be displayed as if you had echoed it.
Quote from: anablepo at Dec 23, 2008, 10:25 AM
...say you’re looking to make a custom template for the iPhone/iPod Touch, if you’ve got complete structure/data separation you can swap out a .css file optimized for the iPhone easily through use of a snippet...
Great idea. I thought I’d generalize this a little (note: untested).
<?php
/* Snippet Title: CustomCSS */
$output = '';
$cssBase = $modx->config['site_url'] . 'css/'; /* or wherever you keep your css files */
/* array of browser agent names and their respective .css filenames */
$browserArray = array(
'iPhone' => 'iphone.css',
'SymbianOS/9.1' => 'symbian.css',
'anotherbrowser' => 'otherbrowser.css',
'yetanother browser' => 'stillotherbrowser.css'
);
/* see if we recognize one */
foreach ($browserArray as $key => $value) {
if (strpos($_SERVER['HTTP_USER_AGENT'],$key)) {
$output .= $cssBase . $value;
break;
}
}
/* if we didn't find one, use the default css file */
if ($output == '') {
$output = $cssBase . 'default.css';
}
return $output;
?>
<link href="[!CustomCSS!]" rel="stylesheet" type="text/css" />
If you use the "ieroot" method with your default .css file, that will handle all the flavors of IE:
http://www.positioniseverything.net/articles/cc-plus.html
Here’s another method (I didn’t look at very carefully):
http://minimaldesign.net/articles/read/never-hack-your-css-files-again
Of course you may be able to get away with just using a mobile stylesheet (as well as screen and print).
Ive added a " ’ " to this line:
$cssBase = $modx->config[’base_url’] . ’assets/templates/4up2date/’; /* or wherever you keep your css files */
Then I made a iphone.css and tried the value "Mozilla/4.0" and just "Mozilla" but I had default.css returned!!
Any suggestion!? Mozilla is for sure my user agent!
Quote from: mrhaw at Dec 28, 2008, 11:42 PM
Any suggestion!?
Are you calling the snippet uncached on a cached document? Have you refreshed the site cache?
Quote from: ZAP at Dec 28, 2008, 11:16 PM
Here’s another method (I didn’t look at very carefully):
http://minimaldesign.net/articles/read/never-hack-your-css-files-again
Of course you may be able to get away with just using a mobile stylesheet (as well as screen and print).
Ironically, the page doesn’t display properly in IE7 Vista.
Quote from: mrhaw at Dec 28, 2008, 11:42 PM
Ive added a " ’ " to this line:
$cssBase = $modx->config[’base_url’] . ’assets/templates/4up2date/’; /* or wherever you keep your css files */
Thanks. Fixed in post above.
Then I made a iphone.css and tried the value "Mozilla/4.0" and just "Mozilla" but I had default.css returned!!
Any suggestion!? Mozilla is for sure my user agent!
Have you tried:
echo $_SERVER['HTTP_USER_AGENT'];
to see what’e being sent?
BTW, stristr() might be a better choice than strpos().