コード例 #1
0
ファイル: ebook.php プロジェクト: omusico/isle-web-framework
    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;
    }
コード例 #2
0
/**
    loads spine array and adds nav points to the ncx file
	then outputs closing tags to ncx file.  The header to
	ncx file is created in epub_opf_header()
*/
function epub_write_ncx()
{
    $toc = epub_get_oebps() . 'toc.ncx';
    $opf_handle = fopen($toc, 'a');
    if (!$opf_handle) {
        echo "unable to open file: {$toc}\n";
        exit;
    }
    $items = epub_push_spine();
    array_unshift($items, array('Text/title.html'));
    $num = 0;
    foreach ($items as $page) {
        $num++;
        $page = $page[0];
        $title = epub_titlesStack();
        if (!$page) {
            continue;
        }
        if ($title) {
            echo "found {$title} for {$page}\n";
        }
        $navpoint = <<<NAVPOINT
 <navPoint id="np-{$num}" playOrder="{$num}">
  <navLabel>
\t<text>{$title}</text>
  </navLabel>
  <content src="{$page}"/>
</navPoint>
NAVPOINT;
        fwrite($opf_handle, "{$navpoint}\n");
    }
    fwrite($opf_handle, "</navMap>\n</ncx>\n");
    fflush($opf_handle);
    fclose($opf_handle);
}