bjori Wed Aug 8 23:45:27 2007 UTC
Added files:
/phd/include PhDHelper.class.php
Modified files:
/phd build.php
/phd/formats xhtml.php
/phd/include PhDFormat.class.php PhDReader.class.php
Log:
- Allow multiple themes to be built at the same time
- Pass all attributes (if any) along to the format_* functions
http://cvs.php.net/viewvc.cgi/phd/build.php?r1=1.8&r2=1.9&diff_format=u
Index: phd/build.php
diff -u phd/build.php:1.8 phd/build.php:1.9
--- phd/build.php:1.8 Tue Aug 7 20:52:09 2007
+++ phd/build.php Wed Aug 8 23:45:26 2007
@@ -1,5 +1,5 @@
<?php
-/* $Id: build.php,v 1.8 2007/08/07 20:52:09 bjori Exp $ */
+/* $Id: build.php,v 1.9 2007/08/08 23:45:26 bjori Exp $ */
if (isset($argc) && $argc == 3) {
$manual = $argv[1];
@@ -35,12 +35,16 @@
set_error_handler("err");
}
-if(!file_exists("cache") || is_file("cache")) mkdir("cache") or die("Can't
create the cache directory");
+if(!file_exists("php") || is_file("php")) mkdir("php") or die("Can't create
the cache directory");
+if(!file_exists("html") || is_file("html")) mkdir("html") or die("Can't create
the cache directory");
+
require "include/PhDReader.class.php";
require "include/PhDFormat.class.php";
require "formats/xhtml.php";
-require "formats/php.php";
-require "themes/phpweb.php";
+require "themes/php/phpdotnet.php";
+require "themes/php/phpweb.php";
+require "themes/php/bightml.php";
+require "themes/php/chunkedhtml.php";
require "mktoc.php";
if ($err) {
@@ -50,42 +54,121 @@
->show();
}
+$themes = array();
$reader = new PhDReader($manual);
-$format = new phpweb($reader, $IDs, $IDMap, $version);
+$format = new XHTMLPhDFormat($IDs, $IDMap, "php");
+$themes["phpweb"] = new phpweb($IDs, $IDMap, $version);
+$themes["bightml"] = new bightml($IDs, $IDMap, $version);
+$themes["chunkedhtml"] = new chunkedhtml($IDs, $IDMap, $version);
+
+$formatmap = $format->getMap();
+$maps = array();
+$textmaps = array();
+foreach($themes as $name => $theme) {
+ $maps[$name] = $theme->getMap();
+ $textmaps[$name] = $theme->getTextMap();
+}
-$map = $format->getMap();
while($reader->read()) {
- $type = $reader->nodeType;
- $name = $reader->name;
+ $nodetype = $reader->nodeType;
+ $nodename = $reader->name;
- switch($type) {
+ switch($nodetype) {
case XMLReader::ELEMENT:
case XMLReader::END_ELEMENT:
- $open = $type == XMLReader::ELEMENT;
+ $open = $nodetype == XMLReader::ELEMENT;
- $funcname = "format_$name";
- if (isset($map[$name])) {
- $tag = $map[$name];
- if (is_array($tag)) {
- $tag = $reader->notXPath($tag);
- }
- if (strncmp($tag, "format_", 7)) {
- $retval = $format->transformFromMap($open, $tag, $name);
- break;
+ $funcname = "format_$nodename";
+ $skip = array();
+ foreach($maps as $theme => $map) {
+ if (isset($map[$nodename])) {
+ $tag = $map[$nodename];
+ if (is_array($tag)) {
+ $tag = $reader->notXPath($tag);
+ }
+ if ($tag) {
+ if (strncmp($tag, "format_", 7)) {
+ $retval = $themes[$theme]->transformFromMap($open,
$tag, $nodename);
+ if ($retval !== false) {
+ $themes[$theme]->appendData($retval,
$reader->isChunk);
+ $skip[] = $theme;
+ }
+ continue;
+ }
+ $funcname = $tag;
+ $retval = $themes[$theme]->{$funcname}($open, $nodename,
$reader->getAttributes());
+ if ($retval !== false) {
+ $themes[$theme]->appendData($retval, $reader->isChunk);
+ $skip[] = $theme;
+ }
+ continue;
+ }
}
- $funcname = $tag;
}
- $retval = $format->{$funcname}($open, $name);
+ if (count($skip) < count($themes)) {
+ if (isset($formatmap[$nodename])) {
+ $tag = $formatmap[$nodename];
+ if (is_array($tag)) {
+ $tag = $reader->notXPath($tag);
+ }
+ if (strncmp($tag, "format_", 7)) {
+ $retval = $format->transformFromMap($open, $tag,
$nodename);
+ foreach($themes as $name => $theme) {
+ if (!in_array($name, $skip)) {
+ $theme->appendData($retval, $reader->isChunk);
+ }
+ }
+ break;
+ }
+ $funcname = $tag;
+ $retval = $format->{$funcname}($open, $nodename,
$reader->getAttributes());
+ foreach($themes as $name => $theme) {
+ if (!in_array($name, $skip)) {
+ $theme->appendData($retval, $reader->isChunk);
+ }
+ }
+ }
+ }
break;
case XMLReader::TEXT:
- $retval = htmlspecialchars($reader->value, ENT_QUOTES);
+ $skip = array();
+ $value = $reader->value;
+ $tagname = $reader->getParentTagName();
+ foreach($textmaps as $theme => $map) {
+ if (isset($map[$tagname])) {
+ $tagname = $map[$tagname];
+ if (is_array($tagname)) {
+ $tagname = $reader->notXPath($tagname, $reader->depth-1);
+ }
+
+ if ($tagname) {
+ $retval = $themes[$theme]->{$tagname}($value, $tagname);
+ if ($retval !== false) {
+ $skip[] = $theme;
+ $themes[$theme]->appendData($retval, false);
+ }
+ }
+ }
+ }
+ if (count($skip) < count($themes)) {
+ $retval = htmlspecialchars($value, ENT_QUOTES);
+ foreach ($themes as $name => $theme) {
+ if (!in_array($name, $skip)) {
+ $theme->appendData($retval, false);
+ }
+ }
+ }
break;
case XMLReader::CDATA:
- $retval = $format->CDATA($reader->value);
+ $value = $reader->value;
+ $retval = $format->CDATA($value);
+ foreach($themes as $name => $theme) {
+ $theme->appendData($retval, false);
+ }
break;
case XMLReader::COMMENT:
@@ -96,13 +179,13 @@
continue 2;
default:
- trigger_error("Don't know how to handle {$name} {$type}",
E_USER_ERROR);
+ trigger_error("Don't know how to handle {$nodename} {$nodetype}",
E_USER_ERROR);
return;
}
- $format->appendData($retval, $reader->isChunk);
}
-copy("cache/manual.php", "cache/index.php");
+copy("php/manual.php", "php/index.php");
+copy("html/manual.html", "html/index.html");
$reader->close();
if ($err) {
http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.13&r2=1.14&diff_format=u
Index: phd/formats/xhtml.php
diff -u phd/formats/xhtml.php:1.13 phd/formats/xhtml.php:1.14
--- phd/formats/xhtml.php:1.13 Tue Aug 7 20:11:57 2007
+++ phd/formats/xhtml.php Wed Aug 8 23:45:26 2007
@@ -1,8 +1,8 @@
<?php
-/* $Id: xhtml.php,v 1.13 2007/08/07 20:11:57 bjori Exp $ */
+/* $Id: xhtml.php,v 1.14 2007/08/08 23:45:26 bjori Exp $ */
class XHTMLPhDFormat extends PhDFormat {
- protected $map = array( /* {{{ */
+ protected $elementmap = array( /* {{{ */
'article' => 'format_container_chunk',
'author' => 'div',
'authorgroup' => 'div', /* DocBook-xsl prints out "by" (i.e.
"PHP Manual by ...") */
@@ -32,6 +32,7 @@
'code' => 'code',
'collab' => 'span',
'collabname' => 'span',
+ 'colspec' => 'format_colspec',
'command' => 'span',
'computeroutput' => 'span',
'constant' => 'format_constant',
@@ -67,7 +68,9 @@
),
'literal' => 'i',
'mediaobject' => 'div',
- 'methodparam' => 'span',
+ 'methodparam' => 'format_methodparam',
+ 'methodsynopsis' => 'format_methodsynopsis',
+ 'methodname' => 'format_methodname',
'member' => 'li',
'note' => 'format_note',
'option' => 'span',
@@ -76,7 +79,10 @@
/* DEFAULT */ 'p',
'example' => 'format_example_content',
),
- 'parameter' => 'tt',
+ 'parameter' => array(
+ /* DEFAULT */ 'format_parameter',
+ 'methodparam' => 'format_methodparam_parameter',
+ ),
'part' => 'format_container_chunk',
'partintro' => 'div',
'personname' => 'span',
@@ -88,6 +94,9 @@
'proptype' => 'span',
'refentry' => 'format_chunk',
'reference' => 'format_container_chunk',
+ 'refsect1' => 'format_refsect1',
+ 'refname' => 'h1',
+ 'row' => 'format_row',
'screen' => 'format_screen',
'sect1' => 'format_chunk',
'sect2' => 'format_chunk',
@@ -110,6 +119,7 @@
'term' => 'span',
'tfoot' => 'format_th',
'thead' => 'format_th',
+ 'tgroup' => 'format_tgroup',
'tip' => 'div',
'title' => array(
/* DEFAULT */ 'h1',
@@ -123,22 +133,19 @@
'sect3' => 'h4',
'table' => 'format_bold_paragraph',
),
- 'type' => 'format_type',
+ 'type' => 'span',
'userinput' => 'format_userinput',
'variablelist' => 'format_variablelist',
'varlistentry' => 'format_varlistentry',
'varname' => 'var',
'warning' => 'div',
- 'xref' => 'format_link',
'year' => 'span',
); /* }}} */
- protected $CURRENT_ID = "";
- protected $ext = "html";
protected $role = false;
- public function __construct(PhDReader $reader, array $IDs, array $IDMap,
$ext = "html") {
- parent::__construct($reader, $IDs, $IDMap, $ext);
+ public function __construct(array $IDs, array $IDMap) {
+ parent::__construct($IDs, $IDMap);
}
/* Overwrite PhDFormat::readContent() to convert special HTML chars */
public function readContent($content = null) {
@@ -167,141 +174,123 @@
}
}
- public function format_container_chunk($open, $name) {
- $this->CURRENT_ID = $id = PhDFormat::getID();
+ public function format_container_chunk($open, $name, $attrs) {
if ($open) {
- return sprintf('<div id="%s" class="%s">', $id, $name);
+ return sprintf('<div id="%s" class="%s">',
$attrs[PhDReader::XMLNS_XML]["id"], $name);
}
return "</div>";
}
- public function format_chunk($open, $name) {
- $this->CURRENT_ID = $id = PhDFormat::getID();
+ public function format_chunk($open, $name, $attrs) {
if ($open) {
- return sprintf('<div id="%s" class="%s">', $id, $name);
+ if(isset($attrs[PhDReader::XMLNS_XML]["id"])) {
+ return sprintf('<div id="%s" class="%s">',
$attrs[PhDReader::XMLNS_XML]["id"], $name);
+ }
+ return sprintf('<div class="%s">', $name);
}
return "</div>";
}
- public function format_function($open, $name) {
- return sprintf('<a href="function.%s.html">%1$s</a>',
$this->readContent());
- }
- public function format_refsect1($open, $name) {
+ public function format_refsect1($open, $name, $attrs) {
if ($open) {
- return sprintf('<div class="refsect %s">',
PhDFormat::readAttribute("role"));
+ if(!isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) {
+ $attrs[PhDReader::XMLNS_DOCBOOK] = "unkown";
+ }
+ return sprintf('<div class="refsect %s">',
$attrs[PhDReader::XMLNS_DOCBOOK]["role"]);
}
return "</div>\n";
}
- public function format_link($open, $name) {
- $content = $fragment = "";
- $class = $name;
- if($linkto = PhDFormat::readAttribute("linkend")) {
- $id = $href = PhDFormat::getFilename($linkto);
- if ($id != $linkto) {
- $fragment = "#$linkto";
+
+ public function format_methodsynopsis($open, $name, $attrs) {
+ if ($open) {
+ $this->params = array("count" => 0, "opt" => 0, "content" => "");
+ return '<div class="methodsynopsis">';
+ }
+ $content = "";
+ if ($this->params["opt"]) {
+ $content = str_repeat("]", $this->params["opt"]);
+ }
+ $content .= ")";
+
+ $content .= "</div>\n";
+
+ return $content;
+ }
+ public function format_methodparam_parameter($open, $name, $attrs) {
+ if ($open) {
+ if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) {
+ return ' <tt class="parameter reference">&$';
}
- $href .= ".".$this->ext;
- } elseif($href = PhDFormat::readAttributeNs("href",
PhDReader::XMLNS_XLINK)) {
- $content = "» ";
- $class .= " external";
- }
- $content .= $name == "xref" ? PhDFormat::getDescription($id, false) :
$this->readContent($name);
- return sprintf('<a href="%s%s" class="%s">%s</a>', $href, $fragment,
$class, $content);
- }
- public function format_methodsynopsis($open, $root) {
- /* We read this element to END_ELEMENT so $open is useless */
- $content = '<div class="methodsynopsis">';
-
- $opt = $count = 0;
- while($child = PhDFormat::getNextChild($root)) {
- if ($child["type"] == XMLReader::END_ELEMENT) {
- $content .= "</span>\n";
- continue;
+ return ' <tt class="parameter">$';
+ }
+ return "</tt>\n";
+
+ }
+ public function format_parameter($open, $name, $attrs) {
+ if ($open) {
+ if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) {
+ return '<i><tt class="parameter reference">&';
}
- $name = $child["name"];
- switch($name) {
- case "parameter":
- $content .= sprintf('<span class="%s">%s$%s</span>', $name,
$this->readAttribute("role") == "reference" ? "&" : "",
$this->readContent($name));
- break;
- case "type":
- $content .= sprintf('<span class="%s">%s</span> ', $name,
$this->readContent($name));
- break;
- case "methodname":
- $content .= sprintf('<span class="%s"><b>%s</b></span>',
$name, $this->readContent($name));
- break;
+ return '<i><tt class="parameter">';
+ }
+ return "</tt></i>\n";
+ }
- case "methodparam":
- if ($count == 0) {
+ public function format_methodparam($open, $name, $attrs) {
+ if ($open) {
+ $content = '';
+ if ($this->params["count"] == 0) {
$content .= " (";
}
- if ($this->readAttribute("choice") == "opt") {
- $opt++;
+ if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["choice"]) &&
$attrs[PhDReader::XMLNS_DOCBOOK]["choice"] == "opt") {
+ $this->params["opt"]++;
$content .= "[";
- } else if($opt) {
- $content .= str_repeat("]", $opt);
- $opt = 0;
+ } else if($this->params["opt"]) {
+ $content .= str_repeat("]", $this->params["opt"]);
+ $this->params["opt"] = 0;
}
- if ($count) {
+ if ($this->params["count"]) {
$content .= ",";
}
$content .= ' <span class="methodparam">';
- ++$count;
-
- break;
- }
+ ++$this->params["count"];
+ return $content;
}
- if ($opt) {
- $content .= str_repeat("]", $opt);
- }
- $content .= ")";
-
- $content .= "</div>";
- return $content;
+ return "</span>";
}
- public function format_refnamediv($open, $root) {
- while ($child = PhDFormat::getNextChild($root)) {
- $name = $child["name"];
- switch($name) {
- case "refname":
- $refname = $this->readContent($name);
- break;
- case "refpurpose":
- $refpurpose = $this->readContent($name);
- break;
- }
+ public function format_methodname($open, $name, $attr) {
+ if ($open) {
+ return ' <span class="methodname"><b>';
}
-
- return sprintf('<div class="refnamediv"><h1 class="refname">%s</h1><p
class="refpurpose">%1$s â %s</p></div>', $refname, $refpurpose);
+ return '</b></span>';
}
- public function format_variablelist($open, $name) {
+
+ public function format_variablelist($open, $name, $attrs) {
if ($open) {
return "<dl>\n";
}
return "</dl>\n";
}
- public function format_varlistentry($open, $name) {
+ public function format_varlistentry($open, $name, $attrs) {
if ($open) {
- $id = PhDFormat::getID();
- if ($id) {
- return sprintf('<dt id="%s">', $id);
- }
- return "<dt>\n";
+ return isset($attrs[PhDReader::XMLNS_XML]["id"]) ? sprintf('<dt
id="%s">', $attrs[PhDReader::XMLNS_XML]["id"]) : "<dt>\n";
}
return "</dt>\n";
}
- public function format_varlistentry_listitem($open, $name) {
+ public function format_varlistentry_listitem($open, $name, $attrs) {
if ($open) {
return "<dd>\n";
}
return "</dd>\n";
}
- public function format_userinput($open, $name) {
+ public function format_userinput($open, $name, $attrs) {
if ($open) {
return sprintf('<strong class="%s"><code>', $name);
}
return "</code></strong>\n";
}
- public function format_systemitem($open, $name) {
+ public function format_systemitem($open, $name, $attrs) {
if ($open) {
- switch($this->readAttribute("role")) {
+ $val = isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"]) ?
$attrs[PhDReader::XMLNS_DOCBOOK]["role"] : null;
+ switch($val) {
case "directive":
/* FIXME: Different roles should probably be handled differently */
default:
@@ -310,83 +299,50 @@
}
return "</code>\n";
}
- public function format_type($open, $name) {
- $type = $this->readContent($name);
- $t = strtolower($type);
- $href = $fragment = "";
-
- switch($t) {
- case "bool":
- $href = "language.types.boolean";
- break;
- case "int":
- $href = "language.types.integer";
- break;
- case "double":
- $href = "language.types.float";
- break;
- case "boolean":
- case "integer":
- case "float":
- case "string":
- case "array":
- case "object":
- case "resource":
- case "null":
- $href = "language.types.$t";
- break;
- case "mixed":
- case "number":
- case "callback":
- $href = "language.pseudo-types";
- $fragment = "language.types.$t";
- break;
- }
- if ($href) {
- return sprintf('<a href="%s.%s%s" class="%s %s">%5$s</a>', $href,
$this->ext, ($fragment ? "#$fragment" : ""), $name, $type);
- }
- return sprintf('<span class="%s %s">%2$s</span>', $name, $type);
- }
- public function format_example_content($open, $name) {
+ public function format_example_content($open, $name, $attrs) {
if ($open) {
return '<div class="example-contents"><p>';
}
return "</p></div>";
}
- public function format_programlisting($open, $name) {
+ public function format_programlisting($open, $name, $attrs) {
if ($open) {
- $this->role = PhDFormat::readAttribute("role");
+ if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) {
+ $this->role = $attrs[PhDReader::XMLNS_DOCBOOK]["role"];
+ } else {
+ $this->role = false;
+ }
return '<div class="example-contents">';
}
$this->role = false;
return "</div>\n";
}
- public function format_screen($open, $name) {
+ public function format_screen($open, $name, $attrs) {
if ($open) {
return '<div class="example-contents"><pre>';
}
return '</pre></div>';
}
- public function format_constant($open, $name) {
+ public function format_constant($open, $name, $attrs) {
if ($open) {
return "<b><tt>";
}
return "</tt></b>";
}
- public function format_note($open, $name) {
+ public function format_note($open, $name, $attrs) {
if ($open) {
return '<blockquote><p>';
}
return "</p></blockquote>";
}
- public function format_note_title($open, $name) {
+ public function format_note_title($open, $name, $attrs) {
if ($open) {
return '<b>';
}
return '</b>';
}
- public function format_bold_paragraph($open, $name) {
+ public function format_bold_paragraph($open, $name, $attrs) {
if ($open) {
return "<p><b>";
}
@@ -394,15 +350,15 @@
}
- public function format_table($open, $name) {
+ public function format_table($open, $name, $attrs) {
if ($open) {
return '<table border="5">';
}
return "</table>\n";
}
- public function format_tgroup($open, $name) {
+ public function format_tgroup($open, $name, $attrs) {
if ($open) {
- $attrs = PhDFormat::tgroup();
+ PhDFormat::tgroup($attrs[PhDReader::XMLNS_DOCBOOK]);
return "<colgroup>\n";
}
return "</colgroup>\n";
@@ -423,58 +379,57 @@
}
return $retval;
}
- public function format_colspec($open, $name) {
+ public function format_colspec($open, $name, $attrs) {
if ($open) {
- $attrs =
self::parse_table_entry_attributes(PhDFormat::colspec(PhDFormat::getAttributes()));
+ $str =
self::parse_table_entry_attributes(PhDFormat::colspec($attrs[PhDReader::XMLNS_DOCBOOK]));
- return sprintf('<col %s />', $attrs);
+ return sprintf('<col %s />', $str);
}
/* noop */
}
- public function format_th($open, $name) {
+ public function format_th($open, $name, $attrs) {
if ($open) {
- $valign = PhDFormat::valign();
+ $valign = PhDFormat::valign($attrs[PhDReader::XMLNS_DOCBOOK]);
return sprintf('<%s valign="%s">', $name, $valign);
}
return "</$name>\n";
}
- public function format_tbody($open, $name) {
+ public function format_tbody($open, $name, $attrs) {
if ($open) {
- $valign = PhDFormat::valign();
+ $valign = PhDFormat::valign($attrs[PhDReader::XMLNS_DOCBOOK]);
return sprintf('<tbody valign="%s">', $valign);
}
return "</tbody>";
}
- public function format_row($open, $name) {
+ public function format_row($open, $name, $attrs) {
if ($open) {
PhDFormat::initRow();
- $valign = PhDFormat::valign();
+ $valign = PhDFormat::valign($attrs[PhDReader::XMLNS_DOCBOOK]);
return sprintf('<tr valign="%s">', $valign);
}
return "</tr>\n";
}
- public function format_th_entry($open, $name) {
+ public function format_th_entry($open, $name, $attrs = array()) {
if ($open) {
- $attrs = PhDFormat::getAttributes();
- $colspan = PhDFormat::colspan($attrs);
+ $colspan = PhDFormat::colspan($attrs[PhDReader::XMLNS_DOCBOOK]);
return sprintf('<th colspan="%d">', $colspan);
}
return '</th>';
}
- public function format_entry($open, $name) {
+ public function format_entry($open, $name, $attrs) {
if ($open) {
- $attrs = PhDFormat::getColspec(PhDFormat::getAttributes());
+ $dbattrs = PhDFormat::getColspec($attrs[PhDReader::XMLNS_DOCBOOK]);
$retval = "";
- if (isset($attrs["colname"])) {
- for($i=PhDFormat::getEntryOffset($attrs); $i>0; --$i) {
+ if (isset($dbattrs["colname"])) {
+ for($i=PhDFormat::getEntryOffset($dbattrs); $i>0; --$i) {
$retval .= '<td class="empty"> </td>';
}
}
- $colspan = PhDFormat::colspan($attrs);
- $rowspan = PhDFormat::rowspan($attrs);
- $moreattrs = self::parse_table_entry_attributes($attrs);
+ $colspan = PhDFormat::colspan($dbattrs);
+ $rowspan = PhDFormat::rowspan($dbattrs);
+ $moreattrs = self::parse_table_entry_attributes($dbattrs);
return sprintf('%s<td colspan="%d" rowspan="%d" %s>', $retval,
$colspan, $rowspan, $moreattrs);
}
return "</td>";
http://cvs.php.net/viewvc.cgi/phd/include/PhDFormat.class.php?r1=1.4&r2=1.5&diff_format=u
Index: phd/include/PhDFormat.class.php
diff -u phd/include/PhDFormat.class.php:1.4 phd/include/PhDFormat.class.php:1.5
--- phd/include/PhDFormat.class.php:1.4 Sun Aug 5 22:50:04 2007
+++ phd/include/PhDFormat.class.php Wed Aug 8 23:45:26 2007
@@ -1,73 +1,23 @@
<?php
-/* $Id: PhDFormat.class.php,v 1.4 2007/08/05 22:50:04 bjori Exp $ */
+/* $Id: PhDFormat.class.php,v 1.5 2007/08/08 23:45:26 bjori Exp $ */
-abstract class PhDFormat {
- private $reader;
- private $IDs = array();
- private $IDMap = array();
+abstract class PhDFormat extends PhDHelper {
private $TABLE = array();
- protected $ext = "";
- /* abstract */ protected $map = array();
-
- public function __construct(PhDReader $reader, array $IDs, array $IDMap,
$ext) {
- $this->reader = $reader;
- $this->IDs = $IDs;
- $this->IDMap = $IDMap;
- $this->ext = $ext;
- }
- final public function getFilename($id) {
- return isset($this->IDs[$id]) ? $this->IDs[$id]["filename"] : false;
- }
- final public function getDescription($id, $long = false) {
- return $long ?
- ($this->IDs[$id]["ldesc"] ? $this->IDs[$id]["ldesc"] :
$this->IDs[$id]["sdesc"]) :
- ($this->IDs[$id]["sdesc"] ? $this->IDs[$id]["sdesc"] :
$this->IDs[$id]["ldesc"]);
- }
- final public function getContainer($id) {
- return $this->IDMap[$id];
- }
- final public function getParent($id) {
- return $this->IDMap[$id]["parent"];
- }
- final public function getMap() {
- return $this->map;
- }
-
- /* PhDReader wrapper functions */
- public function getID() {
- return $this->reader->getID();
- }
- public function readContent($node = null) {
- return $this->reader->readContent($node);
- }
- public function readAttribute($attr) {
- return $this->reader->readAttribute($attr);
- }
- public function readAttributeNs($attr, $ns) {
- return $this->reader->readAttributeNs($attr, $ns);
- }
- public function getAttributes() {
- return $this->reader->getAttributes();
- }
- public function getNextChild($node) {
- return $this->reader->readNode($node) ? array("type" =>
$this->reader->nodeType, "name" => $this->reader->name) : false;
- }
+
/* abstract functions */
abstract public function transformFromMap($open, $tag, $name);
abstract public function CDATA($data);
abstract public function __call($func, $args);
/* Table helper functions */
- public function tgroup() {
- $attrs = self::getAttributes();
-
- $this->TABLE["cols"] = $attrs["cols"];
- unset($attrs["cols"]);
+ public function tgroup($attrs) {
+ if (isset($attrs["cols"])) {
+ $this->TABLE["cols"] = $attrs["cols"];
+ unset($attrs["cols"]);
+ }
$this->TABLE["defaults"] = $attrs;
$this->TABLE["colspec"] = array();
-
- return $attrs;
}
public function colspec(array $attrs) {
$colspec = self::getColSpec($attrs);
@@ -83,9 +33,8 @@
return array_merge($defaults, $this->TABLE["defaults"], $attrs);
}
- public function valign() {
- $valign = self::readAttribute("valign");
- return $valign ? $valign : "middle";
+ public function valign($attrs) {
+ return isset($attrs["valign"]) ? $attrs["valign"] : "middle";
}
public function initRow() {
$this->TABLE["next_colnum"] = 1;
@@ -128,6 +77,10 @@
}
}
+
+interface PhDTheme {
+ public function appendData($data, $isChunk);
+}
/*
* vim600: sw=4 ts=4 fdm=syntax syntax=php et
* vim<600: sw=4 ts=4
http://cvs.php.net/viewvc.cgi/phd/include/PhDReader.class.php?r1=1.7&r2=1.8&diff_format=u
Index: phd/include/PhDReader.class.php
diff -u phd/include/PhDReader.class.php:1.7 phd/include/PhDReader.class.php:1.8
--- phd/include/PhDReader.class.php:1.7 Sun Aug 5 14:49:55 2007
+++ phd/include/PhDReader.class.php Wed Aug 8 23:45:26 2007
@@ -1,11 +1,12 @@
<?php
-/* $Id: PhDReader.class.php,v 1.7 2007/08/05 14:49:55 bjori Exp $ */
+/* $Id: PhDReader.class.php,v 1.8 2007/08/08 23:45:26 bjori Exp $ */
//6271
class PhDReader 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";
const OPEN_CHUNK = 0x01;
const CLOSE_CHUNK = 0x02;
@@ -61,17 +62,19 @@
}
}
- public function notXPath($tag) {
- $depth = $this->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 notXPath($tag, $depth = 0) {
+ if(!$depth) {
+ $depth = $this->depth;
+ }
+ do {
+ if (isset($tag[$this->STACK[--$depth]])) {
+ $tag = $tag[$this->STACK[$depth]];
+ } else {
+ $tag = $tag[0];
+ }
+ } while (is_array($tag));
+ return $tag;
+ }
/* Seek to an ID within the file. */
public function seek($id) {
@@ -93,6 +96,9 @@
return "";
}
+ public function getParentTagName() {
+ return $this->STACK[$this->depth-1];
+ }
public function read() {
$this->isChunk = false;
if(XMLReader::read()) {
@@ -140,16 +146,17 @@
}
/* Get all attributes of current node */
public function getAttributes() {
+ $attrs = array(PhDReader::XMLNS_DOCBOOK => array(),
PhDReader::XMLNS_XML => array());
if ($this->hasAttributes) {
- $attrs = array();
XMLReader::moveToFirstAttribute();
do {
+ $k = $this->namespaceURI;
+ $attrs[!empty($k) ? $k :
PhDReader::XMLNS_DOCBOOK][$this->localName] = $this->value;
$attrs[$this->name] = $this->value;
} while (XMLReader::moveToNextAttribute());
XMLReader::moveToElement();
- return $attrs;
}
- return array();
+ return $attrs;
}
http://cvs.php.net/viewvc.cgi/phd/include/PhDHelper.class.php?view=markup&rev=1.1
Index: phd/include/PhDHelper.class.php
+++ phd/include/PhDHelper.class.php
<?php
/* $Id: PhDHelper.class.php,v 1.1 2007/08/08 23:45:26 bjori Exp $ */
class PhDHelper {
private $IDs = array();
private $IDMap = array();
/* abstract */ protected $elementmap = array();
/* abstract */ protected $textmap = array();
public function __construct(array $IDs, array $IDMap) {
$this->IDs = $IDs;
$this->IDMap = $IDMap;
}
final public function getFilename($id) {
return isset($this->IDs[$id]) ? $this->IDs[$id]["filename"] : false;
}
final public function getDescription($id, $long = false) {
return $long ?
($this->IDs[$id]["ldesc"] ? $this->IDs[$id]["ldesc"] :
$this->IDs[$id]["sdesc"]) :
($this->IDs[$id]["sdesc"] ? $this->IDs[$id]["sdesc"] :
$this->IDs[$id]["ldesc"]);
}
final public function getContainer($id) {
return $this->IDMap[$id];
}
final public function getParent($id) {
return $this->IDMap[$id]["parent"];
}
final public function getMap() {
return $this->elementmap;
}
final public function getTextMap() {
return $this->textmap;
}
}
/*
* vim600: sw=4 ts=4 fdm=syntax syntax=php et
* vim<600: sw=4 ts=4
*/