/** * Class handler. * * @param array $args array of arguments * * @return nothing */ function handle($args) { parent::handle($args); $id = $this->trimmed('id'); if (!$id) { $this->clientError(_('No id.')); } $user =& User::staticGet($id); if (!$user) { $this->clientError(_('No such user.')); } // support redirecting to FOAF rdf/xml if the agent prefers it $page_prefs = 'application/rdf+xml,text/html,application/xhtml+xml,application/xml;q=0.3,text/xml;q=0.2'; $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; $type = common_negotiate_type(common_accept_to_prefs($httpaccept), common_accept_to_prefs($page_prefs)); $page = $type == 'application/rdf+xml' ? 'foaf' : 'showstream'; $url = common_local_url($page, array('nickname' => $user->nickname)); common_redirect($url, 303); }
protected function doPreparation() { // accessing by ID just requires an ID, not a nickname $this->target = Profile::getByID($this->trimmed('id')); // For local users when accessed by id number, redirect with // the nickname as argument instead of id. if ($this->target->isLocal()) { // Support redirecting to FOAF rdf/xml if the agent prefers it... // Internet Explorer doesn't specify "text/html" and does list "*/*" // at least through version 8. We need to list text/html up front to // ensure that only user-agents who specifically ask for RDF get it. $page_prefs = 'text/html,application/xhtml+xml,application/rdf+xml,application/xml;q=0.3,text/xml;q=0.2'; $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; $type = common_negotiate_type(common_accept_to_prefs($httpaccept), common_accept_to_prefs($page_prefs)); $page = $type === 'application/rdf+xml' ? 'foaf' : 'showstream'; $url = common_local_url($page, array('nickname' => $this->target->getNickname())); common_redirect($url, 303); } }
/** * Class handler. * * @param array $args array of arguments * * @return nothing */ function handle($args) { parent::handle($args); $id = $this->trimmed('id'); if (!$id) { $this->clientError(_('No ID.')); } $user = User::staticGet($id); if (!$user) { $this->clientError(_('用户不存在')); } // Support redirecting to FOAF rdf/xml if the agent prefers it... // Internet Explorer doesn't specify "text/html" and does list "*/*" // at least through version 8. We need to list text/html up front to // ensure that only user-agents who specifically ask for RDF get it. $page_prefs = 'text/html,application/xhtml+xml,application/rdf+xml,application/xml;q=0.3,text/xml;q=0.2'; $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; $type = common_negotiate_type(common_accept_to_prefs($httpaccept), common_accept_to_prefs($page_prefs)); $page = $type == 'application/rdf+xml' ? 'foaf' : 'showstream'; $url = common_local_url($page, array('nickname' => $user->nickname)); common_redirect($url, 303); }
function onStartShowHTML($action) { // XXX: This should probably graduate to WAP20Plugin // If they are on the mobile site, serve them MP if (common_config('site', 'mobileserver') . '/' . common_config('site', 'path') . '/' == $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) { $this->serveMobile = true; } else { // If they like the WAP 2.0 mimetype, serve them MP // @fixme $type is undefined, making this if case useless and spewing errors. // What's the intent? //if (strstr('application/vnd.wap.xhtml+xml', $type) !== false) { // $this->serveMobile = true; //} else { // If they are a mobile device that supports WAP 2.0, // serve them MP // XXX: Browser sniffing sucks // I really don't like going through this every page, // perhaps use $_SESSION or cookies // May be better to group the devices in terms of // low,mid,high-end // Or, detect the mobile devices based on their support for // MP 1.0, 1.1, or 1.2 may be ideal. Possible? $this->mobiledevices = array('alcatel', 'android', 'audiovox', 'au-mic,', 'avantgo', 'blackberry', 'blazer', 'cldc-', 'danger', 'epoc', 'ericsson', 'ericy', 'iphone', 'ipaq', 'ipod', 'j2me', 'lg', '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', '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; break; } } //} // If they are okay with MP, and the site has a mobile server, // redirect there if ($this->serveMobile && common_config('site', 'mobileserver') !== false && common_config('site', 'mobileserver') != common_config('site', 'server')) { // FIXME: Redirect to equivalent page on mobile site instead common_redirect($this->_common_path(''), 302); } } if (!$this->serveMobile) { return true; } // @fixme $type is undefined, making this if case useless and spewing errors. // What's the intent? //if (!$type) { $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(_('This page is not available in a ' . 'media type you accept'), 406); } //} header('Content-Type: ' . $type); $action->extraHeaders(); if (preg_match("/.*\\/.*xml/", $type)) { // Required for XML documents $action->xw->startDocument('1.0', 'UTF-8'); } $action->xw->writeDTD('html', '-//WAPFORUM//DTD XHTML Mobile 1.0//EN', $this->DTD); $language = $action->getLanguage(); $action->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => $language)); return false; }
/** * Start an HTML document * * If $type isn't specified, will attempt to do content negotiation. * * Attempts to do content negotiation for language, also. * * @param string $type MIME type to use; default is to do negotation. * * @todo extract content negotiation code to an HTTP module or class. * * @return void */ function startHTML($type = null) { if (!$type) { $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; // XXX: allow content negotiation for RDF, RSS, or XRDS $cp = common_accept_to_prefs($httpaccept); $sp = common_accept_to_prefs(PAGE_TYPE_PREFS); $type = common_negotiate_type($cp, $sp); if (!$type) { // TRANS: Client exception 406 throw new ClientException(_('This page is not available in a ' . 'media type you accept'), 406); } } header('Content-Type: ' . $type); // Output anti-framing headers to prevent clickjacking (respected by newer // browsers). if (common_config('javascript', 'bustframes')) { header('X-XSS-Protection: 1; mode=block'); // detect XSS Reflection attacks header('X-Frame-Options: SAMEORIGIN'); // no rendering if origin mismatch } $this->extraHeaders(); if (preg_match("/.*\\/.*xml/", $type)) { // Required for XML documents $this->startXML(); } $this->writeDTD(); $language = $this->getLanguage(); $attrs = array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => $language, 'lang' => $language); if (Event::handle('StartHtmlElement', array($this, &$attrs))) { $this->elementStart('html', $attrs); Event::handle('EndHtmlElement', array($this, &$attrs)); } }
/** * Start an HTML document * * If $type isn't specified, will attempt to do content negotiation. * * Attempts to do content negotiation for language, also. * * @param string $type MIME type to use; default is to do negotation. * * @todo extract content negotiation code to an HTTP module or class. * * @return void */ function startHTML($type = null) { if (!$type) { $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; // XXX: allow content negotiation for RDF, RSS, or XRDS $cp = common_accept_to_prefs($httpaccept); $sp = common_accept_to_prefs(PAGE_TYPE_PREFS); $type = common_negotiate_type($cp, $sp); if (!$type) { // TRANS: Client exception 406 throw new ClientException(_('This page is not available in a ' . 'media type you accept'), 406); } } header('Content-Type: ' . $type); $this->extraHeaders(); if (preg_match("/.*\\/.*xml/", $type)) { // Required for XML documents $this->xw->startDocument('1.0', 'UTF-8'); } $this->xw->writeDTD('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); $language = $this->getLanguage(); $this->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => $language, 'lang' => $language)); }
protected function checkAccept() { $type = null; $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; if ($httpaccept !== null && $httpaccept != '*/*') { $can_serve = implode(',', Discovery::supportedMimeTypes()); $type = common_negotiate_type(common_accept_to_prefs($httpaccept), common_accept_to_prefs($can_serve)); } else { /* * HACK: for StatusNet to work against us, we must always serve an * XRD to at least versions <1.1.1 (at time of writing) since they * don't send Accept headers (in their 'Discovery::fetchXrd' calls) */ $matches = array(); preg_match('/(StatusNet)\\/(\\d+\\.\\d+(\\.\\d+)?)/', $useragent, $browser); if (count($browser) > 2 && $browser[1] === 'StatusNet' && version_compare($browser[2], '1.1.1') < 1) { return Discovery::XRD_MIMETYPE; } } if (empty($type)) { throw new Exception(_('No specified MIME type in Accept header.')); } return $type; }
public function onStartShowHTML(Action $action) { // TODO: A lot of this should probably graduate to WAP20Plugin $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) { // TRANS: Client exception thrown when requesting a not supported media type. throw new ClientException(_m('This page is not available in a ' . 'media type you accept.'), 406); } // If they are on the mobile site, serve them MP if (common_config('site', 'mobileserver') . '/' . common_config('site', 'path') . '/' == $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) { $this->serveMobile = true; } elseif (isset($_COOKIE['MobileOverride'])) { // Cookie override is controlled by link at bottom. $this->serveMobile = (bool) $_COOKIE['MobileOverride']; } elseif (strstr('application/vnd.wap.xhtml+xml', $type) !== false) { // If they like the WAP 2.0 mimetype, serve them MP $this->serveMobile = true; } elseif (array_key_exists('HTTP_USER_AGENT', $_SERVER)) { // If they are a mobile device that supports WAP 2.0, // serve them MP // XXX: Browser sniffing sucks // I really don't like going through this every page, // perhaps use $_SESSION or cookies // May be better to group the devices in terms of // low,mid,high-end // Or, detect the mobile devices based on their support for // MP 1.0, 1.1, or 1.2 may be ideal. Possible? $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 they are okay with MP, and the site has a mobile server, // redirect there if (common_config('site', 'mobileserver') !== false && common_config('site', 'mobileserver') != common_config('site', 'server')) { // FIXME: Redirect to equivalent page on mobile site instead 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); } // continue return true; }