cvs: phd /phpdotnet/phd/Package/Pear BigXHTML.php XHTML.php
| From: | Moacir de Oliveira Miranda Júnior | Date: | Wed, 24 Jun 2009 14:02:40 +0000 |
| Subject: | cvs: phd /phpdotnet/phd/Package/Pear BigXHTML.php XHTML.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4232@lists.php.net to get a copy of this message | ||
moacir Wed Jun 24 14:02:40 2009 UTC
Modified files:
/phd/phpdotnet/phd/Package/Pear XHTML.php BigXHTML.php
Log:
added format_qandaset from enterprise
http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Package/Pear/XHTML.php?r1=1.1&r2=1.2&diff_format=u
Index: phd/phpdotnet/phd/Package/Pear/XHTML.php
diff -u phd/phpdotnet/phd/Package/Pear/XHTML.php:1.1 phd/phpdotnet/phd/Package/Pear/XHTML.php:1.2
--- phd/phpdotnet/phd/Package/Pear/XHTML.php:1.1 Tue Jun 23 16:17:48 2009
+++ phd/phpdotnet/phd/Package/Pear/XHTML.php Wed Jun 24 14:02:40 2009
@@ -144,7 +144,11 @@
'qandadiv' => 'format_div',
'qandaentry' => 'format_qandaentry',
'qandaset' => 'format_qandaset',
- 'question' => 'format_question',
+ 'question' => array(
+ /* DEFAULT */ 'format_question',
+ 'questions' => 'format_phd_question',
+ ),
+ 'questions' => 'ol',
'quote' => 'format_quote',
'replaceable' => 'format_replaceable',
'refentry' => 'format_chunk',
@@ -418,6 +422,16 @@
return $toc;
}
+ public function createLink($for, &$desc = null, $type = Format::SDESC) {
+ $retval = null;
+ if (isset($this->indexes[$for])) {
+ $rsl = $this->indexes[$for];
+ $retval = $rsl["filename"] . "." . $this->ext . '#' .
$rsl["docbook_id"];
+ $desc = $rsl["sdesc"] ?: $rsl["ldesc"];
+ }
+ return $retval;
+ }
+
/**
* Clean up HTML from empty paragraph tags (<p>).
*
@@ -1068,38 +1082,38 @@
return '</dl>' . $this->restorePara();
}
- /**
- * FIXME: This function is a crazy performance killer
- *
- * @param resource $stream Stream containing the contents of a Q&A section
- *
- * @return string
- */
- public function qandaset($stream)
- {
- $xml = stream_get_contents($stream);
+ public function format_qandaset($open, $name, $attrs, $props) {
+ if ($open) {
+ $node = $this->getReader()->expand();
+ $doc = new \DOMDocument;
+ $doc->appendChild($node);
- $old = libxml_use_internal_errors(true);
- $doc = new \DOMDocument('1.0', 'UTF-8');
- $doc->preserveWhitespace = false;
- $doc->loadXML(html_entity_decode(str_replace('&',
'&amp;', "<div>$xml</div>"), ENT_QUOTES,
'UTF-8'));
- if ($err = libxml_get_errors()) {
- echo 'qandaset xml problem in ' . $this->CURRENT_ID . "\n";
- print_r($err);
- libxml_clear_errors();
- }
- fclose($stream);
- libxml_use_internal_errors($old);
-
- $xpath = new \DOMXPath($doc);
- $nlist = $xpath->query('//div/dl/dt/strong');
- $ret = '<div class="qandaset"><ol
class="qandaset_questions">';
- $i = 0;
- foreach ($nlist as $node) {
- $ret .= '<li><a href="#'
.($this->cchunk['qandaentry'][$i++]). '">' .($node->textContent).
'</a></li>';
- }
+ $xp = new \DOMXPath($doc);
+ $xp->registerNamespace("db", Reader::XMLNS_DOCBOOK);
- return $ret.'</ol>'.$xml.'</div>';
+ $questions = $xp->query("//db:qandaentry/db:question");
+
+ $xml = '<questions xmlns="' .Reader::XMLNS_PHD.
'">';
+ foreach($questions as $node) {
+ $id = $xp->evaluate("ancestor::db:qandaentry",
$node)->item(0)->getAttributeNs(Reader::XMLNS_XML, "id");
+
+ /* FIXME: No ID? How can we create an anchor for it then? */
+ if (!$id) {
+ $id = uniqid("phd");
+ }
+
+ $node->setAttribute("xml:id", $id);
+ $xml .= $doc->saveXML($node);
+ }
+ $xml .= "</questions>";
+
+ $r = new Reader();
+ $r->XML($xml);
+
+ $render = new Render;
+ $render->attach($this);
+ $render->render($r);
+ }
}
public function format_qandaentry($open, $name, $attrs)
@@ -1127,6 +1141,15 @@
return '</strong></dt>';
}
+ public function format_phd_question($open, $name, $attrs, $props)
+ {
+ if ($open) {
+ $href = $this->createLink($attrs[Reader::XMLNS_XML]["id"]);
+ return '<li><a href="' .$href. '">';
+ }
+ return '</a></li>';
+ }
+
public function format_emphasis($open, $name, $attrs)
{
if (isset($attrs[Reader::XMLNS_DOCBOOK]['role']) &&
$attrs[Reader::XMLNS_DOCBOOK]['role'] == "bold")
http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Package/Pear/BigXHTML.php?r1=1.1&r2=1.2&diff_format=u
Index: phd/phpdotnet/phd/Package/Pear/BigXHTML.php
diff -u phd/phpdotnet/phd/Package/Pear/BigXHTML.php:1.1
phd/phpdotnet/phd/Package/Pear/BigXHTML.php:1.2
--- phd/phpdotnet/phd/Package/Pear/BigXHTML.php:1.1 Tue Jun 23 16:17:48 2009
+++ phd/phpdotnet/phd/Package/Pear/BigXHTML.php Wed Jun 24 14:02:40 2009
@@ -99,22 +99,5 @@
}
return $retval;
}
-
- public function format_qandaset($open, $name, $attrs) {
- if ($open) {
- $this->cchunk["qandaentry"] = array();
- $this->ostream = $this->fp;
- $this->fp = fopen("php://temp/maxmemory", "r+");
- return '';
- }
-
- $stream = $this->fp;
- $this->fp = $this->ostream;
- unset($this->ostream);
- rewind($stream);
-
- return parent::qandaset($stream);
- }
-
}