1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
<?php
/*
PLEASE DO NOT MAKE ANY MAJOR MODIFICATIONS TO THIS CODE!
There is a new script collection on the way to replace
these scripts. Please see the htmlhelp folder for the new
build system.
See make_chm.README for information about this system.
*/
include_once('common.php');
include_once('chm_settings.php');
$INDEX_IN_HTML = "index.html";
if (empty($FANCY_PATH)) { $FANCY_PATH = $HTML_PATH; }
// Files on the top level of the TOC
$MAIN_FILES = array(
"preface.html",
"getting-started.html",
"install.html",
"langref.html",
"security.html",
"features.html",
"funcref.html",
"internals.html",
"faq.html",
"appendixes.html"
);
// Header for index and toc
$HEADER = '<!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>';
makeProjectFile();
makeContentFiles();
// Generate the HTML Help content files
function makeContentFiles()
{
global $LANGUAGE, $MANUAL_TITLE, $HEADER, $MAIN_FILES,
$HTML_PATH, $INDEX_IN_HTML, $FIRST_PAGE;
$toc = fopen("chm/php_manual_$LANGUAGE.hhc", "w");
$index = fopen("chm/php_manual_$LANGUAGE.hhk", "w");
// Write out file headers
fputs_wrapper($toc, $HEADER);
fputs_wrapper($index, $HEADER);
// Read original index file and drop out newlines
$indexline = oneLiner("$HTML_PATH/$INDEX_IN_HTML");
// Print out the objects, autoparsing won't find
mapAndIndex($MANUAL_TITLE, $FIRST_PAGE, " ", $toc, $index, 21);
// There is a fancy index
if ($FIRST_PAGE != $INDEX_IN_HTML) {
// Find the name of the Table of Contents
preg_match('|CLASS=\"TOC\" *><DL *><DT *><B *>(.*)</B|U', $indexline, $match);
if (empty($match[1])) { // Fallback
$match[1] = "Table of Contents";
}
mapAndIndex($match[1], $INDEX_IN_HTML, " ", $toc, $index, 21);
}
// Find the name of the Preface
preg_match('|<A +HREF="preface.html" *>([^<]*)</A *>|U', $indexline, $match);
if (empty($match[1])) { // Fallback
$match[1] = "Preface";
}
mapAndIndex($match[1], "preface.html", " ", $toc, $index);
// Now autofind the main pages
$MAIN_REGEXP = join("|", $MAIN_FILES);
preg_match_all("![IVX]+[^<]*<A\\s+HREF=\"($MAIN_REGEXP)\"\\s*>([^<]+)</A\\s*>(.+)</DT\\s*></DL\\s*></DD\\s*><DT\\s*>!Ui", $indexline, $matches, PREG_SET_ORDER);
// Go through the main files, and link in subpages
foreach ($matches as $matchinfo) {
mapAndIndex($matchinfo[2], $matchinfo[1], " ", $toc, $index);
fputs_wrapper($toc, "\n <ul>\n");
preg_match_all("!<A\\s+HREF=\"([^\"]+)\"\\s*>([^<]*)</A\\s*>!iU", $matchinfo[3], $subpages, PREG_SET_ORDER);
foreach ($subpages as $spinfo) {
mapAndIndex($spinfo[2], $spinfo[1], " ", $toc, $index);
findDeeperLinks($spinfo[1], $toc, $index);
}
fputs_wrapper($toc, "\n </ul>\n");
}
// Link in directly the copyright page
$copyline = oneLiner("$HTML_PATH/copyright.html");
preg_match('|<A\\s+NAME="copyright"\\s*></A\\s*><P\\s*><B\\s*>([^<]*)</B|U', $copyline, $match);
if (empty($match[1])) { // Fallback
$match[1] = "Copyright";
}
mapAndIndex($match[1], "copyright.html", " ", $toc, $index, 17);
// Write out closing line, and end files
fputs_wrapper($index, " </ul>\n</body>\n</html>");
fputs_wrapper($toc, " </ul>\n</body>\n</html>");
fclose($index);
fclose($toc);
} // makeContentfiles() function end
// Generates the HTML Help project file
function makeProjectFile()
{
global $LANGUAGE, $MANUAL_TITLE, $LANGUAGES,
$HTML_PATH, $FANCY_PATH, $INDEX_IN_HTML,
$FIRST_PAGE;
// Try to find the fancy index file
if (file_exists("$FANCY_PATH/fancy-index.html")) {
$FIRST_PAGE = "fancy-index.html";
} else {
$FIRST_PAGE = $INDEX_IN_HTML;
}
$FIRST_PAGEP = substr($FANCY_PATH, 4) . "\\$FIRST_PAGE";
// Start writing the project file
$project = fopen("chm/php_manual_$LANGUAGE.hhp", "w");
fputs_wrapper($project, "[OPTIONS]\n");
fputs_wrapper($project, "Compatibility=1.1 or later\n");
fputs_wrapper($project, "Compiled file=php_manual_$LANGUAGE.chm\n");
fputs_wrapper($project, "Contents file=php_manual_$LANGUAGE.hhc\n");
fputs_wrapper($project, "Index file=php_manual_$LANGUAGE.hhk\n");
fputs_wrapper($project, "Default Window=phpdoc\n");
fputs_wrapper($project, "Default topic=$FIRST_PAGEP\n");
fputs_wrapper($project, "Display compile progress=Yes\n");
fputs_wrapper($project, "Full-text search=Yes\n");
// Get the proper language code from the array
fputs_wrapper($project, "Language={$LANGUAGES[$LANGUAGE]["langcode"]}\n");
// Now try to find out how the manual named in the actual language
// this must be in the index.html file as the title (DSSSL generated)
$content = oneLiner("$HTML_PATH/$INDEX_IN_HTML");
if (preg_match("|<TITLE\s*>([^<]*)</TITLE\s*>|U", $content, $found)) {
$MANUAL_TITLE = $found[1];
} else { // Fallback
$MANUAL_TITLE = "PHP Manual";
}
fputs_wrapper($project, "Title=$MANUAL_TITLE\n");
fputs_wrapper($project, "Default Font={$LANGUAGES[$LANGUAGE]['preferred_font']}\n");
// Define the phpdoc window style (adds more functionality)
fputs_wrapper($project, "\n[WINDOWS]\nphpdoc=\"$MANUAL_TITLE\",\"php_manual_$LANGUAGE.hhc\",\"php_manual_$LANGUAGE.hhk\"," .
"\"$FIRST_PAGEP\",\"$FIRST_PAGEP\",,,,,0x23520,,0x386e,,,,,,,,0\n");
// Write out all the filenames as in FANCY_PATH
fputs_wrapper($project, "\n[FILES]\n");
$handle = opendir($FANCY_PATH);
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
fputs_wrapper($project, substr($FANCY_PATH, 4)."\\$file\n");
}
}
closedir($handle);
fclose($project);
} // makeProjectFile() function end
// Print out a SiteMap object for a file
function mapAndIndex($name, $local, $tabs, $toc, $index, $imgnum = "auto")
{
global $FANCY_PATH;
$name = str_replace('"', '"', $name);
fputs_wrapper($toc, "
$tabs<li><object type=\"text/sitemap\">
$tabs <param name=\"Name\" value=\"$name\">
$tabs <param name=\"Local\" value=\"".substr($FANCY_PATH, 4)."\\$local\">
");
if ($imgnum != "auto") {
fputs_wrapper($toc, "$tabs <param name=\"ImageNumber\" value=\"$imgnum\">\r\n");
}
fputs_wrapper($toc, "$tabs </object>\r\n");
fputs_wrapper($index, "
<li><object type=\"text/sitemap\">
<param name=\"Local\" value=\"".substr($FANCY_PATH, 4)."\\$local\">
<param name=\"Name\" value=\"$name\">
</object></li>
");
} // mapAndIndex() function end
// Process a file, and find any links need to be presented in tree
function findDeeperLinks ($filename, $toc, $index)
{
global $HTML_PATH;
$contents = oneLiner("$HTML_PATH/$filename");
// Find all sublinks
if (preg_match_all("!<DT\\s*><A\\s+HREF=\"(([\\w\\.-]+\\.)+html)(\\#[\\w\\.-]+)?\"\\s*>(.*)</A\\s*>!U", $contents, $matches, PREG_SET_ORDER)) {
// Print out the file informations for all the links
fputs_wrapper($toc, "\n <ul>");
foreach ($matches as $onematch) {
$param["html"] = $onematch[1];
if (!empty($onematch[3])) {
$param["html"] .= $onematch[3];
}
$param["title"] = strip_tags($onematch[4]);
mapAndIndex($param["title"], $param["html"], " ", $toc, $index);
}
fputs_wrapper($toc, " </ul>\n");
} else {
// Uncomment this if you want to debug the above pregs
// Note: there are many files normally without deeper
// TOC info, eg. language.expressions.html
// echo "no deeper TOC info found in $filename\n";
// return;
}
} // findDeeperLinks() function end
?>
|