ついに正式版がリリースされました。
libxml2で遊びまくりましょう。SimpleXMLも要チェックです。
PHP4.3.8も同時にリリースされています。セキュリティの改善がメインで「出来る限り早いバージョンアップを強く推奨」とのこと。
T566が帰ってきました(やはり打ち間違いだったらしい)。
フォーカスはかなり改善されました。それにしてもT560i-Jは年を考えると化け物じみている気が。さすがに光度とコントラストはT566が勝っていますが、フォーカスは負けてません。恐ろしい。
肝心の歪みですが……。あれ? 直ってる? あまり変わってないような直ったような。平面になれた頃にもう1度調整してみよう。
PHP5では名前空間付きパラメータに値を渡せるようになった。これは良い点だ。
が、xsl:importやdocument()で外部ファイルの読み込みが出来ない。loadXML()でパースした場合基底URIが設定できないのが原因のようだ。load()ならば問題ない。
確認していないが$DOMObject->documentURI = stringで行けるかも知れない。
xml:space="preseve"に対する対応XSL Functionはソース文章内のxml:space="preserve"は無視する。何故かリテラル結果要素に付いているxml:space="preserve"は認識して空白を保持する。
$DOMObject->preserveWhiteSpace = FALSE;はxml:space="preserve"に従って空白を除去する。
$DOMObject->formatOutput = TRUE;はxml:space="preserve"を無視してインデントする。
なぜこう中途半端なのだろうか。pre要素を何とかさせて欲しい。
例によってマニュアルに書いていない部分が多い。ソースコードから漁ってこよう。
面倒になったので書いてしまった。XHTML以外にも使えるがpre要素だけはよく使うので特別扱いしている。
あらかじめ空白ノードを全て削除しておかなければいけないので使える場面は限られるかも知れない。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xh="http://www.w3.org/1999/xhtml">
<xsl:output omit-xml-declaration="no" version="1.0" method="xml" indent="no" encoding="UTF-8"/>
<xsl:param name="amount" select="' '"/>
<xsl:template match="*[ancestor::*[./@xml:space][1]/@xml:space = 'preserve']
| *[ancestor::xh:pre]" priority="60">
<xsl:element name="{local-name()}" namespace="{namespace-uri(.)}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="*[./@xml:space = 'preserve']
| xh:pre" priority="55">
<xsl:call-template name="space"/>
<xsl:element name="{local-name()}" namespace="{namespace-uri(.)}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element><xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="*[following-sibling::text() or preceding-sibling::text()]" priority="50">
<xsl:element name="{local-name()}" namespace="{namespace-uri(.)}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="*[not(child::node())]" priority="45">
<xsl:call-template name="space"/>
<xsl:element name="{local-name()}" namespace="{namespace-uri(.)}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element><xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="*[child::text()]" priority="40">
<xsl:call-template name="space"/>
<xsl:element name="{local-name()}" namespace="{namespace-uri(.)}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element><xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="*[not(child::text())]" priority="35">
<xsl:call-template name="space"/>
<xsl:element name="{local-name()}" namespace="{namespace-uri(.)}">
<xsl:copy-of select="@*"/><xsl:text>
</xsl:text>
<xsl:apply-templates/>
<xsl:call-template name="space"/>
</xsl:element><xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="comment()">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template name="space">
<xsl:for-each select="ancestor::*">
<xsl:value-of select="$amount"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
interceptor.phpをPHP5で書き直していく。メインのクラスになるHIMMELは大体できあがった。
class HIMMEL
{
protected $id;
protected $mode;
protected $xhtml_version;
protected $sdf_source;
function HIMMEL($mode, $id, $sdf_source = NULL)
{
$this->id = is_file((ROOT == "/" ? "" : ROOT) . ($id == "/" ? "" : $id) . "/index.xml") ? $id : xmlError();
$this->mode = $mode;
$this->sdf_source = $sdf_source;
/* Select XHTML version */
$request_headers = apache_request_headers();
$accept = explode(",", $request_headers["Accept"]);
if (in_array("application/xhtml+xml", $accept)) {
$this->xhtml_version = (double) 1.1;
} else {
$this->xhtml_version = (double) 1.0;
}
/* Apply S3 */
$xhtml = $this->applyS3();
/* HTTP Headers */
$this->HTTPHeaders($xhtml);
print $xhtml;
}
function applyS3()
{
/* Apply S3 */
if ($this->mode == "intercept") {
$result = $this->SmartXSLT((ROOT == "/" ? "" : ROOT) . ($this->id == "/" ? "" : $this->id) . "/index.xml",
(ROOT == "/" ? "" : ROOT) . "/s3/interface.xsl"
);
} elseif($this->mode == "receive") {
$result = $this->SmartXSLT($this->sdf_source, (ROOT == "/" ? "" : ROOT) . "/s3/interface.xsl");
}
/* For old brosers */
if ($this->xhtml_version == 1.0) {
$result = $this->SmartXSLT($result, (ROOT == "/" ? "" : ROOT) . "/s3/11to10.xsl");
}
/* Strip space nodes and indent */
$indent = new DomDocument();
$indent->preserveWhiteSpace = FALSE;
$indent->loadXML($result);
$result = $indent->saveXML();
$result = $this->SmartXSLT($result, (ROOT == "/" ? "" : ROOT) . "/himmel/indent.xsl");
/* Clean up namespace */
$result = $this->SmartXSLT($result, (ROOT == "/" ? "" : ROOT) . "/himmel/valid.xsl");
// Hack for IE6
if (preg_match("/MSIE 6.0/", $_SERVER["HTTP_USER_AGENT"])) {
$result = preg_replace("/<\?xml.*?\?>\n/", "", $result);
}
// Hacks
$result = preg_replace("/(<.*?[^ ])\/>/is", "$1 />", $result);
$result = preg_replace("/<textarea(.*?)\/>/is", '<textarea$1></textarea>', $result);
$result = preg_replace("/<script(.*?)\/>/is", '<script$1></script>', $result);
return $result;
}
function SmartXSLT($xmls, $xsls, $param = NULL)
{
/* Load the sources */
$xml = new DomDocument();
is_file($xmls) ? $xml->load($xmls) : $xml->loadXML($xmls);
$xsl = new DomDocument();
is_file($xsls) ? $xsl->load($xsls) : $xsl->loadXML($xsls);
/* XSLT */
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl);
return $proc->transformToXML($xml);
}
function HTTPHeaders($xhtml)
{
/* Get Modified */
$dom_mod = new DomDocument;
$dom_mod->loadXML($xhtml);
$xph_mod = new domXPath($dom_mod);
$xph_mod->registerNamespace("xh", "http://www.w3.org/1999/xhtml");
$node_mod = $xph_mod->query("/xh:html/xh:head/xh:meta[./@name = 'WWWC']");
$modified = $node_mod->item(0)->getAttribute("content");
$modified = str_replace("/", "-", substr($modified, 0, 10)) . "T" . substr($modified, -5, 5) . "Z";
$modified = parse_w3cdtf($modified);
$modified = $modified["timestamp"];
// If-Modified-Since
if ($request_headers["If-Modified-Since"]) {
$since = parse_http_date($request_headers["If-Modified-Since"]);
if ($since["timestamp"] >= $modified) {
header("HTTP/1.1 304 Not Modified");
exit();
}
}
// Send HTTP Headers
if ($this->version_xhtml >= 1.1) {
header("Content-Type: application/xhtml+xml; charset=UTF-8");
} elseif ($this->version_xhtml == 1.0) {
header("Content-Type: text/html; charset=UTF-8");
}
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $modified) . " GMT");
header("Content-Style-Type: text/css");
header("Content-Script-Type: text/javascript");
}
}
オブジェクト指向なんて何年も前にJavaScriptで触って以来なのでよく分からない。特に変数をどうするかが難しい。そもそも処理がほとんど1本道なのでオブジェクト指向の利点が無いような気もする。
ここ数日HDDの音がおかしい気がする。SpeedFanでS.M.A.R.T.を確認すると「Raw Read Error Rate」が95まで下がっている。即死と言うことはなさそうだが注意した方が良さそうだ。