cvs: phd(PHD_ENTERPRISE) / render.php /formats bigxhtml.php php.php /include PhDConfig.class.php PhDIndex.class.php PhDObjectStorage.class.php
PhDRender.class.php

From: Date: Mon, 28 Jul 2008 22:47:59 +0000
Subject: cvs: phd(PHD_ENTERPRISE) / render.php /formats bigxhtml.php php.php /include PhDConfig.class.php PhDIndex.class.php PhDObjectStorage.class.php
PhDRender.class.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-1948@lists.php.net to get a copy of this message
bjori Mon Jul 28 22:47:59 2008 UTC Added files: (Branch: PHD_ENTERPRISE) /phd render.php /phd/formats bigxhtml.php php.php /phd/include PhDConfig.class.php PhDIndex.class.php PhDObjectStorage.class.php PhDRender.class.php Log: Add these files to the correct branch

http://cvs.php.net/viewvc.cgi/phd/render.php?view=markup&rev=1.1 Index: phd/render.php +++ phd/render.php 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/formats/php.php?view=markup&rev=1.1 Index: phd/formats/php.php +++ phd/formats/php.php <?php /* $Id: php.php,v 1.1 2007/08/05 14:49:55 bjori Exp $ */ class PHPPhDFormat extends XHTMLPhDFormat { protected $CURRENT_ID = ""; protected $ext; public function __construct(PhDReader $reader, array $IDs, array $IDMap, $ext = "php") { parent::__construct($reader, $IDs, $IDMap, $ext); } public function format_function($open, $name) { $func = $this->readContent($name); $link = str_replace(array("_", "::", "->"), "-", $func); if (!substr_compare($this->CURRENT_ID, $link, -strlen($link)) || !($filename = PhDFormat::getFilename("function.$link"))) { return sprintf("<b>%s()</b>", $func); } return sprintf('<a href="%s.%s" class="function">%s()</a>', $filename, $this->ext, $func); } public function format_container_chunk($open, $name) { $this->CURRENT_ID = $id = PhDFormat::getID(); if ($open) { return "<div>"; } $chunks = PhDFormat::getContainer($id); $content = ""; if (count($chunks) > 1) { $content = '<ul class="chunklist chunklist_'.$name.'">'; if ($name == "reference") { foreach($chunks as $chunkid => $junk) { if ($chunkid == "parent") { continue; } $content .= sprintf('<li><a href="%s.%s">%s</a> — %s</li>', $chunkid, $this->ext, PhDFormat::getDescription($chunkid, false), PhDFormat::getDescription($chunkid, true)); } } else { foreach($chunks as $chunkid => $junk) { if ($chunkid == "parent") { continue; } $content .= sprintf('<li><a href="%s.%s">%s</a></li>', $chunkid, $this->ext, PhDFormat::getDescription($chunkid, true)); } } $content .= "</ul>\n"; } $content .= "</div>\n"; return $content; } } /* * 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(); } /* }}} */ }
« previous php.doc.cvs (#1948) next »