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;
72 // If they like the WAP 2.0 mimetype, serve them MP
73 // @fixme $type is undefined, making this if case useless and spewing errors.
75 //if (strstr('application/vnd.wap.xhtml+xml', $type) !== false) {
76 // $this->serveMobile = true;
78 // If they are a mobile device that supports WAP 2.0,
81 // XXX: Browser sniffing sucks
83 // I really don't like going through this every page,
84 // perhaps use $_SESSION or cookies
86 // May be better to group the devices in terms of
89 // Or, detect the mobile devices based on their support for
90 // MP 1.0, 1.1, or 1.2 may be ideal. Possible?
92 $this->mobiledevices = array(
143 'ipad', // Larger screen handles the full theme fairly well.
146 $httpuseragent = strtolower($_SERVER['HTTP_USER_AGENT']);
148 foreach ($blacklist as $md) {
149 if (strstr($httpuseragent, $md) !== false) {
150 $this->serveMobile = false;
155 foreach ($this->mobiledevices as $md) {
156 if (strstr($httpuseragent, $md) !== false) {
157 $this->setMobileFeatures($httpuseragent);
159 $this->serveMobile = true;
165 // If they are okay with MP, and the site has a mobile server,
167 if ($this->serveMobile &&
168 common_config('site', 'mobileserver') !== false &&
169 (common_config('site', 'mobileserver') !=
170 common_config('site', 'server'))) {
172 // FIXME: Redirect to equivalent page on mobile site instead
173 common_redirect($this->_common_path(''), 302);
177 if (!$this->serveMobile) {
181 // @fixme $type is undefined, making this if case useless and spewing errors.
182 // What's the intent?
184 $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ?
185 $_SERVER['HTTP_ACCEPT'] : null;
187 $cp = common_accept_to_prefs($httpaccept);
188 $sp = common_accept_to_prefs(PAGE_TYPE_PREFS_MOBILEPROFILE);
190 $type = common_negotiate_type($cp, $sp);
193 throw new ClientException(_m('This page is not available in a '.
194 'media type you accept.'), 406);
198 header('Content-Type: '.$type);
200 $action->extraHeaders();
201 if (preg_match("/.*\/.*xml/", $type)) {
202 // Required for XML documents
203 $action->xw->startDocument('1.0', 'UTF-8');
205 $action->xw->writeDTD('html',
206 '-//WAPFORUM//DTD XHTML Mobile 1.0//EN',
209 $language = $action->getLanguage();
211 $action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
212 'xml:lang' => $language));
217 function setMobileFeatures($useragent)
219 $mobiledeviceInputFileType = array(
223 $this->mobileFeatures['inputfiletype'] = false;
225 foreach ($mobiledeviceInputFileType as $md) {
226 if (strstr($useragent, $md) !== false) {
227 $this->mobileFeatures['inputfiletype'] = true;
233 function onStartShowStatusNetStyles($action)
235 if (!$this->serveMobile) {
239 $action->primaryCssLink();
241 if (file_exists(Theme::file('css/mp-screen.css'))) {
242 $action->cssLink('css/mp-screen.css', null, 'screen');
244 $action->cssLink('plugins/MobileProfile/mp-screen.css',null,'screen');
247 if (file_exists(Theme::file('css/mp-handheld.css'))) {
248 $action->cssLink('css/mp-handheld.css', null, 'handheld');
250 $action->cssLink('plugins/MobileProfile/mp-handheld.css',null,'handheld');
253 // Allow other plugins to load their styles.
254 Event::handle('EndShowStatusNetStyles', array($action));
255 Event::handle('EndShowLaconicaStyles', array($action));
260 function onStartShowUAStyles($action) {
261 if (!$this->serveMobile) {
268 function onStartShowHeader($action)
270 if (!$this->serveMobile) {
274 $action->elementStart('div', array('id' => 'header'));
275 $this->_showLogo($action);
276 $this->_showPrimaryNav($action);
277 if (common_logged_in()) {
278 $action->showNoticeForm();
280 $action->elementEnd('div');
285 function _showLogo($action)
287 $action->elementStart('address', 'vcard');
288 $action->elementStart('a', array('class' => 'url home bookmark',
289 'href' => common_local_url('public')));
290 if (common_config('site', 'mobilelogo') ||
291 file_exists(Theme::file('logo.png')) ||
292 file_exists(Theme::file('mobilelogo.png'))) {
294 $action->element('img', array('class' => 'photo',
295 'src' => (common_config('site', 'mobilelogo')) ? common_config('site', 'mobilelogo') :
296 ((file_exists(Theme::file('mobilelogo.png'))) ? (Theme::path('mobilelogo.png')) : Theme::path('logo.png')),
297 'alt' => common_config('site', 'name')));
299 $action->element('span', array('class' => 'fn org'), common_config('site', 'name'));
300 $action->elementEnd('a');
301 $action->elementEnd('address');
304 function _showPrimaryNav($action)
306 $user = common_current_user();
307 $action->elementStart('ul', array('id' => 'site_nav_global_primary'));
309 $action->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
311 $action->menuItem(common_local_url('profilesettings'),
313 $action->menuItem(common_local_url('oauthconnectionssettings'),
315 if ($user->hasRight(Right::CONFIGURESITE)) {
316 $action->menuItem(common_local_url('siteadminpanel'),
317 _m('Admin'), _m('Change site configuration'), false, 'nav_admin');
319 if (common_config('invite', 'enabled')) {
320 $action->menuItem(common_local_url('invite'),
323 $action->menuItem(common_local_url('logout'),
326 if (!common_config('site', 'closed')) {
327 $action->menuItem(common_local_url('register'),
330 $action->menuItem(common_local_url('login'),
333 if ($user || !common_config('site', 'private')) {
334 $action->menuItem(common_local_url('peoplesearch'),
337 $action->elementEnd('ul');
340 function onStartShowNoticeFormData($form)
342 if (!$this->serveMobile) {
346 $form->out->element('textarea', array('id' => 'notice_data-text',
349 'name' => 'status_textarea'),
350 ($form->content) ? $form->content : '');
352 $contentLimit = Notice::maxContent();
354 if ($contentLimit > 0) {
355 $form->out->element('div', array('id' => 'notice_text-count'),
359 if (common_config('attachments', 'uploads')) {
360 if ($this->mobileFeatures['inputfiletype']) {
361 $form->out->element('label', array('for' => 'notice_data-attach'), _m('Attach'));
362 $form->out->element('input', array('id' => 'notice_data-attach',
365 'title' => _m('Attach a file')));
366 $form->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
370 $form->out->hidden('notice_return-to', $form->action, 'returnto');
372 $form->out->hidden('notice_in-reply-to', $form->inreplyto, 'inreplyto');
377 function onStartShowAside($action)
379 if ($this->serveMobile) {
384 function onStartShowScripts($action)
389 function _common_path($relative, $ssl=false)
391 $pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : '';
393 if (($ssl && (common_config('site', 'ssl') === 'sometimes'))
394 || common_config('site', 'ssl') === 'always') {
396 if (is_string(common_config('site', 'sslserver')) &&
397 mb_strlen(common_config('site', 'sslserver')) > 0) {
398 $serverpart = common_config('site', 'sslserver');
400 $serverpart = common_config('site', 'mobileserver');
404 $serverpart = common_config('site', 'mobileserver');
407 return $proto.'://'.$serverpart.'/'.$pathpart.$relative;
410 function onPluginVersion(&$versions)
412 $versions[] = array('name' => 'MobileProfile',
413 'version' => STATUSNET_VERSION,
414 'author' => 'Sarven Capadisli',
415 'homepage' => 'http://status.net/wiki/Plugin:MobileProfile',
417 _m('XHTML MobileProfile output for supporting user agents.'));