コード例 #1
0
function al2gt($gettextlangs, $mime)
{
    /* default to "everything is acceptable", as RFC2616 specifies */
    $acceptLang = $_SERVER["HTTP_ACCEPT_LANGUAGE"] == '' ? '*' : $_SERVER["HTTP_ACCEPT_LANGUAGE"];
    $acceptChar = $_SERVER["HTTP_ACCEPT_CHARSET"] == '' ? '*' : $_SERVER["HTTP_ACCEPT_CHARSET"];
    $alparts = @preg_split("/,/", $acceptLang);
    $acparts = @preg_split("/,/", $acceptChar);
    /* Parse the contents of the Accept-Language header.*/
    foreach ($alparts as $part) {
        $part = trim($part);
        if (preg_match("/;/", $part)) {
            $lang = @preg_split("/;/", $part);
            $score = @preg_split("/=/", $lang[1]);
            $alscores[$lang[0]] = $score[1];
        } else {
            $alscores[$part] = 1;
        }
    }
    /* Do the same for the Accept-Charset header. */
    /* RFC2616: ``If no "*" is present in an Accept-Charset field, then
     * all character sets not explicitly mentioned get a quality value of
     * 0, except for ISO-8859-1, which gets a quality value of 1 if not
     * explicitly mentioned.''
     * 
     * Making it 2 for the time being, so that we
     * can distinguish between "not specified" and "specified as 1" later
     * on. */
    $acscores["ISO-8859-1"] = 2;
    foreach ($acparts as $part) {
        $part = trim($part);
        if (preg_match("/;/", $part)) {
            $cs = @preg_split("/;/", $part);
            $score = @preg_split("/=/", $cs[1]);
            $acscores[strtoupper($cs[0])] = $score[1];
        } else {
            $acscores[strtoupper($part)] = 1;
        }
    }
    if ($acscores["ISO-8859-1"] == 2) {
        $acscores["ISO-8859-1"] = isset($acscores["*"]) ? $acscores["*"] : 1;
    }
    /* 
     * Loop through the available languages/encodings, and pick the one
     * with the highest score, excluding the ones with a charset the user
     * did not include.
     */
    $curlscore = 0;
    $curcscore = 0;
    $curgtlang = NULL;
    foreach ($gettextlangs as $gtlang) {
        $tmp1 = preg_replace("/\\_/", "-", $gtlang);
        $tmp2 = @preg_split("/\\./", $tmp1);
        $allang = strtolower($tmp2[0]);
        $gtcs = strtoupper($tmp2[1]);
        $noct = @preg_split("/-/", $allang);
        $testvals = array(array($alscores[$allang], $acscores[$gtcs]), array($alscores[$noct[0]], $acscores[$gtcs]), array($alscores[$allang], $acscores["*"]), array($alscores[$noct[0]], $acscores["*"]), array($alscores["*"], $acscores[$gtcs]), array($alscores["*"], $acscores["*"]));
        $found = FALSE;
        foreach ($testvals as $tval) {
            if (!$found && isset($tval[0]) && isset($tval[1])) {
                $arr = find_match($curlscore, $curcscore, $curgtlang, $tval[0], $tval[1], $gtlang);
                $curlscore = $arr[0];
                $curcscore = $arr[1];
                $curgtlang = $arr[2];
                $found = TRUE;
            }
        }
    }
    /* We must re-parse the gettext-string now, since we may have found it
     * through a "*" qualifier.*/
    $gtparts = @preg_split("/\\./", $curgtlang);
    $tmp = strtolower($gtparts[0]);
    $lang = preg_replace("/\\_/", "-", $tmp);
    $charset = $gtparts[1];
    header("Content-Language: {$lang}");
    header("Content-Type: {$mime}; charset={$charset}");
    return $curgtlang;
}
コード例 #2
0
ファイル: match.php プロジェクト: videophonegeek/tutormatcher
<?php

$request_id = addslashes($_REQUEST[request_id]);
$matches = find_match($request_id);
$request_info = request_info($request_id);
$student_info = student_info($request_info['student_id']);
?>

<div class=title>Make a Match</div>

<table>
<tr>
<td>
<table>
<tr>
    <td align='right'>Name:</td>
    <td><?php 
echo $student_info['name'];
?>
</td>
</tr>
<tr>
    <td align='right'>Subject:</td>
    <td><?php 
echo $request_info['subject_name'];
?>
</td>
</tr>
<tr>
    <td align='right'>Teacher:</td>
    <td><?php