Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b888cb0

Browse files
committedJan 9, 2012
Fixed #13740: Support auto-redirection from MantisBT to MantisTouch for mobile browsers
1. Auto-detect mobile browser. 2. Redirect to a configured instance of MantisTouch, passing in the URL of the MantisBT instance to connect to. This functionality will be controlled via a configuration option that enabled / disables such behavior as well as specify the MantisTouch instance to be used. This can be http://mantisbt.mobi or a private instance of MantisTouch.
1 parent 75e9bb6 commit b888cb0

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-0
lines changed
 

‎config_defaults_inc.php

+16
Original file line numberDiff line numberDiff line change
@@ -3891,3 +3891,19 @@
38913891
'anonymous', 'content_expire', 'html_valid_tags', 'custom_headers', 'rss_key_seed', 'plugins_enabled', 'session_', 'form_security_',
38923892
'compress_html', '_page$', '_url$',
38933893
);
3894+
3895+
/***************
3896+
* MantisTouch *
3897+
***************/
3898+
3899+
/**
3900+
* The MantisTouch URL to direct to. The %s will be replaced by the contents of $g_path.
3901+
* A blank value will disable redirection. The %s is not required when redirecting to
3902+
* MantisTouch instances that point to a single MantisBT instance and hence have a hard-coded URL.
3903+
*
3904+
* Following are three examples:
3905+
* - 'http://mantisbt.mobi?url=%s'
3906+
* - 'http://MyOwnMantisTouch.com/'
3907+
* - ''
3908+
*/
3909+
$g_mantistouch_url = '';

‎core.php

+20
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@
107107
*/
108108
unset($mantisRoot, $mantisLibrary, $mantisCore, $path);
109109

110+
require_once( 'mobile_api.php' );
111+
112+
if ( strlen( $GLOBALS['g_mantistouch_url'] ) > 0 && mobile_is_mobile_browser() ) {
113+
$t_url = sprintf( $GLOBALS['g_mantistouch_url'], $GLOBALS['g_path'] );
114+
115+
if ( OFF == $g_use_iis ) {
116+
header( 'Status: 302' );
117+
}
118+
119+
header( 'Content-Type: text/html' );
120+
121+
if ( ON == $g_use_iis ) {
122+
header( "Refresh: 0;$t_url" );
123+
} else {
124+
header( "Location: $t_url" );
125+
}
126+
127+
exit; # additional output can cause problems so let's just stop output here
128+
}
129+
110130
# load UTF8-capable string functions
111131
require_once( 'utf8/utf8.php' );
112132
require_once( UTF8 . '/str_pad.php' );

‎core/mobile_api.php

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
}

‎docbook/adminguide/en/configuration.sgml

+20
Original file line numberDiff line numberDiff line change
@@ -3185,4 +3185,24 @@
31853185
</variablelist>
31863186
</section>
31873187

3188+
<section id="admin.config.mantistouch">
3189+
<title>MantisTouch</title>
3190+
<para>
3191+
These options are used to integrate with MantisTouch (http://www.mantisbt.org/mantistouch.php) to provide experience targeted to mobile devices.
3192+
</para>
3193+
3194+
<variablelist>
3195+
<varlistentry>
3196+
<term>$g_mantistouch_url</term>
3197+
<listitem>
3198+
<para>
3199+
The MantisTouch URL to direct to. The %s will be replaced by the contents of $g_path configuration option.
3200+
A blank value will disable redirection. The %s is not required when redirecting to
3201+
MantisTouch instances that point to a single MantisBT instance and hence have a hard-coded URL.
3202+
Examples include: '' (default), 'http://mantisbt.mobi?url=%s', and 'http://MyOwnMantisTouch.com/'.
3203+
</para>
3204+
</listitem>
3205+
</varlistentry>
3206+
</variablelist>
3207+
</section>
31883208
</chapter>

1 commit comments

Comments
 (1)

ashumkin commented on Mar 1, 2012

@ashumkin

"up.browser|up.link" is not strictly correct for preg_match
"up.browser|up.link" is better

Please sign in to comment.