Wednesday 05 April 2006 6:28:04 am
Hi all,
I'm working on a little patch for index.php to embed browser (user agent) detection and automagic siteaccess redirection.
The patch is in a very early and dirty stage, but that's what I've achieved so far:
1- download phpSniff libraries ( http://phpsniff.sf.net ) and grab the files you need (phpSniff.class.php and phpSniff.core.php)
2- put the two libraries above somewhere in your installation 3- browse your index.php and find the row (mine is row #368) stating:
$access = changeAccess( $access );
4- Edit the file adding ABOVE the previous line
//load the library and perform the sniff
require_once('phpSniff.class.php');
$client =& new phpSniff('',array('check_cookies'=>'1','default_language'=>'','allow_masquerading'=>''));
//is our client a pocketPC device?
if(preg_match('/windows\ ce/i',$client->property(ua)))
$redir='pda';
/* is english a preferred language? Otherwise defaults to italian. If both italian and english are supported then defaults to italian */
if($client->language_is("it"))
$redir=$redir.'it';
elseif($client->language_is("en"))
$redir=$redir.'en';
else
$redir=$redir.'it';
//switch to the appropriate siteaccess
if ($access[name]=='it')$access[name]=$redir;
In this scenario you have to have a siteaccess structure like the following:
pdait -> pocketpc layout, italian language
pdaen -> pocketpc layout, english language
it -> "full browser" layout, italian language ** DEFAULT en -> "full browser" layout, english language The last line is really ugly, I know. You have to change 'it' with your default siteaccess, this is needed to allow explicit access to any siteaccess. At this point I'm kindly asking for suggestion on how this patch may become better, what I have in mind is to generalize the language/layout part, but I do need to check whether the value of $redir is valid prior to push it into the $access array, I've read the access.php file but didn't find anything. Another thing I've got in the plans is to scan the global site.ini for ISO639-1 access lists (aka 2 letter language name) and subsequently check the UA for each and every language which is available. Please let me know if there are better ways for implementing this into eZ Publish (or if it's already in and I didn't manage to find it!) I love the system, even if I'm relatively new to it.
Regards, DAniele
|