function fancy_design($fname) { global $HTML_PATH, $FANCY_PATH, $LANGUAGE, $LANGUAGES, $counter, $original_index, $publication_date; // Get the contents of the file from $HTML_PATH $content = oneLiner("{$HTML_PATH}/{$fname}", true); // CSS file linking $content = preg_replace("|</HEAD|", '<LINK REL="stylesheet" HREF="style.css"></HEAD', $content); // No margins around $content = preg_replace("/<BODY/", '<BODY TOPMARGIN="0" LEFTMARGIN="0"', $content); // HR dropout $content = preg_replace("/<HR\\s+ALIGN=\"LEFT\"\\s+WIDTH=\"100%\">/", '', $content); // Whole page table and backgrounds $wpbegin = '<TABLE BORDER="0" WIDTH="100%" HEIGHT="100%" CELLSPACING="0" CELLPADDING="0"><TR><TD COLSPAN="3">'; $bnavt = '<TABLE BGCOLOR="#CCCCFF" BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">'; $lnavt = '<TR BGCOLOR="#333366"><TD><IMG SRC="spacer.gif" BORDER="0" WIDTH="1" HEIGHT="1"><BR></TD></TR>'; $space = '<IMG SRC="spacer.gif" WIDTH="10" HEIGHT="1">'; // Navheader backgound $content = preg_replace("/<DIV\\s+CLASS=\"NAVHEADER\"\\s*><TABLE(.*)CELLPADDING=\"0\"(.*)<\\/TABLE\\s*><\\/DIV\\s*>/Us", $wpbegin . '<DIV CLASS="NAVHEADER">' . $bnavt . '<TR><TD><TABLE\\1CELLPADDING="3"\\2</TABLE></TD></TR>' . $lnavt . '</TABLE></DIV></TD></TR><TR><TD>' . $space . '</TD><TD HEIGHT="100%" VALIGN="TOP" WIDTH="100%"><BR>', $content); // Navfooter backgound $content = preg_replace("/<DIV\\s+CLASS=\"NAVFOOTER\"\\s*><TABLE(.*)CELLPADDING=\"0\"(.*)<\\/TABLE\\s*><\\/DIV\\s*>/Us", '<BR></TD><TD>' . $space . '</TD></TR><TR><TD COLSPAN="3"><DIV CLASS="NAVFOOTER">' . $bnavt . $lnavt . '<TR><TD><TABLE\\1CELLPADDING="3"\\2</TABLE></TD></TR></TABLE></DIV></TD></TR></TABLE>', $content); // Fix copyright page fault... if ($fname == "copyright.html") { $content = preg_replace("/&copy;/", "©", $content); $content = preg_replace("/<A\\s+HREF=\"{$original_index}#(authors|translators)\"/U", "<A HREF=\"fancy-index.html\"", $content); $content = preg_replace("|(</TH\\s*></TR\\s*>)|", "\\1<TR><TH COLSPAN=\"3\" ALIGN=\"center\"> </TH></TR>", $content); $content = preg_replace("|( </TD\\s*></TR\\s*>)|", "\\1<TR><TD COLSPAN=\"3\" ALIGN=\"center\"> </TD></TR>", $content); } elseif ($fname == "{$original_index}") { // Find out manual generation date if (preg_match('|<P\\s+CLASS="pubdate"\\s*>([\\d-]+)<BR></P\\s*>|U', $content, $match)) { $publication_date = $match[1]; } else { $publication_date = 'n/a'; } // Modify the index file to meet our needs preg_match('|CLASS=\\"title\\"\\s*><A\\s+NAME=\\"manual\\"\\s*>(.*)</A\\s*>(.*)</H1|U', $content, $match); $indexchange = '<TABLE BORDER="0" WIDTH="100%" HEIGHT="100%" CELLSPACING="0" CELLPADDING="0"><TR><TD COLSPAN="3"><DIV CLASS="NAVHEADER"><TABLE BGCOLOR="#CCCCFF" BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%"><TR><TD><TABLE WIDTH="100%" BORDER="0" CELLPADDING="3" CELLSPACING="0"><TR><TH COLSPAN="3">' . $match[2] . '</TH></TR><TR><TD COLSPAN="3" ALIGN="center"> </TD></TR></TABLE></TD></TR><TR BGCOLOR="#333366"><TD><IMG SRC="spacer.gif" BORDER="0" WIDTH="1" HEIGHT="1"><BR></TD></TR></TABLE> </DIV></TD></TR><TR><TD><IMG SRC="spacer.gif" WIDTH="10" HEIGHT="1"></TD><TD HEIGHT="100%" VALIGN="TOP" WIDTH="100%"><BR>'; $content = preg_replace("/(<DIV\\s+CLASS=\"BOOK\")/", "{$indexchange}\\1", $content); $content = preg_replace("/(<DIV\\s+CLASS=\"author\").*<HR>/Us", "", $content); preg_match('|<DIV\\s+CLASS="TOC"\\s*><DL\\s*><DT\\s*><B\\s*>(.*)</B\\s*>|U', $content, $match); $content = preg_replace("|(CLASS=\"title\"\\s+><A\\s+NAME=\"manual\"\\s*>).*(</A\\s*>).*(</H1)|U", "\\1{$match['1']}\\2\\3", $content); $content = preg_replace("|<DT\\s*><B\\s*>(.*)</B\\s*></DT\\s*>|U", "", $content); } // Print out that new file to $FANCY_PATH $fp = fopen("{$FANCY_PATH}/{$fname}", "w"); $content = setDocumentCharset($content, $LANGUAGES[$LANGUAGE]['mime_charset_name']); fputs_wrapper($fp, $content); fclose($fp); // Print out a message to see the progress echo "{$FANCY_PATH}/{$fname} ready...\n"; $counter++; }
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; } }