cvs: phd(PHD_ENTERPRISE) / render.php /formats bigxhtml.php php.php xhtml.php /include PhDFormat.class.php PhDRender.class.php

From: Date: Mon, 11 Aug 2008 12:46:50 +0000
Subject: cvs: phd(PHD_ENTERPRISE) / render.php /formats bigxhtml.php php.php xhtml.php /include PhDFormat.class.php PhDRender.class.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-2015@lists.php.net to get a copy of this message
loudi Mon Aug 11 12:46:50 2008 UTC Modified files: (Branch: PHD_ENTERPRISE) /phd/formats xhtml.php php.php bigxhtml.php /phd render.php /phd/include PhDFormat.class.php PhDRender.class.php Log: * found another way to fix bug #42927 (missing aliases) without using a new parser * fixed verbose msgs (now each one appears only once) * fixed link in bigxhtml & clean createTOC() functions

http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.68.2.10&r2=1.68.2.11&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.68.2.10 phd/formats/xhtml.php:1.68.2.11 --- phd/formats/xhtml.php:1.68.2.10 Sun Aug 10 14:14:55 2008 +++ phd/formats/xhtml.php Mon Aug 11 12:46:48 2008 @@ -1,5 +1,5 @@ <?php -/* $Id: xhtml.php,v 1.68.2.10 2008/08/10 14:14:55 loudi Exp $ */ +/* $Id: xhtml.php,v 1.68.2.11 2008/08/11 12:46:48 loudi Exp $ */ class PhDXHTMLFormat extends PhDFormat { private $simpleName = "XHTML"; private $myelementmap = array( /* {{{ */ @@ -399,7 +399,6 @@ protected $ext = "html"; protected $fp = array(); protected $outputdir = __DIR__; - public function __construct() { parent::__construct(); parent::registerFormatName($this->simpleName); @@ -411,13 +410,16 @@ $id = $attrs[PhDReader::XMLNS_XML]["id"]; $idstr = ' id="' .$id. '" name="' .$id. '"'; } - return '<' .$tag. ' class="' .$name. '"' . ($props["empty"] ? '/' : "") . $idstr. '>'; + return '<' .$tag. ' class="' .$name. '"' . $idstr . ($props["empty"] ? '/' : "") . '>'; } return '</' .$tag. '>'; } public function appendData($data) { - if ($this->flags & PhDRender::CLOSE) { + if ($this->appendToBuffer) { + $this->buffer .= $data; + return; + } elseif ($this->flags & PhDRender::CLOSE) { $fp = array_pop($this->fp); fwrite($fp, $data); $this->writeChunk($this->CURRENT_CHUNK, $fp); @@ -458,7 +460,7 @@ "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"> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>PHP: '.$title.'</title> </head> <body> @@ -500,40 +502,16 @@ $desc = $rsl["sdesc"] ?: $rsl["ldesc"]; } return $retval; - - if ($desc === null) { - $rsl = $this->sqlite->query("SELECT docbook_id, filename FROM ids WHERE docbook_id='$for'")->fetchArray(SQLITE3_ASSOC); - - if (!is_array($rsl)) { - return false; - } - - $retval = $rsl["filename"] . '.' . $this->ext . '#' . $rsl["docbook_id"]; - } else { - $rsl = $this->sqlite->query($q = "SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE docbook_id='$for'")->fetchArray(SQLITE3_ASSOC); - - if (!is_array($rsl)) { - var_dump($q); - return false; - } - - $retval = $rsl["filename"] . '.' . $this->ext . '#' . $rsl["docbook_id"]; - - if ($type === self::SDESC) { - $desc = $rsl["sdesc"] ?: $rsl["ldesc"]; - } else { - $desc = $rsl["ldesc"] ?: $rsl["sdesc"]; - } - } - - return $retval; } + protected function createTOC(SQLite3Result $result, $lang) { - $toc = '<h2>' . $this->autogen('toc', $lang) . '</h2><ol>'; + $empty = true; + $toc = '<h2>' . $this->autogen('toc', $lang) . '</h2><ol>'; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + $empty = false; $long = $this->parse($row["ldesc"]); $short = $row["sdesc"]; - $link = $row["filename"] . "." . $this->ext . '#' . $row["docbook_id"]; + $link = $this->createLink($row["docbook_id"]); $list = ""; if ($this->cchunk["name"] === "book" || $this->cchunk["name"] === "set") { @@ -541,28 +519,29 @@ if ($childrens) { $list = "<ol>"; while ($child = $childrens->fetchArray(SQLITE3_ASSOC)) { - $childLong = $this->parse($child["ldesc"]); - $childShort = $child["sdesc"]; + $childLong = $this->parse($child["ldesc"]); + $childShort = $child["sdesc"]; - $href = $child["filename"] . "." . $this->ext . '#' . $child["docbook_id"]; - if ($childLong && $childShort && $childLong != $childShort) { - $list .= '<li><a href="' . $href . '">' . $childShort . '</a> — ' . $childLong . "</li>\n"; - } else { - $list .= '<li><a href="' . $href . '">' . ($childLong ?: $childShort) . '</a>' . "</li>\n"; - } + $href = $this->createLink($child["docbook_id"]); + if ($childLong && $childShort && $childLong != $childShort) { + $list .= '<li><a href="' . $href . '">' . $childShort . '</a> — ' . $childLong . "</li>\n"; + } else { + $list .= '<li><a href="' . $href . '">' . ($childLong ?: $childShort) . '</a>' . "</li>\n"; + } } $list .="</ol>"; } } - if ($long && $short && $long != $short) { + if ($long && $short && $long != $short) { $toc .= '<li><a href="' . $link . '">' . $short . '</a> — ' . $long . $list . "</li>\n"; } else { $toc .= '<li><a href="' . $link . '">' . ($long ?: $short) . '</a>' . $list . "</li>\n"; } } $toc .= "</ol>\n"; - - return $toc; + if ($empty) + return ""; + else return $toc; } protected function createNavBar($id) { @@ -669,7 +648,6 @@ break; case PhDRender::INIT: - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); $this->outputdir = $tmp = PhDConfig::output_dir() . strtolower($this->getFormatName()) . '/'; if (file_exists($tmp)) { if (!is_dir($tmp)) { @@ -681,6 +659,9 @@ } } break; + case PhDRender::VERBOSE: + v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + break; } } @@ -1044,8 +1025,10 @@ return $content; } - public function format_methodparam_parameter($open, $name, $attrs) { - if ($open) { + public function format_methodparam_parameter($open, $name, $attrs, $props) { + if ($props["empty"]) + return; + if ($open) { if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) { return ' <tt class="parameter reference">&$'; } @@ -1059,8 +1042,10 @@ } return '</span>'; } - public function format_parameter($open, $name, $attrs) { - if ($open) { + public function format_parameter($open, $name, $attrs, $props) { + if ($props["empty"]) + return; + if ($open) { if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) { return '<i><tt class="parameter reference">&'; } http://cvs.php.net/viewvc.cgi/phd/formats/php.php?r1=1.4.2.7&r2=1.4.2.8&diff_format=u Index: phd/formats/php.php diff -u phd/formats/php.php:1.4.2.7 phd/formats/php.php:1.4.2.8 --- phd/formats/php.php:1.4.2.7 Sun Aug 3 22:06:39 2008 +++ phd/formats/php.php Mon Aug 11 12:46:48 2008 @@ -138,6 +138,9 @@ case PhDRender::INIT: parent::update($event, $val); break; + case PhDRender::VERBOSE: + parent::update($event, $val); + break; } } public function format_suppressed_text($value, $tag) { http://cvs.php.net/viewvc.cgi/phd/formats/bigxhtml.php?r1=1.2.2.7&r2=1.2.2.8&diff_format=u Index: phd/formats/bigxhtml.php diff -u phd/formats/bigxhtml.php:1.2.2.7 phd/formats/bigxhtml.php:1.2.2.8 --- phd/formats/bigxhtml.php:1.2.2.7 Fri Aug 1 18:57:52 2008 +++ phd/formats/bigxhtml.php Mon Aug 11 12:46:48 2008 @@ -41,7 +41,11 @@ parent::registerFormatName($this->simpleName); } public function appendData($data) { - $id = "BIGHTML ID"; + if ($this->appendToBuffer) { + $this->buffer .= $data; + return; + } + $id = "BIGHTML ID"; if ($this->flags & PhDRender::CLOSE) { fwrite($this->bigfp, $data); @@ -75,6 +79,8 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> + <title>PHP Manual</title> </head> <body> '); @@ -110,27 +116,26 @@ if ($val) { if (!is_resource($this->bigfp)) { $this->open(); - v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); } } else { $this->close(); } break; + case PhDRender::VERBOSE: + v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); + break; } } public function createLink($for, &$desc = null, $type = self::SDESC) { $retval = '#' . $for; - if ($desc !== null) { - $result = $this->sqlite->query("SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'")->fetchArray(SQLITE3_ASSOC); - $retval = '#' . $for; - + if (isset($this->idx[$for])) { + $result = $this->idx[$for]; if ($type === self::SDESC) { $desc = $result["sdesc"] ?: $result["ldesc"]; } else { $desc = $result["ldesc"] ?: $result["sdesc"]; - } + } } - return $retval; } http://cvs.php.net/viewvc.cgi/phd/render.php?r1=1.3.2.9&r2=1.3.2.10&diff_format=u Index: phd/render.php diff -u phd/render.php:1.3.2.9 phd/render.php:1.3.2.10 --- phd/render.php:1.3.2.9 Fri Aug 1 18:57:52 2008 +++ phd/render.php Mon Aug 11 12:46:48 2008 @@ -46,8 +46,6 @@ // Indexing & registering formats foreach(range(0, 0) as $i) { - //var_dump(date(DATE_RSS)); - if (PhDIndex::requireIndexing()) { v("Indexing...", VERBOSE_INDEXING); // Create indexer @@ -61,7 +59,6 @@ $render->detach($format); v("Indexing done", VERBOSE_INDEXING); - //var_dump(date(DATE_RSS)); } else { v("Skipping indexing", VERBOSE_INDEXING); } @@ -101,7 +98,10 @@ // Rendering formats foreach(range(0, 0) as $i) { - $reader->open(PhDConfig::xml_file()); + $reader->open(PhDConfig::xml_file()); + foreach($render as $format) { + $format->notify(PhDRender::VERBOSE, true); + } $render->render($reader); } http://cvs.php.net/viewvc.cgi/phd/include/PhDFormat.class.php?r1=1.10.6.9&r2=1.10.6.10&diff_format=u Index: phd/include/PhDFormat.class.php diff -u phd/include/PhDFormat.class.php:1.10.6.9 phd/include/PhDFormat.class.php:1.10.6.10 --- phd/include/PhDFormat.class.php:1.10.6.9 Sun Aug 10 14:14:56 2008 +++ phd/include/PhDFormat.class.php Mon Aug 11 12:46:48 2008 @@ -82,90 +82,25 @@ public function getFormatName() { return $this->formatname; } - + + /* Buffer where append data instead of the standard stream (see format's appendData()) */ + protected $appendToBuffer = false; + protected $buffer = ""; + final public function parse($xml) { - $reader = new XMLReader(); - $bool = $reader->xml("<toparse>".$xml."</toparse>", "UTF-8"); - $parsed = ""; - $STACK = array(); - $lastdepth = -1; - $depth = 0; - while($reader->read()) { - $data = $retval = $name = $open = false; - switch($reader->nodeType) { - case XMLReader::ELEMENT: /* {{{ */ - $open = true; - case XMLReader::END_ELEMENT: - $name = $reader->name; - if ($name == "toparse") break; - $depth = $reader->depth; - $attrs = array( - PhDReader::XMLNS_DOCBOOK => array(), - PhDReader::XMLNS_XML => array(), - ); - - if ($reader->hasAttributes) { - $reader->moveToFirstAttribute(); - do { - $k = $reader->namespaceURI; - $attrs[!empty($k) ? $k : PhDReader::XMLNS_DOCBOOK][$reader->localName] = $reader->value; - } while ($reader->moveToNextAttribute()); - $reader->moveToElement(); - } - - $props = array( - "empty" => $reader->isEmptyElement, - "isChunk" => false, - "lang" => $reader->xmlLang, - "ns" => $reader->namespaceURI, - "sibling" => $lastdepth >= $depth ? $STACK[$depth] : "", - "depth" => $depth, - ); - - $STACK[$depth] = $name; - $map = $this->getElementMap(); - - if (isset($map[$name]) === false) { - $parsed .= $this->UNDEF($open, $name, $attrs, $props); - continue; - } - - $tag = $map[$name]; - while (is_array($tag)) { - if (isset($STACK[--$depth]) && isset($tag[$STACK[--$depth]])) { - $tag = $tag[$STACK[$depth]]; - } else { - $tag = $tag[0]; - } - } - - if ($tag === false) { - $parsed .= $this->UNDEF($open, $name, $attrs, $props); - continue; - } - - if (strncmp($tag, "format_", 7) !== 0) { - $data = $retval = $this->transformFromMap($open, $tag, $name, $attrs, $props); - } else { - $data = $retval = $this->{$tag}($open, $name, $attrs, $props); - } - $parsed .= $data; - - $lastdepth = $depth; - break; - /* }}} */ - - case XMLReader::TEXT: /* {{{ */ - case XMLReader::WHITESPACE: - case XMLReader::SIGNIFICANT_WHITESPACE: - case XMLReader::CDATA: - $parsed .= $reader->value; - break; - /* }}} */ - - } - } - $reader->close(); + $parsed = ""; + $reader = new PhDReader(); + $render = new PhDRender(); + + $reader->XML("<notatag>" . $xml . "</notatag>"); + + $this->appendToBuffer = true; + $render->attach($this); + $render->render($reader); + $this->appendToBuffer = false; + $parsed = $this->buffer; + $this->buffer = ""; + return $parsed; } http://cvs.php.net/viewvc.cgi/phd/include/PhDRender.class.php?r1=1.2.2.5&r2=1.2.2.6&diff_format=u Index: phd/include/PhDRender.class.php diff -u phd/include/PhDRender.class.php:1.2.2.5 phd/include/PhDRender.class.php:1.2.2.6 --- phd/include/PhDRender.class.php:1.2.2.5 Fri Aug 1 14:55:19 2008 +++ phd/include/PhDRender.class.php Mon Aug 11 12:46:48 2008 @@ -6,6 +6,7 @@ const STANDALONE = 0x008; const INIT = 0x010; const FINALIZE = 0x020; + const VERBOSE = 0x040; private $STACK = array(); @@ -76,6 +77,9 @@ $this->STACK[$depth] = $name; + if ($name == "notatag") + continue; + foreach($this as $format) { $map = $this[$format][XMLReader::ELEMENT];
« previous php.doc.cvs (#2015) next »