cvs: phd / mktoc.php /themes/pear pearchunkedhtml.php peartheme.php
| From: | Christian Weiske | Date: | Thu, 16 Oct 2008 19:54:10 +0000 |
| Subject: | cvs: phd / mktoc.php /themes/pear pearchunkedhtml.php peartheme.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-2247@lists.php.net to get a copy of this message | ||
cweiske Thu Oct 16 19:54:10 2008 UTC
Modified files:
/phd mktoc.php
/phd/themes/pear pearchunkedhtml.php peartheme.php
Log:
- document mktoc a bit
- make pearchunkedhtml generate better (valid) navigation bars
- some more comments
http://cvs.php.net/viewvc.cgi/phd/mktoc.php?r1=1.13&r2=1.14&diff_format=u Index: phd/mktoc.php diff -u phd/mktoc.php:1.13 phd/mktoc.php:1.14 --- phd/mktoc.php:1.13 Fri Oct 10 07:28:58 2008 +++ phd/mktoc.php Thu Oct 16 19:54:09 2008 @@ -1,5 +1,37 @@ <?php -/* $Id: mktoc.php,v 1.13 2008/10/10 07:28:58 cweiske Exp $ */ +/** +* Creates the internal table of contents array. +* It is used to look up referenced ids and referenced names. +* +* The TOC is stored in the $ID variable. It is not saved, just generated. +* Generation works by using PhDReader to iterate over each tag, stopping at +* title (or similar) tags and chunk elements. +* Chunk element names are defined in PhDReader::OPEN_CHUNK and +* PhDReader::CLOSE_CHUNK. +* Title tags are title, titleabbrev, refname and refpurpose. +* +* IDs are taken from the xml:id="" attributes of the tags. +* +* It has the following format: +* array( +* '$id' => array( +* 'sdesc' => 'Short description (e.g. title)', +* 'ldesc' => 'Long description (e.g. titleabbrev)', +* 'children' => array('array', 'of', 'children', 'ids'), +* 'parent' => 'parent_id', +* 'filename' => 'filename for chunk' +* ), +* [..more..] +* ) +* +* This script also creates the associative $REFS array, using the normalized +* <refname> value as key and its xml:id as value. This is used in +* PhDHelper::getRefnameLink(), and allows easy refname->link resolution. +* +* @package PhD +* @version CVS: $Id: mktoc.php,v 1.14 2008/10/16 19:54:09 cweiske Exp $ +*/ + $r = new PhDReader(); $REFS = $FILENAMES = array(); $CURRENT_FILENAME = $LAST_CHUNK = ""; @@ -10,7 +42,7 @@ $lastid = 0; -while($r->read()) { +while ($r->read()) { if (!($id = $r->getID())) { $name = $r->name; if (empty($IDs[$lastid]["sdesc"])) { @@ -20,11 +52,11 @@ $REFS[$ref] = $lastid; continue; } - elseif($name == "titleabbrev") { + else if ($name == "titleabbrev") { $IDs[$lastid]["sdesc"] = trim($r->readContent($name)); continue; } - } elseif($name == "refname") { + } else if ($name == "refname") { $refname = trim($r->readContent($name)); $ref = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $refname)); $REFS[$ref] = $lastid; @@ -37,7 +69,8 @@ continue; } - switch($r->isChunk) { + + switch ($r->isChunk) { case PhDReader::OPEN_CHUNK: $CURRENT_FILENAME = $FILENAMES[] = $PARENTS[$r->depth] = $id; break; @@ -58,7 +91,12 @@ $IDs[$id] = array( "filename" => $CURRENT_FILENAME, - "parent" => $r->isChunk ? (isset($PARENTS[$r->depth-1]) ? $PARENTS[$r->depth-1] : $PARENTS[$r->depth-2]) : $CURRENT_FILENAME, + "parent" => $r->isChunk + ? (isset($PARENTS[$r->depth-1]) + ? $PARENTS[$r->depth-1] + : $PARENTS[$r->depth-2] + ) + : $CURRENT_FILENAME, "sdesc" => null, "ldesc" => null, "children" => array(), @@ -71,4 +109,3 @@ * vim600: sw=4 ts=4 fdm=syntax syntax=php et * vim<600: sw=4 ts=4 */ - http://cvs.php.net/viewvc.cgi/phd/themes/pear/pearchunkedhtml.php?r1=1.5&r2=1.6&diff_format=u Index: phd/themes/pear/pearchunkedhtml.php diff -u phd/themes/pear/pearchunkedhtml.php:1.5 phd/themes/pear/pearchunkedhtml.php:1.6 --- phd/themes/pear/pearchunkedhtml.php:1.5 Wed Oct 8 20:19:41 2008 +++ phd/themes/pear/pearchunkedhtml.php Thu Oct 16 19:54:09 2008 @@ -1,19 +1,44 @@ <?php - require_once $ROOT . '/themes/pear/pearweb.php'; -class pearchunkedhtml extends pearweb { + +/** +* PEAR theme for the normal-html-in-many-files version +* +* @package PhD +* @version CVS: $Id: pearchunkedhtml.php,v 1.6 2008/10/16 19:54:09 cweiske Exp $ +*/ +class pearchunkedhtml extends pearweb +{ private $nav = ""; - public function __construct(array $IDs, $ext = "html") { + public function __construct(array $IDs, $ext = "html") + { parent::__construct($IDs, $ext, true); $this->outputdir = PhDConfig::output_dir() . $this->ext . DIRECTORY_SEPARATOR; - if(!file_exists($this->outputdir) || is_file($this->outputdir)) mkdir($this->outputdir) or die("Can't create the cache directory"); - elseif (file_exists($this->outputdir . 'index.html')) unlink($this->outputdir . 'index.html'); // preserve back-compat + if (!file_exists($this->outputdir) || is_file($this->outputdir)) { + mkdir($this->outputdir) or die("Can't create the cache directory"); + } else if (file_exists($this->outputdir . 'index.html')) { + unlink($this->outputdir . 'index.html'); // preserve back-compat + } } - public function header($id) { + + + + /** + * 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 = PhDHelper::getDescription($id, true); $parent = PhDHelper::getParent($id); $this->next = $this->prev = $this->up = array(null, null); + $strNext = $strPrev = ''; + if ($parent && $parent != "ROOT") { $siblings = PhDHelper::getChildren($parent); $this->prev = pearweb::createPrev($id, $parent, $siblings); @@ -28,6 +53,7 @@ $this->up = array($parent.".html", PhDHelper::getDescription($parent, false)); } } + $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> @@ -36,26 +62,33 @@ <meta name="generator" content="PhD" /> <link rel="start" href="index.html" title="PEAR Manual" /> '; - if ($this->up[0]) - $header .= ' <link rel="up" href="'.$this->up[0].'" title="'.$this->up[1].'" /> + if ($this->up[0]) { + $header .= ' <link rel="up" href="'.$this->up[0].'" title="'.$this->up[1].'" /> '; - if ($this->prev[0]) - $header .= ' <link rel="prev" href="'.$this->prev[0].'" title="'.$this->prev[1].'" /> + } + if ($this->prev[0]) { + $strPrev = '<a href="' . $this->prev[0] . '">Prev</a>'; + $header .= ' <link rel="prev" href="' . $this->prev[0] . '" title="' . $this->prev[1] . '" /> '; - if ($this->next[0]) - $header .= ' <link rel="next" href="'.$this->next[0].'" title="'.$this->next[1].'" /> + } + if ($this->next[0]) { + $strNext = '<a href="' . $this->next[0] . '">Next</a>'; + $header .= ' <link rel="next" href="' . $this->next[0] . '" title="' . $this->next[1] . '" /> '; -$header .= ' </head> + } + + $header .= ' </head> <body> '; + $nav = <<<NAV <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">{$title}</th></tr> <tr> - <td width="40%" align="left"><a href="{$this->prev[0]}">Prev</a></td> + <td width="40%" align="left">{$strPrev}</td> <td width="20%"></td> - <td width="40%" align="right"><a href="{$this->next[0]}">Next</a></td> + <td width="40%" align="right">{$strNext}</td> </tr> </table> <hr/> @@ -66,16 +99,35 @@ return $header; } - public function footer($id) { - //FIXME: don't print empty links + + + /** + * Create the footer HTML for the given page id and return it. + * + * @param string $id Page ID + * + * @return string Footer HTML + */ + public function footer($id) + { + $strPrev = $strNext = $strUp = ''; + if ($this->up[0]) { + $strUp = '<a accesskey="h" href="' . $this->up[0] . '">' . $this->up[1] . '</a>'; + } + if ($this->prev[0]) { + $strPrev = '<a accesskey="p" href="' . $this->prev[0] . '">Prev</a>'; + } + if ($this->next[0]) { + $strNext = '<a accesskey="n" href="' . $this->next[0] . '">Next</a>'; + } $nav = <<<NAV <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> - <td width="40%" align="left"><a accesskey="p" href="{$this->prev[0]}">Prev</a></td> - <td width="20%" align="center"><a accesskey="h" href="{$this->up[0]}">{$this->up[1]}</a></td> - <td width="40%" align="right"><a accesskey="n" href="{$this->next[0]}">Next</a></td> + <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[1]}</td> @@ -88,9 +140,16 @@ NAV; return "</div>\n$nav</body></html>\n"; } - public function __destruct() { - if (file_exists($this->outputdir . "guide.html") && !file_exists($this->outputdir . 'index.html')) { + + + + public function __destruct() + { + if (file_exists($this->outputdir . "guide.html") + && !file_exists($this->outputdir . 'index.html') + ) { copy($this->outputdir . "guide.html", $this->outputdir . "index.html"); } } + } http://cvs.php.net/viewvc.cgi/phd/themes/pear/peartheme.php?r1=1.8&r2=1.9&diff_format=u Index: phd/themes/pear/peartheme.php diff -u phd/themes/pear/peartheme.php:1.8 phd/themes/pear/peartheme.php:1.9 --- phd/themes/pear/peartheme.php:1.8 Wed Oct 8 21:17:15 2008 +++ phd/themes/pear/peartheme.php Thu Oct 16 19:54:09 2008 @@ -6,7 +6,10 @@ 'article' => 'format_container_chunk', 'answer' => 'format_answer', 'appendix' => 'format_container_chunk', - 'author' => 'format_suppressed_tags', + 'author' => array( + /* DEFAULT */ 'format_editedby', + 'authorgroup' => 'format_suppressed_tags', + ), 'authorgroup' => 'format_editedby', 'bibliography' => array( /* DEFAULT */ false, @@ -122,7 +125,7 @@ 'warning' => 'format_warning_para', ), 'subtitle' => 'format_subtitle', - 'surname' => 'format_suppressed_tags', + 'surname' => 'format_surname', 'synopsis' => 'format_programlisting', 'table' => 'format_table', 'title' => array( @@ -481,6 +484,11 @@ return ""; } + public function format_surname($open, $name, $attrs) { + /* Add a space before it, so firstname and surname are separated */ + return ' '; + } + public function format_subtitle($open, $name, $attrs) { if ($open) return '<p><font color="red">';
http://cvs.php.net/viewvc.cgi/phd/mktoc.php?r1=1.13&r2=1.14&diff_format=u Index: phd/mktoc.php diff -u phd/mktoc.php:1.13 phd/mktoc.php:1.14 --- phd/mktoc.php:1.13 Fri Oct 10 07:28:58 2008 +++ phd/mktoc.php Thu Oct 16 19:54:09 2008 @@ -1,5 +1,37 @@ <?php -/* $Id: mktoc.php,v 1.13 2008/10/10 07:28:58 cweiske Exp $ */ +/** +* Creates the internal table of contents array. +* It is used to look up referenced ids and referenced names. +* +* The TOC is stored in the $ID variable. It is not saved, just generated. +* Generation works by using PhDReader to iterate over each tag, stopping at +* title (or similar) tags and chunk elements. +* Chunk element names are defined in PhDReader::OPEN_CHUNK and +* PhDReader::CLOSE_CHUNK. +* Title tags are title, titleabbrev, refname and refpurpose. +* +* IDs are taken from the xml:id="" attributes of the tags. +* +* It has the following format: +* array( +* '$id' => array( +* 'sdesc' => 'Short description (e.g. title)', +* 'ldesc' => 'Long description (e.g. titleabbrev)', +* 'children' => array('array', 'of', 'children', 'ids'), +* 'parent' => 'parent_id', +* 'filename' => 'filename for chunk' +* ), +* [..more..] +* ) +* +* This script also creates the associative $REFS array, using the normalized +* <refname> value as key and its xml:id as value. This is used in +* PhDHelper::getRefnameLink(), and allows easy refname->link resolution. +* +* @package PhD +* @version CVS: $Id: mktoc.php,v 1.14 2008/10/16 19:54:09 cweiske Exp $ +*/ + $r = new PhDReader(); $REFS = $FILENAMES = array(); $CURRENT_FILENAME = $LAST_CHUNK = ""; @@ -10,7 +42,7 @@ $lastid = 0; -while($r->read()) { +while ($r->read()) { if (!($id = $r->getID())) { $name = $r->name; if (empty($IDs[$lastid]["sdesc"])) { @@ -20,11 +52,11 @@ $REFS[$ref] = $lastid; continue; } - elseif($name == "titleabbrev") { + else if ($name == "titleabbrev") { $IDs[$lastid]["sdesc"] = trim($r->readContent($name)); continue; } - } elseif($name == "refname") { + } else if ($name == "refname") { $refname = trim($r->readContent($name)); $ref = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $refname)); $REFS[$ref] = $lastid; @@ -37,7 +69,8 @@ continue; } - switch($r->isChunk) { + + switch ($r->isChunk) { case PhDReader::OPEN_CHUNK: $CURRENT_FILENAME = $FILENAMES[] = $PARENTS[$r->depth] = $id; break; @@ -58,7 +91,12 @@ $IDs[$id] = array( "filename" => $CURRENT_FILENAME, - "parent" => $r->isChunk ? (isset($PARENTS[$r->depth-1]) ? $PARENTS[$r->depth-1] : $PARENTS[$r->depth-2]) : $CURRENT_FILENAME, + "parent" => $r->isChunk + ? (isset($PARENTS[$r->depth-1]) + ? $PARENTS[$r->depth-1] + : $PARENTS[$r->depth-2] + ) + : $CURRENT_FILENAME, "sdesc" => null, "ldesc" => null, "children" => array(), @@ -71,4 +109,3 @@ * vim600: sw=4 ts=4 fdm=syntax syntax=php et * vim<600: sw=4 ts=4 */ - http://cvs.php.net/viewvc.cgi/phd/themes/pear/pearchunkedhtml.php?r1=1.5&r2=1.6&diff_format=u Index: phd/themes/pear/pearchunkedhtml.php diff -u phd/themes/pear/pearchunkedhtml.php:1.5 phd/themes/pear/pearchunkedhtml.php:1.6 --- phd/themes/pear/pearchunkedhtml.php:1.5 Wed Oct 8 20:19:41 2008 +++ phd/themes/pear/pearchunkedhtml.php Thu Oct 16 19:54:09 2008 @@ -1,19 +1,44 @@ <?php - require_once $ROOT . '/themes/pear/pearweb.php'; -class pearchunkedhtml extends pearweb { + +/** +* PEAR theme for the normal-html-in-many-files version +* +* @package PhD +* @version CVS: $Id: pearchunkedhtml.php,v 1.6 2008/10/16 19:54:09 cweiske Exp $ +*/ +class pearchunkedhtml extends pearweb +{ private $nav = ""; - public function __construct(array $IDs, $ext = "html") { + public function __construct(array $IDs, $ext = "html") + { parent::__construct($IDs, $ext, true); $this->outputdir = PhDConfig::output_dir() . $this->ext . DIRECTORY_SEPARATOR; - if(!file_exists($this->outputdir) || is_file($this->outputdir)) mkdir($this->outputdir) or die("Can't create the cache directory"); - elseif (file_exists($this->outputdir . 'index.html')) unlink($this->outputdir . 'index.html'); // preserve back-compat + if (!file_exists($this->outputdir) || is_file($this->outputdir)) { + mkdir($this->outputdir) or die("Can't create the cache directory"); + } else if (file_exists($this->outputdir . 'index.html')) { + unlink($this->outputdir . 'index.html'); // preserve back-compat + } } - public function header($id) { + + + + /** + * 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 = PhDHelper::getDescription($id, true); $parent = PhDHelper::getParent($id); $this->next = $this->prev = $this->up = array(null, null); + $strNext = $strPrev = ''; + if ($parent && $parent != "ROOT") { $siblings = PhDHelper::getChildren($parent); $this->prev = pearweb::createPrev($id, $parent, $siblings); @@ -28,6 +53,7 @@ $this->up = array($parent.".html", PhDHelper::getDescription($parent, false)); } } + $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> @@ -36,26 +62,33 @@ <meta name="generator" content="PhD" /> <link rel="start" href="index.html" title="PEAR Manual" /> '; - if ($this->up[0]) - $header .= ' <link rel="up" href="'.$this->up[0].'" title="'.$this->up[1].'" /> + if ($this->up[0]) { + $header .= ' <link rel="up" href="'.$this->up[0].'" title="'.$this->up[1].'" /> '; - if ($this->prev[0]) - $header .= ' <link rel="prev" href="'.$this->prev[0].'" title="'.$this->prev[1].'" /> + } + if ($this->prev[0]) { + $strPrev = '<a href="' . $this->prev[0] . '">Prev</a>'; + $header .= ' <link rel="prev" href="' . $this->prev[0] . '" title="' . $this->prev[1] . '" /> '; - if ($this->next[0]) - $header .= ' <link rel="next" href="'.$this->next[0].'" title="'.$this->next[1].'" /> + } + if ($this->next[0]) { + $strNext = '<a href="' . $this->next[0] . '">Next</a>'; + $header .= ' <link rel="next" href="' . $this->next[0] . '" title="' . $this->next[1] . '" /> '; -$header .= ' </head> + } + + $header .= ' </head> <body> '; + $nav = <<<NAV <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">{$title}</th></tr> <tr> - <td width="40%" align="left"><a href="{$this->prev[0]}">Prev</a></td> + <td width="40%" align="left">{$strPrev}</td> <td width="20%"></td> - <td width="40%" align="right"><a href="{$this->next[0]}">Next</a></td> + <td width="40%" align="right">{$strNext}</td> </tr> </table> <hr/> @@ -66,16 +99,35 @@ return $header; } - public function footer($id) { - //FIXME: don't print empty links + + + /** + * Create the footer HTML for the given page id and return it. + * + * @param string $id Page ID + * + * @return string Footer HTML + */ + public function footer($id) + { + $strPrev = $strNext = $strUp = ''; + if ($this->up[0]) { + $strUp = '<a accesskey="h" href="' . $this->up[0] . '">' . $this->up[1] . '</a>'; + } + if ($this->prev[0]) { + $strPrev = '<a accesskey="p" href="' . $this->prev[0] . '">Prev</a>'; + } + if ($this->next[0]) { + $strNext = '<a accesskey="n" href="' . $this->next[0] . '">Next</a>'; + } $nav = <<<NAV <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> - <td width="40%" align="left"><a accesskey="p" href="{$this->prev[0]}">Prev</a></td> - <td width="20%" align="center"><a accesskey="h" href="{$this->up[0]}">{$this->up[1]}</a></td> - <td width="40%" align="right"><a accesskey="n" href="{$this->next[0]}">Next</a></td> + <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[1]}</td> @@ -88,9 +140,16 @@ NAV; return "</div>\n$nav</body></html>\n"; } - public function __destruct() { - if (file_exists($this->outputdir . "guide.html") && !file_exists($this->outputdir . 'index.html')) { + + + + public function __destruct() + { + if (file_exists($this->outputdir . "guide.html") + && !file_exists($this->outputdir . 'index.html') + ) { copy($this->outputdir . "guide.html", $this->outputdir . "index.html"); } } + } http://cvs.php.net/viewvc.cgi/phd/themes/pear/peartheme.php?r1=1.8&r2=1.9&diff_format=u Index: phd/themes/pear/peartheme.php diff -u phd/themes/pear/peartheme.php:1.8 phd/themes/pear/peartheme.php:1.9 --- phd/themes/pear/peartheme.php:1.8 Wed Oct 8 21:17:15 2008 +++ phd/themes/pear/peartheme.php Thu Oct 16 19:54:09 2008 @@ -6,7 +6,10 @@ 'article' => 'format_container_chunk', 'answer' => 'format_answer', 'appendix' => 'format_container_chunk', - 'author' => 'format_suppressed_tags', + 'author' => array( + /* DEFAULT */ 'format_editedby', + 'authorgroup' => 'format_suppressed_tags', + ), 'authorgroup' => 'format_editedby', 'bibliography' => array( /* DEFAULT */ false, @@ -122,7 +125,7 @@ 'warning' => 'format_warning_para', ), 'subtitle' => 'format_subtitle', - 'surname' => 'format_suppressed_tags', + 'surname' => 'format_surname', 'synopsis' => 'format_programlisting', 'table' => 'format_table', 'title' => array( @@ -481,6 +484,11 @@ return ""; } + public function format_surname($open, $name, $attrs) { + /* Add a space before it, so firstname and surname are separated */ + return ' '; + } + public function format_subtitle($open, $name, $attrs) { if ($open) return '<p><font color="red">';