Example #1
0
 public function execute(Reader $r)
 {
     /* {{{ */
     ReaderKeeper::setReader($r);
     foreach ($this as $format) {
         $format->notify(Render::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 */
             /* break intentionally omitted */
             case \XMLReader::END_ELEMENT:
                 $name = $r->name;
                 $depth = $r->depth;
                 $attrs = array(Reader::XMLNS_DOCBOOK => array(), Reader::XMLNS_XML => array());
                 if ($r->hasAttributes) {
                     $r->moveToFirstAttribute();
                     do {
                         $attrs[$r->namespaceURI ?: Reader::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);
                 }
                 $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);
                     }
                 }
                 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);
                 }
                 break;
                 /* }}} */
             /* }}} */
             case \XMLReader::WHITESPACE:
                 /* {{{ */
             /* {{{ */
             case \XMLReader::SIGNIFICANT_WHITESPACE:
                 /* WS is always WS */
                 $retval = $r->value;
                 foreach ($this as $format) {
                     $format->appendData($retval);
                 }
                 break;
                 /* }}} */
             /* }}} */
             case \XMLReader::PI:
                 $target = $r->name;
                 $data = $r->value;
                 foreach ($this as $format) {
                     $format->parsePI($target, $data);
                 }
                 break;
         }
     }
     /* Closing time */
     foreach ($this as $format) {
         $format->notify(Render::FINALIZE, true);
     }
     $r->close();
     ReaderKeeper::popReader();
 }
Example #2
0
File: Index.php Project: philip/phd
 public function format_sdesc($open, $name, $attrs, $props)
 {
     if ($open) {
         $s = htmlentities(trim(ReaderKeeper::getReader()->readContent()), ENT_COMPAT, "UTF-8");
         if (empty($this->nfo[$this->currentid]["sdesc"])) {
             /* FIXME: How can I mark that node with "reparse" flag? */
             $this->nfo[$this->currentid]["sdesc"] = $s;
         } else {
             if (!is_array($this->nfo[$this->currentid]["sdesc"])) {
                 $this->nfo[$this->currentid]["sdesc"] = (array) $this->nfo[$this->currentid]["sdesc"];
             }
             //In the beginning of the array to stay compatible with 0.4
             array_unshift($this->nfo[$this->currentid]["sdesc"], $s);
         }
     }
 }
Example #3
0
 public function execute(Reader $r)
 {
     /* {{{ */
     ReaderKeeper::setReader($r);
     foreach ($this as $format) {
         $format->notify(Render::INIT, true);
     }
     $lastdepth = -1;
     $in_method_synopsis = false;
     $is_method_return_type = false;
     $method_return_type_content = "";
     while ($r->read()) {
         $type = $r->nodeType;
         $data = $retval = $name = $open = false;
         switch ($type) {
             case \XMLReader::ELEMENT:
                 /* {{{ */
                 $open = true;
                 /* break intentionally omitted */
             /* break intentionally omitted */
             case \XMLReader::END_ELEMENT:
                 $name = $r->name;
                 $depth = $r->depth;
                 $attrs = array(Reader::XMLNS_DOCBOOK => array(), Reader::XMLNS_XML => array());
                 if ($r->hasAttributes) {
                     $r->moveToFirstAttribute();
                     do {
                         $attrs[$r->namespaceURI ?: Reader::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;
                 }
                 if ($name === "methodsynopsis" && $open === true) {
                     $in_method_synopsis = true;
                 }
                 if ($name === "type" && $in_method_synopsis && $open == true) {
                     $is_method_return_type = true;
                 }
                 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 = $format->transformFromMap($open, $tag, $name, $attrs, $props);
                     } else {
                         $data = $format->{$tag}($open, $name, $attrs, $props);
                     }
                     if ($is_method_return_type) {
                         $method_return_type_content .= $data;
                     } else {
                         $format->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) {
                             if ($is_method_return_type) {
                                 // ":" is added in the
                                 // format_type_if_object_or_pseudo_text
                                 // method
                                 $data = $format->{$tag}($value, $name, true);
                             } else {
                                 $data = $format->{$tag}($value, $name);
                             }
                         } else {
                             if ($is_method_return_type) {
                                 $data = ": " . $format->TEXT($value);
                             } else {
                                 $data = $format->TEXT($value);
                             }
                         }
                     } else {
                         $data = $format->TEXT($value);
                     }
                     if ($data === false) {
                         if ($is_method_return_type) {
                             // Probably a primitive that doesn't have a special
                             // inner <span> tag. So add the : for return.
                             $method_return_type_content .= ": " . $value;
                         } else {
                             $format->appendData($value);
                         }
                     } else {
                         if ($is_method_return_type) {
                             // The ": " will have been added in the $data field
                             $method_return_type_content .= $data;
                         } else {
                             $format->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);
                     if ($is_method_return_type) {
                         $method_return_type_content .= $retval;
                     } else {
                         $format->appendData($retval);
                     }
                 }
                 break;
                 /* }}} */
             /* }}} */
             case \XMLReader::WHITESPACE:
                 /* {{{ */
             /* {{{ */
             case \XMLReader::SIGNIFICANT_WHITESPACE:
                 /* WS is always WS */
                 $retval = $r->value;
                 foreach ($this as $format) {
                     if ($is_method_return_type) {
                         $method_return_type_content .= $retval;
                     } else {
                         $format->appendData($retval);
                     }
                 }
                 break;
                 /* }}} */
             /* }}} */
             case \XMLReader::PI:
                 $target = $r->name;
                 $data = $r->value;
                 foreach ($this as $format) {
                     $retval = $format->parsePI($target, $data);
                     if ($retval) {
                         if ($is_method_return_type) {
                             $method_return_type_content .= $retval;
                         } else {
                             $format->appendData($retval);
                         }
                     }
                 }
                 break;
         }
         if ($in_method_synopsis && $name === "type" && $type === \XMLReader::END_ELEMENT) {
             $is_method_return_type = false;
             // There may be other type elements we don't want to buffer
             $in_method_synopsis = false;
         }
         // Constructors use the same rendering as methods. Return type content will be empty, but we need
         // to capture the </div>
         if (($name === "methodsynopsis" || $name == "constructorsynopsis") && $type === \XMLReader::END_ELEMENT) {
             $format->appendData($method_return_type_content);
             $format->appendData("</div>\n");
             $method_return_type_content = "";
         }
     }
     /* Closing time */
     foreach ($this as $format) {
         $format->notify(Render::FINALIZE, true);
     }
     $r->close();
     ReaderKeeper::popReader();
 }
Example #4
0
File: XHTML.php Project: philip/phd
 public function format_qandaset($open, $name, $attrs, $props)
 {
     if ($open) {
         $node = ReaderKeeper::getReader()->expand();
         $doc = new \DOMDocument();
         $doc->appendChild($node);
         $xp = new \DOMXPath($doc);
         $xp->registerNamespace("db", Reader::XMLNS_DOCBOOK);
         $questions = $xp->query("//db:qandaentry/db:question");
         $retval = '<div class="qandaset"><ol class="qandaset_questions">';
         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");
             }
             $retval .= '<li><a href="#' . $id . '">' . htmlentities($node->textContent, ENT_QUOTES, "UTF-8") . '</a></li>';
         }
         $retval .= "</ol></div>";
         return $retval;
     }
 }
Example #5
0
 public function format_entry($open, $name, $attrs, $props)
 {
     if ($open) {
         if ($this->inChangelog) {
             /* FIXME: How can I mark that node with "reparse" flag? */
             $this->currentChangelog[] = htmlentities(trim(ReaderKeeper::getReader()->readContent()), ENT_COMPAT, "UTF-8");
         }
     }
 }
Example #6
0
 public function format_changelog_entry($open, $name, $attrs, $props)
 {
     if ($this->isChangelogRow && $open) {
         $entryType = $this->cchunk['changelog']['entry'] == 'version' ? 'change' : 'version';
         $this->cchunk['changelog'][$entryType] = trim(ReaderKeeper::getReader()->readString());
         $this->cchunk['changelog']['entry'] = $entryType;
     }
 }