|
| 1 | +<?php |
| 2 | +# MantisBT - a php based bugtracking system |
| 3 | + |
| 4 | +# MantisBT is free software: you can redistribute it and/or modify |
| 5 | +# it under the terms of the GNU General Public License as published by |
| 6 | +# the Free Software Foundation, either version 2 of the License, or |
| 7 | +# (at your option) any later version. |
| 8 | +# |
| 9 | +# MantisBT is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +# GNU General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License |
| 15 | +# along with MantisBT. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +/** |
| 18 | + * Mobile API |
| 19 | + * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org |
| 20 | + * @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.net |
| 21 | + * @link http://www.mantisbt.org |
| 22 | + * @package CoreAPI |
| 23 | + * @subpackage MobileAPI |
| 24 | + */ |
| 25 | + |
| 26 | +/** |
| 27 | + * Detects if it's mobile browser |
| 28 | + * Source: http://www.dannyherran.com/2011/02/detect-mobile-browseruser-agent-with-php-ipad-iphone-blackberry-and-others/ |
| 29 | + * @return boolean<p>True if Mobile Browser, False on PC Browser</p> |
| 30 | + */ |
| 31 | +function mobile_is_mobile_browser() { |
| 32 | + $_SERVER['ALL_HTTP'] = isset( $_SERVER['ALL_HTTP'] ) ? $_SERVER['ALL_HTTP'] : ''; |
| 33 | + |
| 34 | + $t_mobile_browser = false; |
| 35 | + |
| 36 | + $t_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); |
| 37 | + |
| 38 | + if ( preg_match( '/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', $t_agent ) ) { |
| 39 | + $t_mobile_browser = true; |
| 40 | + } |
| 41 | + |
| 42 | + if ( ( isset( $_SERVER['HTTP_ACCEPT'] ) ) && ( strpos( strtolower( $_SERVER['HTTP_ACCEPT'] ), 'application/vnd.wap.xhtml+xml' ) !== false ) ) { |
| 43 | + $t_mobile_browser = true; |
| 44 | + } |
| 45 | + |
| 46 | + if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) { |
| 47 | + $t_mobile_browser = true; |
| 48 | + } |
| 49 | + |
| 50 | + if ( isset( $_SERVER['HTTP_PROFILE'] ) ) { |
| 51 | + $t_mobile_browser = true; |
| 52 | + } |
| 53 | + |
| 54 | + $t_mobile_ua = substr( $t_agent, 0, 4 ); |
| 55 | + $t_mobile_agents = array( |
| 56 | + 'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac', |
| 57 | + 'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno', |
| 58 | + 'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-', |
| 59 | + 'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-', |
| 60 | + 'newt','noki','oper','palm','pana','pant','phil','play','port','prox', |
| 61 | + 'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar', |
| 62 | + 'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-', |
| 63 | + 'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp', |
| 64 | + 'wapr','webc','winw','xda','xda-' |
| 65 | + ); |
| 66 | + |
| 67 | + if ( in_array( $t_mobile_ua, $t_mobile_agents ) ) { |
| 68 | + $t_mobile_browser = true; |
| 69 | + } |
| 70 | + |
| 71 | + if ( strpos( strtolower( $_SERVER['ALL_HTTP'] ), 'operamini' ) !== false ) { |
| 72 | + $t_mobile_browser = true; |
| 73 | + } |
| 74 | + |
| 75 | + // Pre-final check to reset everything if the user is on Windows |
| 76 | + if ( strpos( $t_agent, 'windows' ) !== false ) { |
| 77 | + $t_mobile_browser = false; |
| 78 | + } |
| 79 | + |
| 80 | + // But WP7 is also Windows, with a slightly different characteristic |
| 81 | + if ( strpos( $t_agent, 'windows phone' ) !== false ) { |
| 82 | + $t_mobile_browser = true; |
| 83 | + } |
| 84 | + |
| 85 | + return $t_mobile_browser; |
| 86 | +} |
0 commit comments