[43660] trunk/www/includes
ryandesign at macports.org
ryandesign at macports.org
Fri Dec 12 22:12:06 PST 2008
Revision: 43660
http://trac.macports.org/changeset/43660
Author: ryandesign at macports.org
Date: 2008-12-12 22:12:05 -0800 (Fri, 12 Dec 2008)
Log Message:
-----------
Only send application/xhtml+xml Content-Type header if the browser indicates it supports it; otherwise use text/html. Web site is now viewable on Internet Explorer 6 for Windows. See #14062.
Modified Paths:
--------------
trunk/www/includes/common.inc
Added Paths:
-----------
trunk/www/includes/AcceptAbstract.class.php
trunk/www/includes/AcceptCharset.class.php
trunk/www/includes/AcceptEncoding.class.php
trunk/www/includes/AcceptLanguage.class.php
trunk/www/includes/AcceptMime.class.php
Added: trunk/www/includes/AcceptAbstract.class.php
===================================================================
--- trunk/www/includes/AcceptAbstract.class.php (rev 0)
+++ trunk/www/includes/AcceptAbstract.class.php 2008-12-13 06:12:05 UTC (rev 43660)
@@ -0,0 +1,72 @@
+<?php
+
+# -*- coding: utf-8; mode: php; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=php:et:sw=4:ts=4:sts=4
+# $Id$
+# Copyright (c) 2008, The MacPorts Project.
+
+class AcceptAbstract {
+
+ function AcceptAbstract($accept_header) {
+ $this->accept = array();
+
+ if (empty($accept_header)) {
+ return;
+ }
+
+ $fudge_factor = 0.00001;
+
+ $components = preg_split('%\s*,\s*%', $accept_header);
+ $temp = array();
+ foreach ($components as $i => $component) {
+
+ // Find the parts of the string.
+ preg_match('%^
+ ([^\s;]+) # one or more chars -- the value -- match 1
+ (?: # begin group (optional)
+ \s*;\s* # semicolon optionally surrounded by whitespace
+ q= # literal text "q="
+ ([01](?:\.\d+)?) # floating-point number, 0 >= n >= 1 -- the quality -- match 2
+ )? # end group
+ $%ix',
+ $component, $matches
+ );
+
+ $value = $matches[1];
+
+ // If no quality is given, quality 1 is assumed.
+ $q = isset($matches[2]) ? (float)$matches[2] : (float)1;
+
+ // Stuff it in the array, if the quality is non-zero.
+ if ($q > 0) {
+ $temp[$value] = array(
+ 'value' => $value,
+ 'q' => $q - ($i * $fudge_factor),
+ 'i' => $i,
+ );
+ }
+
+ }
+
+ // Sort descending by quality.
+ usort($temp, create_function('$a, $b', 'return ($a["q"] == $b["q"]) ? 0 : ($a["q"] > $b["q"]) ? -1 : 1;'));
+
+ // Unfudge the quality parameter and simplify the array.
+ foreach ($temp as $x) {
+ $this->accept[$x['value']] = $x['q'] + $x['i'] * $fudge_factor;
+ }
+ }
+
+ function getPreferred() {
+ if (empty($this->accept)) {
+ return false;
+ } else {
+ $keys = array_keys($this->accept);
+ return $this->accept[$keys[0]];
+ }
+ }
+
+ function acceptable($value) {
+ return array_key_exists($value, $this->accept);
+ }
+
+}
Property changes on: trunk/www/includes/AcceptAbstract.class.php
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Added: trunk/www/includes/AcceptCharset.class.php
===================================================================
--- trunk/www/includes/AcceptCharset.class.php (rev 0)
+++ trunk/www/includes/AcceptCharset.class.php 2008-12-13 06:12:05 UTC (rev 43660)
@@ -0,0 +1,13 @@
+<?php
+
+# -*- coding: utf-8; mode: php; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=php:et:sw=4:ts=4:sts=4
+# $Id$
+# Copyright (c) 2008, The MacPorts Project.
+
+require_once 'AcceptAbstract.class.php';
+
+class AcceptCharset extends AcceptAbstract {
+ function AcceptCharset() {
+ parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT_CHARSET']) ? $_SERVER['HTTP_ACCEPT_CHARSET'] : '*');
+ }
+}
Property changes on: trunk/www/includes/AcceptCharset.class.php
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Added: trunk/www/includes/AcceptEncoding.class.php
===================================================================
--- trunk/www/includes/AcceptEncoding.class.php (rev 0)
+++ trunk/www/includes/AcceptEncoding.class.php 2008-12-13 06:12:05 UTC (rev 43660)
@@ -0,0 +1,13 @@
+<?php
+
+# -*- coding: utf-8; mode: php; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=php:et:sw=4:ts=4:sts=4
+# $Id$
+# Copyright (c) 2008, The MacPorts Project.
+
+require_once 'AcceptAbstract.class.php';
+
+class AcceptEncoding extends AcceptAbstract {
+ function AcceptEncoding() {
+ parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : 'identity');
+ }
+}
Property changes on: trunk/www/includes/AcceptEncoding.class.php
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Added: trunk/www/includes/AcceptLanguage.class.php
===================================================================
--- trunk/www/includes/AcceptLanguage.class.php (rev 0)
+++ trunk/www/includes/AcceptLanguage.class.php 2008-12-13 06:12:05 UTC (rev 43660)
@@ -0,0 +1,13 @@
+<?php
+
+# -*- coding: utf-8; mode: php; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=php:et:sw=4:ts=4:sts=4
+# $Id$
+# Copyright (c) 2008, The MacPorts Project.
+
+require_once 'AcceptAbstract.class.php';
+
+class AcceptLanguage extends AcceptAbstract {
+ function AcceptLanguage() {
+ parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '*');
+ }
+}
Property changes on: trunk/www/includes/AcceptLanguage.class.php
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Added: trunk/www/includes/AcceptMime.class.php
===================================================================
--- trunk/www/includes/AcceptMime.class.php (rev 0)
+++ trunk/www/includes/AcceptMime.class.php 2008-12-13 06:12:05 UTC (rev 43660)
@@ -0,0 +1,13 @@
+<?php
+
+# -*- coding: utf-8; mode: php; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=php:et:sw=4:ts=4:sts=4
+# $Id$
+# Copyright (c) 2008, The MacPorts Project.
+
+require_once 'AcceptAbstract.class.php';
+
+class AcceptMime extends AcceptAbstract {
+ function AcceptMime() {
+ parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : '*');
+ }
+}
Property changes on: trunk/www/includes/AcceptMime.class.php
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Modified: trunk/www/includes/common.inc
===================================================================
--- trunk/www/includes/common.inc 2008-12-13 05:37:59 UTC (rev 43659)
+++ trunk/www/includes/common.inc 2008-12-13 06:12:05 UTC (rev 43660)
@@ -42,8 +42,15 @@
# Page header:
function print_header($title, $encoding) {
global $MPWEB, $trac_url, $svn_url, $downloads, $guide_url;
-
- header("Content-Type: application/xhtml+xml; charset=$encoding");
+
+ require_once 'AcceptMime.class.php';
+ $accept_mime = new AcceptMime();
+ $mime_type = "text/html";
+ if ($accept_mime->acceptable("application/xhtml+xml")) {
+ $mime_type = "application/xhtml+xml";
+ }
+ header("Content-Type: $mime_type; charset=$encoding");
+
include("$MPWEB/includes/header.inc");
print_warnings();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20081212/1614e7e2/attachment.html>
More information about the macports-changes
mailing list