cvs: phd(PHD_ENTERPRISE) / README build.php render.php /formats bigxhtml.php php.php xhtml.php /include PhDConfig.class.php PhDFormat.class.php
PhDIndex.class.php PhDObjectStorage.class.php PhDReader.class.php PhDRender.class.php /themes/php phpdotnet.php
| From: | Hannes Magnusson | Date: | Mon, 28 Jul 2008 22:40:57 +0000 |
| Subject: | cvs: phd(PHD_ENTERPRISE) / README build.php render.php /formats bigxhtml.php php.php xhtml.php /include PhDConfig.class.php PhDFormat.class.php PhDIndex.class.php PhDObjectStorage.class.php PhDReader.class.php PhDRender.class.php /themes/php phpdotnet.php |
||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-1946@lists.php.net to get a copy of this message | ||
bjori Mon Jul 28 22:40:57 2008 UTC
Added files: (Branch: PHD_ENTERPRISE)
/phd/formats bigxhtml.php
/phd/include PhDConfig.class.php PhDIndex.class.php
PhDObjectStorage.class.php PhDRender.class.php
Removed files:
/phd build.php
Modified files:
/phd render.php README
/phd/formats php.php xhtml.php
/phd/include PhDFormat.class.php PhDReader.class.php
/phd/themes/php phpdotnet.php
Log:
Initial commit of Enterprise PhD 2.0 XP, build#1337
http://cvs.php.net/viewvc.cgi/phd/render.php?r1=1.1&r2=1.2&diff_format=u Index: phd/render.php diff -u /dev/null phd/render.php:1.2 --- /dev/null Mon Jul 28 22:40:57 2008 +++ phd/render.php Mon Jul 28 22:40:56 2008 @@ -0,0 +1,73 @@ +<?php + +require "include/PhDObjectStorage.class.php"; +require "include/PhDConfig.class.php"; + +require "include/PhDReader.class.php"; +require "include/PhDRender.class.php"; +require "include/PhDFormat.class.php"; +require "include/PhDIndex.class.php"; + +require "formats/xhtml.php"; +require "formats/bigxhtml.php"; +require "formats/php.php"; + +$INDEX = "/home/bjori/php/doc/.manual.xml"; +$FILENAME = "/home/bjori/php/doc/.manual.xml"; +//$INDEX = $FILENAME = "/home/bjori/php/cleandocs/json.xml"; +define("NO_SQLITE", false); + +PhDConfig::init(array( + "verbose" => VERBOSE_ALL^(VERBOSE_PARTIAL_CHILD_READING|VERBOSE_CHUNK_WRITING), + "lang_dir" => __DIR__ . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "langs" . DIRECTORY_SEPARATOR, + "output_dir" => __DIR__ . DIRECTORY_SEPARATOR . "output" . DIRECTORY_SEPARATOR, + + "phpweb_version_filename" => dirname($FILENAME) . DIRECTORY_SEPARATOR . 'phpbook' . DIRECTORY_SEPARATOR . 'phpbook-xsl/' . 'version.xml', + "phpweb_acronym_filename" => dirname($FILENAME) . DIRECTORY_SEPARATOR . 'entities' . DIRECTORY_SEPARATOR . 'acronyms.xml', +)); + +$render = new PhDRender(); + +$reader = new PhDReader(); + +foreach(range(0, 0) as $i) { + var_dump(date(DATE_RSS)); + + if (1) { + // Create indexer + $format = new PhDIndex(); + $render->attach($format); + + $reader->open($INDEX); + $render->render($reader); + + $format->commit(); + $render->detach($format); + + var_dump(date(DATE_RSS)); + } + + // Standalone phpweb Format + $xhtml = new PhDPHPFormat(); + $render->attach($xhtml); + + /* + // Standalone Chunked xHTML Format + $xhtml = new PhDXHTMLFormat(); + $render->attach($xhtml); + + // Use the markup from the Chunked xHTML Format to produce Big xHTML + $bightml = new PhDBigXHTMLFormat(); + $xhtml->attach($bightml); + + // Standalone Big xHTML Format + $bightml = new PhDBigXHTMLFormat(); + $render->attach($bightml); + */ +} + +foreach(range(0, 0) as $i) { + $reader->open($FILENAME); + $render->render($reader); +} + http://cvs.php.net/viewvc.cgi/phd/README?r1=1.9&r2=1.9.6.1&diff_format=u Index: phd/README diff -u phd/README:1.9 phd/README:1.9.6.1 --- phd/README:1.9 Sat May 3 15:14:21 2008 +++ phd/README Mon Jul 28 22:40:56 2008 @@ -1,13 +1,13 @@ PhD - PHP DocBook Copyright(c) 2007-2008 The PHP Documentation Team All Rights Reserved. -$Id: README,v 1.9 2008/05/03 15:14:21 bjori Exp $ +$Id: README,v 1.9.6.1 2008/07/28 22:40:56 bjori Exp $ At the moment, the code depends upon the following: - PHP 5.2.3 or later. PHP 5.3 is recommended. PHP 6 is unsupported, but might work. - An available CLI binary. - - DOM, libXML2, and xmlreader. + - DOM, libXML2 (20620 or greater), and xmlreader. Installing the PhD renderer: http://cvs.php.net/viewvc.cgi/phd/formats/php.php?r1=1.2&r2=1.3&diff_format=u Index: phd/formats/php.php diff -u /dev/null phd/formats/php.php:1.3 --- /dev/null Mon Jul 28 22:40:57 2008 +++ phd/formats/php.php Mon Jul 28 22:40:57 2008 @@ -0,0 +1,356 @@ +<?php +class PhDPHPFormat extends PhDXHTMLFormat { + private $myelementmap = array( + 'acronym' => 'format_suppressed_tags', + 'function' => 'format_suppressed_tags', + 'link' => 'format_link', + 'refpurpose' => 'format_refpurpose', + 'varname' => array( + /* DEFAULT */ 'var', + 'fieldsynopsis' => 'format_fieldsynopsis_varname', + ), + 'xref' => 'format_xref', + + + '.title' => array( + /* DEFAULT */ false, + 'info' => array( + /* DEFAULT */ false, + 'article' => 'format_container_chunk_top_title', + 'appendix' => 'format_container_chunk_top_title', + 'book' => 'format_container_chunk_top_title', + 'chapter' => 'format_container_chunk_top_title', + 'part' => 'format_container_chunk_top_title', + 'set' => 'format_container_chunk_top_title', + ), + 'article' => 'format_container_chunk_top_title', + 'appendix' => 'format_container_chunk_top_title', + 'book' => 'format_container_chunk_top_title', + 'chapter' => 'format_container_chunk_top_title', + 'part' => 'format_container_chunk_top_title', + 'set' => 'format_container_chunk_top_title', + ), + '.reference' => 'format_container_chunk_below', + '.question' => array( + /* DEFAULT */ false, + 'questions' => 'format_phd_question', // From the PhD namespace + ), + ); + private $mytextmap = array( + 'acronym' => 'format_acronym_text', + 'function' => 'format_function_text', + 'methodname' => array( + /* DEFAULT */ 'format_function_text', + 'constructorsynopsis' => array( + /* DEFAULT */ 'format_function_text', + 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', + ), + 'methodsynopsis' => array( + /* DEFAULT */ 'format_function_text', + 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', + ), + 'destructorsynopsis' => array( + /* DEFAULT */ 'format_function_text', + 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', + ), + ), + + 'refname' => 'format_refname_text', + 'type' => array( + /* DEFAULT */ 'format_type_text', + 'classsynopsisinfo' => false, + 'fieldsynopsis' => 'format_type_if_object_or_pseudo_text', + 'methodparam' => 'format_type_if_object_or_pseudo_text', + 'methodsynopsis' => array( + /* DEFAULT */ 'format_type_if_object_or_pseudo_text', + 'classsynopsis' => false, + ), + ), + + ); + protected $flags; + protected $ext = "php"; + private $acronyms = array(); + private $versions = array(); + private $refname = ""; + + public function __construct() { + parent::__construct(); + $this->versions = self::generateVersionInfo(PhDConfig::get("phpweb_version_filename")); + $this->acronyms = self::generateAcronymInfo(PhDConfig::get("phpweb_acronym_filename")); + + } + + public function header($id) { + /* Yes. This is scary. I know. */ + return '<?php +include_once $_SERVER[\'DOCUMENT_ROOT\'] . \'/include/shared-manual.inc\'; +$setup = array( + "home" => array("index.php", "PHP Manual"), + "head" => array("UTF-8", "en"), + "this" => array(null, null), + "up" => array(null, null), + "prev" => array(null, null), + "next" => array(null, null), + "toc" => array(), + "parents" => array(), +); +manual_setup($setup); + +manual_header(); +?> +'; + } + public function footer($id) { + return "<?php manual_footer(); ?>"; + } + + + public function getDefaultElementMap() { + return $this->myelementmap; + } + public function getDefaultTextMap() { + return $this->mytextmap; + } + + + public function format_suppressed_tags($open, $name, $attrs, $props) { + return ""; + } + public function update($event, $val = null) { + switch($event) { + case PhDRender::CHUNK: + $this->flags = $val; + break; + + case PhDRender::STANDALONE: + if ($val) { + $this->registerElementMap(array_merge(parent::getDefaultElementMap(), static::getDefaultElementMap())); + $this->registerTextMap(array_merge(parent::getDefaultTextMap(), static::getDefaultTextMap())); + } else { + $this->registerElementMap(static::getDefaultElementMap()); + $this->registerTextMap(static::getDefaultTextMap()); + } + break; + } + } + public function format_suppressed_text($value, $tag) { + return ""; + } + + protected function lookupRefname($for) { + return $this->refs[$for]; + return NO_SQLITE; + $rsl = sqlite_array_query($this->sqlite, "SELECT filename, ldesc, sdesc FROM ids WHERE sdesc='$for' AND element='refentry'", SQLITE_ASSOC); + if (isset($rsl[0])) { + return $rsl[0]["filename"]; + } + return false; + } + public static function generateVersionInfo($filename) { + static $info; + if ($info) { + return $info; + } + $r = new XMLReader; + if (!$r->open($filename)) { + throw new Exception; + } + $versions = array(); + while($r->read()) { + if ( + $r->moveToAttribute("name") + && ($funcname = str_replace( + array("::", "->", "__", "_", '$'), + array("-", "-", "-", "-", ""), + $r->value)) + && $r->moveToAttribute("from") + && ($from = $r->value) + ) { + $versions[strtolower($funcname)] = $from; + $r->moveToElement(); + } + } + $r->close(); + $info = $versions; + return $versions; + } + public static function generateAcronymInfo($filename) { + static $info; + if ($info) { + return $info; + } + $r = new XMLReader; + if (!$r->open($filename)) { + throw new Exception("Could not open $filename"); + } + $acronyms = array(); + while ($r->read()) { + if ($r->nodeType != XMLReader::ELEMENT) { + continue; + } + if ($r->name == "term") { + $r->read(); + $k = $r->value; + $acronyms[$k] = ""; + } else if ($r->name == "simpara") { + $r->read(); + $acronyms[$k] = $r->value; + } + } + $info = $acronyms; + return $acronyms; + } + public function versionInfo($funcname) { + $funcname = str_replace( + array("::", "->", "__", "_", '$', '()'), + array("-", "-", "-", "-", "", ''), + strtolower($funcname)); + return isset($this->versions[$funcname]) ? $this->versions[$funcname] : "No version information available, might be only in CVS"; + } + public function acronymInfo($acronym) { + return isset($this->acronyms[$acronym]) ? $this->acronyms[$acronym] : false; + } + + + public function format_acronym_text($value, $tag) { + $resolved = $this->acronymInfo($value); + if ($resolved) { + return '<acronym title="' .$resolved. '">' .$value. '</acronym>'; + } + return '<acronym>'.$value.'</acronym>'; + } + public function format_refpurpose($open, $tag, $attrs, $props) { + if ($open) { + return '<p class="verinfo">(' .(htmlspecialchars($this->versionInfo($this->refname), ENT_QUOTES, "UTF-8")). ')</p><p class="refpurpose dc-title">'. $this->refname. ' â '; + } + return "</p>\n"; + } + public function format_fieldsynopsis_varname($open, $name, $attrs) { + if ($open) { + $href = ""; + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { + $href = $this->createLink($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"]); + + $href = '<a href="' .$href. '">'; + } + if ($this->cchunk["fieldsynopsis"]["modifier"] == "const") { + return '<var class="fieldsynopsis_varname">'.$href; + } + return '<var class="'.$name.'">'.$href.'$'; + } + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { + return '</a></var>'; + } + return '</var>'; + } + + + public function format_refname_text($value, $tag) { + $this->refname = $value; + return false; + } + public function format_function_text($value, $tag, $display_value = null) { + if ($display_value === null) { + $display_value = $value; + } + + $ref = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $value)); + + $filename = $this->lookupRefname($ref); + + if (($filename !== false) && $this->CURRENT_CHUNK !== $filename) { + $desc = ""; + $href = $this->createLink($filename, $desc); + return '<a href="' . $href . '" class="function" title="' . $desc . '">' . $display_value . ($tag == "function" ? "()" : ""). '</a>'; + } + return '<strong>' . $display_value . ($tag === "function" ? "()" : ""). '</strong>'; + } + public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag) { + $value = $this->TEXT($value); + if ($this->cchunk["classsynopsis"]["classname"] === false) { + return $this->format_function_text($value, $tag); + } + if (strpos($value, '::')) { + $explode = '::'; + } elseif (strpos($value, '->')) { + $explode = '->'; + } else { + return $this->format_function_text($value, $tag); + } + + list($class, $method) = explode($explode, $value); + if ($class !== $this->cchunk["classsynopsis"]["classname"]) { + return $this->format_function_text($value, $tag); + } + return $this->format_function_text($value, $tag, $method); + } + public function format_type_if_object_or_pseudo_text($value, $tag) { + if (in_array(strtolower($value), array("bool", "int", "double", "boolean", "integer", "float", "string", "array", "object", "resource", "null"))) { + return false; + } + return self::format_type_text($value, $tag); + } + public function format_type_text($value, $tag) { + $t = strtolower($value); + + switch($t) { + case "bool": + $id = "language.types.boolean"; + break; + + case "int": + case "long": + $id = "language.types.integer"; + break; + + case "double": + $id = "language.types.float"; + break; + + /* FIXME: These aren't documented yet */ + case "binary": + case "unicode": + $id = "language.types.string"; + break; + + case "void": + case "boolean": + case "integer": + case "float": + case "string": + case "array": + case "object": + case "resource": + case "null": + $id = "language.types.$t"; + break; + + case "mixed": + case "number": + case "callback": + $id = "language.types.$t"; + break; + + default: + /* Check if its a classname. */ + $t = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $t)); + $id = "class.$t"; + } + + $desc = ""; + $href = $this->createLink($id, $desc); + + if ($href) { + return '<a href="' .$href. '" class="' .$tag. ' ' .$value. '" title="' . $desc . '">' .$value. '</a>'; + } + return '<span class="' .$tag. ' ' .$value. '">' .$value. '</span>'; + } + +} + +/* + * vim600: sw=4 ts=4 fdm=syntax syntax=php et + * vim<600: sw=4 ts=4 + */ + http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.68&r2=1.68.2.1&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.68 phd/formats/xhtml.php:1.68.2.1 --- phd/formats/xhtml.php:1.68 Wed Jul 9 22:57:06 2008 +++ phd/formats/xhtml.php Mon Jul 28 22:40:57 2008 @@ -1,20 +1,19 @@ <?php -/* $Id: xhtml.php,v 1.68 2008/07/09 22:57:06 loudi Exp $ */ - -class XHTMLPhDFormat extends PhDFormat { - protected $elementmap = array( /* {{{ */ +/* $Id: xhtml.php,v 1.68.2.1 2008/07/28 22:40:57 bjori Exp $ */ +class PhDXHTMLFormat extends PhDFormat { + private $myelementmap = array( /* {{{ */ 'abstract' => 'div', /* Docbook-xsl prints "abstract"... */ 'abbrev' => 'abbr', 'acronym' => 'acronym', 'affiliation' => 'format_suppressed_tags', 'alt' => 'format_suppressed_tags', - 'article' => 'format_container_chunk', + 'article' => 'format_container_chunk_top', 'author' => array( /* DEFAULT */ 'format_author', 'authorgroup' => 'format_authorgroup_author', ), 'authorgroup' => 'div', - 'appendix' => 'format_container_chunk', + 'appendix' => 'format_container_chunk_top', 'application' => 'span', 'blockquote' => 'blockquote', 'bibliography' => array( @@ -23,14 +22,15 @@ 'book' => 'format_chunk', 'part' => 'format_chunk', ), - 'book' => 'format_container_chunk', - 'chapter' => 'format_container_chunk', + 'book' => 'format_container_chunk_top', + 'chapter' => 'format_container_chunk_top', 'citetitle' => 'i', 'co' => 'format_co', 'colophon' => 'format_chunk', 'copyright' => 'format_copyright', 'date' => 'p', 'editor' => 'format_editor', + 'function' => 'b', 'email' => 'format_suppressed_tags', 'firstname' => 'format_name', 'footnote' => 'format_footnote', @@ -127,7 +127,7 @@ 'indexentry' => 'dd', 'initializer' => 'format_initializer', 'itemizedlist' => 'ul', - 'legalnotice' => 'format_legalnotice_chunk', + 'legalnotice' => 'format_chunk', 'listitem' => array( /* DEFAULT */ 'li', 'varlistentry' => 'format_varlistentry_listitem', @@ -135,6 +135,8 @@ 'link' => 'a', 'literal' => 'format_literal', 'literallayout' => 'pre', + 'link' => 'format_link', + 'xref' => 'format_xref', 'manvolnum' => 'format_manvolnum', 'mediaobject' => 'format_mediaobject', 'methodparam' => 'format_methodparam', @@ -162,13 +164,14 @@ 'note' => 'format_note_content', 'footnote' => 'format_footnote_para', 'refsect1' => 'format_refsect1_para', + 'question' => 'format_suppressed_tags', ), 'paramdef' => 'format_suppressed_tags', 'parameter' => array( /* DEFAULT */ 'format_parameter', 'methodparam' => 'format_methodparam_parameter', ), - 'part' => 'format_container_chunk', + 'part' => 'format_container_chunk_top', 'partintro' => 'div', 'personname' => 'format_personname', 'personblurb' => 'div', @@ -188,7 +191,8 @@ 'pubdate' => 'div', /* Docbook-XSL prints "published" */ 'refentry' => 'format_chunk', 'refentrytitle' => 'span', - 'reference' => 'format_container_chunk', + 'refpurpose' => 'p', + 'reference' => 'format_container_chunk_below', 'refsect1' => 'format_refsect', 'refsect2' => 'format_refsect', 'refsect3' => 'format_refsect', @@ -199,17 +203,35 @@ 'replaceable' => 'span', 'row' => 'format_row', 'screen' => 'format_screen', - 'sect1' => 'format_chunk', - 'sect2' => 'format_chunk', - 'sect3' => 'format_chunk', - 'sect4' => 'format_chunk', - 'sect5' => 'format_chunk', - 'section' => 'format_chunk', + 'sect1' => 'format_section_chunk', + 'sect2' => 'div', + 'sect3' => 'div', + 'sect4' => 'div', + 'sect5' => 'div', + 'section' => array( + /* DEFAULT */ 'div', + 'sect1' => 'format_section_chunk', + 'preface' => 'format_section_chunk', + 'chapter' => 'format_section_chunk', + 'appendix' => 'format_section_chunk', + 'article' => 'format_section_chunk', + 'part' => 'format_section_chunk', + 'reference' => 'format_section_chunk', + 'refentry' => 'format_section_chunk', + 'index' => 'format_section_chunk', + 'bibliography' => 'format_section_chunk', + 'glossary' => 'format_section_chunk', + 'colopone' => 'format_section_chunk', + 'book' => 'format_section_chunk', + 'set' => 'format_section_chunk', + 'setindex' => 'format_section_chunk', + 'legalnotice' => 'format_section_chunk', + ), 'seg' => 'format_seg', 'segmentedlist' => 'format_segmentedlist', 'seglistitem' => 'format_seglistitem', 'segtitle' => 'format_suppressed_tags', - 'set' => 'format_chunk', + 'set' => 'format_container_chunk_top', 'setindex' => 'format_chunk', 'shortaffil' => 'format_suppressed_tags', 'simplelist' => 'ul', /* FIXME: simplelists has few attributes that need to be implemented */ @@ -237,14 +259,22 @@ 'tip' => 'format_admonition', 'title' => array( /* DEFAULT */ 'h1', - 'example' => 'format_bold_paragraph', + 'example' => 'format_example_title', 'formalpara' => 'h5', 'info' => array( /* DEFAULT */ 'h1', - 'example' => 'format_bold_paragraph', + 'example' => 'format_example_title', 'note' => 'format_note_title', 'table' => 'format_table_title', 'informaltable' => 'format_table_title', + + 'article' => 'format_container_chunk_top_title', + 'appendix' => 'format_container_chunk_top_title', + 'book' => 'format_container_chunk_top_title', + 'chapter' => 'format_container_chunk_top_title', + 'part' => 'format_container_chunk_top_title', + 'set' => 'format_container_chunk_top_title', + ), 'indexdiv' => 'dt', 'legalnotice' => 'h4', @@ -261,7 +291,13 @@ 'segmentedlist' => 'strong', 'table' => 'format_table_title', 'variablelist' => 'strong', - ), + 'article' => 'format_container_chunk_top_title', + 'appendix' => 'format_container_chunk_top_title', + 'book' => 'format_container_chunk_top_title', + 'chapter' => 'format_container_chunk_top_title', + 'part' => 'format_container_chunk_top_title', + 'set' => 'format_container_chunk_top_title', + ), 'titleabbrev' => 'format_suppressed_tags', 'type' => 'span', 'userinput' => 'format_userinput', @@ -276,13 +312,16 @@ 'xref' => 'a', 'year' => 'span', 'quote' => 'format_quote', - 'qandadiv' => 'div', - 'qandaset' => 'div', + 'qandaset' => 'format_qandaset', 'qandaentry' => 'dl', - 'question' => 'dt', + 'question' => array( + /* DEFAULT */ 'format_question', + 'questions' => 'format_phd_question', // From the PhD namespace + ), + 'questions' => 'ol', // From the PhD namespace 'answer' => 'dd', ); /* }}} */ - protected $textmap = array( + private $mytextmap = array( 'segtitle' => 'format_segtitle_text', 'affiliation' => 'format_suppressed_text', 'contrib' => 'format_suppressed_text', @@ -301,21 +340,6 @@ 'classsynopsis' => 'format_classsynopsis_ooclass_classname_text', ), ), - 'methodname' => array( - /* DEFAULT */ false, - 'constructorsynopsis' => array( - /* DEFAULT */ false, - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - 'methodsynopsis' => array( - /* DEFAULT */ false, - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - 'destructorsynopsis' => array( - /* DEFAULT */ false, - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - ), 'para' => array( /* DEFAULT */ false, 'footnote' => 'format_footnote_para_text', @@ -347,6 +371,7 @@ "implements" => false, "ooclass" => false, ), + "examples" => 0, "fieldsynopsis" => array( "modifier" => "public", ), @@ -367,16 +392,13 @@ "tablefootnotes" => array( ), ); - - public function __construct(array $IDs) { - parent::__construct($IDs); - } - public function __call($func, $args) { - if ($args[0]) { - trigger_error("No mapper found for '{$func}'", E_USER_WARNING); - return "<font color='red' size='+3'>{$args[1]}</font>"; - } - return "<font color='red' size='+3'>/{$args[1]}</font>"; + + protected $flags; + protected $ext = "html"; + protected $fp = array(); + + public function __construct() { + parent::__construct(); } public function transformFromMap($open, $tag, $name, $attrs, $props) { if ($open) { @@ -389,6 +411,168 @@ } return '</' .$tag. '>'; } + + public function appendData($data) { + if ($this->flags & PhDRender::CLOSE) { + $fp = array_pop($this->fp); + fwrite($fp, $data); + $this->writeChunk($this->CURRENT_CHUNK, $fp); + fclose($fp); + + $this->flags ^= PhDRender::CLOSE; + } elseif ($this->flags & PhDRender::OPEN) { + $this->fp[] = $fp = fopen("php://temp/maxmemory", "r+"); + fwrite($fp, $data); + + $this->flags ^= PhDRender::OPEN; + } else { + $fp = end($this->fp); + fwrite($fp, $data); + } + } + public function header($id) { + $title = $this->getLongDescription($id); + $lang = $this->CURRENT_LANG; + + $prev = $next = $parent = array("href" => null, "desc" => null); + /* {{{ FIXME: This is a complete fuckup */ + $ok = false; + $count = count($this->CHILDRENS)-1; + foreach($this->CHILDRENS as $row => $data) { + if ($data["filename"] === $id) { + if ($row != 0) { + $prev = array("href" => $this->CHILDRENS[$row-1]["filename"]. '.' .$this->ext, "desc" => $this->CHILDRENS[$row-1]["ldesc"] ?: $this->CHILDRENS[$row-1]["sdesc"]); + } + if ($row != $count) { + $next = array("href" => $this->CHILDRENS[$row+1]["filename"]. '.' .$this->ext, "desc" => $this->CHILDRENS[$row+1]["ldesc"] ?: $this->CHILDRENS[$row+1]["sdesc"]); + } + $ok = true; + break; + } + } + if (!$ok) { + //var_dump($id, $this->CHILDRENS); + //echo "\n\n"; + } + $row = $this->getParentInfo($id); + if (isset($row[0])) { + $parent = array("href" => $row[0]["filename"]. '.' .$this->ext, "desc" => $row[0]["ldesc"] ?: $row[0]["sdesc"]); + } + /* }}} */ + + return +'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' .$lang. '"" lang="' .$lang. '"> +<head> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"> + <title>PHP: '.$title.'</title> +</head> +<body> +<div style="text-align: center;"> + <div class="prev" style="float: left;"><a href="' .$prev["href"]. '">' .$prev["desc"]. '</a></div> + <div class="next" style="float: right;"><a href="' .$next["href"]. '">' .$next["desc"] .'</a></div> + <div class="up"><a href="' .$parent["href"]. '">' .$parent["desc"]. '</a></div> + <div class="home"><a href="index.html">PHP Manual</a></div> +</div> +'; + } + public function footer($id) { + return "\n</body>\n</html>\n"; + } + public function writeChunk($id, $fp) { + $filename = PhDConfig::get("output_dir") . $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 createLink($for, &$desc = null, $type = PhDFormat::SDESC) { + $retval = null; + if (isset($this->idx[$for])) { + $rsl = $this->idx[$for]; + $retval = $rsl["filename"] . '.' . $this->ext . '#' . $rsl["docbook_id"]; + $desc = $rsl["sdesc"] ?: $rsl["ldesc"]; + } + return $retval; + + return NO_SQLITE; + if ($desc === null) { + $rsl = sqlite_array_query($this->sqlite, "SELECT docbook_id, filename FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); + + if (!isset($rsl[0])) { + return false; + } + + $retval = $rsl[0]["filename"] . '.' . $this->ext . '#' . $rsl[0]["docbook_id"]; + } else { + $rsl = sqlite_array_query($this->sqlite, $q = "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); + + if (!isset($rsl[0])) { + var_dump($q); + return false; + } + + $retval = $rsl[0]["filename"] . '.' . $this->ext . '#' . $rsl[0]["docbook_id"]; + + if ($type === self::SDESC) { + $desc = $rsl[0]["sdesc"] ?: $rsl[0]["ldesc"]; + } else { + $desc = $rsl[0]["ldesc"] ?: $rsl[0]["sdesc"]; + } + } + + return $retval; + } + public function getLongDescription($for) { + return NO_SQLITE; + $rsl = sqlite_array_query($this->sqlite, $q = "SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); + if (!isset($rsl[0])) { + var_dump($q); + return false; + } + return $rsl[0]["ldesc"] ?: $rsl[0]["sdesc"]; + } + public function getShortDescription($for) { + return NO_SQLITE; + $rsl = sqlite_array_query($this->sqlite, "SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); + return $rsl[0]["sdesc"] ?: $rsl[0]["ldesc"]; + } + public function getParentInfo($for) { + return NO_SQLITE; + $rsl = sqlite_array_query($this->sqlite, "SELECT parent_id FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); + return sqlite_array_query($this->sqlite, "SELECT filename, sdesc, ldesc FROM ids WHERE docbook_id='{$rsl[0]["parent_id"]}'", SQLITE_ASSOC); + } + protected function createTOC($rsl) { + $toc = '<ol>'; + $desc = $title = ""; + foreach($rsl as $row) { + $link = $this->createLink($row["docbook_id"], $desc); + $list = ""; + if ($this->cchunk["name"] === "book" || $this->cchunk["name"] === "set") { + $childrens = sqlite_array_query($this->sqlite, "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='{$row["docbook_id"]}' AND filename=docbook_id", SQLITE_ASSOC); + if (NO_SQLITE && $childrens) { + $list = "<ol>"; + foreach($childrens as $child) { + $href = $this->createLink($child["docbook_id"], $title); + $list .= '<li><a href="' .$href. '">' .$title. "</a></li>\n"; + } + $list .="</ol>"; + } + } + $toc .= '<li><a href="' .$link. '">' .$desc. '</a>' .$list. "</li>\n"; + } + $toc .= "</ol>\n"; + + return $toc; + } + public function CDATA($str) { switch($this->role) { case "php": @@ -401,10 +585,41 @@ public function TEXT($str) { return htmlspecialchars($str, ENT_QUOTES, "UTF-8"); } + public function UNDEF($open, $name, $attrs, $props) { + if ($open) { + trigger_error("No mapper found for '{$name}'", E_USER_WARNING); + } + } + + public function admonition_title($title, $lang) { + return '<b class="' .(strtolower($title)). '">' .($this->autogen($title, $lang)). '</b>'; + } + public function getDefaultElementMap() { + return $this->myelementmap; + } + public function getDefaultTextMap() { + return $this->mytextmap; + } + public function update($event, $val = null) { + switch($event) { + case PhDRender::CHUNK: + $this->flags = $val; + break; + + case PhDRender::STANDALONE: + if ($val) { + $this->registerElementMap(static::getDefaultElementMap()); + $this->registerTextMap(static::getDefaultTextMap()); + } + break; + } + } + public function getChunkInfo() { return $this->cchunk; } - public function format_suppressed_tags($open, $name, $attrs) { + + public function format_suppressed_tags($open, $name, $attrs, $props) { /* Ignore it */ return ""; } @@ -412,7 +627,42 @@ /* Suppress any content */ return ""; } - + + public function format_link($open, $name, $attrs, $props) { + $link = null; + if ($open) { + $link = $class = $content = ""; + + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { + $link = $this->createLink($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"]); + } + elseif (isset($attrs[PhDReader::XMLNS_XLINK]["href"])) { + $link = $attrs[PhDReader::XMLNS_XLINK]["href"]; + $class = " external"; + $content = "» "; + } + if ($props["empty"]) { + $content .= $link ."</a>\n"; + } + + return '<a href="' . $link . '" class="' . $name . $class . '">' . $content; + } + return "</a>"; + } + public function format_xref($open, $name, $attrs, $props) { + if ($open) { + $desc = ""; + $link = $this->createLink($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"], $desc); + + $ret = '<a href="' .$link. '" class="' .$name. '">' .$desc; + + if ($props["empty"]) { + return $ret. "</a>"; + } + return $ret; + } + return "</a>"; + } public function format_literal($open, $name, $attrs) { if ($open) { if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) { @@ -439,7 +689,7 @@ return $this->TEXT($value); } } - + public function format_copyright($open, $name, $attrs) { if ($open) { return '<div class="'.$name.'">© '; @@ -487,31 +737,118 @@ return '</span> '; } - public function format_container_chunk($open, $name, $attrs) { + public function format_container_chunk_top($open, $name, $attrs, $props) { + $this->cchunk = $this->dchunk; + $this->cchunk["name"] = $name; + if(isset($attrs[PhDReader::XMLNS_XML]["id"])) { + $id = $attrs[PhDReader::XMLNS_XML]["id"]; + } else { + $id = uniqid("phd"); + } + + if ($open) { + $this->CURRENT_CHUNK = $id; + $this->notify(PhDRender::CHUNK, PhDRender::OPEN); + + return '<div id="' .$id. '" class="' .$name. '">'; + } + + $this->CURRENT_CHUNK = $id; + $this->notify(PhDRender::CHUNK, PhDRender::CLOSE); + + $toc = ""; + if (NO_SQLITE && !in_array($id, $this->TOC_WRITTEN)) { + $rsl = sqlite_array_query($this->sqlite, "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id' AND filename=docbook_id", SQLITE_ASSOC); + $toc = $this->createTOC($rsl); + } + return $toc."</div>"; + } + public function format_container_chunk_top_title($open, $name, $attrs, $props) { + if ($open) { + return '<h1>'; + } + + $id = $this->CURRENT_CHUNK; + if (NO_SQLITE) { + $this->CHILDRENS = $rsl = sqlite_array_query($this->sqlite, "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id' AND filename=docbook_id", SQLITE_ASSOC); + $toc = $this->createToc($rsl); + } else { + $this->CHILDRENS = array(); + $toc = ""; + } + $this->TOC_WRITTEN[] = $id; + + return '</h1>'.$toc; + } + public function format_container_chunk_below($open, $name, $attrs, $props) { $this->cchunk = $this->dchunk; + if(isset($attrs[PhDReader::XMLNS_XML]["id"])) { + $id = $attrs[PhDReader::XMLNS_XML]["id"]; + } else { + $id = uniqid("phd"); + } + if ($open) { + if (NO_SQLITE) { + $this->CHILDRENS = sqlite_array_query($this->sqlite, "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id' AND filename=docbook_id", SQLITE_ASSOC); + } + $this->CURRENT_CHUNK = $id; + $this->notify(PhDRender::CHUNK, PhDRender::OPEN); + return '<div id="' .$attrs[PhDReader::XMLNS_XML]["id"]. '" class="' .$name. '">'; } - return "</div>"; + + $toc = '<ol>'; + $desc = ""; + $rsl = $this->CHILDRENS; + foreach($rsl as $row) { + $link = $this->createLink($row["docbook_id"], $desc); + $toc .= '<li><a href="' .$link. '">' .$desc. "</a></li>\n"; + } + $toc .= "</ol>\n"; + + $this->CURRENT_CHUNK = $id; + $this->notify(PhDRender::CHUNK, PhDRender::CLOSE); + return $toc . '</div>'; } - public function format_legalnotice_chunk($open, $name, $attrs) { + public function format_section_chunk($open, $name, $attrs, $props) { + static $a = array(); if ($open) { - return '<div id="legalnotice">'; + $a[] = $props["sibling"]; + if ($props["sibling"] === $name) { + return $this->format_chunk($open, $name, $attrs, $props); + } + return $this->transformFromMap($open, "div", $name, $attrs, $props); } - return "</div>\n"; + $x = array_pop($a); + if ($x == $name) { + return $this->format_chunk($open, $name, $attrs, $props); + } + $a[] = $x; + return $this->transformFromMap($open, "div", $name, $attrs, $props); } - public function format_chunk($open, $name, $attrs) { + public function format_chunk($open, $name, $attrs, $props) { if ($open) { $this->cchunk = $this->dchunk; if(isset($attrs[PhDReader::XMLNS_XML]["id"])) { - $class = $name; - if ($name === "refentry") { - //$class .= " -rel-posting"; - } - return '<div id="' .$attrs[PhDReader::XMLNS_XML]["id"]. '" class="' .$class. '">'; + $id = $attrs[PhDReader::XMLNS_XML]["id"]; + } else { + $id = uniqid("phd"); + } + + $class = $name; + if ($name === "refentry") { + //$class .= " -rel-posting"; } - return '<div class="' .$name. '">'; + + $this->CURRENT_CHUNK = $id; + $this->CURRENT_LANG = $props["lang"]; + + $this->notify(PhDRender::CHUNK, PhDRender::OPEN); + return '<div id="' .$id. '" class="' .$class. '">'; } + $this->notify(PhDRender::CHUNK, PhDRender::CLOSE); + $str = ""; foreach ($this->cchunk["footnote"] as $k => $note) { $str .= '<div class="footnote">'; @@ -605,26 +942,7 @@ return $this->TEXT($value); } - public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag) { - $value = $this->TEXT($value); - if ($this->cchunk["classsynopsis"]["classname"] === false) { - return $value; - } - if (strpos($value, '::')) { - $explode = '::'; - } elseif (strpos($value, '->')) { - $explode = '->'; - } else { - return $value; - } - - list($class, $method) = explode($explode, $value); - if ($class !== $this->cchunk["classsynopsis"]["classname"]) { - return $value; - } - return $method; - } - + public function format_fieldsynopsis($open, $name, $attrs) { $this->cchunk["fieldsynopsis"] = $this->dchunk["fieldsynopsis"]; if ($open) { @@ -976,12 +1294,12 @@ } return "<br />"; } - public function format_bold_paragraph($open, $name, $attrs, $props) { + public function format_example_title($open, $name, $attrs, $props) { if ($props["empty"]) { return ""; } if ($open) { - return "<p><b>"; + return "<p><b>" . ($this->autogen('example', $props['lang']) . ++$this->cchunk["examples"]) . " "; } return "</b></p>"; } @@ -1131,9 +1449,51 @@ } return "</td>"; } + public function format_qandaset($open, $name, $attrs, $props) { + if ($open) { + $node = $this->getReader()->expand(); + $doc = new DOMDocument; + $doc->appendChild($node); - public function admonition_title($title, $lang) { - return '<b class="' .(strtolower($title)). '">' .($this->autogen($title, $lang)). '</b>'; + $xp = new DOMXPath($doc); + $xp->registerNamespace("db", PhDReader::XMLNS_DOCBOOK); + + $questions = $xp->query("//db:qandaentry/db:question"); + + $xml = '<questions xmlns="' .PhDReader::XMLNS_PHD. '">'; + foreach($questions as $node) { + $id = $xp->evaluate("ancestor::db:qandaentry", $node)->item(0)->getAttributeNs(PhDReader::XMLNS_XML, "id"); + + /* FIXME: No ID? How can we create an anchor for it then? */ + if (!$id) { + $id = uniqid("phd"); + } + + $node->setAttribute("xml:id", $id); + $xml .= $doc->saveXML($node); + } + $xml .= "</questions>"; + + $r = new PhDReader(); + $r->XML($xml); + + $render = new PhDRender; + $render->attach($this); + $render->render($r); + } + } + public function format_question($open, $name, $attrs, $props) { + if ($open) { + return '<dt><strong>'; + } + return '</strong></dt>'; + } + public function format_phd_question($open, $name, $attrs, $props) { + if ($open) { + $href = $this->createLink($attrs[PhDReader::XMLNS_XML]["id"]); + return '<li><a href="' .$href. '">'; + } + return '</a></li>'; } public function format_citation($open, $name, $attrs, $props) { http://cvs.php.net/viewvc.cgi/phd/include/PhDFormat.class.php?r1=1.10&r2=1.10.6.1&diff_format=u Index: phd/include/PhDFormat.class.php diff -u phd/include/PhDFormat.class.php:1.10 phd/include/PhDFormat.class.php:1.10.6.1 --- phd/include/PhDFormat.class.php:1.10 Mon Feb 4 21:17:25 2008 +++ phd/include/PhDFormat.class.php Mon Jul 28 22:40:57 2008 @@ -1,16 +1,117 @@ <?php -/* $Id: PhDFormat.class.php,v 1.10 2008/02/04 21:17:25 bjori Exp $ */ -abstract class PhDFormat extends PhDHelper { - private $TABLE = array(); - - /* abstract functions */ - abstract public function transformFromMap($open, $tag, $name, $attrs, $props); - abstract public function CDATA($data); - abstract public function TEXT($data); - abstract public function __call($func, $args); +abstract class PhDFormat extends PhDObjectStorage { + const SDESC = 1; + const LDESC = 2; + + private $elementmap = array(); + private $textmapmap = array(); + protected $sqlite; + + private static $autogen = array(); + + public function __construct() { + $this->sqlite = sqlite_open("index.sqlite"); + $this->sortIDs(); + } + + abstract public function transformFromMap($open, $tag, $name, $attrs, $props); + abstract public function UNDEF($open, $name, $attrs, $props); + abstract public function TEXT($value); + abstract public function CDATA($value); + abstract public function createLink($for, &$desc = null, $desc = PhDFormat::SDESC); + abstract public function appendData($data); + abstract public function update($event, $value = null); + + public function sortIDs() { + sqlite_create_aggregate($this->sqlite, "idx", array($this, "SQLiteIndex"), array($this, "SQLiteFinal"), 6); + sqlite_unbuffered_query($this->sqlite, "SELECT idx(docbook_id, filename, parent_id, sdesc, ldesc, element) FROM ids", SQLITE_ASSOC); + print_r($this->idx); + } + public function SQLiteIndex(&$context, $id, $filename, $parent, $sdesc, $ldesc, $element) { + $this->idx[$id] = array( + "docbook_id" => $id, + "filename" => $filename, + "parent_id" => $parent, + "sdesc" => $sdesc, + "ldesc" => $ldesc, + "element" => $element + ); + if ($element == "refentry") { + $this->refs[$sdesc] = $id; + } + + } + public static function SQLiteFinal(&$context) { + return $context; + } + + + final public function notify($event, $val = null) { + $this->update($event, $val); + foreach($this as $format) { + $format->update($event, $val); + } + } + final public function registerElementMap(array $map) { + $this->elementmap = $map; + } + final public function registerTextMap(array $map) { + $this->textmap = $map; + } + final public function attach($obj, $inf = array()) { + if (!($obj instanceof $this) && get_class($obj) != get_class($this)) { + throw new InvalidArgumentException(get_class($this) . " themes *MUST* _inherit_ " .get_class($this). ", got " . get_class($obj)); + } + $obj->notify(PhDRender::STANDALONE, false); + return parent::attach($obj, $inf); + } + final public function getElementMap() { + return $this->elementmap; + } + final public function getTextMap() { + return $this->textmap; + } + final public static function autogen($text, $lang) { + if (isset(self::$autogen[$lang])) { + if (isset(self::$autogen[$lang][$text])) { + return self::$autogen[$lang][$text]; + } + if ($lang == PhDConfig::get("fallback_language")) { + throw new InvalidArgumentException("Cannot autogenerate text for '$text'"); + } + return self::autogen($text, PhDConfig::get("fallback_language")); + } + + $filename = PhDConfig::get("lang_dir") . $lang . ".xml"; + + $r = new XMLReader; + if (!file_exists($filename) || !$r->open($filename)) { + if ($lang == PhDConfig::get("fallback_language")) { + throw new Exception("Cannot open $filename"); + } + return self::autogen($text, PhDConfig::get("fallback_language")); + } + $autogen = array(); + while ($r->read()) { + if ($r->nodeType != XMLReader::ELEMENT) { + continue; + } + if ($r->name == "term") { + $r->read(); + $k = $r->value; + $autogen[$k] = ""; + } else if ($r->name == "simpara") { + $r->read(); + $autogen[$k] = $r->value; + } + } + self::$autogen[$lang] = $autogen; + return self::autogen($text, $lang); + } + - /* Table helper functions */ + /* {{{ Table helper functions */ public function tgroup($attrs) { if (isset($attrs["cols"])) { $this->TABLE["cols"] = $attrs["cols"]; @@ -36,7 +137,6 @@ public function getColCount() { return $this->TABLE["cols"]; } - public function valign($attrs) { return isset($attrs["valign"]) ? $attrs["valign"] : "middle"; } @@ -79,7 +179,7 @@ } return 1; } - + /* }}} */ } /* http://cvs.php.net/viewvc.cgi/phd/include/PhDReader.class.php?r1=1.17&r2=1.17.4.1&diff_format=u Index: phd/include/PhDReader.class.php diff -u phd/include/PhDReader.class.php:1.17 phd/include/PhDReader.class.php:1.17.4.1 --- phd/include/PhDReader.class.php:1.17 Sat May 24 15:04:50 2008 +++ phd/include/PhDReader.class.php Mon Jul 28 22:40:57 2008 @@ -1,248 +1,115 @@ <?php -/* $Id: PhDReader.class.php,v 1.17 2008/05/24 15:04:50 gwynne Exp $ */ +/* $Id: PhDReader.class.php,v 1.17.4.1 2008/07/28 22:40:57 bjori Exp $ */ //6271 class PhDReader extends XMLReader { - - /* {{{ Class constants */ - const XMLNS_XML = "http://www.w3.org/XML/1998/namespace"; - const XMLNS_XLINK = "http://www.w3.org/1999/xlink"; - const XMLNS_PHD = "http://www.php.net/ns/phd"; + const XMLNS_XML = "http://www.w3.org/XML/1998/namespace"; + const XMLNS_XLINK = "http://www.w3.org/1999/xlink"; + const XMLNS_PHD = "http://www.php.net/ns/phd"; const XMLNS_DOCBOOK = "http://docbook.org/ns/docbook"; - const OPEN_CHUNK = 0x01; - const CLOSE_CHUNK = 0x02; - /* }}} */ - - /* {{{ Private props */ - private $STACK = array(); - private $LAST_DEPTH = -1; - private $lastChunkDepth = -1; - private $PREVIOUS_SIBLING = ""; - /* }}} */ - - protected $CHUNK_ME = array( /* {{{ */ - 'article' => true, - 'appendix' => true, - 'bibliography' => array( - /* DEFAULT */ false, - 'article' => true, - 'book' => true, - 'part' => true, - ), - 'book' => true, - 'chapter' => true, - 'colophon' => true, - 'glossary' => array( - /* DEFAULT */ false, - 'article' => true, - 'book' => true, - 'part' => true, - ), - 'index' => array( - /* DEFAULT */ false, - 'article' => true, - 'book' => true, - 'part' => true, - ), - 'legalnotice' => false, - 'part' => true, - 'preface' => true, - 'refentry' => true, - 'reference' => true, - 'sect1' => 'isSectionChunk', - /* - 'sect2' => 'format_section_chunk', - 'sect3' => 'format_section_chunk', - 'sect4' => 'format_section_chunk', - 'sect5' => 'format_section_chunk', - */ - 'section' => 'isSectionChunk', - 'set' => true, - 'setindex' => true, - ); /* }}} */ - - public $isChunk = false; - - public function __construct($encoding = "UTF-8", $xml_opts = NULL) { /* {{{ */ - if (!XMLReader::open(PhDConfig::xml_file(), $encoding, $xml_opts)) { - throw new Exception("Cannot open " . PhDConfig::xml_file()); - } - $ce = PhDConfig::chunk_extra(); - if (is_array($ce)) { - foreach($ce as $el => $v) { - $this->CHUNK_ME[$el] = $v; - } - } - } /* }}} */ - - public function notXPath($tag, $depth = 0) { /* {{{ */ - if(!$depth) { - $depth = $this->depth; - } - do { - if (isset($tag[$this->STACK[--$depth]])) { - $tag = $tag[$this->STACK[$depth]]; - } else { - $tag = $tag[0]; - } - } while (is_array($tag)); - return $tag; - } /* }}} */ - - /* Seek to an ID within the file. */ - public function seek($id) { /* {{{ */ - while(XMLReader::read()) { - if ($this->nodeType === XMLREADER::ELEMENT && $this->hasAttributes && XMLReader::moveToAttributeNs("id", self::XMLNS_XML) && $this->value === $id) { - return XMLReader::moveToElement(); - } - } - return false; - } /* }}} */ - - /* Get the ID of current node */ - public function getID() { /* {{{ */ - if ($this->hasAttributes && XMLReader::moveToAttributeNs("id", self::XMLNS_XML)) { - $id = $this->value; - XMLReader::moveToElement(); - return $id; - } - return ""; - } /* }}} */ - - public function getParentTagName() { /* {{{ */ - return $this->STACK[$this->depth-1]; - } /* }}} */ - public function getPreviousSiblingTagName() { /* {{{ */ - return $this->PREVIOUS_SIBLING; - } /* }}} */ - - public function read() { /* {{{ */ - $this->isChunk = false; - if(XMLReader::read()) { - $type = $this->nodeType; - switch($type) { - case XMLReader::ELEMENT: - $name = $this->name; - $depth = $this->depth; - if ($this->LAST_DEPTH >= $depth) { - $this->PREVIOUS_SIBLING = $this->STACK[$depth]; - } - $this->STACK[$depth] = $name; - $isChunk = $this->isChunk($name); - if ($isChunk) { - $this->isChunk = PhDReader::OPEN_CHUNK; - $this->chunkDepths[] = $this->lastChunkDepth = $depth; - } - break; - - case XMLReader::END_ELEMENT: - $depth = $this->depth; - if ($this->lastChunkDepth == $depth) { - array_pop($this->chunkDepths); - $this->lastChunkDepth = end($this->chunkDepths); - $this->isChunk = PhDReader::CLOSE_CHUNK; - } - $this->LAST_DEPTH = $depth; - break; - } - return true; - } - return false; - } /* }}} */ - - /* Get the attribute value by name, if exists. */ - public function readAttribute($attr) { /* {{{ */ - $retval = XMLReader::moveToAttribute($attr) ? $this->value : ""; - XMLReader::moveToElement(); - return $retval; - } /* }}} */ - public function readAttributeNs($attr, $ns) { /* {{{ */ - $retval = XMLReader::moveToAttributeNs($attr, $ns) ? $this->value : ""; - XMLReader::moveToElement(); - return $retval; - } /* }}} */ - /* Get all attributes of current node */ - public function getAttributes() { /* {{{ */ - $attrs = array(PhDReader::XMLNS_DOCBOOK => array(), PhDReader::XMLNS_XML => array()); - if ($this->hasAttributes) { - XMLReader::moveToFirstAttribute(); - do { - $k = $this->namespaceURI; - $attrs[!empty($k) ? $k : PhDReader::XMLNS_DOCBOOK][$this->localName] = $this->value; - $attrs[$this->name] = $this->value; - } while (XMLReader::moveToNextAttribute()); - XMLReader::moveToElement(); - } - return $attrs; - } /* }}} */ - - - /* Get the content of a named node, or the current node. */ - public function readContent($node = null) { /* {{{ */ - $retval = ""; - - if($this->isEmptyElement) { - return $retval; - } - if (!$node) { - $node = $this->name; - } - $retval = ""; - while (PhDReader::readNode($node)) { - $retval .= $this->value; - } - return $retval; - } /* }}} */ - /* Read $nodeName until END_ELEMENT */ - public function readNode($nodeName) { /* {{{ */ - return XMLReader::read() && !($this->nodeType === XMLReader::END_ELEMENT && $this->name == $nodeName); - } /* }}} */ - - - public function isChunk($tag) { /* {{{ */ - if (isset($this->CHUNK_ME[$tag])) { - $isChunk = $this->CHUNK_ME[$tag]; - if (is_array($isChunk)) { - $isChunk = $this->notXPath($isChunk); - } - if (!is_bool($isChunk)) { - return call_user_func(array($this, $isChunk), $tag); - } - return $isChunk; - } - return false; - } /* }}} */ - public function isSectionChunk($tag) { /* {{{ */ - if ($this->PREVIOUS_SIBLING == $tag && $this->checkSectionDepth()) { - return true; - } - return false; - } /* }}} */ - protected function checkSectionDepth() { /* {{{ */ - static $allowedParents = array("section", "sect2", "sect3", "sect4", "sect5"); - static $chunkers = array( - "sect1", "preface", "chapter", "appendix", "article", "part", "reference", "refentry", - "index", "bibliography", "glossary", "colopone", "book", "set", "setindex", "legalnotice", - ); - - $nodeDepth = $this->depth; - $i = 1; - do { - if (in_array($this->STACK[$nodeDepth-$i], $allowedParents)) { - ++$i; - continue; - } - break; - } while(true); - if ($i <= 1 && in_array($this->STACK[$nodeDepth-$i], $chunkers)) { - return true; - } - return false; - } /* }}} */ -} + + public function __construct() { + } + + public function close() { + return XMLReader::close(); + } + + public function getAttribute($name) { + return XMLReader::getAttribute($name); + } + + public function getAttributeNo($index) { + return XMLReader::getAttributeNo($index); + } + + public function getAttributeNs($name, $namespaceURI) { + return XMLReader::getAttributeNs($name, $namespaceURI); + } + + public function getParserProperty($property) { + return XMLReader::getParserProperty($property); + } + + public function isValid() { + return XMLReader::isValid(); + } + + public function lookupNamespace($prefix) { + return XMLReader::lookupNamespace($prefix); + } + + public function moveToAttributeNo($index) { + return XMLReader::moveToAttributeNo($index); + } + + public function moveToAttribute($name) { + return XMLReader::moveToAttribute($name); + } + + public function moveToAttributeNs($name, $namespaceURI) { + return XMLReader::moveToAttributeNs($name, $namespaceURI); + } + + public function moveToElement() { + return XMLReader::moveToElement(); + } + + public function moveToFirstAttribute() { + return XMLReader::moveToFirstAttribute(); + } + + public function moveToNextAttribute() { + return XMLReader::moveToNextAttribute(); + } + + public function open($URI, $encoding = null, $options = null) { + return XMLReader::open($URI, $encoding, $options); + } + + public function read() { + return XMLReader::read(); + } + + public function next($localname = null) { + return XMLReader::next($localname); + } + + public function readInnerXml() { + return XMLReader::readInnerXml(); + } + + public function readOuterXml() { + return XMLReader::readOuterXml(); + } + + public function readString() { + return XMLReader::readString(); + } + + public function setSchema($filename) { + return XMLReader::setSchema($filename); + } + + public function setParserProperty($property, $value) { + return XMLReader::setParserProperty($property, $value); + } + + public function setRelaxNGSchema($filename) { + return XMLReader::setRelaxNGSchema($filename); + } + + public function setRelaxNGSchemaSource($source) { + return XMLReader::setRelaxNGSchemaSource($source); + } + + public function XML($source, $encoding = null, $options = null) { + return XMLReader::XML($source, $encoding, $options); + } + + public function expand() { + return XMLReader::expand(); + } -/* -* vim600: sw=4 ts=4 syntax=php fdm=marker et -* vim<600: sw=4 ts=4 -*/ +} http://cvs.php.net/viewvc.cgi/phd/themes/php/phpdotnet.php?r1=1.54&r2=1.54.2.1&diff_format=u Index: phd/themes/php/phpdotnet.php diff -u phd/themes/php/phpdotnet.php:1.54 phd/themes/php/phpdotnet.php:1.54.2.1 --- phd/themes/php/phpdotnet.php:1.54 Wed Jul 23 19:21:31 2008 +++ phd/themes/php/phpdotnet.php Mon Jul 28 22:40:57 2008 @@ -1,25 +1,20 @@ <?php -/* $Id: phpdotnet.php,v 1.54 2008/07/23 19:21:31 bjori Exp $ */ +/* $Id: phpdotnet.php,v 1.54.2.1 2008/07/28 22:40:57 bjori Exp $ */ -abstract class phpdotnet extends PhDTheme { - protected $elementmap = array( - 'acronym' => 'format_suppressed_tags', +class PhDPHPFormat extends PhDXHTMLFormat { + protected $myelementmap = array( 'function' => 'format_suppressed_tags', - 'link' => 'format_link', - 'refpurpose' => 'format_refpurpose', - 'title' => array( + 'BOGUStitle' => array( /* DEFAULT */ false, 'article' => 'format_container_chunk_title', 'appendix' => 'format_container_chunk_title', 'chapter' => 'format_container_chunk_title', - 'example' => 'format_example_title', 'part' => 'format_container_chunk_title', 'info' => array( /* DEFAULT */ false, 'article' => 'format_container_chunk_title', 'appendix' => 'format_container_chunk_title', 'chapter' => 'format_container_chunk_title', - 'example' => 'format_example_title', 'part' => 'format_container_chunk_title', ), ), @@ -32,91 +27,50 @@ 'methodparam' => false, 'methodsynopsis' => false, ), - 'varname' => array( - /* DEFAULT */ false, - 'fieldsynopsis' => 'format_fieldsynopsis_varname', - ), - 'xref' => 'format_link', - - 'article' => 'format_container_chunk', - 'appendix' => 'format_container_chunk', - 'bibliography' => array( + 'BOGUSarticle' => 'format_container_chunk', + 'BOGUSappendix' => 'format_container_chunk', + 'BOGUSbibliography' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), - 'book' => 'format_root_chunk', - 'chapter' => 'format_container_chunk', - 'colophon' => 'format_chunk', - 'glossary' => array( + 'BOGUSbook' => 'format_root_chunk', + 'BOGUSchapter' => 'format_container_chunk', + 'BOGUScolophon' => 'format_chunk', + 'BOGUSglossary' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), - 'index' => array( + 'BOGUSindex' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), - 'legalnotice' => 'format_chunk', - 'part' => 'format_container_chunk', - 'preface' => 'format_chunk', - 'refentry' => 'format_chunk', - 'reference' => 'format_container_chunk', - 'phpdoc:exception' => 'format_exception_chunk', - 'sect1' => 'format_chunk', - 'sect2' => 'format_chunk', - 'sect3' => 'format_chunk', - 'sect4' => 'format_chunk', - 'sect5' => 'format_chunk', - 'section' => 'format_chunk', - 'set' => 'format_root_chunk', - 'setindex' => 'format_chunk', - 'qandaset' => 'format_qandaset', - 'qandaentry' => 'format_qandaentry', - 'question' => 'format_question', - 'answer' => 'format_answer', + 'BOGUSlegalnotice' => 'format_chunk', + 'BOGUSpart' => 'format_container_chunk', + 'BOGUSpreface' => 'format_chunk', + 'BOGUSrefentry' => 'format_chunk', + 'BOGUSreference' => 'format_container_chunk', + 'BOGUSsect1' => 'format_chunk', + 'BOGUSsect2' => 'format_chunk', + 'BOGUSsect3' => 'format_chunk', + 'BOGUSsect4' => 'format_chunk', + 'BOGUSsect5' => 'format_chunk', + 'BOGUSsection' => 'format_chunk', + 'BOGUSset' => 'format_root_chunk', + 'BOGUSsetindex' => 'format_chunk', + 'BOGUSphpdoc:exception' => 'format_exception_chunk', ); - protected $textmap = array( - 'acronym' => 'format_acronym_text', - 'function' => 'format_function_text', - 'methodname' => array( - /* DEFAULT */ 'format_function_text', - 'constructorsynopsis' => array( - /* DEFAULT */ 'format_function_text', - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - 'methodsynopsis' => array( - /* DEFAULT */ 'format_function_text', - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - 'destructorsynopsis' => array( - /* DEFAULT */ 'format_function_text', - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - ), - 'type' => array( - /* DEFAULT */ 'format_type_text', - 'classsynopsisinfo' => false, - 'fieldsynopsis' => 'format_type_if_object_or_pseudo_text', - 'methodparam' => 'format_type_if_object_or_pseudo_text', - 'methodsynopsis' => array( - /* DEFAULT */ 'format_type_if_object_or_pseudo_text', - 'classsynopsis' => false, - ), - ), - 'refname' => 'format_refname_text', + protected $mytextmap = array( 'titleabbrev' => 'format_suppressed_tags', ); - private $versions = array(); - private $acronyms = array(); - protected $chunked = true; protected $lang = "en"; protected $CURRENT_ID = ""; @@ -129,471 +83,8 @@ "modifier" => "public", ), "container_chunk" => null, - "qandaentry" => array( - ), - "examples" => 0, - "verinfo" => false, - "refname" => array(), ); - public function __construct(array $IDs, array $filenames, $ext = "php", $chunked = true) { - parent::__construct($IDs, $ext); - $this->ext = $ext; - if (isset($filenames["version"], $filenames["acronym"])) { - $this->versions = self::generateVersionInfo($filenames["version"]); - $this->acronyms = self::generateAcronymInfo($filenames["acronym"]); - } - $this->chunked = $chunked; - } - public static function generateVersionInfo($filename) { - static $info; - if ($info) { - return $info; - } - $r = new XMLReader; - if (!$r->open($filename)) { - throw new Exception; - } - $versions = array(); - while($r->read()) { - if ( - $r->moveToAttribute("name") - && ($funcname = str_replace( - array("::", "->", "__", "_", '$'), - array("-", "-", "-", "-", ""), - $r->value)) - && $r->moveToAttribute("from") - && ($from = $r->value) - ) { - $versions[strtolower($funcname)] = $from; - $r->moveToElement(); - } - } - $r->close(); - $info = $versions; - return $versions; - } - public static function generateAcronymInfo($filename) { - static $info; - if ($info) { - return $info; - } - $r = new XMLReader; - if (!$r->open($filename)) { - throw new Exception("Could not open $filename"); - } - $acronyms = array(); - while ($r->read()) { - if ($r->nodeType != XMLReader::ELEMENT) { - continue; - } - if ($r->name == "term") { - $r->read(); - $k = $r->value; - $acronyms[$k] = ""; - } else if ($r->name == "simpara") { - $r->read(); - $acronyms[$k] = $r->value; - } - } - $info = $acronyms; - return $acronyms; - } - public function format_link($open, $name, $attrs, $props) { - if ($open) { - $content = $fragment = ""; - $class = $name; - - if(isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { - $linkto = $attrs[PhDReader::XMLNS_DOCBOOK]["linkend"]; - $id = $href = PhDHelper::getFilename($linkto); - - if ($id != $linkto) { - $fragment = "#$linkto"; - } - if ($this->chunked) { - $href .= ".".$this->ext; - } - } elseif(isset($attrs[PhDReader::XMLNS_XLINK]["href"])) { - $href = $attrs[PhDReader::XMLNS_XLINK]["href"]; - $content = "» "; - $class .= " external"; - } - if ($name == "xref") { - if ($this->chunked) { - $link = $href; - } else { - $link = "#"; - if (isset($linkto)) { - $link .= $linkto; - } else { - $link .= $href; - } - } - return '<a href="' .$link. '" class="' .$class. '">' .($content.PhDHelper::getDescription($id, false)). '</a>'; - } elseif ($props["empty"]) { - if ($this->chunked) { - $link = ""; - } else { - $link = "#"; - } - return '<a href="' .$link.$href.$fragment. '" class="' .$class. '">' .$content.$href.$fragment. '</a>'; - } else { - if ($this->chunked) { - $link = $href.$fragment; - } elseif(isset($linkto)) { - if ($fragment) { - $link = $fragment; - } else { - $link = "#$href"; - } - } else { - $link = $href; - } - return '<a href="' .$link. '" class="' .$class. '">' .$content; - } - } - return "</a>"; - } - public function format_fieldsynopsis_varname($open, $name, $attrs) { - if ($open) { - $href = ""; - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { - $linkto = $attrs[PhDReader::XMLNS_DOCBOOK]["linkend"]; - $href = PhDHelper::getFilename($linkto); - - if ($this->chunked) { - if ($href != $linkto) { - $href .= ".{$this->ext}#{$linkto}"; - } else { - $href .= '.' .$this->ext; - } - } else { - $href = '#' .$linkto; - } - $href = '<a href="' .$href. '">'; - } - - if ( - $this->cchunk["fieldsynopsis"]["modifier"] == "const" || - ( - $nfo = $this->format->getChunkInfo() AND $nfo["fieldsynopsis"]["modifier"] == "const" - ) - ) { - return ' <var class="fieldsynopsis_varname">'.$href; - } - return ' <var class="'.$name.'">'.$href.'$'; - } - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { - return '</a></var>'; - } - return '</var>'; - } - - - - - public function versionInfo($funcname) { - $funcname = str_replace( - array("::", "->", "__", "_", '$', '()'), - array("-", "-", "-", "-", "", ''), - strtolower($funcname)); - if(isset($this->versions[$funcname])) { - return $this->versions[$funcname]; - } - v("No version info for $funcname", VERBOSE_NOVERSION); - return false; - } - public function acronymInfo($acronym) { - return isset($this->acronyms[$acronym]) ? $this->acronyms[$acronym] : false; - } - - public function format_acronym_text($value, $tag) { - $resolved = $this->acronymInfo($value); - if ($resolved) { - return '<acronym title="' .$resolved. '">' .$value. '</acronym>'; - } - return '<acronym>'.$value.'</acronym>'; - } - public function format_refpurpose($open, $tag, $attrs) { - if ($open) { - $retval = ""; - if ($this->cchunk["verinfo"]) { - $verinfo = ""; - foreach($this->cchunk["refname"] as $refname) { - $verinfo = $this->versionInfo($refname); - - if ($verinfo) { - break; - } - } - if (!$verinfo) { - $verinfo = "No version information available, might be only in CVS"; - } - - $retval = '<p class="verinfo">(' .(htmlspecialchars($verinfo, ENT_QUOTES, "UTF-8")). ')</p>'; - } - $refnames = implode('</span> -- <span class="refname">', $this->cchunk["refname"]); - - $retval .= '<p class="refpurpose"><span class="refname">'. $refnames. '</span> — <span class="dc-title">'; - return $retval; - } - return "</span></p>\n"; - } - public function format_refname_text($value, $tag) { - $this->cchunk["refname"][] = $this->format->TEXT($value); - return false; - } - public function format_chunk($open, $name, $attrs, $props) { - if (isset($attrs[PhDReader::XMLNS_XML]["id"])) { - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; - } - if ($props["isChunk"]) { - $this->cchunk = $this->dchunk; - } - if (isset($props["lang"])) { - $this->lang = $props["lang"]; - } - if ($name == "refentry") { - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) { - $this->cchunk["verinfo"] = !($attrs[PhDReader::XMLNS_DOCBOOK]["role"] == "noversion"); - } else { - $this->cchunk["verinfo"] = true; - } - } - return false; - } - public function format_container_chunk($open, $name, $attrs, $props) { - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; - if ($open) { - if ($props["isChunk"]) { - $this->cchunk = $this->dchunk; - } - if ($name != "reference") { - $chunks = PhDHelper::getChildren($id); - if (!count($chunks)) { - return "<div>"; - } - $content = '<h2>'.$this->autogen("toc", $props["lang"]). '</h2><ul class="chunklist chunklist_'.$name.'">'; - foreach($chunks as $chunkid => $junk) { - if ($this->chunked) { - $content .= '<li><a href="'.$chunkid. '.' .$this->ext. '">' .(PhDHelper::getDescription($chunkid, true)). '</a></li>'; - } else { - $content .= '<li><a href="#'.$chunkid. '">' .(PhDHelper::getDescription($chunkid, true)). '</a></li>'; - } - } - $content .= "</ul>\n"; - $this->cchunk["container_chunk"] = $content; - } - return "<div>"; - } - - $content = ""; - if ($name == "reference") { - $chunks = PhDHelper::getChildren($id); - if (count($chunks)) { - $content = '<h2>'.$this->autogen("toc", $props["lang"]). '</h2><ul class="chunklist chunklist_reference">'; - foreach($chunks as $chunkid => $junk) { - if ($this->chunked) { - $content .= '<li><a href="'.$chunkid. '.' .$this->ext. '">' .(PhDHelper::getDescription($chunkid, false)). '</a> â ' .(PhDHelper::getDescription($chunkid, true)). '</li>'; - } else { - $content .= '<li><a href="#'.$chunkid.'">' .(PhDHelper::getDescription($chunkid, false)). '</a> â ' .(PhDHelper::getDescription($chunkid, true)). '</li>'; - } - } - $content .= "</ul>\n"; - } - } - $content .= "</div>\n"; - - return $content; - } - public function format_exception_chunk($open, $name, $attrs, $props) { - return $this->format_container_chunk($open, "reference", $attrs, $props); - } - - public function format_container_chunk_title($open, $name, $attrs) { - if ($open) { - return "<h1>"; - } - $ret = ""; - if ($this->cchunk["container_chunk"]) { - $ret = $this->cchunk["container_chunk"]; - $this->cchunk["container_chunk"] = null; - } - return "</h1>\n" .$ret; - } - public function format_root_chunk($open, $name, $attrs) { - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; - if ($open) { - return "<div>"; - } - - $chunks = PhDHelper::getChildren($id); - $content = '<ul class="chunklist chunklist_'.$name.'">'; - foreach($chunks as $chunkid => $junk) { - $href = $this->chunked ? $chunkid .'.'. $this->ext : "#$chunkid"; - $long = PhDHelper::getDescription($chunkid, true); - $short = PhDHelper::getDescription($chunkid, false); - if ($long && $short && $long != $short) { - $content .= '<li><a href="' .$href. '">' .$short. '</a> â ' .$long; - } else { - $content .= '<li><a href="' .$href. '">' .($long ? $long : $short). '</a>'; - } - $children = PhDHelper::getChildren($chunkid); - if (count($children)) { - $content .= '<ul class="chunklist chunklist_'.$name.' chunklist_children">'; - foreach(PhDHelper::getChildren($chunkid) as $childid => $junk) { - $href = $this->chunked ? $childid .'.'. $this->ext : "#$childid"; - $long = PhDHelper::getDescription($childid, true); - $short = PhDHelper::getDescription($childid, false); - if ($long && $short && $long != $short) { - $content .= '<li><a href="' .$href. '">' .$short. '</a> â ' .$long. '</li>'; - } else { - $content .= '<li><a href="' .$href. '">' .($long ? $long : $short). '</a></li>'; - } - } - $content .="</ul>"; - } - $content .= "</li>"; - } - $content .= "</ul>"; - - return $content; - } - - public function format_suppressed_tags($open, $name) { - /* ignore it */ - return ""; - } - - public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag) { - $display_value = $this->format->format_classsynopsis_methodsynopsis_methodname_text($value, $tag); - return $this->format_function_text($value, $tag, $display_value); - } - - public function format_function_text($value, $tag, $display_value = null) { - if ($display_value === null) { - $display_value = $value; - } - $rel = ""; - if ($this->format->role == "seealso") { - $rel = ' rel="rdfs-seeAlso"'; - } - - $ref = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $value)); - if (($filename = $this->getRefnameLink($ref)) !== null && $this->CURRENT_ID !== $filename) { - if ($this->chunked) { - return '<a href="'.$filename. '.' .$this->ext. '" class="function"'.$rel.'>' .$display_value.($tag == "function" ? "()" : ""). '</a>'; - } - return '<a href="#'.$filename. '" class="function"'.$rel.'>' .$display_value.($tag == "function" ? "()" : ""). '</a>'; - } - return '<b>' .$display_value.($tag == "function" ? "()" : ""). '</b>'; - } - public function format_type_if_object_or_pseudo_text($type, $tagname) { - if (in_array(strtolower($type), array("bool", "int", "double", "boolean", "integer", "float", "string", "array", "object", "resource", "null"))) { - return false; - } - return self::format_type_text($type, $tagname); - } - public function format_type_text($type, $tagname) { - $t = strtolower($type); - $href = $fragment = ""; - - switch($t) { - case "bool": - $href = "language.types.boolean"; - break; - case "int": - $href = "language.types.integer"; - break; - case "double": - $href = "language.types.float"; - break; - case "boolean": - case "integer": - case "float": - case "string": - case "array": - case "object": - case "resource": - case "null": - $href = "language.types.$t"; - break; - case "mixed": - case "number": - case "callback": - $href = "language.pseudo-types"; - $fragment = "language.types.$t"; - break; - default: - /* Check if its a classname. */ - $href = PhDTheme::getFilename("class.$t"); - } - - if ($href && $this->chunked) { - return '<a href="' .$href. '.' .$this->ext.($fragment ? "#$fragment" : ""). '" class="' .$tagname. ' ' .$type. '">' .$type. '</a>'; - } - if ($href) { - return '<a href="#' .($fragment ? $fragment : $href). '" class="' .$tagname. ' ' .$type. '">' .$type. '</a>'; - } - return '<span class="' .$tagname. ' ' .$type. '">' .$type. '</span>'; - } - - public function format_example_title($open, $name, $attrs, $props) { - if ($props["empty"]) { - return ""; - } - if ($open) { - return "<p><b>" . ($this->autogen('example', $props['lang']) . ++$this->cchunk["examples"]) . " "; - } - return "</b></p>"; - } - - /* FIXME: This function is a crazy performance killer */ - public function qandaset($stream) { - $xml = stream_get_contents($stream); - - $old = libxml_use_internal_errors(true); - $doc = new DOMDocument("1.0", "UTF-8"); - $doc->preserveWhitespace = false; - $doc->loadXML(html_entity_decode(str_replace("&", "&amp;", "<div>$xml</div>"), ENT_QUOTES, "UTF-8")); - if ($err = libxml_get_errors()) { - print_r($err); - libxml_clear_errors(); - } - fclose($stream); - libxml_use_internal_errors($old); - - $xpath = new DOMXPath($doc); - $nlist = $xpath->query("//div/dl/dt"); - $ret = '<div class="qandaset"><ol class="qandaset_questions">'; - $i = 0; - foreach($nlist as $node) { - $ret .= '<li><a href="#' .($this->cchunk["qandaentry"][$i++]). '">' .($node->textContent). '</a></li>'; - } - - return $ret.'</ol>'.$xml.'</div>'; - } - public function format_qandaentry($open, $name, $attrs) { - if ($open) { - $this->cchunk["qandaentry"][] = $attrs[PhDReader::XMLNS_XML]["id"]; - return '<dl>'; - } - return '</dl>'; - } - public function format_answer($open, $name, $attrs) { - if ($open) { - return '<dd><a name="' .end($this->cchunk["qandaentry"]).'"></a>'; - } - return "</dd>"; - } - public function format_question($open, $name, $attrs) { - if ($open) { - return '<dt><strong>'; - } - return '</strong></dt>'; - } - } /* http://cvs.php.net/viewvc.cgi/phd/formats/bigxhtml.php?view=markup&rev=1.1 Index: phd/formats/bigxhtml.php +++ phd/formats/bigxhtml.php <?php class PhDBigXHTMLFormat extends PhDXHTMLFormat { private $myelementmap = array( 'link' => 'format_link', 'xref' => 'format_xref', 'title' => array( /* DEFAULT */ false, 'info' => array( /* DEFAULT */ false, 'article' => 'format_container_chunk_top_title', 'appendix' => 'format_container_chunk_top_title', 'book' => 'format_container_chunk_top_title', 'chapter' => 'format_container_chunk_top_title', 'part' => 'format_container_chunk_top_title', 'set' => 'format_container_chunk_top_title', ), 'article' => 'format_container_chunk_top_title', 'appendix' => 'format_container_chunk_top_title', 'book' => 'format_container_chunk_top_title', 'chapter' => 'format_container_chunk_top_title', 'part' => 'format_container_chunk_top_title', 'set' => 'format_container_chunk_top_title', ), 'reference' => 'format_container_chunk_below', 'question' => array( /* DEFAULT */ false, 'questions' => 'format_phd_question', // From the PhD namespace ), ); private $mytextmap = array( ); private $bigfp; protected $flags; public function __construct() { parent::__construct(); } public function appendData($data) { $id = "BIGHTML ID"; if ($this->flags & PhDRender::CLOSE) { fwrite($this->bigfp, $data); /* Append footer */ fwrite($this->bigfp, $this->footer($id)); $this->flags ^= PhDRender::CLOSE; } elseif ($this->flags & PhDRender::OPEN) { /* Prepend header */ fwrite($this->bigfp, $this->header($id)); fwrite($this->bigfp, $data); $this->flags ^= PhDRender::OPEN; } else { fwrite($this->bigfp, $data); } } public function header($id) { return "\n"; } public function footer($id) { return "\n<hr />\n"; } public function open() { static $i = 0; $i++; $this->bigfp = fopen(PhDConfig::get("output_dir") . "bightml$i.html", "w+"); // FIXME: Use correct lang attribute and insert <title> of the DB file fwrite($this->bigfp, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> </head> <body> '); } public function close() { fwrite($this->bigfp, "</body>\n</html>"); fclose($this->bigfp); } public function getDefaultElementMap() { return $this->myelementmap; } public function getDefaultTextMap() { return $this->mytextmap; } public function update($event, $val = null) { switch($event) { case PhDRender::CHUNK: $this->flags = $val; break; case PhDRender::STANDALONE: if ($val) { $this->registerElementMap(parent::getDefaultElementMap()); $this->registerTextMap(parent::getDefaultTextMap()); } else { $this->registerElementMap(static::getDefaultElementMap()); $this->registerTextMap(static::getDefaultTextMap()); } break; case PhDRender::INIT: if ($val) { if (!is_resource($this->bigfp)) { $this->open(); } } else { $this->close(); } break; } } public function createLink($for, &$desc = null, $type = self::SDESC) { $retval = '#' . $for; if ($desc !== null) { $rsl = sqlite_array_query($this->sqlite, "SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); $retval = '#' . $for; if ($type === self::SDESC) { $desc = $rsl[0]["sdesc"] ?: $rsl[0]["ldesc"]; } else { $desc = $rsl[0]["ldesc"] ?: $rsl[0]["sdesc"]; } } return $retval; } } /* * vim600: sw=4 ts=4 fdm=syntax syntax=php et * vim<600: sw=4 ts=4 */ http://cvs.php.net/viewvc.cgi/phd/include/PhDConfig.class.php?view=markup&rev=1.1 Index: phd/include/PhDConfig.class.php +++ phd/include/PhDConfig.class.php <?php define('VERBOSE_INDEXING', 0x01); define('VERBOSE_FORMAT_RENDERING', 0x02); define('VERBOSE_THEME_RENDERING', 0x04); define('VERBOSE_RENDER_STYLE', 0x08); define('VERBOSE_PARTIAL_READING', 0x10); define('VERBOSE_PARTIAL_CHILD_READING', 0x20); define('VERBOSE_TOC_WRITING', 0x40); define('VERBOSE_CHUNK_WRITING', 0x80); define('VERBOSE_ALL', 0xFF); class PhDConfig { private static $opts = array( "output_format" => array( ), "output_theme" => array( ), "chunk_extra" => array( ), "index" => true, "xml_root" => __DIR__, "xml_file" => false, "language" => "en", "fallback_language" => "en", "build_log_file" => false, "verbose" => VERBOSE_ALL, "date_format" => "H:i:s", "render_ids" => array( ), "skip_ids" => array( ), "output_dir" => __DIR__, "lang_dir" => __DIR__, ); public static function init(array $a) { self::$opts = array_merge(self::$opts, (array)$a); } public static function get($opt) { if (!is_string($opt)) { throw new UnexpectedValueException("Excpecting a string"); } if (!isset(self::$opts[$opt])) { throw new UnexpectedValueException("Unknown option: $opt"); } return self::$opts[$opt]; } } http://cvs.php.net/viewvc.cgi/phd/include/PhDIndex.class.php?view=markup&rev=1.1 Index: phd/include/PhDIndex.class.php +++ phd/include/PhDIndex.class.php <?php class PhDIndex extends PhDFormat { private $myelementmap = array( 'article' => 'format_container_chunk', 'appendix' => 'format_container_chunk', 'bibliography' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), 'book' => 'format_container_chunk', 'chapter' => 'format_container_chunk', 'colophon' => 'format_chunk', 'glossary' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), 'index' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), 'legalnotice' => 'format_legalnotice_chunk', 'part' => 'format_container_chunk', 'preface' => 'format_chunk', 'refentry' => 'format_chunk', 'reference' => 'format_container_chunk', 'sect1' => 'format_section_chunk', 'section' => array( /* DEFAULT */ false, 'sect1' => 'format_section_chunk', 'preface' => 'format_section_chunk', 'chapter' => 'format_section_chunk', 'appendix' => 'format_section_chunk', 'article' => 'format_section_chunk', 'part' => 'format_section_chunk', 'reference' => 'format_section_chunk', 'refentry' => 'format_section_chunk', 'index' => 'format_section_chunk', 'bibliography' => 'format_section_chunk', 'glossary' => 'format_section_chunk', 'colopone' => 'format_section_chunk', 'book' => 'format_section_chunk', 'set' => 'format_section_chunk', 'setindex' => 'format_section_chunk', 'legalnotice' => 'format_section_chunk', ), 'set' => 'format_container_chunk', 'setindex' => 'format_chunk', 'title' => 'format_ldesc', 'refpurpose' => 'format_ldesc', 'refname' => 'format_refname', 'titleabbrev' => 'format_sdesc', ); private $mytextmap = array( ); private $chunks = array(); public function transformFromMap($open, $tag, $name, $attrs, $props) { } public function TEXT($value) { } public function CDATA($value) { } public function createLink($for, &$desc = null, $desc = PhDFormat::SDESC) { } public function appendData($data) { } public function update($event, $value = null) { switch($event) { case PhDRender::CHUNK: $this->flags = $value; break; case PhDRender::STANDALONE: if ($value) { $this->registerElementMap(static::getDefaultElementMap()); $this->registerTextMap(static::getDefaultTextMap()); } break; case PhDRender::INIT: if ($value) { if (file_exists("index.sqlite")) { unlink("index.sqlite"); } $db = sqlite_open("index.sqlite"); sqlite_exec($db, 'PRAGMA default_synchronous=OFF'); sqlite_exec($db, 'PRAGMA count_changes=OFF'); sqlite_exec($db, 'PRAGMA cache_size=100000'); $create = <<<SQL CREATE TABLE ids ( docbook_id TEXT PRIMARY KEY, filename TEXT, parent_id TEXT, sdesc TEXT, ldesc TEXT, element TEXT ); SQL; sqlite_exec($db, 'PRAGMA default_synchronous=OFF'); sqlite_exec($db, 'PRAGMA count_changes=OFF'); sqlite_exec($db, 'PRAGMA cache_size=100000'); sqlite_exec($db, $create); $this->db = $db; $this->chunks = array(); } else { //print_r($this->chunks); } } } public function getDefaultElementMap() { return $this->myelementmap; } public function getDefaultTextMap() { return $this->mytextmap; } public function UNDEF($open, $name, $attrs, $props) { if ($open) { if(!isset($attrs[PhDReader::XMLNS_XML]["id"])) { return false; } $id = $attrs[PhDReader::XMLNS_XML]["id"]; $this->storeInfo($name, $id, $this->currentchunk); return false; } if(!isset($attrs[PhDReader::XMLNS_XML]["id"])) { return false; } $this->appendID(); return false; } protected function storeInfo($elm, $id, $filename) { $this->nfo[$id] = array( "parent" => "", "filename" => $filename, "sdesc" => "", "ldesc" => "", "element" => $elm, "children" => array(), ); $this->ids[] = $id; $this->currentid = $id; } public function appendID() { static $rand = 0; $lastchunkid = array_pop($this->ids); $parentid = end($this->ids); $this->currentid = $parentid; $a = $this->nfo[$lastchunkid]; if (is_array($a["sdesc"])) { $array = true; $sdesc = array_shift($a["sdesc"]); } else { $array = false; $sdesc = $a["sdesc"]; } $this->commit .= sprintf( "INSERT INTO ids (docbook_id, filename, parent_id, sdesc, ldesc, element) VALUES('%s', '%s', '%s', '%s', '%s', '%s');\n", sqlite_escape_string($lastchunkid), sqlite_escape_string($a["filename"]), sqlite_escape_string($this->currentchunk), sqlite_escape_string($sdesc), sqlite_escape_string($a["ldesc"]), sqlite_escape_string($a["element"]) ); if ($array === true && !empty($a["sdesc"])) { foreach($a["sdesc"] as $sdesc) { ++$rand; $this->commit .= sprintf( "INSERT INTO ids (docbook_id, filename, parent_id, sdesc, ldesc, element) VALUES('%s', '%s', '', '%s', '%s', '%s');\n", "phdgen-" . $rand, sqlite_escape_string($a["filename"]), sqlite_escape_string($sdesc), sqlite_escape_string($a["ldesc"]), sqlite_escape_string($a["element"]) ); } } } public function format_section_chunk($open, $name, $attrs, $props) { static $a = array(); if ($open) { $a[] = $props["sibling"]; if ($props["sibling"] === $name) { return $this->format_chunk($open, $name, $attrs, $props); } return $this->UNDEF($open, $name, $attrs, $props); } $x = array_pop($a); if ($x == $name) { return $this->format_chunk($open, $name, $attrs, $props); } $a[] = $x; return $this->UNDEF($open, $name, $attrs, $props); } public function format_container_chunk($open, $name, $attrs, $props) { return $this->format_chunk($open, $name, $attrs, $props); } public function format_chunk($open, $name, $attrs, $props) { if ($open) { if(isset($attrs[PhDReader::XMLNS_XML]["id"])) { $id = $attrs[PhDReader::XMLNS_XML]["id"]; } else { $id = uniqid("phd"); } $this->chunks[] = $id; $this->currentchunk = $id; $this->storeInfo($name, $id, $id); $this->notify(PhDRender::CHUNK, PhDRender::OPEN); return false; } array_pop($this->chunks); $this->currentchunk = end($this->chunks); $this->notify(PhDRender::CHUNK, PhDRender::CLOSE); $this->appendID(); return false; } public function format_legalnotice_chunk($open, $name, $attrs, $props) { return $this->format_chunk($open, $name, $attrs, $props); } public function format_ldesc($open, $name, $attrs, $props) { if ($open) { if (empty($this->nfo[$this->currentid]["ldesc"])) { /* FIXME: How can I mark that node with "reparse" flag? */ $s = $this->getReader()->readInnerXml(); $this->nfo[$this->currentid]["ldesc"] = $s; } } } public function format_sdesc($open, $name, $attrs, $props) { if ($open) { if (empty($this->nfo[$this->currentid]["sdesc"])) { /* FIXME: How can I mark that node with "reparse" flag? */ $s = $this->getReader()->readInnerXml(); $this->nfo[$this->currentid]["sdesc"] = $s; } } } public function format_refname($open, $name, $attrs, $props) { if ($open) { $s = $this->getReader()->readInnerXml(); $s = str_replace(array("_", "::", "->"), array("-", "-", "-"), $s); $this->nfo[$this->currentid]["sdesc"][] = strtolower($s); } } public function commit() { var_dump(sqlite_exec($this->db, 'BEGIN TRANSACTION; '.$this->commit.' COMMIT')); $this->commit = null; } } http://cvs.php.net/viewvc.cgi/phd/include/PhDObjectStorage.class.php?view=markup&rev=1.1 Index: phd/include/PhDObjectStorage.class.php +++ phd/include/PhDObjectStorage.class.php <?php class PhDObjectStorage extends SplObjectStorage { protected static $r = array(); public function attach($obj, $inf = array()) { if (!($obj instanceof PhDFormat)) { throw new InvalidArgumentException("Only classess inheriting PhDFormat supported"); } if (empty($inf)) { $inf = array( XMLReader::ELEMENT => $obj->getElementMap(), XMLReader::TEXT => $obj->getTextMap(), ); } parent::attach($obj, $inf); } final protected static function setReader(PhDReader $r) { self::$r[] = $r; } final protected function getReader() { return end(self::$r); } final protected function popReader() { return array_pop(self::$r); } } http://cvs.php.net/viewvc.cgi/phd/include/PhDRender.class.php?view=markup&rev=1.1 Index: phd/include/PhDRender.class.php +++ phd/include/PhDRender.class.php <?php class PhDRender extends PhDObjectStorage { const CHUNK = 0x001; const OPEN = 0x002; const CLOSE = 0x004; const STANDALONE = 0x008; const INIT = 0x010; private $STACK = array(); public function __construct() { /* {{{ */ } /* }}} */ public function notXPath($tag, $depth) { /* {{{ */ do { if (isset($tag[$this->STACK[--$depth]])) { $tag = $tag[$this->STACK[$depth]]; } else { $tag = $tag[0]; } } while (is_array($tag)); return $tag; } /* }}} */ public function attach($obj, $inf = array()) { /* {{{ */ if (!($obj instanceof PhDFormat)) { throw new InvalidArgumentException("All formats *MUST* inherit PhDFormat"); } $obj->notify(PhDRender::STANDALONE, true); return parent::attach($obj, $inf); } /* }}} */ public function render(PhDReader $r) { /* {{{ */ PhDObjectStorage::setReader($r); foreach($this as $format) { $format->notify(PhDRender::INIT, true); } $lastdepth = -1; while($r->read()) { $type = $r->nodeType; $data = $retval = $name = $open = false; switch($type) { case XMLReader::ELEMENT: /* {{{ */ $open = true; /* break intentionally omitted */ case XMLReader::END_ELEMENT: $name = $r->name; $depth = $r->depth; $attrs = array( PhDReader::XMLNS_DOCBOOK => array(), PhDReader::XMLNS_XML => array(), ); if ($r->hasAttributes) { $r->moveToFirstAttribute(); do { $k = $r->namespaceURI; $attrs[!empty($k) ? $k : PhDReader::XMLNS_DOCBOOK][$r->localName] = $r->value; } while ($r->moveToNextAttribute()); $r->moveToElement(); } $props = array( "empty" => $r->isEmptyElement, "isChunk" => false, "lang" => $r->xmlLang, "ns" => $r->namespaceURI, "sibling" => $lastdepth >= $depth ? $this->STACK[$depth] : "", "depth" => $depth, ); $this->STACK[$depth] = $name; foreach($this as $format) { $map = $this[$format][XMLReader::ELEMENT]; if (isset($map[$name]) === false) { $data = $format->UNDEF($open, $name, $attrs, $props); $format->appendData($data); continue; } $tag = $map[$name]; if (is_array($tag)) { $tag = $this->notXPath($tag, $depth); } if ($tag === false) { $data = $format->UNDEF($open, $name, $attrs, $props); $format->appendData($data); continue; } if (strncmp($tag, "format_", 7) !== 0) { $data = $retval = $format->transformFromMap($open, $tag, $name, $attrs, $props); } else { $data = $retval = $format->{$tag}($open, $name, $attrs, $props); } $format->appendData($data); foreach($format as $theme) { $map = $format[$theme][XMLReader::ELEMENT]; if (isset($map[$name])) { $tag = $map[$name]; if (is_array($tag)) { $tag = $this->notXPath($tag, $depth); } if ($tag !== false) { $retval = $theme->{$tag}($open, $name, $attrs, $props); if ($retval !== false) { $data = $retval; } } } $theme->appendData($data); } } $lastdepth = $depth; break; /* }}} */ case XMLReader::TEXT: /* {{{ */ $value = $r->value; $eldepth = $r->depth - 1; $name = $this->STACK[$eldepth]; foreach($this as $format) { $map = $this[$format][XMLReader::TEXT]; if (isset($map[$name])) { $tag = $map[$name]; if (is_array($tag)) { $tag = $this->notXPath($tag, $eldepth); } if ($tag !== false) { $data = $retval = $format->{$tag}($value, $name); } else { $data = $retval = $format->TEXT($value); } } else { $data = $retval = $format->TEXT($value); } if ($data === false) { $format->appendData($value); } else { $format->appendData($data); } foreach($format as $theme) { $map = $format[$theme][XMLReader::TEXT]; if (isset($map[$name])) { $tag = $map[$name]; if (is_array($tag)) { $tag = $this->notXPath($tag, $eldepth); } if ($tag !== false) { $retval = $format->{$tag}($value, $name); if ($retval !== false) { $data = $retval; } } } $theme->appendData($data); } } break; /* }}} */ case XMLReader::CDATA: /* {{{ */ /* Different formats may want to escape the CDATA sections differently */ $value = $r->value; foreach($this as $format) { $retval = $format->CDATA($value); $format->appendData($retval); foreach($format as $theme) { $theme->appendData($retval); } } break; /* }}} */ case XMLReader::WHITESPACE: /* {{{ */ case XMLReader::SIGNIFICANT_WHITESPACE: /* WS is always WS */ $retval = $r->value; foreach($this as $format) { $format->appendData($retval); foreach($format as $theme) { $theme->appendData($retval); } } break; /* }}} */ } } /* Closing time */ foreach($this as $format) { //$format->notify(PhDRender::INIT, false); } $r->close(); PhDObjectStorage::popReader(); } /* }}} */ }
http://cvs.php.net/viewvc.cgi/phd/render.php?r1=1.1&r2=1.2&diff_format=u Index: phd/render.php diff -u /dev/null phd/render.php:1.2 --- /dev/null Mon Jul 28 22:40:57 2008 +++ phd/render.php Mon Jul 28 22:40:56 2008 @@ -0,0 +1,73 @@ +<?php + +require "include/PhDObjectStorage.class.php"; +require "include/PhDConfig.class.php"; + +require "include/PhDReader.class.php"; +require "include/PhDRender.class.php"; +require "include/PhDFormat.class.php"; +require "include/PhDIndex.class.php"; + +require "formats/xhtml.php"; +require "formats/bigxhtml.php"; +require "formats/php.php"; + +$INDEX = "/home/bjori/php/doc/.manual.xml"; +$FILENAME = "/home/bjori/php/doc/.manual.xml"; +//$INDEX = $FILENAME = "/home/bjori/php/cleandocs/json.xml"; +define("NO_SQLITE", false); + +PhDConfig::init(array( + "verbose" => VERBOSE_ALL^(VERBOSE_PARTIAL_CHILD_READING|VERBOSE_CHUNK_WRITING), + "lang_dir" => __DIR__ . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "langs" . DIRECTORY_SEPARATOR, + "output_dir" => __DIR__ . DIRECTORY_SEPARATOR . "output" . DIRECTORY_SEPARATOR, + + "phpweb_version_filename" => dirname($FILENAME) . DIRECTORY_SEPARATOR . 'phpbook' . DIRECTORY_SEPARATOR . 'phpbook-xsl/' . 'version.xml', + "phpweb_acronym_filename" => dirname($FILENAME) . DIRECTORY_SEPARATOR . 'entities' . DIRECTORY_SEPARATOR . 'acronyms.xml', +)); + +$render = new PhDRender(); + +$reader = new PhDReader(); + +foreach(range(0, 0) as $i) { + var_dump(date(DATE_RSS)); + + if (1) { + // Create indexer + $format = new PhDIndex(); + $render->attach($format); + + $reader->open($INDEX); + $render->render($reader); + + $format->commit(); + $render->detach($format); + + var_dump(date(DATE_RSS)); + } + + // Standalone phpweb Format + $xhtml = new PhDPHPFormat(); + $render->attach($xhtml); + + /* + // Standalone Chunked xHTML Format + $xhtml = new PhDXHTMLFormat(); + $render->attach($xhtml); + + // Use the markup from the Chunked xHTML Format to produce Big xHTML + $bightml = new PhDBigXHTMLFormat(); + $xhtml->attach($bightml); + + // Standalone Big xHTML Format + $bightml = new PhDBigXHTMLFormat(); + $render->attach($bightml); + */ +} + +foreach(range(0, 0) as $i) { + $reader->open($FILENAME); + $render->render($reader); +} + http://cvs.php.net/viewvc.cgi/phd/README?r1=1.9&r2=1.9.6.1&diff_format=u Index: phd/README diff -u phd/README:1.9 phd/README:1.9.6.1 --- phd/README:1.9 Sat May 3 15:14:21 2008 +++ phd/README Mon Jul 28 22:40:56 2008 @@ -1,13 +1,13 @@ PhD - PHP DocBook Copyright(c) 2007-2008 The PHP Documentation Team All Rights Reserved. -$Id: README,v 1.9 2008/05/03 15:14:21 bjori Exp $ +$Id: README,v 1.9.6.1 2008/07/28 22:40:56 bjori Exp $ At the moment, the code depends upon the following: - PHP 5.2.3 or later. PHP 5.3 is recommended. PHP 6 is unsupported, but might work. - An available CLI binary. - - DOM, libXML2, and xmlreader. + - DOM, libXML2 (20620 or greater), and xmlreader. Installing the PhD renderer: http://cvs.php.net/viewvc.cgi/phd/formats/php.php?r1=1.2&r2=1.3&diff_format=u Index: phd/formats/php.php diff -u /dev/null phd/formats/php.php:1.3 --- /dev/null Mon Jul 28 22:40:57 2008 +++ phd/formats/php.php Mon Jul 28 22:40:57 2008 @@ -0,0 +1,356 @@ +<?php +class PhDPHPFormat extends PhDXHTMLFormat { + private $myelementmap = array( + 'acronym' => 'format_suppressed_tags', + 'function' => 'format_suppressed_tags', + 'link' => 'format_link', + 'refpurpose' => 'format_refpurpose', + 'varname' => array( + /* DEFAULT */ 'var', + 'fieldsynopsis' => 'format_fieldsynopsis_varname', + ), + 'xref' => 'format_xref', + + + '.title' => array( + /* DEFAULT */ false, + 'info' => array( + /* DEFAULT */ false, + 'article' => 'format_container_chunk_top_title', + 'appendix' => 'format_container_chunk_top_title', + 'book' => 'format_container_chunk_top_title', + 'chapter' => 'format_container_chunk_top_title', + 'part' => 'format_container_chunk_top_title', + 'set' => 'format_container_chunk_top_title', + ), + 'article' => 'format_container_chunk_top_title', + 'appendix' => 'format_container_chunk_top_title', + 'book' => 'format_container_chunk_top_title', + 'chapter' => 'format_container_chunk_top_title', + 'part' => 'format_container_chunk_top_title', + 'set' => 'format_container_chunk_top_title', + ), + '.reference' => 'format_container_chunk_below', + '.question' => array( + /* DEFAULT */ false, + 'questions' => 'format_phd_question', // From the PhD namespace + ), + ); + private $mytextmap = array( + 'acronym' => 'format_acronym_text', + 'function' => 'format_function_text', + 'methodname' => array( + /* DEFAULT */ 'format_function_text', + 'constructorsynopsis' => array( + /* DEFAULT */ 'format_function_text', + 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', + ), + 'methodsynopsis' => array( + /* DEFAULT */ 'format_function_text', + 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', + ), + 'destructorsynopsis' => array( + /* DEFAULT */ 'format_function_text', + 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', + ), + ), + + 'refname' => 'format_refname_text', + 'type' => array( + /* DEFAULT */ 'format_type_text', + 'classsynopsisinfo' => false, + 'fieldsynopsis' => 'format_type_if_object_or_pseudo_text', + 'methodparam' => 'format_type_if_object_or_pseudo_text', + 'methodsynopsis' => array( + /* DEFAULT */ 'format_type_if_object_or_pseudo_text', + 'classsynopsis' => false, + ), + ), + + ); + protected $flags; + protected $ext = "php"; + private $acronyms = array(); + private $versions = array(); + private $refname = ""; + + public function __construct() { + parent::__construct(); + $this->versions = self::generateVersionInfo(PhDConfig::get("phpweb_version_filename")); + $this->acronyms = self::generateAcronymInfo(PhDConfig::get("phpweb_acronym_filename")); + + } + + public function header($id) { + /* Yes. This is scary. I know. */ + return '<?php +include_once $_SERVER[\'DOCUMENT_ROOT\'] . \'/include/shared-manual.inc\'; +$setup = array( + "home" => array("index.php", "PHP Manual"), + "head" => array("UTF-8", "en"), + "this" => array(null, null), + "up" => array(null, null), + "prev" => array(null, null), + "next" => array(null, null), + "toc" => array(), + "parents" => array(), +); +manual_setup($setup); + +manual_header(); +?> +'; + } + public function footer($id) { + return "<?php manual_footer(); ?>"; + } + + + public function getDefaultElementMap() { + return $this->myelementmap; + } + public function getDefaultTextMap() { + return $this->mytextmap; + } + + + public function format_suppressed_tags($open, $name, $attrs, $props) { + return ""; + } + public function update($event, $val = null) { + switch($event) { + case PhDRender::CHUNK: + $this->flags = $val; + break; + + case PhDRender::STANDALONE: + if ($val) { + $this->registerElementMap(array_merge(parent::getDefaultElementMap(), static::getDefaultElementMap())); + $this->registerTextMap(array_merge(parent::getDefaultTextMap(), static::getDefaultTextMap())); + } else { + $this->registerElementMap(static::getDefaultElementMap()); + $this->registerTextMap(static::getDefaultTextMap()); + } + break; + } + } + public function format_suppressed_text($value, $tag) { + return ""; + } + + protected function lookupRefname($for) { + return $this->refs[$for]; + return NO_SQLITE; + $rsl = sqlite_array_query($this->sqlite, "SELECT filename, ldesc, sdesc FROM ids WHERE sdesc='$for' AND element='refentry'", SQLITE_ASSOC); + if (isset($rsl[0])) { + return $rsl[0]["filename"]; + } + return false; + } + public static function generateVersionInfo($filename) { + static $info; + if ($info) { + return $info; + } + $r = new XMLReader; + if (!$r->open($filename)) { + throw new Exception; + } + $versions = array(); + while($r->read()) { + if ( + $r->moveToAttribute("name") + && ($funcname = str_replace( + array("::", "->", "__", "_", '$'), + array("-", "-", "-", "-", ""), + $r->value)) + && $r->moveToAttribute("from") + && ($from = $r->value) + ) { + $versions[strtolower($funcname)] = $from; + $r->moveToElement(); + } + } + $r->close(); + $info = $versions; + return $versions; + } + public static function generateAcronymInfo($filename) { + static $info; + if ($info) { + return $info; + } + $r = new XMLReader; + if (!$r->open($filename)) { + throw new Exception("Could not open $filename"); + } + $acronyms = array(); + while ($r->read()) { + if ($r->nodeType != XMLReader::ELEMENT) { + continue; + } + if ($r->name == "term") { + $r->read(); + $k = $r->value; + $acronyms[$k] = ""; + } else if ($r->name == "simpara") { + $r->read(); + $acronyms[$k] = $r->value; + } + } + $info = $acronyms; + return $acronyms; + } + public function versionInfo($funcname) { + $funcname = str_replace( + array("::", "->", "__", "_", '$', '()'), + array("-", "-", "-", "-", "", ''), + strtolower($funcname)); + return isset($this->versions[$funcname]) ? $this->versions[$funcname] : "No version information available, might be only in CVS"; + } + public function acronymInfo($acronym) { + return isset($this->acronyms[$acronym]) ? $this->acronyms[$acronym] : false; + } + + + public function format_acronym_text($value, $tag) { + $resolved = $this->acronymInfo($value); + if ($resolved) { + return '<acronym title="' .$resolved. '">' .$value. '</acronym>'; + } + return '<acronym>'.$value.'</acronym>'; + } + public function format_refpurpose($open, $tag, $attrs, $props) { + if ($open) { + return '<p class="verinfo">(' .(htmlspecialchars($this->versionInfo($this->refname), ENT_QUOTES, "UTF-8")). ')</p><p class="refpurpose dc-title">'. $this->refname. ' â '; + } + return "</p>\n"; + } + public function format_fieldsynopsis_varname($open, $name, $attrs) { + if ($open) { + $href = ""; + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { + $href = $this->createLink($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"]); + + $href = '<a href="' .$href. '">'; + } + if ($this->cchunk["fieldsynopsis"]["modifier"] == "const") { + return '<var class="fieldsynopsis_varname">'.$href; + } + return '<var class="'.$name.'">'.$href.'$'; + } + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { + return '</a></var>'; + } + return '</var>'; + } + + + public function format_refname_text($value, $tag) { + $this->refname = $value; + return false; + } + public function format_function_text($value, $tag, $display_value = null) { + if ($display_value === null) { + $display_value = $value; + } + + $ref = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $value)); + + $filename = $this->lookupRefname($ref); + + if (($filename !== false) && $this->CURRENT_CHUNK !== $filename) { + $desc = ""; + $href = $this->createLink($filename, $desc); + return '<a href="' . $href . '" class="function" title="' . $desc . '">' . $display_value . ($tag == "function" ? "()" : ""). '</a>'; + } + return '<strong>' . $display_value . ($tag === "function" ? "()" : ""). '</strong>'; + } + public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag) { + $value = $this->TEXT($value); + if ($this->cchunk["classsynopsis"]["classname"] === false) { + return $this->format_function_text($value, $tag); + } + if (strpos($value, '::')) { + $explode = '::'; + } elseif (strpos($value, '->')) { + $explode = '->'; + } else { + return $this->format_function_text($value, $tag); + } + + list($class, $method) = explode($explode, $value); + if ($class !== $this->cchunk["classsynopsis"]["classname"]) { + return $this->format_function_text($value, $tag); + } + return $this->format_function_text($value, $tag, $method); + } + public function format_type_if_object_or_pseudo_text($value, $tag) { + if (in_array(strtolower($value), array("bool", "int", "double", "boolean", "integer", "float", "string", "array", "object", "resource", "null"))) { + return false; + } + return self::format_type_text($value, $tag); + } + public function format_type_text($value, $tag) { + $t = strtolower($value); + + switch($t) { + case "bool": + $id = "language.types.boolean"; + break; + + case "int": + case "long": + $id = "language.types.integer"; + break; + + case "double": + $id = "language.types.float"; + break; + + /* FIXME: These aren't documented yet */ + case "binary": + case "unicode": + $id = "language.types.string"; + break; + + case "void": + case "boolean": + case "integer": + case "float": + case "string": + case "array": + case "object": + case "resource": + case "null": + $id = "language.types.$t"; + break; + + case "mixed": + case "number": + case "callback": + $id = "language.types.$t"; + break; + + default: + /* Check if its a classname. */ + $t = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $t)); + $id = "class.$t"; + } + + $desc = ""; + $href = $this->createLink($id, $desc); + + if ($href) { + return '<a href="' .$href. '" class="' .$tag. ' ' .$value. '" title="' . $desc . '">' .$value. '</a>'; + } + return '<span class="' .$tag. ' ' .$value. '">' .$value. '</span>'; + } + +} + +/* + * vim600: sw=4 ts=4 fdm=syntax syntax=php et + * vim<600: sw=4 ts=4 + */ + http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.68&r2=1.68.2.1&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.68 phd/formats/xhtml.php:1.68.2.1 --- phd/formats/xhtml.php:1.68 Wed Jul 9 22:57:06 2008 +++ phd/formats/xhtml.php Mon Jul 28 22:40:57 2008 @@ -1,20 +1,19 @@ <?php -/* $Id: xhtml.php,v 1.68 2008/07/09 22:57:06 loudi Exp $ */ - -class XHTMLPhDFormat extends PhDFormat { - protected $elementmap = array( /* {{{ */ +/* $Id: xhtml.php,v 1.68.2.1 2008/07/28 22:40:57 bjori Exp $ */ +class PhDXHTMLFormat extends PhDFormat { + private $myelementmap = array( /* {{{ */ 'abstract' => 'div', /* Docbook-xsl prints "abstract"... */ 'abbrev' => 'abbr', 'acronym' => 'acronym', 'affiliation' => 'format_suppressed_tags', 'alt' => 'format_suppressed_tags', - 'article' => 'format_container_chunk', + 'article' => 'format_container_chunk_top', 'author' => array( /* DEFAULT */ 'format_author', 'authorgroup' => 'format_authorgroup_author', ), 'authorgroup' => 'div', - 'appendix' => 'format_container_chunk', + 'appendix' => 'format_container_chunk_top', 'application' => 'span', 'blockquote' => 'blockquote', 'bibliography' => array( @@ -23,14 +22,15 @@ 'book' => 'format_chunk', 'part' => 'format_chunk', ), - 'book' => 'format_container_chunk', - 'chapter' => 'format_container_chunk', + 'book' => 'format_container_chunk_top', + 'chapter' => 'format_container_chunk_top', 'citetitle' => 'i', 'co' => 'format_co', 'colophon' => 'format_chunk', 'copyright' => 'format_copyright', 'date' => 'p', 'editor' => 'format_editor', + 'function' => 'b', 'email' => 'format_suppressed_tags', 'firstname' => 'format_name', 'footnote' => 'format_footnote', @@ -127,7 +127,7 @@ 'indexentry' => 'dd', 'initializer' => 'format_initializer', 'itemizedlist' => 'ul', - 'legalnotice' => 'format_legalnotice_chunk', + 'legalnotice' => 'format_chunk', 'listitem' => array( /* DEFAULT */ 'li', 'varlistentry' => 'format_varlistentry_listitem', @@ -135,6 +135,8 @@ 'link' => 'a', 'literal' => 'format_literal', 'literallayout' => 'pre', + 'link' => 'format_link', + 'xref' => 'format_xref', 'manvolnum' => 'format_manvolnum', 'mediaobject' => 'format_mediaobject', 'methodparam' => 'format_methodparam', @@ -162,13 +164,14 @@ 'note' => 'format_note_content', 'footnote' => 'format_footnote_para', 'refsect1' => 'format_refsect1_para', + 'question' => 'format_suppressed_tags', ), 'paramdef' => 'format_suppressed_tags', 'parameter' => array( /* DEFAULT */ 'format_parameter', 'methodparam' => 'format_methodparam_parameter', ), - 'part' => 'format_container_chunk', + 'part' => 'format_container_chunk_top', 'partintro' => 'div', 'personname' => 'format_personname', 'personblurb' => 'div', @@ -188,7 +191,8 @@ 'pubdate' => 'div', /* Docbook-XSL prints "published" */ 'refentry' => 'format_chunk', 'refentrytitle' => 'span', - 'reference' => 'format_container_chunk', + 'refpurpose' => 'p', + 'reference' => 'format_container_chunk_below', 'refsect1' => 'format_refsect', 'refsect2' => 'format_refsect', 'refsect3' => 'format_refsect', @@ -199,17 +203,35 @@ 'replaceable' => 'span', 'row' => 'format_row', 'screen' => 'format_screen', - 'sect1' => 'format_chunk', - 'sect2' => 'format_chunk', - 'sect3' => 'format_chunk', - 'sect4' => 'format_chunk', - 'sect5' => 'format_chunk', - 'section' => 'format_chunk', + 'sect1' => 'format_section_chunk', + 'sect2' => 'div', + 'sect3' => 'div', + 'sect4' => 'div', + 'sect5' => 'div', + 'section' => array( + /* DEFAULT */ 'div', + 'sect1' => 'format_section_chunk', + 'preface' => 'format_section_chunk', + 'chapter' => 'format_section_chunk', + 'appendix' => 'format_section_chunk', + 'article' => 'format_section_chunk', + 'part' => 'format_section_chunk', + 'reference' => 'format_section_chunk', + 'refentry' => 'format_section_chunk', + 'index' => 'format_section_chunk', + 'bibliography' => 'format_section_chunk', + 'glossary' => 'format_section_chunk', + 'colopone' => 'format_section_chunk', + 'book' => 'format_section_chunk', + 'set' => 'format_section_chunk', + 'setindex' => 'format_section_chunk', + 'legalnotice' => 'format_section_chunk', + ), 'seg' => 'format_seg', 'segmentedlist' => 'format_segmentedlist', 'seglistitem' => 'format_seglistitem', 'segtitle' => 'format_suppressed_tags', - 'set' => 'format_chunk', + 'set' => 'format_container_chunk_top', 'setindex' => 'format_chunk', 'shortaffil' => 'format_suppressed_tags', 'simplelist' => 'ul', /* FIXME: simplelists has few attributes that need to be implemented */ @@ -237,14 +259,22 @@ 'tip' => 'format_admonition', 'title' => array( /* DEFAULT */ 'h1', - 'example' => 'format_bold_paragraph', + 'example' => 'format_example_title', 'formalpara' => 'h5', 'info' => array( /* DEFAULT */ 'h1', - 'example' => 'format_bold_paragraph', + 'example' => 'format_example_title', 'note' => 'format_note_title', 'table' => 'format_table_title', 'informaltable' => 'format_table_title', + + 'article' => 'format_container_chunk_top_title', + 'appendix' => 'format_container_chunk_top_title', + 'book' => 'format_container_chunk_top_title', + 'chapter' => 'format_container_chunk_top_title', + 'part' => 'format_container_chunk_top_title', + 'set' => 'format_container_chunk_top_title', + ), 'indexdiv' => 'dt', 'legalnotice' => 'h4', @@ -261,7 +291,13 @@ 'segmentedlist' => 'strong', 'table' => 'format_table_title', 'variablelist' => 'strong', - ), + 'article' => 'format_container_chunk_top_title', + 'appendix' => 'format_container_chunk_top_title', + 'book' => 'format_container_chunk_top_title', + 'chapter' => 'format_container_chunk_top_title', + 'part' => 'format_container_chunk_top_title', + 'set' => 'format_container_chunk_top_title', + ), 'titleabbrev' => 'format_suppressed_tags', 'type' => 'span', 'userinput' => 'format_userinput', @@ -276,13 +312,16 @@ 'xref' => 'a', 'year' => 'span', 'quote' => 'format_quote', - 'qandadiv' => 'div', - 'qandaset' => 'div', + 'qandaset' => 'format_qandaset', 'qandaentry' => 'dl', - 'question' => 'dt', + 'question' => array( + /* DEFAULT */ 'format_question', + 'questions' => 'format_phd_question', // From the PhD namespace + ), + 'questions' => 'ol', // From the PhD namespace 'answer' => 'dd', ); /* }}} */ - protected $textmap = array( + private $mytextmap = array( 'segtitle' => 'format_segtitle_text', 'affiliation' => 'format_suppressed_text', 'contrib' => 'format_suppressed_text', @@ -301,21 +340,6 @@ 'classsynopsis' => 'format_classsynopsis_ooclass_classname_text', ), ), - 'methodname' => array( - /* DEFAULT */ false, - 'constructorsynopsis' => array( - /* DEFAULT */ false, - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - 'methodsynopsis' => array( - /* DEFAULT */ false, - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - 'destructorsynopsis' => array( - /* DEFAULT */ false, - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - ), 'para' => array( /* DEFAULT */ false, 'footnote' => 'format_footnote_para_text', @@ -347,6 +371,7 @@ "implements" => false, "ooclass" => false, ), + "examples" => 0, "fieldsynopsis" => array( "modifier" => "public", ), @@ -367,16 +392,13 @@ "tablefootnotes" => array( ), ); - - public function __construct(array $IDs) { - parent::__construct($IDs); - } - public function __call($func, $args) { - if ($args[0]) { - trigger_error("No mapper found for '{$func}'", E_USER_WARNING); - return "<font color='red' size='+3'>{$args[1]}</font>"; - } - return "<font color='red' size='+3'>/{$args[1]}</font>"; + + protected $flags; + protected $ext = "html"; + protected $fp = array(); + + public function __construct() { + parent::__construct(); } public function transformFromMap($open, $tag, $name, $attrs, $props) { if ($open) { @@ -389,6 +411,168 @@ } return '</' .$tag. '>'; } + + public function appendData($data) { + if ($this->flags & PhDRender::CLOSE) { + $fp = array_pop($this->fp); + fwrite($fp, $data); + $this->writeChunk($this->CURRENT_CHUNK, $fp); + fclose($fp); + + $this->flags ^= PhDRender::CLOSE; + } elseif ($this->flags & PhDRender::OPEN) { + $this->fp[] = $fp = fopen("php://temp/maxmemory", "r+"); + fwrite($fp, $data); + + $this->flags ^= PhDRender::OPEN; + } else { + $fp = end($this->fp); + fwrite($fp, $data); + } + } + public function header($id) { + $title = $this->getLongDescription($id); + $lang = $this->CURRENT_LANG; + + $prev = $next = $parent = array("href" => null, "desc" => null); + /* {{{ FIXME: This is a complete fuckup */ + $ok = false; + $count = count($this->CHILDRENS)-1; + foreach($this->CHILDRENS as $row => $data) { + if ($data["filename"] === $id) { + if ($row != 0) { + $prev = array("href" => $this->CHILDRENS[$row-1]["filename"]. '.' .$this->ext, "desc" => $this->CHILDRENS[$row-1]["ldesc"] ?: $this->CHILDRENS[$row-1]["sdesc"]); + } + if ($row != $count) { + $next = array("href" => $this->CHILDRENS[$row+1]["filename"]. '.' .$this->ext, "desc" => $this->CHILDRENS[$row+1]["ldesc"] ?: $this->CHILDRENS[$row+1]["sdesc"]); + } + $ok = true; + break; + } + } + if (!$ok) { + //var_dump($id, $this->CHILDRENS); + //echo "\n\n"; + } + $row = $this->getParentInfo($id); + if (isset($row[0])) { + $parent = array("href" => $row[0]["filename"]. '.' .$this->ext, "desc" => $row[0]["ldesc"] ?: $row[0]["sdesc"]); + } + /* }}} */ + + return +'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' .$lang. '"" lang="' .$lang. '"> +<head> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"> + <title>PHP: '.$title.'</title> +</head> +<body> +<div style="text-align: center;"> + <div class="prev" style="float: left;"><a href="' .$prev["href"]. '">' .$prev["desc"]. '</a></div> + <div class="next" style="float: right;"><a href="' .$next["href"]. '">' .$next["desc"] .'</a></div> + <div class="up"><a href="' .$parent["href"]. '">' .$parent["desc"]. '</a></div> + <div class="home"><a href="index.html">PHP Manual</a></div> +</div> +'; + } + public function footer($id) { + return "\n</body>\n</html>\n"; + } + public function writeChunk($id, $fp) { + $filename = PhDConfig::get("output_dir") . $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 createLink($for, &$desc = null, $type = PhDFormat::SDESC) { + $retval = null; + if (isset($this->idx[$for])) { + $rsl = $this->idx[$for]; + $retval = $rsl["filename"] . '.' . $this->ext . '#' . $rsl["docbook_id"]; + $desc = $rsl["sdesc"] ?: $rsl["ldesc"]; + } + return $retval; + + return NO_SQLITE; + if ($desc === null) { + $rsl = sqlite_array_query($this->sqlite, "SELECT docbook_id, filename FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); + + if (!isset($rsl[0])) { + return false; + } + + $retval = $rsl[0]["filename"] . '.' . $this->ext . '#' . $rsl[0]["docbook_id"]; + } else { + $rsl = sqlite_array_query($this->sqlite, $q = "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); + + if (!isset($rsl[0])) { + var_dump($q); + return false; + } + + $retval = $rsl[0]["filename"] . '.' . $this->ext . '#' . $rsl[0]["docbook_id"]; + + if ($type === self::SDESC) { + $desc = $rsl[0]["sdesc"] ?: $rsl[0]["ldesc"]; + } else { + $desc = $rsl[0]["ldesc"] ?: $rsl[0]["sdesc"]; + } + } + + return $retval; + } + public function getLongDescription($for) { + return NO_SQLITE; + $rsl = sqlite_array_query($this->sqlite, $q = "SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); + if (!isset($rsl[0])) { + var_dump($q); + return false; + } + return $rsl[0]["ldesc"] ?: $rsl[0]["sdesc"]; + } + public function getShortDescription($for) { + return NO_SQLITE; + $rsl = sqlite_array_query($this->sqlite, "SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); + return $rsl[0]["sdesc"] ?: $rsl[0]["ldesc"]; + } + public function getParentInfo($for) { + return NO_SQLITE; + $rsl = sqlite_array_query($this->sqlite, "SELECT parent_id FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); + return sqlite_array_query($this->sqlite, "SELECT filename, sdesc, ldesc FROM ids WHERE docbook_id='{$rsl[0]["parent_id"]}'", SQLITE_ASSOC); + } + protected function createTOC($rsl) { + $toc = '<ol>'; + $desc = $title = ""; + foreach($rsl as $row) { + $link = $this->createLink($row["docbook_id"], $desc); + $list = ""; + if ($this->cchunk["name"] === "book" || $this->cchunk["name"] === "set") { + $childrens = sqlite_array_query($this->sqlite, "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='{$row["docbook_id"]}' AND filename=docbook_id", SQLITE_ASSOC); + if (NO_SQLITE && $childrens) { + $list = "<ol>"; + foreach($childrens as $child) { + $href = $this->createLink($child["docbook_id"], $title); + $list .= '<li><a href="' .$href. '">' .$title. "</a></li>\n"; + } + $list .="</ol>"; + } + } + $toc .= '<li><a href="' .$link. '">' .$desc. '</a>' .$list. "</li>\n"; + } + $toc .= "</ol>\n"; + + return $toc; + } + public function CDATA($str) { switch($this->role) { case "php": @@ -401,10 +585,41 @@ public function TEXT($str) { return htmlspecialchars($str, ENT_QUOTES, "UTF-8"); } + public function UNDEF($open, $name, $attrs, $props) { + if ($open) { + trigger_error("No mapper found for '{$name}'", E_USER_WARNING); + } + } + + public function admonition_title($title, $lang) { + return '<b class="' .(strtolower($title)). '">' .($this->autogen($title, $lang)). '</b>'; + } + public function getDefaultElementMap() { + return $this->myelementmap; + } + public function getDefaultTextMap() { + return $this->mytextmap; + } + public function update($event, $val = null) { + switch($event) { + case PhDRender::CHUNK: + $this->flags = $val; + break; + + case PhDRender::STANDALONE: + if ($val) { + $this->registerElementMap(static::getDefaultElementMap()); + $this->registerTextMap(static::getDefaultTextMap()); + } + break; + } + } + public function getChunkInfo() { return $this->cchunk; } - public function format_suppressed_tags($open, $name, $attrs) { + + public function format_suppressed_tags($open, $name, $attrs, $props) { /* Ignore it */ return ""; } @@ -412,7 +627,42 @@ /* Suppress any content */ return ""; } - + + public function format_link($open, $name, $attrs, $props) { + $link = null; + if ($open) { + $link = $class = $content = ""; + + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { + $link = $this->createLink($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"]); + } + elseif (isset($attrs[PhDReader::XMLNS_XLINK]["href"])) { + $link = $attrs[PhDReader::XMLNS_XLINK]["href"]; + $class = " external"; + $content = "» "; + } + if ($props["empty"]) { + $content .= $link ."</a>\n"; + } + + return '<a href="' . $link . '" class="' . $name . $class . '">' . $content; + } + return "</a>"; + } + public function format_xref($open, $name, $attrs, $props) { + if ($open) { + $desc = ""; + $link = $this->createLink($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"], $desc); + + $ret = '<a href="' .$link. '" class="' .$name. '">' .$desc; + + if ($props["empty"]) { + return $ret. "</a>"; + } + return $ret; + } + return "</a>"; + } public function format_literal($open, $name, $attrs) { if ($open) { if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) { @@ -439,7 +689,7 @@ return $this->TEXT($value); } } - + public function format_copyright($open, $name, $attrs) { if ($open) { return '<div class="'.$name.'">© '; @@ -487,31 +737,118 @@ return '</span> '; } - public function format_container_chunk($open, $name, $attrs) { + public function format_container_chunk_top($open, $name, $attrs, $props) { + $this->cchunk = $this->dchunk; + $this->cchunk["name"] = $name; + if(isset($attrs[PhDReader::XMLNS_XML]["id"])) { + $id = $attrs[PhDReader::XMLNS_XML]["id"]; + } else { + $id = uniqid("phd"); + } + + if ($open) { + $this->CURRENT_CHUNK = $id; + $this->notify(PhDRender::CHUNK, PhDRender::OPEN); + + return '<div id="' .$id. '" class="' .$name. '">'; + } + + $this->CURRENT_CHUNK = $id; + $this->notify(PhDRender::CHUNK, PhDRender::CLOSE); + + $toc = ""; + if (NO_SQLITE && !in_array($id, $this->TOC_WRITTEN)) { + $rsl = sqlite_array_query($this->sqlite, "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id' AND filename=docbook_id", SQLITE_ASSOC); + $toc = $this->createTOC($rsl); + } + return $toc."</div>"; + } + public function format_container_chunk_top_title($open, $name, $attrs, $props) { + if ($open) { + return '<h1>'; + } + + $id = $this->CURRENT_CHUNK; + if (NO_SQLITE) { + $this->CHILDRENS = $rsl = sqlite_array_query($this->sqlite, "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id' AND filename=docbook_id", SQLITE_ASSOC); + $toc = $this->createToc($rsl); + } else { + $this->CHILDRENS = array(); + $toc = ""; + } + $this->TOC_WRITTEN[] = $id; + + return '</h1>'.$toc; + } + public function format_container_chunk_below($open, $name, $attrs, $props) { $this->cchunk = $this->dchunk; + if(isset($attrs[PhDReader::XMLNS_XML]["id"])) { + $id = $attrs[PhDReader::XMLNS_XML]["id"]; + } else { + $id = uniqid("phd"); + } + if ($open) { + if (NO_SQLITE) { + $this->CHILDRENS = sqlite_array_query($this->sqlite, "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id' AND filename=docbook_id", SQLITE_ASSOC); + } + $this->CURRENT_CHUNK = $id; + $this->notify(PhDRender::CHUNK, PhDRender::OPEN); + return '<div id="' .$attrs[PhDReader::XMLNS_XML]["id"]. '" class="' .$name. '">'; } - return "</div>"; + + $toc = '<ol>'; + $desc = ""; + $rsl = $this->CHILDRENS; + foreach($rsl as $row) { + $link = $this->createLink($row["docbook_id"], $desc); + $toc .= '<li><a href="' .$link. '">' .$desc. "</a></li>\n"; + } + $toc .= "</ol>\n"; + + $this->CURRENT_CHUNK = $id; + $this->notify(PhDRender::CHUNK, PhDRender::CLOSE); + return $toc . '</div>'; } - public function format_legalnotice_chunk($open, $name, $attrs) { + public function format_section_chunk($open, $name, $attrs, $props) { + static $a = array(); if ($open) { - return '<div id="legalnotice">'; + $a[] = $props["sibling"]; + if ($props["sibling"] === $name) { + return $this->format_chunk($open, $name, $attrs, $props); + } + return $this->transformFromMap($open, "div", $name, $attrs, $props); } - return "</div>\n"; + $x = array_pop($a); + if ($x == $name) { + return $this->format_chunk($open, $name, $attrs, $props); + } + $a[] = $x; + return $this->transformFromMap($open, "div", $name, $attrs, $props); } - public function format_chunk($open, $name, $attrs) { + public function format_chunk($open, $name, $attrs, $props) { if ($open) { $this->cchunk = $this->dchunk; if(isset($attrs[PhDReader::XMLNS_XML]["id"])) { - $class = $name; - if ($name === "refentry") { - //$class .= " -rel-posting"; - } - return '<div id="' .$attrs[PhDReader::XMLNS_XML]["id"]. '" class="' .$class. '">'; + $id = $attrs[PhDReader::XMLNS_XML]["id"]; + } else { + $id = uniqid("phd"); + } + + $class = $name; + if ($name === "refentry") { + //$class .= " -rel-posting"; } - return '<div class="' .$name. '">'; + + $this->CURRENT_CHUNK = $id; + $this->CURRENT_LANG = $props["lang"]; + + $this->notify(PhDRender::CHUNK, PhDRender::OPEN); + return '<div id="' .$id. '" class="' .$class. '">'; } + $this->notify(PhDRender::CHUNK, PhDRender::CLOSE); + $str = ""; foreach ($this->cchunk["footnote"] as $k => $note) { $str .= '<div class="footnote">'; @@ -605,26 +942,7 @@ return $this->TEXT($value); } - public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag) { - $value = $this->TEXT($value); - if ($this->cchunk["classsynopsis"]["classname"] === false) { - return $value; - } - if (strpos($value, '::')) { - $explode = '::'; - } elseif (strpos($value, '->')) { - $explode = '->'; - } else { - return $value; - } - - list($class, $method) = explode($explode, $value); - if ($class !== $this->cchunk["classsynopsis"]["classname"]) { - return $value; - } - return $method; - } - + public function format_fieldsynopsis($open, $name, $attrs) { $this->cchunk["fieldsynopsis"] = $this->dchunk["fieldsynopsis"]; if ($open) { @@ -976,12 +1294,12 @@ } return "<br />"; } - public function format_bold_paragraph($open, $name, $attrs, $props) { + public function format_example_title($open, $name, $attrs, $props) { if ($props["empty"]) { return ""; } if ($open) { - return "<p><b>"; + return "<p><b>" . ($this->autogen('example', $props['lang']) . ++$this->cchunk["examples"]) . " "; } return "</b></p>"; } @@ -1131,9 +1449,51 @@ } return "</td>"; } + public function format_qandaset($open, $name, $attrs, $props) { + if ($open) { + $node = $this->getReader()->expand(); + $doc = new DOMDocument; + $doc->appendChild($node); - public function admonition_title($title, $lang) { - return '<b class="' .(strtolower($title)). '">' .($this->autogen($title, $lang)). '</b>'; + $xp = new DOMXPath($doc); + $xp->registerNamespace("db", PhDReader::XMLNS_DOCBOOK); + + $questions = $xp->query("//db:qandaentry/db:question"); + + $xml = '<questions xmlns="' .PhDReader::XMLNS_PHD. '">'; + foreach($questions as $node) { + $id = $xp->evaluate("ancestor::db:qandaentry", $node)->item(0)->getAttributeNs(PhDReader::XMLNS_XML, "id"); + + /* FIXME: No ID? How can we create an anchor for it then? */ + if (!$id) { + $id = uniqid("phd"); + } + + $node->setAttribute("xml:id", $id); + $xml .= $doc->saveXML($node); + } + $xml .= "</questions>"; + + $r = new PhDReader(); + $r->XML($xml); + + $render = new PhDRender; + $render->attach($this); + $render->render($r); + } + } + public function format_question($open, $name, $attrs, $props) { + if ($open) { + return '<dt><strong>'; + } + return '</strong></dt>'; + } + public function format_phd_question($open, $name, $attrs, $props) { + if ($open) { + $href = $this->createLink($attrs[PhDReader::XMLNS_XML]["id"]); + return '<li><a href="' .$href. '">'; + } + return '</a></li>'; } public function format_citation($open, $name, $attrs, $props) { http://cvs.php.net/viewvc.cgi/phd/include/PhDFormat.class.php?r1=1.10&r2=1.10.6.1&diff_format=u Index: phd/include/PhDFormat.class.php diff -u phd/include/PhDFormat.class.php:1.10 phd/include/PhDFormat.class.php:1.10.6.1 --- phd/include/PhDFormat.class.php:1.10 Mon Feb 4 21:17:25 2008 +++ phd/include/PhDFormat.class.php Mon Jul 28 22:40:57 2008 @@ -1,16 +1,117 @@ <?php -/* $Id: PhDFormat.class.php,v 1.10 2008/02/04 21:17:25 bjori Exp $ */ -abstract class PhDFormat extends PhDHelper { - private $TABLE = array(); - - /* abstract functions */ - abstract public function transformFromMap($open, $tag, $name, $attrs, $props); - abstract public function CDATA($data); - abstract public function TEXT($data); - abstract public function __call($func, $args); +abstract class PhDFormat extends PhDObjectStorage { + const SDESC = 1; + const LDESC = 2; + + private $elementmap = array(); + private $textmapmap = array(); + protected $sqlite; + + private static $autogen = array(); + + public function __construct() { + $this->sqlite = sqlite_open("index.sqlite"); + $this->sortIDs(); + } + + abstract public function transformFromMap($open, $tag, $name, $attrs, $props); + abstract public function UNDEF($open, $name, $attrs, $props); + abstract public function TEXT($value); + abstract public function CDATA($value); + abstract public function createLink($for, &$desc = null, $desc = PhDFormat::SDESC); + abstract public function appendData($data); + abstract public function update($event, $value = null); + + public function sortIDs() { + sqlite_create_aggregate($this->sqlite, "idx", array($this, "SQLiteIndex"), array($this, "SQLiteFinal"), 6); + sqlite_unbuffered_query($this->sqlite, "SELECT idx(docbook_id, filename, parent_id, sdesc, ldesc, element) FROM ids", SQLITE_ASSOC); + print_r($this->idx); + } + public function SQLiteIndex(&$context, $id, $filename, $parent, $sdesc, $ldesc, $element) { + $this->idx[$id] = array( + "docbook_id" => $id, + "filename" => $filename, + "parent_id" => $parent, + "sdesc" => $sdesc, + "ldesc" => $ldesc, + "element" => $element + ); + if ($element == "refentry") { + $this->refs[$sdesc] = $id; + } + + } + public static function SQLiteFinal(&$context) { + return $context; + } + + + final public function notify($event, $val = null) { + $this->update($event, $val); + foreach($this as $format) { + $format->update($event, $val); + } + } + final public function registerElementMap(array $map) { + $this->elementmap = $map; + } + final public function registerTextMap(array $map) { + $this->textmap = $map; + } + final public function attach($obj, $inf = array()) { + if (!($obj instanceof $this) && get_class($obj) != get_class($this)) { + throw new InvalidArgumentException(get_class($this) . " themes *MUST* _inherit_ " .get_class($this). ", got " . get_class($obj)); + } + $obj->notify(PhDRender::STANDALONE, false); + return parent::attach($obj, $inf); + } + final public function getElementMap() { + return $this->elementmap; + } + final public function getTextMap() { + return $this->textmap; + } + final public static function autogen($text, $lang) { + if (isset(self::$autogen[$lang])) { + if (isset(self::$autogen[$lang][$text])) { + return self::$autogen[$lang][$text]; + } + if ($lang == PhDConfig::get("fallback_language")) { + throw new InvalidArgumentException("Cannot autogenerate text for '$text'"); + } + return self::autogen($text, PhDConfig::get("fallback_language")); + } + + $filename = PhDConfig::get("lang_dir") . $lang . ".xml"; + + $r = new XMLReader; + if (!file_exists($filename) || !$r->open($filename)) { + if ($lang == PhDConfig::get("fallback_language")) { + throw new Exception("Cannot open $filename"); + } + return self::autogen($text, PhDConfig::get("fallback_language")); + } + $autogen = array(); + while ($r->read()) { + if ($r->nodeType != XMLReader::ELEMENT) { + continue; + } + if ($r->name == "term") { + $r->read(); + $k = $r->value; + $autogen[$k] = ""; + } else if ($r->name == "simpara") { + $r->read(); + $autogen[$k] = $r->value; + } + } + self::$autogen[$lang] = $autogen; + return self::autogen($text, $lang); + } + - /* Table helper functions */ + /* {{{ Table helper functions */ public function tgroup($attrs) { if (isset($attrs["cols"])) { $this->TABLE["cols"] = $attrs["cols"]; @@ -36,7 +137,6 @@ public function getColCount() { return $this->TABLE["cols"]; } - public function valign($attrs) { return isset($attrs["valign"]) ? $attrs["valign"] : "middle"; } @@ -79,7 +179,7 @@ } return 1; } - + /* }}} */ } /* http://cvs.php.net/viewvc.cgi/phd/include/PhDReader.class.php?r1=1.17&r2=1.17.4.1&diff_format=u Index: phd/include/PhDReader.class.php diff -u phd/include/PhDReader.class.php:1.17 phd/include/PhDReader.class.php:1.17.4.1 --- phd/include/PhDReader.class.php:1.17 Sat May 24 15:04:50 2008 +++ phd/include/PhDReader.class.php Mon Jul 28 22:40:57 2008 @@ -1,248 +1,115 @@ <?php -/* $Id: PhDReader.class.php,v 1.17 2008/05/24 15:04:50 gwynne Exp $ */ +/* $Id: PhDReader.class.php,v 1.17.4.1 2008/07/28 22:40:57 bjori Exp $ */ //6271 class PhDReader extends XMLReader { - - /* {{{ Class constants */ - const XMLNS_XML = "http://www.w3.org/XML/1998/namespace"; - const XMLNS_XLINK = "http://www.w3.org/1999/xlink"; - const XMLNS_PHD = "http://www.php.net/ns/phd"; + const XMLNS_XML = "http://www.w3.org/XML/1998/namespace"; + const XMLNS_XLINK = "http://www.w3.org/1999/xlink"; + const XMLNS_PHD = "http://www.php.net/ns/phd"; const XMLNS_DOCBOOK = "http://docbook.org/ns/docbook"; - const OPEN_CHUNK = 0x01; - const CLOSE_CHUNK = 0x02; - /* }}} */ - - /* {{{ Private props */ - private $STACK = array(); - private $LAST_DEPTH = -1; - private $lastChunkDepth = -1; - private $PREVIOUS_SIBLING = ""; - /* }}} */ - - protected $CHUNK_ME = array( /* {{{ */ - 'article' => true, - 'appendix' => true, - 'bibliography' => array( - /* DEFAULT */ false, - 'article' => true, - 'book' => true, - 'part' => true, - ), - 'book' => true, - 'chapter' => true, - 'colophon' => true, - 'glossary' => array( - /* DEFAULT */ false, - 'article' => true, - 'book' => true, - 'part' => true, - ), - 'index' => array( - /* DEFAULT */ false, - 'article' => true, - 'book' => true, - 'part' => true, - ), - 'legalnotice' => false, - 'part' => true, - 'preface' => true, - 'refentry' => true, - 'reference' => true, - 'sect1' => 'isSectionChunk', - /* - 'sect2' => 'format_section_chunk', - 'sect3' => 'format_section_chunk', - 'sect4' => 'format_section_chunk', - 'sect5' => 'format_section_chunk', - */ - 'section' => 'isSectionChunk', - 'set' => true, - 'setindex' => true, - ); /* }}} */ - - public $isChunk = false; - - public function __construct($encoding = "UTF-8", $xml_opts = NULL) { /* {{{ */ - if (!XMLReader::open(PhDConfig::xml_file(), $encoding, $xml_opts)) { - throw new Exception("Cannot open " . PhDConfig::xml_file()); - } - $ce = PhDConfig::chunk_extra(); - if (is_array($ce)) { - foreach($ce as $el => $v) { - $this->CHUNK_ME[$el] = $v; - } - } - } /* }}} */ - - public function notXPath($tag, $depth = 0) { /* {{{ */ - if(!$depth) { - $depth = $this->depth; - } - do { - if (isset($tag[$this->STACK[--$depth]])) { - $tag = $tag[$this->STACK[$depth]]; - } else { - $tag = $tag[0]; - } - } while (is_array($tag)); - return $tag; - } /* }}} */ - - /* Seek to an ID within the file. */ - public function seek($id) { /* {{{ */ - while(XMLReader::read()) { - if ($this->nodeType === XMLREADER::ELEMENT && $this->hasAttributes && XMLReader::moveToAttributeNs("id", self::XMLNS_XML) && $this->value === $id) { - return XMLReader::moveToElement(); - } - } - return false; - } /* }}} */ - - /* Get the ID of current node */ - public function getID() { /* {{{ */ - if ($this->hasAttributes && XMLReader::moveToAttributeNs("id", self::XMLNS_XML)) { - $id = $this->value; - XMLReader::moveToElement(); - return $id; - } - return ""; - } /* }}} */ - - public function getParentTagName() { /* {{{ */ - return $this->STACK[$this->depth-1]; - } /* }}} */ - public function getPreviousSiblingTagName() { /* {{{ */ - return $this->PREVIOUS_SIBLING; - } /* }}} */ - - public function read() { /* {{{ */ - $this->isChunk = false; - if(XMLReader::read()) { - $type = $this->nodeType; - switch($type) { - case XMLReader::ELEMENT: - $name = $this->name; - $depth = $this->depth; - if ($this->LAST_DEPTH >= $depth) { - $this->PREVIOUS_SIBLING = $this->STACK[$depth]; - } - $this->STACK[$depth] = $name; - $isChunk = $this->isChunk($name); - if ($isChunk) { - $this->isChunk = PhDReader::OPEN_CHUNK; - $this->chunkDepths[] = $this->lastChunkDepth = $depth; - } - break; - - case XMLReader::END_ELEMENT: - $depth = $this->depth; - if ($this->lastChunkDepth == $depth) { - array_pop($this->chunkDepths); - $this->lastChunkDepth = end($this->chunkDepths); - $this->isChunk = PhDReader::CLOSE_CHUNK; - } - $this->LAST_DEPTH = $depth; - break; - } - return true; - } - return false; - } /* }}} */ - - /* Get the attribute value by name, if exists. */ - public function readAttribute($attr) { /* {{{ */ - $retval = XMLReader::moveToAttribute($attr) ? $this->value : ""; - XMLReader::moveToElement(); - return $retval; - } /* }}} */ - public function readAttributeNs($attr, $ns) { /* {{{ */ - $retval = XMLReader::moveToAttributeNs($attr, $ns) ? $this->value : ""; - XMLReader::moveToElement(); - return $retval; - } /* }}} */ - /* Get all attributes of current node */ - public function getAttributes() { /* {{{ */ - $attrs = array(PhDReader::XMLNS_DOCBOOK => array(), PhDReader::XMLNS_XML => array()); - if ($this->hasAttributes) { - XMLReader::moveToFirstAttribute(); - do { - $k = $this->namespaceURI; - $attrs[!empty($k) ? $k : PhDReader::XMLNS_DOCBOOK][$this->localName] = $this->value; - $attrs[$this->name] = $this->value; - } while (XMLReader::moveToNextAttribute()); - XMLReader::moveToElement(); - } - return $attrs; - } /* }}} */ - - - /* Get the content of a named node, or the current node. */ - public function readContent($node = null) { /* {{{ */ - $retval = ""; - - if($this->isEmptyElement) { - return $retval; - } - if (!$node) { - $node = $this->name; - } - $retval = ""; - while (PhDReader::readNode($node)) { - $retval .= $this->value; - } - return $retval; - } /* }}} */ - /* Read $nodeName until END_ELEMENT */ - public function readNode($nodeName) { /* {{{ */ - return XMLReader::read() && !($this->nodeType === XMLReader::END_ELEMENT && $this->name == $nodeName); - } /* }}} */ - - - public function isChunk($tag) { /* {{{ */ - if (isset($this->CHUNK_ME[$tag])) { - $isChunk = $this->CHUNK_ME[$tag]; - if (is_array($isChunk)) { - $isChunk = $this->notXPath($isChunk); - } - if (!is_bool($isChunk)) { - return call_user_func(array($this, $isChunk), $tag); - } - return $isChunk; - } - return false; - } /* }}} */ - public function isSectionChunk($tag) { /* {{{ */ - if ($this->PREVIOUS_SIBLING == $tag && $this->checkSectionDepth()) { - return true; - } - return false; - } /* }}} */ - protected function checkSectionDepth() { /* {{{ */ - static $allowedParents = array("section", "sect2", "sect3", "sect4", "sect5"); - static $chunkers = array( - "sect1", "preface", "chapter", "appendix", "article", "part", "reference", "refentry", - "index", "bibliography", "glossary", "colopone", "book", "set", "setindex", "legalnotice", - ); - - $nodeDepth = $this->depth; - $i = 1; - do { - if (in_array($this->STACK[$nodeDepth-$i], $allowedParents)) { - ++$i; - continue; - } - break; - } while(true); - if ($i <= 1 && in_array($this->STACK[$nodeDepth-$i], $chunkers)) { - return true; - } - return false; - } /* }}} */ -} + + public function __construct() { + } + + public function close() { + return XMLReader::close(); + } + + public function getAttribute($name) { + return XMLReader::getAttribute($name); + } + + public function getAttributeNo($index) { + return XMLReader::getAttributeNo($index); + } + + public function getAttributeNs($name, $namespaceURI) { + return XMLReader::getAttributeNs($name, $namespaceURI); + } + + public function getParserProperty($property) { + return XMLReader::getParserProperty($property); + } + + public function isValid() { + return XMLReader::isValid(); + } + + public function lookupNamespace($prefix) { + return XMLReader::lookupNamespace($prefix); + } + + public function moveToAttributeNo($index) { + return XMLReader::moveToAttributeNo($index); + } + + public function moveToAttribute($name) { + return XMLReader::moveToAttribute($name); + } + + public function moveToAttributeNs($name, $namespaceURI) { + return XMLReader::moveToAttributeNs($name, $namespaceURI); + } + + public function moveToElement() { + return XMLReader::moveToElement(); + } + + public function moveToFirstAttribute() { + return XMLReader::moveToFirstAttribute(); + } + + public function moveToNextAttribute() { + return XMLReader::moveToNextAttribute(); + } + + public function open($URI, $encoding = null, $options = null) { + return XMLReader::open($URI, $encoding, $options); + } + + public function read() { + return XMLReader::read(); + } + + public function next($localname = null) { + return XMLReader::next($localname); + } + + public function readInnerXml() { + return XMLReader::readInnerXml(); + } + + public function readOuterXml() { + return XMLReader::readOuterXml(); + } + + public function readString() { + return XMLReader::readString(); + } + + public function setSchema($filename) { + return XMLReader::setSchema($filename); + } + + public function setParserProperty($property, $value) { + return XMLReader::setParserProperty($property, $value); + } + + public function setRelaxNGSchema($filename) { + return XMLReader::setRelaxNGSchema($filename); + } + + public function setRelaxNGSchemaSource($source) { + return XMLReader::setRelaxNGSchemaSource($source); + } + + public function XML($source, $encoding = null, $options = null) { + return XMLReader::XML($source, $encoding, $options); + } + + public function expand() { + return XMLReader::expand(); + } -/* -* vim600: sw=4 ts=4 syntax=php fdm=marker et -* vim<600: sw=4 ts=4 -*/ +} http://cvs.php.net/viewvc.cgi/phd/themes/php/phpdotnet.php?r1=1.54&r2=1.54.2.1&diff_format=u Index: phd/themes/php/phpdotnet.php diff -u phd/themes/php/phpdotnet.php:1.54 phd/themes/php/phpdotnet.php:1.54.2.1 --- phd/themes/php/phpdotnet.php:1.54 Wed Jul 23 19:21:31 2008 +++ phd/themes/php/phpdotnet.php Mon Jul 28 22:40:57 2008 @@ -1,25 +1,20 @@ <?php -/* $Id: phpdotnet.php,v 1.54 2008/07/23 19:21:31 bjori Exp $ */ +/* $Id: phpdotnet.php,v 1.54.2.1 2008/07/28 22:40:57 bjori Exp $ */ -abstract class phpdotnet extends PhDTheme { - protected $elementmap = array( - 'acronym' => 'format_suppressed_tags', +class PhDPHPFormat extends PhDXHTMLFormat { + protected $myelementmap = array( 'function' => 'format_suppressed_tags', - 'link' => 'format_link', - 'refpurpose' => 'format_refpurpose', - 'title' => array( + 'BOGUStitle' => array( /* DEFAULT */ false, 'article' => 'format_container_chunk_title', 'appendix' => 'format_container_chunk_title', 'chapter' => 'format_container_chunk_title', - 'example' => 'format_example_title', 'part' => 'format_container_chunk_title', 'info' => array( /* DEFAULT */ false, 'article' => 'format_container_chunk_title', 'appendix' => 'format_container_chunk_title', 'chapter' => 'format_container_chunk_title', - 'example' => 'format_example_title', 'part' => 'format_container_chunk_title', ), ), @@ -32,91 +27,50 @@ 'methodparam' => false, 'methodsynopsis' => false, ), - 'varname' => array( - /* DEFAULT */ false, - 'fieldsynopsis' => 'format_fieldsynopsis_varname', - ), - 'xref' => 'format_link', - - 'article' => 'format_container_chunk', - 'appendix' => 'format_container_chunk', - 'bibliography' => array( + 'BOGUSarticle' => 'format_container_chunk', + 'BOGUSappendix' => 'format_container_chunk', + 'BOGUSbibliography' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), - 'book' => 'format_root_chunk', - 'chapter' => 'format_container_chunk', - 'colophon' => 'format_chunk', - 'glossary' => array( + 'BOGUSbook' => 'format_root_chunk', + 'BOGUSchapter' => 'format_container_chunk', + 'BOGUScolophon' => 'format_chunk', + 'BOGUSglossary' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), - 'index' => array( + 'BOGUSindex' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), - 'legalnotice' => 'format_chunk', - 'part' => 'format_container_chunk', - 'preface' => 'format_chunk', - 'refentry' => 'format_chunk', - 'reference' => 'format_container_chunk', - 'phpdoc:exception' => 'format_exception_chunk', - 'sect1' => 'format_chunk', - 'sect2' => 'format_chunk', - 'sect3' => 'format_chunk', - 'sect4' => 'format_chunk', - 'sect5' => 'format_chunk', - 'section' => 'format_chunk', - 'set' => 'format_root_chunk', - 'setindex' => 'format_chunk', - 'qandaset' => 'format_qandaset', - 'qandaentry' => 'format_qandaentry', - 'question' => 'format_question', - 'answer' => 'format_answer', + 'BOGUSlegalnotice' => 'format_chunk', + 'BOGUSpart' => 'format_container_chunk', + 'BOGUSpreface' => 'format_chunk', + 'BOGUSrefentry' => 'format_chunk', + 'BOGUSreference' => 'format_container_chunk', + 'BOGUSsect1' => 'format_chunk', + 'BOGUSsect2' => 'format_chunk', + 'BOGUSsect3' => 'format_chunk', + 'BOGUSsect4' => 'format_chunk', + 'BOGUSsect5' => 'format_chunk', + 'BOGUSsection' => 'format_chunk', + 'BOGUSset' => 'format_root_chunk', + 'BOGUSsetindex' => 'format_chunk', + 'BOGUSphpdoc:exception' => 'format_exception_chunk', ); - protected $textmap = array( - 'acronym' => 'format_acronym_text', - 'function' => 'format_function_text', - 'methodname' => array( - /* DEFAULT */ 'format_function_text', - 'constructorsynopsis' => array( - /* DEFAULT */ 'format_function_text', - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - 'methodsynopsis' => array( - /* DEFAULT */ 'format_function_text', - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - 'destructorsynopsis' => array( - /* DEFAULT */ 'format_function_text', - 'classsynopsis' => 'format_classsynopsis_methodsynopsis_methodname_text', - ), - ), - 'type' => array( - /* DEFAULT */ 'format_type_text', - 'classsynopsisinfo' => false, - 'fieldsynopsis' => 'format_type_if_object_or_pseudo_text', - 'methodparam' => 'format_type_if_object_or_pseudo_text', - 'methodsynopsis' => array( - /* DEFAULT */ 'format_type_if_object_or_pseudo_text', - 'classsynopsis' => false, - ), - ), - 'refname' => 'format_refname_text', + protected $mytextmap = array( 'titleabbrev' => 'format_suppressed_tags', ); - private $versions = array(); - private $acronyms = array(); - protected $chunked = true; protected $lang = "en"; protected $CURRENT_ID = ""; @@ -129,471 +83,8 @@ "modifier" => "public", ), "container_chunk" => null, - "qandaentry" => array( - ), - "examples" => 0, - "verinfo" => false, - "refname" => array(), ); - public function __construct(array $IDs, array $filenames, $ext = "php", $chunked = true) { - parent::__construct($IDs, $ext); - $this->ext = $ext; - if (isset($filenames["version"], $filenames["acronym"])) { - $this->versions = self::generateVersionInfo($filenames["version"]); - $this->acronyms = self::generateAcronymInfo($filenames["acronym"]); - } - $this->chunked = $chunked; - } - public static function generateVersionInfo($filename) { - static $info; - if ($info) { - return $info; - } - $r = new XMLReader; - if (!$r->open($filename)) { - throw new Exception; - } - $versions = array(); - while($r->read()) { - if ( - $r->moveToAttribute("name") - && ($funcname = str_replace( - array("::", "->", "__", "_", '$'), - array("-", "-", "-", "-", ""), - $r->value)) - && $r->moveToAttribute("from") - && ($from = $r->value) - ) { - $versions[strtolower($funcname)] = $from; - $r->moveToElement(); - } - } - $r->close(); - $info = $versions; - return $versions; - } - public static function generateAcronymInfo($filename) { - static $info; - if ($info) { - return $info; - } - $r = new XMLReader; - if (!$r->open($filename)) { - throw new Exception("Could not open $filename"); - } - $acronyms = array(); - while ($r->read()) { - if ($r->nodeType != XMLReader::ELEMENT) { - continue; - } - if ($r->name == "term") { - $r->read(); - $k = $r->value; - $acronyms[$k] = ""; - } else if ($r->name == "simpara") { - $r->read(); - $acronyms[$k] = $r->value; - } - } - $info = $acronyms; - return $acronyms; - } - public function format_link($open, $name, $attrs, $props) { - if ($open) { - $content = $fragment = ""; - $class = $name; - - if(isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { - $linkto = $attrs[PhDReader::XMLNS_DOCBOOK]["linkend"]; - $id = $href = PhDHelper::getFilename($linkto); - - if ($id != $linkto) { - $fragment = "#$linkto"; - } - if ($this->chunked) { - $href .= ".".$this->ext; - } - } elseif(isset($attrs[PhDReader::XMLNS_XLINK]["href"])) { - $href = $attrs[PhDReader::XMLNS_XLINK]["href"]; - $content = "» "; - $class .= " external"; - } - if ($name == "xref") { - if ($this->chunked) { - $link = $href; - } else { - $link = "#"; - if (isset($linkto)) { - $link .= $linkto; - } else { - $link .= $href; - } - } - return '<a href="' .$link. '" class="' .$class. '">' .($content.PhDHelper::getDescription($id, false)). '</a>'; - } elseif ($props["empty"]) { - if ($this->chunked) { - $link = ""; - } else { - $link = "#"; - } - return '<a href="' .$link.$href.$fragment. '" class="' .$class. '">' .$content.$href.$fragment. '</a>'; - } else { - if ($this->chunked) { - $link = $href.$fragment; - } elseif(isset($linkto)) { - if ($fragment) { - $link = $fragment; - } else { - $link = "#$href"; - } - } else { - $link = $href; - } - return '<a href="' .$link. '" class="' .$class. '">' .$content; - } - } - return "</a>"; - } - public function format_fieldsynopsis_varname($open, $name, $attrs) { - if ($open) { - $href = ""; - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { - $linkto = $attrs[PhDReader::XMLNS_DOCBOOK]["linkend"]; - $href = PhDHelper::getFilename($linkto); - - if ($this->chunked) { - if ($href != $linkto) { - $href .= ".{$this->ext}#{$linkto}"; - } else { - $href .= '.' .$this->ext; - } - } else { - $href = '#' .$linkto; - } - $href = '<a href="' .$href. '">'; - } - - if ( - $this->cchunk["fieldsynopsis"]["modifier"] == "const" || - ( - $nfo = $this->format->getChunkInfo() AND $nfo["fieldsynopsis"]["modifier"] == "const" - ) - ) { - return ' <var class="fieldsynopsis_varname">'.$href; - } - return ' <var class="'.$name.'">'.$href.'$'; - } - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { - return '</a></var>'; - } - return '</var>'; - } - - - - - public function versionInfo($funcname) { - $funcname = str_replace( - array("::", "->", "__", "_", '$', '()'), - array("-", "-", "-", "-", "", ''), - strtolower($funcname)); - if(isset($this->versions[$funcname])) { - return $this->versions[$funcname]; - } - v("No version info for $funcname", VERBOSE_NOVERSION); - return false; - } - public function acronymInfo($acronym) { - return isset($this->acronyms[$acronym]) ? $this->acronyms[$acronym] : false; - } - - public function format_acronym_text($value, $tag) { - $resolved = $this->acronymInfo($value); - if ($resolved) { - return '<acronym title="' .$resolved. '">' .$value. '</acronym>'; - } - return '<acronym>'.$value.'</acronym>'; - } - public function format_refpurpose($open, $tag, $attrs) { - if ($open) { - $retval = ""; - if ($this->cchunk["verinfo"]) { - $verinfo = ""; - foreach($this->cchunk["refname"] as $refname) { - $verinfo = $this->versionInfo($refname); - - if ($verinfo) { - break; - } - } - if (!$verinfo) { - $verinfo = "No version information available, might be only in CVS"; - } - - $retval = '<p class="verinfo">(' .(htmlspecialchars($verinfo, ENT_QUOTES, "UTF-8")). ')</p>'; - } - $refnames = implode('</span> -- <span class="refname">', $this->cchunk["refname"]); - - $retval .= '<p class="refpurpose"><span class="refname">'. $refnames. '</span> — <span class="dc-title">'; - return $retval; - } - return "</span></p>\n"; - } - public function format_refname_text($value, $tag) { - $this->cchunk["refname"][] = $this->format->TEXT($value); - return false; - } - public function format_chunk($open, $name, $attrs, $props) { - if (isset($attrs[PhDReader::XMLNS_XML]["id"])) { - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; - } - if ($props["isChunk"]) { - $this->cchunk = $this->dchunk; - } - if (isset($props["lang"])) { - $this->lang = $props["lang"]; - } - if ($name == "refentry") { - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) { - $this->cchunk["verinfo"] = !($attrs[PhDReader::XMLNS_DOCBOOK]["role"] == "noversion"); - } else { - $this->cchunk["verinfo"] = true; - } - } - return false; - } - public function format_container_chunk($open, $name, $attrs, $props) { - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; - if ($open) { - if ($props["isChunk"]) { - $this->cchunk = $this->dchunk; - } - if ($name != "reference") { - $chunks = PhDHelper::getChildren($id); - if (!count($chunks)) { - return "<div>"; - } - $content = '<h2>'.$this->autogen("toc", $props["lang"]). '</h2><ul class="chunklist chunklist_'.$name.'">'; - foreach($chunks as $chunkid => $junk) { - if ($this->chunked) { - $content .= '<li><a href="'.$chunkid. '.' .$this->ext. '">' .(PhDHelper::getDescription($chunkid, true)). '</a></li>'; - } else { - $content .= '<li><a href="#'.$chunkid. '">' .(PhDHelper::getDescription($chunkid, true)). '</a></li>'; - } - } - $content .= "</ul>\n"; - $this->cchunk["container_chunk"] = $content; - } - return "<div>"; - } - - $content = ""; - if ($name == "reference") { - $chunks = PhDHelper::getChildren($id); - if (count($chunks)) { - $content = '<h2>'.$this->autogen("toc", $props["lang"]). '</h2><ul class="chunklist chunklist_reference">'; - foreach($chunks as $chunkid => $junk) { - if ($this->chunked) { - $content .= '<li><a href="'.$chunkid. '.' .$this->ext. '">' .(PhDHelper::getDescription($chunkid, false)). '</a> â ' .(PhDHelper::getDescription($chunkid, true)). '</li>'; - } else { - $content .= '<li><a href="#'.$chunkid.'">' .(PhDHelper::getDescription($chunkid, false)). '</a> â ' .(PhDHelper::getDescription($chunkid, true)). '</li>'; - } - } - $content .= "</ul>\n"; - } - } - $content .= "</div>\n"; - - return $content; - } - public function format_exception_chunk($open, $name, $attrs, $props) { - return $this->format_container_chunk($open, "reference", $attrs, $props); - } - - public function format_container_chunk_title($open, $name, $attrs) { - if ($open) { - return "<h1>"; - } - $ret = ""; - if ($this->cchunk["container_chunk"]) { - $ret = $this->cchunk["container_chunk"]; - $this->cchunk["container_chunk"] = null; - } - return "</h1>\n" .$ret; - } - public function format_root_chunk($open, $name, $attrs) { - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; - if ($open) { - return "<div>"; - } - - $chunks = PhDHelper::getChildren($id); - $content = '<ul class="chunklist chunklist_'.$name.'">'; - foreach($chunks as $chunkid => $junk) { - $href = $this->chunked ? $chunkid .'.'. $this->ext : "#$chunkid"; - $long = PhDHelper::getDescription($chunkid, true); - $short = PhDHelper::getDescription($chunkid, false); - if ($long && $short && $long != $short) { - $content .= '<li><a href="' .$href. '">' .$short. '</a> â ' .$long; - } else { - $content .= '<li><a href="' .$href. '">' .($long ? $long : $short). '</a>'; - } - $children = PhDHelper::getChildren($chunkid); - if (count($children)) { - $content .= '<ul class="chunklist chunklist_'.$name.' chunklist_children">'; - foreach(PhDHelper::getChildren($chunkid) as $childid => $junk) { - $href = $this->chunked ? $childid .'.'. $this->ext : "#$childid"; - $long = PhDHelper::getDescription($childid, true); - $short = PhDHelper::getDescription($childid, false); - if ($long && $short && $long != $short) { - $content .= '<li><a href="' .$href. '">' .$short. '</a> â ' .$long. '</li>'; - } else { - $content .= '<li><a href="' .$href. '">' .($long ? $long : $short). '</a></li>'; - } - } - $content .="</ul>"; - } - $content .= "</li>"; - } - $content .= "</ul>"; - - return $content; - } - - public function format_suppressed_tags($open, $name) { - /* ignore it */ - return ""; - } - - public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag) { - $display_value = $this->format->format_classsynopsis_methodsynopsis_methodname_text($value, $tag); - return $this->format_function_text($value, $tag, $display_value); - } - - public function format_function_text($value, $tag, $display_value = null) { - if ($display_value === null) { - $display_value = $value; - } - $rel = ""; - if ($this->format->role == "seealso") { - $rel = ' rel="rdfs-seeAlso"'; - } - - $ref = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $value)); - if (($filename = $this->getRefnameLink($ref)) !== null && $this->CURRENT_ID !== $filename) { - if ($this->chunked) { - return '<a href="'.$filename. '.' .$this->ext. '" class="function"'.$rel.'>' .$display_value.($tag == "function" ? "()" : ""). '</a>'; - } - return '<a href="#'.$filename. '" class="function"'.$rel.'>' .$display_value.($tag == "function" ? "()" : ""). '</a>'; - } - return '<b>' .$display_value.($tag == "function" ? "()" : ""). '</b>'; - } - public function format_type_if_object_or_pseudo_text($type, $tagname) { - if (in_array(strtolower($type), array("bool", "int", "double", "boolean", "integer", "float", "string", "array", "object", "resource", "null"))) { - return false; - } - return self::format_type_text($type, $tagname); - } - public function format_type_text($type, $tagname) { - $t = strtolower($type); - $href = $fragment = ""; - - switch($t) { - case "bool": - $href = "language.types.boolean"; - break; - case "int": - $href = "language.types.integer"; - break; - case "double": - $href = "language.types.float"; - break; - case "boolean": - case "integer": - case "float": - case "string": - case "array": - case "object": - case "resource": - case "null": - $href = "language.types.$t"; - break; - case "mixed": - case "number": - case "callback": - $href = "language.pseudo-types"; - $fragment = "language.types.$t"; - break; - default: - /* Check if its a classname. */ - $href = PhDTheme::getFilename("class.$t"); - } - - if ($href && $this->chunked) { - return '<a href="' .$href. '.' .$this->ext.($fragment ? "#$fragment" : ""). '" class="' .$tagname. ' ' .$type. '">' .$type. '</a>'; - } - if ($href) { - return '<a href="#' .($fragment ? $fragment : $href). '" class="' .$tagname. ' ' .$type. '">' .$type. '</a>'; - } - return '<span class="' .$tagname. ' ' .$type. '">' .$type. '</span>'; - } - - public function format_example_title($open, $name, $attrs, $props) { - if ($props["empty"]) { - return ""; - } - if ($open) { - return "<p><b>" . ($this->autogen('example', $props['lang']) . ++$this->cchunk["examples"]) . " "; - } - return "</b></p>"; - } - - /* FIXME: This function is a crazy performance killer */ - public function qandaset($stream) { - $xml = stream_get_contents($stream); - - $old = libxml_use_internal_errors(true); - $doc = new DOMDocument("1.0", "UTF-8"); - $doc->preserveWhitespace = false; - $doc->loadXML(html_entity_decode(str_replace("&", "&amp;", "<div>$xml</div>"), ENT_QUOTES, "UTF-8")); - if ($err = libxml_get_errors()) { - print_r($err); - libxml_clear_errors(); - } - fclose($stream); - libxml_use_internal_errors($old); - - $xpath = new DOMXPath($doc); - $nlist = $xpath->query("//div/dl/dt"); - $ret = '<div class="qandaset"><ol class="qandaset_questions">'; - $i = 0; - foreach($nlist as $node) { - $ret .= '<li><a href="#' .($this->cchunk["qandaentry"][$i++]). '">' .($node->textContent). '</a></li>'; - } - - return $ret.'</ol>'.$xml.'</div>'; - } - public function format_qandaentry($open, $name, $attrs) { - if ($open) { - $this->cchunk["qandaentry"][] = $attrs[PhDReader::XMLNS_XML]["id"]; - return '<dl>'; - } - return '</dl>'; - } - public function format_answer($open, $name, $attrs) { - if ($open) { - return '<dd><a name="' .end($this->cchunk["qandaentry"]).'"></a>'; - } - return "</dd>"; - } - public function format_question($open, $name, $attrs) { - if ($open) { - return '<dt><strong>'; - } - return '</strong></dt>'; - } - } /* http://cvs.php.net/viewvc.cgi/phd/formats/bigxhtml.php?view=markup&rev=1.1 Index: phd/formats/bigxhtml.php +++ phd/formats/bigxhtml.php <?php class PhDBigXHTMLFormat extends PhDXHTMLFormat { private $myelementmap = array( 'link' => 'format_link', 'xref' => 'format_xref', 'title' => array( /* DEFAULT */ false, 'info' => array( /* DEFAULT */ false, 'article' => 'format_container_chunk_top_title', 'appendix' => 'format_container_chunk_top_title', 'book' => 'format_container_chunk_top_title', 'chapter' => 'format_container_chunk_top_title', 'part' => 'format_container_chunk_top_title', 'set' => 'format_container_chunk_top_title', ), 'article' => 'format_container_chunk_top_title', 'appendix' => 'format_container_chunk_top_title', 'book' => 'format_container_chunk_top_title', 'chapter' => 'format_container_chunk_top_title', 'part' => 'format_container_chunk_top_title', 'set' => 'format_container_chunk_top_title', ), 'reference' => 'format_container_chunk_below', 'question' => array( /* DEFAULT */ false, 'questions' => 'format_phd_question', // From the PhD namespace ), ); private $mytextmap = array( ); private $bigfp; protected $flags; public function __construct() { parent::__construct(); } public function appendData($data) { $id = "BIGHTML ID"; if ($this->flags & PhDRender::CLOSE) { fwrite($this->bigfp, $data); /* Append footer */ fwrite($this->bigfp, $this->footer($id)); $this->flags ^= PhDRender::CLOSE; } elseif ($this->flags & PhDRender::OPEN) { /* Prepend header */ fwrite($this->bigfp, $this->header($id)); fwrite($this->bigfp, $data); $this->flags ^= PhDRender::OPEN; } else { fwrite($this->bigfp, $data); } } public function header($id) { return "\n"; } public function footer($id) { return "\n<hr />\n"; } public function open() { static $i = 0; $i++; $this->bigfp = fopen(PhDConfig::get("output_dir") . "bightml$i.html", "w+"); // FIXME: Use correct lang attribute and insert <title> of the DB file fwrite($this->bigfp, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> </head> <body> '); } public function close() { fwrite($this->bigfp, "</body>\n</html>"); fclose($this->bigfp); } public function getDefaultElementMap() { return $this->myelementmap; } public function getDefaultTextMap() { return $this->mytextmap; } public function update($event, $val = null) { switch($event) { case PhDRender::CHUNK: $this->flags = $val; break; case PhDRender::STANDALONE: if ($val) { $this->registerElementMap(parent::getDefaultElementMap()); $this->registerTextMap(parent::getDefaultTextMap()); } else { $this->registerElementMap(static::getDefaultElementMap()); $this->registerTextMap(static::getDefaultTextMap()); } break; case PhDRender::INIT: if ($val) { if (!is_resource($this->bigfp)) { $this->open(); } } else { $this->close(); } break; } } public function createLink($for, &$desc = null, $type = self::SDESC) { $retval = '#' . $for; if ($desc !== null) { $rsl = sqlite_array_query($this->sqlite, "SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'", SQLITE_ASSOC); $retval = '#' . $for; if ($type === self::SDESC) { $desc = $rsl[0]["sdesc"] ?: $rsl[0]["ldesc"]; } else { $desc = $rsl[0]["ldesc"] ?: $rsl[0]["sdesc"]; } } return $retval; } } /* * vim600: sw=4 ts=4 fdm=syntax syntax=php et * vim<600: sw=4 ts=4 */ http://cvs.php.net/viewvc.cgi/phd/include/PhDConfig.class.php?view=markup&rev=1.1 Index: phd/include/PhDConfig.class.php +++ phd/include/PhDConfig.class.php <?php define('VERBOSE_INDEXING', 0x01); define('VERBOSE_FORMAT_RENDERING', 0x02); define('VERBOSE_THEME_RENDERING', 0x04); define('VERBOSE_RENDER_STYLE', 0x08); define('VERBOSE_PARTIAL_READING', 0x10); define('VERBOSE_PARTIAL_CHILD_READING', 0x20); define('VERBOSE_TOC_WRITING', 0x40); define('VERBOSE_CHUNK_WRITING', 0x80); define('VERBOSE_ALL', 0xFF); class PhDConfig { private static $opts = array( "output_format" => array( ), "output_theme" => array( ), "chunk_extra" => array( ), "index" => true, "xml_root" => __DIR__, "xml_file" => false, "language" => "en", "fallback_language" => "en", "build_log_file" => false, "verbose" => VERBOSE_ALL, "date_format" => "H:i:s", "render_ids" => array( ), "skip_ids" => array( ), "output_dir" => __DIR__, "lang_dir" => __DIR__, ); public static function init(array $a) { self::$opts = array_merge(self::$opts, (array)$a); } public static function get($opt) { if (!is_string($opt)) { throw new UnexpectedValueException("Excpecting a string"); } if (!isset(self::$opts[$opt])) { throw new UnexpectedValueException("Unknown option: $opt"); } return self::$opts[$opt]; } } http://cvs.php.net/viewvc.cgi/phd/include/PhDIndex.class.php?view=markup&rev=1.1 Index: phd/include/PhDIndex.class.php +++ phd/include/PhDIndex.class.php <?php class PhDIndex extends PhDFormat { private $myelementmap = array( 'article' => 'format_container_chunk', 'appendix' => 'format_container_chunk', 'bibliography' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), 'book' => 'format_container_chunk', 'chapter' => 'format_container_chunk', 'colophon' => 'format_chunk', 'glossary' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), 'index' => array( /* DEFAULT */ false, 'article' => 'format_chunk', 'book' => 'format_chunk', 'part' => 'format_chunk', ), 'legalnotice' => 'format_legalnotice_chunk', 'part' => 'format_container_chunk', 'preface' => 'format_chunk', 'refentry' => 'format_chunk', 'reference' => 'format_container_chunk', 'sect1' => 'format_section_chunk', 'section' => array( /* DEFAULT */ false, 'sect1' => 'format_section_chunk', 'preface' => 'format_section_chunk', 'chapter' => 'format_section_chunk', 'appendix' => 'format_section_chunk', 'article' => 'format_section_chunk', 'part' => 'format_section_chunk', 'reference' => 'format_section_chunk', 'refentry' => 'format_section_chunk', 'index' => 'format_section_chunk', 'bibliography' => 'format_section_chunk', 'glossary' => 'format_section_chunk', 'colopone' => 'format_section_chunk', 'book' => 'format_section_chunk', 'set' => 'format_section_chunk', 'setindex' => 'format_section_chunk', 'legalnotice' => 'format_section_chunk', ), 'set' => 'format_container_chunk', 'setindex' => 'format_chunk', 'title' => 'format_ldesc', 'refpurpose' => 'format_ldesc', 'refname' => 'format_refname', 'titleabbrev' => 'format_sdesc', ); private $mytextmap = array( ); private $chunks = array(); public function transformFromMap($open, $tag, $name, $attrs, $props) { } public function TEXT($value) { } public function CDATA($value) { } public function createLink($for, &$desc = null, $desc = PhDFormat::SDESC) { } public function appendData($data) { } public function update($event, $value = null) { switch($event) { case PhDRender::CHUNK: $this->flags = $value; break; case PhDRender::STANDALONE: if ($value) { $this->registerElementMap(static::getDefaultElementMap()); $this->registerTextMap(static::getDefaultTextMap()); } break; case PhDRender::INIT: if ($value) { if (file_exists("index.sqlite")) { unlink("index.sqlite"); } $db = sqlite_open("index.sqlite"); sqlite_exec($db, 'PRAGMA default_synchronous=OFF'); sqlite_exec($db, 'PRAGMA count_changes=OFF'); sqlite_exec($db, 'PRAGMA cache_size=100000'); $create = <<<SQL CREATE TABLE ids ( docbook_id TEXT PRIMARY KEY, filename TEXT, parent_id TEXT, sdesc TEXT, ldesc TEXT, element TEXT ); SQL; sqlite_exec($db, 'PRAGMA default_synchronous=OFF'); sqlite_exec($db, 'PRAGMA count_changes=OFF'); sqlite_exec($db, 'PRAGMA cache_size=100000'); sqlite_exec($db, $create); $this->db = $db; $this->chunks = array(); } else { //print_r($this->chunks); } } } public function getDefaultElementMap() { return $this->myelementmap; } public function getDefaultTextMap() { return $this->mytextmap; } public function UNDEF($open, $name, $attrs, $props) { if ($open) { if(!isset($attrs[PhDReader::XMLNS_XML]["id"])) { return false; } $id = $attrs[PhDReader::XMLNS_XML]["id"]; $this->storeInfo($name, $id, $this->currentchunk); return false; } if(!isset($attrs[PhDReader::XMLNS_XML]["id"])) { return false; } $this->appendID(); return false; } protected function storeInfo($elm, $id, $filename) { $this->nfo[$id] = array( "parent" => "", "filename" => $filename, "sdesc" => "", "ldesc" => "", "element" => $elm, "children" => array(), ); $this->ids[] = $id; $this->currentid = $id; } public function appendID() { static $rand = 0; $lastchunkid = array_pop($this->ids); $parentid = end($this->ids); $this->currentid = $parentid; $a = $this->nfo[$lastchunkid]; if (is_array($a["sdesc"])) { $array = true; $sdesc = array_shift($a["sdesc"]); } else { $array = false; $sdesc = $a["sdesc"]; } $this->commit .= sprintf( "INSERT INTO ids (docbook_id, filename, parent_id, sdesc, ldesc, element) VALUES('%s', '%s', '%s', '%s', '%s', '%s');\n", sqlite_escape_string($lastchunkid), sqlite_escape_string($a["filename"]), sqlite_escape_string($this->currentchunk), sqlite_escape_string($sdesc), sqlite_escape_string($a["ldesc"]), sqlite_escape_string($a["element"]) ); if ($array === true && !empty($a["sdesc"])) { foreach($a["sdesc"] as $sdesc) { ++$rand; $this->commit .= sprintf( "INSERT INTO ids (docbook_id, filename, parent_id, sdesc, ldesc, element) VALUES('%s', '%s', '', '%s', '%s', '%s');\n", "phdgen-" . $rand, sqlite_escape_string($a["filename"]), sqlite_escape_string($sdesc), sqlite_escape_string($a["ldesc"]), sqlite_escape_string($a["element"]) ); } } } public function format_section_chunk($open, $name, $attrs, $props) { static $a = array(); if ($open) { $a[] = $props["sibling"]; if ($props["sibling"] === $name) { return $this->format_chunk($open, $name, $attrs, $props); } return $this->UNDEF($open, $name, $attrs, $props); } $x = array_pop($a); if ($x == $name) { return $this->format_chunk($open, $name, $attrs, $props); } $a[] = $x; return $this->UNDEF($open, $name, $attrs, $props); } public function format_container_chunk($open, $name, $attrs, $props) { return $this->format_chunk($open, $name, $attrs, $props); } public function format_chunk($open, $name, $attrs, $props) { if ($open) { if(isset($attrs[PhDReader::XMLNS_XML]["id"])) { $id = $attrs[PhDReader::XMLNS_XML]["id"]; } else { $id = uniqid("phd"); } $this->chunks[] = $id; $this->currentchunk = $id; $this->storeInfo($name, $id, $id); $this->notify(PhDRender::CHUNK, PhDRender::OPEN); return false; } array_pop($this->chunks); $this->currentchunk = end($this->chunks); $this->notify(PhDRender::CHUNK, PhDRender::CLOSE); $this->appendID(); return false; } public function format_legalnotice_chunk($open, $name, $attrs, $props) { return $this->format_chunk($open, $name, $attrs, $props); } public function format_ldesc($open, $name, $attrs, $props) { if ($open) { if (empty($this->nfo[$this->currentid]["ldesc"])) { /* FIXME: How can I mark that node with "reparse" flag? */ $s = $this->getReader()->readInnerXml(); $this->nfo[$this->currentid]["ldesc"] = $s; } } } public function format_sdesc($open, $name, $attrs, $props) { if ($open) { if (empty($this->nfo[$this->currentid]["sdesc"])) { /* FIXME: How can I mark that node with "reparse" flag? */ $s = $this->getReader()->readInnerXml(); $this->nfo[$this->currentid]["sdesc"] = $s; } } } public function format_refname($open, $name, $attrs, $props) { if ($open) { $s = $this->getReader()->readInnerXml(); $s = str_replace(array("_", "::", "->"), array("-", "-", "-"), $s); $this->nfo[$this->currentid]["sdesc"][] = strtolower($s); } } public function commit() { var_dump(sqlite_exec($this->db, 'BEGIN TRANSACTION; '.$this->commit.' COMMIT')); $this->commit = null; } } http://cvs.php.net/viewvc.cgi/phd/include/PhDObjectStorage.class.php?view=markup&rev=1.1 Index: phd/include/PhDObjectStorage.class.php +++ phd/include/PhDObjectStorage.class.php <?php class PhDObjectStorage extends SplObjectStorage { protected static $r = array(); public function attach($obj, $inf = array()) { if (!($obj instanceof PhDFormat)) { throw new InvalidArgumentException("Only classess inheriting PhDFormat supported"); } if (empty($inf)) { $inf = array( XMLReader::ELEMENT => $obj->getElementMap(), XMLReader::TEXT => $obj->getTextMap(), ); } parent::attach($obj, $inf); } final protected static function setReader(PhDReader $r) { self::$r[] = $r; } final protected function getReader() { return end(self::$r); } final protected function popReader() { return array_pop(self::$r); } } http://cvs.php.net/viewvc.cgi/phd/include/PhDRender.class.php?view=markup&rev=1.1 Index: phd/include/PhDRender.class.php +++ phd/include/PhDRender.class.php <?php class PhDRender extends PhDObjectStorage { const CHUNK = 0x001; const OPEN = 0x002; const CLOSE = 0x004; const STANDALONE = 0x008; const INIT = 0x010; private $STACK = array(); public function __construct() { /* {{{ */ } /* }}} */ public function notXPath($tag, $depth) { /* {{{ */ do { if (isset($tag[$this->STACK[--$depth]])) { $tag = $tag[$this->STACK[$depth]]; } else { $tag = $tag[0]; } } while (is_array($tag)); return $tag; } /* }}} */ public function attach($obj, $inf = array()) { /* {{{ */ if (!($obj instanceof PhDFormat)) { throw new InvalidArgumentException("All formats *MUST* inherit PhDFormat"); } $obj->notify(PhDRender::STANDALONE, true); return parent::attach($obj, $inf); } /* }}} */ public function render(PhDReader $r) { /* {{{ */ PhDObjectStorage::setReader($r); foreach($this as $format) { $format->notify(PhDRender::INIT, true); } $lastdepth = -1; while($r->read()) { $type = $r->nodeType; $data = $retval = $name = $open = false; switch($type) { case XMLReader::ELEMENT: /* {{{ */ $open = true; /* break intentionally omitted */ case XMLReader::END_ELEMENT: $name = $r->name; $depth = $r->depth; $attrs = array( PhDReader::XMLNS_DOCBOOK => array(), PhDReader::XMLNS_XML => array(), ); if ($r->hasAttributes) { $r->moveToFirstAttribute(); do { $k = $r->namespaceURI; $attrs[!empty($k) ? $k : PhDReader::XMLNS_DOCBOOK][$r->localName] = $r->value; } while ($r->moveToNextAttribute()); $r->moveToElement(); } $props = array( "empty" => $r->isEmptyElement, "isChunk" => false, "lang" => $r->xmlLang, "ns" => $r->namespaceURI, "sibling" => $lastdepth >= $depth ? $this->STACK[$depth] : "", "depth" => $depth, ); $this->STACK[$depth] = $name; foreach($this as $format) { $map = $this[$format][XMLReader::ELEMENT]; if (isset($map[$name]) === false) { $data = $format->UNDEF($open, $name, $attrs, $props); $format->appendData($data); continue; } $tag = $map[$name]; if (is_array($tag)) { $tag = $this->notXPath($tag, $depth); } if ($tag === false) { $data = $format->UNDEF($open, $name, $attrs, $props); $format->appendData($data); continue; } if (strncmp($tag, "format_", 7) !== 0) { $data = $retval = $format->transformFromMap($open, $tag, $name, $attrs, $props); } else { $data = $retval = $format->{$tag}($open, $name, $attrs, $props); } $format->appendData($data); foreach($format as $theme) { $map = $format[$theme][XMLReader::ELEMENT]; if (isset($map[$name])) { $tag = $map[$name]; if (is_array($tag)) { $tag = $this->notXPath($tag, $depth); } if ($tag !== false) { $retval = $theme->{$tag}($open, $name, $attrs, $props); if ($retval !== false) { $data = $retval; } } } $theme->appendData($data); } } $lastdepth = $depth; break; /* }}} */ case XMLReader::TEXT: /* {{{ */ $value = $r->value; $eldepth = $r->depth - 1; $name = $this->STACK[$eldepth]; foreach($this as $format) { $map = $this[$format][XMLReader::TEXT]; if (isset($map[$name])) { $tag = $map[$name]; if (is_array($tag)) { $tag = $this->notXPath($tag, $eldepth); } if ($tag !== false) { $data = $retval = $format->{$tag}($value, $name); } else { $data = $retval = $format->TEXT($value); } } else { $data = $retval = $format->TEXT($value); } if ($data === false) { $format->appendData($value); } else { $format->appendData($data); } foreach($format as $theme) { $map = $format[$theme][XMLReader::TEXT]; if (isset($map[$name])) { $tag = $map[$name]; if (is_array($tag)) { $tag = $this->notXPath($tag, $eldepth); } if ($tag !== false) { $retval = $format->{$tag}($value, $name); if ($retval !== false) { $data = $retval; } } } $theme->appendData($data); } } break; /* }}} */ case XMLReader::CDATA: /* {{{ */ /* Different formats may want to escape the CDATA sections differently */ $value = $r->value; foreach($this as $format) { $retval = $format->CDATA($value); $format->appendData($retval); foreach($format as $theme) { $theme->appendData($retval); } } break; /* }}} */ case XMLReader::WHITESPACE: /* {{{ */ case XMLReader::SIGNIFICANT_WHITESPACE: /* WS is always WS */ $retval = $r->value; foreach($this as $format) { $format->appendData($retval); foreach($format as $theme) { $theme->appendData($retval); } } break; /* }}} */ } } /* Closing time */ foreach($this as $format) { //$format->notify(PhDRender::INIT, false); } $r->close(); PhDObjectStorage::popReader(); } /* }}} */ }