From d09444309f80fe1f274ec2dda4975a96506fcca9 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 2 Oct 2009 11:46:14 +0000 Subject: [PATCH 1/5] Init for WAP 2.0 and XHTML Mobile Profile support. WAP20Plugin is a superclass for various WAP 2.0 document types. MobileProfilePlugin extends WAP20Plugin and it is intended for serving XHTML Mobile Profile 1.0. Feature support for document types like WML 2.0 or WAP Push should be created as seperate plugins and quite possibly extend WAP20Plugin. --- plugins/Mobile/WAP20Plugin.php | 56 ++++++++ plugins/MobileProfile/MobileProfilePlugin.php | 129 ++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 plugins/Mobile/WAP20Plugin.php create mode 100644 plugins/MobileProfile/MobileProfilePlugin.php diff --git a/plugins/Mobile/WAP20Plugin.php b/plugins/Mobile/WAP20Plugin.php new file mode 100644 index 0000000000..aae48a5200 --- /dev/null +++ b/plugins/Mobile/WAP20Plugin.php @@ -0,0 +1,56 @@ +. + * + * @category Plugin + * @package StatusNet + * @author Sarven Capadisli + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + + +/** + * Superclass for plugin to output XHTML Mobile Profile + * + * @category Plugin + * @package StatusNet + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class WAP20Plugin extends Plugin +{ + + function onStartShowHTML($action) + { + + } + +} + + +?> diff --git a/plugins/MobileProfile/MobileProfilePlugin.php b/plugins/MobileProfile/MobileProfilePlugin.php new file mode 100644 index 0000000000..5ee2d90978 --- /dev/null +++ b/plugins/MobileProfile/MobileProfilePlugin.php @@ -0,0 +1,129 @@ +. + * + * @category Plugin + * @package StatusNet + * @author Sarven Capadisli + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +define('PAGE_TYPE_PREFS', + 'application/vnd.wap.xhtml+xml, application/xhtml+xml, text/xml;q=0.9'. + ', text/html;q=0.3' + ); + +require_once INSTALLDIR.'/plugins/Mobile/WAP20Plugin.php'; + + +/** + * Superclass for plugin to output XHTML Mobile Profile + * + * @category Plugin + * @package StatusNet + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class MobileProfilePlugin extends WAP20Plugin +{ + public $DTDversion = null; + public $serveMobile = false; + + function __construct($DTD='http://www.wapforum.org/DTD/xhtml-mobile10.dtd') + { + $this->DTD = $DTD; + + parent::__construct(); + } + + + function onStartShowHTML($action) + { + if (!$type) { + $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? + $_SERVER['HTTP_ACCEPT'] : null; + + $cp = common_accept_to_prefs($httpaccept); + $sp = common_accept_to_prefs(PAGE_TYPE_PREFS); + + $type = common_negotiate_type($cp, $sp); + + if (!$type) { + throw new ClientException(_('This page is not available in a '. + 'media type you accept'), 406); + } + } + + // XXX: If user is on the mobile site e.g., m.siteserver.com + // or they really want it, serve the mobile version + + // FIXME: This is dirty and probably not accurate of doing it + if ((common_config('site', 'mobileserver').'/'.common_config('site', 'path').'/' == + $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) || + preg_match("/.*\/.*wap.*xml/", $type)) { + + $this->serveMobile = true; + } + else { + $this->serveMobile = false; + return true; + } + + header('Content-Type: '.$type); + + $action->extraHeaders(); + + $action->startXML('html', + '-//WAPFORUM//DTD XHTML Mobile 1.0//EN', + $this->DTD); + + $language = $action->getLanguage(); + + $action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', + 'xml:lang' => $language)); + + return false; + } + + + + function onStartShowAside($action) + { + + } + + + function onStartShowScripts($action) + { + + } + +} + + +?> From 43cd0f87190e55c0973350265fffd2e6c3e5caa2 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 2 Oct 2009 12:46:26 +0000 Subject: [PATCH 2/5] Don't need text/xml until further evidence --- plugins/MobileProfile/MobileProfilePlugin.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/MobileProfile/MobileProfilePlugin.php b/plugins/MobileProfile/MobileProfilePlugin.php index 5ee2d90978..dd67ffcc9d 100644 --- a/plugins/MobileProfile/MobileProfilePlugin.php +++ b/plugins/MobileProfile/MobileProfilePlugin.php @@ -32,9 +32,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { } define('PAGE_TYPE_PREFS', - 'application/vnd.wap.xhtml+xml, application/xhtml+xml, text/xml;q=0.9'. - ', text/html;q=0.3' - ); + 'application/vnd.wap.xhtml+xml, application/xhtml+xml, text/html;q=0.9'); require_once INSTALLDIR.'/plugins/Mobile/WAP20Plugin.php'; From c2046a9ab6539669f8fdfe24798b124246e7807c Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Fri, 2 Oct 2009 15:38:20 +0000 Subject: [PATCH 3/5] Better logic to determine what to do with the visitor. Whether to serve them the Mobile Profile or not, and possibly redirect. --- plugins/MobileProfile/MobileProfilePlugin.php | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/plugins/MobileProfile/MobileProfilePlugin.php b/plugins/MobileProfile/MobileProfilePlugin.php index dd67ffcc9d..cce8f8081c 100644 --- a/plugins/MobileProfile/MobileProfilePlugin.php +++ b/plugins/MobileProfile/MobileProfilePlugin.php @@ -77,19 +77,57 @@ class MobileProfilePlugin extends WAP20Plugin } } - // XXX: If user is on the mobile site e.g., m.siteserver.com - // or they really want it, serve the mobile version + // XXX: This should probably graduate to WAP20Plugin - // FIXME: This is dirty and probably not accurate of doing it - if ((common_config('site', 'mobileserver').'/'.common_config('site', 'path').'/' == - $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) || - preg_match("/.*\/.*wap.*xml/", $type)) { + // If they are on the mobile site, serve them MP + if ((common_config('site', 'mobileserver').'/'. + common_config('site', 'path').'/' == + $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) { $this->serveMobile = true; } else { - $this->serveMobile = false; - return true; + // If they like the WAP 2.0 mimetype, serve them MP + if (strstr('application/vnd.wap.xhtml+xml', $type) !== false) { + $this->serveMobile = true; + } + else { + // If they are a mobile device that supports WAP 2.0, + // serve them MP + + // XXX: Browser sniffing sucks + // I really don't like going through this every page, + // find a better way + $this->mobiledevices = + array('alcatel', 'android', 'audiovox', 'au-mic,', + 'avantgo', 'blackberry', 'blazer', 'cldc-', 'danger', + 'epoc', 'ericsson', 'ericy', 'ipone', 'ipaq', 'j2me', + 'lg', 'midp-', 'mobile', 'mot', 'netfront', 'nitro', + 'nokia', 'opera mini', 'palm', 'palmsource', + 'panasonic', 'philips', 'pocketpc', 'portalmmm', + 'rover', 'samsung', 'sanyo', 'series60', 'sharp', + 'sie-', 'smartphone', 'sony', 'symbian', + 'up.browser', 'up.link', 'up.link', 'vodafone', + 'wap1', 'wap2', 'windows ce'); + + $httpuseragent = strtolower($_SERVER['HTTP_USER_AGENT']); + + foreach($this->mobiledevices as $mb) { + if (strstr($httpuseragent, $mb) !== false) { + $this->serveMobile = true; + break; + } + } + } + + // If they are okay with MP, and the site has a mobile server, + // redirect there + if ($this->serveMobile && + common_config('site', 'mobileserver') !== false) { + + header("Location: ".common_config('site', 'mobileserver')); + exit(); + } } header('Content-Type: '.$type); From 604cfd8b116886cac04a8d062c66f11fb601318f Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 3 Oct 2009 20:17:26 +0000 Subject: [PATCH 4/5] Updated comment about browser sniffing --- plugins/MobileProfile/MobileProfilePlugin.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/MobileProfile/MobileProfilePlugin.php b/plugins/MobileProfile/MobileProfilePlugin.php index cce8f8081c..f594f3c0ee 100644 --- a/plugins/MobileProfile/MobileProfilePlugin.php +++ b/plugins/MobileProfile/MobileProfilePlugin.php @@ -96,8 +96,16 @@ class MobileProfilePlugin extends WAP20Plugin // serve them MP // XXX: Browser sniffing sucks + // I really don't like going through this every page, // find a better way + + // May be better to categorize the devices in terms of + // low,mid,high-end + + // Or, detect the mobile devices based on their support for + // MP 1.0, 1.1, or 1.2 may be ideal. Possible? + $this->mobiledevices = array('alcatel', 'android', 'audiovox', 'au-mic,', 'avantgo', 'blackberry', 'blazer', 'cldc-', 'danger', @@ -112,8 +120,8 @@ class MobileProfilePlugin extends WAP20Plugin $httpuseragent = strtolower($_SERVER['HTTP_USER_AGENT']); - foreach($this->mobiledevices as $mb) { - if (strstr($httpuseragent, $mb) !== false) { + foreach($this->mobiledevices as $md) { + if (strstr($httpuseragent, $md) !== false) { $this->serveMobile = true; break; } From 63700f79588ded641645bc5eaf9265ea837bfff6 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 3 Oct 2009 20:22:40 +0000 Subject: [PATCH 5/5] Minor correction to public variable name --- plugins/MobileProfile/MobileProfilePlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/MobileProfile/MobileProfilePlugin.php b/plugins/MobileProfile/MobileProfilePlugin.php index f594f3c0ee..cd88a6f7b7 100644 --- a/plugins/MobileProfile/MobileProfilePlugin.php +++ b/plugins/MobileProfile/MobileProfilePlugin.php @@ -49,7 +49,7 @@ require_once INSTALLDIR.'/plugins/Mobile/WAP20Plugin.php'; class MobileProfilePlugin extends WAP20Plugin { - public $DTDversion = null; + public $DTD = null; public $serveMobile = false; function __construct($DTD='http://www.wapforum.org/DTD/xhtml-mobile10.dtd')