cvs: phd /phpdotnet/phd/Package/Pear CHM.php ChunkedXHTML.php Factory.php Web.php XHTML.php

From: Date: Mon, 29 Jun 2009 11:28:30 +0000
Subject: cvs: phd /phpdotnet/phd/Package/Pear CHM.php ChunkedXHTML.php Factory.php Web.php XHTML.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-4273@lists.php.net to get a copy of this message
moacir Mon Jun 29 11:28:30 2009 UTC Added files: /phd/phpdotnet/phd/Package/Pear Web.php ChunkedXHTML.php CHM.php Modified files: /phd/phpdotnet/phd/Package/Pear Factory.php XHTML.php Log: Added Web.php, ChunkedXHTML.php and CHM.php

http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Package/Pear/Factory.php?r1=1.1&r2=1.2&diff_format=u Index: phd/phpdotnet/phd/Package/Pear/Factory.php diff -u phd/phpdotnet/phd/Package/Pear/Factory.php:1.1 phd/phpdotnet/phd/Package/Pear/Factory.php:1.2 --- phd/phpdotnet/phd/Package/Pear/Factory.php:1.1 Tue Jun 23 16:17:48 2009 +++ phd/phpdotnet/phd/Package/Pear/Factory.php Mon Jun 29 11:28:30 2009 @@ -2,10 +2,22 @@ namespace phpdotnet\phd; class Package_Pear_Factory extends Format_Factory { - public function createBigXhtmlFormat() { return new Package_Pear_BigXHTML(); + } + + public function createXhtmlFormat() { + return new Package_Pear_ChunkedXHTML(); + } + + public function createPHPFormat() { + return new Package_Pear_Web(); + } + + public function createChmFormat() { + return new Package_Pear_CHM(); } + } ?> http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Package/Pear/XHTML.php?r1=1.2&r2=1.3&diff_format=u Index: phd/phpdotnet/phd/Package/Pear/XHTML.php diff -u phd/phpdotnet/phd/Package/Pear/XHTML.php:1.2 phd/phpdotnet/phd/Package/Pear/XHTML.php:1.3 --- phd/phpdotnet/phd/Package/Pear/XHTML.php:1.2 Wed Jun 24 14:02:40 2009 +++ phd/phpdotnet/phd/Package/Pear/XHTML.php Mon Jun 29 11:28:30 2009 @@ -380,11 +380,15 @@ return $this->mytextmap; } - protected function createTOC($id, $lang) { - if (!$this->getChildrens($id)) { + protected function createTOC($id, $name, $props, $depth = 1, $header = true) { + if (!$this->getChildrens($id) || $depth == 0) { return ""; } - $toc = '<strong>' . $this->autogen('toc', $lang) . '</strong><ul>'; + $toc = ''; + if ($header) { + $toc .= '<strong>' . $this->autogen('toc', $props['lang']) . '</strong>'; + } + $toc .= "<ul class=\"chunklist chunklist_$name\">\n"; foreach ($this->getChildrens($id) as $child) { $isLDesc = null; $isSDesc = null; @@ -393,24 +397,8 @@ $link = $this->createLink($child); $list = ""; - if ($this->cchunk["name"] === "book" || $this->cchunk["name"] === "set") { - if ($this->getChildrens($child)) { - $list = "<ul>"; - foreach ($this->getChildrens($child) as $subChild) { - $isSubLDesc = null; - $isSubSDesc = null; - $subLong = $this->parse($this->getLongDescription($subChild, $isLDesc)); - $subShort = $this->getShortDescription($subChild, $isSubSDesc); - - $href = $this->createLink($subChild); - if ($isSubLDesc && $isSubSDesc) { - $list .= '<li><a href="' . $href . '">' . $subShort . '</a> — ' . $subLong . "</li>\n"; - } else { - $list .= '<li><a href="' . $href . '">' . ($subLong ?: $subShort) . '</a>' . "</li>\n"; - } - } - $list .="</ul>"; - } + if ($depth > 1 ) { + $list = $this->createTOC($child, $name, $props, $depth -1, false); } if ($isLDesc && $isSDesc) { $toc .= '<li><a href="' . $link . '">' . $short . '</a> — ' . $long . $list . "</li>\n"; @@ -444,64 +432,6 @@ return preg_replace('#<p>\\s*</p>#s', '', $str); } - public function format_chunk($open, $name, $attrs, $props) - { - $id = null; - if (isset($attrs[Reader::XMLNS_XML]['id'])) { - $this->CURRENT_ID = $id = $attrs[Reader::XMLNS_XML]['id']; - } - if ($props['isChunk']) { - $this->cchunk = $this->dchunk; - } - if (isset($props['lang'])) { - $this->lang = $props['lang']; - } - if ($name == 'refentry') { - if (isset($attrs[Reader::XMLNS_DOCBOOK]['role'])) { - $this->cchunk['verinfo'] = !($attrs[Reader::XMLNS_DOCBOOK]['role'] == 'noversion'); - } else { - $this->cchunk['verinfo'] = true; - } - } - $this->CURRENT_CHUNK = $id; - $this->notify(Render::CHUNK, $open ? Render::OPEN : Render::CLOSE); - if ($name == 'legalnotice') { - if ($open) { - return '<div class="' . $name . '" ' . ($id ? "id=\"{$id}\"" : '') . '">'; - } - return "</div>\n"; - } - return false; - } - - public function format_container_chunk($open, $name, $attrs, $props) - { - if (!isset($attrs[Reader::XMLNS_XML]['id'])) { - if ($open) { - return "<div class=\"{$name}\">"; - } else { - return "</div>\n"; - } - } - $this->CURRENT_ID = $id = $attrs[Reader::XMLNS_XML]['id']; - $this->CURRENT_CHUNK = $id; - $this->notify(Render::CHUNK, $open ? Render::OPEN : Render::CLOSE); - if (!$open) { - return "</div>\n"; - } - - if ($props['isChunk']) { - $this->cchunk = $this->dchunk; - } - $toc = $this->createTOC($id, $props["lang"]); - if ($toc) { - $toc = "<div class=\"TOC\">\n" . $toc . "</div>\n"; - } - $this->cchunk['container_chunk'] = $toc; - - return "<div class=\"{$name}\" id=\"{$id}\">"; - } - public function format_div($open, $name, $attrs, $props) { if ($open) { @@ -516,44 +446,7 @@ return $this->format_container_chunk($open, 'reference', $attrs, $props); } - /** - * Formatting for the root element of a chunk. - * - * @param bool $open Whether we should open or close this element. - * @param string $name Name of the element - * @param array $attrs Attributes present for the element. Array keys are the attribute namespaces. - * @param array $props Associative array of additional properties - * - * @return string - */ - public function format_root_chunk($open, $name, $attrs, $props) - { - $this->cchunk = $this->dchunk; - $this->cchunk["name"] = $name; - if(isset($attrs[Reader::XMLNS_XML]["id"])) { - $id = $attrs[Reader::XMLNS_XML]["id"]; - } else { - $id = uniqid("phd"); - } - - if ($open) { - $this->CURRENT_CHUNK = $id; - $this->notify(Render::CHUNK, Render::OPEN); - - return '<div id="' .$id. '" class="' .$name. '">'; - } - - $this->CURRENT_CHUNK = $id; - $this->notify(Render::CHUNK, Render::CLOSE); - /* - $toc = ""; - $toc = $this->createTOC($id, $props["lang"]); - - return $toc."</div>"; - */ - return "</div>"; - } - + /** * Format a link for an element * @@ -621,20 +514,6 @@ return '</a>'; } - public function format_container_chunk_title($open, $name, $attrs, $props) - { - if ($open) { - return $props["empty"] ? '' : '<h1>'; - } - $ret = ''; - if (isset($this->cchunk['container_chunk']) && $this->cchunk['container_chunk']) { - $ret = $this->cchunk['container_chunk']; - $this->cchunk['container_chunk'] = null; - } - - return "</h1>\n" .$ret; - } - public function transformFromMap($open, $tag, $name, $attrs, $props) { if ($open) { @@ -1932,4 +1811,123 @@ return '&lt;<a href="mailto:' . $value . '">' . $value . '</a>&gt;'; } +//Chunk Functions + + /** + * Formatting for the root element of a chunk. + * + * @param bool $open Whether we should open or close this element. + * @param string $name Name of the element + * @param array $attrs Attributes present for the element. Array keys are the attribute namespaces. + * @param array $props Associative array of additional properties + * + * @return string + */ + public function format_root_chunk($open, $name, $attrs, $props) + { + $this->CURRENT_CHUNK = $this->CURRENT_ID = $id = $attrs[Reader::XMLNS_XML]['id']; + if ($open) { + $this->notify(Render::CHUNK, Render::OPEN); + return "<div class=\"{$name}\">"; + } + $this->notify(Render::CHUNK, Render::CLOSE); + + $content = $this->createTOC( + $id, $name, $props, + isset($attrs[Reader::XMLNS_PHD]['toc-depth']) + ? (int)$attrs[Reader::XMLNS_PHD]['toc-depth'] : 1 + ); + + $content .= "</div>\n"; + + return $content; + } + + public function format_chunk($open, $name, $attrs, $props) + { + $id = null; + if (isset($attrs[Reader::XMLNS_XML]['id'])) { + $this->CURRENT_ID = $id = $attrs[Reader::XMLNS_XML]['id']; + } + + $isChunk = isset($attrs[Reader::XMLNS_PHD]['chunk']) + ? $attrs[Reader::XMLNS_PHD]['chunk'] == "true" : true; + + if ($isChunk) { + $this->cchunk = $this->dchunk; + $this->CURRENT_CHUNK = $id; + $this->notify(Render::CHUNK, $open ? Render::OPEN : Render::CLOSE); + } + + if (isset($props['lang'])) { + $this->lang = $props['lang']; + } + if ($name == 'refentry') { + if (isset($attrs[Reader::XMLNS_DOCBOOK]['role'])) { + $this->cchunk['verinfo'] = !($attrs[Reader::XMLNS_DOCBOOK]['role'] == 'noversion'); + } else { + $this->cchunk['verinfo'] = true; + } + } + + if ($name == 'legalnotice') { + if ($open) { + return '<div class="' . $name . '" ' . ($id ? "id=\"{$id}\"" : '') . '">'; + } + return "</div>\n"; + } + return false; + } + + public function format_container_chunk($open, $name, $attrs, $props) + { + if (!isset($attrs[Reader::XMLNS_XML]['id'])) { + if ($open) { + return "<div class=\"{$name}\">"; + } else { + return "</div>\n"; + } + } + $this->CURRENT_ID = $id = $attrs[Reader::XMLNS_XML]['id']; + + $isChunk = isset($attrs[Reader::XMLNS_PHD]['chunk']) + ? $attrs[Reader::XMLNS_PHD]['chunk'] == "true": true; + + if ($isChunk) { + $this->cchunk = $this->dchunk; + $this->CURRENT_CHUNK = $id; + $this->notify(Render::CHUNK, $open ? Render::OPEN : Render::CLOSE); + } + + if (!$open) { + return "</div>\n"; + } + + $toc = $this->createTOC( + $id, $name, $props, + isset($attrs[Reader::XMLNS_PHD]['toc-depth']) + ? (int)$attrs[Reader::XMLNS_PHD]['toc-depth'] : 1 + ); + + if ($toc) { + $toc = "<div class=\"TOC\">\n" . $toc . "</div>\n"; + } + $this->cchunk['container_chunk'] = $toc; + + return "<div class=\"{$name}\" id=\"{$id}\">"; + } + + public function format_container_chunk_title($open, $name, $attrs, $props) + { + if ($open) { + return $props["empty"] ? '' : '<h1>'; + } + $ret = ''; + if (isset($this->cchunk['container_chunk']) && $this->cchunk['container_chunk']) { + $ret = $this->cchunk['container_chunk']; + $this->cchunk['container_chunk'] = null; + } + return "</h1>\n" .$ret; + } + } http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Package/Pear/Web.php?view=markup&rev=1.1 Index: phd/phpdotnet/phd/Package/Pear/Web.php +++ phd/phpdotnet/phd/Package/Pear/Web.php <?php namespace phpdotnet\phd; class Package_Pear_Web extends Package_Pear_ChunkedXHTML { protected $formatname = "Pear-Web"; protected $title = "Pear Manual"; public function __construct() { parent::__construct(); parent::registerFormatName($this->formatname); $this->ext = "php"; } public function __destruct() { parent::close(); } /** * Add the header to this file. * * @param string $id The id of this chunk * * @return string */ public function header($id) { $ext = "." . $this->ext; $parent = Format::getParent($id); if (!$parent || $parent == "ROOT") return '<?php sendManualHeaders("UTF-8","en"); setupNavigation(array( "home" => array("index.php", "'.addslashes($this->title).'"), "prev" => array("#", ""), "next" => array("#", ""), "up" => array("#", ""), "toc" => array( array("#", "")))); manualHeader("index.php", "'.addslashes($this->title).'"); ?> '; // Fetch the siblings information $toc = array(); $siblings = Format::getChildrens($parent); foreach ($siblings as $sibling => $array) { $toc[] = array($sibling.$ext, empty($array["sdesc"]) ? $array["ldesc"] : $array["sdesc"]); } // Build the PEAR navigation table $nav = array( 'home' => array('index' . $ext, $this->title), 'prev' => $this->createPrev($id, $parent, $siblings), 'next' => $this->createNext($id, $parent, $siblings), 'up' => array($this->getFilename($parent).$ext, Format::getLongDescription($parent)), 'toc' => $toc ); return "<?php \n" . "sendManualHeaders(\"UTF-8\", \"{$this->lang}\");\n" . "setupNavigation(" . var_export($nav, true) . ");\n" . 'manualHeader("' . $this->getFilename($id).$ext . '", ' . var_export(Format::getLongDescription($id), true) . ');' . "\n" . "?>\n"; } /** * Create the footer for the given page id and return it. * * In this instance, we return raw php with the pearweb manual footer call. * * @param string $id Page ID * * @return string Footer code */ public function footer($id) { $ext = '.' . $this->ext; $parent = Format::getParent($id); return '<?php manualFooter("' . $this->getFilename($id) . $ext . '", ' . var_export(Format::getLongDescription($id), true) . '); ?>'; } /** * Create the previous page link information * * @param string $id ID of the page * @param string $parent ID of the parent element * @param array $siblings array of siblings * * @return array(0=>filename,1=>description) */ protected function createPrev($id, $parent, $siblings) { if (!isset($siblings[$id]) || $parent == 'ROOT') { return array(null, null); } $ext = '.' .$this->ext; // Seek to $id while (list($tmp,) = each($siblings)) { if ($tmp == $id) { // Set the internal pointer back to $id if (prev($siblings) === false) { end($siblings); } break; } } $tmp = prev($siblings); if ($tmp) { while (!empty($tmp["children"])) { $tmp = end($tmp["children"]); } return array( $tmp["filename"].$ext, htmlspecialchars(empty($tmp["sdesc"]) ? $tmp["ldesc"] : $tmp["sdesc"]) ); break; } return array(Format::getFilename($parent).$ext, Format::getLongDescription($parent, false)); } /** * Create the next page link information * * @param string $id ID of the page * @param string $parent ID of the parent element * @param array $siblings array of siblings * * @return array(0=>filename,1=>description) */ protected function createNext($id, $parent, $siblings) { $ext = '.' .$this->ext; $next = array(null, null); // {{{ Create the "next" link if (!empty($siblings[$id]["children"])) { $tmp = reset($siblings[$id]["children"]); return array( $tmp["filename"].$ext, htmlspecialchars(empty($tmp["sdesc"]) ? $tmp["ldesc"] : $tmp["sdesc"]) ); } do { if (!isset($siblings[$id])) { break; } // Seek to $id while (list($tmp,) = each($siblings)) { if ($tmp == $id) { break; } } $tmp = current($siblings); prev($siblings); // Reset the internal pointer to previous pos if ($tmp) { $next = array( $tmp["filename"].$ext, htmlspecialchars(empty($tmp["sdesc"]) ? $tmp["ldesc"] : $tmp["sdesc"]) ); break; } // We are the end element in this chapter $grandpa = Format::getParent($parent); if (!$grandpa || $grandpa == "ROOT") { // There is no next relative break; } $siblings = Format::getChildrens($grandpa); $id = $parent; $parent = $grandpa; } while (true); return $next; } } http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Package/Pear/ChunkedXHTML.php?view=markup&rev=1.1 Index: phd/phpdotnet/phd/Package/Pear/ChunkedXHTML.php +++ phd/phpdotnet/phd/Package/Pear/ChunkedXHTML.php <?php namespace phpdotnet\phd; class Package_Pear_ChunkedXHTML extends Package_Pear_XHTML { protected $formatname = "Pear-Chunked-XHTML"; protected $title = "Pear Manual"; public function __construct() { parent::__construct(); parent::registerFormatName($this->formatname); $this->chunked = true; } public function __destruct() { $this->close(); } public function appendData($data) { if ($this->appendToBuffer) { $this->buffer .= $data; return; } elseif ($this->flags & Render::CLOSE) { $fp = array_pop($this->fp); fwrite($fp, $data); $this->writeChunk($this->CURRENT_CHUNK, $fp); fclose($fp); $this->flags ^= Render::CLOSE; } elseif ($this->flags & Render::OPEN) { $this->fp[] = $fp = fopen("php://temp/maxmemory", "r+"); fwrite($fp, $data); $this->flags ^= Render::OPEN; } else { $fp = end($this->fp); fwrite($fp, $data); } } public function writeChunk($id, $fp) { $filename = $this->outputdir . $id . '.' .$this->ext; rewind($fp); file_put_contents($filename, $this->header($id)); file_put_contents($filename, $fp, FILE_APPEND); file_put_contents($filename, $this->footer($id), FILE_APPEND); } public function close() { foreach ($this->fp as $fp) { fclose($fp); } } public function update($event, $val = null) { switch($event) { case Render::CHUNK: $this->flags = $val; break; case Render::STANDALONE: if ($val) { $this->registerElementMap(static::getDefaultElementMap()); $this->registerTextMap(static::getDefaultTextMap()); } break; case Render::INIT: $this->outputdir = $tmp = Config::output_dir() . strtolower($this->getFormatName()) . '/'; if (file_exists($tmp)) { if (!is_dir($tmp)) { v("Output directory is a file?", E_USER_ERROR); } } else { if (!mkdir($tmp)) { v("Can't create output directory", E_USER_ERROR); } } break; case Render::VERBOSE: v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } /** * Generates the header HTML for the given ID. * Full doctype, html head, begin of body tag and top navigation. * * @param string $id Page ID * * @return string Header HTML */ public function header($id) { $title = $this->getLongDescription($id); $lang = Config::language(); $this->prev = $this->next = $this->up = array("href" => null, "desc" => null); $strPrev = $strNext = ''; if ($parentId = $this->getParent($id)) { $this->up = array("href" => $this->getFilename($parentId) . '.' .$this->ext, "desc" => htmlspecialchars($this->getShortDescription($parentId))); } if ($prevId = Format::getPrevious($id)) { $this->prev = array("href" => Format::getFilename($prevId) . '.' .$this->ext, "desc" => htmlspecialchars($this->getShortDescription($prevId))); } if ($nextId = Format::getNext($id)) { $this->next = array("href" => Format::getFilename($nextId) . '.' .$this->ext, "desc" => htmlspecialchars($this->getShortDescription($nextId))); } $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>' . $title . '</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <meta name="generator" content="PhD" /> <link rel="start" href="index.html" title="'.$this->title.'" /> '; if ($this->up["href"]) { $header .= ' <link rel="up" href="'.$this->up["href"].'" title="'.$this->up["desc"].'" /> '; } if ($this->prev["href"]) { $strPrev = '<a href="' . $this->prev["href"] . '" title="' . $this->prev["desc"] . '">Prev</a>'; $header .= ' <link rel="prev" href="' . $this->prev["href"] . '" title="' . $this->prev["desc"] . '" /> '; } if ($this->next["href"]) { $strNext = '<a href="' . $this->next["href"] . '" title="' . $this->next["desc"] . '">Next</a>'; $header .= ' <link rel="next" href="' . $this->next["href"] . '" title="' . $this->next["desc"] . '" /> '; } $header .= ' </head> <body> '; $nav = <<<NAV <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" style="text-align: center">{$title}</th></tr> <tr> <td width="40%" align="left">{$strPrev}</td> <td width="20%"></td> <td width="40%" align="right">{$strNext}</td> </tr> </table> <hr/> </div> NAV; $header .= $nav . "<div id=\"body\">\n"; return $header; } public function footer($id) { $strPrev = $strNext = $strUp = ''; if ($this->up["href"]) { $strUp = '<a accesskey="h" href="' . $this->up["href"] . '">' . $this->up["desc"] . '</a>'; } if ($this->prev["href"]) { $strPrev = '<a accesskey="p" href="' . $this->prev["href"] . '">Prev</a>'; } if ($this->next["href"]) { $strNext = '<a accesskey="n" href="' . $this->next["href"] . '">Next</a>'; } $strHome = $id !== 'index' ? '<a accesskey="h" href="index.html">'.$this->title.'</a>' : ''; $nav = <<<NAV <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left">{$strPrev}</td> <td width="20%" align="center">{$strUp}</td> <td width="40%" align="right">{$strNext}</td> </tr> <tr> <td width="40%" align="left" valign="top">{$this->prev["desc"]}</td> <td width="20%" align="center">{$strHome}</td> <td width="40%" align="right" valign="top">{$this->next["desc"]}</td> </tr> </table> </div> NAV; return "</div>\n$nav</body></html>\n"; } } ?> http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Package/Pear/CHM.php?view=markup&rev=1.1 Index: phd/phpdotnet/phd/Package/Pear/CHM.php +++ phd/phpdotnet/phd/Package/Pear/CHM.php <?php namespace phpdotnet\phd; class Package_Pear_CHM extends Package_Pear_ChunkedXHTML { const DEFAULT_FONT = "Arial,10,0"; const DEFAULT_TITLE = "PEAR Manual"; // Array to manual code -> HTML Help Code conversion // Code list: http://www.helpware.net/htmlhelp/hh_info.htm // Charset list: http://www.microsoft.com/globaldev/nlsweb/default.asp // Language code: http://www.unicode.org/unicode/onlinedat/languages.html // MIME preferred charset list: http://www.iana.org/assignments/character-sets // Font list: http://www.microsoft.com/office/ork/xp/three/inte03.htm private $LANGUAGES = array( "hk" => array( "langcode" => "0xc04 Hong Kong Cantonese", "preferred_charset" => "CP950", "mime_charset_name" => "Big5", "preferred_font" => "MingLiu,10,0" ), "tw" => array( "langcode" => "0x404 Traditional Chinese", "preferred_charset" => "CP950", "mime_charset_name" => "Big5", "preferred_font" => "MingLiu,10,0" ), "cs" => array( "langcode" => "0x405 Czech", "preferred_charset" => "Windows-1250", "mime_charset_name" => "Windows-1250", "preferred_font" => self::DEFAULT_FONT, ), "da" => array( "langcode" => "0x406 Danish", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT, "title" => "PEAR Manualen" ), "de" => array( "langcode" => "0x407 German (Germany)", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT, "title" => "PEAR Handbuch", ), "el" => array( "langcode" => "0x408 Greek", "preferred_charset" => "Windows-1253", "mime_charset_name" => "Windows-1253", "preferred_font" => self::DEFAULT_FONT ), "en" => array( "langcode" => "0x809 English (United Kingdom)", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT, "title" => "PEAR Manual", ), "es" => array( "langcode" => "0xc0a Spanish (International Sort)", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT ), "fr" => array( "langcode" => "0x40c French (France)", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT, "title" => "Manuel de PEAR" ), "fi" => array( "langcode" => "0x40b Finnish", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT ), "he" => array( "langcode" => "0x40d Hebrew", "preferred_charset" => "Windows-1255", "mime_charset_name" => "Windows-1255", "preferred_font" => self::DEFAULT_FONT ), "hu" => array( "langcode" => "0x40e Hungarian", "preferred_charset" => "Windows-1250", "mime_charset_name" => "Windows-1250", "preferred_font" => self::DEFAULT_FONT ), "it" => array( "langcode" => "0x410 Italian (Italy)", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT, "title" => "Manuale PEAR", ), "ja" => array( "langcode" => "0x411 Japanese", "preferred_charset" => "CP932", "mime_charset_name" => "csWindows31J", "preferred_font" => "MS PGothic,10,0" ), "kr" => array( "langcode" => "0x412 Korean", "preferred_charset" => "CP949", "mime_charset_name" => "EUC-KR", "preferred_font" => "Gulim,10,0" ), "nl" => array( "langcode" => "0x413 Dutch (Netherlands)", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT ), "no" => array( "langcode" => "0x414 Norwegian (Bokmal)", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT ), "pl" => array( "langcode" => "0x415 Polish", "preferred_charset" => "Windows-1250", "mime_charset_name" => "Windows-1250", "preferred_font" => self::DEFAULT_FONT ), "pt_BR" => array( "langcode" => "0x416 Portuguese (Brazil)", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT, "title" => "Manual do PEAR", ), "ro" => array( "langcode" => "0x418 Romanian", "preferred_charset" => "Windows-1250", "mime_charset_name" => "Windows-1250", "preferred_font" => self::DEFAULT_FONT ), "ru" => array( "langcode" => "0x419 Russian", "preferred_charset" => "Windows-1251", "mime_charset_name" => "Windows-1251", "preferred_font" => self::DEFAULT_FONT ), "sk" => array( "langcode" => "0x41b Slovak", "preferred_charset" => "Windows-1250", "mime_charset_name" => "Windows-1250", "preferred_font" => self::DEFAULT_FONT ), "sl" => array( "langcode" => "0x424 Slovenian", "preferred_charset" => "Windows-1250", "mime_charset_name" => "Windows-1250", "preferred_font" => self::DEFAULT_FONT ), "sv" => array( "langcode" => "0x41d Swedish", "preferred_charset" => "Windows-1252", "mime_charset_name" => "Windows-1252", "preferred_font" => self::DEFAULT_FONT ), "zh" => array( "langcode" => "0x804 Simplified Chinese", "preferred_charset" => "CP936", "mime_charset_name" => "gb2312", "preferred_font" => "simsun,10,0" ) ); // HTML Help Workshop project file protected $hhpStream; // CHM Table of contents protected $hhcStream; protected $currentTocDepth = 0; protected $lastContent = null; protected $toc; // CHM Index Map protected $hhkStream; // Project files Output directory protected $chmdir; public function __construct(array $IDs, $ext = "html", $dir = "chm") { parent::__construct($IDs, $ext); $this->chmdir = Config::output_dir() . $dir . DIRECTORY_SEPARATOR; if(!file_exists($this->chmdir) || is_file($this->chmdir)) mkdir($this->chmdir) or die("Can't create the CHM project directory"); $this->outputdir = Config::output_dir() . $dir . DIRECTORY_SEPARATOR . "res" . DIRECTORY_SEPARATOR; if(!file_exists($this->outputdir) || is_file($this->outputdir)) mkdir($this->outputdir) or die("Can't create the cache directory"); $lang = Config::language(); $this->hhpStream = fopen($this->chmdir . "pear_manual_{$lang}.hhp", "w"); $this->hhcStream = fopen($this->chmdir . "pear_manual_{$lang}.hhc", "w"); $this->hhkStream = fopen($this->chmdir . "pear_manual_{$lang}.hhk", "w"); foreach(array("reset-fonts", "style", "manual") as $name) { if (!file_exists($this->outputdir . "$name.css")) { file_put_contents($this->outputdir . "$name.css", $this->fetchStylesheet($name)); } } self::headerChm(); } public function __destruct() { self::footerChm(); fclose($this->hhpStream); fclose($this->hhcStream); fclose($this->hhkStream); parent::__destruct(); } protected function appendChm($name, $ref, $isChunk, $hasChild) { switch ($isChunk) { case Reader_Legacy::OPEN_CHUNK : $this->currentTocDepth++; fwrite($this->hhpStream, "{$ref}\n"); fwrite($this->hhcStream, "{$this->offset(1)}<li><object type=\"text/sitemap\">\n" . "{$this->offset(3)}<param name=\"Name\" value=\"" . htmlentities($name) . "\">\n" . "{$this->offset(3)}<param name=\"Local\" value=\"{$ref}\">\n" . "{$this->offset(2)}</object>\n"); if ($hasChild) fwrite($this->hhcStream, "{$this->offset(2)}<ul>\n"); fwrite($this->hhkStream, " <li><object type=\"text/sitemap\">\n" . " <param name=\"Local\" value=\"{$ref}\">\n" . " <param name=\"Name\" value=\"" . htmlentities(self::cleanIndexName($name)) . "\">\n" . " </object>\n </li>\n"); break; case Reader_Legacy::CLOSE_CHUNK : if ($hasChild) { fwrite($this->hhcStream, "{$this->offset(2)}</ul>\n"); } $this->currentTocDepth--; break; } } /** * Clean up the index name. * Newlines and double spaces don't look that good in some chm viewer apps. * * @param string $value Value to fix * * @return string Fixed/cleaned value */ protected static function cleanIndexName($value) { return str_replace( array("\n", "\r", ' '), array('', '', ' '), $value ); } protected function headerChm() { $lang = Config::language(); fwrite($this->hhpStream, '[OPTIONS] Compatibility=1.1 or later Compiled file=pear_manual_' . $lang . '.chm Contents file=pear_manual_' . $lang . '.hhc Index file=pear_manual_' . $lang . '.hhk Default Window=doc Default topic=res\index.html Display compile progress=Yes Full-text search=Yes Language=' . $this->LANGUAGES[$lang]["langcode"] . ' Title=' . ($this->LANGUAGES[$lang]["title"] ? $this->LANGUAGES[$lang]["title"] : self::DEFAULT_TITLE) . ' Default Font=' . ($this->LANGUAGES[$lang]["preferred_font"] ? $this->LANGUAGES[$lang]["preferred_font"] : self::DEFAULT_FONT). ' [WINDOWS] doc="' . ($this->LANGUAGES[$lang]["title"] ? $this->LANGUAGES[$lang]["title"] : self::DEFAULT_TITLE) . '","pear_manual_' . $lang . '.hhc","pear_manual_' . $lang . '.hhk","res\index.html","res\index.html",,,,,0x23520,,0x386e,,,,,,,,0 [FILES] res\reset-fonts.css res\style.css res\manual.css '); fwrite($this->hhcStream, '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <meta name="generator" content="PhD"> <!-- Sitemap 1.0 --> </head> <body> <object type="text/site properties"> <param name="Window Styles" value="0x800227"> </object> <ul> '); fwrite($this->hhkStream, '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html> <head> <meta name="generator" content="PhD"> <!-- Sitemap 1.0 --> </head> <body> <object type="text/site properties"> <param name="Window Styles" value="0x800227"> </object> <ul> '); } protected function footerChm() { fwrite($this->hhcStream, " </ul>\n" . " </body>\n" . "</html>\n"); fwrite($this->hhkStream, " </ul>\n" . " </body>\n" . "</html>\n"); } public function appendData($data, $isChunk) { if ($this->lastContent) $this->appendChm($this->lastContent["name"], $this->lastContent["reference"], $isChunk, $this->lastContent["hasChild"]); $this->lastContent = null; return parent::appendData($data, $isChunk); } public function format_chunk($open, $name, $attrs, $props) { $this->collectContent($attrs); return parent::format_chunk($open, $name, $attrs, $props); } public function format_container_chunk($open, $name, $attrs, $props) { $this->collectContent($attrs); return parent::format_container_chunk($open, $name, $attrs, $props); } public function format_root_chunk($open, $name, $attrs, $props) { $this->collectContent($attrs); return parent::format_root_chunk($open, $name, $attrs, $props); } /** * Generate the HTML header. * Uses parent::header() and adds some additional stylesheets. * * @param string $id Page ID * * @return string Header HTML */ public function header($id) { $header = parent::header($id); // Add CSS link to <head> $header = preg_replace('#( *)</head>#', '$1 <link media="all" rel="stylesheet" type="text/css" href="reset-fonts.css"/> $1 <link media="all" rel="stylesheet" type="text/css" href="style.css"/> $1 <link media="all" rel="stylesheet" type="text/css" href="manual.css"/> $1</head>', $header ); return $header; } private function collectContent($attrs) { if (isset($attrs[Reader_Legacy::XMLNS_XML]["id"])) { $id = $attrs[Reader_Legacy::XMLNS_XML]["id"]; $this->lastContent = array( "name" => Helper::getDescription($id), "reference" => "res\\" . (Helper::getFilename($id) ? Helper::getFilename($id) : $id) . "." . $this->ext, "hasChild" => (count(Helper::getChildren($id)) > 0) ); } } private function fetchStylesheet($name) { $stylesheet = file_get_contents("http://pear.php.net/css/$name.css"); if ($stylesheet) return $stylesheet; else { v("Stylesheet $name not fetched. Uses default rendering style.", E_USER_WARNING); return ""; } } private function offset($offset) { $spaces = ""; for ($i = 0; $i < $offset + 2 * $this->currentTocDepth; $i++) $spaces .= " "; return $spaces; } }
« previous php.doc.cvs (#4273) next »