cvs: phd /formats AbstractXHTMLFormat.php
| From: | Moacir de Oliveira Miranda Júnior | Date: | Sat, 13 Jun 2009 12:54:23 +0000 |
| Subject: | cvs: phd /formats AbstractXHTMLFormat.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4142@lists.php.net to get a copy of this message | ||
moacir Sat Jun 13 12:54:23 2009 UTC
Added files:
/phd/formats AbstractXHTMLFormat.php
Log:
class AbstractXHTMLFormat added
http://cvs.php.net/viewvc.cgi/phd/formats/AbstractXHTMLFormat.php?view=markup&rev=1.1
Index: phd/formats/AbstractXHTMLFormat.php
+++ phd/formats/AbstractXHTMLFormat.php
<?php
abstract class AbstractXHTMLFormat extends PhDEnterpriseFormat {
private $formatname = "XHTML";
protected $title;
protected $flags;
protected $ext = "html";
protected $fp = array();
protected $outputdir = __DIR__;
public $role = false;
/* Current Chunk variables */
protected $cchunk = array();
/* Default Chunk variables */
protected $dchunk = array(
"classsynopsis" => array(
"close" => false,
"classname" => false,
),
"classsynopsisinfo" => array(
"implements" => false,
"ooclass" => false,
),
"examples" => 0,
"fieldsynopsis" => array(
"modifier" => "public",
),
"co" => 0,
"callouts" => 0,
"segmentedlist" => array(
"seglistitem" => 0,
"segtitle" => array(
),
),
"table" => false,
"procedure" => false,
"mediaobject" => array(
"alt" => false,
),
"footnote" => array(
),
"tablefootnotes" => array(
),
);
public function __construct() {
parent::__construct();
parent::registerFormatName($this->formatname);
}
public abstract function header($id);
public abstract function footer($id);
public function transformFromMap($open, $tag, $name, $attrs, $props) {
if ($open) {
$idstr = "";
if (isset($attrs[PhDEnterpriseReader::XMLNS_XML]["id"])) {
$id = $attrs[PhDEnterpriseReader::XMLNS_XML]["id"];
$idstr = ' id="' .$id. '" name="' .$id.
'"';
}
return '<' .$tag. ' class="' .$name. '"' .
$idstr . ($props["empty"] ? '/' : "") . '>';
}
return '</' .$tag. '>';
}
public function appendData($data) {
if ($this->appendToBuffer) {
$this->buffer .= $data;
return;
} elseif ($this->flags & PhDRender::CLOSE) {
$fp = array_pop($this->fp);
fwrite($fp, $data);
$this->writeChunk($this->CURRENT_CHUNK, $fp);
fclose($fp);
$this->flags ^= PhDRender::CLOSE;
} elseif ($this->flags & PhDRender::OPEN) {
$this->fp[] = $fp = fopen("php://temp/maxmemory", "r+");
fwrite($fp, $data);
$this->flags ^= PhDRender::OPEN;
} else {
$fp = end($this->fp);
fwrite($fp, $data);
}
}
public function writeChunk($id, $fp) {
$filename = $this->outputdir . $id . '.' .$this->ext;
rewind($fp);
file_put_contents($filename, $this->header($id));
file_put_contents($filename, $fp, FILE_APPEND);
file_put_contents($filename, $this->footer($id), FILE_APPEND);
}
public function close() {
foreach ($this->fp as $fp) {
fclose($fp);
}
}
public function createLink($for, &$desc = null, $type = PhDEnterpriseFormat::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;
}
public function TEXT($str) {
return htmlspecialchars($str, ENT_QUOTES, "UTF-8");
}
public function CDATA($str) {
switch($this->role) {
case "php":
return '<div class="phpcode">' .(highlight_string(trim($str),
1)). '</div>';
break;
default:
return '<div class="cdata"><pre>'
.(htmlspecialchars($str, ENT_QUOTES, "UTF-8")). '</pre></div>';
}
}
public function UNDEF($open, $name, $attrs, $props) {
if ($open) {
trigger_error("No mapper found for '{$name}'", E_USER_WARNING);
}
}
protected function createTOC($id, $lang) {
if (!$this->getChildrens($id)) {
return "";
}
$toc = '<h2>' . $this->autogen('toc', $lang) .
'</h2><ol>';
foreach ($this->getChildrens($id) as $child) {
$isLDesc = null;
$isSDesc = null;
$long = $this->parse($this->getLongDescription($child, $isLDesc));
$short = $this->getShortDescription($child, $isSDesc);
$link = $this->createLink($child);
$list = "";
if ($this->cchunk["name"] === "book" ||
$this->cchunk["name"] === "set") {
if ($this->getChildrens($child)) {
$list = "<ol>";
foreach ($this->getChildrens($child) as $subChild) {
$isSubLDesc = null;
$isSubSDesc = null;
$subLong = $this->parse($this->getLongDescription($subChild,
$isLDesc));
$subShort = $this->getShortDescription($subChild, $isSubSDesc);
$href = $this->createLink($subChild);
if ($isSubLDesc && $isSubSDesc) {
$list .= '<li><a href="' . $href .
'">' . $subShort . '</a> â ' . $subLong .
"</li>\n";
} else {
$list .= '<li><a href="' . $href .
'">' . ($subLong ?: $subShort) . '</a>' .
"</li>\n";
}
}
$list .="</ol>";
}
}
if ($isLDesc && $isSDesc) {
$toc .= '<li><a href="' . $link . '">' .
$short . '</a> â ' . $long . $list . "</li>\n";
} else {
$toc .= '<li><a href="' . $link . '">' .
($long ?: $short) . '</a>' . $list . "</li>\n";
}
}
$toc .= "</ol>\n";
return $toc;
}
public function update($event, $val = null) {
switch($event) {
case PhDRender::CHUNK:
$this->flags = $val;
break;
case PhDRender::STANDALONE:
if ($val) {
$this->registerElementMap(static::getDefaultElementMap());
$this->registerTextMap(static::getDefaultTextMap());
}
break;
case PhDRender::INIT:
$this->outputdir = $tmp = PhDConfig::output_dir() .
strtolower($this->getFormatName()) . '/';
if (file_exists($tmp)) {
if (!is_dir($tmp)) {
v("Output directory is a file?", E_USER_ERROR);
}
} else {
if (!mkdir($tmp)) {
v("Can't create output directory", E_USER_ERROR);
}
}
break;
case PhDRender::VERBOSE:
v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
break;
}
}
public function getChunkInfo() {
return $this->cchunk;
}
}