set_oebps() ;
$Renderer->set_current_page(epub_clean_name(str_replace(':', '_', $id)) . '.html') ;
$this->_renderer = $Renderer;
if(is_null($Renderer)){
msg("No renderer for $mode found",-1);
exit;
}
global $ID;
$oldID = $ID;
$ID = cleanID($id);
$wiki_file = wikiFN($id);
if(!file_exists($wiki_file)) {
epub_push_spine(array("",""));
echo htmlentities($id) . " not found\n";
return false;
}
epub_update_progress("reading $id");
$instructions = p_cached_instructions($wiki_file, false, $id);
if(is_null($instructions)) return '';
$Renderer->notoc();
$Renderer->smileys = getSmileys();
$Renderer->entities = getEntities();
$Renderer->acronyms = array();
$Renderer->interwiki = getInterwiki();
epub_update_progress("rendering $id, this could take some time");
// Loop through the instructions
foreach ( $instructions as $instruction ) {
// Execute the callback against the Renderer
call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]);
}
$result = "";
$result .='
';
$result .= '' . "\n";
$result .= "\n
\n";
$result .= '\n";
$info = $Renderer->info;
$data = array($mode,& $Renderer->doc);
trigger_event('RENDERER_CONTENT_POSTPROCESS',$data);
$xhtml = $Renderer->doc;
$result .= $xhtml;
//handle image maps
if(strpos($result, 'usemap') !== false) {
$R = $Renderer;
$result = preg_replace_callback(
'|
|im',
function($matches) use($R) {
if(strpos( $matches[1],'?') !== false) {
list($pre, $img) = explode('=', $matches[1]);
}
else $img = basename($matches[1]);
$name = '../'. $R->copy_media($img);
echo "Map image name = $name\n";
return '
';
},
$result
);
//Convert internal links to localized epub links
$result = preg_replace_callback(
'|
|im',
function($matches) {
if(strpos($matches[0], 'http') !== false) return $matches[0]; //External link, no conversioon needed
$matches[0]= preg_replace_callback(
'|href\s*=\s*([\"\'])(.*?)\1|m', //test $matches[0]
function($m) {
if(stripos($m[0],'javascript:') !== false) {
return $m[0]; // we do no convert javascript links
}
$patterns = array('!^' . preg_quote(DOKU_BASE) . '!', "/^doku.php/","!^\?\s*id\s*=\s*!");
$_REQUEST['epubid'] = preg_replace($patterns, "", $m[2]);
$id = getID('epubid') . '.html' ;
$id = "../Text/" . str_replace(':','_',$id) ;
echo "revised url: " . htmlentities($id)."\n";
return "href='$id'";
},$matches[0]);
return $matches[0];
}, $result
);
}
$result .= "\n
\n";
$result = preg_replace_callback("/&(\w+);/m", "epbub_entity_replace", $result );
$result = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/m", "\n", $result);
$result = preg_replace("/^\s+/m", "", $result );
$result = preg_replace_callback(
'|