registerFormatName("Chunked-XHTML"); $this->setTitle("Index"); $this->setChunked(true); } public function __destruct() { $this->close(); } public function appendData($data) { if ($this->appendToBuffer) { $this->buffer .= $data; return; } elseif ($this->flags & Render::CLOSE) { $fp = $this->popFileStream(); fwrite($fp, $data); $this->writeChunk($this->CURRENT_CHUNK, $fp); fclose($fp); $this->flags ^= Render::CLOSE; } elseif ($this->flags & Render::OPEN) { $fp = fopen("php://temp/maxmemory", "r+"); fwrite($fp, $data); $this->pushFileStream($fp); $this->flags ^= Render::OPEN; } elseif ($data !== null) { $fp = $this->getFileStream(); fwrite(end($fp), $data); } } public function writeChunk($id, $fp) { $filename = $this->getOutputDir() . Format::getFilename($id) . $this->getExt(); 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->getFileStream() as $fp) { fclose($fp); } } public function update($event, $value = null) { switch($event) { case Render::CHUNK: $this->flags = $value; break; case Render::STANDALONE: if ($value) { $this->registerElementMap(static::getDefaultElementMap()); $this->registerTextMap(static::getDefaultTextMap()); } break; case Render::INIT: if ($this->appendToBuffer) { return; //Don't create output dir when rendering to buffer } $this->setOutputDir($this->config->outputDir . strtolower($this->getFormatName()) . '/'); $this->postConstruct(); if (file_exists($this->getOutputDir())) { if (!is_dir($this->getOutputDir())) { throw new \Error('Output directory is a file?'); } } else { if (!mkdir($this->getOutputDir(), 0777, true)) { throw new \Error("Can't create output directory"); } } if ($this->config->css) { $this->fetchStylesheet(); } break; case Render::VERBOSE: $this->outputHandler->v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } } public function header($id) { $title = $this->getLongDescription($id); $lang = $this->config->language; $root = Format::getRootIndex(); static $cssLinks = null; if ($cssLinks === null) { $cssLinks = $this->createCSSLinks(); } $prev = $next = $parent = array("href" => null, "desc" => null); if ($parentId = $this->getParent($id)) { $parent = array("href" => $this->getFilename($parentId) . $this->getExt(), "desc" => $this->getShortDescription($parentId)); } if ($prevId = Format::getPrevious($id)) { $prev = array("href" => Format::getFilename($prevId) . $this->getExt(), "desc" => $this->getShortDescription($prevId)); } if ($nextId = Format::getNext($id)) { $next = array("href" => Format::getFilename($nextId) . $this->getExt(), "desc" => $this->getShortDescription($nextId)); } $navBar = $this->createNavBar($id); return ' '.(($title != $root["ldesc"]) ? $root["ldesc"].': ' : "").$title.' '.$cssLinks.' \n \n
'.$navBar.'
'.($prevId ? '' : '') .' '.($nextId ? '' : '') .' '.($parentId ? '' : '') .'

'; } public function footer($id) { return "\n
\n\n\n"; } protected function createNavBar($id) { $root = Format::getRootIndex(); $navBar = ' \n"; } }