cvs: phd(PHD_ENTERPRISE) /formats xhtml.php /include PhDFormat.class.php PhDIndex.class.php

From: Date: Sun, 10 Aug 2008 14:14:56 +0000
Subject: cvs: phd(PHD_ENTERPRISE) /formats xhtml.php /include PhDFormat.class.php PhDIndex.class.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-2012@lists.php.net to get a copy of this message
loudi Sun Aug 10 14:14:56 2008 UTC Modified files: (Branch: PHD_ENTERPRISE) /phd/formats xhtml.php /phd/include PhDFormat.class.php PhDIndex.class.php Log: * fixes <refname>s (now appears fine in TOCs) * fixes <xref>s * description is now the short one in next/previous/up (like in HEAD) * TOC now appears fine when called by format_container_chunk_below function * fixed bug #42927 (missing aliases): indexed description is now parsed

http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.68.2.9&r2=1.68.2.10&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.68.2.9 phd/formats/xhtml.php:1.68.2.10 --- phd/formats/xhtml.php:1.68.2.9 Sat Aug 9 15:08:06 2008 +++ phd/formats/xhtml.php Sun Aug 10 14:14:55 2008 @@ -1,5 +1,5 @@ <?php -/* $Id: xhtml.php,v 1.68.2.9 2008/08/09 15:08:06 loudi Exp $ */ +/* $Id: xhtml.php,v 1.68.2.10 2008/08/10 14:14:55 loudi Exp $ */ class PhDXHTMLFormat extends PhDFormat { private $simpleName = "XHTML"; private $myelementmap = array( /* {{{ */ @@ -311,7 +311,7 @@ ), 'void' => 'format_void', 'warning' => 'format_admonition', - 'xref' => 'a', + 'xref' => 'format_xref', 'year' => 'span', 'quote' => 'format_quote', 'qandaset' => 'format_qandaset', @@ -442,15 +442,15 @@ if ($parentId = $this->getParent($id)) { $parent = array("href" => $this->getFilename($parentId) . '.' .$this->ext, - "desc" => $this->getLongDescription($parentId)); + "desc" => $this->getShortDescription($parentId)); } if ($prevId = PhDFormat::getPrevious($id)) { $prev = array("href" => PhDFormat::getFilename($prevId) . '.' .$this->ext, - "desc" => $this->getLongDescription($prevId)); + "desc" => $this->getShortDescription($prevId)); } if ($nextId = PhDFormat::getNext($id)) { $next = array("href" => PhDFormat::getFilename($nextId) . '.' .$this->ext, - "desc" => $this->getLongDescription($nextId)); + "desc" => $this->getShortDescription($nextId)); } $navBar = $this->createNavBar($id); return @@ -528,24 +528,37 @@ return $retval; } - protected function createTOC(SQLite3Result $result) { - $toc = '<ol>'; - $desc = $title = ""; - while ($row = $result->fetchArray()) { - $link = $this->createLink($row["docbook_id"], $desc); + protected function createTOC(SQLite3Result $result, $lang) { + $toc = '<h2>' . $this->autogen('toc', $lang) . '</h2><ol>'; + while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + $long = $this->parse($row["ldesc"]); + $short = $row["sdesc"]; + $link = $row["filename"] . "." . $this->ext . '#' . $row["docbook_id"]; + $list = ""; if ($this->cchunk["name"] === "book" || $this->cchunk["name"] === "set") { $childrens = $this->sqlite->query("SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='{$row["docbook_id"]}' AND filename=docbook_id"); if ($childrens) { $list = "<ol>"; - while ($child = $childrens->fetchArray()) { - $href = $this->createLink($child["docbook_id"], $title); - $list .= '<li><a href="' .$href. '">' .$title. "</a></li>\n"; + while ($child = $childrens->fetchArray(SQLITE3_ASSOC)) { + $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"; + } } $list .="</ol>"; } } - $toc .= '<li><a href="' .$link. '">' .$desc. '</a>' .$list. "</li>\n"; + 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"; @@ -803,6 +816,10 @@ } if ($open) { + if (!NO_SQLITE) { + $this->CHILDRENS = $this->sqlite->query("SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id' AND filename=docbook_id"); + } + $this->CURRENT_CHUNK = $id; $this->notify(PhDRender::CHUNK, PhDRender::OPEN); @@ -815,7 +832,7 @@ $toc = ""; if (!NO_SQLITE && !in_array($id, $this->TOC_WRITTEN)) { $result = $this->sqlite->query("SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id'"); - $toc = $this->createTOC($result); + $toc = $this->createTOC($result, $props["lang"]); } return $toc."</div>"; } @@ -827,7 +844,7 @@ $id = $this->CURRENT_CHUNK; if (!NO_SQLITE) { $this->CHILDRENS = $result = $this->sqlite->query("SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id'"); - $toc = $this->createTOC($result); + $toc = $this->createTOC($result, $props["lang"]); } else { $this->CHILDRENS = array(); $toc = ""; @@ -838,6 +855,7 @@ } public function format_container_chunk_below($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 { @@ -846,9 +864,6 @@ } if ($open) { - if (!NO_SQLITE) { - $this->CHILDRENS = $this->sqlite->query("SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id' AND filename=docbook_id"); - } $this->CURRENT_CHUNK = $id; $this->notify(PhDRender::CHUNK, PhDRender::OPEN); @@ -858,9 +873,9 @@ $toc = '<ol>'; $desc = ""; $rsl = $this->CHILDRENS; - while ($child = $rsl->fetchArray(SQLITE3_ASSOC)) { - $link = $this->createLink($child["docbook_id"], $desc); - $toc .= '<li><a href="' .$link. '">' .$desc. "</a></li>\n"; + if (!NO_SQLITE && !in_array($id, $this->TOC_WRITTEN)) { + $result = $this->sqlite->query("SELECT docbook_id, filename, sdesc, ldesc FROM ids WHERE parent_id='$id'"); + $toc = $this->createTOC($result, $props["lang"]); } $toc .= "</ol>\n"; http://cvs.php.net/viewvc.cgi/phd/include/PhDFormat.class.php?r1=1.10.6.8&r2=1.10.6.9&diff_format=u Index: phd/include/PhDFormat.class.php diff -u phd/include/PhDFormat.class.php:1.10.6.8 phd/include/PhDFormat.class.php:1.10.6.9 --- phd/include/PhDFormat.class.php:1.10.6.8 Sun Aug 3 22:06:40 2008 +++ phd/include/PhDFormat.class.php Sun Aug 10 14:14:56 2008 @@ -83,6 +83,92 @@ return $this->formatname; } + 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(); + return $parsed; + } + final public static function autogen($text, $lang) { if (isset(self::$autogen[$lang])) { if (isset(self::$autogen[$lang][$text])) { http://cvs.php.net/viewvc.cgi/phd/include/PhDIndex.class.php?r1=1.2.2.8&r2=1.2.2.9&diff_format=u Index: phd/include/PhDIndex.class.php diff -u phd/include/PhDIndex.class.php:1.2.2.8 phd/include/PhDIndex.class.php:1.2.2.9 --- phd/include/PhDIndex.class.php:1.2.2.8 Sun Aug 3 22:06:40 2008 +++ phd/include/PhDIndex.class.php Sun Aug 10 14:14:56 2008 @@ -58,7 +58,7 @@ 'title' => 'format_ldesc', 'refpurpose' => 'format_ldesc', - 'refname' => 'format_refname', + 'refname' => 'format_sdesc', 'titleabbrev' => 'format_sdesc', ); private $mytextmap = array( @@ -300,13 +300,15 @@ } } - public function format_refname($open, $name, $attrs, $props) { + + /*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() { if (isset($this->commit) && $this->commit) { var_dump($this->db->exec('BEGIN TRANSACTION; '.$this->commit.' COMMIT'));
« previous php.doc.cvs (#2012) next »