/**
* Set output of book content.
*
* @access private
* @return void
*/
private function setVisibleContent()
{
$book = $this->epub;
$component = $this->cakeRequest->query('comp');
$callback = function ($m) use($book, $component) {
$method = $m[1];
$path = $m[2];
$end = '';
if (preg_match('/^src\\s*:/', $method)) {
$end = ')';
}
if (preg_match('/^#/', $path)) {
return $method . '\'' . $path . '\'' . $end;
}
$hash = '';
if (preg_match('/^(.+)#(.+)$/', $path, $matches)) {
$path = $matches[1];
$hash = '#' . $matches[2];
}
$comp = $book->getComponentName($component, $path);
if (!$comp) {
return $method . '\'#\'' . $end;
}
$out = $method . '\'?comp=' . $comp . $hash . '\'' . $end;
return $end ? $out : str_replace('&', '&', $out);
};
$content = preg_replace_callback(array('/(src\\s*:\\s*url\\()(.*?)\\)/', '/(\\@import\\s+)["\'](.*?)["\'];/', '/(href=)["\']([^:]*?)["\']/', '/(src=)["\']([^:]*?)["\']/'), $callback, $book->component($component));
header('Pragma: public');
header('Cache-Control: maxage=' . 1209600);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 1209600) . ' GMT');
header('Content-Type: ' . $book->componentContentType($component));
print $content;
exit;
}