Esempio n. 1
0
    function create($id, $user_title = false)
    {
        ob_start();
        $id = ltrim($id, ':');
        $id = ":{$id}";
        $namespace = getNS($id);
        epub_save_namespace($namespace);
        $mode = 'epub';
        $Renderer =& plugin_load('renderer', $mode);
        $Renderer->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 "{$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 .= '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n";
        $result .= "\n<head>\n";
        $result .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>' . "\n";
        $result .= '<link rel="stylesheet"  type="text/css" href="../Styles/style.css"/>';
        epub_check_for_mathjax($result);
        $result .= "\n<title>";
        $result .= "</title>\n</head><body>\n";
        $result .= "<div class='dokuwiki'>\n";
        $info = $Renderer->info;
        $data = array($mode, &$Renderer->doc);
        trigger_event('RENDERER_CONTENT_POSTPROCESS', $data);
        $xhtml = $Renderer->doc;
        $result .= $xhtml;
        $result .= "\n</div></body></html>\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('|<p>([\\s\\n]*)(.*?<div.*?/div>.*?)([\\s\\n])*<\\/p>|im', create_function('$matches', '$result = $matches[1] . $matches[2] . $matches[3];
											//echo "$result\\n";
											return $result;'), $result);
        ob_end_flush();
        if ($user_title) {
            $id = 'title.html';
        } else {
            $id = epub_clean_name(str_replace(':', '_', $id)) . '.html';
        }
        io_saveFile(epub_get_oebps() . "Text/{$id}", $result);
        if ($user_title) {
            epub_write_zip('Text/title.html');
            $ID = $oldID;
            return true;
        }
        $item_num = epub_write_item("Text/{$id}", "application/xhtml+xml");
        epub_push_spine(array("Text/{$id}", $item_num));
        epub_save_namespace();
        $ID = $oldID;
        return true;
    }
Esempio n. 2
0
/**
   Adds content.opf and toc.ncx to zip file and closes it
*/
function epub_finalize_zip()
{
    $zip = epub_zip_handle();
    if (!$zip) {
        return false;
    }
    epub_write_zip('content.opf');
    epub_write_zip('toc.ncx');
    $zip->close();
    return true;
}