'.$navBar.' |
'.($prevId ? '' : '') .'
'.($nextId ? '' : '') .'
'.($parentId ? '' : '') .'
'; } public function footer($id) { return "\n | \n
'; break; default: return '
'; } } return '
'; } public function format_refsect($open, $name, $attrs) { static $role = 0; if ($open) { if(!isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) { $attrs[Reader::XMLNS_DOCBOOK]["role"] = "unknown-" . ++$role; } $this->role = $role = $attrs[Reader::XMLNS_DOCBOOK]["role"]; if (isset($attrs[Reader::XMLNS_XML]["id"])) { $id = $attrs[Reader::XMLNS_XML]["id"]; } else { $id = $name. "-" . $this->CURRENT_CHUNK . "-" . $role; } return '&$';
}
return ' $';
}
return "
";
}
public function format_initializer($open, $name, $attrs) {
if ($open) {
return ' = ';
}
return '';
}
public function format_parameter($open, $name, $attrs, $props)
{
if ($props["empty"]) {
return '';
}
if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) {
return '&';
}
return '';
}
return "
";
}
public function format_void($open, $name, $attrs, $props) {
if ($props['sibling'] == 'methodname') {
return ' ( void';
} else {
return 'void';
}
}
public function format_methodparam($open, $name, $attrs) {
if ($open) {
$content = '';
if ($this->params["count"] == 0) {
$content .= " (";
}
if (isset($attrs[Reader::XMLNS_DOCBOOK]["choice"]) && $attrs[Reader::XMLNS_DOCBOOK]["choice"] == "opt") {
$this->params["opt"]++;
$content .= "[";
} else if($this->params["opt"]) {
$content .= str_repeat("]", $this->params["opt"]);
$this->params["opt"] = 0;
}
if ($this->params["count"]) {
$content .= ",";
}
$content .= ' ';
++$this->params["count"];
return $content;
}
return "";
}
public function format_methodname($open, $name, $attr) {
if ($open) {
return ' ';
}
return '';
}
public function format_varname($open, $name, $attrs) {
if ($open) {
return '$';
}
return "";
}
public function format_fieldsynopsis_varname($open, $name, $attrs) {
if ($open) {
if ($this->cchunk["fieldsynopsis"]["modifier"] === "const") {
return '';
}
return '$';
}
return '';
}
public function format_footnoteref($open, $name, $attrs, $props) {
if ($open) {
$linkend = $attrs[Reader::XMLNS_DOCBOOK]["linkend"];
$found = false;
foreach($this->cchunk["footnote"] as $k => $note) {
if ($note["id"] === $linkend) {
return '[' .($k + 1). ']';
}
}
trigger_error("footnoteref ID '$linkend' not found", E_USER_WARNING);
return "";
}
}
public function format_footnote($open, $name, $attrs, $props) {
if ($open) {
$count = count($this->cchunk["footnote"]);
$noteid = isset($attrs[Reader::XMLNS_XML]["id"]) ? $attrs[Reader::XMLNS_XML]["id"] : $count + 1;
$note = array("id" => $noteid, "str" => "");
$this->cchunk["footnote"][$count] = $note;
if ($this->cchunk["table"]) {
$this->cchunk["tablefootnotes"][$count] = $noteid;
}
return '[' .($count + 1). ']';
}
return "";
}
/* {{{ FIXME: These are crazy workarounds :( */
public function format_footnote_constant($open, $name, $attrs, $props) {
$k = count($this->cchunk["footnote"]) - 1;
$this->cchunk["footnote"][$k]["str"] .= self::format_constant($open, $name, $attrs, $props);
return "";
}
public function format_footnote_constant_text($value, $tag) {
$k = count($this->cchunk["footnote"]) - 1;
$this->cchunk["footnote"][$k]["str"] .= $value;
return "";
}
public function format_footnote_para($open, $name, $attrs, $props) {
$k = count($this->cchunk["footnote"]) - 1;
if ($open) {
$this->cchunk["footnote"][$k]["str"] .= '';
return "";
}
$this->cchunk["footnote"][$k]["str"] .= "";
return "";
}
public function format_footnote_para_text($value, $tag) {
$k = count($this->cchunk["footnote"]) - 1;
$this->cchunk["footnote"][$k]["str"] .= $value;
return "";
}
/* }}} */
public function format_co($open, $name, $attrs, $props) {
if (($open || $props["empty"]) && isset($attrs[Reader::XMLNS_XML]["id"])) {
$co = ++$this->cchunk["co"];
return '' .str_repeat("*", $co) .'';
}
/* Suppress closing tag if any */
return "";
}
public function format_calloutlist($open, $name, $attrs) {
if ($open) {
$this->cchunk["callouts"] = 0;
return '';
}
return '
';
}
public function format_callout($open, $name, $attrs) {
if ($open) {
return '' .str_repeat("*", ++$this->cchunk["callouts"]). ' ';
}
return " \n";
}
public function format_quote($open, $name, $attrs) {
if ($open) {
return '"';
}
return '"';
}
public function format_manvolnum($open, $name, $attrs) {
if ($open) {
return '(';
}
return ")";
}
public function format_segmentedlist($open, $name, $attrs) {
$this->cchunk["segmentedlist"] = $this->dchunk["segmentedlist"];
if ($open) {
return '';
}
return '';
}
public function format_segtitle_text($value, $tag) {
$this->cchunk["segmentedlist"]["segtitle"][count($this->cchunk["segmentedlist"]["segtitle"])] = $value;
/* Suppress the text */
return "";
}
public function format_seglistitem($open, $name, $attrs) {
if ($open) {
$this->cchunk["segmentedlist"]["seglistitem"] = 0;
return '';
}
return '';
}
public function format_seg($open, $name, $attrs) {
if ($open) {
return '' .$this->cchunk["segmentedlist"]["segtitle"][$this->cchunk["segmentedlist"]["seglistitem"]++]. ':';
}
return '';
}
public function format_procedure($open, $name, $attrs) {
$this->cchunk["procedure"] = false;
if ($open) {
return '';
}
return '';
}
public function format_step($open, $name, $attrs) {
if ($open) {
$ret = "";
if ($this->cchunk["procedure"] === false) {
$this->cchunk["procedure"] = true;
$ret = '';
}
return $ret . "- ";
}
return '
';
}
public function format_variablelist($open, $name, $attrs) {
if ($open) {
return "\n";
}
return "
\n";
}
public function format_varlistentry($open, $name, $attrs) {
if ($open) {
return isset($attrs[Reader::XMLNS_XML]["id"]) ? '- ' : "
- \n";
}
return "
\n";
}
public function format_varlistentry_listitem($open, $name, $attrs) {
if ($open) {
return " - \n";
}
return "
\n";
}
public function format_term($open, $name, $attrs, $props) {
if ($open) {
if ($props["sibling"] == $name) {
return '
';
}
return '';
}
return "";
}
public function format_trademark($open, $name, $attrs, $props) {
if ($open) {
return '';
}
return '®';
}
public function format_userinput($open, $name, $attrs) {
if ($open) {
return '';
}
return "
";
}
public function format_systemitem($open, $name, $attrs) {
if ($open) {
$val = isset($attrs[Reader::XMLNS_DOCBOOK]["role"]) ? $attrs[Reader::XMLNS_DOCBOOK]["role"] : null;
switch($val) {
case "directive":
/* FIXME: Different roles should probably be handled differently */
default:
return '';
}
}
return "
";
}
public function format_example_content($open, $name, $attrs) {
if ($open) {
return '';
}
return "
";
}
public function format_programlisting($open, $name, $attrs) {
if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) {
$this->role = $attrs[Reader::XMLNS_DOCBOOK]["role"];
} else {
$this->role = false;
}
return '';
}
$this->role = false;
return "\n";
}
public function format_programlisting_text($value, $tag) {
return $this->CDATA($value);
}
public function format_screen($open, $name, $attrs) {
if ($open) {
return '';
}
return '';
}
public function format_constant($open, $name, $attrs)
{
if ($open) {
return "";
}
return "
";
}
public function admonition_title($title, $lang)
{
return '' .($this->autogen($title, $lang)). '';
}
public function format_admonition($open, $name, $attrs, $props) {
if ($open) {
return '' .$this->admonition_title($name, $props["lang"]);
}
return "";
}
public function format_authorgroup_author($open, $name, $attrs, $props) {
if ($open) {
if ($props["sibling"] !== $name) {
return '' .$this->admonition_title("by", $props["lang"]). ':
';
}
return '';
}
return "\n";
}
public function format_editor($open, $name, $attrs, $props) {
if ($open) {
return '' .$this->admonition_title("editedby", $props["lang"]). ': ';
}
return "\n";
}
public function format_note($open, $name, $attrs, $props) {
if ($open) {
return ''.$this->admonition_title("note", $props["lang"]). ': ';
}
return "
";
}
public function format_note_title($open, $name, $attrs)
{
if ($open) {
return '';
}
return '
';
}
public function format_example($open, $name, $attrs, $props) {
static $n = 0;
if ($open) {
++$n;
if (isset($props["id"])) {
return '';
}
return '';
}
return '';
}
public function format_example_title($open, $name, $attrs, $props)
{
if ($props["empty"]) {
return "";
}
if ($open) {
return "" . ($this->autogen('example', $props['lang'])
. (isset($this->cchunk["examples"]) ? ++$this->cchunk["examples"] : "")) . " ";
}
return "
";
}
public function format_table_title($open, $name, $attrs, $props)
{
if ($props["empty"]) {
return "";
}
if ($open) {
return "";
}
return " ";
}
public function format_mediaobject($open, $name, $attrs) {
$this->cchunk["mediaobject"] = $this->dchunk["mediaobject"];
if ($open) {
return '';
}
return '';
}
public function format_alt_text($value, $tag) {
$this->cchunk["mediaobject"]["alt"] = $value;
}
public function format_imagedata($open, $name, $attrs) {
$file = $attrs[Reader::XMLNS_DOCBOOK]["fileref"];
if ($newpath = $this->mediamanager->handleFile($file)) {
$curfile = $this->mediamanager->findFile($file);
$width = isset($attrs[Reader::XMLNS_DOCBOOK]["width"]) ? 'width="' . $attrs[Reader::XMLNS_DOCBOOK]["width"] . '"' : '';
$height = isset($attrs[Reader::XMLNS_DOCBOOK]["depth"]) ? 'height="' . $attrs[Reader::XMLNS_DOCBOOK]["depth"] . '"' : '';
$alt = 'alt="' . ($this->cchunk["mediaobject"]["alt"] !== false ? $this->cchunk["mediaobject"]["alt"] : basename($file)) . '"';
// Generate height and width when none are supplied.
if ($curfile && '' === $width . $height) {
list(,,,$dimensions,,,,) = getimagesize($curfile);
} else {
$dimensions = $width . ' ' . $height;
}
// Generate warnings when only 1 dimension supplied or alt is not supplied.
if (!$width xor !$height) {
v('Missing %s attribute for %s', (!$width ? 'width' : 'height'), $file, VERBOSE_MISSING_ATTRIBUTES);
}
if (false === $this->cchunk["mediaobject"]["alt"]) {
v('Missing alt attribute for %s', $file, VERBOSE_MISSING_ATTRIBUTES);
}
return '
';
} else {
return '';
}
}
public function format_table($open, $name, $attrs, $props) {
if ($open) {
$this->cchunk["table"] = true;
// Initialize an empty tgroup in case we never process such element
Format::tgroup(array());
$idstr = '';
if (isset($attrs[Reader::XMLNS_XML]["id"])) {
$idstr = ' id="' . $attrs[Reader::XMLNS_XML]["id"] . '"';
}
return '';
}
$this->cchunk["table"] = false;
$str = "";
if (isset($this->cchunk["tablefootnotes"]) && $this->cchunk["tablefootnotes"]) {
$opts = array(Reader::XMLNS_DOCBOOK => array());
$str = $this->format_tbody(true, "footnote", $opts, $props);
$str .= $this->format_row(true, "footnote", $opts, $props);
$str .= $this->format_entry(true, "footnote", $opts, $props+array("colspan" => $this->getColCount()));
foreach ($this->cchunk["tablefootnotes"] as $k => $noteid) {
$str .= '';
$str .= '[' .($k + 1). ']' .$this->cchunk["footnote"][$k]["str"];
unset($this->cchunk["footnote"][$k]);
$str .= "\n";
}
$str .= $this->format_entry(false, "footnote", $opts, $props);
$str .= $this->format_row(false, "footnote", $opts, $props);
$str .= $this->format_tbody(false, "footnote", $opts, $props);
$this->cchunk["tablefootnotes"] = $this->dchunk["tablefootnotes"];
}
return "$str
\n";
}
public function format_tgroup($open, $name, $attrs) {
if ($open) {
Format::tgroup($attrs[Reader::XMLNS_DOCBOOK]);
return '';
}
return '';
}
private static function parse_table_entry_attributes($attrs)
{
$style = array();
$retval = '';
if (!empty($attrs['align'])) {
if ('char' != $attrs['align']) {
$style[] = 'text-align: ' . $attrs['align'];
} elseif (isset($attrs['char'])) {
// There's no analogue in CSS, but as this stuff isn't supported
// in any browser, it is unlikely to appear in DocBook anyway
$retval .= ' align="char" char="'
. htmlspecialchars($attrs["char"], ENT_QUOTES) . '"';
if (isset($attrs['charoff'])) {
$retval .= ' charoff="'
. htmlspecialchars($attrs["charoff"], ENT_QUOTES) . '"';
}
}
}
if (isset($attrs["valign"])) {
$style[] = 'vertical-align: ' . $attrs["valign"];
}
if (isset($attrs["colwidth"])) {
if (preg_match('/^\\d+\\*$/', $attrs['colwidth'])) {
// relative_length measure has no analogue in CSS and is
// unsupported in browsers, leave as is
$retval .= ' width="' . $attrs['colwidth'] . '"';
} else {
// probably fixed width, use inline styles
$style[] = 'width: ' . $attrs['colwidth'];
}
}
return $retval . (empty($style) ? '' : ' style="' . implode('; ', $style) . ';"');
}
public function format_colspec($open, $name, $attrs)
{
if ($open) {
$str = self::parse_table_entry_attributes(Format::colspec($attrs[Reader::XMLNS_DOCBOOK]));
return ' ';
}
/* noop */
}
public function format_th($open, $name, $attrs)
{
if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]['valign'])) {
return '<' . $name . ' style="vertical-align: '
. $attrs[Reader::XMLNS_DOCBOOK]['valign'] . ';">';
} else {
return '<' . $name . '>';
}
}
return "$name>\n";
}
public function format_tbody($open, $name, $attrs)
{
if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]['valign'])) {
return '';
} else {
return '';
}
}
return "";
}
public function format_row($open, $name, $attrs)
{
if ($open) {
$idstr = '';
if (isset($attrs[Reader::XMLNS_XML]['id'])) {
$idstr = ' id="'. $attrs[Reader::XMLNS_XML]['id']. '"';
}
Format::initRow();
if (isset($attrs[Reader::XMLNS_DOCBOOK]['valign'])) {
return '';
} else {
return ' ';
}
}
return " \n";
}
public function format_th_entry($open, $name, $attrs, $props) {
if ($props["empty"]) {
return ' ';
}
if ($open) {
$colspan = Format::colspan($attrs[Reader::XMLNS_DOCBOOK]);
if ($colspan == 1) {
return '';
} else {
return ' ';
}
}
return ' ';
}
public function format_entry($open, $name, $attrs, $props) {
if ($props["empty"]) {
return ' ';
}
if ($open) {
$dbattrs = (array)Format::getColspec($attrs[Reader::XMLNS_DOCBOOK]);
$retval = "";
if (isset($dbattrs["colname"])) {
for($i=Format::getEntryOffset($dbattrs); $i>0; --$i) {
$retval .= ' ';
}
}
/*
* "colspan" is *not* an standard prop, only used to overwrite the
* colspan for s in tables
*/
if (isset($props["colspan"])) {
$colspan = $props["colspan"];
} else {
$colspan = Format::colspan($dbattrs);
}
$rowspan = Format::rowspan($dbattrs);
$moreattrs = self::parse_table_entry_attributes($dbattrs);
$sColspan = $colspan == 1 ? '' : ' colspan="' .((int)$colspan) . '"';
$sRowspan = $rowspan == 1 ? '' : ' rowspan="' .((int)$rowspan). '"';
return $retval. '';
}
return " ";
}
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 = '';
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 .= '- '.htmlentities($node->textContent, ENT_QUOTES, "UTF-8").'
';
}
$retval .= "
";
return $retval;
}
}
public function format_question($open, $name, $attrs, $props) {
if ($open) {
return '- ';
}
return '
';
}
public function format_phd_question($open, $name, $attrs, $props) {
if ($open) {
$href = $this->createLink($attrs[Reader::XMLNS_XML]["id"]);
return '- ';
}
return '
';
}
public function format_citation($open, $name, $attrs, $props) {
if ($open) {
return '[';
}
return ']';
}
public function format_email_text($value) {
return '<' . $value . '>';
}
public function format_bold_paragraph($open, $name, $attrs, $props)
{
if ($props["empty"]) {
return "";
}
if ($open) {
return "";
}
return "
";
}
/**
* Functions from the old XHTMLPhDFormat
*/
public function format_legalnotice_chunk($open, $name, $attrs) {
if ($open) {
return '';
}
return "\n";
}
public function format_div($open, $name, $attrs, $props) {
if ($open) {
return '';
}
return '';
}
public function format_screen_text($value, $tag) {
return nl2br($this->TEXT($value));
}
/**
* Renders a tag.
*
* @return string HTML code
*/
public function format_tag($open, $name, $attrs, $props) {
static $arFixes = array(
'attribute' => array('', ''),
'attvalue' => array('"', '"'),
'comment' => array('<!--', '-->'),
'element' => array('', ''),
'emptytag' => array('<', '/>'),
'endtag' => array('</', '>'),
'genentity' => array('&', ';'),
'localname' => array('', ''),
'namespace' => array('', ''),
'numcharref' => array('&#', ';'),
'paramentity' => array('%', ';'),
'pi' => array('<?', '?>'),
'prefix' => array('', ''),
'starttag' => array('<', '>'),
'xmlpi' => array('<?', '?>'),
);
if ($props['empty']) {
return '';
}
$class = 'starttag';
if (isset($attrs['class'])) {
$class = $attrs['class'];
}
if (!isset($arFixes[$class])) {
trigger_error('Unknown tag class "' . $class . '"', E_USER_WARNING);
$class = 'starttag';
}
if (!$open) {
return $arFixes[$class][1] . '';
}
return '' . $arFixes[$class][0];
}
public function format_dl($open, $name, $attrs, $props) {
if ($open) {
return '';
}
return '
';
}
public function format_itemizedlist($open, $name, $attrs, $props) {
if ($open) {
return '';
}
return '
';
}
public function format_orderedlist($open, $name, $attrs, $props) {
if ($open) {
$numeration = "1";
if (isset($attrs[Reader::XMLNS_DOCBOOK]["numeration"])) {
switch($attrs[Reader::XMLNS_DOCBOOK]["numeration"]) {
case "upperalpha":
$numeration = "A";
break;
case "loweralpha":
$numeration = "a";
break;
case "upperroman":
$numeration = "I";
break;
case "lowerroman":
$numeration = "i";
break;
}
}
return '';
}
return '
';
}
}
/*
* vim600: sw=4 ts=4 syntax=php et
* vim<600: sw=4 ts=4
*/