]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/MobileProfile/MobileProfilePlugin.php
Init for WAP 2.0 and XHTML Mobile Profile support. WAP20Plugin is a
[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/xml;q=0.9'.
36        ', text/html;q=0.3'
37       );
38
39 require_once INSTALLDIR.'/plugins/Mobile/WAP20Plugin.php';
40
41
42 /**
43  * Superclass for plugin to output XHTML Mobile Profile
44  *
45  * @category Plugin
46  * @package  StatusNet
47  * @author   Sarven Capadisli <csarven@status.net>
48  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49  * @link     http://status.net/
50  */
51
52 class MobileProfilePlugin extends WAP20Plugin
53 {
54     public $DTDversion      = null;
55     public $serveMobile     = false;
56
57     function __construct($DTD='http://www.wapforum.org/DTD/xhtml-mobile10.dtd')
58     {
59         $this->DTD       = $DTD;
60
61         parent::__construct();
62     }
63
64
65     function onStartShowHTML($action)
66     {
67         if (!$type) {
68             $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ?
69               $_SERVER['HTTP_ACCEPT'] : null;
70
71             $cp = common_accept_to_prefs($httpaccept);
72             $sp = common_accept_to_prefs(PAGE_TYPE_PREFS);
73
74             $type = common_negotiate_type($cp, $sp);
75
76             if (!$type) {
77                 throw new ClientException(_('This page is not available in a '.
78                                             'media type you accept'), 406);
79             }
80         }
81
82         // XXX: If user is on the mobile site e.g., m.siteserver.com 
83         // or they really want it, serve the mobile version
84
85         // FIXME: This is dirty and probably not accurate of doing it
86         if ((common_config('site', 'mobileserver').'/'.common_config('site', 'path').'/' == 
87             $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) ||
88             preg_match("/.*\/.*wap.*xml/", $type)) {
89
90             $this->serveMobile = true;
91         }
92         else {
93             $this->serveMobile = false;
94             return true;
95         }
96
97         header('Content-Type: '.$type);
98
99         $action->extraHeaders();
100
101         $action->startXML('html',
102                         '-//WAPFORUM//DTD XHTML Mobile 1.0//EN',
103                         $this->DTD);
104
105         $language = $action->getLanguage();
106
107         $action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml',
108                                             'xml:lang' => $language));
109
110         return false;
111     }
112
113
114
115     function onStartShowAside($action)
116     {
117
118     }
119
120
121     function onStartShowScripts($action)
122     {
123
124     }
125
126 }
127
128
129 ?>