]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/MobileProfile/MobileProfilePlugin.php
Don't need text/xml until further evidence
[quix0rs-gnu-social.git] / plugins / MobileProfile / MobileProfilePlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * XHTML Mobile Profile plugin that uses WAP 2.0 Plugin
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Plugin
23  * @package   StatusNet
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/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 define('PAGE_TYPE_PREFS',
35        'application/vnd.wap.xhtml+xml, application/xhtml+xml, text/html;q=0.9');
36
37 require_once INSTALLDIR.'/plugins/Mobile/WAP20Plugin.php';
38
39
40 /**
41  * Superclass for plugin to output XHTML Mobile Profile
42  *
43  * @category Plugin
44  * @package  StatusNet
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/
48  */
49
50 class MobileProfilePlugin extends WAP20Plugin
51 {
52     public $DTDversion      = null;
53     public $serveMobile     = false;
54
55     function __construct($DTD='http://www.wapforum.org/DTD/xhtml-mobile10.dtd')
56     {
57         $this->DTD       = $DTD;
58
59         parent::__construct();
60     }
61
62
63     function onStartShowHTML($action)
64     {
65         if (!$type) {
66             $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ?
67               $_SERVER['HTTP_ACCEPT'] : null;
68
69             $cp = common_accept_to_prefs($httpaccept);
70             $sp = common_accept_to_prefs(PAGE_TYPE_PREFS);
71
72             $type = common_negotiate_type($cp, $sp);
73
74             if (!$type) {
75                 throw new ClientException(_('This page is not available in a '.
76                                             'media type you accept'), 406);
77             }
78         }
79
80         // XXX: If user is on the mobile site e.g., m.siteserver.com 
81         // or they really want it, serve the mobile version
82
83         // FIXME: This is dirty and probably not accurate of doing it
84         if ((common_config('site', 'mobileserver').'/'.common_config('site', 'path').'/' == 
85             $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) ||
86             preg_match("/.*\/.*wap.*xml/", $type)) {
87
88             $this->serveMobile = true;
89         }
90         else {
91             $this->serveMobile = false;
92             return true;
93         }
94
95         header('Content-Type: '.$type);
96
97         $action->extraHeaders();
98
99         $action->startXML('html',
100                         '-//WAPFORUM//DTD XHTML Mobile 1.0//EN',
101                         $this->DTD);
102
103         $language = $action->getLanguage();
104
105         $action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
106                                             'xml:lang' => $language));
107
108         return false;
109     }
110
111
112
113     function onStartShowAside($action)
114     {
115
116     }
117
118
119     function onStartShowScripts($action)
120     {
121
122     }
123
124 }
125
126
127 ?>