cvs: phd(PHD_ENTERPRISE) /formats bigxhtml.php php.php xhtml.php /include PhDFormat.class.php
| From: | Rudy Nappée | Date: | Tue, 12 Aug 2008 14:12:12 +0000 |
| Subject: | cvs: phd(PHD_ENTERPRISE) /formats bigxhtml.php php.php xhtml.php /include PhDFormat.class.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-2022@lists.php.net to get a copy of this message | ||
loudi Tue Aug 12 14:12:12 2008 UTC
Modified files: (Branch: PHD_ENTERPRISE)
/phd/formats xhtml.php bigxhtml.php php.php
/phd/include PhDFormat.class.php
Log:
* now formats exclusively uses helper functions which uses cached indexes (try to avoid DB
requests in formats)
=> more than twice faster
* fixes format names
http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.68.2.11&r2=1.68.2.12&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.68.2.11 phd/formats/xhtml.php:1.68.2.12 --- phd/formats/xhtml.php:1.68.2.11 Mon Aug 11 12:46:48 2008 +++ phd/formats/xhtml.php Tue Aug 12 14:12:12 2008 @@ -1,7 +1,7 @@ <?php -/* $Id: xhtml.php,v 1.68.2.11 2008/08/11 12:46:48 loudi Exp $ */ +/* $Id: xhtml.php,v 1.68.2.12 2008/08/12 14:12:12 loudi Exp $ */ class PhDXHTMLFormat extends PhDFormat { - private $simpleName = "XHTML"; + private $formatname = "XHTML"; private $myelementmap = array( /* {{{ */ 'abstract' => 'div', /* Docbook-xsl prints "abstract"... */ 'abbrev' => 'abbr', @@ -401,7 +401,7 @@ protected $outputdir = __DIR__; public function __construct() { parent::__construct(); - parent::registerFormatName($this->simpleName); + parent::registerFormatName($this->formatname); } public function transformFromMap($open, $tag, $name, $attrs, $props) { if ($open) { @@ -441,7 +441,7 @@ $lang = $this->CURRENT_LANG; $prev = $next = $parent = array("href" => null, "desc" => null); - + if ($parentId = $this->getParent($id)) { $parent = array("href" => $this->getFilename($parentId) . '.' .$this->ext, "desc" => $this->getShortDescription($parentId)); @@ -496,52 +496,54 @@ } public function createLink($for, &$desc = null, $type = PhDFormat::SDESC) { $retval = null; - if (isset($this->idx[$for])) { - $rsl = $this->idx[$for]; + if (isset($this->indexes[$for])) { + $rsl = $this->indexes[$for]; $retval = $rsl["filename"] . "." . $this->ext . '#' . $rsl["docbook_id"]; $desc = $rsl["sdesc"] ?: $rsl["ldesc"]; } return $retval; } - protected function createTOC(SQLite3Result $result, $lang) { - $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 = $this->createLink($row["docbook_id"]); - + protected function createTOC($id, $lang) { + if (!$this->getChildrens($id)) { + return ""; + } + $toc = '<h2>' . $this->autogen('toc', $lang) . '</h2><ol>'; + foreach ($this->getChildrens($id) as $child) { + $isLDesc = null; + $isSDesc = null; + $long = $this->parse($this->getLongDescription($child, $isLDesc)); + $short = $this->getShortDescription($child, $isSDesc); + $link = $this->createLink($child); + $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) { + if ($this->getChildrens($child)) { $list = "<ol>"; - while ($child = $childrens->fetchArray(SQLITE3_ASSOC)) { - $childLong = $this->parse($child["ldesc"]); - $childShort = $child["sdesc"]; - - $href = $this->createLink($child["docbook_id"]); - if ($childLong && $childShort && $childLong != $childShort) { - $list .= '<li><a href="' . $href . '">' . $childShort . '</a> â ' . $childLong . "</li>\n"; + foreach ($this->getChildrens($child) as $subChild) { + $isSubLDesc = null; + $isSubSDesc = null; + $subLong = $this->parse($this->getLongDescription($subChild, $isLDesc)); + $subShort = $this->getShortDescription($subChild, $isSubSDesc); + + $href = $this->createLink($subChild); + if ($isSubLDesc && $isSubSDesc) { + $list .= '<li><a href="' . $href . '">' . $subShort . '</a> â ' . $subLong . "</li>\n"; } else { - $list .= '<li><a href="' . $href . '">' . ($childLong ?: $childShort) . '</a>' . "</li>\n"; + $list .= '<li><a href="' . $href . '">' . ($subLong ?: $subShort) . '</a>' . "</li>\n"; } } $list .="</ol>"; } } - if ($long && $short && $long != $short) { + if ($isLDesc && $isSDesc) { $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"; - if ($empty) - return ""; - else return $toc; + return $toc; } protected function createNavBar($id) { @@ -597,11 +599,10 @@ } // Fetch siblings of the current node $parent = $this->getParent($id); - $childrens = $this->sqlite->query("SELECT docbook_id FROM ids WHERE parent_id='$parent'"); - while ($child = $childrens->fetchArray(SQLITE3_ASSOC)) { + foreach ($this->getChildrens($parent) as $child) { $desc = ""; - $link = $this->createLink($child["docbook_id"], $desc); - $active = ($id === $child["docbook_id"]); + $link = $this->createLink($child, $desc); + $active = ($id === $child); $navBar .= " <li" .($active ? " class=\"active\"" : ""). "><a href=\"$link\">$desc</a></li>\n"; } return $navBar . " </ul>\n"; @@ -797,10 +798,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); @@ -809,12 +806,11 @@ $this->CURRENT_CHUNK = $id; $this->notify(PhDRender::CHUNK, PhDRender::CLOSE); - $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, $props["lang"]); + if (!in_array($id, $this->TOC_WRITTEN)) { + $toc = $this->createTOC($id, $props["lang"]); } + return $toc."</div>"; } public function format_container_chunk_top_title($open, $name, $attrs, $props) { @@ -823,13 +819,9 @@ } $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, $props["lang"]); - } else { - $this->CHILDRENS = array(); - $toc = ""; - } + + $toc = $this->createTOC($id, $props["lang"]); + $this->TOC_WRITTEN[] = $id; return '</h1>'.$toc; @@ -853,10 +845,8 @@ $toc = '<ol>'; $desc = ""; - $rsl = $this->CHILDRENS; - 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"]); + if (!in_array($id, $this->TOC_WRITTEN)) { + $toc = $this->createTOC($id, $props["lang"]); } $toc .= "</ol>\n"; http://cvs.php.net/viewvc.cgi/phd/formats/bigxhtml.php?r1=1.2.2.8&r2=1.2.2.9&diff_format=u Index: phd/formats/bigxhtml.php diff -u phd/formats/bigxhtml.php:1.2.2.8 phd/formats/bigxhtml.php:1.2.2.9 --- phd/formats/bigxhtml.php:1.2.2.8 Mon Aug 11 12:46:48 2008 +++ phd/formats/bigxhtml.php Tue Aug 12 14:12:12 2008 @@ -1,6 +1,6 @@ <?php class PhDBigXHTMLFormat extends PhDXHTMLFormat { - private $simpleName = "Big-XHTML"; + private $formatname = "Big-XHTML"; private $myelementmap = array( 'link' => 'format_link', 'xref' => 'format_xref', @@ -28,7 +28,7 @@ 'questions' => 'format_phd_question', // From the PhD namespace ), - + ); private $mytextmap = array( ); @@ -38,7 +38,7 @@ public function __construct() { parent::__construct(); - parent::registerFormatName($this->simpleName); + parent::registerFormatName($this->formatname); } public function appendData($data) { if ($this->appendToBuffer) { @@ -74,7 +74,7 @@ $i++; $this->bigfp = fopen(PhDConfig::output_dir() . "bightml$i.html", "w+"); // FIXME: Use correct lang attribute and insert <title> of the DB file - fwrite($this->bigfp, + 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"> @@ -128,13 +128,13 @@ } public function createLink($for, &$desc = null, $type = self::SDESC) { $retval = '#' . $for; - if (isset($this->idx[$for])) { - $result = $this->idx[$for]; + if (isset($this->indexes[$for])) { + $result = $this->indexes[$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/formats/php.php?r1=1.4.2.8&r2=1.4.2.9&diff_format=u Index: phd/formats/php.php diff -u phd/formats/php.php:1.4.2.8 phd/formats/php.php:1.4.2.9 --- phd/formats/php.php:1.4.2.8 Mon Aug 11 12:46:48 2008 +++ phd/formats/php.php Tue Aug 12 14:12:12 2008 @@ -1,6 +1,6 @@ <?php class PhDPHPFormat extends PhDXHTMLFormat { - private $simpleName = "PHP"; + private $formatname = "PHP"; private $myelementmap = array( 'acronym' => 'format_suppressed_tags', 'function' => 'format_suppressed_tags', @@ -77,7 +77,7 @@ public function __construct() { parent::__construct(); - parent::registerFormatName($this->simpleName); + parent::registerFormatName($this->formatname); $this->versions = self::generateVersionInfo(PhDConfig::phpweb_version_filename()); $this->acronyms = self::generateAcronymInfo(PhDConfig::phpweb_acronym_filename()); http://cvs.php.net/viewvc.cgi/phd/include/PhDFormat.class.php?r1=1.10.6.10&r2=1.10.6.11&diff_format=u Index: phd/include/PhDFormat.class.php diff -u phd/include/PhDFormat.class.php:1.10.6.10 phd/include/PhDFormat.class.php:1.10.6.11 --- phd/include/PhDFormat.class.php:1.10.6.10 Mon Aug 11 12:46:48 2008 +++ phd/include/PhDFormat.class.php Tue Aug 12 14:12:12 2008 @@ -9,6 +9,10 @@ private $formatname = "UNKNOWN"; protected $sqlite; + /* Indexing maps */ + protected $indexes = array(); + protected $childrens = array(); + private static $autogen = array(); public function __construct() { @@ -27,11 +31,14 @@ abstract public function update($event, $value = null); public function sortIDs() { - $this->sqlite->createAggregate("idx", array($this, "SQLiteIndex"), array($this, "SQLiteFinal"), 8); - $this->sqlite->query('SELECT idx(docbook_id, filename, parent_id, sdesc, ldesc, element, previous, next) FROM ids'); + $this->sqlite->createAggregate("indexes", array($this, "SQLiteIndex"), array($this, "SQLiteFinal"), 8); + $this->sqlite->createAggregate("childrens", array($this, "SQLiteChildrens"), array($this, "SQLiteFinal"), 2); + $this->sqlite->query('SELECT indexes(docbook_id, filename, parent_id, sdesc, ldesc, element, previous, next) FROM ids'); + $this->sqlite->query('SELECT childrens(docbook_id, parent_id) FROM ids'); } + public function SQLiteIndex(&$context, $index, $id, $filename, $parent, $sdesc, $ldesc, $element, $previous, $next) { - $this->idx[$id] = array( + $this->indexes[$id] = array( "docbook_id" => $id, "filename" => $filename, "parent_id" => $parent, @@ -46,6 +53,14 @@ } } + + public function SQLiteChildrens(&$context, $index, $id, $parent) { + if (!isset($this->childrens[$parent]) || !is_array($this->childrens[$parent])) { + $this->childrens[$parent] = array(); + } + $this->childrens[$parent][] = $id; + } + public static function SQLiteFinal(&$context) { return $context; } @@ -82,28 +97,28 @@ 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) { $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; } - + final public static function autogen($text, $lang) { if (isset(self::$autogen[$lang])) { if (isset(self::$autogen[$lang][$text])) { @@ -144,52 +159,40 @@ /* {{{ TOC helper functions */ final public function getFilename($id) { - $row = $this->sqlite->query($q = "SELECT filename FROM ids WHERE docbook_id='$id'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; - } - return $row["filename"]; + return $this->indexes[$id]["filename"]; } final public function getPrevious($id) { - $row = $this->sqlite->query($q = "SELECT previous FROM ids WHERE docbook_id='$id'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; - } - return $row["previous"]; + return $this->indexes[$id]["previous"]; } final public function getNext($id) { - $row = $this->sqlite->query($q = "SELECT next FROM ids WHERE docbook_id='$id'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; - } - return $row["next"]; + return $this->indexes[$id]["next"]; } final public function getParent($id) { - $row = $this->sqlite->query($q = "SELECT parent_id FROM ids WHERE docbook_id='$id'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; - } - return $row["parent_id"]; - } - final public function getLongDescription($for) { - $row = $this->sqlite->query($q = "SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; - } - return $row["ldesc"] ?: $row["sdesc"]; - } - final public function getShortDescription($for) { - $row = $this->sqlite->query($q = "SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; + return $this->indexes[$id]["parent_id"]; + } + final public function getLongDescription($id, &$isLDesc = null) { + if ($this->indexes[$id]["ldesc"]) { + $isLDesc = true; + return $this->indexes[$id]["ldesc"]; + } else { + $isLDesc = false; + return $this->indexes[$id]["sdesc"]; + } + } + final public function getShortDescription($id, &$isSDesc = null) { + if ($this->indexes[$id]["sdesc"]) { + $isSDesc = true; + return $this->indexes[$id]["sdesc"]; + } else { + $isSDesc = false; + return $this->indexes[$id]["ldesc"]; + } + } + final public function getChildrens($id) { + if (!isset($this->childrens[$id]) || !is_array($this->childrens[$id]) || count($this->childrens[$id]) == 0) { + return null; } - return $row["sdesc"] ?: $row["ldesc"]; + return $this->childrens[$id]; } /* }}} */
http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.68.2.11&r2=1.68.2.12&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.68.2.11 phd/formats/xhtml.php:1.68.2.12 --- phd/formats/xhtml.php:1.68.2.11 Mon Aug 11 12:46:48 2008 +++ phd/formats/xhtml.php Tue Aug 12 14:12:12 2008 @@ -1,7 +1,7 @@ <?php -/* $Id: xhtml.php,v 1.68.2.11 2008/08/11 12:46:48 loudi Exp $ */ +/* $Id: xhtml.php,v 1.68.2.12 2008/08/12 14:12:12 loudi Exp $ */ class PhDXHTMLFormat extends PhDFormat { - private $simpleName = "XHTML"; + private $formatname = "XHTML"; private $myelementmap = array( /* {{{ */ 'abstract' => 'div', /* Docbook-xsl prints "abstract"... */ 'abbrev' => 'abbr', @@ -401,7 +401,7 @@ protected $outputdir = __DIR__; public function __construct() { parent::__construct(); - parent::registerFormatName($this->simpleName); + parent::registerFormatName($this->formatname); } public function transformFromMap($open, $tag, $name, $attrs, $props) { if ($open) { @@ -441,7 +441,7 @@ $lang = $this->CURRENT_LANG; $prev = $next = $parent = array("href" => null, "desc" => null); - + if ($parentId = $this->getParent($id)) { $parent = array("href" => $this->getFilename($parentId) . '.' .$this->ext, "desc" => $this->getShortDescription($parentId)); @@ -496,52 +496,54 @@ } public function createLink($for, &$desc = null, $type = PhDFormat::SDESC) { $retval = null; - if (isset($this->idx[$for])) { - $rsl = $this->idx[$for]; + if (isset($this->indexes[$for])) { + $rsl = $this->indexes[$for]; $retval = $rsl["filename"] . "." . $this->ext . '#' . $rsl["docbook_id"]; $desc = $rsl["sdesc"] ?: $rsl["ldesc"]; } return $retval; } - protected function createTOC(SQLite3Result $result, $lang) { - $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 = $this->createLink($row["docbook_id"]); - + protected function createTOC($id, $lang) { + if (!$this->getChildrens($id)) { + return ""; + } + $toc = '<h2>' . $this->autogen('toc', $lang) . '</h2><ol>'; + foreach ($this->getChildrens($id) as $child) { + $isLDesc = null; + $isSDesc = null; + $long = $this->parse($this->getLongDescription($child, $isLDesc)); + $short = $this->getShortDescription($child, $isSDesc); + $link = $this->createLink($child); + $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) { + if ($this->getChildrens($child)) { $list = "<ol>"; - while ($child = $childrens->fetchArray(SQLITE3_ASSOC)) { - $childLong = $this->parse($child["ldesc"]); - $childShort = $child["sdesc"]; - - $href = $this->createLink($child["docbook_id"]); - if ($childLong && $childShort && $childLong != $childShort) { - $list .= '<li><a href="' . $href . '">' . $childShort . '</a> â ' . $childLong . "</li>\n"; + foreach ($this->getChildrens($child) as $subChild) { + $isSubLDesc = null; + $isSubSDesc = null; + $subLong = $this->parse($this->getLongDescription($subChild, $isLDesc)); + $subShort = $this->getShortDescription($subChild, $isSubSDesc); + + $href = $this->createLink($subChild); + if ($isSubLDesc && $isSubSDesc) { + $list .= '<li><a href="' . $href . '">' . $subShort . '</a> â ' . $subLong . "</li>\n"; } else { - $list .= '<li><a href="' . $href . '">' . ($childLong ?: $childShort) . '</a>' . "</li>\n"; + $list .= '<li><a href="' . $href . '">' . ($subLong ?: $subShort) . '</a>' . "</li>\n"; } } $list .="</ol>"; } } - if ($long && $short && $long != $short) { + if ($isLDesc && $isSDesc) { $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"; - if ($empty) - return ""; - else return $toc; + return $toc; } protected function createNavBar($id) { @@ -597,11 +599,10 @@ } // Fetch siblings of the current node $parent = $this->getParent($id); - $childrens = $this->sqlite->query("SELECT docbook_id FROM ids WHERE parent_id='$parent'"); - while ($child = $childrens->fetchArray(SQLITE3_ASSOC)) { + foreach ($this->getChildrens($parent) as $child) { $desc = ""; - $link = $this->createLink($child["docbook_id"], $desc); - $active = ($id === $child["docbook_id"]); + $link = $this->createLink($child, $desc); + $active = ($id === $child); $navBar .= " <li" .($active ? " class=\"active\"" : ""). "><a href=\"$link\">$desc</a></li>\n"; } return $navBar . " </ul>\n"; @@ -797,10 +798,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); @@ -809,12 +806,11 @@ $this->CURRENT_CHUNK = $id; $this->notify(PhDRender::CHUNK, PhDRender::CLOSE); - $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, $props["lang"]); + if (!in_array($id, $this->TOC_WRITTEN)) { + $toc = $this->createTOC($id, $props["lang"]); } + return $toc."</div>"; } public function format_container_chunk_top_title($open, $name, $attrs, $props) { @@ -823,13 +819,9 @@ } $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, $props["lang"]); - } else { - $this->CHILDRENS = array(); - $toc = ""; - } + + $toc = $this->createTOC($id, $props["lang"]); + $this->TOC_WRITTEN[] = $id; return '</h1>'.$toc; @@ -853,10 +845,8 @@ $toc = '<ol>'; $desc = ""; - $rsl = $this->CHILDRENS; - 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"]); + if (!in_array($id, $this->TOC_WRITTEN)) { + $toc = $this->createTOC($id, $props["lang"]); } $toc .= "</ol>\n"; http://cvs.php.net/viewvc.cgi/phd/formats/bigxhtml.php?r1=1.2.2.8&r2=1.2.2.9&diff_format=u Index: phd/formats/bigxhtml.php diff -u phd/formats/bigxhtml.php:1.2.2.8 phd/formats/bigxhtml.php:1.2.2.9 --- phd/formats/bigxhtml.php:1.2.2.8 Mon Aug 11 12:46:48 2008 +++ phd/formats/bigxhtml.php Tue Aug 12 14:12:12 2008 @@ -1,6 +1,6 @@ <?php class PhDBigXHTMLFormat extends PhDXHTMLFormat { - private $simpleName = "Big-XHTML"; + private $formatname = "Big-XHTML"; private $myelementmap = array( 'link' => 'format_link', 'xref' => 'format_xref', @@ -28,7 +28,7 @@ 'questions' => 'format_phd_question', // From the PhD namespace ), - + ); private $mytextmap = array( ); @@ -38,7 +38,7 @@ public function __construct() { parent::__construct(); - parent::registerFormatName($this->simpleName); + parent::registerFormatName($this->formatname); } public function appendData($data) { if ($this->appendToBuffer) { @@ -74,7 +74,7 @@ $i++; $this->bigfp = fopen(PhDConfig::output_dir() . "bightml$i.html", "w+"); // FIXME: Use correct lang attribute and insert <title> of the DB file - fwrite($this->bigfp, + 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"> @@ -128,13 +128,13 @@ } public function createLink($for, &$desc = null, $type = self::SDESC) { $retval = '#' . $for; - if (isset($this->idx[$for])) { - $result = $this->idx[$for]; + if (isset($this->indexes[$for])) { + $result = $this->indexes[$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/formats/php.php?r1=1.4.2.8&r2=1.4.2.9&diff_format=u Index: phd/formats/php.php diff -u phd/formats/php.php:1.4.2.8 phd/formats/php.php:1.4.2.9 --- phd/formats/php.php:1.4.2.8 Mon Aug 11 12:46:48 2008 +++ phd/formats/php.php Tue Aug 12 14:12:12 2008 @@ -1,6 +1,6 @@ <?php class PhDPHPFormat extends PhDXHTMLFormat { - private $simpleName = "PHP"; + private $formatname = "PHP"; private $myelementmap = array( 'acronym' => 'format_suppressed_tags', 'function' => 'format_suppressed_tags', @@ -77,7 +77,7 @@ public function __construct() { parent::__construct(); - parent::registerFormatName($this->simpleName); + parent::registerFormatName($this->formatname); $this->versions = self::generateVersionInfo(PhDConfig::phpweb_version_filename()); $this->acronyms = self::generateAcronymInfo(PhDConfig::phpweb_acronym_filename()); http://cvs.php.net/viewvc.cgi/phd/include/PhDFormat.class.php?r1=1.10.6.10&r2=1.10.6.11&diff_format=u Index: phd/include/PhDFormat.class.php diff -u phd/include/PhDFormat.class.php:1.10.6.10 phd/include/PhDFormat.class.php:1.10.6.11 --- phd/include/PhDFormat.class.php:1.10.6.10 Mon Aug 11 12:46:48 2008 +++ phd/include/PhDFormat.class.php Tue Aug 12 14:12:12 2008 @@ -9,6 +9,10 @@ private $formatname = "UNKNOWN"; protected $sqlite; + /* Indexing maps */ + protected $indexes = array(); + protected $childrens = array(); + private static $autogen = array(); public function __construct() { @@ -27,11 +31,14 @@ abstract public function update($event, $value = null); public function sortIDs() { - $this->sqlite->createAggregate("idx", array($this, "SQLiteIndex"), array($this, "SQLiteFinal"), 8); - $this->sqlite->query('SELECT idx(docbook_id, filename, parent_id, sdesc, ldesc, element, previous, next) FROM ids'); + $this->sqlite->createAggregate("indexes", array($this, "SQLiteIndex"), array($this, "SQLiteFinal"), 8); + $this->sqlite->createAggregate("childrens", array($this, "SQLiteChildrens"), array($this, "SQLiteFinal"), 2); + $this->sqlite->query('SELECT indexes(docbook_id, filename, parent_id, sdesc, ldesc, element, previous, next) FROM ids'); + $this->sqlite->query('SELECT childrens(docbook_id, parent_id) FROM ids'); } + public function SQLiteIndex(&$context, $index, $id, $filename, $parent, $sdesc, $ldesc, $element, $previous, $next) { - $this->idx[$id] = array( + $this->indexes[$id] = array( "docbook_id" => $id, "filename" => $filename, "parent_id" => $parent, @@ -46,6 +53,14 @@ } } + + public function SQLiteChildrens(&$context, $index, $id, $parent) { + if (!isset($this->childrens[$parent]) || !is_array($this->childrens[$parent])) { + $this->childrens[$parent] = array(); + } + $this->childrens[$parent][] = $id; + } + public static function SQLiteFinal(&$context) { return $context; } @@ -82,28 +97,28 @@ 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) { $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; } - + final public static function autogen($text, $lang) { if (isset(self::$autogen[$lang])) { if (isset(self::$autogen[$lang][$text])) { @@ -144,52 +159,40 @@ /* {{{ TOC helper functions */ final public function getFilename($id) { - $row = $this->sqlite->query($q = "SELECT filename FROM ids WHERE docbook_id='$id'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; - } - return $row["filename"]; + return $this->indexes[$id]["filename"]; } final public function getPrevious($id) { - $row = $this->sqlite->query($q = "SELECT previous FROM ids WHERE docbook_id='$id'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; - } - return $row["previous"]; + return $this->indexes[$id]["previous"]; } final public function getNext($id) { - $row = $this->sqlite->query($q = "SELECT next FROM ids WHERE docbook_id='$id'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; - } - return $row["next"]; + return $this->indexes[$id]["next"]; } final public function getParent($id) { - $row = $this->sqlite->query($q = "SELECT parent_id FROM ids WHERE docbook_id='$id'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; - } - return $row["parent_id"]; - } - final public function getLongDescription($for) { - $row = $this->sqlite->query($q = "SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; - } - return $row["ldesc"] ?: $row["sdesc"]; - } - final public function getShortDescription($for) { - $row = $this->sqlite->query($q = "SELECT sdesc, ldesc FROM ids WHERE docbook_id='$for'")->fetchArray(SQLITE3_ASSOC); - if (!is_array($row)) { - var_dump($q); - return false; + return $this->indexes[$id]["parent_id"]; + } + final public function getLongDescription($id, &$isLDesc = null) { + if ($this->indexes[$id]["ldesc"]) { + $isLDesc = true; + return $this->indexes[$id]["ldesc"]; + } else { + $isLDesc = false; + return $this->indexes[$id]["sdesc"]; + } + } + final public function getShortDescription($id, &$isSDesc = null) { + if ($this->indexes[$id]["sdesc"]) { + $isSDesc = true; + return $this->indexes[$id]["sdesc"]; + } else { + $isSDesc = false; + return $this->indexes[$id]["ldesc"]; + } + } + final public function getChildrens($id) { + if (!isset($this->childrens[$id]) || !is_array($this->childrens[$id]) || count($this->childrens[$id]) == 0) { + return null; } - return $row["sdesc"] ?: $row["ldesc"]; + return $this->childrens[$id]; } /* }}} */