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';
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;
54 public $mobileFeatures = array();
56 function __construct($DTD='http://www.wapforum.org/DTD/xhtml-mobile10.dtd')
60 parent::__construct();
64 function onStartShowHTML($action)
66 // XXX: This should probably graduate to WAP20Plugin
68 // If they are on the mobile site, serve them MP
69 if ((common_config('site', 'mobileserver').'/'.
70 common_config('site', 'path').'/' ==
71 $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) {
73 $this->serveMobile = true;
75 // If they like the WAP 2.0 mimetype, serve them MP
76 if (strstr('application/vnd.wap.xhtml+xml', $type) !== false) {
77 $this->serveMobile = true;
79 // If they are a mobile device that supports WAP 2.0,
82 // XXX: Browser sniffing sucks
84 // I really don't like going through this every page,
85 // perhaps use $_SESSION or cookies
87 // May be better to group the devices in terms of
90 // Or, detect the mobile devices based on their support for
91 // MP 1.0, 1.1, or 1.2 may be ideal. Possible?
93 $this->mobiledevices = array(
142 $httpuseragent = strtolower($_SERVER['HTTP_USER_AGENT']);
144 foreach ($this->mobiledevices as $md) {
145 if (strstr($httpuseragent, $md) !== false) {
146 $this->setMobileFeatures($httpuseragent);
148 $this->serveMobile = true;
154 // If they are okay with MP, and the site has a mobile server,
156 if ($this->serveMobile &&
157 common_config('site', 'mobileserver') !== false &&
158 (common_config('site', 'mobileserver') !=
159 common_config('site', 'server'))) {
161 // FIXME: Redirect to equivalent page on mobile site instead
162 common_redirect($this->_common_path(''), 302);
166 if (!$this->serveMobile) {
171 $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ?
172 $_SERVER['HTTP_ACCEPT'] : null;
174 $cp = common_accept_to_prefs($httpaccept);
175 $sp = common_accept_to_prefs(PAGE_TYPE_PREFS_MOBILEPROFILE);
177 $type = common_negotiate_type($cp, $sp);
180 throw new ClientException(_('This page is not available in a '.
181 'media type you accept'), 406);
185 header('Content-Type: '.$type);
187 $action->extraHeaders();
188 if (preg_match("/.*\/.*xml/", $type)) {
189 // Required for XML documents
190 $action->xw->startDocument('1.0', 'UTF-8');
192 $action->xw->writeDTD('html',
193 '-//WAPFORUM//DTD XHTML Mobile 1.0//EN',
196 $language = $action->getLanguage();
198 $action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
199 'xml:lang' => $language));
205 function setMobileFeatures($useragent)
207 $mobiledeviceInputFileType = array(
211 $this->mobileFeatures['inputfiletype'] = false;
213 foreach ($mobiledeviceInputFileType as $md) {
214 if (strstr($useragent, $md) !== false) {
215 $this->mobileFeatures['inputfiletype'] = true;
222 function onStartShowHeadElements($action)
224 if (!$action->serveMobile) {
228 $action->showTitle();
229 $action->showShortcutIcon();
230 $action->showStylesheets();
231 $action->showFeeds();
232 $action->showDescription();
233 $action->extraHead();
237 function onStartShowStatusNetStyles($action)
239 if (!$this->serveMobile) {
243 if (file_exists(Theme::file('css/mp-screen.css'))) {
244 $action->cssLink('css/mp-screen.css', null, 'screen');
246 $action->cssLink('plugins/MobileProfile/mp-screen.css',null,'screen');
249 if (file_exists(Theme::file('css/mp-handheld.css'))) {
250 $action->cssLink('css/mp-handheld.css', null, 'handheld');
252 $action->cssLink('plugins/MobileProfile/mp-handheld.css',null,'handheld');
259 function onStartShowHeader($action)
261 if (!$this->serveMobile) {
265 $action->elementStart('div', array('id' => 'header'));
266 $this->_showLogo($action);
267 $this->_showPrimaryNav($action);
268 if (common_logged_in()) {
269 $action->showNoticeForm();
271 $action->elementEnd('div');
277 function _showLogo($action)
279 $action->elementStart('address', 'vcard');
280 $action->elementStart('a', array('class' => 'url home bookmark',
281 'href' => common_local_url('public')));
282 if (common_config('site', 'mobilelogo') ||
283 file_exists(Theme::file('logo.png')) ||
284 file_exists(Theme::file('mobilelogo.png'))) {
286 $action->element('img', array('class' => 'photo',
287 'src' => (common_config('site', 'mobilelogo')) ? common_config('site', 'mobilelogo') :
288 ((file_exists(Theme::file('mobilelogo.png'))) ? (Theme::path('mobilelogo.png')) : Theme::path('logo.png')),
289 'alt' => common_config('site', 'name')));
291 $action->element('span', array('class' => 'fn org'), common_config('site', 'name'));
292 $action->elementEnd('a');
293 $action->elementEnd('address');
297 function _showPrimaryNav($action)
299 $user = common_current_user();
301 if (common_config('xmpp', 'enabled')) {
302 $connect = 'imsettings';
303 } else if (common_config('sms', 'enabled')) {
304 $connect = 'smssettings';
305 } else if (common_config('twitter', 'enabled')) {
306 $connect = 'twittersettings';
309 $action->elementStart('ul', array('id' => 'site_nav_global_primary'));
311 $action->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
313 $action->menuItem(common_local_url('profilesettings'),
316 $action->menuItem(common_local_url($connect),
319 if ($user->hasRight(Right::CONFIGURESITE)) {
320 $action->menuItem(common_local_url('siteadminpanel'),
321 _('Admin'), _('Change site configuration'), false, 'nav_admin');
323 if (common_config('invite', 'enabled')) {
324 $action->menuItem(common_local_url('invite'),
327 $action->menuItem(common_local_url('logout'),
330 if (!common_config('site', 'closed')) {
331 $action->menuItem(common_local_url('register'),
334 $action->menuItem(common_local_url('login'),
337 if ($user || !common_config('site', 'private')) {
338 $action->menuItem(common_local_url('peoplesearch'),
341 $action->elementEnd('ul');
345 function onStartShowNoticeFormData($form)
347 if (!$this->serveMobile) {
351 $form->out->element('textarea', array('id' => 'notice_data-text',
354 'name' => 'status_textarea'),
355 ($form->content) ? $form->content : '');
357 $contentLimit = Notice::maxContent();
359 if ($contentLimit > 0) {
360 $form->out->element('div', array('id' => 'notice_text-count'),
364 if (common_config('attachments', 'uploads')) {
365 if ($this->mobileFeatures['inputfiletype']) {
366 $form->out->element('label', array('for' => 'notice_data-attach'), _('Attach'));
367 $form->out->element('input', array('id' => 'notice_data-attach',
370 'title' => _('Attach a file')));
371 $form->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
375 $form->out->hidden('notice_return-to', $form->action, 'returnto');
377 $form->out->hidden('notice_in-reply-to', $form->inreplyto, 'inreplyto');
383 function onStartShowAside($action)
385 if ($this->serveMobile) {
391 function onStartShowScripts($action)
397 function _common_path($relative, $ssl=false)
399 $pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : '';
401 if (($ssl && (common_config('site', 'ssl') === 'sometimes'))
402 || common_config('site', 'ssl') === 'always') {
404 if (is_string(common_config('site', 'sslserver')) &&
405 mb_strlen(common_config('site', 'sslserver')) > 0) {
406 $serverpart = common_config('site', 'sslserver');
408 $serverpart = common_config('site', 'mobileserver');
412 $serverpart = common_config('site', 'mobileserver');
415 return $proto.'://'.$serverpart.'/'.$pathpart.$relative;