3 * StatusNet, the distributed open-source microblogging tool
5 * XHTML Mobile Profile plugin that uses WAP 2.0 Plugin
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Sarven Capadisli <csarven@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 define('PAGE_TYPE_PREFS',
35 'application/vnd.wap.xhtml+xml, application/xhtml+xml, text/html;q=0.9');
37 require_once INSTALLDIR.'/plugins/Mobile/WAP20Plugin.php';
41 * Superclass for plugin to output XHTML Mobile Profile
45 * @author Sarven Capadisli <csarven@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://status.net/
50 class MobileProfilePlugin extends WAP20Plugin
53 public $serveMobile = false;
55 function __construct($DTD='http://www.wapforum.org/DTD/xhtml-mobile10.dtd')
59 parent::__construct();
63 function onStartShowHTML($action)
66 $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ?
67 $_SERVER['HTTP_ACCEPT'] : null;
69 $cp = common_accept_to_prefs($httpaccept);
70 $sp = common_accept_to_prefs(PAGE_TYPE_PREFS);
72 $type = common_negotiate_type($cp, $sp);
75 throw new ClientException(_('This page is not available in a '.
76 'media type you accept'), 406);
80 // XXX: This should probably graduate to WAP20Plugin
82 // If they are on the mobile site, serve them MP
83 if ((common_config('site', 'mobileserver').'/'.
84 common_config('site', 'path').'/' ==
85 $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) {
87 $this->serveMobile = true;
90 // If they like the WAP 2.0 mimetype, serve them MP
91 if (strstr('application/vnd.wap.xhtml+xml', $type) !== false) {
92 $this->serveMobile = true;
95 // If they are a mobile device that supports WAP 2.0,
98 // XXX: Browser sniffing sucks
100 // I really don't like going through this every page,
103 // May be better to categorize the devices in terms of
106 // Or, detect the mobile devices based on their support for
107 // MP 1.0, 1.1, or 1.2 may be ideal. Possible?
109 $this->mobiledevices =
110 array('alcatel', 'android', 'audiovox', 'au-mic,',
111 'avantgo', 'blackberry', 'blazer', 'cldc-', 'danger',
112 'epoc', 'ericsson', 'ericy', 'ipone', 'ipaq', 'j2me',
113 'lg', 'midp-', 'mobile', 'mot', 'netfront', 'nitro',
114 'nokia', 'opera mini', 'palm', 'palmsource',
115 'panasonic', 'philips', 'pocketpc', 'portalmmm',
116 'rover', 'samsung', 'sanyo', 'series60', 'sharp',
117 'sie-', 'smartphone', 'sony', 'symbian',
118 'up.browser', 'up.link', 'up.link', 'vodafone',
119 'wap1', 'wap2', 'windows ce');
121 $httpuseragent = strtolower($_SERVER['HTTP_USER_AGENT']);
123 foreach($this->mobiledevices as $md) {
124 if (strstr($httpuseragent, $md) !== false) {
125 $this->serveMobile = true;
131 // If they are okay with MP, and the site has a mobile server,
133 if ($this->serveMobile &&
134 common_config('site', 'mobileserver') !== false &&
135 (common_config('site', 'mobileserver') !=
136 common_config('site', 'server'))) {
138 // FIXME: Redirect to equivalent page on mobile site instead
139 header("Location: ".$this->_common_path(''));
144 if (!$this->serveMobile) {
148 header('Content-Type: '.$type);
150 $action->extraHeaders();
152 $action->startXML('html',
153 '-//WAPFORUM//DTD XHTML Mobile 1.0//EN',
156 $language = $action->getLanguage();
158 $action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
159 'xml:lang' => $language));
165 function onStartShowHeadElements($action)
167 if (!$action->serveMobile) {
171 $action->showTitle();
172 $action->showShortcutIcon();
173 $action->showStylesheets();
174 $action->showFeeds();
175 $action->showDescription();
176 $action->extraHead();
180 function onStartShowStatusNetStyles($action)
182 if (!$action->serveMobile) {
186 if (file_exists(theme_file('css/mp-screen.css'))) {
187 $action->cssLink('css/mp-screen.css', null, 'screen');
190 $action->element('link', array('rel' => 'stylesheet',
191 'type' => 'text/css',
192 'href' => common_path('plugins/MobileProfile/mp-screen.css') . '?version=' . STATUSNET_VERSION,
193 'media' => 'screen'));
196 if (file_exists(theme_file('css/mp-handheld.css'))) {
197 $action->cssLink('css/mp-handheld.css', null, 'handheld');
200 $action->element('link', array('rel' => 'stylesheet',
201 'type' => 'text/css',
202 'href' => common_path('plugins/MobileProfile/mp-handheld.css') . '?version=' . STATUSNET_VERSION,
203 'media' => 'handheld'));
210 function onStartShowHeader($action)
212 if (!$this->serveMobile) {
216 $action->elementStart('div', array('id' => 'header'));
217 $this->_showLogo($action);
218 $action->showPrimaryNav();
219 $action->showSiteNotice();
220 if (common_logged_in()) {
221 $action->showNoticeForm();
223 $action->showAnonymousMessage();
225 $action->elementEnd('div');
229 function _showLogo($action)
231 $action->elementStart('address', 'vcard');
232 $action->elementStart('a', array('class' => 'url home bookmark',
233 'href' => common_local_url('public')));
234 if (common_config('site', 'mobilelogo') ||
235 file_exists(theme_file('logo.png')) ||
236 file_exists(theme_file('mobilelogo.gif'))) {
238 $action->element('img', array('class' => 'photo',
239 'src' => (common_config('site', 'mobilelogo')) ? common_config('site', 'mobilelogo') :
240 ((file_exists(theme_file('mobilelogo.gif'))) ? (theme_path('mobilelogo.gif')): theme_path('logo.png')),
241 'alt' => common_config('site', 'name')));
243 $action->element('span', array('class' => 'fn org'), common_config('site', 'name'));
244 $action->elementEnd('a');
245 $action->elementEnd('address');
249 function onStartShowAside($action)
251 if ($this->serveMobile) {
257 function onStartShowScripts($action)
263 function _common_path($relative, $ssl=false)
265 $pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : '';
267 if (($ssl && (common_config('site', 'ssl') === 'sometimes'))
268 || common_config('site', 'ssl') === 'always') {
270 if (is_string(common_config('site', 'sslserver')) &&
271 mb_strlen(common_config('site', 'sslserver')) > 0) {
272 $serverpart = common_config('site', 'sslserver');
274 $serverpart = common_config('site', 'mobileserver');
278 $serverpart = common_config('site', 'mobileserver');
281 return $proto.'://'.$serverpart.'/'.$pathpart.$relative;