【 PHP の HTML Help ファイル ( .chm ) をもっと使いやすくする 】
HTMLで利用 |
PHP のマニュアルはとても親切に作られていますが、あまりにも情報が 多すぎて必要な情報にたどり着くのに多少時間がかかります そこで、.chm 内の HTML に直接アクセスできる機能を用いてオリジナ ルのヘルプページ ( HTML ) を作成します
|
アクセス方法には二通りありますが、通常 ms-its: が使用されます
ms-its:file:///D:/winofsql/php_MyManual/php_manual_ja.chm::ja/index.html
ms-its:D:/winofsql/php_MyManual/php_manual_ja.chm::ja/index.html
ms-its:D:\winofsql\php_MyManual\php_manual_ja.chm::ja/index.html
hh.exe を使用して、.chm ファイルから 元の HTML ファイルとツリーの定義ファイルを作成する事ができます
hh -decompile D:\winofsql\php_MyManual php_manual_ja.chm
実行すると、.hhc と .hhk が作成されます。どちらも似たような HTML ファイルです。.hhc の先頭部分を以下 に示します
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta name="generator" content="PHP 4 - Auto TOC script">
<!-- Sitemap 1.0 -->
</head>
<body>
<object type="text/site properties">
<param name="Window Styles" value="0x800227">
</object>
<ul>
<li><object type="text/sitemap">
<param name="Name" value="PHP マニュアル">
<param name="Local" value="ja/fancy-index.html">
<param name="ImageNumber" value="21">
</object>
<li><object type="text/sitemap">
<param name="Name" value="目次">
<param name="Local" value="ja/index.html">
<param name="ImageNumber" value="21">
</object>
.hhc は、もともとツリーを表示させる為に階層構造になっていますので簡易 HTML ツリーを作成する為に WSH を使用して、コンバートします
conv.vbs
Dim Fs,Fp,Ofp
Dim strLine,strTag
Dim bFirst
Dim regEx,Matches
Dim strTargetTitle,strTargetUrl
Dim IdCount
Set Fs = CreateObject("Scripting.FileSystemObject")
Set regEx = New RegExp
Set Fp = Fs.OpenTextFile( "php_manual_ja.hhc", 1 )
Set Ofp = Fs.CreateTextFile( "control.htm", True )
Ofp.WriteLine "<SCRIPT language=VBScript>"
Ofp.WriteLine "Dim Loc"
Ofp.WriteLine "function Init()"
Ofp.WriteLine "Dim aWork,i,Elements"
Ofp.WriteLine "Loc = window.location"
Ofp.WriteLine "aWork = Split( Loc, ""/"" )"
Ofp.WriteLine "Loc = """""
Ofp.WriteLine "For i = 0 to Ubound( aWork ) - 1"
Ofp.WriteLine " if i <> 0 then"
Ofp.WriteLine " Loc = Loc & ""/"""
Ofp.WriteLine " end if"
Ofp.WriteLine " Loc = Loc & aWork(i)"
Ofp.WriteLine "Next"
Ofp.WriteLine "Loc = ""ms-its:"" & Loc & ""/php_manual_ja.chm::/"""
Ofp.WriteLine "Set Elements = document.all.tags(""INPUT"")"
Ofp.WriteLine "For i = 0 to Elements.length - 1"
Ofp.WriteLine " Elements(i).checked = false"
Ofp.WriteLine "Next"
Ofp.WriteLine "end function"
Ofp.WriteLine "function Cont( id )"
Ofp.WriteLine "if document.all( id ).style.display = """" then"
Ofp.WriteLine " document.all( id ).style.display = ""none"""
Ofp.WriteLine "else"
Ofp.WriteLine " document.all( id ).style.display = """""
Ofp.WriteLine "end if"
Ofp.WriteLine "end function"
Ofp.WriteLine "</SCRIPT>"
Ofp.WriteLine "<SCRIPT for=window event=onload language=""VBScript"">"
Ofp.WriteLine " Call Init()"
Ofp.WriteLine "</SCRIPT>"
Ofp.WriteLine "<HTML>"
Ofp.WriteLine "<HEAD>"
Ofp.WriteLine "<META HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; CHARSET=Shift_JIS"">"
Ofp.WriteLine "<LINK rel=""stylesheet"" href=""style.css"">"
Ofp.WriteLine "</HEAD>"
Ofp.WriteLine "<BODY>"
Ofp.WriteLine "<TABLE width=500 cellspacing=0 cellpadding=3><tr><td>"
bFirst = True
IdCounrt = 0
strTargetTitle = "" : strTargetUrl = ""
Do While not Fp.AtEndOfStream
strLine = Fp.ReadLine
strLine = Ltrim( strLine )
strTag = Left( strLine, 4 )
strTag = Ucase( strTag )
Select Case strTag
Case "<UL>"
if bFirst then
bFirst = False
Ofp.WriteLine "<UL>"
else
Ofp.WriteLine "<LI><INPUT style='margin-left:-23' type=checkbox onClick='Call Cont(""Id" & IdCount _
& """)'><SPAN onClick='parent.Act.location=Loc&""" & strTargetUrl & """'>" & strTargetTitle & "</SPAN>"
Ofp.WriteLine "<UL id=Id" & IdCount & " style='display:none'>"
strTargetTitle = "" : strTargetUrl = ""
end if
Case "</UL"
if strTargetUrl <> "" then
Ofp.WriteLine "<LI><SPAN onClick='parent.Act.location=Loc&""" & strTargetUrl & """'>" & strTargetTitle & "</SPAN>"
strTargetTitle = "" : strTargetUrl = ""
end if
Ofp.WriteLine "</UL>"
Case "</BO"
if strTargetUrl <> "" then
Ofp.WriteLine "<LI><SPAN onClick='parent.Act.location=Loc&""" & strTargetUrl & """'>" & strTargetTitle & "</SPAN>"
strTargetTitle = "" : strTargetUrl = ""
end if
Case "<LI>"
if strTargetUrl <> "" then
Ofp.WriteLine "<LI><SPAN onClick='parent.Act.location=Loc&""" & strTargetUrl & """'>" & strTargetTitle & "</SPAN>"
strTargetTitle = "" : strTargetUrl = ""
end if
IdCount = IdCount + 1
strLine = Fp.ReadLine
regEx.Pattern = "name=""([^""]+)"".+value=""([^""]+)"""
regEx.Global = True
Set Matches = regEx.Execute(strLine) ' 検索を実行
For Each Match in Matches
if Ucase(Match.SubMatches(0)) = "NAME" then
strTargetTitle = Match.SubMatches(1)
Exit For
end if
if Ucase(Match.SubMatches(0)) = "LOCAL" then
strTargetUrl = Match.SubMatches(1)
Exit For
end if
Next
strLine = Fp.ReadLine
regEx.Pattern = "name=""([^""]+)"".+value=""([^""]+)"""
regEx.Global = True
Set Matches = regEx.Execute(strLine) ' 検索を実行
For Each Match in Matches
if Ucase(Match.SubMatches(0)) = "NAME" then
strTargetTitle = Match.SubMatches(1)
Exit For
end if
if Ucase(Match.SubMatches(0)) = "LOCAL" then
strTargetUrl = Match.SubMatches(1)
Exit For
end if
Next
End Select
Loop
Ofp.WriteLine "</TD><TR></TABLE>"
Ofp.WriteLine "</BODY>"
Ofp.WriteLine "</HTML>"
Ofp.Close
Fp.Close
以下は、実行結果の HTML 展開部分のサンプルです
<LI><INPUT style='margin-left:-23' type=checkbox onClick='Call Cont("Id539")'>
<SPAN onClick='parent.Act.location=Loc&"ja/ref.dir.html"'>ディレクトリ関数</SPAN>
<UL id=Id539 style='display:none'>
<LI><SPAN onClick='parent.Act.location=Loc&"ja/function.chdir.html"'>chdir</SPAN>
<LI><SPAN onClick='parent.Act.location=Loc&"ja/function.chroot.html"'>chroot</SPAN>
<LI><SPAN onClick='parent.Act.location=Loc&"ja/class.dir.html"'>dir</SPAN>
コンバート直後は、全ての情報が含まれていますので必要無い情報を省いて、さらに関数はカテゴリで まとめて探しやすくします
フレームを使用しているので以下の HTML が実行する HTML です
<SCRIPT language=VBScript>
Dim Loc
function CreateLocation()
Dim aWork,i
Loc = window.location
aWork = Split( Loc, "/" )
Loc = ""
For i = 0 to Ubound( aWork ) - 1
if i <> 0 then
Loc = Loc & "/"
end if
Loc = Loc & aWork(i)
Next
Loc = "ms-its:" & Loc & "/php_manual_ja.chm::"
end function
</SCRIPT>
<SCRIPT for=window event=onload language="VBScript">
Call CreateLocation()
document.all("Act").src = Loc & "/ja/fancy-index.html"
</SCRIPT>
<HTML>
<HEAD>
<TITLE>PHP マニュアル支援</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=Shift_JIS">
</HEAD>
<FRAMESET id="TopFrame" cols="250,*" framespacing="1">
<FRAME name="Ctrl" src="control.htm">
<FRAME name="Act">
</FRAMESET>
|