Ticket #14062: patch-macports-www-ie-mime.diff

File patch-macports-www-ie-mime.diff, 5.4 KB (added by raimue (Rainer Müller), 16 years ago)
  • includes/common.inc

     
    55# Copyright (c) 2004, OpenDarwin.
    66# Copyright (c) 2004-2007, The MacPorts Project.
    77
     8require_once 'lib/AcceptMime.class.php';
    89
    910######################################################################
    1011
     
    4243# Page header:
    4344function print_header($title, $encoding) {
    4445    global $MPWEB, $trac_url, $svn_url, $downloads, $guide_url;
    45    
    46     header("Content-Type: application/xhtml+xml; charset=$encoding");
     46
     47    $accept_mime = new AcceptMime();
     48    $mime_type = "text/html";
     49    if ($accept_mime->acceptable("application/xhtml+xml")) {
     50        $mime_type = "application/xhtml+xml";
     51    }
     52    header("Content-Type: $mime_type; charset=$encoding");
     53
    4754    include("$MPWEB/includes/header.inc");
    4855    print_warnings();
    4956}
  • lib/AcceptEncoding.class.php

     
     1<?php
     2
     3require_once 'AcceptAbstract.class.php';
     4
     5class AcceptEncoding extends AcceptAbstract {
     6        function AcceptEncoding() {
     7                parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : 'identity');
     8        }
     9}
     10
     11?>
  • lib/AcceptMime.class.php

    Property changes on: lib/AcceptEncoding.class.php
    ___________________________________________________________________
    Name: svn:keywords
       + Id Author
    
     
     1<?php
     2
     3require_once 'AcceptAbstract.class.php';
     4
     5class AcceptMime extends AcceptAbstract {
     6        function AcceptMime() {
     7                parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : '*');
     8        }
     9}
     10
     11?>
  • lib/AcceptCharset.class.php

    Property changes on: lib/AcceptMime.class.php
    ___________________________________________________________________
    Name: svn:keywords
       + Id Author
    
     
     1<?php
     2
     3require_once 'AcceptAbstract.class.php';
     4
     5class AcceptCharset extends AcceptAbstract {
     6        function AcceptCharset() {
     7                parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT_CHARSET']) ? $_SERVER['HTTP_ACCEPT_CHARSET'] : '*');
     8        }
     9}
     10
     11?>
  • lib/AcceptAbstract.class.php

    Property changes on: lib/AcceptCharset.class.php
    ___________________________________________________________________
    Name: svn:keywords
       + Id Author
    
     
     1<?php
     2
     3class AcceptAbstract {
     4       
     5        function AcceptAbstract($accept_header) {
     6                $this->accept = array();
     7               
     8                if (empty($accept_header)) {
     9                        return;
     10                }
     11               
     12                $fudge_factor = 0.00001;
     13               
     14                $components = preg_split('%\s*,\s*%', $accept_header);
     15                $temp = array();
     16                foreach ($components as $i => $component) {
     17                       
     18                        // Find the parts of the string.
     19                        preg_match('%^
     20                                ([^\s;]+)            # one or more chars -- the value -- match 1
     21                                (?:                  # begin group (optional)
     22                                        \s*;\s*              # semicolon optionally surrounded by whitespace
     23                                        q=                   # literal text "q="
     24                                        ([01](?:\.\d+)?)     # floating-point number, 0 >= n >= 1 -- the quality -- match 2
     25                                )?                   # end group
     26                                $%ix',
     27                                $component, $matches
     28                        );
     29                       
     30                        $value = $matches[1];
     31                       
     32                        // If no quality is given, quality 1 is assumed.
     33                        $q = isset($matches[2]) ? (float)$matches[2] : (float)1;
     34                       
     35                        // Stuff it in the array, if the quality is non-zero.
     36                        if ($q > 0) {
     37                                $temp[$value] = array(
     38                                        'value' => $value,
     39                                        'q' => $q - ($i * $fudge_factor),
     40                                        'i' => $i,
     41                                );
     42                        }
     43                       
     44                }
     45               
     46                // Sort descending by quality.
     47                usort($temp, create_function('$a, $b', 'return ($a["q"] == $b["q"]) ? 0 : ($a["q"] > $b["q"]) ? -1 : 1;'));
     48               
     49                // Unfudge the quality parameter and simplify the array.
     50                foreach ($temp as $x) {
     51                        $this->accept[$x['value']] = $x['q'] + $x['i'] * $fudge_factor;
     52                }
     53        }
     54       
     55        function getPreferred() {
     56                if (empty($this->accept)) {
     57                        return false;
     58                } else {
     59                        $keys = array_keys($this->accept);
     60                        return $this->accept[$keys[0]];
     61                }
     62        }
     63       
     64        function acceptable($value) {
     65                return array_key_exists($value, $this->accept);
     66        }
     67       
     68}
     69
     70?>
  • lib/AcceptLanguage.class.php

    Property changes on: lib/AcceptAbstract.class.php
    ___________________________________________________________________
    Name: svn:keywords
       + Id Author
    
     
     1<?php
     2
     3require_once 'AcceptAbstract.class.php';
     4
     5class AcceptLanguage extends AcceptAbstract {
     6        function AcceptLanguage() {
     7                parent::AcceptAbstract(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '*');
     8        }
     9}
     10
     11?>