cvs: phd /include PhDEnterpriseFormat.class.php PhDEnterpriseReader.class.php PhDFormatFactory.php PhDIndex.class.php PhDObjectStorage.class.php
PhDRender.class.php

From: Date: Sat, 13 Jun 2009 11:18:08 +0000
Subject: cvs: phd /include PhDEnterpriseFormat.class.php PhDEnterpriseReader.class.php PhDFormatFactory.php PhDIndex.class.php PhDObjectStorage.class.php
PhDRender.class.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-4141@lists.php.net to get a copy of this message
moacir Sat Jun 13 11:18:08 2009 UTC Added files: /phd/include PhDEnterpriseFormat.class.php PhDEnterpriseReader.class.php Modified files: /phd/include PhDFormatFactory.php PhDIndex.class.php PhDObjectStorage.class.php PhDRender.class.php Log: Merging from Enterprise

http://cvs.php.net/viewvc.cgi/phd/include/PhDFormatFactory.php?r1=1.1&r2=1.2&diff_format=u Index: phd/include/PhDFormatFactory.php diff -u /dev/null phd/include/PhDFormatFactory.php:1.2 --- /dev/null Sat Jun 13 11:18:08 2009 +++ phd/include/PhDFormatFactory.php Sat Jun 13 11:18:08 2009 @@ -0,0 +1,29 @@ +<?php + +abstract class PhDFormatFactory { + public function createXhtmlFormat() { + trigger_error("This format is not supported by this package", E_USER_ERROR); + } + public function createBigXhtmlFormat() { + trigger_error("This format is not supported by this package", E_USER_ERROR); + } + public function createPHPFormat() { + trigger_error("This format is not supported by this package", E_USER_ERROR); + } + + public static final function createFactory() { + global $ROOT; + $package = PhDConfig::package(); + $classname = "{$package}Factory"; + + require_once $ROOT . "/packages/$package/$classname.class.php"; + + $factory = new $classname(); + if (!($factory instanceof PhDFormatFactory)) { + throw new Exception("All Factories must inherit PhDFormatFactory"); + } + return $factory; + } +} + +?> http://cvs.php.net/viewvc.cgi/phd/include/PhDIndex.class.php?r1=1.2&r2=1.3&diff_format=u Index: phd/include/PhDIndex.class.php diff -u /dev/null phd/include/PhDIndex.class.php:1.3 --- /dev/null Sat Jun 13 11:18:08 2009 +++ phd/include/PhDIndex.class.php Sat Jun 13 11:18:08 2009 @@ -0,0 +1,320 @@ +<?php +class PhDIndex extends PhDEnterpriseFormat { + 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', + 'phpdoc:exception' => '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_sdesc', + 'titleabbrev' => 'format_sdesc', + ); + private $mytextmap = array( + ); + private $chunks = array(); + private $previousId = ""; + + public function transformFromMap($open, $tag, $name, $attrs, $props) { + } + public function TEXT($value) { + } + public function CDATA($value) { + } + public function createLink($for, &$desc = null, $type = PhDEnterpriseFormat::SDESC) { + } + public function appendData($data) { + } + // Require indexing if --index=true, if no indexing has been successfully done before + // or if xml input file has changed since the last indexing + final static public function requireIndexing() { + if (!PhDConfig::index() && file_exists(PhDConfig::output_dir() . "index.sqlite")) { + $db = new SQLite3(PhDConfig::output_dir() . 'index.sqlite'); + $indexingCount = $db->query('SELECT COUNT(time) FROM indexing')->fetchArray(SQLITE3_NUM); + if ($indexingCount[0] > 0) { + $indexing = $db->query('SELECT time FROM indexing')->fetchArray(SQLITE3_ASSOC); + $xmlLastModification = filemtime(PhDConfig::xml_file()); + if ($indexing["time"] > $xmlLastModification) { + return false; + } + } + } + return true; + } + 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(PhDConfig::output_dir() . "index.sqlite")) { + $db = new SQLite3(PhDConfig::output_dir() . 'index.sqlite'); + $db->exec('DELETE FROM ids'); + $db->exec('DELETE FROM indexing'); + } else { + $db = new SQLite3(PhDConfig::output_dir() . 'index.sqlite'); + $create = <<<SQL +CREATE TABLE ids ( + docbook_id TEXT PRIMARY KEY, + filename TEXT, + parent_id TEXT, + sdesc TEXT, + ldesc TEXT, + element TEXT, + previous TEXT, + next TEXT +); +CREATE TABLE indexing ( + time INTEGER PRIMARY KEY +); +SQL; + $db->exec('PRAGMA default_synchronous=OFF'); + $db->exec('PRAGMA count_changes=OFF'); + $db->exec('PRAGMA cache_size=100000'); + $db->exec($create); + } + $this->db = $db; + + $this->chunks = array(); + } else { + print_r($this->chunks); + } + break; + case PhDRender::FINALIZE: + $this->db->exec("INSERT INTO indexing (time) VALUES ('" . time() . "')"); + break; + } + } + public function getDefaultElementMap() { + return $this->myelementmap; + } + public function getDefaultTextMap() { + return $this->mytextmap; + } + public function UNDEF($open, $name, $attrs, $props) { + /*if ($open) { + if(isset($attrs[PhDEnterpriseReader::XMLNS_XML]["id"])) { + $id = $attrs[PhDEnterpriseReader::XMLNS_XML]["id"]; + $this->storeInfo($name, $id, $this->currentchunk); + } + return false; + } + + if(isset($attrs[PhDEnterpriseReader::XMLNS_XML]["id"])) { + $this->appendID(); + }*/ + return false; + } + protected function storeInfo($elm, $id, $filename, $isChunk = true) { + $this->ids[] = $id; + $this->currentid = $id; + $this->nfo[$id] = array( + "parent" => "", + "filename" => $filename, + "sdesc" => "", + "ldesc" => "", + "element" => $elm, + "children" => array(), + "previous" => $this->previousId + ); + // Append "next" to the previously inserted row + if ($isChunk) { + $this->commitAfter .= sprintf( + "UPDATE ids SET next = '%s' WHERE docbook_id = '%s';\n", + $this->db->escapeString($id), + $this->db->escapeString($this->previousId) + ); + //echo "resquete UPDATE ids SET next = '".$this->db->escapeString($id)."' WHERE docbook_id = '".$this->db->escapeString($this->previousId)."';\n"; + $this->previousId = $id; + } + } + public function appendID($isChunk = true) { + static $rand = 0; + + $lastChunkId = array_pop($this->ids); + $parentid = end($this->ids); + + $this->currentid = $parentid; + $lastChunk = $this->nfo[$lastChunkId]; + if (is_array($lastChunk["sdesc"])) { + $array = true; + $sdesc = array_shift($lastChunk["sdesc"]); + } else { + $array = false; + $sdesc = $lastChunk["sdesc"]; + } + $this->commit .= sprintf( + "INSERT INTO ids (docbook_id, filename, parent_id, sdesc, ldesc, element, previous, next) VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '');\n", + $this->db->escapeString($lastChunkId), + $this->db->escapeString($lastChunk["filename"]), + $this->db->escapeString($this->currentchunk), + $this->db->escapeString($sdesc), + $this->db->escapeString($lastChunk["ldesc"]), + $this->db->escapeString($lastChunk["element"]), + $this->db->escapeString($lastChunk["previous"]) + ); + if ($array === true && !empty($a["sdesc"])) { + foreach($lastChunk["sdesc"] as $sdesc) { + ++$rand; + $this->commit .= sprintf( + "INSERT INTO ids (docbook_id, filename, parent_id, sdesc, ldesc, element, previous, next) VALUES('%s', '%s', '', '%s', '%s', '%s', '%s', '');\n", + "phdgen-" . $rand, + $this->db->escapeString($lastChunk["filename"]), + $this->db->escapeString($sdesc), + $this->db->escapeString($lastChunk["ldesc"]), + $this->db->escapeString($lastChunk["element"]), + $this->db->escapeString($lastChunk["previous"]) + ); + } + } + } + + public function format_section_chunk($open, $name, $attrs, $props) { + static $sectionChunks = array(); + if ($open) { + $sectionChunks[] = $props["sibling"]; + if ($props["sibling"] === $name) { + return $this->format_chunk($open, $name, $attrs, $props); + } + if(isset($attrs[PhDEnterpriseReader::XMLNS_XML]["id"])) { + $id = $attrs[PhDEnterpriseReader::XMLNS_XML]["id"]; + return $this->storeInfo($name, $id, $this->currentchunk, false); + } + return $this->UNDEF($open, $name, $attrs, $props); + } + $x = array_pop($sectionChunks); + if ($x == $name) { + return $this->format_chunk($open, $name, $attrs, $props); + } + $sectionChunks[] = $x; + if(isset($attrs[PhDEnterpriseReader::XMLNS_XML]["id"])) { + $id = $attrs[PhDEnterpriseReader::XMLNS_XML]["id"]; + return $this->appendID(false); + } + 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[PhDEnterpriseReader::XMLNS_XML]["id"])) { + $id = $attrs[PhDEnterpriseReader::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() { + if (isset($this->commit) && $this->commit) { + var_dump($this->db->exec('BEGIN TRANSACTION; '.$this->commit.' COMMIT')); + var_dump($this->db->exec('BEGIN TRANSACTION; '.$this->commitAfter.' COMMIT')); + $this->commit = $this->commitAfter = null; + } + } +} + http://cvs.php.net/viewvc.cgi/phd/include/PhDObjectStorage.class.php?r1=1.2&r2=1.3&diff_format=u Index: phd/include/PhDObjectStorage.class.php diff -u /dev/null phd/include/PhDObjectStorage.class.php:1.3 --- /dev/null Sat Jun 13 11:18:08 2009 +++ phd/include/PhDObjectStorage.class.php Sat Jun 13 11:18:08 2009 @@ -0,0 +1,27 @@ +<?php +class PhDObjectStorage extends SplObjectStorage { + protected static $r = array(); + + public function attach($obj, $inf = array()) { + if (!($obj instanceof PhDEnterpriseFormat)) { + throw new InvalidArgumentException("Only classess inheriting PhDEnterpriseFormat supported"); + } + if (empty($inf)) { + $inf = array( + XMLReader::ELEMENT => $obj->getElementMap(), + XMLReader::TEXT => $obj->getTextMap(), + ); + } + parent::attach($obj, $inf); + } + final protected static function setReader(PhDEnterpriseReader $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?r1=1.2&r2=1.3&diff_format=u Index: phd/include/PhDRender.class.php diff -u /dev/null phd/include/PhDRender.class.php:1.3 --- /dev/null Sat Jun 13 11:18:08 2009 +++ phd/include/PhDRender.class.php Sat Jun 13 11:18:08 2009 @@ -0,0 +1,226 @@ +<?php +class PhDRender extends PhDObjectStorage { + const CHUNK = 0x001; + const OPEN = 0x002; + const CLOSE = 0x004; + const STANDALONE = 0x008; + const INIT = 0x010; + const FINALIZE = 0x020; + const VERBOSE = 0x040; + + 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 PhDEnterpriseFormat)) { + throw new InvalidArgumentException("All formats *MUST* inherit PhDEnterpriseFormat"); + } + $obj->notify(PhDRender::STANDALONE, true); + + return parent::attach($obj, $inf); + } /* }}} */ + + public function render(PhDEnterpriseReader $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( + PhDEnterpriseReader::XMLNS_DOCBOOK => array(), + PhDEnterpriseReader::XMLNS_XML => array(), + ); + + if ($r->hasAttributes) { + $r->moveToFirstAttribute(); + do { + $k = $r->namespaceURI; + $attrs[!empty($k) ? $k : PhDEnterpriseReader::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; + + if ($name == "notatag") + continue; + + 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::FINALIZE, true); + } + $r->close(); + + PhDObjectStorage::popReader(); + + } /* }}} */ + +} + http://cvs.php.net/viewvc.cgi/phd/include/PhDEnterpriseFormat.class.php?view=markup&rev=1.1 Index: phd/include/PhDEnterpriseFormat.class.php +++ phd/include/PhDEnterpriseFormat.class.php <?php abstract class PhDEnterpriseFormat extends PhDObjectStorage { const SDESC = 1; const LDESC = 2; private $elementmap = array(); private $textmap = array(); private $formatname = "UNKNOWN"; protected $sqlite; /* Indexing maps */ protected $indexes = array(); protected $childrens = array(); private static $autogen = array(); public function __construct() { if (file_exists(PhDConfig::output_dir() . "index.sqlite")) { $this->sqlite = new SQLite3(PhDConfig::output_dir() . '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, $type = PhDEnterpriseFormat::SDESC); abstract public function appendData($data); abstract public function update($event, $value = null); public function sortIDs() { $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->indexes[$id] = array( "docbook_id" => $id, "filename" => $filename, "parent_id" => $parent, "sdesc" => $sdesc, "ldesc" => $ldesc, "element" => $element, "previous" => $previous, "next" => $next ); if ($element == "refentry") { $this->refs[$sdesc] = $id; } } 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; } 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 function registerFormatName($name) { $this->formatname = $name; } 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 PhDEnterpriseReader(); $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])) { return self::$autogen[$lang][$text]; } if ($lang == PhDConfig::fallback_language()) { throw new InvalidArgumentException("Cannot autogenerate text for '$text'"); } return self::autogen($text, PhDConfig::fallback_language()); } $filename = PhDConfig::lang_dir() . $lang . ".xml"; $r = new XMLReader; if (!file_exists($filename) || !$r->open($filename)) { if ($lang == PhDConfig::fallback_language()) { throw new Exception("Cannot open $filename"); } return self::autogen($text, PhDConfig::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); } /* {{{ TOC helper functions */ final public function getFilename($id) { return $this->indexes[$id]["filename"]; } final public function getPrevious($id) { return $this->indexes[$id]["previous"]; } final public function getNext($id) { return $this->indexes[$id]["next"]; } final public function getParent($id) { 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 $this->childrens[$id]; } /* }}} */ /* {{{ Table helper functions */ public function tgroup($attrs) { if (isset($attrs["cols"])) { $this->TABLE["cols"] = $attrs["cols"]; unset($attrs["cols"]); } $this->TABLE["defaults"] = $attrs; $this->TABLE["colspec"] = array(); } public function colspec(array $attrs) { $colspec = self::getColSpec($attrs); $this->TABLE["colspec"][$colspec["colnum"]] = $colspec; return $colspec; } public function getColspec(array $attrs) { /* defaults */ $defaults["colname"] = count($this->TABLE["colspec"])+1; $defaults["colnum"] = count($this->TABLE["colspec"])+1; $defaults["align"] = "left"; return array_merge($defaults, $this->TABLE["defaults"], $attrs); } public function getColCount() { return $this->TABLE["cols"]; } public function valign($attrs) { return isset($attrs["valign"]) ? $attrs["valign"] : "middle"; } public function initRow() { $this->TABLE["next_colnum"] = 1; } public function getEntryOffset(array $attrs) { $curr = $this->TABLE["next_colnum"]; foreach($this->TABLE["colspec"] as $col => $spec) { if ($spec["colname"] == $attrs["colname"]) { $colnum = $spec["colnum"]; $this->TABLE["next_colnum"] += $colnum-$curr; return $colnum-$curr; } } return -1; } public function colspan(array $attrs) { if (isset($attrs["namest"])) { foreach($this->TABLE["colspec"] as $colnum => $spec) { if ($spec["colname"] == $attrs["namest"]) { $from = $spec["colnum"]; continue; } if ($spec["colname"] == $attrs["nameend"]) { $to = $spec["colnum"]; continue; } } $colspan = $to-$from+1; $this->TABLE["next_colnum"] += $colspan; return $colspan; } $this->TABLE["next_colnum"]++; return 1; } public function rowspan($attrs) { if (isset($attrs["morerows"])) { return $attrs["morerows"]+1; } return 1; } /* }}} */ } /* * vim600: sw=4 ts=4 fdm=syntax syntax=php et * vim<600: sw=4 ts=4 */ http://cvs.php.net/viewvc.cgi/phd/include/PhDEnterpriseReader.class.php?view=markup&rev=1.1 Index: phd/include/PhDEnterpriseReader.class.php +++ phd/include/PhDEnterpriseReader.class.php <?php /* $Id: PhDEnterpriseReader.class.php,v 1.1 2009/06/13 11:18:08 moacir Exp $ */ //6271 class PhDEnterpriseReader extends XMLReader { 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"; 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(); } }
« previous php.doc.cvs (#4141) next »