function copy_media($media, $external = false)
 {
     $name = epub_clean_name(str_replace(':', '_', basename($media)));
     $ret_name = $name;
     $mime_type = mimetype($name);
     list($type, $ext) = explode('/', $mime_type[1]);
     if ($type !== 'image') {
         return;
     }
     if ($external) {
         if (!$this->allow_url_fopen) {
             return;
         }
         $tmp = str_replace('https://', "", $media);
         $tmp = str_replace('http://', "", $media);
         $tmp = str_replace('www.', "", $tmp);
         if ($this->isWin) {
             $tmp = preg_replace('/^[A-Z]:/', "", $tmp);
         }
         $tmp = ltrim($tmp, '/\\/');
         $elems = explode('/', $tmp);
         if ($this->isWin) {
             $elems = explode('\\', $tmp);
         }
         if (count($elems && $elems[0])) {
             $elems[0] = preg_replace('#/\\W#', '_', $elems[0]);
             $name = $elems[0] . "_" . $name;
         }
     }
     if (!preg_match("/^Images/", $name)) {
         $name = "Images/{$name}";
     }
     $file = $this->oebps . $name;
     if (file_exists($file)) {
         return $name;
     }
     if (!$external) {
         $media = mediaFN($media);
     }
     if (copy($media, $file)) {
         epub_write_item($name, $mime_type[1]);
         return $name;
     } else {
         if (!$this->isWin && epub_save_image($media, $file)) {
             epub_write_item($name, $mime_type[1]);
             return $name;
         }
     }
     return false;
 }
Beispiel #2
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;
    }