public function format_root_set($open, $name, $attrs, $props) { if ($open) { parent::newChunk(); $this->cchunk = $this->dchunk; $pdfDoc = new PdfWriter(); try { $pdfDoc->setCompressionMode(\HaruDoc::COMP_ALL); } catch (\HaruException $e) { v("PDF Compression failed, you need to compile libharu with Zlib...", E_USER_WARNING); } parent::setPdfDoc($pdfDoc); if (isset($attrs[Reader::XMLNS_XML]["base"]) && ($base = $attrs[Reader::XMLNS_XML]["base"])) { parent::setChunkInfo("xml-base", $base); } $id = $attrs[Reader::XMLNS_XML]["id"]; $this->cchunk["root-outline"] = $this->cchunk["id-to-outline"][$id] = $pdfDoc->createOutline(Format::getShortDescription($id), null, true); $this->setIdToPage($id); } else { $this->resolveLinks($this->cchunk["setname"]); $pdfDoc = parent::getPdfDoc(); v("Writing Full PDF Manual (%s)", $this->cchunk["setname"], VERBOSE_TOC_WRITING); $filename = $this->getOutputDir(); if (Config::output_filename()) { $filename .= Config::output_filename(); } else { $filename .= strtolower($this->getFormatName()) . $this->getExt(); } $pdfDoc->saveToFile($filename); unset($pdfDoc); } return ""; }
/** * Add the header to this file. * * @param string $id The id of this chunk * * @return string */ public function header($id) { $ext = $this->ext; $parent = Format::getParent($id); //we link toc feeds if there are children if (count($this->getChildren($id)) > 0) { $extraHeader = <<<XML <link rel="alternate" type="application/atom+xml" title="Live Bookmarks" href="feeds/{$id}.atom" /> XML; } else { $extraHeader = ''; } if (!$parent || $parent == 'ROOT') { return '<?php sendManualHeaders("UTF-8","en"); setupNavigation(array( "home" => array("index.php", "' . addslashes($this->title) . '"), "prev" => array("#", ""), "next" => array("#", ""), "up" => array("#", ""), "toc" => array( array("#", "")))); manualHeader("index.php"' . ', ' . var_export($this->title, true) . ', ' . var_export($extraHeader, true) . '); ?> '; } $toc = array(); $siblingIDs = Format::getChildren($parent); foreach ($siblingIDs as $sid) { $sdesc = Format::getShortDescription($sid); $ldesc = Format::getLongDescription($sid); $toc[] = array($sid . $ext, empty($sdesc) ? $ldesc : $sdesc); } $prev = $next = array(null, null); if ($prevID = Format::getPrevious($id)) { $prev = array(Format::getFilename($prevID) . $ext, Format::getLongDescription($prevID)); } if ($nextID = Format::getNext($id)) { $next = array(Format::getFilename($nextID) . $ext, Format::getLongDescription($nextID)); } // Build the PEAR navigation table $nav = array('home' => array('index' . $ext, $this->title), 'prev' => $prev, 'next' => $next, 'up' => array($this->getFilename($parent) . $ext, Format::getLongDescription($parent)), 'toc' => $toc); return "<?php \n" . "sendManualHeaders(\"UTF-8\", \"{$this->lang}\");\n" . "setupNavigation(" . var_export($nav, true) . ");\n" . 'manualHeader("' . $this->getFilename($id) . $ext . '"' . ', ' . var_export(Format::getLongDescription($id), true) . ', ' . var_export($extraHeader, true) . ');' . "\n" . "?>\n"; }
public function header($id) { $title = Format::getShortDescription($id); $parent = Format::getParent($id); $next = $prev = $up = array(null, null); if ($parent && $parent != "ROOT") { $siblings = Format::getChildren($parent); if ($nextId = Format::getNext($id)) { $next = array(Format::getFilename($nextId) . $this->getExt(), Format::getShortDescription($nextId)); } if ($prevId = Format::getPrevious($id)) { $prev = array(Format::getFilename($prevId) . $this->getExt(), Format::getShortDescription($prevId)); } $up = array($parent . $this->getExt(), Format::getShortDescription($parent)); } $this->nav = <<<NAV <div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="{$prev[0]}">{$prev[1]}</a></div> <div class="next" style="text-align: right; float: right;"><a href="{$next[0]}">{$next[1]}</a></div> <div class="up"><a href="{$up[0]}">{$up[1]}</a></div> </div> NAV; return "<?php include_once '../include/init.inc.php'; echo site_header('{$title}');?>\n" . $this->nav . "<hr />\n"; }
/** * Format a link for an element * * @param bool $open If the link should be opened. * @param string $name Name of the element. * @param array $attrs Attributes present for the element. Array keys are the attribute namespaces. * @param array $props Properties * * @return string */ public function format_link($open, $name, $attrs, $props) { if ($open) { $content = $fragment = ''; $class = $name; if (isset($attrs[Reader::XMLNS_DOCBOOK]['linkend'])) { $linkto = $attrs[Reader::XMLNS_DOCBOOK]['linkend']; $id = $href = Format::getFilename($linkto); if ($id != $linkto) { $fragment = "#{$linkto}"; } if ($this->chunked) { $href .= $this->ext; } } elseif (isset($attrs[Reader::XMLNS_XLINK]['href'])) { $href = $attrs[Reader::XMLNS_XLINK]['href']; $class .= ' external'; } if ($name == 'xref') { if ($this->chunked) { $link = $href; } else { $link = '#'; if (isset($linkto)) { $link .= $linkto; } else { $link .= $href; } } return '<a href="' . htmlspecialchars($link) . '" class="' . $class . '">' . ($content . Format::getShortDescription($id)) . '</a>'; } elseif ($props['empty']) { if ($this->chunked) { $link = ''; } else { $link = '#'; } return '<a href="' . $link . $href . $fragment . '" class="' . $class . '">' . $content . $href . $fragment . '</a>'; } else { if ($this->chunked) { $link = $href . $fragment; } elseif (isset($linkto)) { if ($fragment) { $link = $fragment; } else { $link = "#{$href}"; } } else { $link = $href; } return '<a href="' . htmlspecialchars($link) . '" class="' . $class . '">' . $content; } } return '</a>'; }
public function header($id) { static $written_toc = array(); $ext = $this->getExt(); $parent = Format::getParent($id); $filename = "toc" . DIRECTORY_SEPARATOR . $parent . ".inc"; $up = array(0 => null, 1 => null); $incl = ''; $next = $prev = array(null, null); if ($parent && $parent != "ROOT") { $siblings = Format::getChildren($parent); if (!isset($written_toc[$filename])) { $written_toc[$filename] = true; $toc = $toc_deprecated = array(); foreach ($siblings as $sid) { $sibling_short_desc = Format::getShortDescription($sid); $entry = array(Format::getFilename($sid) . $ext, $sibling_short_desc); if (isset($this->deprecated[$sibling_short_desc])) { $toc_deprecated[] = $entry; } else { $toc[] = $entry; } } $parents = array(); $p = $parent; while (($p = Format::getParent($p)) && $p != "ROOT") { $parents[] = array(Format::getFilename($p) . $ext, Format::getShortDescription($p)); } $content = '<?php $TOC = ' . var_export($toc, true) . '; $TOC_DEPRECATED = ' . var_export($toc_deprecated, true) . '; $PARENTS = ' . var_export($parents, true) . ';'; file_put_contents($this->getOutputDir() . $filename, $content); v("Wrote TOC (%s)", $this->getOutputDir() . $filename, VERBOSE_TOC_WRITING); } $incl = 'include_once dirname(__FILE__) ."/toc/' . $parent . '.inc";'; $up = array(Format::getFilename($parent) . $ext, Format::getShortDescription($parent)); if ($prevId = Format::getPrevious($id)) { $prev = array(Format::getFilename($prevId) . $ext, Format::getShortDescription($prevId)); } if ($nextId = Format::getNext($id)) { $next = array(Format::getFilename($nextId) . $ext, Format::getShortDescription($nextId)); } } $setup = array("home" => array('index' . $ext, $this->getTitle()), "head" => array("UTF-8", $this->lang), "this" => array($id . $ext, Format::getShortDescription($id)), "up" => $up, "prev" => $prev, "next" => $next, "alternatives" => $this->cchunk["alternatives"]); if ($this->getChildren($id)) { $lang = Config::language(); $setup["extra_header_links"] = array("rel" => "alternate", "href" => "/manual/{$lang}/feeds/{$id}.atom", "type" => "application/atom+xml"); } $var = var_export($setup, true); return '<?php include_once $_SERVER[\'DOCUMENT_ROOT\'] . \'/include/shared-manual.inc\'; $TOC = array(); $TOC_DEPRECATED = array(); $PARENTS = array(); ' . $incl . ' $setup = ' . $var . '; $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); manual_header(); ?> '; }
private function collectContent($attrs) { if (isset($attrs[Reader::XMLNS_XML]["id"]) && $this->isChunkID($attrs[Reader::XMLNS_XML]["id"])) { $id = $attrs[Reader::XMLNS_XML]["id"]; $this->lastContent = array("name" => Format::getShortDescription($id), "reference" => "res\\" . (Format::getFilename($id) ? Format::getFilename($id) : $id) . $this->ext, "hasChild" => count(Format::getChildren($id)) > 0); } }
public function format_xref($open, $name, $attrs, $props) { if ($props['empty']) { return "\"" . Format::getShortDescription($attrs[Reader::XMLNS_DOCBOOK]["linkend"]) . "\""; } return ""; }
public function format_tocsect2($open, $name, $attrs) { if (!isset($attrs[Reader::XMLNS_XML]["id"])) { return ""; } $id = $attrs[Reader::XMLNS_XML]["id"]; $hasChild = count(Format::getChildren($id)) > 0; if ($open) { $name = htmlspecialchars(Format::getShortDescription($id), ENT_QUOTES, 'UTF-8'); $url = (Format::getFilename($id) ? Format::getFilename($id) : $id) . $this->getExt(); fwrite($this->getFileStream(), " <tocsect2 name=\"{$name}\" url=\"{$url}\"/>\n"); } return ""; }
public function format_link($open, $name, $attrs, $props) { if ($open && !$props["empty"]) { $this->pdfDoc->setFont(PdfWriter::FONT_NORMAL, 12, array(0, 0, 1)); // blue if (isset($attrs[Reader::XMLNS_DOCBOOK]["linkend"])) { $this->cchunk["linkend"] = $attrs[Reader::XMLNS_DOCBOOK]["linkend"]; } elseif (isset($attrs[Reader::XMLNS_XLINK]["href"])) { $this->cchunk["href"] = $attrs[Reader::XMLNS_XLINK]["href"]; } } elseif ($open && $name == "xref" && isset($attrs[Reader::XMLNS_DOCBOOK]["linkend"]) && ($linkend = $attrs[Reader::XMLNS_DOCBOOK]["linkend"])) { $this->cchunk["linkend"] = $linkend; $this->pdfDoc->setFont(PdfWriter::FONT_NORMAL, 12, array(0, 0, 1)); // blue $this->format_link_text(Format::getShortDescription($linkend), $name); $this->pdfDoc->revertFont(); $this->cchunk["linkend"] = ""; } elseif (!$open) { $this->cchunk["href"] = ""; $this->cchunk["linkend"] = ""; $this->pdfDoc->revertFont(); } return ""; }
public function format_tocnode($open, $name, $attrs, $props, $newpage = false) { if ($open) { if ($newpage) { parent::getPdfDoc()->add(PdfWriter::PAGE); } else { parent::getPdfDoc()->add(PdfWriter::LINE_JUMP); } if (isset($attrs[Reader::XMLNS_XML]["base"]) && ($base = $attrs[Reader::XMLNS_XML]["base"])) { parent::setChunkInfo("xml-base", $base); } if (isset($attrs[Reader::XMLNS_XML]["id"]) && ($id = $attrs[Reader::XMLNS_XML]["id"])) { $parentId = Format::getParent($id); if (isset($this->cchunk["id-to-outline"][$parentId])) { $this->cchunk["id-to-outline"][$id] = parent::getPdfDoc()->createOutline(Format::getShortDescription($id), $this->cchunk["id-to-outline"][$parentId], false); } else { $this->cchunk["id-to-outline"][$id] = parent::getPdfDoc()->createOutline(Format::getShortDescription($id), $this->cchunk["root-outline"], false); } $this->setIdToPage($id); } parent::setChunkInfo("examplenumber", 0); } return ""; }
public function format_root_chunk($open, $name, $attrs) { $this->CURRENT_CHUNK = $this->CURRENT_ID = $id = $attrs[Reader::XMLNS_XML]["id"]; if ($open) { $this->notify(Render::CHUNK, Render::OPEN); return '<div id="' . $id . '" class="' . $name . '">'; } $this->notify(Render::CHUNK, Render::CLOSE); $chunks = Format::getChildren($id); $content = '<ul class="chunklist chunklist_' . $name . '">'; foreach ($chunks as $chunkid) { $href = $this->chunked ? $chunkid . $this->ext : "#{$chunkid}"; $long = Format::getLongDescription($chunkid); $short = Format::getShortDescription($chunkid); if ($long && $short && $long != $short) { $content .= '<li><a href="' . $href . '">' . $short . '</a> — ' . $long; } else { $content .= '<li><a href="' . $href . '">' . ($long ? $long : $short) . '</a>'; } $children = Format::getChildren($chunkid); if (count($children)) { $content .= '<ul class="chunklist chunklist_' . $name . ' chunklist_children">'; foreach (Format::getChildren($chunkid) as $childid) { $href = $this->chunked ? $childid . $this->ext : "#{$childid}"; $long = Format::getLongDescription($childid); $short = Format::getShortDescription($childid); if ($long && $short && $long != $short) { $content .= '<li><a href="' . $href . '">' . $short . '</a> — ' . $long . '</li>'; } else { $content .= '<li><a href="' . $href . '">' . ($long ? $long : $short) . '</a></li>'; } } $content .= "</ul>"; } $content .= "</li>"; } $content .= "</ul></div>"; return $content; }