Exemple #1
0
function ewiki_page_wiki_mini_tarball_dump($id, $data, $action)
{
    global $ewiki_config, $ewiki_plugins;
    #-- get all pages / binary files
    $result = ewiki_db::GETALL(array("id", "version", "flags"));
    if ($result) {
        #-- HTTP headers
        header("Content-Type: application/x-tar");
        header("Content-Disposition: attachment; filename=\"InitPages.tar.gz\"");
        #-- start tar file
        $tarball = new ewiki_virtual_tarball();
        $tarball->open(0);
        #-- convert all pages
        while ($row = $result->get(0, 0x1037)) {
            $id = $row["id"];
            $row = ewiki_db::GET($id);
            $content =& $row["content"];
            $fn = $id;
            if (!$row || !$row["id"] || !$row["content"]) {
                continue;
            }
            #-- for tarball
            $perms = array("mtime" => $row["lastmodified"], "uname" => "ewiki", "mode" => 0664 | ($row["flags"] & EWIKI_DB_F_WRITEABLE ? 02 : 00));
            #-- add file
            $tarball->add($fn, $content, $perms);
        }
        #-- end output
        $tarball->close();
    }
    #-- fin
    die;
}
Exemple #2
0
function ewiki_page_wiki_dump_send($imgs = 1, $fullhtml = 0, $virtual = 0, $linksto = 0)
{
    global $ewiki_config, $ewiki_plugins;
    #-- reconfigure ewiki_format() to generate offline pages and files
    $html_ext = ".htm";
    if ($fullhtml) {
        $html_ext = ".html";
    }
    $ewiki_config["script"] = "%s{$html_ext}";
    $ewiki_config["script_binary"] = "%s";
    $ewiki_config["print_title"] = 0;
    #-- fetch also dynamic pages
    if ($virtual) {
        $virtual = array_keys($ewiki_plugins["page"]);
    } else {
        $virtual = array();
    }
    #-- get all pages / binary files
    $result = ewiki_db::GETALL(array("id", "version", "flags"));
    if ($result) {
        #-- HTTP headers
        header("Content-Type: application/x-tar");
        header("Content-Disposition: attachment; filename=\"WikiDump.tar.gz\"");
        #-- start tar file
        $tarball = new ewiki_virtual_tarball();
        $tarball->open(0);
        #-- convert all pages
        while (($row = $result->get()) || count($virtual)) {
            $content = "";
            #-- fetch page from database
            if ($id = $row["id"]) {
                $row = ewiki_db::GET($id);
            } elseif ($id = array_pop($virtual)) {
                $pf = $ewiki_plugins["page"][$id];
                $content = $pf($id, $content, "view");
                $row = array("flags" => EWIKI_DB_F_TEXT | EWIKI_DB_F_HTML, "lastmodified" => time());
            } else {
                break;
            }
            #-- file name
            $fn = $id;
            $fn = urlencode($fn);
            #-- post process for ordinary pages / binary data
            if (empty($content)) {
                switch ($row["flags"] & EWIKI_DB_F_TYPE) {
                    case EWIKI_DB_F_TEXT:
                        $content = ewiki_format($row["content"]);
                        break;
                    case EWIKI_DB_F_BINARY:
                        if ($row["meta"]["class"] == "image" && $imgs) {
                            $content =& $row["content"];
                        } else {
                            return;
                        }
                        break;
                    default:
                        # don't want it
                        continue;
                }
            }
            #-- size check
            if (empty($content)) {
                continue;
            }
            #-- for tarball
            $perms = array("mtime" => $row["lastmodified"], "uname" => "ewiki", "mode" => 0664 | ($row["flags"] & EWIKI_DB_F_WRITEABLE ? 02 : 00));
            #-- html post process
            if (!($row["flags"] & EWIKI_DB_F_BINARY)) {
                #-- use page template
                if ($fullhtml) {
                    $content = ewiki_dump_template($id, $content, $linksto);
                }
                #-- add links/ page
                if ($linksto) {
                    $tarball->add("{$fn}.links{$html_ext}", ewiki_dump_template($id, ewiki_page_links($id, $row, "links"), $lto = -1), $perms);
                }
                $fn .= $html_ext;
            }
            #-- add file
            $tarball->add($fn, $content, $perms);
        }
        #-- end output
        $tarball->close();
    }
    #-- fin
    die;
}