function _mobile_tools_site_detection in Mobile Tools 5
Same name and namespace in other branches
- 6.3 mobile_tools.module \_mobile_tools_site_detection()
- 6 mobile_tools.module \_mobile_tools_site_detection()
1 call to _mobile_tools_site_detection()
- mobile_tools_is_mobile_site in ./
mobile_tools.module - Detection of the site type . the values comes out the configuration form.
File
- ./
mobile_tools.module, line 744 - Mobile Tools provides a range of functionality assisting in creating a mobile drupal site . this functionality contains:
Code
function _mobile_tools_site_detection() {
global $base_url;
// first check if the url is a m.* or .mobi url!!
$server_domain_elements = explode('.', $_SERVER['SERVER_NAME']);
if (count($server_domain_elements) > 0) {
if ($server_domain_elements[0] == 'm') {
// check for m.* domain
return 'mobile';
}
if ($server_domain_elements[count($server_domain_elements) - 1] == 'mobi') {
// check for *.mobi
return 'mobile';
}
}
// If this doesn't return an answer, we will have to do a comparison of the mobile and desktop url!
$mobile_url = parse_url(variable_get('mobile_tools_mobile_url', mobile_tools_create_mobile_url($base_url)));
$mobile_url['host'] = mobile_tools_prepare_url($mobile_url['host']);
$desktop_url = parse_url(variable_get('mobile_tools_desktop_url', $base_url));
$desktop_url['host'] = mobile_tools_prepare_url($desktop_url['host']);
if (!array_key_exists('path', $desktop_url)) {
$desktop_url['path'] = '';
}
if (!array_key_exists('path', $mobile_url)) {
$mobile_url['path'] = '';
}
$server_name = mobile_tools_prepare_url($_SERVER['SERVER_NAME']);
// Check domain first
if ($mobile_url['host'] == $server_name && $desktop_url['host'] != $server_name) {
return 'mobile';
}
else {
if ($mobile_url['host'] != $server_name && $desktop_url['host'] == $server_name) {
return 'desktop';
}
else {
if ($mobile_url['host'] == $server_name && $desktop_url['host'] == $server_name) {
$significant = strlen($mobile_url['path']) > strlen($desktop_url['path']) ? 'mobile' : 'desktop';
//we check the most significatn url (with the longest path)
if (preg_match('|' . $desktop_url['path'] . '|', request_uri())) {
if (preg_match('|' . $mobile_url['path'] . '|', request_uri())) {
return $significant;
// if both patterns match, return the significant
}
return 'desktop';
}
else {
return 'mobile';
}
}
else {
return 'desktop';
}
}
}
}