1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
<?php
/* $Id: PhDThemeXhtml.class.php 276143 2009-02-19 12:00:38Z cweiske $ */
/**
* Base class for XHTML themes
*/
abstract class PhDThemeXhtml extends PhDTheme
{
/**
* If we are a theme generating chunks or not
*
* @var boolean
*/
protected $chunked = true;
/**
* Media manager object
*
* @var PhDMediaManager
*/
public $mediamanager = null;
/**
* Language
*/
protected $lang = 'en';
/**
* Called after the constructor finished.
* This is needed since themes set their outputdir and outputfile
* in the constructor. That file/dir is used for mediamanager.
* That means we cannot instantiate and complete the manager in our
* constructor centrally.
*
* Each theme needs its own media manager, since the manager contains
* the output path.
*
* @return void
*/
public function postConstruct()
{
$this->mediamanager = new PhDMediaManager($GLOBALS['OPTIONS']['xml_root']);
if (isset($this->outputdir) && $this->outputdir) {
$this->mediamanager->output_dir = $this->outputdir;
} else {
$this->mediamanager->output_dir = $this->outputfile . '-data/';
$this->mediamanager->relative_ref_path = basename($this->mediamanager->output_dir) . '/';
}
}//public function postConstruct()
/**
* Creates a table of contents for the given id.
* Also creates nested TOCs if that's wanted ($depth)
*
* @param string $id ID of section for which to generate TOC
* @param string $name Tag name (for ul class)
* @param array $props Build properties (?? FIXME)
* @param integer $depth Depth of TOC
* @param boolean $header If the header shall be shown ("Table of contents")
*
* @return string HTML code for TOC
*/
public function createToc($id, $name, $props, $depth = 1, $header = true)
{
$chunks = PhDHelper::getChildren($id);
if ($depth == 0 || !count($chunks)) {
return '';
}
$content = '';
if ($header) {
$content .= " <strong>" . $this->format->autogen("toc", $props["lang"]) . "</strong>\n";
}
$content .= " <ul class=\"chunklist chunklist_$name\">\n";
foreach ($chunks as $chunkid => $junk) {
$long = $this->format->TEXT(PhDHelper::getDescription($chunkid, true));
$short = $this->format->TEXT(PhDHelper::getDescription($chunkid, false));
if ($long && $short && $long != $short) {
$desc = $short . '</a> -- ' . $long;
} else {
$desc = ($long ? $long : $short) . '</a>';
}
//FIXME
if ($this->chunked) {
$content .= " <li><a href=\"{$chunkid}.{$this->ext}\">" . $desc;
} else {
$content .= " <li><a href=\"#{$chunkid}\">" . $this->format->TEXT(PhDHelper::getDescription($chunkid, false)) . "</a>";
}
if ($depth > 1) {
$content .= $this->createToc($chunkid, $name, $props, $depth - 1, false);
}
$content .= "</li>\n";;
}
$content .= " </ul>\n";
return $content;
}
/**
* Handle an image.
*/
public function format_imagedata($open, $name, $attrs) {
$file = $attrs[PhDReader::XMLNS_DOCBOOK]["fileref"];
$newpath = $this->mediamanager->handleFile($file);
if ($this->format->cchunk["mediaobject"]["alt"] !== false) {
return '<img src="' . $newpath . '" alt="' .$this->format->cchunk["mediaobject"]["alt"]. '" />';
}
return '<img src="' . $newpath . '" />';
}
/**
* Handle a <phd:toc> tag.
*/
public function format_phd_toc($open, $name, $attrs, $props) {
if ($open) {
return '<div class="phd-toc">';
}
return $this->createToc(
$attrs[PhDReader::XMLNS_PHD]['element'],
'phd-toc',
$props,
isset($attrs[PhDReader::XMLNS_PHD]['toc-depth'])
? (int)$attrs[PhDReader::XMLNS_PHD]['toc-depth'] : 1,
false
) . "</div>\n";
}
}
/*
* vim600: sw=4 ts=4 fdm=syntax syntax=php et
* vim<600: sw=4 ts=4
*/
?>
|