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_MOBILEPROFILE',
35 'application/vnd.wap.xhtml+xml, application/xhtml+xml, text/html;q=0.9');
37 require_once INSTALLDIR.'/plugins/Mobile/WAP20Plugin.php';
40 * Superclass for plugin to output XHTML Mobile Profile
44 * @author Sarven Capadisli <csarven@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://status.net/
48 class MobileProfilePlugin extends WAP20Plugin
51 public $serveMobile = false;
52 public $mobileFeatures = array();
54 function __construct($DTD='http://www.wapforum.org/DTD/xhtml-mobile10.dtd')
58 parent::__construct();
61 function onStartShowHTML($action)
63 // XXX: This should probably graduate to WAP20Plugin
65 // If they are on the mobile site, serve them MP
66 if ((common_config('site', 'mobileserver').'/'.
67 common_config('site', 'path').'/' ==
68 $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) {
70 $this->serveMobile = true;
71 } else if (isset($_COOKIE['MobileOverride'])) {
72 // Cookie override is controlled by link at bottom.
73 $this->serveMobile = (bool)$_COOKIE['MobileOverride'];
75 // If they like the WAP 2.0 mimetype, serve them MP
76 // @fixme $type is undefined, making this if case useless and spewing errors.
78 //if (strstr('application/vnd.wap.xhtml+xml', $type) !== false) {
79 // $this->serveMobile = true;
81 // If they are a mobile device that supports WAP 2.0,
84 // XXX: Browser sniffing sucks
86 // I really don't like going through this every page,
87 // perhaps use $_SESSION or cookies
89 // May be better to group the devices in terms of
92 // Or, detect the mobile devices based on their support for
93 // MP 1.0, 1.1, or 1.2 may be ideal. Possible?
95 $this->mobiledevices = array(
146 'ipad', // Larger screen handles the full theme fairly well.
149 $httpuseragent = strtolower($_SERVER['HTTP_USER_AGENT']);
151 foreach ($blacklist as $md) {
152 if (strstr($httpuseragent, $md) !== false) {
153 $this->serveMobile = false;
158 foreach ($this->mobiledevices as $md) {
159 if (strstr($httpuseragent, $md) !== false) {
160 $this->setMobileFeatures($httpuseragent);
162 $this->serveMobile = true;
168 // If they are okay with MP, and the site has a mobile server,
170 if ($this->serveMobile &&
171 common_config('site', 'mobileserver') !== false &&
172 (common_config('site', 'mobileserver') !=
173 common_config('site', 'server'))) {
175 // FIXME: Redirect to equivalent page on mobile site instead
176 common_redirect($this->_common_path(''), 302);
180 if (!$this->serveMobile) {
184 // @fixme $type is undefined, making this if case useless and spewing errors.
185 // What's the intent?
187 $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ?
188 $_SERVER['HTTP_ACCEPT'] : null;
190 $cp = common_accept_to_prefs($httpaccept);
191 $sp = common_accept_to_prefs(PAGE_TYPE_PREFS_MOBILEPROFILE);
193 $type = common_negotiate_type($cp, $sp);
196 // TRANS: Client exception thrown when requesting a not supported media type.
197 throw new ClientException(_m('This page is not available in a '.
198 'media type you accept.'), 406);
202 header('Content-Type: '.$type);
204 $action->extraHeaders();
205 if (preg_match("/.*\/.*xml/", $type)) {
206 // Required for XML documents
207 $action->xw->startDocument('1.0', 'UTF-8');
209 $action->xw->writeDTD('html',
210 '-//WAPFORUM//DTD XHTML Mobile 1.0//EN',
213 $language = $action->getLanguage();
215 $action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
216 'xml:lang' => $language));
221 function setMobileFeatures($useragent)
223 $mobiledeviceInputFileType = array(
227 $this->mobileFeatures['inputfiletype'] = false;
229 foreach ($mobiledeviceInputFileType as $md) {
230 if (strstr($useragent, $md) !== false) {
231 $this->mobileFeatures['inputfiletype'] = true;
237 function onStartShowStatusNetStyles($action)
239 if (!$this->serveMobile) {
243 $action->primaryCssLink();
245 if (file_exists(Theme::file('css/mp-screen.css'))) {
246 $action->cssLink('css/mp-screen.css', null, 'screen');
248 $action->cssLink($this->path('mp-screen.css'),null,'screen');
251 if (file_exists(Theme::file('css/mp-handheld.css'))) {
252 $action->cssLink('css/mp-handheld.css', null, 'handheld');
254 $action->cssLink($this->path('mp-handheld.css'),null,'handheld');
257 // Allow other plugins to load their styles.
258 Event::handle('EndShowStatusNetStyles', array($action));
259 Event::handle('EndShowLaconicaStyles', array($action));
264 function onStartShowUAStyles($action) {
265 if (!$this->serveMobile) {
272 function onStartShowHeader($action)
274 if (!$this->serveMobile) {
278 $action->elementStart('div', array('id' => 'header'));
279 $this->_showLogo($action);
280 $this->_showPrimaryNav($action);
281 if (common_logged_in()) {
282 $action->showNoticeForm();
284 $action->elementEnd('div');
289 function _showLogo($action)
291 $action->elementStart('address', 'vcard');
292 $action->elementStart('a', array('class' => 'url home bookmark',
293 'href' => common_local_url('public')));
294 if (common_config('site', 'mobilelogo') ||
295 file_exists(Theme::file('logo.png')) ||
296 file_exists(Theme::file('mobilelogo.png'))) {
298 $action->element('img', array('class' => 'photo',
299 'src' => (common_config('site', 'mobilelogo')) ? common_config('site', 'mobilelogo') :
300 ((file_exists(Theme::file('mobilelogo.png'))) ? (Theme::path('mobilelogo.png')) : Theme::path('logo.png')),
301 'alt' => common_config('site', 'name')));
303 $action->element('span', array('class' => 'fn org'), common_config('site', 'name'));
304 $action->elementEnd('a');
305 $action->elementEnd('address');
308 function _showPrimaryNav($action)
310 $user = common_current_user();
311 $action->elementStart('ul', array('id' => 'site_nav_global_primary'));
313 $action->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
314 // TRANS: Menu item in mobile profile to go to start page of site.
316 $action->menuItem(common_local_url('profilesettings'),
317 // TRANS: Menu item in mobile profile to go to user account settings.
319 $action->menuItem(common_local_url('oauthconnectionssettings'),
320 // TRANS: Menu item in mobile profile to connect to other services.
322 if ($user->hasRight(Right::CONFIGURESITE)) {
323 $action->menuItem(common_local_url('siteadminpanel'),
324 // TRANS: Menu item in mobile profile to manage site settings.
326 _m('Change site configuration'), false, 'nav_admin');
328 if (common_config('invite', 'enabled')) {
329 $action->menuItem(common_local_url('invite'),
330 // TRANS: Menu item in mobile profile to invite other people.
333 $action->menuItem(common_local_url('logout'),
334 // TRANS: Menu item in mobile profile log the current user off.
337 if (!common_config('site', 'closed')) {
338 $action->menuItem(common_local_url('register'),
339 // TRANS: Menu item in mobile profile to register with the site.
342 $action->menuItem(common_local_url('login'),
343 // TRANS: Menu item in mobile profile to log in.
346 if ($user || !common_config('site', 'private')) {
347 $action->menuItem(common_local_url('peoplesearch'),
348 // TRANS: Menu item in mobile profile to search the site.
351 $action->elementEnd('ul');
354 function onStartShowNoticeFormData($form)
356 if (!$this->serveMobile) {
360 $form->out->element('textarea', array('id' => 'notice_data-text',
363 'name' => 'status_textarea'),
364 ($form->content) ? $form->content : '');
366 $contentLimit = Notice::maxContent();
368 if ($contentLimit > 0) {
369 $form->out->element('div', array('class' => 'count'),
373 if (common_config('attachments', 'uploads')) {
374 if ($this->mobileFeatures['inputfiletype']) {
375 $form->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
376 // TRANS: Field label in mobile profile to attach a file to a status.
377 $form->out->element('label', array('for' => 'notice_data-attach'), _m('Attach'));
378 $form->out->element('input', array('id' => 'notice_data-attach',
381 // TRANS: Field title in mobile profile to attach a file to a status.
382 'title' => _m('Attach a file.')));
386 $form->out->hidden('notice_return-to', $form->action, 'returnto');
388 $form->out->hidden('notice_in-reply-to', $form->inreplyto, 'inreplyto');
393 function onStartShowAside($action)
395 if ($this->serveMobile) {
400 function onEndShowScripts($action)
402 $action->inlineScript('
404 $("#mobile-toggle-disable").click(function() {
405 $.cookie("MobileOverride", "0", {path: "/"});
406 window.location.reload();
409 $("#mobile-toggle-enable").click(function() {
410 $.cookie("MobileOverride", "1", {path: "/"});
411 window.location.reload();
419 function onEndShowInsideFooter($action)
421 if ($this->serveMobile) {
422 // TRANS: Link to switch site layout from mobile to desktop mode. Appears at very bottom of page.
423 $linkText = _m('Switch to desktop site layout.');
424 $key = 'mobile-toggle-disable';
426 // TRANS: Link to switch site layout from desktop to mobile mode. Appears at very bottom of page.
427 $linkText = _m('Switch to mobile site layout.');
428 $key = 'mobile-toggle-enable';
430 $action->elementStart('p');
431 $action->element('a', array('href' => '#', 'id' => $key), $linkText);
432 $action->elementEnd('p');
436 function _common_path($relative, $ssl=false)
438 $pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : '';
440 if (($ssl && (common_config('site', 'ssl') === 'sometimes'))
441 || common_config('site', 'ssl') === 'always') {
443 if (is_string(common_config('site', 'sslserver')) &&
444 mb_strlen(common_config('site', 'sslserver')) > 0) {
445 $serverpart = common_config('site', 'sslserver');
447 $serverpart = common_config('site', 'mobileserver');
451 $serverpart = common_config('site', 'mobileserver');
454 return $proto.'://'.$serverpart.'/'.$pathpart.$relative;
457 function onPluginVersion(&$versions)
459 $versions[] = array('name' => 'MobileProfile',
460 'version' => STATUSNET_VERSION,
461 'author' => 'Sarven Capadisli',
462 'homepage' => 'http://status.net/wiki/Plugin:MobileProfile',
464 // TRANS: Plugin description.
465 _m('XHTML MobileProfile output for supporting user agents.'));