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
|
<?php
/*
This file is part of the Windows Compiled HTML Help
Manual Generator of the PHP Documentation project.
The logic in this file comes from an extract
of phpweb/include/shared-manual.inc and
phpweb/include/layout.inc (clean_note()).
From time to time, it may be needed to update
the code, as the manual notes system changes.
This file is consistent with:
layout.inc - 1.66
shared-manual.inc - 1.125
This file also includes code to generate a project
file for the notes.
Grab the notes file (all compressed) from:
http://ANY_MIRROR_SITE.php.net/backend/notes/all.bz2
*/
// Check dependencies, die if error found
if (!$USE_NOTES) { die("ERROR: User note generator called"); }
// Merge all possible language manuals. Only the available
// manual[s] will be active, while viewing
$lang_chms = '';
foreach ($LANGUAGES as $code) {
$lang_chms .= "php_manual_$code.chm\n";
}
// We need a list of files for an IE6 workaround
$NOTE_FILE_LIST = array();
// Start writing the notes project file
$nproject = fopen("$NOTES_TARGET/php_manual_notes.hhp", "w");
fputs($nproject,
"[OPTIONS]
Compatibility=1.1 or later
Compiled file=php_manual_notes.chm
Default topic=_index.html
Display compile progress=No
Full-text search=Yes
Language=0x0809 English (UNITED KINGDOM)
Title=User Notes
[MERGE FILES]
$lang_chms
[FILES]
");
// Walk through all files in HTML_DIR directory
$handle = opendir($HTML_SRC);
while (false !== ($filename = readdir($handle))) {
// Only process html files generated by XSL sheets
if (strpos($filename, ".html") && (strpos($filename, "_") !== 0)) {
// Get title (used for HTML page title)
$content = join("", file("$HTML_SRC/$filename"));
preg_match("!<title>([^<]+)</title>!Us", $content, $match);
// Get user notes, or false on failure
$user_notes = manualUserNotes($match[1], $filename);
// If there are no user notes for this page,
// no file will be generated, but if we generate
// a file, we add it to project file too
if ($user_notes != FALSE) {
$WITH_NOTES++;
$notes = fopen("$NOTES_TARGET/$filename", "w");
fwrite($notes, $user_notes);
fclose($notes);
fwrite($nproject, $filename . "\n");
$NOTE_FILE_LIST[] = $filename;
echo "> $WITH_NOTES\r";
} else {
$WITHOUT_NOTES++;
}
}
}
closedir($handle);
// Copy note supplemental files, and add to file list
copy("suppfiles/notes/_index.html", "$NOTES_TARGET/_index.html");
fwrite($nproject, "_index.html\n");
copy("suppfiles/notes/_style.css", "$NOTES_TARGET/_style.css");
fwrite($nproject, "_style.css\n");
// RAQ : Wednesday, 16 March 2005 01:54 pm : Allow all note pages to have a global JavaScript file.
copy('suppfiles/notes/_notes_script.js', "$NOTES_TARGET/_notes_script.js");
fwrite($nproject, "_notes_script.js\n");
// Write out a list of files to work around an IE6 bug
$jsfile = fopen("$NOTES_TARGET/_filelist.js", "w");
fwrite($jsfile, "note_file_list = ' " . join(" ", $NOTE_FILE_LIST) . " ';\n\n");
fwrite($jsfile, "if (note_file_list.indexOf(' ' + chmfile_page + ' ') != -1) { notesIframe(); }");
fclose($jsfile);
fwrite($nproject, "_filelist.js\n");
// Close ready project file
fclose($nproject);
// Make entry HTML fragment for a user note
function makeEntry($date, $name, $blurb)
{
// Begin user notes header
$entryhtml = "<div><p class=\"unheader\">\n";
// Get email/name of the user note writer
$name = htmlspecialchars($name);
if ($name && $name != "php-general@lists.php.net" && $name != "user@example.com") {
if (ereg("(.+)@(.+)\.(.+)", $name)) {
$entryhtml .= "<a href=\"mailto:$name\" class=\"useremail\"><span>$name</span></a>";
} else {
$entryhtml .= "<b><span>$name</span></b>";
}
}
// Append date
$entryhtml .= " (<span>" . date("d-M-Y h:i", $date) . "</span>)</p>\n";
// Append user note text, cleared
$entryhtml .= "<p class=\"untext\"><tt><span>" . clean_note($blurb) . "</span></tt></p></div>\n";
// Return with entry HTML fragment
return $entryhtml;
}
// Get user notes for this particular page, returns an array with notes
function manualGetUserNotes($id)
{
global $NOTES_SRC, $NOTE_NUM;
$notes = array();
$hash = substr(md5($id),0,16);
$notes_file = "$NOTES_SRC/$hash[0]/$hash";
if ($fp = @fopen($notes_file,"r")) {
while (!feof($fp)) {
$line = chop(fgets($fp,8096));
if ($line == "") continue;
list($id,$sect,$rate,$ts,$user,$note) = explode("|",$line);
$notes[] = array(
"id" => $id,
"sect" => $sect,
"rate" => $rate,
"xwhen" => $ts,
"user" => $user,
"note" => base64_decode($note)
);
}
fclose($fp);
}
$NOTE_NUM += count($notes);
return $notes;
}
// Get the HTML file for a user note page, or false on failure
function manualUserNotes($title, $id)
{
// Don't want .html at the end of the ids
if (substr($id,-5) == '.html') { $id = substr($id,0,-5); }
// Get user notes
$notes = manualGetUserNotes($id);
// If we have no notes, do not produce useless HTML
if (count($notes) == 0) {
return FALSE;
}
// start HTML output
// RAQ : Wednesday, 16 March 2005 01:54 pm : Allow all note pages to have a global JavaScript file and use new notesLoading() function for body's onLoad.
$notehtml = <<<END_OF_MULTI
<html>
<head>
<title>N: $title</title>
<link rel="stylesheet" href="_style.css">
<script language="JavaScript1.2" src="_notes_script.js"></script>
</head>
<body onLoad="if(parent.nbuff) {parent.displayNotes();} else {loadWithNotes();}">
<h3>User contributed notes:</h3>
END_OF_MULTI;
// Go through manual notes, and make entries
foreach ($notes as $note) {
$notehtml .= makeEntry($note['xwhen'], $note['user'], $note['note'], $note['id']);
}
// Be good guys, and end HTML code here
$notehtml .= "\n</body></html>";
// Return with manual notes for this page
return $notehtml;
}
// Clean note to get right display
function clean_note($text) {
// Do not allow people to fool the system with bogus HTML
$text = htmlspecialchars(trim($text));
// turn urls into links
$text = preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\\s|\\)|\"|\\.\\s|$)/","<a href=\"\\1\">\\1</a>\\3",$text);
// this 'fixing' code will go away eventually
$fixes = array('<br>','<p>','</p>');
reset($fixes);
while (list(,$f)=each($fixes)) {
$text=str_replace(htmlspecialchars($f), $f, $text);
$text=str_replace(htmlspecialchars(strtoupper($f)), $f, $text);
}
// Allow only one <br> (drop out long empty sections)
$text = preg_replace("!(<br>\\s*)+!", "<br>", $text);
// wordwrap is not applicable here, because (it is buggy and)
// we need to make text break as window resized
// Convert new lines in notes to <br> / <br />
$text = nl2br(preg_replace("![\\n\\r]+!", "\n", $text));
// Get files to smaller size (bad hack :)
$text = str_replace("<br />", "<br>", $text);
// We do not use <pre> but would like to see indentation
$text = str_replace(" ", " ", $text);
// Paras cannot be used here, replace with <br><br>
$text = str_replace("<p>", "<br><br>", $text);
// Drop out end of paras
$text = str_replace("</p>", "", $text);
return $text;
}
?>
|