123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- define('PAGE_TYPE_PREFS_MOBILEPROFILE',
- 'application/vnd.wap.xhtml+xml, application/xhtml+xml, text/html;q=0.9');
- require_once INSTALLDIR.'/plugins/Mobile/WAP20Plugin.php';
- class MobileProfilePlugin extends WAP20Plugin
- {
- public $DTD = null;
- public $serveMobile = false;
- public $reallyMobile = false;
- public $mobileFeatures = array();
- function __construct($DTD='http://www.wapforum.org/DTD/xhtml-mobile10.dtd')
- {
- $this->DTD = $DTD;
- parent::__construct();
- }
- public function onStartShowHTML(Action $action)
- {
-
- $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null;
- $cp = common_accept_to_prefs($httpaccept);
- $sp = common_accept_to_prefs(PAGE_TYPE_PREFS_MOBILEPROFILE);
- $type = common_negotiate_type($cp, $sp);
- if (!$type) {
-
- throw new ClientException(_m('This page is not available in a '.
- 'media type you accept.'), 406);
- }
-
- if ((common_config('site', 'mobileserver').'/'.common_config('site', 'path').'/'
- == $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) {
- $this->serveMobile = true;
- } elseif (isset($_COOKIE['MobileOverride'])) {
-
- $this->serveMobile = (bool)$_COOKIE['MobileOverride'];
- } elseif (strstr('application/vnd.wap.xhtml+xml', $type) !== false) {
-
- $this->serveMobile = true;
- } elseif (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
-
-
-
-
-
-
-
-
-
- $this->mobiledevices = array(
- 'alcatel',
- 'android',
- 'audiovox',
- 'au-mic,',
- 'avantgo',
- 'blackberry',
- 'blazer',
- 'cldc-',
- 'danger',
- 'epoc',
- 'ericsson',
- 'ericy',
- 'iphone',
- 'ipaq',
- 'ipod',
- 'j2me',
- 'lg',
- 'maemo',
- 'midp-',
- 'mobile',
- 'mot',
- 'netfront',
- 'nitro',
- 'nokia',
- 'opera mini',
- 'palm',
- 'palmsource',
- 'panasonic',
- 'philips',
- 'pocketpc',
- 'portalmmm',
- 'rover',
- 'samsung',
- 'sanyo',
- 'series60',
- 'sharp',
- 'sie-',
- 'smartphone',
- 'sony',
- 'symbian',
- 'up.browser',
- 'up.link',
- 'up.link',
- 'vodafone',
- 'wap1',
- 'wap2',
- 'webos',
- 'windows ce'
- );
- $blacklist = array(
- 'ipad',
- );
- $httpuseragent = strtolower($_SERVER['HTTP_USER_AGENT']);
- foreach ($blacklist as $md) {
- if (strstr($httpuseragent, $md) !== false) {
- $this->serveMobile = false;
- return true;
- }
- }
- foreach ($this->mobiledevices as $md) {
- if (strstr($httpuseragent, $md) !== false) {
- $this->setMobileFeatures($httpuseragent);
- $this->serveMobile = true;
- $this->reallyMobile = true;
- break;
- }
- }
- }
- if (!$this->serveMobile) {
- return true;
- }
-
-
- if (common_config('site', 'mobileserver') !== false &&
- common_config('site', 'mobileserver') != common_config('site', 'server')) {
-
- common_redirect($this->_common_path(''), 302);
- }
- header('Content-Type: '.$type);
- if ($this->reallyMobile) {
- $action->setDTD('html', '-//WAPFORUM//DTD XHTML Mobile 1.0//EN', $this->DTD);
- }
-
- return true;
- }
- function setMobileFeatures($useragent)
- {
- $mobiledeviceInputFileType = array(
- 'nokia'
- );
- $this->mobileFeatures['inputfiletype'] = false;
- foreach ($mobiledeviceInputFileType as $md) {
- if (strstr($useragent, $md) !== false) {
- $this->mobileFeatures['inputfiletype'] = true;
- break;
- }
- }
- }
- public function onStartShowStylesheets(Action $action)
- {
- if (!$this->serveMobile) {
- return true;
- }
- $action->primaryCssLink();
- $action->cssLink($this->path('mp-screen.css'),null,'screen');
- if (file_exists(Theme::file('css/mp-screen.css'))) {
- $action->cssLink('css/mp-screen.css', null, 'screen');
- }
- $action->cssLink($this->path('mp-handheld.css'),null,'handheld');
- if (file_exists(Theme::file('css/mp-handheld.css'))) {
- $action->cssLink('css/mp-handheld.css', null, 'handheld');
- }
-
- Event::handle('EndShowStylesheets', array($action));
- return false;
- }
- public function onStartShowUAStyles(Action $action) {
- if (!$this->serveMobile) {
- return true;
- }
- return false;
- }
- public function onStartShowHeader(Action $action)
- {
- if (!$this->serveMobile) {
- return true;
- }
- $action->elementStart('div', array('id' => 'header'));
- $this->_showLogo($action);
- $action->showPrimaryNav();
- $action->elementEnd('div');
- return false;
- }
- protected function _showLogo(Action $action)
- {
- $action->elementStart('address');
- if (common_config('singleuser', 'enabled')) {
- $user = User::singleUser();
- $url = common_local_url('showstream', array('nickname' => $user->getNickname()));
- } else {
- $url = common_local_url('public');
- }
- $action->elementStart('a', array('class' => 'h-card home bookmark',
- 'href' => $url));
- if (common_config('site', 'mobilelogo') ||
- file_exists(Theme::file('logo.png')) ||
- file_exists(Theme::file('mobilelogo.png'))) {
- $action->element('img', array('class' => 'u-photo',
- 'src' => (common_config('site', 'mobilelogo')) ? common_config('site', 'mobilelogo') :
- ((file_exists(Theme::file('mobilelogo.png'))) ? (Theme::path('mobilelogo.png')) : Theme::path('logo.png')),
- 'alt' => common_config('site', 'name')));
- }
- $action->elementEnd('a');
- $action->elementEnd('address');
- }
- public function onStartShowAside(Action $action)
- {
- if ($this->serveMobile) {
- return false;
- }
- }
- public function onStartShowLocalNavBlock(Action $action)
- {
- if ($this->serveMobile) {
-
- $action->element('a', array('href' => '#', 'id' => 'navtoggle'), 'Show Navigation');
- }
- }
- public function onEndShowScripts(Action $action)
- {
-
- $action->inlineScript('
- $(function() {
- $("#mobile-toggle-disable").click(function() {
- $.cookie("MobileOverride", "0", {path: "/"});
- window.location.reload();
- return false;
- });
- $("#mobile-toggle-enable").click(function() {
- $.cookie("MobileOverride", "1", {path: "/"});
- window.location.reload();
- return false;
- });
- $("#navtoggle").click(function () {
- $("#site_nav_local_views").fadeToggle();
- var text = $("#navtoggle").text();
- $("#navtoggle").text(
- text == "Show Navigation" ? "Hide Navigation" : "Show Navigation");
- });
- });'
- );
- if ($this->serveMobile) {
- $action->inlineScript('$(function() { $(".checkbox-wrapper").unbind("click"); });');
- }
- }
- public function onEndShowInsideFooter(Action $action)
- {
- if ($this->serveMobile) {
-
- $linkText = _m('Switch to desktop site layout.');
- $key = 'mobile-toggle-disable';
- } else {
-
- $linkText = _m('Switch to mobile site layout.');
- $key = 'mobile-toggle-enable';
- }
- $action->elementStart('p');
- $action->element('a', array('href' => '#', 'id' => $key), $linkText);
- $action->elementEnd('p');
- return true;
- }
- function _common_path($relative, $ssl=false)
- {
- $pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : '';
- if (($ssl && (common_config('site', 'ssl') === 'sometimes'))
- || common_config('site', 'ssl') === 'always') {
- $proto = 'https';
- if (is_string(common_config('site', 'sslserver')) &&
- mb_strlen(common_config('site', 'sslserver')) > 0) {
- $serverpart = common_config('site', 'sslserver');
- } else {
- $serverpart = common_config('site', 'mobileserver');
- }
- } else {
- $proto = 'http';
- $serverpart = common_config('site', 'mobileserver');
- }
- return $proto.'://'.$serverpart.'/'.$pathpart.$relative;
- }
- function onPluginVersion(array &$versions)
- {
- $versions[] = array('name' => 'MobileProfile',
- 'version' => GNUSOCIAL_VERSION,
- 'author' => 'Sarven Capadisli',
- 'homepage' => 'http://status.net/wiki/Plugin:MobileProfile',
- 'rawdescription' =>
-
- _m('XHTML MobileProfile output for supporting user agents.'));
- return true;
- }
- }
|