Skip to content

Commit

Permalink
Fixed #13740: Support auto-redirection from MantisBT to MantisTouch f…
Browse files Browse the repository at this point in the history
…or 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.
  • Loading branch information
vboctor committed Jan 9, 2012
1 parent 75e9bb6 commit b888cb0
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -3891,3 +3891,19 @@
'anonymous', 'content_expire', 'html_valid_tags', 'custom_headers', 'rss_key_seed', 'plugins_enabled', 'session_', 'form_security_',
'compress_html', '_page$', '_url$',
);

/***************
* MantisTouch *
***************/

/**
* The MantisTouch URL to direct to. The %s will be replaced by the contents of $g_path.
* A blank value will disable redirection. The %s is not required when redirecting to
* MantisTouch instances that point to a single MantisBT instance and hence have a hard-coded URL.
*
* Following are three examples:
* - 'http://mantisbt.mobi?url=%s'
* - 'http://MyOwnMantisTouch.com/'
* - ''
*/
$g_mantistouch_url = '';
20 changes: 20 additions & 0 deletions core.php
Expand Up @@ -107,6 +107,26 @@
*/
unset($mantisRoot, $mantisLibrary, $mantisCore, $path);

require_once( 'mobile_api.php' );

if ( strlen( $GLOBALS['g_mantistouch_url'] ) > 0 && mobile_is_mobile_browser() ) {
$t_url = sprintf( $GLOBALS['g_mantistouch_url'], $GLOBALS['g_path'] );

if ( OFF == $g_use_iis ) {
header( 'Status: 302' );
}

header( 'Content-Type: text/html' );

if ( ON == $g_use_iis ) {
header( "Refresh: 0;$t_url" );
} else {
header( "Location: $t_url" );
}

exit; # additional output can cause problems so let's just stop output here
}

# load UTF8-capable string functions
require_once( 'utf8/utf8.php' );
require_once( UTF8 . '/str_pad.php' );
Expand Down
86 changes: 86 additions & 0 deletions core/mobile_api.php
@@ -0,0 +1,86 @@
<?php
# MantisBT - a php based bugtracking system

# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.

/**
* Mobile API
* @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
* @package CoreAPI
* @subpackage MobileAPI
*/

/**
* Detects if it's mobile browser
* Source: http://www.dannyherran.com/2011/02/detect-mobile-browseruser-agent-with-php-ipad-iphone-blackberry-and-others/
* @return boolean<p>True if Mobile Browser, False on PC Browser</p>
*/
function mobile_is_mobile_browser() {
$_SERVER['ALL_HTTP'] = isset( $_SERVER['ALL_HTTP'] ) ? $_SERVER['ALL_HTTP'] : '';

$t_mobile_browser = false;

$t_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );

if ( preg_match( '/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', $t_agent ) ) {
$t_mobile_browser = true;
}

if ( ( isset( $_SERVER['HTTP_ACCEPT'] ) ) && ( strpos( strtolower( $_SERVER['HTTP_ACCEPT'] ), 'application/vnd.wap.xhtml+xml' ) !== false ) ) {
$t_mobile_browser = true;
}

if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) {
$t_mobile_browser = true;
}

if ( isset( $_SERVER['HTTP_PROFILE'] ) ) {
$t_mobile_browser = true;
}

$t_mobile_ua = substr( $t_agent, 0, 4 );
$t_mobile_agents = array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','xda','xda-'
);

if ( in_array( $t_mobile_ua, $t_mobile_agents ) ) {
$t_mobile_browser = true;
}

if ( strpos( strtolower( $_SERVER['ALL_HTTP'] ), 'operamini' ) !== false ) {
$t_mobile_browser = true;
}

// Pre-final check to reset everything if the user is on Windows
if ( strpos( $t_agent, 'windows' ) !== false ) {
$t_mobile_browser = false;
}

// But WP7 is also Windows, with a slightly different characteristic
if ( strpos( $t_agent, 'windows phone' ) !== false ) {
$t_mobile_browser = true;
}

return $t_mobile_browser;
}
20 changes: 20 additions & 0 deletions docbook/adminguide/en/configuration.sgml
Expand Up @@ -3185,4 +3185,24 @@
</variablelist>
</section>

<section id="admin.config.mantistouch">
<title>MantisTouch</title>
<para>
These options are used to integrate with MantisTouch (http://www.mantisbt.org/mantistouch.php) to provide experience targeted to mobile devices.
</para>

<variablelist>
<varlistentry>
<term>$g_mantistouch_url</term>
<listitem>
<para>
The MantisTouch URL to direct to. The %s will be replaced by the contents of $g_path configuration option.
A blank value will disable redirection. The %s is not required when redirecting to
MantisTouch instances that point to a single MantisBT instance and hence have a hard-coded URL.
Examples include: '' (default), 'http://mantisbt.mobi?url=%s', and 'http://MyOwnMantisTouch.com/'.
</para>
</listitem>
</varlistentry>
</variablelist>
</section>
</chapter>

1 comment on commit b888cb0

@ashumkin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.